Skip to content
247 linesCodeBlameRaw
1import { Package, Plus } from "lucide-react";
2import { Outlet, data, redirect, useLocation, useNavigation } from "react-router";
3
4import type { Route } from "./+types/layout";
5import { page } from "../../lib/meta";
6import { ButtonLink } from "../../components/ui";
7import { Avatar } from "../../components/ui/avatar";
8import { Badge } from "../../components/ui/badge";
9import { WelcomeBanner } from "../../components/welcome";
10import { clearWelcome, welcomes } from "../../lib/invites";
11import { notFound } from "../../lib/not-found.server";
12import { redirectIfRenamed } from "../../lib/renamed.server";
13import { rememberWorkspace } from "../../lib/workspace-choice";
14import { workspacePage, workspaceRedirect } from "../../lib/workspace-nav";
15import { WorkspacePageSkeleton } from "../../components/workspace-skeletons";
16import { identity } from "../../lib/services.server";
17import { getViewer, roleIn } from "../../lib/session.server";
18
19export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
20 return page(args, { title: `${loaderData?.workspace.name ?? params.owner} · g1t` });
21}
22
23export async function loader({ params, context, request }: Route.LoaderArgs) {
24 const url = new URL(request.url);
25 // `?tab=projects` and the like, from the tabs this page once had: that
26 // page's own address.
27 const moved = url.search ? workspaceRedirect(url.pathname, url.search) : null;
28 if (moved) throw redirect(moved);
29 const viewer = getViewer(context);
30 const workspace = await identity.getWorkspace(params.owner);
31 if (!workspace) {
32 // A workspace's old name, after a rename: its pages are at the new one.
33 await redirectIfRenamed(request, params.owner);
34 throw notFound("workspace");
35 }
36 const role = roleIn(viewer, workspace.slug);
37 // Opening one of your workspaces makes it the one you are in.
38 if (!role) return { workspace, role, welcome: false };
39 const secure = new URL(request.url).protocol === "https:";
40 const headers = new Headers({ "Set-Cookie": rememberWorkspace(workspace.slug, secure) });
41 // Just joined with an invite: welcomed once (routes/invite.tsx).
42 const welcome = welcomes(request.headers.get("cookie"), workspace.slug);
43 if (welcome) headers.append("Set-Cookie", clearWelcome(secure));
44 return data({ workspace, role, welcome }, { headers });
45}
46
47/** A workspace's own pages, each with its title and what it is for. */
48const PAGES: Record<string, { title: string; about: string }> = {
49 workspace: {
50 title: "Workspace",
51 about: "Who is in it, what it is on, and what it has spent this month. Everything about the workspace itself is in this sidebar.",
52 },
53 settings: { title: "General", about: "The workspace's name, icon, address and description, who can create teams, and deleting it." },
54 people: {
55 title: "People",
56 about: "Everyone in the workspace, people and agents, in one directory: who they are, what they own, the teams they're on and who's around.",
57 },
58 members: {
59 title: "Members and invites",
60 about: "Members create repositories and have the base permission on each one. Owners are Admins on every repository, and also manage members, tokens, billing and integrations.",
61 },
62 "org-chart": {
63 title: "Org chart",
64 about: "Who reports to whom, with each team's agents beside the person who leads it.",
65 },
66 projects: {
67 title: "Projects",
68 about: "Everything the workspace builds and runs. Search, filter and sort them, and pin the ones you use most to keep them in your sidebar.",
69 },
70 teams: {
71 title: "Teams",
72 about: "People, agents, or both, with a lead, a channel, roles on repositories and a budget for their agents. Everyone on a team, agents included, knows who their teammates are.",
73 },
74 repositories: {
75 title: "Repositories",
76 about: "Every repository in the workspace: who can see it, whether it is archived, and the ones deleted recently.",
77 },
78 tokens: {
79 title: "Access tokens",
80 about: "Tokens that belong to the workspace, not a person: for CI, integrations and agents that work for the whole team. Each has the permissions an owner gives it, in all of the workspace's repositories or the ones chosen.",
81 },
82 "personal-access-tokens": {
83 title: "Personal access tokens",
84 about: "Which of your members' own tokens may reach the workspace and for how long, the tokens made for it that wait for an owner's approval, and every token that can reach it.",
85 },
86 packages: {
87 title: "Packages",
88 about: "What the workspace publishes and installs, beside its code: container images, npm, Composer, Go, Cargo, Maven, NuGet and RubyGems, with the same members, roles and tokens.",
89 },
90 usage: { title: "Usage", about: "What the workspace's agents cost, run by run, by repository, pull request and model." },
91 gateway: {
92 title: "AI Gateway",
93 about: "Your own code's model requests, sent with the workspace's access tokens: each one's model, tokens, cost and status.",
94 },
95 billing: { title: "Billing and plans", about: "The g1t plan, the trial, your spend limit and caps, prepaying, and every charge." },
96 agents: {
97 title: "Agents",
98 about: "The workspace's agents together: what they are working on now, what waits on you, and where this month's agent budget went.",
99 },
100 memory: {
101 title: "Workspace memory",
102 about: "What holds across all of the workspace's projects, given to every agent in every one of them, beside each project's own memory.",
103 },
104 context: {
105 title: "Context",
106 about: "Everything the workspace builds and runs, and what it knows: a catalog built from its projects, memory with a review queue, one search over all of it, and a scorecard for each project.",
107 },
108 audit: {
109 title: "Audit log",
110 about: "Every action agents took with their run credentials, and every change people and tokens made: by whom, on whose behalf, to what, and whether it was allowed.",
111 },
112 guardrails: {
113 title: "Guardrails",
114 about: "What agents may reach, run, spend and take in every project's sandboxes. Each project can override these under its settings.",
115 },
116 webhooks: {
117 title: "Webhooks",
118 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
119 },
120 secrets: {
121 title: "Secrets and variables",
122 about: "Shared with every repository, or the ones you link: read by workflows, deployments, or both. A repository's own row of the same key wins.",
123 },
124 security: {
125 title: "Security",
126 about: "Open alerts in every project: secrets found in pushes and history, and vulnerable dependencies. Each project's Security page has the details and the security update g1t opened for each.",
127 },
128 integrations: {
129 title: "Integrations",
130 about:
131 "The tools your team works with, connected once for everyone in the workspace and its agents. Secrets are sealed when saved, and agents never see them.",
132 },
133};
134
135/** A workspace page's heading: its title and what it is for. */
136function PageHeader({ title, about }: { title: string; about: string }) {
137 return (
138 <header className="mb-8 border-b border-line pb-6">
139 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
140 <p className="mt-1.5 text-sm text-muted">{about}</p>
141 </header>
142 );
143}
144
145/** Artifacts' pages that are lists, not one artifact. */
146const ARTIFACT_LISTS = new Set(["new", "templates", "trash", "stale", "spaces"]);
147
148/** Whether the page (its path after `/-/`, in parts) is one artifact or a project's doc file. */
149function isArtifactPage(parts: string[]): boolean {
150 if (parts[0] !== "artifacts" || parts.length < 2) return false;
151 if (parts[1] === "repo") return true;
152 return !ARTIFACT_LISTS.has(parts[1]!) && parts.length === 2;
153}
154
155export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
156 const { workspace, role, welcome } = loaderData;
157 const { pathname } = useLocation();
158 const going = useNavigation().location;
159 // The workspace's own page is its overview. Its other pages are found
160 // from the sidebar, which lights the one you are on, and the top bar's
161 // trail leads back here; each has a heading of its own.
162 const here = workspacePage(pathname, workspace.slug);
163 // On the way to another of its pages: that page's heading and shape
164 // until it arrives.
165 const next = going && going.pathname !== pathname ? workspacePage(going.pathname, workspace.slug) : null;
166 const shown = next ?? here;
167 const parts = (pathname.split("/-/")[1] ?? "").split("/").filter(Boolean);
168 // Chat fills the page edge to edge: its conversation, thread and details
169 // are columns of their own (components/chat/channel.tsx).
170 if (parts[0] === "chat" && !next) return <Outlet />;
171 // Code's Overview lays itself out, as Mission control did.
172 if (parts[0] === "overview" && parts.length === 1 && !next) return <Outlet />;
173 // An open artifact, or a project's doc, fills the panel: its header runs edge to edge right under
174 // the top bar (components/folios/shell.tsx), and its page sets its own width.
175 if (isArtifactPage(parts) && !next) {
176 return (
177 <div className="px-4 pb-10 sm:px-6 lg:px-8">
178 <Outlet />
179 </div>
180 );
181 }
182 if (shown !== "overview") {
183 const key = shown ?? parts[0] ?? "";
184 const heading = PAGES[key];
185 // A page within one (a single package or team) and a page that is
186 // coming (Insights) have headings of their own.
187 const titled = heading && (shown != null || parts.length === 1);
188 return (
189 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
190 {titled && (
191 // A phone's Agents tab opens on its list of agents (agents/layout.tsx); the fleet's heading would sit above it.
192 <div className={key === "agents" ? "max-md:hidden" : undefined}>
193 <PageHeader title={heading.title} about={heading.about} />
194 </div>
195 )}
196 {next ? <WorkspacePageSkeleton page={next} /> : <Outlet />}
197 </div>
198 );
199 }
200 return (
201 <>
202 {/* The workspace's own header band, above its overview. */}
203 <div className="border-b border-line bg-surface/60">
204 <div className="mx-auto max-w-6xl px-4 py-8">
205 {welcome && (
206 <div className="mb-6">
207 <WelcomeBanner title={`You're in ${workspace.name}`}>
208 You joined as a {role}. Its projects, issues and agents are all here.
209 </WelcomeBanner>
210 </div>
211 )}
212 <div className="flex flex-wrap items-center gap-4">
213 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
214 <div className="min-w-0 grow">
215 <div className="flex flex-wrap items-center gap-2.5">
216 <h1 className="truncate text-2xl font-semibold tracking-tight">
217 {workspace.name}
218 </h1>
219 {role && <Badge size="md">{role}</Badge>}
220 </div>
221 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
222 </div>
223 {role ? (
224 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
225 <Plus size={15} />
226 New project
227 </ButtonLink>
228 ) : (
229 // A visitor's sidebar is not this workspace's: its packages
230 // are a link here, as its projects are below.
231 <ButtonLink to={`/${workspace.slug}/-/packages`} variant="outline" prefetch="intent">
232 <Package size={15} />
233 Packages
234 </ButtonLink>
235 )}
236 </div>
237 {workspace.description && (
238 <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>
239 )}
240 </div>
241 </div>
242 <div className="mx-auto max-w-6xl px-4 py-8">
243 {next ? <WorkspacePageSkeleton page="overview" /> : <Outlet />}
244 </div>
245 </>
246 );
247}