@ractive-ch/tab-mcp-client 0.1.0-alpha.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/registry.ts", "../../src/secret.ts", "../../src/version.ts", "../../src/tab-mcp.ts"],
3
+ "sources": ["../../src/always-allowed.ts", "../../src/registry.ts", "../../src/secret.ts", "../../src/version.ts", "../../src/tab-mcp.ts"],
4
4
  "sourcesContent": [
5
+ "/**\n * The tools a user chose \"Always allow\" for, per grant (AI app). Kept in\n * memory for the page's lifetime; an entry goes when its grant goes or its\n * tool is unregistered, so a re-paired app or a new tool under the same name\n * is asked again.\n */\nexport class AlwaysAllowed {\n\treadonly #tools = new Map<string, Set<string>>();\n\n\thas(grantId: string, tool: string): boolean {\n\t\treturn this.#tools.get(grantId)?.has(tool) === true;\n\t}\n\n\tadd(grantId: string, tool: string): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Set();\n\t\ttools.add(tool);\n\t\tthis.#tools.set(grantId, tools);\n\t}\n\n\t/** Forget every grant not in `grantIds`. */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tfor (const grantId of this.#tools.keys()) {\n\t\t\tif (!keep.has(grantId)) this.#tools.delete(grantId);\n\t\t}\n\t}\n\n\t/** Forget every tool not in `names`. */\n\tkeepTools(names: Iterable<string>): void {\n\t\tconst keep = new Set(names);\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools) if (!keep.has(tool)) tools.delete(tool);\n\t\t}\n\t}\n}\n",
5
6
  "/**\n * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`\n * (DEC-010). Part of the eagerly loaded core.\n */\n\nimport type {\n\tJsonSchema,\n\tRegisterToolOptions,\n\tTool,\n\tToolAnnotations,\n} from \"./types.ts\";\n\nconst NAME = /^[A-Za-z0-9_.-]{1,128}$/;\n\n/** A validated tool as the registry keeps it. */\nexport interface RegisteredTool {\n\treadonly name: string;\n\treadonly title: string | undefined;\n\treadonly description: string;\n\treadonly inputSchema: JsonSchema;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** `x-mcp-header` makes the relay validate headers it does not know; not supported in v1. */\nfunction usesMcpHeader(schema: unknown, depth = 0): boolean {\n\tif (depth > 64 || typeof schema !== \"object\" || schema === null) return false;\n\tif (!Array.isArray(schema) && \"x-mcp-header\" in schema) return true;\n\treturn Object.values(schema).some((v) => usesMcpHeader(v, depth + 1));\n}\n\n/** A JSON pointer (`/a/b~1c`) inside `root`, or `undefined`. */\nfunction resolvePointer(root: unknown, pointer: string): unknown {\n\tlet node: unknown = root;\n\tfor (const raw of pointer.split(\"/\").slice(1)) {\n\t\tconst key = decodeURIComponent(raw)\n\t\t\t.replaceAll(\"~1\", \"/\")\n\t\t\t.replaceAll(\"~0\", \"~\");\n\t\tif (typeof node !== \"object\" || node === null || !Object.hasOwn(node, key))\n\t\t\treturn undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node;\n}\n\n/**\n * What the validator (loaded only on `connect()`) would throw on later, found\n * now so that a bad schema fails registration: patterns that are not\n * regular expressions, and `$ref`s that do not resolve inside the schema.\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tif (this.#tools.get(registered.name) === registered) {\n\t\t\t\t\tthis.#tools.delete(registered.name);\n\t\t\t\t\tthis.#changed();\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
6
7
  "/**\n * The address secret (DEC-027): 32 random bytes as base64url without padding,\n * kept in `localStorage`. The relay derives the stable address from it.\n */\n\nimport type { SecretStorage } from \"./types.ts\";\n\nconst SECRET = /^[A-Za-z0-9_-]{43}$/;\n/** base64url without padding. */\nexport function base64url(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nexport function newSecret(): string {\n\treturn base64url(crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport function isSecret(value: unknown): value is string {\n\treturn typeof value === \"string\" && SECRET.test(value);\n}\n\n/** `localStorage`, or `null` where it is missing or blocked. */\nfunction defaultStorage(): SecretStorage | null {\n\ttry {\n\t\tconst storage = (globalThis as { localStorage?: SecretStorage })\n\t\t\t.localStorage;\n\t\treturn storage ?? null;\n\t} catch {\n\t\treturn null; // SecurityError: storage blocked for this page\n\t}\n}\n\n/** Reads, creates and rotates the secret; falls back to memory without storage. */\nexport class SecretStore {\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t#memory: string | undefined;\n\n\tconstructor(storage: SecretStorage | null | undefined, key: string) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t}\n\n\t/** The current secret; storage first, so a rotation in another tab is seen. */\n\tget(): string {\n\t\tlet stored: string | null = null;\n\t\ttry {\n\t\t\tstored = this.#storage?.getItem(this.#key) ?? null;\n\t\t} catch {\n\t\t\t// unreadable: use a page-lifetime secret\n\t\t}\n\t\tif (isSecret(stored)) {\n\t\t\tthis.#memory = stored;\n\t\t\treturn stored;\n\t\t}\n\t\treturn this.#memory ?? this.rotate();\n\t}\n\n\t/** Make and keep a new secret (a new address). */\n\trotate(): string {\n\t\tconst secret = newSecret();\n\t\tthis.#memory = secret;\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t\treturn secret;\n\t}\n}\n",
7
- "/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.1.0-alpha.1\";\n",
8
- "/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tPairingCode,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (\n\t\t\tappName !== undefined &&\n\t\t\t(typeof appName !== \"string\" || appName.length > 64)\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be a string of at most 64 characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\n\t\tthis.#registry.onChange(() =>\n\t\t\tthis.#emit(\"toolschange\", { tools: this.tools }),\n\t\t);\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * Never reconnects by itself.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI tool\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmDialog(\n\t\t\t\trequest,\n\t\t\t\tdoc,\n\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t),\n\t\t);\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\n\t\t};\n\t}\n}\n"
8
+ "/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.2.0\";\n",
9
+ "/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tPairingCode,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * Never reconnects by itself.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\n\t\t};\n\t}\n}\n"
9
10
  ],
10
- "mappings": ";AAYA,IAAM,EAAO,0BAYb,SAAS,CAAa,CAAC,EAA0C,CAChE,OAAO,OAAO,IAAM,UAAY,IAAM,MAAQ,CAAC,MAAM,QAAQ,CAAC,EAI/D,SAAS,CAAa,CAAC,EAAiB,EAAQ,EAAY,CAC3D,GAAI,EAAQ,IAAM,OAAO,IAAW,UAAY,IAAW,KAAM,MAAO,GACxE,GAAI,CAAC,MAAM,QAAQ,CAAM,GAAK,iBAAkB,EAAQ,MAAO,GAC/D,OAAO,OAAO,OAAO,CAAM,EAAE,KAAK,CAAC,IAAM,EAAc,EAAG,EAAQ,CAAC,CAAC,EAIrE,SAAS,CAAc,CAAC,EAAe,EAA0B,CAChE,IAAI,EAAgB,EACpB,QAAW,KAAO,EAAQ,MAAM,GAAG,EAAE,MAAM,CAAC,EAAG,CAC9C,IAAM,EAAM,mBAAmB,CAAG,EAChC,WAAW,KAAM,GAAG,EACpB,WAAW,KAAM,GAAG,EACtB,GAAI,OAAO,IAAS,UAAY,IAAS,MAAQ,CAAC,OAAO,OAAO,EAAM,CAAG,EACxE,OACD,EAAQ,EAAiC,GAE1C,OAAO,EAQR,SAAS,CAAa,CAAC,EAAmC,CACzD,IAAM,EAAU,IAAI,IACd,EAAiB,CAAC,EAClB,EAAqB,CAAC,EACtB,EAAO,CAAC,EAAe,IAAwB,CACpD,GAAI,EAAQ,IAAM,OAAO,IAAS,UAAY,IAAS,KAAM,OAC7D,GAAI,CAAC,MAAM,QAAQ,CAAI,EAAG,CACzB,IAAM,EAAI,EACV,GAAI,OAAO,EAAE,UAAe,SAAU,EAAQ,IAAI,EAAE,OAAU,EAC9D,GAAI,OAAO,EAAE,OAAY,SAAU,EAAK,KAA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YAAa,CAAC,IAAS,CACtB,GAAI,EAAQ,GAAK,KAAK,GAAU,KAAK,GAAgB,CAAI,GAE1D,WAAY,CAAC,IAAU,CACtB,GAAI,CAAC,EAAQ,EAAG,OAChB,KAAK,GAAW,CACf,GAAG,KAAK,GAAQ,OAAO,CAAC,IAAM,EAAE,UAAY,EAAM,OAAO,EACzD,CACD,CAAC,GAEF,aAAc,CAAC,IAAY,CAC1B,GAAI,CAAC,EAAQ,EAAG,OAChB,KAAK,GAAW,KAAK,GAAQ,OAAO,CAAC,IAAM,EAAE,UAAY,CAAO,CAAC,GAElE,SAAU,IAAM,CACf,GAAI,EAAQ,EAAG,KAAK,GAAM,WAAY,IAAI,GAE3C,MAAO,CAAC,IAAU,CACjB,GAAI,EAAQ,EAAG,KAAK,GAAM,QAAS,CAAE,OAAM,CAAC,GAE7C,OAAQ,CAAC,EAA0B,IAAiB,CACnD,GAAI,CAAC,EAAQ,EAAG,OAChB,KAAK,GAAc,OACnB,KAAK,GAAW,OAChB,KAAK,GAAgB,MAAS,EAC9B,KAAK,GAAU,cAAc,EAC7B,KAAK,GAAM,eAAgB,CAAE,SAAQ,MAAK,CAAC,EAE7C,EAEF",
12
+ "debugId": "12206338B775070064756E2164756E21",
12
13
  "names": []
13
14
  }
