@ractive-ch/tab-mcp-client 0.14.0 → 0.16.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.
- package/README.md +538 -126
- package/always-allowed.d.ts +25 -6
- package/cdn/confirm-y30cx7e1.min.js +4 -0
- package/cdn/confirm-y30cx7e1.min.js.map +10 -0
- package/cdn/connect-bbhj2y7w.min.js +6 -0
- package/cdn/connect-bbhj2y7w.min.js.map +12 -0
- package/cdn/connection-0y7ngtq7.min.js +17 -0
- package/cdn/connection-0y7ngtq7.min.js.map +22 -0
- package/cdn/index-vt5zk9me.min.js +91 -0
- package/cdn/index-vt5zk9me.min.js.map +13 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +6 -6
- package/confirm-fgnjgd08.js +263 -0
- package/confirm-fgnjgd08.js.map +10 -0
- package/confirm.d.ts +54 -0
- package/connect-8jpb0k29.js +484 -0
- package/connect-8jpb0k29.js.map +10 -0
- package/connect.d.ts +40 -0
- package/{connection-eqsag07j.js → connection-1d8rxgbq.js} +515 -242
- package/connection-1d8rxgbq.js.map +16 -0
- package/connection.d.ts +9 -9
- package/dialog.d.ts +83 -0
- package/{index-nmn1j689.js → index-5jyqehpk.js} +14 -10
- package/index-5jyqehpk.js.map +11 -0
- package/index-jnz7w9xa.js +392 -0
- package/index-jnz7w9xa.js.map +12 -0
- package/index.d.ts +1 -1
- package/index.js +285 -244
- package/index.js.map +6 -6
- package/mapping.d.ts +37 -4
- package/mcp.d.ts +23 -8
- package/package.json +5 -1
- package/react.d.ts +13 -12
- package/react.js +20 -14
- package/react.js.map +3 -3
- package/registry.d.ts +12 -5
- package/secret.d.ts +5 -2
- package/serve.d.ts +68 -0
- package/setup.d.ts +15 -25
- package/setup.js +1 -1
- package/strings.d.ts +107 -0
- package/tab-mcp.d.ts +76 -36
- package/tunnel.d.ts +74 -0
- package/tunnel.js +263 -0
- package/tunnel.js.map +10 -0
- package/types.d.ts +206 -73
- package/webmcp.d.ts +13 -18
- package/cdn/connection-dweyrdbn.min.js +0 -12
- package/cdn/connection-dweyrdbn.min.js.map +0 -21
- package/cdn/ui-5zecjy7s.min.js +0 -86
- package/cdn/ui-5zecjy7s.min.js.map +0 -14
- package/connection-eqsag07j.js.map +0 -15
- package/index-nmn1j689.js.map +0 -11
- package/ui-4qv8d1a3.js +0 -781
- package/ui-4qv8d1a3.js.map +0 -11
- package/ui.d.ts +0 -83
package/index.js.map
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/registry.ts", "../src/secret.ts", "../src/version.ts", "../src/webmcp.ts", "../src/tab-mcp.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\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\t/** `RegisterToolOptions.webmcp`: offered through WebMCP even if consequential, or never. */\n\treadonly webmcp?: boolean | undefined;\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 * Without `$id`s; once the validator is loaded, it checks too (`setCompiler`).\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\n/** The validator's check of a schema: throws a `TypeError` naming the problem. */\nexport type SchemaCompiler = (tool: RegisteredTool) => void;\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\t#compile: SchemaCompiler | undefined;\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 { signal, webmcp } = options;\n\t\tconst registered: RegisteredTool = { ...validateTool(tool), webmcp };\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.#compile?.(registered);\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\"abort\", () => this.remove(registered), {\n\t\t\tonce: true,\n\t\t});\n\t\tthis.#changed();\n\t}\n\n\t/**\n\t * The validator is loaded: from now on each schema is compiled when it is\n\t * registered, and a tool it refuses is refused (DEC-086).\n\t */\n\tsetCompiler(compile: SchemaCompiler): void {\n\t\tthis.#compile ??= compile;\n\t}\n\n\t/** Unregister this tool, if it still is. */\n\tremove(tool: RegisteredTool): void {\n\t\tif (this.#tools.get(tool.name) !== tool) return;\n\t\tthis.#tools.delete(tool.name);\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
|
-
"/**\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/** A key the secret may still be under (the default of 0.4 and older). */\n\treadonly #oldKey: string | undefined;\n\t/** Set once a page of this origin took over the old key's secret. */\n\treadonly #claimKey: string | undefined;\n\t#memory: string | undefined;\n\n\tconstructor(\n\t\tstorage: SecretStorage | null | undefined,\n\t\tkey: string,\n\t\toldKey?: string,\n\t) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t\tthis.#oldKey = oldKey;\n\t\tthis.#claimKey = oldKey === undefined ? undefined : `${oldKey}#moved`;\n\t}\n\n\t
|
|
5
|
+
"/**\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\tToolCaller,\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 outputSchema?: JsonSchema | undefined;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n\t/**\n\t * `RegisterToolOptions.callers`, copied; `undefined`: the default, which\n\t * `toolsFor` (serve.ts, the relay and a port) and `mirror` (webmcp.ts) apply.\n\t */\n\treadonly callers?: readonly ToolCaller[] | undefined;\n\t/** `RegisterToolOptions.exposedTo`, passed on to the native registration. */\n\treadonly exposedTo?: string[] | undefined;\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** Keywords whose values are data, not schemas (CC 13). */\nconst DATA = /^(default|examples|const|enum)$/;\n/** Keywords whose values map names to schemas: the names are not keywords. */\nconst NAMED =\n\t/^(properties|patternProperties|\\$defs|definitions|dependentSchemas)$/;\n\n/**\n * Calls `visit` for every schema object in `node`, itself included. The\n * values of `default`, `examples`, `const` and `enum` are data and are\n * skipped. An array, or the map under `properties` and the like (`map`), is\n * not a schema itself: its values are, and its keys are names, not keywords.\n */\nfunction eachSchema(\n\tnode: unknown,\n\tvisit: (schema: Record<string, unknown>) => void,\n\tdepth = 0,\n\tmap = false,\n): void {\n\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\tmap ||= Array.isArray(node);\n\tif (!map) visit(node as Record<string, unknown>);\n\tfor (const [key, value] of Object.entries(node))\n\t\tif (map || !DATA.test(key))\n\t\t\teachSchema(value, visit, depth + 1, !map && NAMED.test(key));\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\tlet key: string;\n\t\ttry {\n\t\t\tkey = decodeURIComponent(raw);\n\t\t} catch {\n\t\t\treturn undefined; // a malformed `%`\n\t\t}\n\t\tkey = key.replaceAll(\"~1\", \"/\").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 * Without `$id`s; once the validator is loaded, it checks too (`setCompiler`).\n * Also `x-mcp-header`, which makes the relay validate headers it does not\n * know; not supported in v1.\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tlet header = false;\n\teachSchema(root, (o) => {\n\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\tconst pp = o[\"patternProperties\"];\n\t\tif (isPlainObject(pp)) patterns.push(...Object.keys(pp));\n\t\tif (\"x-mcp-header\" in o) header = true;\n\t});\n\tif (header) return \"x-mcp-header is not supported by tab-mcp\";\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 {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema,\n\t\toutputSchema,\n\t\texecute,\n\t\tannotations,\n\t} = 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\t/**\n\t * An object schema (MCP wants `\"type\": \"object\"`), copied as JSON and\n\t * checked by `schemaProblem`: an AI app compiles the output schema too.\n\t */\n\tconst copy = (schema: unknown, what: string): JsonSchema => {\n\t\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\t\tthrow new TypeError(\n\t\t\t\t`registerTool: the ${what} of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t\t);\n\t\t}\n\t\tlet copied: JsonSchema;\n\t\ttry {\n\t\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t\t} catch {\n\t\t\tthrow new TypeError(`registerTool: the ${what} of ${name} must be JSON`);\n\t\t}\n\t\tconst problem = schemaProblem(copied);\n\t\tif (problem !== undefined)\n\t\t\tthrow new TypeError(`registerTool: the ${what} of ${name}: ${problem}`);\n\t\treturn copied;\n\t};\n\tconst copied = copy(inputSchema ?? { type: \"object\" }, \"inputSchema\");\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\t// A hint that is not a boolean is refused, not dropped: a dropped\n\t// `consequentialHint: \"true\"` would run the tool without asking (CC 2).\n\t// Every key ending in `Hint`, and `debugging`, counts as a hint, also\n\t// one tab-mcp does not know (a later draft's, or a misspelt one); other\n\t// keys that are not booleans are ignored.\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\telse if (value !== undefined && /Hint$|^debugging$/.test(key))\n\t\t\tthrow new TypeError(`registerTool: ${key} of ${name} must be a boolean`);\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\toutputSchema:\n\t\t\toutputSchema === undefined\n\t\t\t\t? undefined\n\t\t\t\t: copy(outputSchema, \"outputSchema\"),\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\n/** The validator's check of a schema: throws a `TypeError` naming the problem. */\nexport type SchemaCompiler = (tool: RegisteredTool) => void;\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\t#compile: SchemaCompiler | undefined;\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool, an\n\t * `InvalidStateError` `DOMException` for a duplicate name and the abort\n\t * reason for an aborted signal (as WebMCP).\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst { signal, exposedTo } = options;\n\t\t// A copy: the page's array may change later, what was registered does\n\t\t// not. Not a list: the spread throws a `TypeError` itself.\n\t\tconst callers = options.callers && [...options.callers];\n\t\t// The option of 0.15 and before, refused rather than ignored: an ignored\n\t\t// `webmcp: false` would put the tool into WebMCP (DEC-165).\n\t\tif (\n\t\t\t\"webmcp\" in options ||\n\t\t\tcallers?.some((c) => !/^(relay|local|webmcp)$/.test(c))\n\t\t)\n\t\t\tthrow new TypeError(\n\t\t\t\t'registerTool: callers must be \"relay\", \"local\" or \"webmcp\"; option webmcp is gone',\n\t\t\t);\n\t\tconst registered: RegisteredTool = {\n\t\t\t...validateTool(tool),\n\t\t\tcallers,\n\t\t\texposedTo,\n\t\t};\n\t\tsignal?.throwIfAborted();\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.#compile?.(registered);\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\"abort\", () => this.remove(registered), {\n\t\t\tonce: true,\n\t\t});\n\t\tthis.#changed();\n\t}\n\n\t/**\n\t * The validator is loaded: from now on each schema is compiled when it is\n\t * registered, and a tool it refuses is refused (DEC-086).\n\t */\n\tsetCompiler(compile: SchemaCompiler): void {\n\t\tthis.#compile ??= compile;\n\t}\n\n\t/** Unregister this tool, if it still is. */\n\tremove(tool: RegisteredTool): void {\n\t\tif (this.#tools.get(tool.name) !== tool) return;\n\t\tthis.#tools.delete(tool.name);\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
|
+
"/**\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/** A key the secret may still be under (the default of 0.4 and older). */\n\treadonly #oldKey: string | undefined;\n\t/** Set once a page of this origin took over the old key's secret. */\n\treadonly #claimKey: string | undefined;\n\t#memory: string | undefined;\n\n\tconstructor(\n\t\tstorage: SecretStorage | null | undefined,\n\t\tkey: string,\n\t\toldKey?: string,\n\t) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t\tthis.#oldKey = oldKey;\n\t\tthis.#claimKey = oldKey === undefined ? undefined : `${oldKey}#moved`;\n\t}\n\n\t/**\n\t * The current secret, or `undefined` while this page has none (none made\n\t * yet); storage first, so a rotation in another tab is seen.\n\t */\n\tcurrent(): string | undefined {\n\t\tlet stored: string | null = null;\n\t\ttry {\n\t\t\tstored = this.#storage?.getItem(this.#key) ?? null;\n\t\t\t// The old shared key's secret is copied once (DEC-083): the first page\n\t\t\t// keeps the address and marks it taken, so the next page gets its own.\n\t\t\t// The old key stays, for pages still on 0.4 and for a rollback.\n\t\t\tif (\n\t\t\t\t!isSecret(stored) &&\n\t\t\t\tthis.#oldKey !== undefined &&\n\t\t\t\tthis.#claimKey !== undefined &&\n\t\t\t\tthis.#storage?.getItem(this.#claimKey) == null\n\t\t\t) {\n\t\t\t\tconst old = this.#storage?.getItem(this.#oldKey) ?? null;\n\t\t\t\tif (isSecret(old)) {\n\t\t\t\t\tstored = old; // kept for this page even if the writes below fail\n\t\t\t\t\tthis.#claim(old);\n\t\t\t\t}\n\t\t\t}\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;\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\t// Also marks the old shared secret taken: an address abandoned with \"New\n\t\t// address\" is not picked up again by another page of the site.\n\t\tthis.#claim(secret);\n\t\treturn secret;\n\t}\n\n\t#claim(secret: string): void {\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t\tif (this.#claimKey !== undefined)\n\t\t\t\tthis.#storage?.setItem(this.#claimKey, this.#key);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t}\n}\n",
|
|
7
7
|
"/** The library's name and version, sent in `hello`; the version is package.json's. */\nimport { version } from \"../package.json\" with { type: \"json\" };\n\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION: string = version;\n",
|
|
8
|
-
"/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119): with `webmcp: true`, each tool that is offered there is
|
|
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 type { CallHost, 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\tConfirmAnswer,\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tIdentityAssertionHandler,\n\tIdentityState,\n\tPairingCode,\n\tReconnectingInfo,\n\tRegisterToolOptions,\n\tRelayClient,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\nimport { mirror, nativeContext } from \"./webmcp.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** The default waits before each reconnect attempt; the last one repeats. */\nconst RECONNECT_DELAYS_MS = [5_000, 10_000, 20_000, 40_000, 60_000];\n/** Reasons after which the library connects again by itself. */\nconst RECONNECT_REASONS = new Set<DisconnectReason>([\n\t\"network\",\n\t\"heartbeat\",\n\t\"shutdown\",\n]);\n\nfunction reconnectDelays(\n\toption: TabMcpOptions[\"reconnect\"],\n): readonly number[] | undefined {\n\tif (option === false) return undefined;\n\tif (option === undefined || option === true) return RECONNECT_DELAYS_MS;\n\tconst delays = option.delaysMs ?? RECONNECT_DELAYS_MS;\n\tif (\n\t\t!Array.isArray(delays) ||\n\t\tdelays.length === 0 ||\n\t\t!delays.every((d) => typeof d === \"number\" && d >= 0 && d < 2 ** 31)\n\t) {\n\t\tthrow new TypeError(\"TabMcp: reconnect.delaysMs: a non-empty list of ms\");\n\t}\n\treturn [...delays];\n}\n\n/** A delay option: `undefined`, or a whole wait `setTimeout` can keep (below 2^31 ms). */\nfunction delayOption(name: string, value: unknown): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (\n\t\ttypeof value !== \"number\" ||\n\t\t!Number.isFinite(value) ||\n\t\tvalue < 0 ||\n\t\tvalue >= 2 ** 31\n\t) {\n\t\tthrow new TypeError(`TabMcp: ${name} must be a number of milliseconds`);\n\t}\n\treturn value;\n}\n\n/** A grant as the page sees it: frozen, so a page cannot change what decides Always allow. */\nfunction frozenGrant(grant: Grant): Grant {\n\treturn Object.freeze({\n\t\t...grant,\n\t\tclient: Object.freeze({ ...grant.client }),\n\t});\n}\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\tpairing: m.pairing === \"oidc\" ? \"oidc\" : \"code\",\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 #alwaysAllow: boolean;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t/** The channel of the tabs that share the secret (DEC-095). */\n\treadonly #tabs: string | undefined;\n\t/** Replaced since the last session: `newAddress()` takes the address back first. */\n\t#takenOver = false;\n\treadonly #identityAssertion: IdentityAssertionHandler | undefined;\n\t#identity: IdentityState = \"none\";\n\t#identityMessage: string | undefined;\n\t/** Incremented per identity request, so a late answer of an older one is dropped. */\n\t#identityRound = 0;\n\treadonly #identityTimeoutMs: number;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: readonly Grant[] = Object.freeze([]);\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\t/** Waits between reconnect attempts; `undefined`: reconnecting is off. */\n\treadonly #reconnectDelays: readonly number[] | undefined;\n\t#reconnecting: ReconnectingInfo | undefined;\n\t#reconnectTimer: ReturnType<typeof setTimeout> | undefined;\n\t#unwatch: (() => void) | undefined;\n\t/** The page's `connect()` waits on the running reconnect attempt: its promise tells it. */\n\t#pageWaits = false;\n\t/** The open \"Connect your AI app\" dialog: one at a time. */\n\t#connectDialog: { doc: Document; shown: Promise<void> } | undefined;\n\t/**\n\t * What a tool call needs, through the relay and WebMCP alike. The events\n\t * always, even from a connection that is no longer current: a call that\n\t * started must end, and every end has its start.\n\t */\n\treadonly #calls: CallHost = {\n\t\tregistry: this.#registry,\n\t\tconfirm: (request) => this.#confirm(request),\n\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t};\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 = delayOption(\n\t\t\t\"confirmDelayMs\",\n\t\t\toptions.confirmDelayMs,\n\t\t);\n\t\tthis.#alwaysAllow = options.alwaysAllow === true;\n\t\tthis.#identityAssertion = options.identityAssertion;\n\t\tthis.#identityTimeoutMs =\n\t\t\tdelayOption(\"identityTimeoutMs\", options.identityTimeoutMs) ?? 15_000;\n\t\tthis.#reconnectDelays = reconnectDelays(options.reconnect);\n\t\t// One address per relay and page (server name); the default of 0.4 and\n\t\t// older, per relay only, is moved over once (DEC-083).\n\t\tconst key =\n\t\t\toptions.storageKey ??\n\t\t\t`tab-mcp:secret:${origin}:${encodeURIComponent(server.name)}`;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\tkey,\n\t\t\toptions.storageKey === undefined ? `tab-mcp:secret:${origin}` : undefined,\n\t\t);\n\t\t// Tabs that share the secret share this channel; with `storage: null`\n\t\t// every tab has an address of its own (DEC-095).\n\t\tthis.#tabs = options.storage === null ? undefined : `${key}#tabs`;\n\t\tthis.#registry.onChange(() =>\n\t\t\tthis.#emit(\"toolschange\", { tools: this.tools }),\n\t\t);\n\t\t// Also through the browser's own WebMCP, where it has it (DEC-115):\n\t\t// consequential tools only when their registration says so.\n\t\tconst context = options.webmcp === true ? nativeContext() : undefined;\n\t\tif (context !== undefined)\n\t\t\tmirror(\n\t\t\t\tthis.#registry,\n\t\t\t\tcontext,\n\t\t\t\t(tool) => tool.webmcp ?? tool.annotations.consequentialHint !== true,\n\t\t\t\t(tool, input, signal) =>\n\t\t\t\t\tthis.#load().then((lazy) =>\n\t\t\t\t\t\tlazy.callFromWebMcp(this.#calls, tool, input, signal),\n\t\t\t\t\t),\n\t\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<Input extends object = Record<string, unknown>>(\n\t\ttool: Tool<Input>,\n\t\toptions: RegisterToolOptions = {},\n\t): Promise<void> {\n\t\ttry {\n\t\t\t// The arguments are checked against `inputSchema` before `execute` runs.\n\t\t\tthis.#registry.register(tool as unknown as 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 (frozen; a new array when they change). */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/**\n\t * While the library connects again by itself after the connection broke:\n\t * the next attempt and when it starts. `undefined` otherwise.\n\t */\n\tget reconnecting(): ReconnectingInfo | undefined {\n\t\treturn this.#reconnecting;\n\t}\n\n\t/** Who the relay knows as the page's user (identity binding). */\n\tget identity(): IdentityState {\n\t\treturn this.#identity;\n\t}\n\n\t/** Why the relay refused the identity, while `identity` is `refused`. */\n\tget identityMessage(): string | undefined {\n\t\treturn this.#identityMessage;\n\t}\n\n\t/**\n\t * Ask the `identityAssertion` hook again and send the result, e.g. after\n\t * the user signed in without a page load. Resolves `true` once the relay\n\t * accepted it; `false` when nobody is signed in, it was refused, or the\n\t * page is not connected.\n\t */\n\trefreshIdentity(): Promise<boolean> {\n\t\tconst session = this.#session;\n\t\tconst ask = this.#identityAssertion;\n\t\tif (\n\t\t\tthis.#state !== \"connected\" ||\n\t\t\tsession === undefined ||\n\t\t\task === undefined\n\t\t) {\n\t\t\treturn Promise.resolve(false);\n\t\t}\n\t\tconst round = ++this.#identityRound;\n\t\tconst connection = this.#connection;\n\t\tthis.#setIdentity(\"pending\");\n\t\t// No answer in time, from the hook or the relay (an old relay, a lost\n\t\t// message, a hook that never settles): give up.\n\t\tconst timer = setTimeout(() => {\n\t\t\tif (round !== this.#identityRound || this.#identity !== \"pending\") return;\n\t\t\tthis.#identityRound++; // a late answer is dropped\n\t\t\tthis.#setIdentity(\"none\");\n\t\t}, this.#identityTimeoutMs);\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tconst settle = (event: TabMcpEventMap[\"identitychange\"]) => {\n\t\t\t\tif (event.detail.state === \"pending\") return;\n\t\t\t\tthis.removeEventListener(\"identitychange\", settle);\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(event.detail.state === \"bound\");\n\t\t\t};\n\t\t\tthis.addEventListener(\"identitychange\", settle);\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() =>\n\t\t\t\t\task({ address: session.address, sessionId: session.sessionId }),\n\t\t\t\t)\n\t\t\t\t.then(\n\t\t\t\t\t(assertion) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tround !== this.#identityRound ||\n\t\t\t\t\t\t\tthis.#connection !== connection\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Superseded (a newer request, a sign-out, a new connection): that one settles the state.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (typeof assertion !== \"string\" || assertion === \"\") {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tconnection?.send({ type: \"identity\", assertion, round }) !== true\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\t\t\tthis.#emit(\"error\", {\n\t\t\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * The page's user signed out: the relay ends every AI connection of this\n\t * address at once (identity binding). Call it from the web app's logout.\n\t * Returns `false` when it could not be sent (not connected); the grants\n\t * then stay, but work only while a page signed in as the same person is\n\t * open.\n\t */\n\tsignOut(): boolean {\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"identity.logout\" }) === true;\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 * While reconnecting (`reconnecting`), it makes the next attempt at once.\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) {\n\t\t\tif (this.#reconnecting !== undefined) this.#pageWaits = true;\n\t\t\treturn this.#connecting;\n\t\t}\n\t\tif (this.#reconnecting !== undefined) return this.#attemptReconnect(true);\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\treturn this.#start();\n\t}\n\n\t#start(revokeAll?: boolean): Promise<SessionInfo> {\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation, revokeAll);\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\t/**\n\t * The lazy chunk (on `connect()` or the first WebMCP call). The validator\n\t * is loaded with it: it checks the schemas from now on (DEC-086).\n\t */\n\tasync #load(): Promise<typeof import(\"./connection.ts\")> {\n\t\tconst lazy = await import(\"./connection.ts\");\n\t\tfor (const error of lazy.compileRegistry(this.#registry))\n\t\t\tthis.#emit(\"error\", { error });\n\t\treturn lazy;\n\t}\n\n\tasync #open(generation: number, revokeAll?: boolean): Promise<SessionInfo> {\n\t\tconst { openConnection, addressIdOf, withAddress } = await this.#load();\n\t\tconst secret = this.#secrets.get();\n\t\tconst address = await addressIdOf(secret);\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\twithAddress(this.#relayUrl, address),\n\t\t\tsecret,\n\t\t\trevokeAll,\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. After `replaced`, it first connects with the old address\n\t * again, so that the relay disconnects the apps that now talk to whoever\n\t * took it over (DEC-095), then connects with the new one. Call it from a\n\t * user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tif (this.#takenOver) {\n\t\t\t// `hello.revokeAll`: the relay revokes as it hands the address back, and\n\t\t\t// the connection resolves only once no grant is left. Taken over again\n\t\t\t// first: reject, keep the secret, so that a retry takes it back again.\n\t\t\tthis.#end(\"new_address\");\n\t\t\treturn this.#start(true).then(\n\t\t\t\t() => this.#renew(true),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tthis.#takenOver = true;\n\t\t\t\t\tthrow error;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn this.#renew(false);\n\t}\n\n\t#renew(on: boolean): Promise<SessionInfo | undefined> {\n\t\tconst wasOn =\n\t\t\ton || this.#state !== \"disconnected\" || this.#reconnecting !== undefined;\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\tthis.#takenOver = false; // nobody else has the new secret\n\t\t// It was on: the user chose that already, as for a reconnect.\n\t\treturn wasOn ? this.connect({ resume: true }) : 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.#stopReconnecting();\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.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** Wait, then connect again (attempt `attempt`, from 1). */\n\t#scheduleReconnect(reason: DisconnectReason, attempt: number): void {\n\t\tconst delays = this.#reconnectDelays;\n\t\tif (delays === undefined) return;\n\t\tconst delay = delays[Math.min(attempt, delays.length) - 1] ?? 0;\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = setTimeout(() => {\n\t\t\tthis.#attemptReconnect().catch(() => {}); // the next one is scheduled\n\t\t}, delay);\n\t\tthis.#watch();\n\t\tthis.#reconnecting = { reason, attempt, at: Date.now() + delay };\n\t\tthis.#emit(\"reconnecting\", this.#reconnecting);\n\t}\n\n\t/**\n\t * Make the next reconnect attempt now; on failure, schedule the one after.\n\t * `byPage`: from `connect()`, whose promise tells the page why it failed.\n\t */\n\t#attemptReconnect(byPage = false): Promise<SessionInfo> {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst info = this.#reconnecting;\n\t\tthis.#pageWaits = byPage;\n\t\tconst attempt = this.#start();\n\t\tattempt.catch((error: unknown) => {\n\t\t\tconst pageWaits = this.#pageWaits;\n\t\t\tthis.#pageWaits = false;\n\t\t\tif (info === undefined || this.#reconnecting !== info) return;\n\t\t\t// Only what may get better: an unreachable relay (network), a\n\t\t\t// heartbeat or a shutdown; a refusal stops it (DEC-082).\n\t\t\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\t\t\tif (reason === undefined || RECONNECT_REASONS.has(reason)) {\n\t\t\t\tthis.#scheduleReconnect(info.reason, info.attempt + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A refusal stops it. Without a connect() of the page's waiting on this\n\t\t\t// attempt, nothing else tells the page why: `error` does, before `null`.\n\t\t\tthis.#stopReconnecting(\n\t\t\t\tpageWaits\n\t\t\t\t\t? undefined\n\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: new Error(String(error)),\n\t\t\t);\n\t\t});\n\t\treturn attempt;\n\t}\n\n\t/** Back to the front, or online again: try at once instead of waiting. */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst doc = (globalThis as { document?: Document }).document;\n\t\tconst now = () => {\n\t\t\t// Only while waiting: an attempt that is running is not doubled.\n\t\t\tif (this.#reconnectTimer !== undefined)\n\t\t\t\tthis.#attemptReconnect().catch(() => {});\n\t\t};\n\t\tconst visible = () => {\n\t\t\tif (doc?.visibilityState !== \"hidden\") now();\n\t\t};\n\t\tdoc?.addEventListener(\"visibilitychange\", visible);\n\t\tg.addEventListener?.(\"online\", now);\n\t\tthis.#unwatch = () => {\n\t\t\tdoc?.removeEventListener(\"visibilitychange\", visible);\n\t\t\tg.removeEventListener?.(\"online\", now);\n\t\t};\n\t}\n\n\t/**\n\t * Stop reconnecting. `why` (a refusal) goes out as `error` before the\n\t * `null`, once the state is clear: a listener that calls `connect()` then\n\t * starts afresh, with the user-activation check.\n\t */\n\t#stopReconnecting(why?: Error): void {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tthis.#unwatch?.();\n\t\tthis.#unwatch = undefined;\n\t\tif (this.#reconnecting === undefined) return;\n\t\tthis.#reconnecting = undefined;\n\t\tif (why !== undefined) this.#emit(\"error\", { error: why });\n\t\tthis.#emit(\"reconnecting\", null);\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. One dialog at\n\t * a time (they would share one pairing): while it is open, a call for the\n\t * same document opens no second one and resolves with it, and a call for\n\t * another document rejects with an `InvalidStateError`. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tshowConnectDialog(options: { document?: Document } = {}): Promise<void> {\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tconst open = this.#connectDialog;\n\t\tif (open !== undefined) {\n\t\t\treturn open.doc === doc\n\t\t\t\t? open.shown\n\t\t\t\t: Promise.reject(\n\t\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\t\"showConnectDialog: the dialog is already open in another document\",\n\t\t\t\t\t\t\t\"InvalidStateError\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t}\n\t\tconst shown = this.#showConnectDialog(doc).finally(() => {\n\t\t\tif (this.#connectDialog?.shown === shown) this.#connectDialog = undefined;\n\t\t});\n\t\tthis.#connectDialog = { doc, shown };\n\t\treturn shown;\n\t}\n\n\tasync #showConnectDialog(doc: Document): 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(this, connecting, doc, this.#server.name);\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#setIdentity(state: IdentityState, message?: string): void {\n\t\tif (this.#identity === state && message === undefined) return;\n\t\tthis.#identity = state;\n\t\tthis.#identityMessage = state === \"refused\" ? message : undefined;\n\t\tthis.#emit(\n\t\t\t\"identitychange\",\n\t\t\tmessage === undefined ? { state } : { state, message },\n\t\t);\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: readonly Grant[]): void {\n\t\tthis.#grants = Object.freeze(grants.map(frozenGrant));\n\t\tthis.#emit(\"grantschange\", { grants: this.#grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<ConfirmAnswer> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\t// Anything but true or \"unanswered\" is a refusal.\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((answer) => (answer === \"unanswered\" ? answer : answer === true));\n\t\t}\n\t\treturn this.confirmInPage(request);\n\t}\n\n\t/**\n\t * The library's own confirmation: the dialog in the page with Don't allow\n\t * and Allow, and Always allow with `alwaysAllow: true` (what runs without\n\t * `onConfirm`). An `onConfirm`\n\t * may hand some calls to it. Resolves `false` where there is no document.\n\t */\n\tconfirmInPage(request: ConfirmRequest): Promise<boolean> {\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\t// The tools allowed always live in the UI chunk too: only it adds them.\n\t\treturn import(\"./ui.ts\").then((ui) =>\n\t\t\tui.confirmInPage(this, request, doc, {\n\t\t\t\tallowDelayMs: this.#confirmDelayMs,\n\t\t\t\talwaysAllow: this.#alwaysAllow,\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\tlet replacedHere = false;\n\t\treturn {\n\t\t\t...this.#calls,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\ttabs: this.#tabs,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\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: RelayClient = {\n\t\t\t\t\tkind: \"relay\",\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.#takenOver = false;\n\t\t\t\tthis.#stopReconnecting();\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\tif (session.pairing === \"oidc\") void this.refreshIdentity();\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\t// After `closed`, so no longer current: only a connection that was\n\t\t\t// current when it was replaced reports it.\n\t\t\treplaced: (detail) => {\n\t\t\t\tif (replacedHere) this.#emit(\"replaced\", detail);\n\t\t\t},\n\t\t\tidentityResult: (bound, round, message) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Only the answer to the newest assertion counts: the relay echoes\n\t\t\t\t// its round, so a lost or late answer cannot pass for a newer one.\n\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\tif (bound) this.#setIdentity(\"bound\");\n\t\t\t\telse this.#setIdentity(\"refused\", message ?? \"\");\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\t// Taken over: `newAddress()` takes it back first, whatever runs by\n\t\t\t\t// then (review of PR 39).\n\t\t\t\tif (reason === \"replaced\") this.#takenOver = replacedHere = true;\n\t\t\t\t// Any listener below may end it all (`disconnect()`, `newAddress()`):\n\t\t\t\t// that bumps the generation, and then nothing is scheduled.\n\t\t\t\tconst generation = this.#generation;\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.#identityRound++;\n\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t\t// After the page heard of it: its listener may have connected or ended it.\n\t\t\t\tif (\n\t\t\t\t\tRECONNECT_REASONS.has(reason) &&\n\t\t\t\t\tthis.#generation === generation &&\n\t\t\t\t\tthis.#state === \"disconnected\" &&\n\t\t\t\t\tthis.#connecting === undefined\n\t\t\t\t)\n\t\t\t\t\tthis.#scheduleReconnect(reason, 1);\n\t\t\t},\n\t\t};\n\t}\n}\n"
|
|
8
|
+
"/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. Part of the\n * core: only the detection, the registrations and the `<html>` attribute;\n * a call loads the lazy chunk, which checks, confirms and runs it.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\n\n/** What the library uses of the browser's `ModelContext`. */\nexport interface ModelContext {\n\tregisterTool(\n\t\ttool: object,\n\t\toptions: { signal: AbortSignal; exposedTo: string[] | undefined },\n\t): unknown;\n}\n\n/** Runs a call of a mirrored tool; `signal` is the browser's, if it gives one. */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n) => Promise<unknown>;\n\n/**\n * The browser's own `ModelContext` of this document, read when a `TabMcp` is\n * made, through `Document.prototype`'s getter: never an own\n * `document.modelContext` (a polyfill such as `@mcp-b/global`, or any page\n * script; DEC-115). `undefined` without native WebMCP or a document.\n */\nexport function nativeContext(): ModelContext | undefined {\n\ttry {\n\t\treturn Object.getOwnPropertyDescriptor(\n\t\t\tDocument.prototype,\n\t\t\t\"modelContext\",\n\t\t)?.get?.call(document);\n\t} catch {\n\t\treturn undefined; // no document\n\t}\n}\n\n/** The WebMCP hints; the MCP-only ones are left out. */\nconst HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\n\n/**\n * Mirror `registry`'s tools into `context`, now and whenever the registry\n * changes: those whose `callers` list `\"webmcp\"`, and without `callers` those\n * not marked consequential, where MCP's `destructiveHint` counts as\n * `consequentialHint` (DEC-143, DEC-165). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n): void {\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst sync = (): void => {\n\t\tfor (const [tool, controller] of mirrors) {\n\t\t\tif (registry.get(tool.name) === tool) continue;\n\t\t\tcontroller.abort();\n\t\t\tmirrors.delete(tool);\n\t\t}\n\t\tfor (const tool of registry.list()) {\n\t\t\tconst { annotations, callers } = tool;\n\t\t\tconst consequential =\n\t\t\t\tannotations.consequentialHint ?? annotations.destructiveHint;\n\t\t\t// The one place of the rule for WebMCP (the relay and a port: `toolsFor`).\n\t\t\tif (mirrors.has(tool) || !(callers?.includes(\"webmcp\") ?? !consequential))\n\t\t\t\tcontinue;\n\t\t\tconst controller = new AbortController();\n\t\t\tmirrors.set(tool, controller);\n\t\t\tconst hints: Record<string, boolean | undefined> = {\n\t\t\t\tconsequentialHint: consequential,\n\t\t\t};\n\t\t\tfor (const key of HINTS) hints[key] ??= annotations[key];\n\t\t\tconst { signal } = controller;\n\t\t\tPromise.resolve()\n\t\t\t\t// Not once unmirrored: whatever the browser does with an aborted\n\t\t\t\t// signal.\n\t\t\t\t.then(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\t\tcontext.registerTool(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t// WebIDL dictionaries: `undefined` is the same as left out.\n\t\t\t\t\t\t\t\ttitle: tool.title,\n\t\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t\t\t\t\t\toutputSchema: tool.outputSchema,\n\t\t\t\t\t\t\t\tannotations: hints,\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(tool, input, options?.signal),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal, exposedTo: tool.exposedTo },\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // unmirrored meanwhile\n\t\t\t\t\tif (warned.has(tool.name)) return;\n\t\t\t\t\twarned.add(tool.name);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`tab-mcp: ${tool.name} is not offered through WebMCP:`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t};\n\tregistry.onChange(sync);\n\tsync();\n}\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 type { CallHost, ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage, TabMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmAnswer,\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDialogOptions,\n\tDisconnectReason,\n\tGrant,\n\tIdentityAssertionHandler,\n\tIdentityState,\n\tPairingCode,\n\tReconnectingInfo,\n\tRegisterToolOptions,\n\tRelayClient,\n\tServeHandle,\n\tServeOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n\tTunnelPort,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\nimport { mirror, nativeContext } from \"./webmcp.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/**\n * The library's waits, in milliseconds: constants for pages (CU 17), which\n * only tests change. `reconnectDelaysMs`: before each reconnect attempt,\n * the last one repeating. `answerTimeoutMs`: for an identity assertion and\n * the relay's answer to it, and for the relay's answer to `revoke()` and\n * `signOut()`.\n */\nexport const timing: {\n\treconnectDelaysMs: number[];\n\tanswerTimeoutMs: number;\n} = {\n\treconnectDelaysMs: [5_000, 10_000, 20_000, 40_000, 60_000],\n\tanswerTimeoutMs: 15_000,\n};\n/** Reasons after which the library connects again by itself. */\nconst RECONNECT_REASONS = new Set<DisconnectReason>([\n\t\"network\",\n\t\"heartbeat\",\n\t\"shutdown\",\n]);\n\n/** A grant as the page sees it: frozen, so a page cannot change what decides Always allow. */\nfunction frozenGrant(grant: Grant): Grant {\n\treturn Object.freeze({\n\t\t...grant,\n\t\tclient: Object.freeze({ ...grant.client }),\n\t});\n}\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\tpairing: m.pairing === \"oidc\" ? \"oidc\" : \"code\",\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\n/** What `connect()`, `showConnectDialog()` and `newAddress()` reject with without a relay. */\nfunction noRelay(): Promise<never> {\n\treturn Promise.reject(new TypeError(\"TabMcp: this TabMcp has no relay\"));\n}\n\n/** What a method that asks the relay rejects with while it cannot. */\nfunction notConnected(): Promise<never> {\n\treturn Promise.reject(\n\t\tnew DOMException(\"TabMcp: not connected\", \"InvalidStateError\"),\n\t);\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 (and, without\n * `relay`, only through `serve` and WebMCP).\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * await 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 #alwaysAllow: boolean;\n\treadonly #ui: DialogOptions | undefined;\n\t/** `undefined` without a relay: tools only through `serve` and WebMCP. */\n\treadonly #relayUrl: string | undefined;\n\treadonly #secrets: SecretStore | undefined;\n\t/** The channel of the tabs that share the secret (DEC-095). */\n\treadonly #tabs: string | undefined;\n\t/**\n\t * The page was on when a takeover ended its session (or when a\n\t * `newAddress()` failed), and nothing was ended since: the next\n\t * `newAddress()` connects with the new address. Only that; whether it\n\t * takes the old address back does not depend on it (DEC-136).\n\t */\n\t#stayOn = false;\n\t/** The running `newAddress()`: a second call returns it, `connect()` waits for it. */\n\t#renewing: Promise<void> | undefined;\n\treadonly #identityAssertion: IdentityAssertionHandler | undefined;\n\t#identity: IdentityState = \"none\";\n\t#identityMessage: string | undefined;\n\t/** Incremented per identity request, so a late answer of an older one is dropped. */\n\t#identityRound = 0;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: readonly Grant[] = Object.freeze([]);\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\treadonly #reconnect: boolean;\n\t#reconnecting: ReconnectingInfo | undefined;\n\t#reconnectTimer: ReturnType<typeof setTimeout> | undefined;\n\t#unwatch: (() => void) | undefined;\n\t/** The open \"Connect your AI app\" dialog: one at a time. */\n\t#connectDialog: { doc: Document; shown: Promise<void> } | undefined;\n\t/**\n\t * What a tool call needs, through the relay and WebMCP alike. The events\n\t * always, even from a connection that is no longer current: a call that\n\t * started must end, and every end has its start.\n\t */\n\treadonly #calls: CallHost = {\n\t\tregistry: this.#registry,\n\t\tconfirm: (request) => this.#confirm(request),\n\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t};\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { server, appName } = options;\n\t\tconst relay =\n\t\t\toptions.relay === undefined ? undefined : tabUrl(options.relay);\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 = relay?.url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#alwaysAllow = options.alwaysAllow === true;\n\t\tthis.#ui = options.ui;\n\t\tthis.#identityAssertion = options.identityAssertion;\n\t\tthis.#reconnect = options.reconnect !== false;\n\t\tif (relay !== undefined) {\n\t\t\t// One address per relay and page (server name); the default of 0.4 and\n\t\t\t// older, per relay only, is moved over once (DEC-083).\n\t\t\tconst key =\n\t\t\t\toptions.storageKey ??\n\t\t\t\t`tab-mcp:secret:${relay.origin}:${encodeURIComponent(server.name)}`;\n\t\t\tthis.#secrets = new SecretStore(\n\t\t\t\toptions.storage,\n\t\t\t\tkey,\n\t\t\t\toptions.storageKey === undefined\n\t\t\t\t\t? `tab-mcp:secret:${relay.origin}`\n\t\t\t\t\t: undefined,\n\t\t\t);\n\t\t\t// Tabs that share the secret share this channel; with `storage: null`\n\t\t\t// every tab has an address of its own (DEC-095).\n\t\t\tthis.#tabs = options.storage === null ? undefined : `${key}#tabs`;\n\t\t}\n\t\tthis.#registry.onChange(() =>\n\t\t\tthis.#emit(\"toolschange\", { tools: this.tools }),\n\t\t);\n\t\t// Also through the browser's own WebMCP, where it has it (DEC-115):\n\t\t// consequential tools only when their registration says so.\n\t\tconst context = options.webmcp === true ? nativeContext() : undefined;\n\t\tif (context !== undefined)\n\t\t\tmirror(this.#registry, context, (tool, input, signal) =>\n\t\t\t\tthis.#load().then((lazy) =>\n\t\t\t\t\tlazy.callFromWebMcp(this.#calls, tool, input, signal),\n\t\t\t\t),\n\t\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 (the\n\t * tool is registered, or refused, before it returns); await it or catch\n\t * the rejection (DEC-010).\n\t */\n\tregisterTool<Input extends object = Record<string, unknown>>(\n\t\ttool: Tool<Input>,\n\t\toptions: RegisterToolOptions = {},\n\t): Promise<void> {\n\t\ttry {\n\t\t\t// The arguments are checked against `inputSchema` before `execute` runs.\n\t\t\tthis.#registry.register(tool as unknown as 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: its `address` is the one to give to AI apps. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The AI apps connected to this address (frozen; a new array when they change). */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/**\n\t * While `state` is `reconnecting`: the next (or running) attempt and when\n\t * it starts. `undefined` otherwise.\n\t */\n\tget reconnecting(): ReconnectingInfo | undefined {\n\t\treturn this.#reconnecting;\n\t}\n\n\t/** Who the relay knows as the page's user (identity binding). */\n\tget identity(): IdentityState {\n\t\treturn this.#identity;\n\t}\n\n\t/** Why the relay refused the identity, while `identity` is `refused`. */\n\tget identityMessage(): string | undefined {\n\t\treturn this.#identityMessage;\n\t}\n\n\t/**\n\t * Ask the `identityAssertion` hook again and send the result, e.g. after\n\t * the user signed in without a page load. Resolves with the outcome, the\n\t * new `identity`: `bound` once the relay accepted it, `refused`, or `none`\n\t * when nobody is signed in or no answer came in time. Rejects with an\n\t * `InvalidStateError` while not connected, and with a `TypeError` without\n\t * the hook.\n\t */\n\trefreshIdentity(): Promise<IdentityState> {\n\t\tconst session = this.#session;\n\t\tconst ask = this.#identityAssertion;\n\t\tif (ask === undefined)\n\t\t\treturn Promise.reject(new TypeError(\"TabMcp: no identityAssertion\"));\n\t\tif (session === undefined) return notConnected();\n\t\tconst round = ++this.#identityRound;\n\t\tconst connection = this.#connection;\n\t\tthis.#setIdentity(\"pending\");\n\t\t// No answer in time, from the hook or the relay (an old relay, a lost\n\t\t// message, a hook that never settles): give up.\n\t\tconst timer = setTimeout(() => {\n\t\t\tif (round !== this.#identityRound || this.#identity !== \"pending\") return;\n\t\t\tthis.#identityRound++; // a late answer is dropped\n\t\t\tthis.#setIdentity(\"none\");\n\t\t}, timing.answerTimeoutMs);\n\t\treturn new Promise<IdentityState>((resolve) => {\n\t\t\tconst settle = (event: TabMcpEventMap[\"identitychange\"]) => {\n\t\t\t\tconst { identity } = event.detail;\n\t\t\t\tif (identity === \"pending\") return;\n\t\t\t\tthis.removeEventListener(\"identitychange\", settle);\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(identity);\n\t\t\t};\n\t\t\tthis.addEventListener(\"identitychange\", settle);\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() =>\n\t\t\t\t\task({ address: session.address, sessionId: session.sessionId }),\n\t\t\t\t)\n\t\t\t\t.then(\n\t\t\t\t\t(assertion) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tround !== this.#identityRound ||\n\t\t\t\t\t\t\tthis.#connection !== connection\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Superseded (a newer request, a sign-out, a new connection): that one settles the state.\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (typeof assertion !== \"string\" || assertion === \"\") {\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tconnection?.send({ type: \"identity\", assertion, round }) !== true\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\t\t\tthis.#emit(\"error\", {\n\t\t\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * The page's user signed out: the relay ends every AI connection of this\n\t * address at once (identity binding). Call it from the web app's logout.\n\t * `identity` goes to `none` at once. Resolves once the relay removed the\n\t * grants; rejects with an `InvalidStateError` while not connected to a\n\t * relay that pairs by sign-in (`session.pairing` is `oidc`), and when the\n\t * session ends first. Grants that stay work only while a page signed in\n\t * as the same person is open.\n\t */\n\tsignOut(): Promise<void> {\n\t\tthis.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\treturn this.#session?.pairing === \"oidc\"\n\t\t\t? this.#ask({ type: \"identity.logout\" }, () => !this.#grants.length)\n\t\t\t: notConnected();\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 * While `reconnecting`, it makes the next attempt at once.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#relayUrl === undefined) return noRelay();\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\tif (this.#reconnecting !== undefined) return this.#attemptReconnect();\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\t// While `newAddress()` runs: afterwards, with the new address.\n\t\treturn this.#renewing\n\t\t\t? this.#renewing.then(() => this.connect({ resume: true }))\n\t\t\t: this.#start();\n\t}\n\n\t/** Open the page's connection; a reconnect attempt stays `reconnecting`. */\n\t#start(): Promise<SessionInfo> {\n\t\tif (!this.#reconnecting) this.#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\t// A failed attempt: the next one is scheduled, or it stops.\n\t\t\t\tif (!this.#reconnecting) this.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\t/**\n\t * The lazy chunk (on `connect()` or the first WebMCP call). The validator\n\t * is loaded with it: it checks the schemas from now on (DEC-086).\n\t */\n\tasync #load(): Promise<typeof import(\"./connection.ts\")> {\n\t\tconst lazy = await import(\"./connection.ts\");\n\t\tfor (const error of lazy.compileRegistry(this.#registry))\n\t\t\tthis.#emit(\"error\", { error });\n\t\treturn lazy;\n\t}\n\n\t/**\n\t * Open a connection. `takeBack`: the secret of an address to take back\n\t * (`hello.revokeAll`, DEC-095); that connection is never current, so its\n\t * session and events stay unseen, but `#end` closes it.\n\t */\n\tasync #open(generation: number, takeBack?: string): Promise<SessionInfo> {\n\t\tconst { openConnection, addressIdOf, withAddress } = await this.#load();\n\t\tconst relayUrl = this.#relayUrl;\n\t\tif (relayUrl === undefined || this.#secrets === undefined) return noRelay();\n\t\tconst secret =\n\t\t\ttakeBack ?? this.#secrets.current() ?? this.#secrets.rotate();\n\t\tconst address = await addressIdOf(secret);\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\twithAddress(relayUrl, address),\n\t\t\tsecret,\n\t\t\t{ address, revokeAll: !!takeBack },\n\t\t);\n\t\tif (!takeBack) ref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** Whether this `TabMcp` has a relay; without one, `connect()` rejects. */\n\tget hasRelay(): boolean {\n\t\treturn this.#relayUrl !== undefined;\n\t}\n\n\t/**\n\t * Serve the tools over a port, without a relay: for this site's own\n\t * assistant, e.g. a chat in an iframe whose backend calls the tools through\n\t * `createTunnelFetch` (`@ractive-ch/tab-mcp-client/tunnel`). The port\n\t * carries the relay's `http.*` messages as plain objects; a `MessagePort`\n\t * fits. Whoever holds the other end calls the tools without pairing, as\n\t * `options.client` (`kind: \"local\"`): hand it out only to a frame whose\n\t * origin you checked. Consequential tools still ask: `options.onConfirm`\n\t * for this port's calls (in the site's chat, say), else the page's\n\t * `onConfirm` or dialog. Each request may take `options.requestTimeoutMs`\n\t * (300 s). Only tools whose `callers` include `\"local\"` (by default all)\n\t * are listed and callable. Resolves once the port\n\t * is served; may be called for several ports. Rejects with a `TypeError`\n\t * for options it cannot use.\n\t */\n\tserve(port: TunnelPort, options: ServeOptions): Promise<ServeHandle> {\n\t\treturn this.#load().then((lazy) =>\n\t\t\tlazy.servePort(\n\t\t\t\t{\n\t\t\t\t\t...this.#calls,\n\t\t\t\t\tserver: this.#server,\n\t\t\t\t\terror: (error) => this.#emit(\"error\", { error }),\n\t\t\t\t},\n\t\t\t\tport,\n\t\t\t\toptions,\n\t\t\t),\n\t\t);\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. If the page has one already, it first takes it back: it\n\t * connects with the old secret and the relay revokes every grant of it in\n\t * the same step (`hello.revokeAll`, DEC-095, DEC-136), connected or not,\n\t * taken over or not. Then it makes a new secret and connects with it if\n\t * the page was connected, connecting or reconnecting, and resolves once\n\t * that is done (the new session is `session`). Rejects, and keeps the old\n\t * secret so that a retry takes it back again, when the old address could\n\t * not be taken back (relay unreachable, taken over again first). Call it\n\t * from a user action.\n\t */\n\tnewAddress(): Promise<void> {\n\t\t// Without a relay there is no secret store.\n\t\tconst secrets = this.#secrets;\n\t\tif (!secrets) return noRelay();\n\t\t// biome-ignore lint/suspicious/noAssignInExpressions: one promise per run\n\t\treturn (this.#renewing ??= this.#renew(secrets).finally(() => {\n\t\t\tthis.#renewing = undefined;\n\t\t}));\n\t}\n\n\tasync #renew(secrets: SecretStore): Promise<void> {\n\t\tconst wasOn = this.#state !== \"disconnected\" || this.#stayOn;\n\t\t// Read now, also when the page is off or was taken over (CC 4). Another\n\t\t// tab that rotated the secret since took the address it had back itself.\n\t\tconst old = secrets.current();\n\t\tthis.#end(\"new_address\");\n\t\tconst generation = this.#generation;\n\t\tif (old) {\n\t\t\tthis.#setState(\"connecting\");\n\t\t\ttry {\n\t\t\t\tawait this.#open(generation, old);\n\t\t\t} catch (error) {\n\t\t\t\tif (generation === this.#generation) {\n\t\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\t\tthis.#stayOn = wasOn; // a retry does the same\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\t// The take-back connection, unless `#end` closed it already.\n\t\t\t\tif (generation === this.#generation) {\n\t\t\t\t\tthis.#connection?.close(\"new_address\");\n\t\t\t\t\tthis.#connection = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tsecrets.rotate();\n\t\t// The relay revoked them (CC 14).\n\t\tthis.#setGrants([]);\n\t\t// It was on: the user chose that already, as for a reconnect.\n\t\tif (wasOn) await this.#start();\n\t\telse this.#setState(\"disconnected\");\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.#stopReconnecting();\n\t\tthis.#stayOn = false;\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\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.#identityRound++;\n\t\tthis.#setIdentity(\"none\");\n\t\t// With the reason also when it ended connecting or reconnecting: the\n\t\t// page turned it off (or got a new address) all the same.\n\t\tthis.#setState(\"disconnected\", reason);\n\t}\n\n\t/**\n\t * Wait, then connect again (attempt `attempt`, from 1); `state` is\n\t * `reconnecting`, and `statechange` says so for each attempt.\n\t */\n\t#scheduleReconnect(reason: DisconnectReason, attempt: number): void {\n\t\tconst delays = timing.reconnectDelaysMs;\n\t\t// Up to 20 % either way, so that the tabs a relay restart disconnected\n\t\t// do not all come back at the same moment (CC 11).\n\t\tconst delay =\n\t\t\t(delays[Math.min(attempt, delays.length) - 1] ?? 0) *\n\t\t\t(0.8 + 0.4 * Math.random());\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = setTimeout(() => {\n\t\t\tthis.#attemptReconnect().catch(() => {}); // the next one is scheduled\n\t\t}, delay);\n\t\tthis.#watch();\n\t\tthis.#reconnecting = { reason, attempt, at: Date.now() + delay };\n\t\tthis.#setState(\"reconnecting\", attempt > 1 ? undefined : reason);\n\t}\n\n\t/** Make the next reconnect attempt now; on failure, schedule the one after. */\n\t#attemptReconnect(): Promise<SessionInfo> {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst attempt = this.#start();\n\t\tattempt.catch((error: unknown) => {\n\t\t\t// Read now, not when the attempt started: a listener before this may\n\t\t\t// have ended it all or started the next attempt, which then owns the\n\t\t\t// next step (CC 10).\n\t\t\tconst info = this.#reconnecting;\n\t\t\tif (info === undefined || this.#connecting !== undefined) return;\n\t\t\t// Only what may get better: an unreachable relay (network), a\n\t\t\t// heartbeat or a shutdown; a refusal stops it (DEC-082).\n\t\t\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\t\t\tif (reason === undefined || RECONNECT_REASONS.has(reason)) {\n\t\t\t\tthis.#scheduleReconnect(info.reason, info.attempt + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A refusal stops it, and `error` says why, before `statechange`.\n\t\t\t// The state is `disconnected` already, so that a `connect()` from\n\t\t\t// the listener starts afresh (with the user-activation check).\n\t\t\tthis.#stopReconnecting();\n\t\t\tthis.#state = \"disconnected\";\n\t\t\tthis.#emit(\"error\", {\n\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t});\n\t\t\tif (this.#state === \"disconnected\")\n\t\t\t\tthis.#emit(\"statechange\", { state: \"disconnected\" });\n\t\t});\n\t\treturn attempt;\n\t}\n\n\t/** Back to the front, or online again: try at once instead of waiting. */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst doc = (globalThis as { document?: Document }).document;\n\t\tconst now = () => {\n\t\t\t// Only while waiting: an attempt that is running is not doubled.\n\t\t\tif (this.#reconnectTimer !== undefined)\n\t\t\t\tthis.#attemptReconnect().catch(() => {});\n\t\t};\n\t\tconst visible = () => {\n\t\t\tif (doc?.visibilityState !== \"hidden\") now();\n\t\t};\n\t\tdoc?.addEventListener(\"visibilitychange\", visible);\n\t\tg.addEventListener?.(\"online\", now);\n\t\tthis.#unwatch = () => {\n\t\t\tdoc?.removeEventListener(\"visibilitychange\", visible);\n\t\t\tg.removeEventListener?.(\"online\", now);\n\t\t};\n\t}\n\n\t/** Stop reconnecting; the caller sets the state that follows. */\n\t#stopReconnecting(): void {\n\t\tclearTimeout(this.#reconnectTimer);\n\t\tthis.#reconnectTimer = undefined;\n\t\tthis.#unwatch?.();\n\t\tthis.#unwatch = undefined;\n\t\tthis.#reconnecting = undefined;\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. Resolves once\n\t * the relay removed the grant (at once for one that is not in `grants`).\n\t * Rejects with an `InvalidStateError` while not connected (only the relay\n\t * can do it) and when the session ends first, and with the relay's error\n\t * when it refuses (its `code` is `store_unavailable` when it could not\n\t * save the change: try again; `unknown_id` for a grant it does not know).\n\t */\n\trevoke(grantId: string): Promise<void> {\n\t\tconst gone = () => !this.#grants.some((g) => g.grantId === grantId);\n\t\treturn gone()\n\t\t\t? Promise.resolve()\n\t\t\t: this.#ask({ type: \"grant.revoke\", grantId }, gone);\n\t}\n\n\t/**\n\t * Send `message` to the relay and resolve once `done()` holds (it is\n\t * checked on each change of the grants). Rejects when not connected, when\n\t * the session ends first, with the relay's refusal (`store_unavailable`:\n\t * it could not save the change; `unknown_id`), and with a `TimeoutError`\n\t * when none of that happened within `timing.answerTimeoutMs`.\n\t */\n\t#ask(message: TabMessage, done: () => boolean): Promise<void> {\n\t\tif (!this.#session || this.#connection?.send(message) !== true)\n\t\t\treturn notConnected();\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst types = [\"grantschange\", \"statechange\", \"error\"];\n\t\t\tconst settle = (error?: unknown) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tfor (const type of types) this.removeEventListener(type, check);\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t};\n\t\t\tconst check = (event?: Event) => {\n\t\t\t\tconst error = (event as Partial<TabMcpEventMap[\"error\"]>)?.detail\n\t\t\t\t\t?.error as { code?: string } | undefined;\n\t\t\t\tif (done()) settle();\n\t\t\t\telse if (\n\t\t\t\t\terror?.code === \"store_unavailable\" ||\n\t\t\t\t\terror?.code === \"unknown_id\"\n\t\t\t\t)\n\t\t\t\t\tsettle(error);\n\t\t\t\telse if (this.#state !== \"connected\")\n\t\t\t\t\tsettle(\n\t\t\t\t\t\tnew DOMException(\"TabMcp: not connected\", \"InvalidStateError\"),\n\t\t\t\t\t);\n\t\t\t};\n\t\t\tconst timer = setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\tsettle(\n\t\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\t\"TabMcp: the relay did not answer\",\n\t\t\t\t\t\t\t\"TimeoutError\",\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\ttiming.answerTimeoutMs,\n\t\t\t);\n\t\t\tfor (const type of types) this.addEventListener(type, check);\n\t\t\tcheck();\n\t\t});\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. One dialog at\n\t * a time (they would share one pairing): while it is open, a call for the\n\t * same document opens no second one and resolves with it, and a call for\n\t * another document rejects with an `InvalidStateError`. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tshowConnectDialog(options: { document?: Document } = {}): Promise<void> {\n\t\tif (this.#relayUrl === undefined) return noRelay();\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tconst open = this.#connectDialog;\n\t\tif (open !== undefined) {\n\t\t\treturn open.doc === doc\n\t\t\t\t? open.shown\n\t\t\t\t: Promise.reject(\n\t\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\t\"showConnectDialog: the dialog is already open in another document\",\n\t\t\t\t\t\t\t\"InvalidStateError\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t}\n\t\tconst shown = this.#showConnectDialog(doc).finally(() => {\n\t\t\tif (this.#connectDialog?.shown === shown) this.#connectDialog = undefined;\n\t\t});\n\t\tthis.#connectDialog = { doc, shown };\n\t\treturn shown;\n\t}\n\n\tasync #showConnectDialog(doc: Document): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./connect.ts\");\n\t\tawait showConnectDialog(this, connecting, doc, this.#server.name, this.#ui);\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/** A new state; `reconnecting` again means the next attempt was scheduled. */\n\t#setState(state: ConnectionState, reason?: DisconnectReason): void {\n\t\tif (this.#state === state && state !== \"reconnecting\") return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", reason ? { state, reason } : { state });\n\t}\n\n\t#setIdentity(identity: IdentityState, message?: string): void {\n\t\tif (this.#identity === identity && message === undefined) return;\n\t\tthis.#identity = identity;\n\t\tthis.#identityMessage = identity === \"refused\" ? message : undefined;\n\t\tthis.#emit(\"identitychange\", {\n\t\t\tidentity,\n\t\t\tidentityMessage: this.#identityMessage,\n\t\t});\n\t}\n\n\t#setPairingCode(pairingCode: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && pairingCode === undefined) return;\n\t\tthis.#pairingCode = pairingCode;\n\t\tthis.#emit(\"pairingcode\", { pairingCode });\n\t}\n\n\t#setGrants(grants: readonly Grant[]): void {\n\t\tthis.#grants = Object.freeze(grants.map(frozenGrant));\n\t\tthis.#emit(\"grantschange\", { grants: this.#grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<ConfirmAnswer> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\t// Anything but true or \"unanswered\" is a refusal.\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((answer) => (answer === \"unanswered\" ? answer : answer === true));\n\t\t}\n\t\treturn this.confirmInPage(request);\n\t}\n\n\t/**\n\t * The library's own confirmation: the dialog in the page with Don't allow\n\t * and Allow, and Allow until reload with `alwaysAllow: true` (what runs\n\t * without `onConfirm`), in `options.document` (default: the global one).\n\t * An `onConfirm` may hand some calls to it. Resolves `false` where there\n\t * is no document.\n\t */\n\tconfirmInPage(\n\t\trequest: ConfirmRequest,\n\t\toptions: { document?: Document } = {},\n\t): Promise<boolean> {\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\t// The tools allowed until reload live in the dialogs' chunks too: only they add them.\n\t\treturn import(\"./confirm.ts\").then((ui) =>\n\t\t\tui.confirmInPage(this, request, doc, {\n\t\t\t\talwaysAllow: this.#alwaysAllow,\n\t\t\t\tui: this.#ui,\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\tlet replacedHere = false;\n\t\treturn {\n\t\t\t...this.#calls,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\ttabs: this.#tabs,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\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: RelayClient = {\n\t\t\t\t\tkind: \"relay\",\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.#stayOn = false;\n\t\t\t\tthis.#stopReconnecting();\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.#setState(\"connected\");\n\t\t\t\tif (session.pairing === \"oidc\" && this.#identityAssertion)\n\t\t\t\t\tvoid this.refreshIdentity();\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\t// After `closed`, so no longer current: only a connection that was\n\t\t\t// current when it was replaced reports it.\n\t\t\treplaced: (detail) => {\n\t\t\t\tif (replacedHere) this.#emit(\"replaced\", detail);\n\t\t\t},\n\t\t\tidentityResult: (bound, round, message) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\t// Only the answer to the newest assertion counts: the relay echoes\n\t\t\t\t// its round, so a lost or late answer cannot pass for a newer one.\n\t\t\t\tif (round !== this.#identityRound) return;\n\t\t\t\tif (bound) this.#setIdentity(\"bound\");\n\t\t\t\telse this.#setIdentity(\"refused\", message ?? \"\");\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) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tif (reason === \"replaced\") this.#stayOn = replacedHere = true;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\t// Any listener of these may end it all (`disconnect()`,\n\t\t\t\t// `newAddress()`): that bumps the generation.\n\t\t\t\tconst generation = this.#generation;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#identityRound++;\n\t\t\t\tthis.#setIdentity(\"none\");\n\t\t\t\tif (generation !== this.#generation) return;\n\t\t\t\t// Reconnecting is decided before the page hears of it, so its\n\t\t\t\t// listener sees `reconnecting` (or calls `connect()`, which then\n\t\t\t\t// makes the first attempt at once).\n\t\t\t\tif (this.#reconnect && RECONNECT_REASONS.has(reason))\n\t\t\t\t\tthis.#scheduleReconnect(reason, 1);\n\t\t\t\telse this.#setState(\"disconnected\", reason);\n\t\t\t},\n\t\t};\n\t}\n}\n"
|
|
10
10
|
],
|
|
11
|
-
"mappings": ";AAYA,IAAM,OAAO;AAcb,SAAS,aAAa,CAAC,GAA0C;AAAA,EAChE,OAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,MAAM,QAAQ,CAAC;AAAA;AAI/D,SAAS,aAAa,CAAC,QAAiB,QAAQ,GAAY;AAAA,EAC3D,IAAI,QAAQ,MAAM,OAAO,WAAW,YAAY,WAAW;AAAA,IAAM,OAAO;AAAA,EACxE,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,kBAAkB;AAAA,IAAQ,OAAO;AAAA,EAC/D,OAAO,OAAO,OAAO,MAAM,EAAE,KAAK,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,CAAC;AAAA;AAIrE,SAAS,cAAc,CAAC,MAAe,SAA0B;AAAA,EAChE,IA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AC1C,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAGhB,IAAI,UAAU,KAAK;AAAA,UAAgB;AAAA,QACnC,IAAI;AAAA,UAAO,KAAK,aAAa,OAAO;AAAA,QACpC;AAAA,UAAK,KAAK,aAAa,WAAW,WAAW,EAAE;AAAA;AAAA,MAEhD,OAAO,CAAC,UAAU;AAAA,QACjB,IAAI,QAAQ;AAAA,UAAG,KAAK,MAAM,SAAS,EAAE,MAAM,CAAC;AAAA;AAAA,MAE7C,QAAQ,CAAC,WAA6B;AAAA,QACrC,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAChB,IAAI,WAAW;AAAA,UAAY,KAAK,UAAU,eAAe;AAAA,QACzD,KAAK,cAAc;AAAA,QACnB,KAAK,WAAW;AAAA,QAGhB,MAAM,aAAa,KAAK;AAAA,QACxB,KAAK,gBAAgB,SAAS;AAAA,QAC9B,KAAK;AAAA,QACL,KAAK,aAAa,MAAM;AAAA,QACxB,IAAI,eAAe,KAAK;AAAA,UAAa;AAAA,QAIrC,IAAI,KAAK,cAAc,kBAAkB,IAAI,MAAM;AAAA,UAClD,KAAK,mBAAmB,QAAQ,CAAC;AAAA,QAClC;AAAA,UAAK,KAAK,UAAU,gBAAgB,MAAM;AAAA;AAAA,IAE5C;AAAA;AAEF;",
|
|
12
|
+
"debugId": "6E29CB68C279C2FB64756E2164756E21",
|
|
13
13
|
"names": []
|
|
14
14
|
}
|
package/mapping.d.ts
CHANGED
|
@@ -14,15 +14,48 @@ export interface CallToolResult {
|
|
|
14
14
|
content: unknown[];
|
|
15
15
|
structuredContent?: Record<string, unknown>;
|
|
16
16
|
isError?: boolean;
|
|
17
|
+
_meta?: Record<string, unknown>;
|
|
17
18
|
[key: string]: unknown;
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* `result` with `_meta["ch.ractive.tab-mcp/annotations"].untrustedContentHint`
|
|
22
|
+
* set, for every result of a tool marked `untrustedContentHint` (DEC-166):
|
|
23
|
+
* MCP has no such hint, and `openWorldHint` in `tools/list` says something
|
|
24
|
+
* else. The tool's own `_meta` is kept; `result` is not changed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function markUntrusted(result: CallToolResult): CallToolResult;
|
|
19
27
|
export declare function errorResult(message: string): CallToolResult;
|
|
20
28
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `
|
|
29
|
+
* Whether `value` is an MCP `CallToolResult`: an object whose `content` is an
|
|
30
|
+
* array of MCP content blocks (`isContentBlock`), with `isError` a boolean
|
|
31
|
+
* and `structuredContent` and `_meta` objects where present. Domain data
|
|
32
|
+
* that happens to have a `content` array (a ProseMirror document,
|
|
33
|
+
* `{ title, content: ["…"] }`, a chat message with its own blocks) is not
|
|
34
|
+
* one (CC 3). Other keys are allowed next to blocks, as MCP allows them on a
|
|
35
|
+
* result; with an empty `content` they are not, so that `{ title, content:
|
|
36
|
+
* [] }` is data, not an empty result.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isCallToolResult(value: unknown): value is CallToolResult;
|
|
39
|
+
/**
|
|
40
|
+
* What `execute` returned → a `CallToolResult`: a string is one text block; a
|
|
41
|
+
* `CallToolResult` (`isCallToolResult`) passes through; `undefined` is an
|
|
42
|
+
* empty result; any other JSON value is a text block with its JSON, plus
|
|
43
|
+
* that JSON as `structuredContent` when it is an object (so a `Date` or a
|
|
44
|
+
* `URL`, whose JSON is a string, has none).
|
|
25
45
|
*/
|
|
26
46
|
export declare function toCallToolResult(value: unknown): CallToolResult;
|
|
47
|
+
/**
|
|
48
|
+
* The text blocks of a result, one per line. With `noted`, each other block
|
|
49
|
+
* (an image, a resource) is a line that says it was left out, naming its type.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resultText(result: CallToolResult, noted?: boolean): string;
|
|
52
|
+
/**
|
|
53
|
+
* What a WebMCP caller gets for what `execute` returned (WM 4, WM 6): an MCP
|
|
54
|
+
* result as its `structuredContent` if it has one, else as its text
|
|
55
|
+
* (`resultText`, other blocks noted); `undefined` (which a browser cannot
|
|
56
|
+
* serialize as JSON, so the call would fail) and an empty MCP result as
|
|
57
|
+
* "Done."; any other value as it is.
|
|
58
|
+
*/
|
|
59
|
+
export declare function webMcpValue(value: unknown): unknown;
|
|
27
60
|
/** A thrown value → an `isError` result with its message. */
|
|
28
61
|
export declare function thrownResult(error: unknown): CallToolResult;
|
package/mcp.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import type { GrantRef } from "./protocol.js";
|
|
|
14
14
|
import type { RegisteredTool, ToolRegistry } from "./registry.js";
|
|
15
15
|
import type { ConfirmAnswer, ConfirmRequest, ServerInfo, ToolCallClient, ToolCallEnd, ToolCallOutcome, ToolCallStart } from "./types.js";
|
|
16
16
|
export declare const MCP_PROTOCOL_VERSION = "2026-07-28";
|
|
17
|
+
/** After the description of a consequential tool in `tools/list`. */
|
|
18
|
+
export declare const CONFIRMED_IN_TAB = "The page may ask the user to allow each call, usually in the page's browser tab.";
|
|
17
19
|
type Json = Record<string, unknown>;
|
|
18
20
|
export interface ToolSource {
|
|
19
21
|
list(): RegisteredTool[];
|
|
@@ -34,6 +36,12 @@ export interface McpHandlerOptions extends CallContext {
|
|
|
34
36
|
server: ServerInfo;
|
|
35
37
|
/** The caller of a request, from its grant. */
|
|
36
38
|
client(grant: GrantRef): ToolCallClient;
|
|
39
|
+
/**
|
|
40
|
+
* The largest response body the relay passes on (`limits.maxBodyBytes`);
|
|
41
|
+
* `undefined`: no limit. A larger tool result is answered as an error
|
|
42
|
+
* result instead (CC 7).
|
|
43
|
+
*/
|
|
44
|
+
maxBodyBytes?: () => number | undefined;
|
|
37
45
|
}
|
|
38
46
|
/** Checks arguments against a tool's input schema. */
|
|
39
47
|
export type ArgumentValidator = (args: unknown) => {
|
|
@@ -89,17 +97,24 @@ export interface CallRun {
|
|
|
89
97
|
* events around the argument check, the confirmation of a consequential
|
|
90
98
|
* tool and `execute`. The one path for both callers, so they cannot drift.
|
|
91
99
|
*/
|
|
92
|
-
export declare function runCall(context: CallContext, tool: RegisteredTool, raw: Json, signal: AbortSignal, client: ToolCallClient
|
|
100
|
+
export declare function runCall(context: CallContext, tool: RegisteredTool, raw: Json, signal: AbortSignal, client: ToolCallClient,
|
|
101
|
+
/**
|
|
102
|
+
* Whether the caller can be sent this result: `undefined` if so, else an
|
|
103
|
+
* error result to send instead. Before `toolcallend`, so that the event
|
|
104
|
+
* says what the caller gets.
|
|
105
|
+
*/
|
|
106
|
+
deliverable?: (result: CallToolResult) => CallToolResult | undefined): Promise<CallRun>;
|
|
93
107
|
/**
|
|
94
108
|
* A call from an agent in the browser (WebMCP) of the mirrored `tool`: the
|
|
95
109
|
* same path as an AI app's call (`runCall`), its outcome as WebMCP has it.
|
|
96
|
-
* Resolves with what `execute` returned
|
|
97
|
-
* resolves too, as `{ error: "<message>" }`:
|
|
98
|
-
* allow", a question not answered, a tool that is
|
|
99
|
-
* threw, an `isError` result.
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
110
|
+
* Resolves with what `execute` returned, as `webMcpValue` maps it. Every
|
|
111
|
+
* failure the agent should read resolves too, as `{ error: "<message>" }`:
|
|
112
|
+
* invalid arguments, "Don't allow", a question not answered, a tool that is
|
|
113
|
+
* gone, what `execute` threw, an `isError` result.
|
|
114
|
+
* WebMCP hands the agent a rejection without its message (the draft: an
|
|
115
|
+
* `OperationError`; Chrome 156: `UnknownError`), so the agent would learn
|
|
116
|
+
* neither why nor what to change (DEC-120). Only a call the browser
|
|
117
|
+
* cancelled rejects (`AbortError`): its caller has gone already.
|
|
103
118
|
*/
|
|
104
119
|
export declare function webMcpCall(context: CallContext, tool: RegisteredTool, input: unknown, signal: unknown): Promise<unknown>;
|
|
105
120
|
export declare function createMcpHandler(options: McpHandlerOptions): McpHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ractive-ch/tab-mcp-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Browser library: offer a web page's tools to AI agents through a tab-mcp relay",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./setup.d.ts",
|
|
17
17
|
"default": "./setup.js"
|
|
18
18
|
},
|
|
19
|
+
"./tunnel": {
|
|
20
|
+
"types": "./tunnel.d.ts",
|
|
21
|
+
"default": "./tunnel.js"
|
|
22
|
+
},
|
|
19
23
|
"./visible": {
|
|
20
24
|
"types": "./visible.d.ts",
|
|
21
25
|
"default": "./visible.js"
|
package/react.d.ts
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
* dialog. `react` (18.3 or 19) is an optional peer dependency; the core
|
|
6
6
|
* entry stays free of it.
|
|
7
7
|
*/
|
|
8
|
-
import { type ButtonHTMLAttributes, type
|
|
8
|
+
import { type ButtonHTMLAttributes, type ReactElement, type ReactNode } from "react";
|
|
9
9
|
import { type ConnectionState, type Grant, type IdentityState, type PairingCode, type ReconnectingInfo, type RegisterToolOptions, type SessionInfo, TabMcp, type TabMcpOptions, type Tool, type ToolCallEnd, type ToolCallStart } from "./index.js";
|
|
10
10
|
/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */
|
|
11
11
|
export interface TabMcpSnapshot {
|
|
12
12
|
state: ConnectionState;
|
|
13
|
-
/** The MCP address to give to AI apps
|
|
14
|
-
address: string | undefined;
|
|
13
|
+
/** The session while connected; `session.address` is the MCP address to give to AI apps. */
|
|
15
14
|
session: SessionInfo | undefined;
|
|
16
15
|
/** The AI apps connected to this address. */
|
|
17
16
|
grants: readonly Grant[];
|
|
@@ -21,7 +20,7 @@ export interface TabMcpSnapshot {
|
|
|
21
20
|
identity: IdentityState;
|
|
22
21
|
/** Why the relay refused the identity (`identity: "refused"`). */
|
|
23
22
|
identityMessage: string | undefined;
|
|
24
|
-
/** While
|
|
23
|
+
/** While `state` is `reconnecting`: the next attempt and when it starts. */
|
|
25
24
|
reconnecting: ReconnectingInfo | undefined;
|
|
26
25
|
/** Names of the registered tools. */
|
|
27
26
|
tools: readonly string[];
|
|
@@ -35,7 +34,8 @@ export type TabMcpProviderProps = ((TabMcpOptions & {
|
|
|
35
34
|
children?: ReactNode;
|
|
36
35
|
};
|
|
37
36
|
/**
|
|
38
|
-
* Makes one `TabMcp` for its tree from the props of its first render
|
|
37
|
+
* Makes one `TabMcp` for its tree from the props of its first render
|
|
38
|
+
* (`relay` may be left out, as for `TabMcp`). A
|
|
39
39
|
* changed `relay` or `server.name` makes a new instance (and warns); other
|
|
40
40
|
* changes are ignored, but `onConfirm` and `identityAssertion` are always
|
|
41
41
|
* the latest ones (also when added or removed later). Pass `client` to use an instance of your own instead. The
|
|
@@ -57,11 +57,12 @@ export type UseToolOptions = Omit<RegisterToolOptions, "signal">;
|
|
|
57
57
|
* Registers a tool while the component is mounted (with an `AbortSignal`,
|
|
58
58
|
* aborted on unmount). `execute` is always the latest one, so a new closure
|
|
59
59
|
* on each render does not register again; the tool is registered again only
|
|
60
|
-
* when its name, title, description, input schema or annotations
|
|
61
|
-
* `options.
|
|
62
|
-
*
|
|
60
|
+
* when its name, title, description, input or output schema or annotations
|
|
61
|
+
* change, or `options.callers` or `options.exposedTo` (a tool allowed until reload stays allowed when it is
|
|
62
|
+
* registered again unchanged). A duplicate name or an invalid tool is thrown
|
|
63
|
+
* from the component's next render, for an error boundary.
|
|
63
64
|
*/
|
|
64
|
-
export declare function useTool<Input extends object = Record<string, unknown>>(tool: Tool<Input>,
|
|
65
|
+
export declare function useTool<Input extends object = Record<string, unknown>>(tool: Tool<Input>, options?: UseToolOptions): void;
|
|
65
66
|
/** A tool call of an AI app, as `useToolCalls()` lists it. */
|
|
66
67
|
export interface ToolCallRecord extends ToolCallStart {
|
|
67
68
|
/** When it started, `Date.now()`. */
|
|
@@ -83,12 +84,12 @@ export interface ConnectButtonProps extends Omit<ButtonHTMLAttributes<HTMLButton
|
|
|
83
84
|
/** The label; default: the state ("Connect your AI app", "AI app connected"). */
|
|
84
85
|
children?: ReactNode | ((state: TabMcpSnapshot) => ReactNode);
|
|
85
86
|
}
|
|
86
|
-
/** The default label of `ConnectButton`. */
|
|
87
|
-
export declare function connectLabel(state: TabMcpSnapshot): string;
|
|
88
87
|
/**
|
|
89
88
|
* A button that opens the library's "Connect your AI app" dialog
|
|
90
89
|
* (`showConnectDialog()`), labelled with the state. `data-state` is
|
|
91
90
|
* `disconnected`, `connecting`, `connected` or `reconnecting`, for styling.
|
|
92
91
|
* An `onClick` that calls `event.preventDefault()` keeps the dialog closed.
|
|
92
|
+
* Renders nothing for a `TabMcp` without a relay: there is nothing to
|
|
93
|
+
* connect.
|
|
93
94
|
*/
|
|
94
|
-
export declare function ConnectButton({ children, onClick, ...rest }: ConnectButtonProps): ReactElement;
|
|
95
|
+
export declare function ConnectButton({ children, onClick, ...rest }: ConnectButtonProps): ReactElement | null;
|