Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Devices: lead each paired device with its person, the device name as the detail
Bruno433605e22db9
diff --git a/server/index.ts b/server/index.tsindex 7fdedac0ea..7c49100dc7 100644--- a/server/index.ts+++ b/server/index.ts@@ -12798,7 +12798,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {return json(res, 200, { ok: true });}if (method === "GET" && path === "/api/auth/sessions") {- return json(res, 200, { sessions: sessions.list(), current: auth.kind === "session" ? auth.session.id : null });+ return json(res, 200, { sessions: sessions.list(sessionPersonName), current: auth.kind === "session" ? auth.session.id : null });}m = path.match(/^\/api\/auth\/sessions\/([\w-]+)$/);if (m && method === "DELETE") {diff --git a/server/sessions.test.ts b/server/sessions.test.tsindex 08bd7aeee8..3f3c737c60 100644--- a/server/sessions.test.ts+++ b/server/sessions.test.ts@@ -571,6 +571,14 @@ describe("sessions", () => {expect(reloaded.authenticate("omb_sess_nope")).toBeNull();});+ it("names each device's person when asked, and leaves it out when that is just the label", () => {+ const mac = pair("Chrome on Mac");+ pair("iPhone");+ const named = registry.list((record) => (record.id === mac.session.id ? "Ada" : record.label));+ expect(named.map((s) => [s.label, s.person])).toEqual([["Chrome on Mac", "Ada"], ["iPhone", undefined]]);+ expect(registry.list().every((s) => s.person === undefined)).toBe(true);+ });+it("expires after 30 days and can be revoked", () => {const { token, session } = pair();clock += SESSION_TTL_MS - 1;diff --git a/server/sessions.ts b/server/sessions.tsindex 24d5ce4846..d620760bf7 100644--- a/server/sessions.ts+++ b/server/sessions.ts@@ -107,6 +107,8 @@ export interface PublicSession {owner?: string;teamRole?: TeamRole;token?: true;+ /** Who this device belongs to, when the server can tell and it is not just the device's own label. */+ person?: string;}export interface PairingCode {@@ -177,7 +179,7 @@ export function isPairingCredential(value: string): boolean {return value.startsWith(PAIRING_CREDENTIAL_PREFIX);}-function publicSession(record: SessionRecord): PublicSession {+function publicSession(record: SessionRecord, personName?: (record: SessionRecord) => string): PublicSession {const view: PublicSession = {id: record.id,label: record.label,@@ -190,6 +192,8 @@ function publicSession(record: SessionRecord): PublicSession {if (record.owner) view.owner = record.owner;if (record.teamRole) view.teamRole = record.teamRole;if (record.token) view.token = true;+ const person = personName?.(record).trim();+ if (person && person !== record.label) view.person = person;return view;}@@ -704,9 +708,10 @@ export class SessionRegistry {return this.sessions.find((s) => s.id === sessionId && s.expiresAt > this.now() && !this.personal(s.scopes)) ?? null;}- list(): PublicSession[] {+ /** `personName` names each device's person (server/index.ts sessionPersonName), so the device list can lead with it. */+ list(personName?: (record: SessionRecord) => string): PublicSession[] {this.prune();- return this.sessions.map(publicSession);+ return this.sessions.map((record) => publicSession(record, personName));}/** The stored digest of each live bearer session among `ids`: the phone relay derives a phone's keys from it. */@@ -724,7 +729,7 @@ export class SessionRegistry {/** The live sessions a Team Cloud member's own codes opened: their phones. Never an Admin-signed pairing (an app). */memberPhones(): PublicSession[] {this.prune();- return this.sessions.filter((s) => s.membershipAuthority === "team" && s.memberCheckedAt !== undefined).map(publicSession);+ return this.sessions.filter((s) => s.membershipAuthority === "team" && s.memberCheckedAt !== undefined).map((record) => publicSession(record));}/** Every code a member made for a phone stops working, and every phone such a code opened signs out. Never an Admin-signed pairing (an app). */diff --git a/src/components/ServerPairingCard.computerName.dom.test.ts b/src/components/ServerPairingCard.computerName.dom.test.tsindex c4e4953596..2627d88ddb 100644--- a/src/components/ServerPairingCard.computerName.dom.test.ts+++ b/src/components/ServerPairingCard.computerName.dom.test.ts@@ -43,3 +43,13 @@ it.each([if (list.length) await vi.waitFor(() => expect(host.querySelector("[data-paired-device]")).not.toBeNull());await vi.waitFor(() => expect(host.querySelector("[data-computer-name]")).not.toBeNull());});++it("leads a device row with its person and keeps the device as the detail", async () => {+ sessions.list = [{ ...phone, label: "Chrome on Mac", person: "Ada" }];+ flushSync(() => root.render(createElement(ServerPairingCard)));+ await vi.waitFor(() => expect(host.querySelector("[data-paired-device]")).not.toBeNull());+ const row = host.querySelector("[data-paired-device]")!;+ const [title, detail] = row.querySelectorAll("span.truncate");+ expect(title?.textContent).toBe("Ada");+ expect(detail?.textContent).toMatch(/^Chrome on Mac · /);+});diff --git a/src/components/ServerPairingCard.tsx b/src/components/ServerPairingCard.tsxindex e5f0d4bfe3..a18c03b414 100644--- a/src/components/ServerPairingCard.tsx+++ b/src/components/ServerPairingCard.tsx@@ -36,6 +36,8 @@ export interface PairedDevice {lastSeenAt: number;expiresAt: number;email?: string;+ /** The device's person, when the server knows it; the label then names the device. Absent on older servers. */+ person?: string;}/**@@ -299,9 +301,9 @@ export function ServerPairingCard({ initialSession = null, initialPairingCodes =<div key={device.id} className="flex min-h-16 items-center gap-3 px-4 py-3" data-paired-device={device.id}><span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary"><Smartphone size={18} strokeWidth={1.75} aria-hidden="true" /></span><span className="flex min-w-0 flex-1 flex-col gap-0.5">- <span className="truncate text-[14px] leading-5 text-ink">{device.label}</span>+ <span className="truncate text-[14px] leading-5 text-ink">{device.person ?? device.label}</span><span className="truncate text-[13px] leading-[18px] text-ink-secondary">- {[device.email, cloudHome ? null : scopeName(device), t("remote.serverPairing.seen", { when: lastSeen(device.lastSeenAt, now) }), device.id === current ? t("remote.serverPairing.thisBrowser") : null].filter(Boolean).join(" · ")}+ {[device.person ? device.label : null, device.email === device.person ? null : device.email, cloudHome ? null : scopeName(device), t("remote.serverPairing.seen", { when: lastSeen(device.lastSeenAt, now) }), device.id === current ? t("remote.serverPairing.thisBrowser") : null].filter(Boolean).join(" · ")}</span></span>{device.id === current ? null : (