@@ -0,0 +1,4 @@
1
+ var M=0;function s(e,o,t={},...i){let a=e.createElement(o);if(t.className!==void 0)a.className=t.className;if(t.id!==void 0)a.id=t.id;if(t.text!==void 0)a.textContent=t.text;return a.append(...i),a}function m(e,o,t){let i=s(e,"button",{text:o});return i.type="button",i.addEventListener("click",t),i}function B(e,o,t){let i=`tab-mcp-${++M}`,a=s(e,"dialog",{className:`tab-mcp-dialog ${o}`});a.setAttribute("aria-labelledby",`${i}-title`);let r=a.style;r.setProperty("max-width","var(--tab-mcp-max-width, 34rem)"),r.setProperty("font","var(--tab-mcp-font, inherit)"),r.setProperty("color","var(--tab-mcp-color, CanvasText)"),r.setProperty("background","var(--tab-mcp-background, Canvas)"),r.setProperty("border","var(--tab-mcp-border, 1px solid GrayText)"),r.setProperty("border-radius","var(--tab-mcp-radius, 0.5rem)"),r.setProperty("padding","var(--tab-mcp-padding, 1rem 1.25rem)");let p=s(e,"h2",{id:`${i}-title`,text:t});return p.style.setProperty("margin-top","0"),p.style.setProperty("font-size","var(--tab-mcp-title-size, 1.25em)"),a.append(p),{dialog:a,heading:p}}function x(e){let o=e.host||e.id;return e.name!==void 0&&e.name!==""?`${e.name} (${o})`:o}function V(e){try{return JSON.stringify(e,null,2)}catch{return}}var Y=750,F=500;function U(e,o,t={}){let i=Math.max(F,t.allowDelayMs??Y);if(e.signal.aborted)return Promise.resolve("deny");let a=e.tool.title??e.tool.name,{dialog:r}=B(o,"tab-mcp-confirm",`Allow ${a}?`),p=m(o,"Don't allow",()=>r.close("deny")),d=m(o,"Allow",()=>{if(!d.disabled)r.close("allow")}),u=m(o,"Always allow",()=>{if(!u.disabled)r.close("always")});d.disabled=!0,u.disabled=!0;let h=s(o,"div",{className:"tab-mcp-actions"},p," ",d," ",u),b=s(o,"p",{className:"tab-mcp-always-note",text:`Always allow: ${a} runs without asking for ${x(e.client)} until you reload this page or disconnect it.`}),w=V(e.arguments),g=s(o,"pre",{className:"tab-mcp-arguments",text:w??"The arguments cannot be shown, so this call cannot be allowed."});if(w===void 0)d.hidden=!0,u.hidden=!0,b.hidden=!0;return g.style.setProperty("white-space","pre-wrap"),g.style.setProperty("max-height","12rem"),g.style.setProperty("overflow","auto"),g.hidden=Object.keys(e.arguments).length===0,r.append(s(o,"p",{text:`${x(e.client)} wants to run ${a}.`}),s(o,"p",{className:"tab-mcp-description",text:e.tool.description}),g,h,b),o.body.append(r),new Promise((N)=>{let v=()=>r.close("deny");e.signal.addEventListener("abort",v,{once:!0});let l;r.addEventListener("close",()=>{clearTimeout(l),e.signal.removeEventListener("abort",v);let f=r.returnValue;r.remove(),N(f==="allow"||f==="always"?f:"deny")},{once:!0}),r.showModal(),p.focus(),l=setTimeout(()=>{d.disabled=!1,u.disabled=!1},i)})}var J=[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."],["Claude Code","Run: claude mcp add --transport http tools ADDRESS"]];function Q(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function X(e,o,t){let{dialog:i}=B(t,"tab-mcp-connect","Connect your AI app"),a=s(t,"p",{className:"tab-mcp-status",text:"Connecting…"});a.setAttribute("role","status");let r=`tab-mcp-${++M}-address`,p=s(t,"label",{text:"Add this address to your AI app:"});p.htmlFor=r;let d=s(t,"input",{id:r,className:"tab-mcp-address-input"});d.readOnly=!0,d.style.setProperty("width","100%"),d.style.setProperty("font-family","var(--tab-mcp-mono, monospace)");let u=m(t,"Copy",()=>{let n=()=>{u.textContent="Copied"},c=t.defaultView?.navigator?.clipboard;if(c!==void 0)c.writeText(d.value).then(n,()=>d.select());else d.select()}),h=m(t,"New address",()=>W());h.className="tab-mcp-new-address";let b=s(t,"div",{className:"tab-mcp-address"},p,d," ",u," ",h),w=`tab-mcp-${++M}-new-address`,g=s(t,"p",{id:w}),N=m(t,"Cancel",()=>{l.hidden=!0,h.focus()}),v=m(t,"Disconnect and get new address",()=>O());v.className="tab-mcp-new-address-confirm";let l=s(t,"div",{className:"tab-mcp-new-address-question"},g,s(t,"div",{className:"tab-mcp-actions"},N," ",v));l.setAttribute("role","group"),l.setAttribute("aria-labelledby",w),l.hidden=!0;let f=s(t,"strong",{className:"tab-mcp-code-value"});f.style.setProperty("font-size","var(--tab-mcp-code-size, 1.5em)"),f.style.setProperty("letter-spacing","0.1em");let A=s(t,"p",{className:"tab-mcp-code"},"When asked, enter the code ",f,s(t,"br"),s(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."}));A.setAttribute("aria-live","polite");let k=s(t,"ul"),L=s(t,"details",{className:"tab-mcp-help"},s(t,"summary",{text:"How do I add it?"}),k),R=s(t,"ul"),T=s(t,"div",{className:"tab-mcp-apps"},s(t,"h3",{text:"Connected"}),R),C=m(t,"Close",()=>i.close()),K=s(t,"div",{className:"tab-mcp-actions"},C);i.append(a,b,l,A,L,T,K),b.hidden=!0,A.hidden=!0,L.hidden=!0,T.hidden=!0;let D=!1,H=()=>{let n=e.grants.map((c)=>x(c.client));if(n.length===0)return!1;return g.textContent=`A new address disconnects ${Q(n)}. To use this page again, add the new address to ${n.length===1?"it":"them"}.`,!0},W=()=>{if(e.state!=="connected")return;if(!H()){O();return}l.hidden=!1,N.focus()},O=()=>{C.focus(),l.hidden=!0,D=!0,a.textContent="Getting a new address…",e.newAddress().then(()=>{D=!1,a.textContent="This is a new address. Add it to your AI app again.",C.focus()},(n)=>{D=!1,a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}. Close this and connect again.`,C.focus()})},E=(n)=>{if(n===void 0){b.hidden=!0,l.hidden=!0,L.hidden=!0;return}d.value=n.address,u.textContent="Copy";let c=n.appName??e.appName;if(!D)a.textContent=c!==void 0?`${c} is ready for your AI app.`:"This page is ready for your AI app.";h.disabled=e.state!=="connected",b.hidden=!1,L.hidden=!1,k.replaceChildren(...J.map(([I,j])=>s(t,"li",{},s(t,"strong",{text:I}),`: ${j.replace("ADDRESS",n.address)}`)))},P=()=>{let n=e.pairingCode;f.textContent=n?.code??"",A.hidden=n===void 0},S=s(t,"p",{className:"tab-mcp-apps-note"});T.append(S);let G=new Set(e.grants.map((n)=>n.grantId)),y=()=>{for(let c of e.grants){if(G.has(c.grantId))continue;G.add(c.grantId),a.textContent=`${x(c.client)} is connected.`}let n=e.state==="connected";if(R.replaceChildren(...e.grants.map((c)=>{let I=m(t,"Disconnect",()=>{if(!e.revoke(c.grantId))y()});return I.disabled=!n,s(t,"li",{},`${x(c.client)} connected `,I)})),S.textContent=n?"":"To disconnect an app, connect this page again first.",S.hidden=n,T.hidden=e.grants.length===0,!l.hidden&&!H())l.hidden=!0,h.focus()},_=(n)=>{if(n.detail.reason!=="new_address")a.textContent="Disconnected. AI apps can use this page again after you connect.";E(void 0),y(),P()},z=()=>{E(e.session),y()};return e.addEventListener("pairingcode",P),e.addEventListener("grantschange",y),e.addEventListener("connected",z),e.addEventListener("disconnected",_),t.body.append(i),e.startPairing(),y(),P(),E(e.session),o.then((n)=>E(n),(n)=>{a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}`}),new Promise((n)=>{i.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",P),e.removeEventListener("grantschange",y),e.removeEventListener("connected",z),e.removeEventListener("disconnected",_),i.remove(),n()},{once:!0}),i.showModal(),C.focus()})}export{U as confirmDialog,X as showConnectDialog};
2
+
3
+ //# debugId=B932565F1A8EDC6A64756E2164756E21
4
+ //# sourceMappingURL=ui-zmrhb8xg.min.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ui.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn JSON.stringify(args, null, 2);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/**\n * Ask whether a consequential tool may run. \"Allow\" and \"Always allow\" stay\n * disabled for `allowDelayMs` (default 750, at least 500) after the dialog\n * opens, so a click meant for the page cannot approve. Everything else\n * (Don't allow, Escape, an aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tconst always = button(doc, \"Always allow\", () => {\n\t\tif (!always.disabled) dialog.close(\"always\");\n\t});\n\tallow.disabled = true;\n\talways.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t\t\" \",\n\t\talways,\n\t);\n\tconst alwaysNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-always-note\",\n\t\ttext: `Always allow: ${title} runs without asking for ${clientLabel(request.client)} until you reload this page or disconnect it.`,\n\t});\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tallow.hidden = true;\n\t\talways.hidden = true;\n\t\talwaysNote.hidden = true;\n\t}\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\n\t\t}),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\talwaysNote,\n\t);\n\tdoc.body.append(dialog);\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t\talways.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code while the relay sends one, and the\n * connected apps with Disconnect. Pairing is on while it is open. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\n\t});\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\tcodeLine.setAttribute(\"aria-live\", \"polite\");\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tclose.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tclose.focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tcopy.textContent = \"Copy\";\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\tconst renderGrants = () => {\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n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ontextprotocol/serverInfo";
83
83
  var META_SUBSCRIPTION = "io.modelcontextprotocol/subscriptionId";
84
84
  var HEADER_MISMATCH = -32020;
85
85
  var UNSUPPORTED_VERSION = -32022;
86
+ var lastCallId = 0;
87
+ function copy(value) {
88
+ try {
89
+ return structuredClone(value);
90
+ } catch {
91
+ return value;
92
+ }
93
+ }
86
94
  var encoder = new TextEncoder;
87
95
  function isObject(v) {
88
96
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -207,10 +215,32 @@ function createMcpHandler(options) {
207
215
  const raw = params["arguments"] ?? {};
208
216
  if (!isObject(raw))
209
217
  return { invalid: "Invalid params: arguments must be an object" };
218
+ const client = options.client(grant);
219
+ const call = {
220
+ id: ++lastCallId,
221
+ tool: tool.name,
222
+ arguments: copy(raw),
223
+ client: { ...client }
224
+ };
225
+ if (tool.title !== undefined)
226
+ call.title = tool.title;
227
+ const started = Date.now();
228
+ options.observe?.start(call);
229
+ const [outcome, res] = await decideAndRun(tool, raw, signal, client);
230
+ options.observe?.end({
231
+ id: call.id,
232
+ tool: tool.name,
233
+ client: { ...client },
234
+ outcome,
235
+ result: copy(res),
236
+ durationMs: Date.now() - started
237
+ });
238
+ return res;
239
+ }
240
+ async function decideAndRun(tool, raw, signal, client) {
210
241
  const invalid = validate(tool, raw);
211
242
  if (invalid !== undefined)
212
- return errorResult(invalid);
213
- const client = options.client(grant);
243
+ return ["error", errorResult(invalid)];
214
244
  if (tool.annotations.consequentialHint === true) {
215
245
  const question = {
216
246
  tool: { name: tool.name, description: tool.description },
@@ -227,15 +257,22 @@ function createMcpHandler(options) {
227
257
  allowed = false;
228
258
  }
229
259
  if (!allowed)
230
- return errorResult("The user declined");
260
+ return [
261
+ signal.aborted ? "cancelled" : "declined",
262
+ errorResult("The user declined")
263
+ ];
231
264
  }
232
265
  if (signal.aborted)
233
- return errorResult("Cancelled");
266
+ return ["cancelled", errorResult("Cancelled")];
267
+ let res;
234
268
  try {
235
- return toCallToolResult(await tool.execute(raw, { signal, client }));
269
+ res = toCallToolResult(await tool.execute(raw, { signal, client }));
236
270
  } catch (error) {
237
- return thrownResult(error);
271
+ res = thrownResult(error);
238
272
  }
273
+ if (signal.aborted)
274
+ return ["cancelled", res];
275
+ return [res.isError === true ? "error" : "ok", res];
239
276
  }
240
277
  function callTool(id, params, signal, grant) {
241
278
  const stream = new ReadableStream({
@@ -622,7 +659,11 @@ function openConnection(host, url, secret) {
622
659
  tools: host.registry,
623
660
  server: host.server,
624
661
  confirm: (request) => host.confirm(request),
625
- client: (grant) => host.clientFor(grant)
662
+ client: (grant) => host.clientFor(grant),
663
+ observe: {
664
+ start: (call) => host.toolCallStarted(call),
665
+ end: (call) => host.toolCallEnded(call)
666
+ }
626
667
  });
627
668
  const stopWatching = host.registry.onChange(() => handler.toolsChanged());
628
669
  function send(message) {
@@ -896,5 +937,5 @@ export {
896
937
  openConnection
897
938
  };
898
939
 
899
- //# debugId=A284BD4DD9FAEEA364756E2164756E21
900
- //# sourceMappingURL=connection-1gf7vqz2.js.map
940
+ //# debugId=26D08B19889F01DB64756E2164756E21
941
+ //# sourceMappingURL=connection-ag7eyd36.js.map
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/mcp.ts", "../src/mapping.ts", "../src/protocol.ts", "../src/connection.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The tab's MCP server: the stateless 2026-07-28 subset tab-mcp needs\n * (DEC-049), written for the page instead of bundling the SDK. It answers\n * `server/discover`, `tools/list`, `tools/call` (as SSE, DEC-020) and\n * `subscriptions/listen`, and applies the request checks of the 2026-07-28\n * Streamable HTTP transport (content type, JSON-RPC shape, `_meta` envelope,\n * `MCP-Protocol-Version` / `Mcp-Method` / `Mcp-Name`). Status codes and error\n * codes follow the MCP TypeScript SDK's `createMcpHandler`; the conformance\n * tests compare the two.\n */\n\nimport { Validator } from \"@cfworker/json-schema\";\nimport {\n\tANNOTATIONS_META_KEY,\n\ttype CallToolResult,\n\terrorResult,\n\tmapAnnotations,\n\tthrownResult,\n\ttoCallToolResult,\n} from \"./mapping.ts\";\nimport type { GrantRef } from \"./protocol.ts\";\nimport type { RegisteredTool } from \"./registry.ts\";\nimport type {\n\tConfirmRequest,\n\tServerInfo,\n\tToolCallClient,\n\tToolCallEnd,\n\tToolCallOutcome,\n\tToolCallStart,\n} from \"./types.ts\";\n\nexport const MCP_PROTOCOL_VERSION = \"2026-07-28\";\nconst META_VERSION = \"io.modelcontextprotocol/protocolVersion\";\nconst META_CAPABILITIES = \"io.modelcontextprotocol/clientCapabilities\";\nconst META_CLIENT_INFO = \"io.modelcontextprotocol/clientInfo\";\nconst META_SERVER_INFO = \"io.modelcontextprotocol/serverInfo\";\nconst META_SUBSCRIPTION = \"io.modelcontextprotocol/subscriptionId\";\n\nconst HEADER_MISMATCH = -32020;\nconst UNSUPPORTED_VERSION = -32022;\n\ntype Id = string | number;\ntype Json = Record<string, unknown>;\n\nexport interface ToolSource {\n\tlist(): RegisteredTool[];\n\tget(name: string): RegisteredTool | undefined;\n}\n\nexport interface McpHandlerOptions {\n\ttools: ToolSource;\n\tserver: ServerInfo;\n\t/** Ask the user before a consequential tool runs. */\n\tconfirm(request: ConfirmRequest): Promise<boolean>;\n\t/** The caller of a request, from its grant. */\n\tclient(grant: GrantRef): ToolCallClient;\n\t/** Told about every call of a known tool, as it starts and as it ends. */\n\tobserve?: {\n\t\tstart(call: ToolCallStart): void;\n\t\tend(call: ToolCallEnd): void;\n\t};\n}\n\n/** Tool call ids, unique in the page. */\nlet lastCallId = 0;\n\n/** A deep copy for an event; the value itself when it cannot be cloned. */\nfunction copy<T>(value: T): T {\n\ttry {\n\t\treturn structuredClone(value);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\nexport interface McpRequestContext {\n\tgrant: GrantRef;\n\t/** The body as text when the caller already has it. */\n\tbody?: string;\n}\n\nexport interface McpHandler {\n\thandle(request: Request, context: McpRequestContext): Promise<Response>;\n\t/** The tool list changed: tell the listen streams. */\n\ttoolsChanged(): void;\n\t/** End every listen stream (the session is over). */\n\tclose(): void;\n}\n\nconst encoder = new TextEncoder();\n\nfunction isObject(v: unknown): v is Json {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\nfunction json(status: number, value: unknown): Response {\n\treturn new Response(JSON.stringify(value), {\n\t\tstatus,\n\t\theaders: { \"content-type\": \"application/json\" },\n\t});\n}\n\nfunction rpcError(\n\tstatus: number,\n\tid: Id | null,\n\tcode: number,\n\tmessage: string,\n\tdata?: unknown,\n): Response {\n\tconst error: Json = { code, message };\n\tif (data !== undefined) error[\"data\"] = data;\n\treturn json(status, { jsonrpc: \"2.0\", id, error });\n}\n\nfunction mismatch(id: Id | null, header: string, body: string): Response {\n\treturn rpcError(\n\t\t400,\n\t\tid,\n\t\tHEADER_MISMATCH,\n\t\t`Bad Request: the request headers and body disagree: ${body}`,\n\t\t{\n\t\t\tmismatch: { header, body },\n\t\t},\n\t);\n}\n\nfunction sseEvent(message: unknown): Uint8Array {\n\treturn encoder.encode(`event: message\\ndata: ${JSON.stringify(message)}\\n\\n`);\n}\n\nconst SSE_HEADERS = {\n\t\"content-type\": \"text/event-stream\",\n\t\"cache-control\": \"no-cache\",\n};\n\n/** `application/json`, with or without parameters. */\nfunction isJsonContentType(value: string | null): boolean {\n\treturn (\n\t\t(value ?? \"\").split(\";\")[0]?.trim().toLowerCase() === \"application/json\"\n\t);\n}\n\n/** Decode the `=?base64?…?=` sentinel of SEP-2243 headers; `undefined` if malformed. */\nexport function decodeHeaderValue(value: string): string | undefined {\n\tif (!(value.startsWith(\"=?base64?\") && value.endsWith(\"?=\"))) return value;\n\tconst b64 = value.slice(9, -2);\n\tif (\n\t\t!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(\n\t\t\tb64,\n\t\t)\n\t)\n\t\treturn undefined;\n\ttry {\n\t\tconst bin = atob(b64);\n\t\tconst bytes = Uint8Array.from(bin, (c) => c.charCodeAt(0));\n\t\treturn new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The first problem of a 2026-07-28 `_meta` envelope, or `undefined`. */\nfunction envelopeIssue(\n\tmeta: Json,\n): { key: string; problem: string } | undefined {\n\tif (!(META_VERSION in meta)) return { key: META_VERSION, problem: \"missing\" };\n\tif (!(META_CAPABILITIES in meta))\n\t\treturn { key: META_CAPABILITIES, problem: \"missing\" };\n\tif (typeof meta[META_VERSION] !== \"string\") {\n\t\treturn { key: META_VERSION, problem: \"expected a protocol version string\" };\n\t}\n\tif (!isObject(meta[META_CAPABILITIES]))\n\t\treturn { key: META_CAPABILITIES, problem: \"expected an object\" };\n\tconst info = meta[META_CLIENT_INFO];\n\tif (\n\t\tinfo !== undefined &&\n\t\t!(\n\t\t\tisObject(info) &&\n\t\t\ttypeof info[\"name\"] === \"string\" &&\n\t\t\ttypeof info[\"version\"] === \"string\"\n\t\t)\n\t) {\n\t\treturn { key: META_CLIENT_INFO, problem: \"expected {name, version}\" };\n\t}\n\treturn undefined;\n}\n\n/** Listen streams honour only the tool list (the tab has nothing else). */\nfunction honoured(params: Json): Json {\n\tconst requested = params[\"notifications\"];\n\treturn isObject(requested) && requested[\"toolsListChanged\"] === true\n\t\t? { toolsListChanged: true }\n\t\t: {};\n}\n\nexport function createMcpHandler(options: McpHandlerOptions): McpHandler {\n\tconst { tools, server } = options;\n\tconst serverInfo: Json = { name: server.name, version: server.version };\n\tif (server.title !== undefined) serverInfo[\"title\"] = server.title;\n\tconst validators = new WeakMap<RegisteredTool, Validator>();\n\tconst listeners = new Set<{\n\t\tid: Id;\n\t\tsend(message: unknown): void;\n\t\tend(): void;\n\t}>();\n\tlet changeQueued = false;\n\n\tconst resultMeta = (extra: Json = {}) => ({\n\t\t...extra,\n\t\t[META_SERVER_INFO]: serverInfo,\n\t});\n\n\tfunction result(id: Id, value: Json): Json {\n\t\treturn {\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid,\n\t\t\tresult: { ...value, resultType: \"complete\", _meta: resultMeta() },\n\t\t};\n\t}\n\n\tfunction validate(tool: RegisteredTool, args: Json): string | undefined {\n\t\tlet validator = validators.get(tool);\n\t\tif (validator === undefined) {\n\t\t\tvalidator = new Validator(tool.inputSchema as never, \"2020-12\", false);\n\t\t\tvalidators.set(tool, validator);\n\t\t}\n\t\tconst outcome = validator.validate(args);\n\t\tif (outcome.valid) return undefined;\n\t\tconst detail = outcome.errors\n\t\t\t.filter((e) => e.keyword !== \"properties\" && e.keyword !== \"$ref\")\n\t\t\t.map((e) => `${e.instanceLocation} ${e.error}`)\n\t\t\t.slice(0, 5)\n\t\t\t.join(\"; \");\n\t\treturn `Input validation error: Invalid arguments for tool ${tool.name}: ${detail || \"the arguments do not match the schema\"}`;\n\t}\n\n\tfunction listTools(): Json[] {\n\t\treturn tools.list().map((tool) => {\n\t\t\tconst entry: Json = { name: tool.name };\n\t\t\tif (tool.title !== undefined) entry[\"title\"] = tool.title;\n\t\t\tentry[\"description\"] = tool.description;\n\t\t\tentry[\"inputSchema\"] = tool.inputSchema;\n\t\t\tconst { annotations, meta } = mapAnnotations(tool.annotations);\n\t\t\tif (annotations !== undefined) entry[\"annotations\"] = annotations;\n\t\t\tif (meta !== undefined) entry[\"_meta\"] = { [ANNOTATIONS_META_KEY]: meta };\n\t\t\treturn entry;\n\t\t});\n\t}\n\n\tasync function runTool(\n\t\tparams: Json,\n\t\tsignal: AbortSignal,\n\t\tgrant: GrantRef,\n\t): Promise<CallToolResult | { invalid: string }> {\n\t\tconst name = params[\"name\"];\n\t\tif (typeof name !== \"string\")\n\t\t\treturn { invalid: \"Invalid params: name must be a string\" };\n\t\tconst tool = tools.get(name);\n\t\tif (tool === undefined) return { invalid: `Tool ${name} not found` };\n\t\tconst raw = params[\"arguments\"] ?? {};\n\t\tif (!isObject(raw))\n\t\t\treturn { invalid: \"Invalid params: arguments must be an object\" };\n\t\tconst client = options.client(grant);\n\t\t// Copies: a listener cannot change what the tool gets or the AI app receives.\n\t\tconst call: ToolCallStart = {\n\t\t\tid: ++lastCallId,\n\t\t\ttool: tool.name,\n\t\t\targuments: copy(raw),\n\t\t\tclient: { ...client },\n\t\t};\n\t\tif (tool.title !== undefined) call.title = tool.title;\n\t\tconst started = Date.now();\n\t\toptions.observe?.start(call);\n\t\tconst [outcome, res] = await decideAndRun(tool, raw, signal, client);\n\t\toptions.observe?.end({\n\t\t\tid: call.id,\n\t\t\ttool: tool.name,\n\t\t\tclient: { ...client },\n\t\t\toutcome,\n\t\t\tresult: copy(res),\n\t\t\tdurationMs: Date.now() - started,\n\t\t});\n\t\treturn res;\n\t}\n\n\t/** Validate, confirm and run one call. */\n\tasync function decideAndRun(\n\t\ttool: RegisteredTool,\n\t\traw: Json,\n\t\tsignal: AbortSignal,\n\t\tclient: ToolCallClient,\n\t): Promise<[ToolCallOutcome, CallToolResult]> {\n\t\tconst invalid = validate(tool, raw);\n\t\tif (invalid !== undefined) return [\"error\", errorResult(invalid)];\n\t\tif (tool.annotations.consequentialHint === true) {\n\t\t\tconst question: ConfirmRequest = {\n\t\t\t\ttool: { name: tool.name, description: tool.description },\n\t\t\t\targuments: raw,\n\t\t\t\tclient,\n\t\t\t\tsignal,\n\t\t\t};\n\t\t\tif (tool.title !== undefined) question.tool.title = tool.title;\n\t\t\tlet allowed = false;\n\t\t\ttry {\n\t\t\t\tallowed = await options.confirm(question);\n\t\t\t} catch {\n\t\t\t\tallowed = false;\n\t\t\t}\n\t\t\tif (!allowed)\n\t\t\t\treturn [\n\t\t\t\t\tsignal.aborted ? \"cancelled\" : \"declined\",\n\t\t\t\t\terrorResult(\"The user declined\"),\n\t\t\t\t];\n\t\t}\n\t\tif (signal.aborted) return [\"cancelled\", errorResult(\"Cancelled\")];\n\t\tlet res: CallToolResult;\n\t\ttry {\n\t\t\tres = toCallToolResult(await tool.execute(raw, { signal, client }));\n\t\t} catch (error) {\n\t\t\tres = thrownResult(error);\n\t\t}\n\t\t// Cancelled is cancelled, however the tool answered the abort.\n\t\tif (signal.aborted) return [\"cancelled\", res];\n\t\treturn [res.isError === true ? \"error\" : \"ok\", res];\n\t}\n\n\tfunction callTool(\n\t\tid: Id,\n\t\tparams: Json,\n\t\tsignal: AbortSignal,\n\t\tgrant: GrantRef,\n\t): Response {\n\t\tconst stream = new ReadableStream<Uint8Array>({\n\t\t\tstart: (controller) => {\n\t\t\t\t/** Send the one answer and end the stream, whatever happens. */\n\t\t\t\tconst finish = (message: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // nobody listens any more\n\t\t\t\t\tlet event: Uint8Array;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tevent = sseEvent(message);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// e.g. a BigInt or a cycle inside a passed-through result\n\t\t\t\t\t\tevent = sseEvent(\n\t\t\t\t\t\t\tresult(\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\terrorResult(\"The tool returned a result that is not JSON.\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcontroller.enqueue(event);\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// the stream was cancelled meanwhile\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\trunTool(params, signal, grant).then(\n\t\t\t\t\t(outcome) =>\n\t\t\t\t\t\tfinish(\n\t\t\t\t\t\t\ttypeof outcome[\"invalid\"] === \"string\"\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\terror: { code: -32602, message: outcome[\"invalid\"] },\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: result(id, outcome as CallToolResult),\n\t\t\t\t\t\t),\n\t\t\t\t\t() =>\n\t\t\t\t\t\tfinish({\n\t\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\terror: { code: -32603, message: \"Internal error\" },\n\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t\treturn new Response(stream, { status: 200, headers: SSE_HEADERS });\n\t}\n\n\tfunction listen(id: Id, params: Json, signal: AbortSignal): Response {\n\t\tconst notifications = honoured(params);\n\t\tconst finalResult = {\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid,\n\t\t\tresult: {\n\t\t\t\tresultType: \"complete\",\n\t\t\t\t_meta: resultMeta({ [META_SUBSCRIPTION]: id }),\n\t\t\t},\n\t\t};\n\t\t// This stream's own listener: two AI apps may both use the same id.\n\t\tlet own: { id: Id; send(m: unknown): void; end(): void } | undefined;\n\t\tconst stream = new ReadableStream<Uint8Array>({\n\t\t\tstart: (controller) => {\n\t\t\t\tcontroller.enqueue(\n\t\t\t\t\tsseEvent({\n\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\tmethod: \"notifications/subscriptions/acknowledged\",\n\t\t\t\t\t\tparams: { notifications, _meta: { [META_SUBSCRIPTION]: id } },\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tif (Object.keys(notifications).length === 0) {\n\t\t\t\t\tcontroller.enqueue(sseEvent(finalResult));\n\t\t\t\t\tcontroller.close();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst listener = {\n\t\t\t\t\tid,\n\t\t\t\t\tsend: (message: unknown) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tcontroller.enqueue(sseEvent(message));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tend: () => {\n\t\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tcontroller.enqueue(sseEvent(finalResult));\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// already cancelled\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\town = listener;\n\t\t\t\tlisteners.add(listener);\n\t\t\t\tsignal.addEventListener(\"abort\", () => {\n\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// already closed\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t\tcancel: () => {\n\t\t\t\tif (own !== undefined) listeners.delete(own);\n\t\t\t},\n\t\t});\n\t\treturn new Response(stream, { status: 200, headers: SSE_HEADERS });\n\t}\n\n\t/** The request checks; a `Response` when the request is refused. */\n\tfunction check(\n\t\trequest: Request,\n\t\tbody: unknown,\n\t): Response | { id: Id; method: string; params: Json } | \"notification\" {\n\t\tif (Array.isArray(body)) {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32600,\n\t\t\t\t\"Bad Request: JSON-RPC batches are not supported by this endpoint\",\n\t\t\t);\n\t\t}\n\t\tif (!isObject(body) || body[\"jsonrpc\"] !== \"2.0\") {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32600,\n\t\t\t\t\"Bad Request: the request body is not a valid JSON-RPC message\",\n\t\t\t);\n\t\t}\n\t\tconst method = body[\"method\"];\n\t\tconst rawId = body[\"id\"];\n\t\tif (typeof method !== \"string\") {\n\t\t\treturn \"result\" in body || \"error\" in body\n\t\t\t\t? rpcError(\n\t\t\t\t\t\t400,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\t-32600,\n\t\t\t\t\t\t\"Bad Request: JSON-RPC responses cannot be posted to this endpoint\",\n\t\t\t\t\t)\n\t\t\t\t: rpcError(\n\t\t\t\t\t\t400,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\t-32600,\n\t\t\t\t\t\t\"Bad Request: the request body is not a valid JSON-RPC message\",\n\t\t\t\t\t);\n\t\t}\n\t\tconst headerVersion = request.headers.get(\"mcp-protocol-version\");\n\t\tconst headerMethod = request.headers.get(\"mcp-method\");\n\t\tconst params = isObject(body[\"params\"]) ? body[\"params\"] : {};\n\t\tconst meta = isObject(params[\"_meta\"]) ? params[\"_meta\"] : undefined;\n\t\tconst claim = meta !== undefined && META_VERSION in meta;\n\t\tconst claimed =\n\t\t\ttypeof meta?.[META_VERSION] === \"string\"\n\t\t\t\t? (meta[META_VERSION] as string)\n\t\t\t\t: undefined;\n\t\tconst headerModern =\n\t\t\theaderVersion !== null && headerVersion >= MCP_PROTOCOL_VERSION;\n\n\t\tif (rawId === undefined) {\n\t\t\t// A notification: nothing to answer, but the headers must agree.\n\t\t\tif (\n\t\t\t\tclaimed !== undefined &&\n\t\t\t\theaderVersion !== null &&\n\t\t\t\theaderVersion !== claimed\n\t\t\t) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tnull,\n\t\t\t\t\theaderVersion,\n\t\t\t\t\t`the notification envelope names protocol version ${claimed} but the MCP-Protocol-Version header names ${headerVersion}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\t(claim || headerModern) &&\n\t\t\t\theaderMethod !== null &&\n\t\t\t\theaderMethod !== method\n\t\t\t) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tnull,\n\t\t\t\t\theaderMethod,\n\t\t\t\t\t`the notification body names method ${method} but the Mcp-Method header names ${headerMethod}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn \"notification\";\n\t\t}\n\t\tif (typeof rawId !== \"string\" && typeof rawId !== \"number\") {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32600,\n\t\t\t\t\"Bad Request: the request body is not a valid JSON-RPC message\",\n\t\t\t);\n\t\t}\n\t\tconst id = rawId;\n\t\tif (\n\t\t\t!claim ||\n\t\t\t(method === \"initialize\" &&\n\t\t\t\t(claimed === undefined || claimed < MCP_PROTOCOL_VERSION))\n\t\t) {\n\t\t\tif (method === \"initialize\") {\n\t\t\t\tif (headerModern) {\n\t\t\t\t\treturn mismatch(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\theaderVersion,\n\t\t\t\t\t\t\"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst requested =\n\t\t\t\t\ttypeof params[\"protocolVersion\"] === \"string\"\n\t\t\t\t\t\t? params[\"protocolVersion\"]\n\t\t\t\t\t\t: undefined;\n\t\t\t\treturn unsupported(id, requested);\n\t\t\t}\n\t\t\tif (headerModern) {\n\t\t\t\tconst missing = meta === undefined ? [\"_meta\"] : [META_VERSION];\n\t\t\t\treturn rpcError(\n\t\t\t\t\t400,\n\t\t\t\t\tid,\n\t\t\t\t\t-32602,\n\t\t\t\t\t`Invalid params: the MCP-Protocol-Version header names protocol revision ${headerVersion}, but the request is missing the required per-request envelope key(s): ${missing.join(\", \")}`,\n\t\t\t\t\t{ envelope: { missing } },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn unsupported(id, headerVersion ?? undefined);\n\t\t}\n\t\tconst issue = envelopeIssue(meta);\n\t\tif (issue !== undefined) {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tid,\n\t\t\t\t-32602,\n\t\t\t\t`Invalid _meta envelope for protocol revision ${MCP_PROTOCOL_VERSION}: ${issue.key}: ${issue.problem}`,\n\t\t\t\t{ envelope: issue },\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\theaderVersion !== null &&\n\t\t\tclaimed !== undefined &&\n\t\t\theaderVersion !== claimed\n\t\t) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\theaderVersion,\n\t\t\t\t`the body envelope names protocol version ${claimed} but the MCP-Protocol-Version header names ${headerVersion}`,\n\t\t\t);\n\t\t}\n\t\tif (headerMethod !== null && headerMethod !== method) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\theaderMethod,\n\t\t\t\t`the body names method ${method} but the Mcp-Method header names ${headerMethod}`,\n\t\t\t);\n\t\t}\n\t\tif (claimed !== MCP_PROTOCOL_VERSION) return unsupported(id, claimed);\n\t\tif (headerVersion === null) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\t\"(missing)\",\n\t\t\t\t`the body envelope names protocol version ${claimed} but the required MCP-Protocol-Version header is absent`,\n\t\t\t);\n\t\t}\n\t\tif (headerMethod === null) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\t\"(missing)\",\n\t\t\t\t`the body names method ${method} but the required Mcp-Method header is absent`,\n\t\t\t);\n\t\t}\n\t\tif (method === \"tools/call\" && typeof params[\"name\"] === \"string\") {\n\t\t\tconst name = params[\"name\"];\n\t\t\tconst header = request.headers.get(\"mcp-name\");\n\t\t\tif (header === null) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tid,\n\t\t\t\t\t\"(missing)\",\n\t\t\t\t\t`the body carries params.name=\"${name}\" but the required Mcp-Name header is absent`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decoded = decodeHeaderValue(header);\n\t\t\tif (decoded === undefined) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tid,\n\t\t\t\t\theader,\n\t\t\t\t\t\"the Mcp-Name header carries an invalid Base64 sentinel value\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (decoded !== name) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tid,\n\t\t\t\t\theader,\n\t\t\t\t\t`the body carries params.name=\"${name}\" but the Mcp-Name header names \"${decoded}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn { id, method, params };\n\t}\n\n\tfunction unsupported(id: Id, requested: string | undefined): Response {\n\t\treturn requested === undefined\n\t\t\t? rpcError(\n\t\t\t\t\t400,\n\t\t\t\t\tid,\n\t\t\t\t\tUNSUPPORTED_VERSION,\n\t\t\t\t\t\"Unsupported protocol version: the request did not name a protocol version\",\n\t\t\t\t\t{ supported: [MCP_PROTOCOL_VERSION] },\n\t\t\t\t)\n\t\t\t: rpcError(\n\t\t\t\t\t400,\n\t\t\t\t\tid,\n\t\t\t\t\tUNSUPPORTED_VERSION,\n\t\t\t\t\t`Unsupported protocol version: ${requested}`,\n\t\t\t\t\t{ supported: [MCP_PROTOCOL_VERSION], requested },\n\t\t\t\t);\n\t}\n\n\tasync function handle(\n\t\trequest: Request,\n\t\tcontext: McpRequestContext,\n\t): Promise<Response> {\n\t\tif (request.method.toUpperCase() !== \"POST\")\n\t\t\treturn rpcError(405, null, -32000, \"Method not allowed.\");\n\t\tif (!isJsonContentType(request.headers.get(\"content-type\"))) {\n\t\t\treturn rpcError(\n\t\t\t\t415,\n\t\t\t\tnull,\n\t\t\t\t-32000,\n\t\t\t\t\"Unsupported Media Type: Content-Type must be application/json\",\n\t\t\t);\n\t\t}\n\t\tlet body: unknown;\n\t\ttry {\n\t\t\tbody = JSON.parse(context.body ?? (await request.text()));\n\t\t} catch {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32700,\n\t\t\t\t\"Parse error: the request body is not valid JSON\",\n\t\t\t);\n\t\t}\n\t\tconst checked = check(request, body);\n\t\tif (checked instanceof Response) return checked;\n\t\tif (checked === \"notification\") return new Response(null, { status: 202 });\n\t\tconst { id, method, params } = checked;\n\t\tswitch (method) {\n\t\t\tcase \"server/discover\": {\n\t\t\t\tconst discover: Json = {\n\t\t\t\t\tsupportedVersions: [MCP_PROTOCOL_VERSION],\n\t\t\t\t\tcapabilities: { tools: { listChanged: true } },\n\t\t\t\t};\n\t\t\t\tif (server.instructions !== undefined)\n\t\t\t\t\tdiscover[\"instructions\"] = server.instructions;\n\t\t\t\tdiscover[\"ttlMs\"] = 0;\n\t\t\t\tdiscover[\"cacheScope\"] = \"private\";\n\t\t\t\treturn json(200, result(id, discover));\n\t\t\t}\n\t\t\tcase \"tools/list\":\n\t\t\t\treturn json(\n\t\t\t\t\t200,\n\t\t\t\t\tresult(id, { tools: listTools(), ttlMs: 0, cacheScope: \"private\" }),\n\t\t\t\t);\n\t\t\tcase \"tools/call\":\n\t\t\t\treturn callTool(id, params, request.signal, context.grant);\n\t\t\tcase \"subscriptions/listen\":\n\t\t\t\treturn listen(id, params, request.signal);\n\t\t\tdefault:\n\t\t\t\treturn rpcError(404, id, -32601, \"Method not found\");\n\t\t}\n\t}\n\n\treturn {\n\t\thandle: (request, context) =>\n\t\t\thandle(request, context).catch(() =>\n\t\t\t\trpcError(500, null, -32603, \"Internal server error\"),\n\t\t\t),\n\t\ttoolsChanged() {\n\t\t\tif (changeQueued) return;\n\t\t\tchangeQueued = true;\n\t\t\t// Several registrations in one task produce one notification.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tchangeQueued = false;\n\t\t\t\tfor (const listener of [...listeners]) {\n\t\t\t\t\tlistener.send({\n\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\tmethod: \"notifications/tools/list_changed\",\n\t\t\t\t\t\tparams: { _meta: { [META_SUBSCRIPTION]: listener.id } },\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tclose() {\n\t\t\tfor (const listener of [...listeners]) listener.end();\n\t\t},\n\t};\n}\n",
6
+ "/**\n * WebMCP → MCP mapping of annotations (DEC-022) and results (DEC-023).\n */\n\nimport type { ToolAnnotations } from \"./types.ts\";\n\n/** `_meta` key that keeps the original WebMCP hints. */\nexport const ANNOTATIONS_META_KEY = \"ch.ractive.tab-mcp/annotations\";\n\nconst WEBMCP_HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\nconst MCP_ONLY_HINTS = [\n\t\"destructiveHint\",\n\t\"idempotentHint\",\n\t\"openWorldHint\",\n] as const;\n\nexport interface McpToolAnnotations {\n\tannotations?: Record<string, boolean>;\n\tmeta?: Record<string, boolean>;\n}\n\n/** MCP annotations plus the WebMCP originals for `_meta`. */\nexport function mapAnnotations(hints: ToolAnnotations): McpToolAnnotations {\n\tconst annotations: Record<string, boolean> = {};\n\tif (hints.readOnlyHint === true) {\n\t\tannotations[\"readOnlyHint\"] = true;\n\t\tannotations[\"destructiveHint\"] = false;\n\t} else if (hints.readOnlyHint === false) {\n\t\tannotations[\"readOnlyHint\"] = false;\n\t}\n\tif (hints.consequentialHint === true) annotations[\"destructiveHint\"] = true;\n\tif (hints.untrustedContentHint === true) annotations[\"openWorldHint\"] = true;\n\tfor (const key of MCP_ONLY_HINTS) {\n\t\tconst value = hints[key];\n\t\tif (value !== undefined) annotations[key] = value; // MCP hints win\n\t}\n\tconst meta: Record<string, boolean> = {};\n\tfor (const key of WEBMCP_HINTS) {\n\t\tconst value = hints[key];\n\t\tif (value !== undefined) meta[key] = value;\n\t}\n\tconst out: McpToolAnnotations = {};\n\tif (Object.keys(annotations).length > 0) out.annotations = annotations;\n\tif (Object.keys(meta).length > 0) out.meta = meta;\n\treturn out;\n}\n\nexport interface CallToolResult {\n\tcontent: unknown[];\n\tstructuredContent?: Record<string, unknown>;\n\tisError?: boolean;\n\t[key: string]: unknown;\n}\n\nexport function errorResult(message: string): CallToolResult {\n\treturn { content: [{ type: \"text\", text: message }], isError: true };\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/**\n * What `execute` returned → a `CallToolResult`: a string is one text block; an\n * object with a `content` array passes through; `undefined` is an empty\n * result; any other JSON value is a text block with its JSON, plus\n * `structuredContent` when it is an object.\n */\nexport function toCallToolResult(value: unknown): CallToolResult {\n\tif (typeof value === \"string\")\n\t\treturn { content: [{ type: \"text\", text: value }] };\n\tif (value === undefined) return { content: [] };\n\tif (isPlainObject(value) && Array.isArray(value[\"content\"])) {\n\t\treturn value as CallToolResult;\n\t}\n\tlet text: string | undefined;\n\ttry {\n\t\ttext = JSON.stringify(value);\n\t} catch {\n\t\t// cyclic or BigInt\n\t}\n\tif (text === undefined)\n\t\treturn errorResult(\"The tool returned a value that is not JSON.\");\n\tconst result: CallToolResult = { content: [{ type: \"text\", text }] };\n\tif (isPlainObject(value)) result.structuredContent = value;\n\treturn result;\n}\n\n/** A thrown value → an `isError` result with its message. */\nexport function thrownResult(error: unknown): CallToolResult {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn errorResult(message || \"The tool failed.\");\n}\n",
7
+ "/**\n * The tab↔relay protocol, version 1, as the tab speaks it\n * (`kb/design/protocol.md`). Internal: not part of the public API.\n */\n\nimport type { Grant, Limits } from \"./types.ts\";\n\nexport const SUBPROTOCOL = \"tab-mcp.v1\";\n\n/** Who is calling a tunnelled request (the relay's view of the grant). */\nexport interface GrantRef {\n\tgrantId: string;\n\tclientId: string;\n\tscopes: string[];\n}\n\n// Relay → tab\n\nexport interface SessionMessage {\n\ttype: \"session\";\n\tsessionId: string;\n\taddress: string;\n\torigin: string;\n\tappName?: string;\n\texpiresAt: string;\n\tlimits: Limits;\n\tgrants: Grant[];\n}\nexport interface PingMessage {\n\ttype: \"ping\";\n\tt: number;\n}\nexport interface ByeMessage {\n\ttype: \"bye\";\n\treason: string;\n}\nexport interface HttpRequestMessage {\n\ttype: \"http.request\";\n\tid: string;\n\tmethod: string;\n\tpath: string;\n\theaders: Record<string, string>;\n\tbody: string;\n\tgrant: GrantRef;\n}\nexport interface HttpCancelMessage {\n\ttype: \"http.cancel\";\n\tid: string;\n\treason: string;\n}\nexport interface PairingCodeMessage {\n\ttype: \"pairing.code\";\n\tcode: string;\n\texpiresAt: string;\n}\nexport interface GrantAddedMessage {\n\ttype: \"grant.added\";\n\tgrant: Grant;\n}\nexport interface GrantRemovedMessage {\n\ttype: \"grant.removed\";\n\tgrantId: string;\n\treason: string;\n}\nexport interface ErrorMessage {\n\ttype: \"error\";\n\tcode: string;\n\tmessage: string;\n\tid?: string;\n}\nexport type RelayMessage =\n\t| SessionMessage\n\t| PingMessage\n\t| ByeMessage\n\t| HttpRequestMessage\n\t| HttpCancelMessage\n\t| PairingCodeMessage\n\t| GrantAddedMessage\n\t| GrantRemovedMessage\n\t| ErrorMessage;\n\n// Tab → relay\n\nexport type TabMessage =\n\t| {\n\t\t\ttype: \"hello\";\n\t\t\tlibrary: { name: string; version: string };\n\t\t\tpage: { title: string };\n\t\t\tapp?: { name: string };\n\t\t\tsecret: string;\n\t }\n\t| { type: \"pong\"; t: number }\n\t| { type: \"bye\"; reason: string }\n\t| {\n\t\t\ttype: \"http.response\";\n\t\t\tid: string;\n\t\t\tstatus: number;\n\t\t\theaders: Record<string, string>;\n\t\t\tbody: string;\n\t }\n\t| {\n\t\t\ttype: \"http.response.start\";\n\t\t\tid: string;\n\t\t\tstatus: number;\n\t\t\theaders: Record<string, string>;\n\t }\n\t| { type: \"http.response.chunk\"; id: string; data: string }\n\t| { type: \"http.response.end\"; id: string }\n\t| { type: \"pairing.start\" }\n\t| { type: \"pairing.stop\" }\n\t| { type: \"grant.revoke\"; grantId: string }\n\t| { type: \"grants.revokeAll\" }\n\t| { type: \"error\"; code: string; message: string; id?: string };\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(v: unknown): v is Json {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\nconst str = (v: unknown): v is string => typeof v === \"string\";\n\nfunction isGrant(v: unknown): v is Grant {\n\tif (!isObject(v) || !str(v[\"grantId\"]) || !str(v[\"createdAt\"])) return false;\n\tconst c = v[\"client\"];\n\treturn isObject(c) && str(c[\"id\"]) && str(c[\"name\"]) && str(c[\"host\"]);\n}\n\nfunction isLimits(v: unknown): v is Limits {\n\tif (!isObject(v)) return false;\n\treturn [\n\t\t\"maxMessageBytes\",\n\t\t\"maxBodyBytes\",\n\t\t\"requestTimeoutMs\",\n\t\t\"idleTimeoutMs\",\n\t\t\"heartbeatMs\",\n\t\t\"keepAliveMs\",\n\t\t\"maxConcurrentRequests\",\n\t].every((k) => typeof v[k] === \"number\");\n}\n\nfunction isStringRecord(v: unknown): v is Record<string, string> {\n\treturn isObject(v) && Object.values(v).every(str);\n}\n\n/**\n * Parse one frame from the relay. Returns `undefined` for anything malformed\n * or unknown; the caller ignores it (forward compatibility).\n */\nexport function parseRelayMessage(text: string): RelayMessage | undefined {\n\tlet v: unknown;\n\ttry {\n\t\tv = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (!isObject(v)) return undefined;\n\tswitch (v[\"type\"]) {\n\t\tcase \"session\":\n\t\t\treturn str(v[\"sessionId\"]) &&\n\t\t\t\tstr(v[\"address\"]) &&\n\t\t\t\tstr(v[\"origin\"]) &&\n\t\t\t\tstr(v[\"expiresAt\"]) &&\n\t\t\t\tisLimits(v[\"limits\"]) &&\n\t\t\t\tArray.isArray(v[\"grants\"]) &&\n\t\t\t\tv[\"grants\"].every(isGrant) &&\n\t\t\t\t(v[\"appName\"] === undefined || str(v[\"appName\"]))\n\t\t\t\t? (v as unknown as SessionMessage)\n\t\t\t\t: undefined;\n\t\tcase \"ping\":\n\t\t\treturn typeof v[\"t\"] === \"number\"\n\t\t\t\t? (v as unknown as PingMessage)\n\t\t\t\t: undefined;\n\t\tcase \"bye\":\n\t\t\treturn { type: \"bye\", reason: str(v[\"reason\"]) ? v[\"reason\"] : \"\" };\n\t\tcase \"http.request\":\n\t\t\treturn str(v[\"id\"]) &&\n\t\t\t\tstr(v[\"method\"]) &&\n\t\t\t\tstr(v[\"path\"]) &&\n\t\t\t\tisStringRecord(v[\"headers\"]) &&\n\t\t\t\tstr(v[\"body\"]) &&\n\t\t\t\tisObject(v[\"grant\"]) &&\n\t\t\t\tstr(v[\"grant\"][\"grantId\"]) &&\n\t\t\t\tstr(v[\"grant\"][\"clientId\"])\n\t\t\t\t? (v as unknown as HttpRequestMessage)\n\t\t\t\t: undefined;\n\t\tcase \"http.cancel\":\n\t\t\treturn str(v[\"id\"]) ? (v as unknown as HttpCancelMessage) : undefined;\n\t\tcase \"pairing.code\":\n\t\t\treturn str(v[\"code\"]) && str(v[\"expiresAt\"])\n\t\t\t\t? (v as unknown as PairingCodeMessage)\n\t\t\t\t: undefined;\n\t\tcase \"grant.added\":\n\t\t\treturn isGrant(v[\"grant\"])\n\t\t\t\t? (v as unknown as GrantAddedMessage)\n\t\t\t\t: undefined;\n\t\tcase \"grant.removed\":\n\t\t\treturn str(v[\"grantId\"])\n\t\t\t\t? {\n\t\t\t\t\t\ttype: \"grant.removed\",\n\t\t\t\t\t\tgrantId: v[\"grantId\"],\n\t\t\t\t\t\treason: str(v[\"reason\"]) ? v[\"reason\"] : \"\",\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tcase \"error\":\n\t\t\treturn str(v[\"code\"]) ? (v as unknown as ErrorMessage) : undefined;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n",
8
+ "/**\n * The lazily loaded part (DEC-035): the WebSocket session with the relay, the\n * HTTP tunnel and the MCP handler. Loaded by `TabMcp.connect()`.\n */\n\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport { createMcpHandler } from \"./mcp.ts\";\nimport {\n\ttype HttpRequestMessage,\n\tparseRelayMessage,\n\ttype RelayMessage,\n\tSUBPROTOCOL,\n\ttype TabMessage,\n} from \"./protocol.ts\";\nimport type { DisconnectReason, SessionInfo } from \"./types.ts\";\n\n/** How long `connect()` waits for the relay's `session`. */\nconst CONNECT_TIMEOUT_MS = 15_000;\n\nconst CLOSE_REASONS: Record<number, DisconnectReason> = {\n\t1000: \"closed\",\n\t1008: \"policy\",\n\t1009: \"too_large\",\n\t4001: \"expired\",\n\t4002: \"idle\",\n\t4003: \"heartbeat\",\n\t4004: \"shutdown\",\n\t4005: \"replaced\",\n\t4008: \"rate_limited\",\n};\n\nconst BYE_REASONS: Record<string, DisconnectReason> = {\n\treplaced: \"replaced\",\n\texpired: \"expired\",\n\tidle: \"idle\",\n\tshutdown: \"shutdown\",\n};\n\n/** Response headers the relay passes on (it drops the rest). */\nconst RESPONSE_HEADERS = [\"content-type\", \"cache-control\"];\n\nfunction pageTitle(): string {\n\tconst title = (globalThis as { document?: { title?: unknown } }).document\n\t\t?.title;\n\treturn typeof title === \"string\" ? title.slice(0, 300) : \"\";\n}\n\nfunction frameInfo(text: string): { type: string; id?: string } | undefined {\n\ttry {\n\t\tconst v = JSON.parse(text) as Record<string, unknown>;\n\t\tif (typeof v !== \"object\" || v === null || typeof v[\"type\"] !== \"string\")\n\t\t\treturn undefined;\n\t\treturn typeof v[\"id\"] === \"string\"\n\t\t\t? { type: v[\"type\"], id: v[\"id\"] }\n\t\t\t: { type: v[\"type\"] };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nconst KNOWN_TYPES = new Set([\n\t\"session\",\n\t\"ping\",\n\t\"bye\",\n\t\"http.request\",\n\t\"http.cancel\",\n\t\"pairing.code\",\n\t\"grant.added\",\n\t\"grant.removed\",\n\t\"error\",\n]);\n\n/**\n * Room for a message's envelope (`http.response` with its headers, or a\n * chunk) with an id of up to 128 characters (protocol limit).\n */\nconst ENVELOPE_BYTES = 512;\n/** Worst case per UTF-16 unit once JSON-encoded as UTF-8: `\\u0001` is 6 bytes. */\nconst WORST_BYTES_PER_UNIT = 6;\nconst MIN_CHUNK_UNITS = 64;\nexport const MIN_MESSAGE_BYTES: number =\n\tENVELOPE_BYTES + WORST_BYTES_PER_UNIT * MIN_CHUNK_UNITS;\n\n/**\n * The largest piece of body text (UTF-16 units) whose message cannot exceed\n * the relay's `maxMessageBytes`; `undefined` if the limit is too small to\n * frame anything useful.\n */\nexport function chunkSize(maxMessageBytes: number): number | undefined {\n\tconst units = Math.floor(\n\t\t(maxMessageBytes - ENVELOPE_BYTES) / WORST_BYTES_PER_UNIT,\n\t);\n\treturn units >= MIN_CHUNK_UNITS ? units : undefined;\n}\n\n/**\n * Split text into pieces of at most `max` UTF-16 units, never between the two\n * halves of a surrogate pair (a lone half would not survive JSON and UTF-8).\n */\nexport function* pieces(text: string, max: number): Generator<string> {\n\tlet i = 0;\n\twhile (i < text.length) {\n\t\tlet end = Math.min(i + max, text.length);\n\t\tconst last = text.charCodeAt(end - 1);\n\t\tif (end < text.length && last >= 0xd800 && last <= 0xdbff) {\n\t\t\tend += end - 1 > i ? -1 : 1; // keep the pair together\n\t\t}\n\t\tyield text.slice(i, end);\n\t\ti = end;\n\t}\n}\n\n/** Open the WebSocket and run the session. */\nexport function openConnection(\n\thost: ConnectionHost,\n\turl: string,\n\tsecret: string,\n): ConnectionHandle {\n\tconst ws = new WebSocket(url, SUBPROTOCOL);\n\tconst inflight = new Map<string, AbortController>();\n\tlet state: \"opening\" | \"ready\" | \"closed\" = \"opening\";\n\tlet byeReason: DisconnectReason | undefined;\n\tlet maxChunk = 64 * 1024;\n\tlet heartbeat: ReturnType<typeof setTimeout> | undefined;\n\tlet heartbeatMs = 0;\n\n\tlet resolveReady!: (session: SessionInfo) => void;\n\tlet rejectReady!: (error: Error) => void;\n\tconst ready = new Promise<SessionInfo>((resolve, reject) => {\n\t\tresolveReady = resolve;\n\t\trejectReady = reject;\n\t});\n\tready.catch(() => {}); // the caller handles it; never an unhandled rejection here\n\tconst connectTimer = setTimeout(() => {\n\t\tfail(new Error(\"The relay did not answer in time.\"));\n\t}, CONNECT_TIMEOUT_MS);\n\n\tconst handler = createMcpHandler({\n\t\ttools: host.registry,\n\t\tserver: host.server,\n\t\tconfirm: (request) => host.confirm(request),\n\t\tclient: (grant) => host.clientFor(grant),\n\t\tobserve: {\n\t\t\tstart: (call) => host.toolCallStarted(call),\n\t\t\tend: (call) => host.toolCallEnded(call),\n\t\t},\n\t});\n\tconst stopWatching = host.registry.onChange(() => handler.toolsChanged());\n\n\tfunction send(message: TabMessage): boolean {\n\t\tif (ws.readyState !== WebSocket.OPEN) return false;\n\t\ttry {\n\t\t\tws.send(JSON.stringify(message));\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/** Two missed pings mean the connection is dead (protocol: heartbeat). */\n\tfunction armHeartbeat(): void {\n\t\tif (heartbeatMs <= 0) return;\n\t\tclearTimeout(heartbeat);\n\t\theartbeat = setTimeout(() => {\n\t\t\tbyeReason ??= \"heartbeat\";\n\t\t\tfinish(4003);\n\t\t\ttry {\n\t\t\t\tws.close();\n\t\t\t} catch {\n\t\t\t\t// already closing\n\t\t\t}\n\t\t}, heartbeatMs * 2.5);\n\t}\n\n\tfunction fail(error: Error): void {\n\t\tif (state !== \"opening\") return;\n\t\tfinish(0);\n\t\trejectReady(error);\n\t\ttry {\n\t\t\tws.close();\n\t\t} catch {\n\t\t\t// already closed\n\t\t}\n\t}\n\n\t/** The session is over: clean up once and tell the host. */\n\tfunction finish(code: number): void {\n\t\tif (state === \"closed\") return;\n\t\tconst wasReady = state === \"ready\";\n\t\tstate = \"closed\";\n\t\tclearTimeout(connectTimer);\n\t\tclearTimeout(heartbeat);\n\t\tstopWatching();\n\t\tfor (const controller of inflight.values()) controller.abort();\n\t\tinflight.clear();\n\t\thandler.close();\n\t\tif (wasReady) {\n\t\t\tconst reason =\n\t\t\t\tbyeReason ??\n\t\t\t\tCLOSE_REASONS[code] ??\n\t\t\t\t(code === 1006 ? \"network\" : \"closed\");\n\t\t\thost.closed(reason, code);\n\t\t}\n\t}\n\n\tasync function tunnel(msg: HttpRequestMessage): Promise<void> {\n\t\tconst controller = new AbortController();\n\t\tinflight.set(msg.id, controller);\n\t\tconst live = () =>\n\t\t\tstate === \"ready\" &&\n\t\t\tinflight.get(msg.id) === controller &&\n\t\t\t!controller.signal.aborted;\n\t\ttry {\n\t\t\tconst request = new Request(`https://tab.invalid${msg.path}`, {\n\t\t\t\tmethod: msg.method,\n\t\t\t\theaders: msg.headers,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst response = await handler.handle(request, {\n\t\t\t\tgrant: msg.grant,\n\t\t\t\tbody: msg.body,\n\t\t\t});\n\t\t\tif (!live()) {\n\t\t\t\tawait response.body?.cancel().catch(() => {});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst headers: Record<string, string> = {};\n\t\t\tfor (const name of RESPONSE_HEADERS) {\n\t\t\t\tconst value = response.headers.get(name);\n\t\t\t\tif (value !== null) headers[name] = value;\n\t\t\t}\n\t\t\tconst streamed = (headers[\"content-type\"] ?? \"\").startsWith(\n\t\t\t\t\"text/event-stream\",\n\t\t\t);\n\t\t\tif (!streamed || response.body === null) {\n\t\t\t\tconst body = await response.text();\n\t\t\t\tif (!live()) return;\n\t\t\t\tif (body.length <= maxChunk) {\n\t\t\t\t\tsend({\n\t\t\t\t\t\ttype: \"http.response\",\n\t\t\t\t\t\tid: msg.id,\n\t\t\t\t\t\tstatus: response.status,\n\t\t\t\t\t\theaders,\n\t\t\t\t\t\tbody,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Too big for one message: stream it (the relay passes it on whole).\n\t\t\t\tsend({\n\t\t\t\t\ttype: \"http.response.start\",\n\t\t\t\t\tid: msg.id,\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\theaders,\n\t\t\t\t});\n\t\t\t\tfor (const data of pieces(body, maxChunk)) {\n\t\t\t\t\tif (!live()) break;\n\t\t\t\t\tsend({ type: \"http.response.chunk\", id: msg.id, data });\n\t\t\t\t}\n\t\t\t\tif (live()) send({ type: \"http.response.end\", id: msg.id });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsend({\n\t\t\t\ttype: \"http.response.start\",\n\t\t\t\tid: msg.id,\n\t\t\t\tstatus: response.status,\n\t\t\t\theaders,\n\t\t\t});\n\t\t\tconst reader = response.body.getReader();\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tcontroller.signal.addEventListener(\"abort\", () => {\n\t\t\t\treader.cancel().catch(() => {});\n\t\t\t});\n\t\t\tfor (;;) {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done || !live()) break;\n\t\t\t\tconst text = decoder.decode(value, { stream: true });\n\t\t\t\tfor (const data of pieces(text, maxChunk)) {\n\t\t\t\t\tsend({ type: \"http.response.chunk\", id: msg.id, data });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (live()) send({ type: \"http.response.end\", id: msg.id });\n\t\t} catch (error) {\n\t\t\tif (live()) {\n\t\t\t\thost.error(error instanceof Error ? error : new Error(String(error)));\n\t\t\t\tsend({\n\t\t\t\t\ttype: \"http.response\",\n\t\t\t\t\tid: msg.id,\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\tid: null,\n\t\t\t\t\t\terror: { code: -32603, message: \"Internal server error\" },\n\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t}\n\t\t} finally {\n\t\t\tif (inflight.get(msg.id) === controller) inflight.delete(msg.id);\n\t\t}\n\t}\n\n\tfunction onMessage(message: RelayMessage): void {\n\t\tif (state === \"opening\") {\n\t\t\tif (message.type === \"session\") {\n\t\t\t\tconst chunk = chunkSize(message.limits.maxMessageBytes);\n\t\t\t\tif (chunk === undefined) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`The relay's message limit (${message.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${MIN_MESSAGE_BYTES}.`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tmaxChunk = chunk;\n\t\t\t\tstate = \"ready\";\n\t\t\t\tclearTimeout(connectTimer);\n\t\t\t\theartbeatMs = message.limits.heartbeatMs;\n\t\t\t\tarmHeartbeat();\n\t\t\t\tresolveReady(host.sessionStarted(message));\n\t\t\t} else if (message.type === \"error\") {\n\t\t\t\tfail(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t`The relay refused the connection: ${message.message || message.code}`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (message.type === \"bye\") {\n\t\t\t\tfail(new Error(`The relay ended the connection: ${message.reason}`));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (state !== \"ready\") return;\n\t\tswitch (message.type) {\n\t\t\tcase \"ping\":\n\t\t\t\tarmHeartbeat();\n\t\t\t\tsend({ type: \"pong\", t: message.t });\n\t\t\t\treturn;\n\t\t\tcase \"http.request\":\n\t\t\t\tvoid tunnel(message);\n\t\t\t\treturn;\n\t\t\tcase \"http.cancel\":\n\t\t\t\tinflight.get(message.id)?.abort();\n\t\t\t\tinflight.delete(message.id);\n\t\t\t\treturn;\n\t\t\tcase \"pairing.code\":\n\t\t\t\thost.pairingCode({ code: message.code, expiresAt: message.expiresAt });\n\t\t\t\treturn;\n\t\t\tcase \"grant.added\":\n\t\t\t\thost.grantAdded(message.grant);\n\t\t\t\treturn;\n\t\t\tcase \"grant.removed\":\n\t\t\t\thost.grantRemoved(message.grantId);\n\t\t\t\treturn;\n\t\t\tcase \"bye\":\n\t\t\t\tbyeReason = BYE_REASONS[message.reason] ?? \"closed\";\n\t\t\t\tif (byeReason === \"replaced\") host.replaced();\n\t\t\t\treturn;\n\t\t\tcase \"error\":\n\t\t\t\thost.error(\n\t\t\t\t\tnew Error(`Relay error ${message.code}: ${message.message}`),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\tcase \"session\":\n\t\t\t\treturn; // only once\n\t\t}\n\t}\n\n\tws.addEventListener(\"open\", () => {\n\t\tif (ws.protocol !== \"\" && ws.protocol !== SUBPROTOCOL) {\n\t\t\tfail(new Error(`The relay speaks ${ws.protocol}, not ${SUBPROTOCOL}.`));\n\t\t\treturn;\n\t\t}\n\t\tconst hello: TabMessage = {\n\t\t\ttype: \"hello\",\n\t\t\tlibrary: host.library,\n\t\t\tpage: { title: pageTitle() },\n\t\t\tsecret,\n\t\t};\n\t\tif (host.appName !== undefined) hello.app = { name: host.appName };\n\t\tsend(hello);\n\t});\n\tws.addEventListener(\"message\", (event: MessageEvent) => {\n\t\tif (typeof event.data !== \"string\") return;\n\t\tconst message = parseRelayMessage(event.data);\n\t\tif (message !== undefined) {\n\t\t\tif (state === \"ready\") armHeartbeat(); // any traffic shows the link is alive\n\t\t\tonMessage(message);\n\t\t\treturn;\n\t\t}\n\t\tconst info = frameInfo(event.data);\n\t\tif (info?.id !== undefined) {\n\t\t\tsend(\n\t\t\t\tKNOWN_TYPES.has(info.type)\n\t\t\t\t\t? {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tcode: \"bad_message\",\n\t\t\t\t\t\t\tmessage: `malformed ${info.type}`,\n\t\t\t\t\t\t\tid: info.id,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tcode: \"unknown_type\",\n\t\t\t\t\t\t\tmessage: `unknown type ${info.type}`,\n\t\t\t\t\t\t\tid: info.id,\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t}\n\t});\n\tws.addEventListener(\"close\", (event: CloseEvent) => {\n\t\tif (state === \"opening\") {\n\t\t\tfinish(event.code);\n\t\t\trejectReady(\n\t\t\t\tnew Error(\n\t\t\t\t\tevent.code === 1006\n\t\t\t\t\t\t? \"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).\"\n\t\t\t\t\t\t: `The relay closed the connection (${event.code}${event.reason ? `: ${event.reason}` : \"\"}).`,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tfinish(event.code);\n\t});\n\n\treturn {\n\t\tready,\n\t\tsend,\n\t\tclose(reason: DisconnectReason) {\n\t\t\tif (state === \"closed\") return;\n\t\t\tif (state === \"opening\") {\n\t\t\t\tfail(\n\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\"The connection was cancelled\",\n\t\t\t\t\t\t\"AbortError\",\n\t\t\t\t\t) as Error,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbyeReason = reason;\n\t\t\tsend({ type: \"bye\", reason: \"user\" });\n\t\t\tfinish(1000);\n\t\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AAA,MACA,YAAY;AAAA,MACZ,KAAK,EAAE,MAAM,OAAO,QAAQ,OAAO,CAAC;AAAA,MACpC,OAAO,IAAI;AAAA,MACX,IAAI;AAAA,QACH,GAAG,MAAM,MAAM,KAAK;AAAA,QACnB,MAAM;AAAA;AAAA,EAIV;AAAA;",
11
+ "debugId": "26D08B19889F01DB64756E2164756E21",
12
+ "names": []
13
+ }
package/index.d.ts CHANGED
@@ -3,5 +3,5 @@
3
3
  * tab-mcp relay. This entry is the small core; `connect()` loads the rest.
4
4
  */
5
5
  export { TabMcp } from "./tab-mcp.js";
6
- export type { ConfirmHandler, ConfirmRequest, ConnectionState, ConnectOptions, DisconnectDetail, DisconnectReason, Grant, JsonSchema, Limits, PairingCode, RegisterToolOptions, SecretStorage, ServerInfo, SessionInfo, TabMcpEventMap, TabMcpOptions, Tool, ToolAnnotations, ToolCallClient, ToolExecuteOptions, } from "./types.js";
6
+ export type { ConfirmHandler, ConfirmRequest, ConnectionState, ConnectOptions, DisconnectDetail, DisconnectReason, Grant, JsonSchema, Limits, PairingCode, RegisterToolOptions, SecretStorage, ServerInfo, SessionInfo, TabMcpEventMap, TabMcpOptions, Tool, ToolAnnotations, ToolCallClient, ToolCallEnd, ToolCallOutcome, ToolCallResult, ToolCallStart, ToolExecuteOptions, } from "./types.js";
7
7
  export { VERSION } from "./version.js";