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.
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 1 | import { env } from "cloudflare:workers"; |
| 2 | import { data } from "react-router"; | |
| 3 | ||
| The phone app: Chat in full with phone notifications, plus Code and Customize (#4) | 4 | import { notifyClient, type NotifyPreferencesChange, type PresenceChange, type PushDevice, type PushSubscriptionJson } from "@g1t/contracts"; |
| Chat has sounds. A short warm cue plays for a message in a conversation you have open but aren't looking at, a direct message, a mention of you and an agent finishing something for you, with a soft tick for sending that is off until you turn it on; never for your own messages, a muted conversation, a conversation you are looking at in a window that has the front, or while you have paused notifications, and never twice for one message or more than once in a second and a half. The cues are made by the browser itself in two sets, Soft and Bright, so nothing is downloaded; the Sounds and notifications section of your notification settings turns them on and off, picks the set and the volume, plays each one, and offers desktop notifications for when the window is behind; Do not disturb is the one pause everyone sees, set from the chat sidebar's bell, the settings, or your avatar menu, now with a two-hour choice, and the top bar's bell shows a dot while it's on. Your choices are kept with your account. The sound layer sits behind one small interface so the desktop app can play them natively later. The chat and notifications guides say the rules. | 5 | import type { SoundSettingsChange } from "@g1t/contracts/sounds"; |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 6 | |
| 7 | import type { Route } from "./+types/api"; | |
| Chat has sounds. A short warm cue plays for a message in a conversation you have open but aren't looking at, a direct message, a mention of you and an agent finishing something for you, with a soft tick for sending that is off until you turn it on; never for your own messages, a muted conversation, a conversation you are looking at in a window that has the front, or while you have paused notifications, and never twice for one message or more than once in a second and a half. The cues are made by the browser itself in two sets, Soft and Bright, so nothing is downloaded; the Sounds and notifications section of your notification settings turns them on and off, picks the set and the volume, plays each one, and offers desktop notifications for when the window is behind; Do not disturb is the one pause everyone sees, set from the chat sidebar's bell, the settings, or your avatar menu, now with a two-hour choice, and the top bar's bell shows a dot while it's on. Your choices are kept with your account. The sound layer sits behind one small interface so the desktop app can play them natively later. The chat and notifications guides say the rules. | 8 | import { identity } from "../../lib/services.server"; |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 9 | import { assertSameOrigin, requireUser } from "../../lib/session.server"; |
| 10 | ||
| 11 | function client() { | |
| 12 | if (!env.NOTIFY) throw data({ error: "Notifications are not set up here." }, { status: 503 }); | |
| 13 | return notifyClient(env.NOTIFY); | |
| 14 | } | |
| 15 | ||
| 16 | /** | |
| 17 | * The signed-in person's notification settings, as JSON: `GET` their | |
| The phone app: Chat in full with phone notifications, plus Code and Customize (#4) | 18 | * status (with `?endpoint=` for whether this browser gets pushes, and how |
| 19 | * many phones do), `POST` a change: `subscribe`, `unsubscribe`, | |
| 20 | * `register_device` and `unregister_device` (the phone app, with its Expo | |
| 21 | * push token), `preferences`, `test`, `presence` (your status, being away, | |
| 22 | * Do Not Disturb), or `sounds` (what you hear when chat moves, kept with | |
| 23 | * the account by identity). | |
| 24 | * | |
| 25 | * The phone app calls this with its access token and no `Origin`, which | |
| 26 | * the same-origin check lets through (lib/same-origin.ts). | |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 27 | */ |
| 28 | export async function loader({ context, request }: Route.LoaderArgs) { | |
| 29 | const user = requireUser(context, request); | |
| 30 | const endpoint = new URL(request.url).searchParams.get("endpoint"); | |
| 31 | const status = await client().status(user, endpoint); | |
| 32 | return Response.json(status, { headers: { "cache-control": "no-store" } }); | |
| 33 | } | |
| 34 | ||
| 35 | type Sent = { | |
| 36 | intent?: string; | |
| 37 | subscription?: PushSubscriptionJson & { expirationTime?: number | null }; | |
| 38 | endpoint?: string; | |
| The phone app: Chat in full with phone notifications, plus Code and Customize (#4) | 39 | device?: PushDevice; |
| 40 | token?: string; | |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 41 | preferences?: NotifyPreferencesChange; |
| Chat has sounds. A short warm cue plays for a message in a conversation you have open but aren't looking at, a direct message, a mention of you and an agent finishing something for you, with a soft tick for sending that is off until you turn it on; never for your own messages, a muted conversation, a conversation you are looking at in a window that has the front, or while you have paused notifications, and never twice for one message or more than once in a second and a half. The cues are made by the browser itself in two sets, Soft and Bright, so nothing is downloaded; the Sounds and notifications section of your notification settings turns them on and off, picks the set and the volume, plays each one, and offers desktop notifications for when the window is behind; Do not disturb is the one pause everyone sees, set from the chat sidebar's bell, the settings, or your avatar menu, now with a two-hour choice, and the top bar's bell shows a dot while it's on. Your choices are kept with your account. The sound layer sits behind one small interface so the desktop app can play them natively later. The chat and notifications guides say the rules. | 42 | change?: PresenceChange | SoundSettingsChange; |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 43 | }; |
| 44 | ||
| 45 | export async function action({ context, request }: Route.ActionArgs) { | |
| 46 | assertSameOrigin(request); | |
| 47 | const user = requireUser(context, request); | |
| 48 | const sent = (await request.json().catch(() => ({}))) as Sent; | |
| 49 | const notify = client(); | |
| 50 | switch (sent.intent) { | |
| 51 | case "subscribe": { | |
| 52 | const s = sent.subscription; | |
| 53 | if (!s?.endpoint || !s.keys?.p256dh || !s.keys?.auth) return Response.json({ ok: false }, { status: 400 }); | |
| 54 | const subscription: PushSubscriptionJson = { endpoint: s.endpoint, keys: { p256dh: s.keys.p256dh, auth: s.keys.auth } }; | |
| 55 | return Response.json(await notify.subscribe(user, subscription, request.headers.get("user-agent"))); | |
| 56 | } | |
| 57 | case "unsubscribe": | |
| 58 | return Response.json(await notify.unsubscribe(user, String(sent.endpoint ?? ""))); | |
| The phone app: Chat in full with phone notifications, plus Code and Customize (#4) | 59 | case "register_device": { |
| 60 | const d = sent.device; | |
| 61 | if (typeof d?.token !== "string" || (d.platform !== "android" && d.platform !== "ios")) return Response.json({ ok: false }, { status: 400 }); | |
| 62 | const device: PushDevice = { token: d.token, platform: d.platform, name: typeof d.name === "string" ? d.name : null }; | |
| 63 | const registered = await notify.registerDevice(user, device); | |
| The phone app with your own g1t, on g1t.sh/download until Google Play, and Node 24 (#5) | 64 | // The service checks the token is Expo's; `off` is this g1t sending phones nothing (PHONE_PUSH=off), not a mistake. |
| 65 | return Response.json(registered, { status: registered.ok || registered.off ? 200 : 400 }); | |
| The phone app: Chat in full with phone notifications, plus Code and Customize (#4) | 66 | } |
| 67 | case "unregister_device": | |
| 68 | return Response.json(await notify.unregisterDevice(user, String(sent.token ?? ""))); | |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 69 | case "preferences": |
| 70 | return Response.json(await notify.setPreferences(user, sent.preferences ?? {})); | |
| 71 | case "test": | |
| 72 | return Response.json(await notify.test(user)); | |
| Chat has sounds. A short warm cue plays for a message in a conversation you have open but aren't looking at, a direct message, a mention of you and an agent finishing something for you, with a soft tick for sending that is off until you turn it on; never for your own messages, a muted conversation, a conversation you are looking at in a window that has the front, or while you have paused notifications, and never twice for one message or more than once in a second and a half. The cues are made by the browser itself in two sets, Soft and Bright, so nothing is downloaded; the Sounds and notifications section of your notification settings turns them on and off, picks the set and the volume, plays each one, and offers desktop notifications for when the window is behind; Do not disturb is the one pause everyone sees, set from the chat sidebar's bell, the settings, or your avatar menu, now with a two-hour choice, and the top bar's bell shows a dot while it's on. Your choices are kept with your account. The sound layer sits behind one small interface so the desktop app can play them natively later. The chat and notifications guides say the rules. | 73 | case "sounds": { |
| 74 | const saved = await identity.setSoundSettings(user, (sent.change ?? {}) as SoundSettingsChange); | |
| 75 | if (!saved.ok) return Response.json({ ok: false, error: saved.error.message }, { status: 400 }); | |
| 76 | return Response.json(saved.value); | |
| 77 | } | |
| One kind of access token; presence and status; usernames keep their case; the tour is a miniature of the real app; icons for password managers | 78 | case "presence": { |
| 79 | // Set by hand here: a calendar's or an integration's comes through their own door. | |
| Chat has sounds. A short warm cue plays for a message in a conversation you have open but aren't looking at, a direct message, a mention of you and an agent finishing something for you, with a soft tick for sending that is off until you turn it on; never for your own messages, a muted conversation, a conversation you are looking at in a window that has the front, or while you have paused notifications, and never twice for one message or more than once in a second and a half. The cues are made by the browser itself in two sets, Soft and Bright, so nothing is downloaded; the Sounds and notifications section of your notification settings turns them on and off, picks the set and the volume, plays each one, and offers desktop notifications for when the window is behind; Do not disturb is the one pause everyone sees, set from the chat sidebar's bell, the settings, or your avatar menu, now with a two-hour choice, and the top bar's bell shows a dot while it's on. Your choices are kept with your account. The sound layer sits behind one small interface so the desktop app can play them natively later. The chat and notifications guides say the rules. | 80 | const change = (sent.change ?? {}) as PresenceChange; |
| One kind of access token; presence and status; usernames keep their case; the tour is a miniature of the real app; icons for password managers | 81 | const status = change.status ? { ...change.status, source: "manual" as const } : change.status; |
| 82 | return Response.json(await notify.setPresence(user, { ...change, ...("status" in change ? { status } : {}) })); | |
| 83 | } | |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 84 | default: |
| 85 | return Response.json({ ok: false }, { status: 400 }); | |
| 86 | } | |
| 87 | } |
This file's history is long; its oldest lines are credited to the oldest commit read.