Skip to content
74 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

The phone app: Chat in full with phone notifications, plus Code and Customize (#4)1/**
2 * Links into the app. A `g1t://` link names a site path, as on the desktop
3 * (apps/desktop/src-tauri/src/links.rs): `g1t://acme/-/chat/dm/chn_1` is
4 * the page `/acme/-/chat/dm/chn_1`. The app has screens for some of the
5 * site's pages; `routeFor` says which screen shows a site path, and the
6 * rest open on the site.
7 *
8 * Kept free of React Native imports so `npm test` runs it under Node.
9 */
10
11/** Where the app's OAuth sign-in comes back to. */
12export const OAUTH_CALLBACK_PATH = "/oauth/callback";
13
14/** Path segments a workspace or account can never be named (the site's own pages). */
15const NOT_OWNERS = new Set(["settings", "notifications", "oauth", "device", "login", "register", "-"]);
16
17/**
18 * The app's screen for a site path, or null when the app has none and the
19 * page should open on the site.
20 */
21export function routeFor(sitePath: string): string | null {
22 const [pathname, query = ""] = sitePath.split("?", 2);
23 const parts = pathname.split("/").filter(Boolean).map(decodeURIComponentSafe);
24 const keep = query ? `?${query}` : "";
25 if (parts.length === 0) return "/";
26 if (`/${parts.join("/")}` === OAUTH_CALLBACK_PATH) return OAUTH_CALLBACK_PATH + keep;
27 const [owner, second, third, fourth, fifth] = parts;
The phone app with your own g1t, on g1t.sh/download until Google Play, and Node 24 (#5)28 // `g1t://connect?server=<site>`: point the app at a g1t, as a self-hosted one's download page offers.
29 if (owner === "connect" && !second && /(^|&)server=/.test(query)) return `/connect?${query}`;
The phone app: Chat in full with phone notifications, plus Code and Customize (#4)30 if (NOT_OWNERS.has(owner.toLowerCase())) return null;
31 const workspace = `workspace=${encodeURIComponent(owner)}`;
32
33 // A workspace's own pages: /<workspace>/-/<page>.
34 if (second === "-") {
35 if (third === "chat") {
36 if (!fourth) return `/chat?${workspace}`;
37 if (fourth === "dm" && fifth) return `/chat/${encodeURIComponent(fifth)}?${workspace}`;
38 if (fourth !== "browse" && fourth !== "dm" && !fifth) return `/chat/${encodeURIComponent(fourth)}?${workspace}`;
39 return null;
40 }
41 if (third === "overview" && !fourth) return `/code?${workspace}`;
42 if (third === "marketplace" || third === "integrations" || (third === "agents" && fourth === "skills")) {
43 return `/customize?${workspace}`;
44 }
45 return null;
46 }
47
48 // A repository's pages: /<owner>/<repo>[/pull/<n> | /issues/<n>].
49 if (!second) return null;
50 const repo = `/code/${encodeURIComponent(owner)}/${encodeURIComponent(second)}`;
51 if (!third) return repo;
52 if (third === "pull" && fourth && /^\d+$/.test(fourth) && !fifth) return `${repo}/pull/${fourth}`;
53 if (third === "issues" && fourth && /^\d+$/.test(fourth) && !fifth) return `${repo}/issues/${fourth}`;
54 return null;
55}
56
57/**
58 * The site path a `g1t://` link names, or null for any other link.
59 * `g1t://acme/-/chat?x` is `/acme/-/chat?x`.
60 */
61export function sitePathOf(link: string): string | null {
62 const match = /^g1t:\/\/([^?#]*)(\?[^#]*)?/i.exec(link);
63 if (!match) return null;
64 const path = `/${match[1].replace(/^\/+/, "")}`;
65 return path + (match[2] ?? "");
66}
67
68function decodeURIComponentSafe(part: string): string {
69 try {
70 return decodeURIComponent(part);
71 } catch {
72 return part;
73 }
74}

This file's history is long; its oldest lines are credited to the oldest commit read.