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