{"draft":null,"from":263,"to":318,"files":[{"path":"client/src/api.ts","added":46,"removed":2,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -4,6 +4,7 @@\n \n import { randomUUID } from \"node:crypto\";\n import { setDefaultResultOrder } from \"node:dns\";\n+import { CALLER_HEADER } from \"../../src/caller.ts\";\n import type {\n \tChangeAnswer,\n \tDraftSyncAnswer,\n@@ -19,6 +20,7 @@\n \tSyncAnswer,\n } from \"./api-answers.ts\";\n import { ApiError, errorSentence, neverSent } from \"./api-error.ts\";\n+import { UsageError } from \"./args.ts\";\n import type { AutosettleAnswer, AutosettleMode } from \"./autosettle-commands.ts\";\n import {\n \tboxQuery,\n@@ -67,6 +69,7 @@\n \tIssueRow,\n \tIssueSearchHit,\n } from \"./issues-wire.ts\";\n+import { isLocal, LOCAL_BASE, localFetch, NO_STORE } from \"./local-store.ts\";\n import type { Modes } from \"./modes.ts\";\n \n export * from \"./api-answers.ts\";\n@@ -141,6 +144,23 @@\n \t| { dryRun: true; plan: CopyPlan }\n \t| { ok: true; id: number; from: { project: string; issue: number }; skipped: { comments: number[]; asks: number[] } };\n \n+/**\n+ * The server's line when another chat just used this seat (seatNotice on an answer): kept until main() prints it with\n+ * the news, once however many answers carried it.\n+ */\n+const seatNotices = new Set<string>();\n+function noteSeat(answer: unknown): void {\n+\tif (typeof answer !== \"object\" || answer === null || Array.isArray(answer)) return;\n+\tconst line = (answer as { seatNotice?: unknown }).seatNotice;\n+\tif (typeof line === \"string\" && line !== \"\" && line.length <= 300 && !/[\\u0000-\\u001f]/.test(line))\n+\t\tseatNotices.add(line);\n+}\n+export function takeSeatNotices(): string[] {\n+\tconst out = [...seatNotices];\n+\tseatNotices.clear();\n+\treturn out;\n+}\n+\n export class Api {\n \treadonly config: Config;\n \treadonly timeoutMs: number;\n@@ -169,10 +189,17 @@\n \t/** The Issues Worker (#54) this folder's issues calls go to; set by the issues commands (issues.ts). */\n \tissuesServer: string | undefined;\n \n+\t/** Who is calling this seat (src/caller.ts): this chat's session, this computer and this folder. Set by open(). */\n+\tcaller: string | undefined;\n+\n \turl(path: string, server = this.config.server): string {\n-\t\treturn `${server.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(this.config.project)}${path}`;\n+\t\tconst base = isLocal(server) ? LOCAL_BASE : server;\n+\t\treturn `${base.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(this.config.project)}${path}`;\n \t}\n \n+\t/** A local project's calls: answered in this process (local-store.ts). */\n+\tprivate local: ((input: string, init?: RequestInit) => Promise<Response>) | undefined;\n+\n \tagentPath(action: string): string {\n \t\treturn `/a/${encodeURIComponent(this.config.agent)}/${action}`;\n \t}\n@@ -182,6 +209,8 @@\n \t\t\t// Which client made the call (#29); the mods send theirs too.\n \t\t\t\"x-abso-client\": `abso-cli/${clientVersion()}`,\n \t\t\t...(this.config.token && !this.config.visitor ? { authorization: `Bearer ${this.config.token}` } : {}),\n+\t\t\t// A visitor says nothing about where it's reading from.\n+\t\t\t...(this.caller !== undefined && !this.config.visitor ? { [CALLER_HEADER]: this.caller } : {}),\n \t\t\t...(contentType ? { \"content-type\": contentType } : {}),\n \t\t};\n \t}\n@@ -191,6 +220,12 @@\n \t * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).\n \t */\n \tsend(url: string, init: RequestInit = {}): Promise<Response> {\n+\t\tif (isLocal(this.config.server)) {\n+\t\t\tconst dir = this.config.localStore;\n+\t\t\tif (dir === undefined) return Promise.reject(new UsageError(NO_STORE));\n+\t\t\tthis.local ??= localFetch(dir);\n+\t\t\treturn this.local(url, init);\n+\t\t}\n \t\tif (!this.config.visitor) return fetch(url, init);\n \t\tif ((init.method ?? \"GET\") !== \"GET\")\n \t\t\treturn Promise.reject(new ApiError(\"a folder that reads signed out sends only reads\"));\n@@ -225,6 +260,8 @@\n \t\t\t\t\tsignal: AbortSignal.timeout(timeoutMs),\n \t\t\t\t});\n \t\t\t} catch (err) {\n+\t\t\t\t// A local project's refusal (no store, a Node without SQLite) says itself.\n+\t\t\t\tif (err instanceof UsageError) throw err;\n \t\t\t\tconst e = err as Error;\n \t\t\t\tconst why =\n \t\t\t\t\te.name === \"TimeoutError\"\n@@ -258,7 +295,9 @@\n \t\t\t\tres.status,\n \t\t\t);\n \t\ttry {\n-\t\t\treturn JSON.parse(text) as T;\n+\t\t\tconst parsed = JSON.parse(text) as T;\n+\t\t\tnoteSeat(parsed);\n+\t\t\treturn parsed;\n \t\t} catch {\n \t\t\tthrow new ApiError(\n \t\t\t\t`${method} ${path} answered with something that isn't JSON: ${text.slice(0, 300)}`,\n@@ -977,6 +1016,11 @@\n \t\treturn this.json(\"POST\", this.agentPath(\"news\"), {});\n \t}\n \n+\t/** A ticket that opens this agent's news stream once, within a minute (abso 690; news-stream.ts). */\n+\tnewsTicket(): Promise<{ url: string; protocols: string[]; expiresAt: number | string }> {\n+\t\treturn this.json(\"POST\", this.agentPath(\"news/ticket\"), {});\n+\t}\n+\n \t/** This agent's unpublished changes, file by file. */\n \tdiff(): Promise<DiffAnswer> {\n \t\treturn this.json(\"POST\", this.agentPath(\"diff\"), {});"}],"unmatched":[]}