@ractive-ch/tab-mcp-client 0.21.0-rc.1 → 0.21.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/CHANGELOG.md +9 -2
- package/README.md +31 -16
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +2 -2
- package/cdn/webmcp-8xby3trn.min.js +4 -0
- package/cdn/{webmcp-ny13npet.min.js.map → webmcp-8xby3trn.min.js.map} +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/react.js +9 -5
- package/react.js.map +3 -3
- package/skill/SKILL.md +14 -10
- package/skill/references/react.md +1 -1
- package/skill/references/sign-in.md +1 -1
- package/{webmcp-acj1tef8.js → webmcp-gw6rrbnh.js} +24 -3
- package/{webmcp-acj1tef8.js.map → webmcp-gw6rrbnh.js.map} +3 -3
- package/webmcp.d.ts +6 -1
- package/cdn/webmcp-ny13npet.min.js +0 -4
package/index.js.map
CHANGED
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
"/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport type { 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\tBrowserExtension,\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 type { ModelContext } from \"./webmcp.ts\";\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. In the\n * core; the mirror itself is a chunk of its own (DEC-171).\n */\nfunction 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\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/** An app id as the relay takes it (DEC-196). */\nconst APP_ID = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;\n\n/**\n * The app id a server name gives: lower case, letters without their marks,\n * each run of anything but a-z and 0-9 as one `-`, none at either end, at\n * most 32 characters; `\"\"` when nothing is left.\n */\nexport function appIdOf(name: string): string {\n\treturn name\n\t\t.normalize(\"NFKD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-|-$/g, \"\")\n\t\t.slice(0, 32)\n\t\t.replace(/-$/, \"\");\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 `disconnectAll()` reject with without a relay. */\nfunction noRelay(): Promise<never> {\n\treturn Promise.reject(new TypeError(\"TabMcp: this TabMcp has no relay\"));\n}\n\n/**\n * A rejection of `disconnectAll()`: `secretChanged` says whether the apps\n * were disconnected and the secret is new (only connecting with it failed)\n * or not (the old one could not be taken back and is kept, with its grants).\n */\nfunction changed(error: unknown, secretChanged: boolean): unknown {\n\treturn Object.assign(Object(error), { secretChanged });\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\n/** The lazy chunk (`connection.ts`). */\ntype Lazy = typeof import(\"./connection.ts\");\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\t/**\n\t * With `webmcp: true`: the tab-mcp browser extension while it serves this\n\t * page, with the AI apps that reach the page's tools through it (DEC-207);\n\t * `extensionchange` says when it changes. `undefined` without it, while\n\t * its AI access is off, and without WebMCP. Declared only: the mirror's\n\t * chunk defines it on the instance once it hears the extension, so that\n\t * the core carries no bytes for it (until then it is `undefined`).\n\t */\n\tdeclare readonly extension: BrowserExtension | undefined;\n\treadonly #server: ServerInfo;\n\treadonly #app: string;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #alwaysAllow: TabMcpOptions[\"alwaysAllow\"];\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 * `disconnectAll()` failed), and nothing was ended since: the next\n\t * `disconnectAll()` connects with the new secret. 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 `disconnectAll()`: 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#pairingUntil: string | undefined;\n\t/** The last `pairing.start` went to an `oidc` session (DEC-202). */\n\t#asked = false;\n\t/** `connect()` from a click while reconnecting: that session asks again. */\n\t#clicked = false;\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 lazy chunk, once `#load()` loaded it. */\n\t#lazy: Lazy | 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\tonConfirm: () => this.#onConfirm,\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\tconst app = options.app ?? appIdOf(server.name);\n\t\tif (\n\t\t\toptions.app !== undefined\n\t\t\t\t? typeof app !== \"string\" || !APP_ID.test(app)\n\t\t\t\t: relay && app === \"\"\n\t\t) {\n\t\t\tthrow new TypeError(\n\t\t\t\toptions.app !== undefined\n\t\t\t\t\t? \"TabMcp: app must be 1-32 characters of a-z, 0-9 and -, not starting or ending with -\"\n\t\t\t\t\t: \"TabMcp: server.name has no letter a-z and no digit to make the address of: set app\",\n\t\t\t);\n\t\t}\n\t\tthis.#app = app;\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;\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, 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(options.storage, key);\n\t\t\t// Tabs that share the secret share this channel; with `storage: null`\n\t\t\t// every tab has a secret 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// every tool whose `callers` do not leave \"webmcp\" out (DEC-209). The getter\n\t\t// is read now (WM 10); the mirror loads only then (DEC-171), with the\n\t\t// handshake with the tab-mcp browser extension (DEC-207).\n\t\tconst context = options.webmcp === true ? nativeContext() : undefined;\n\t\tif (context !== undefined)\n\t\t\timport(\"./webmcp.ts\").then(\n\t\t\t\t(m) =>\n\t\t\t\t\tm.mirror(\n\t\t\t\t\t\tthis.#registry,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t(tool, input, signal, by) =>\n\t\t\t\t\t\t\tthis.#load().then((lazy) =>\n\t\t\t\t\t\t\t\tlazy.callFromWebMcp(this.#calls, tool, input, signal, by),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\tapp,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\t// Passed, not imported there: a chunk shared with the core\n\t\t\t\t\t\t// would cost the core more.\n\t\t\t\t\t\tVERSION,\n\t\t\t\t\t),\n\t\t\t\t// Like a failed registration: warned, the relay unaffected.\n\t\t\t\t(error: unknown) =>\n\t\t\t\t\tconsole.warn(\"tab-mcp: no tools are offered through WebMCP:\", error),\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 with a\n\t * `NetworkError` when the 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 * Identity binding: until when a sign-in pairs this page (ISO time, on\n\t * the page's clock: the relay's duration counted from its answer to the\n\t * last `startPairing()`, DEC-202). A reconnect the library makes by\n\t * itself does not start it anew: it is the time of the reconnect then.\n\t * `undefined` while pairing is off, until the relay answers, after the\n\t * session ended, and from relays up to 0.12.1, which do not say.\n\t */\n\tget pairingUntil(): string | undefined {\n\t\treturn this.#pairingUntil;\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.#reconnecting !== undefined) {\n\t\t\tthis.#clicked ||= options.resume !== true;\n\t\t\treturn this.#attemptReconnect();\n\t\t}\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\t// While `disconnectAll()` runs: afterwards, with the new secret.\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<Lazy> {\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\tthis.#lazy = lazy;\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 } = 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(this.#host(ref), relayUrl, secret, {\n\t\t\taddress,\n\t\t\trevokeAll: !!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 * Disconnect every AI app and start over with a new secret. The address\n\t * people add to an AI app names the app and stays the same (DEC-196);\n\t * what changes is the page behind it, so every AI app has to pair again.\n\t * If the page has a secret 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 secret could\n\t * not be taken back (relay unreachable, taken over again first). With a\n\t * relay, every rejection has `secretChanged`: `false` then, `true` when\n\t * only connecting with the new secret failed (without one: a\n\t * `TypeError`). Call it from a user action.\n\t */\n\tdisconnectAll(): 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(\"disconnect_all\");\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 changed(error, false);\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(\"disconnect_all\");\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)\n\t\t\tawait this.#start().catch((error: unknown) => {\n\t\t\t\tthrow changed(error, true);\n\t\t\t});\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.#clearPairing();\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 disconnected all apps) 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/**\n\t * Back to the front, or online again: try at once instead of waiting. The\n\t * listeners are in the lazy chunk, loaded by the connection that broke\n\t * (if loading it failed, the timer still tries).\n\t */\n\t#watch(): void {\n\t\tthis.#unwatch ??= this.#lazy?.onWake(() => {\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}\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/**\n\t * The pairing dialog opened: ask the relay for codes (DEC-028). With\n\t * identity binding each call while connected starts the relay's ten\n\t * minutes for a sign-in anew (`pairingUntil`, DEC-202): call it only\n\t * when the user acts (opens the dialog, continues after the time is up).\n\t */\n\tstartPairing(): void {\n\t\tthis.#pairing = true;\n\t\t// Owed to the relay until sent: also a reconnect sends it then.\n\t\tthis.#asked = false;\n\t\tif (this.#state === \"connected\") this.#askPairing();\n\t}\n\n\t/** Send `pairing.start`; `pairingUntil` waits for the relay's answer. */\n\t#askPairing(): void {\n\t\tthis.#setPairingUntil(undefined);\n\t\tthis.#asked = this.#session?.pairing === \"oidc\";\n\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.#clearPairing();\n\t}\n\n\t/** No code, no time for a sign-in: pairing is off or the session ended. */\n\t#clearPairing(): void {\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#setPairingUntil(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 * and when the relay no longer knows it: it leaves `grants` then).\n\t * Rejects with an `InvalidStateError` while not connected (only the relay\n\t * can do it), a `NetworkError` when the session ends before the answer,\n\t * and with the relay's error when it refuses (its `code` is\n\t * `store_unavailable` when it could not save the change: try again).\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 with an\n\t * `InvalidStateError` when it cannot send, a `NetworkError` when the\n\t * session ends first, the relay's refusal of this message\n\t * (`store_unavailable`: it could not save the change; `unknown_id`), and a\n\t * `TimeoutError` when none of that happened within\n\t * `timing.answerTimeoutMs`.\n\t */\n\t#ask(\n\t\tmessage: TabMessage & { grantId?: string },\n\t\tdone: () => boolean,\n\t): Promise<void> {\n\t\t// With a session, the lazy chunk is loaded: the waiting is there.\n\t\treturn !this.#session || this.#connection?.send(message) !== true\n\t\t\t? notConnected()\n\t\t\t: (this.#lazy as Lazy).answer(\n\t\t\t\t\tthis,\n\t\t\t\t\tmessage,\n\t\t\t\t\tdone,\n\t\t\t\t\t() => this.#state === \"connected\",\n\t\t\t\t\ttiming.answerTimeoutMs,\n\t\t\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#setPairingUntil(pairingUntil: string | undefined): void {\n\t\tif (this.#pairingUntil === pairingUntil) return;\n\t\tthis.#pairingUntil = pairingUntil;\n\t\tthis.#emit(\"pairinguntil\", { pairingUntil });\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/**\n\t * A call the user allowed runs without asking, else `onConfirm` or the\n\t * dialog: decided out of the core, in the confirmation's chunk (a chunk\n\t * of its own for the allowances would cost the core more bytes, DEC-200).\n\t * If that chunk does not load, the page's own `onConfirm` asks (only its\n\t * `true` runs the call); without one the call is refused, never allowed.\n\t */\n\t#confirm(request: ConfirmRequest): Promise<ConfirmAnswer> {\n\t\tconst ask = this.#onConfirm;\n\t\treturn import(\"./confirm.ts\").then(\n\t\t\t(m) => m.confirmCall(this, request, ask),\n\t\t\t() => ask?.(request) ?? false,\n\t\t);\n\t}\n\n\t/**\n\t * For `./allowed` and the dialogs, not for pages: the tools, where the\n\t * secret is kept, and `alwaysAllow`.\n\t * @internal\n\t */\n\tget _allowed(): [\n\t\tToolRegistry,\n\t\tSecretStore | undefined,\n\t\tTabMcpOptions[\"alwaysAllow\"],\n\t] {\n\t\treturn [this.#registry, this.#secrets, this.#alwaysAllow];\n\t}\n\n\t/**\n\t * For `./react`, not for pages: the dialogs' options, whose `strings`\n\t * `ConnectButton` reads too (one table for every text, given once).\n\t * @internal\n\t */\n\tget _ui(): DialogOptions | undefined {\n\t\treturn this.#ui;\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` (what runs without\n\t * `onConfirm`), in `options.document` (default: the global one). An\n\t * `onConfirm` may hand some calls to it. A call the user allowed for its\n\t * AI app resolves `true` unasked. A WebMCP call resolves `true` unasked\n\t * too, without loading the dialog, as without `onConfirm` (DEC-215). Resolves `false` where there is no document.\n\t */\n\tconfirmInPage(\n\t\trequest: ConfirmRequest,\n\t\toptions: { document?: Document } = {},\n\t): Promise<boolean> {\n\t\tif (request.client.kind === \"webmcp\") return Promise.resolve(true);\n\t\tconst doc = options.document ?? globalThis.document;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\treturn import(\"./confirm.ts\").then((ui) =>\n\t\t\tui.confirmInPage(this, request, doc, { ui: this.#ui }),\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\tapp: this.#app,\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\t// A reconnect the library made by itself does not start a\n\t\t\t\t// sign-in's time anew once the user's start was sent, answered\n\t\t\t\t// or not: only the user does (DEC-202). Codes come again.\n\t\t\t\tconst ended =\n\t\t\t\t\tthis.#pairing &&\n\t\t\t\t\tthis.#reconnecting &&\n\t\t\t\t\t!this.#clicked &&\n\t\t\t\t\tthis.#asked &&\n\t\t\t\t\tsession.pairing === \"oidc\";\n\t\t\t\tthis.#clicked = false;\n\t\t\t\tthis.#stopReconnecting();\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (ended) this.#setPairingUntil(new Date().toISOString());\n\t\t\t\telse if (this.#pairing) this.#askPairing();\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\tpairingOpen: (until) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingUntil(until);\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// `disconnectAll()`): that bumps the generation.\n\t\t\t\tconst generation = this.#generation;\n\t\t\t\tthis.#clearPairing();\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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EBF06E2D5864756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/package.json
CHANGED
package/react.js
CHANGED
|
@@ -132,12 +132,16 @@ function TabMcpProvider(props) {
|
|
|
132
132
|
...options
|
|
133
133
|
} = props;
|
|
134
134
|
const handlers = () => latest.current;
|
|
135
|
+
const onConfirm = (request) => {
|
|
136
|
+
const ask = handlers().onConfirm;
|
|
137
|
+
return ask === undefined ? instance.confirmInPage(request) : ask(request);
|
|
138
|
+
};
|
|
139
|
+
Object.defineProperty(onConfirm, "own", {
|
|
140
|
+
get: () => handlers().onConfirm !== undefined
|
|
141
|
+
});
|
|
135
142
|
const instance = new TabMcp({
|
|
136
143
|
...options,
|
|
137
|
-
onConfirm
|
|
138
|
-
const ask = handlers().onConfirm;
|
|
139
|
-
return ask === undefined ? instance.confirmInPage(request) : ask(request);
|
|
140
|
-
},
|
|
144
|
+
onConfirm,
|
|
141
145
|
identityAssertion: (request) => handlers().identityAssertion?.(request) ?? null
|
|
142
146
|
});
|
|
143
147
|
return instance;
|
|
@@ -323,5 +327,5 @@ export {
|
|
|
323
327
|
useToolCalls
|
|
324
328
|
};
|
|
325
329
|
|
|
326
|
-
//# debugId=
|
|
330
|
+
//# debugId=0BE3C1AC61208FFB64756E2164756E21
|
|
327
331
|
//# sourceMappingURL=react.js.map
|
package/react.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/react.ts", "../src/text.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"\"use client\";\n/**\n * `@ractive-ch/tab-mcp-client/react`: React bindings for single-page apps\n * (iteration 9). One `TabMcp` per `<TabMcpProvider>`, hooks for its state,\n * its tools and the calls of AI apps, and a button that opens the connect\n * dialog. `react` (18.3 or 19) is an optional peer dependency; the core\n * entry stays free of it.\n */\n\nimport {\n\ttype ButtonHTMLAttributes,\n\tcreateContext,\n\tcreateElement,\n\ttype MouseEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseInsertionEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedTools,\n} from \"./allowed.ts\";\nimport {\n\ttype BrowserExtension,\n\ttype ConfirmRequest,\n\ttype ConnectionState,\n\ttype Grant,\n\ttype IdentityAssertionRequest,\n\ttype IdentityState,\n\ttype PairingCode,\n\ttype ReconnectingInfo,\n\ttype RegisterToolOptions,\n\ttype SessionInfo,\n\tTabMcp,\n\ttype TabMcpEventMap,\n\ttype TabMcpOptions,\n\ttype Tool,\n\ttype ToolCallEnd,\n\ttype ToolCallStart,\n} from \"./index.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport { isPlural, plural } from \"./text.ts\";\n\n/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */\nexport interface TabMcpSnapshot {\n\tstate: ConnectionState;\n\t/** The session while connected; `session.address` is the MCP address to give to AI apps. */\n\tsession: SessionInfo | undefined;\n\t/** The AI apps connected to this address. */\n\tgrants: readonly Grant[];\n\t/** The pairing code to show, while the connect dialog is open. */\n\tpairingCode: PairingCode | undefined;\n\t/** Identity binding: until when a sign-in pairs the page (`TabMcp.pairingUntil`). */\n\tpairingUntil: string | undefined;\n\t/** Who the relay knows as the page's user (identity binding). */\n\tidentity: IdentityState;\n\t/** Why the relay refused the identity (`identity: \"refused\"`). */\n\tidentityMessage: string | undefined;\n\t/** While `state` is `reconnecting`: the next attempt and when it starts. */\n\treconnecting: ReconnectingInfo | undefined;\n\t/** Names of the registered tools. */\n\ttools: readonly string[];\n\t/**\n\t * The tab-mcp browser extension while it serves the page, with the AI\n\t * apps connected through it (`TabMcp.extension`, `webmcp: true`).\n\t */\n\textension: BrowserExtension | undefined;\n}\n\nconst EMPTY: readonly never[] = Object.freeze([]);\n\n/** What the server renders, and what hydration starts from. */\nconst SERVER_SNAPSHOT: TabMcpSnapshot = Object.freeze({\n\tstate: \"disconnected\",\n\tsession: undefined,\n\tgrants: EMPTY,\n\tpairingCode: undefined,\n\tpairingUntil: undefined,\n\tidentity: \"none\",\n\tidentityMessage: undefined,\n\treconnecting: undefined,\n\ttools: EMPTY,\n\textension: undefined,\n});\n\nconst STATE_EVENTS = [\n\t\"statechange\",\n\t\"grantschange\",\n\t\"pairingcode\",\n\t\"pairinguntil\",\n\t\"identitychange\",\n\t\"toolschange\",\n\t\"extensionchange\",\n] as const satisfies readonly (keyof TabMcpEventMap)[];\n\n/** The external store of one `TabMcp`: a snapshot that changes only with the instance. */\nclass Store {\n\treadonly #mcp: TabMcp;\n\treadonly #listeners = new Set<() => void>();\n\t#snapshot: TabMcpSnapshot;\n\n\tconstructor(mcp: TabMcp) {\n\t\tthis.#mcp = mcp;\n\t\tthis.#snapshot = this.#read(SERVER_SNAPSHOT);\n\t\tconst update = () => {\n\t\t\tconst next = this.#read(this.#snapshot);\n\t\t\tif (next === this.#snapshot) return;\n\t\t\tthis.#snapshot = next;\n\t\t\tfor (const listener of [...this.#listeners]) listener();\n\t\t};\n\t\tfor (const type of STATE_EVENTS) mcp.addEventListener(type, update);\n\t}\n\n\treadonly subscribe = (listener: () => void): (() => void) => {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t};\n\n\treadonly getSnapshot = (): TabMcpSnapshot => this.#snapshot;\n\n\t/** The current values; `previous` itself when none changed. */\n\t#read(previous: TabMcpSnapshot): TabMcpSnapshot {\n\t\tconst mcp = this.#mcp;\n\t\tconst tools = mcp.tools;\n\t\tconst next: TabMcpSnapshot = {\n\t\t\tstate: mcp.state,\n\t\t\tsession: mcp.session,\n\t\t\tgrants: mcp.grants,\n\t\t\tpairingCode: mcp.pairingCode,\n\t\t\tpairingUntil: mcp.pairingUntil,\n\t\t\tidentity: mcp.identity,\n\t\t\tidentityMessage: mcp.identityMessage,\n\t\t\treconnecting: mcp.reconnecting,\n\t\t\ttools:\n\t\t\t\ttools.length === previous.tools.length &&\n\t\t\t\ttools.every((t, i) => t === previous.tools[i])\n\t\t\t\t\t? previous.tools\n\t\t\t\t\t: tools,\n\t\t\textension: mcp.extension,\n\t\t};\n\t\tconst same = (Object.keys(next) as (keyof TabMcpSnapshot)[]).every(\n\t\t\t(key) => next[key] === previous[key],\n\t\t);\n\t\treturn same ? previous : next;\n\t}\n}\n\nconst stores = new WeakMap<TabMcp, Store>();\n\nfunction storeOf(mcp: TabMcp): Store {\n\tlet store = stores.get(mcp);\n\tif (store === undefined) {\n\t\tstore = new Store(mcp);\n\t\tstores.set(mcp, store);\n\t}\n\treturn store;\n}\n\nconst Context = createContext<TabMcp | undefined>(undefined);\n\n/** Props of `TabMcpProvider`: the `TabMcp` options, or an instance of your own. */\nexport type TabMcpProviderProps = (\n\t| (TabMcpOptions & { client?: undefined })\n\t| { client: TabMcp }\n) & { children?: ReactNode };\n\n/**\n * Makes one `TabMcp` for its tree from the props of its first render\n * (`relay` may be left out, as for `TabMcp`). A\n * changed `relay` or `server.name` makes a new instance (and warns); other\n * changes are ignored, but `onConfirm` and `identityAssertion` are always\n * the latest ones (also when added or removed later). Pass `client` to use an instance of your own instead. The\n * provider's own instance is disconnected when the provider unmounts; it\n * never connects on the server.\n */\nexport function TabMcpProvider(props: TabMcpProviderProps): ReactElement {\n\tconst latest = useRef(props);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = props;\n\t});\n\tconst own = props.client === undefined ? props : undefined;\n\tconst relay = own?.relay;\n\tconst serverName = own?.server?.name;\n\tconst create = (): TabMcp => {\n\t\tconst {\n\t\t\tchildren: _,\n\t\t\tclient: __,\n\t\t\t...options\n\t\t} = props as TabMcpOptions & {\n\t\t\tchildren?: ReactNode;\n\t\t\tclient?: undefined;\n\t\t};\n\t\t// Always installed, so that a handler added, changed or removed in a\n\t\t// later render counts: without one, the library's own behaviour.\n\t\tconst handlers = () => latest.current as Partial<TabMcpOptions>;\n\t\tconst instance: TabMcp = new TabMcp({\n\t\t\t...options,\n\t\t\tonConfirm: (request: ConfirmRequest) => {\n\t\t\t\tconst ask = handlers().onConfirm;\n\t\t\t\treturn ask === undefined\n\t\t\t\t\t? instance.confirmInPage(request)\n\t\t\t\t\t: ask(request);\n\t\t\t},\n\t\t\tidentityAssertion: (request: IdentityAssertionRequest) =>\n\t\t\t\thandlers().identityAssertion?.(request) ?? null,\n\t\t});\n\t\treturn instance;\n\t};\n\t// In state, not in `useMemo`, which React may discard and run again. A\n\t// changed relay or server name replaces it while rendering, as React\n\t// recommends for state that follows props.\n\tconst [state, setState] = useState(() =>\n\t\town === undefined ? undefined : { relay, serverName, mcp: create() },\n\t);\n\tlet current = state;\n\tif (own === undefined) {\n\t\tcurrent = undefined;\n\t} else if (\n\t\tcurrent === undefined ||\n\t\tcurrent.relay !== relay ||\n\t\tcurrent.serverName !== serverName\n\t) {\n\t\tcurrent = { relay, serverName, mcp: create() };\n\t}\n\tif (current !== state) setState(current);\n\tconst mcp = props.client ?? (current as { mcp: TabMcp }).mcp;\n\n\tconst previous = useRef<TabMcp | undefined>(undefined);\n\t/** The instance the mounted effect is for; `undefined` after its cleanup. */\n\tconst active = useRef<TabMcp | undefined>(undefined);\n\tuseEffect(() => {\n\t\tif (\n\t\t\tprevious.current !== undefined &&\n\t\t\tprevious.current !== mcp &&\n\t\t\tprops.client === undefined\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"TabMcpProvider: relay or server.name changed, so the page has a new TabMcp; its tools and connection start over\",\n\t\t\t);\n\t\t}\n\t\tprevious.current = mcp;\n\t\tif (props.client !== undefined) return;\n\t\tactive.current = mcp;\n\t\t// Disconnected a moment later, unless the effect ran again for the same\n\t\t// instance meanwhile: StrictMode's simulated unmount and mount would\n\t\t// otherwise cancel a `connect()` that a child's effect started (CU 24).\n\t\treturn () => {\n\t\t\tactive.current = undefined;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (active.current !== mcp) mcp.disconnect();\n\t\t\t});\n\t\t};\n\t}, [mcp, props.client]);\n\n\treturn createElement(Context.Provider, { value: mcp }, props.children);\n}\n\n/** The provider's `TabMcp`, for everything the hooks do not cover. */\nexport function useTabMcp(): TabMcp {\n\tconst mcp = useContext(Context);\n\tif (mcp === undefined)\n\t\tthrow new Error(\"useTabMcp: no <TabMcpProvider> above this component\");\n\treturn mcp;\n}\n\n/**\n * The connection state, address, grants, pairing code, identity,\n * reconnecting and the tab-mcp browser extension of the provider's `TabMcp`. Re-renders only when one of them\n * changes; the server and hydration see `disconnected`.\n */\nexport function useTabMcpState(): TabMcpSnapshot {\n\tconst store = storeOf(useTabMcp());\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getSnapshot,\n\t\t() => SERVER_SNAPSHOT,\n\t);\n}\n\n/** What `useAllowedTools(grantId)` returns: one object per change, the same object otherwise. */\nexport interface AllowedToolsSnapshot {\n\t/** The page's tools that ask, each with whether it runs without asking for this app. */\n\ttools: (AllowedTool & { allowed: boolean })[];\n\t/** \"Always allow everything\" is on for this app. */\n\teverything: boolean;\n\t/** To change them: `allow`, `ask`, `setEverything`, `forget`. */\n\tallowedTools: AllowedTools;\n}\n\n/**\n * The tools that run without asking for one connected AI app\n * (`grant.grantId`), for switches of the page's own: `allowedTools(mcp)` of\n * `@ractive-ch/tab-mcp-client/allowed` as state. Re-renders when they or the\n * tools change; the server and hydration see none.\n */\nexport function useAllowedTools(grantId: string): AllowedToolsSnapshot {\n\tconst allowed = allowedTools(useTabMcp());\n\tconst subscribe = useCallback(\n\t\t(changed: () => void) => allowed.onChange(changed),\n\t\t[allowed],\n\t);\n\tconst last = useRef<{ key: string; snapshot: AllowedToolsSnapshot }>(\n\t\tundefined,\n\t);\n\tconst server = useRef<AllowedToolsSnapshot>(undefined);\n\t// Reads only: a changed tool left the list already.\n\tconst getSnapshot = () => {\n\t\tconst everything = allowed.everything(grantId);\n\t\tconst listed = new Set(allowed.list(grantId));\n\t\tconst tools = allowed\n\t\t\t.tools()\n\t\t\t.map((t) => ({ ...t, allowed: everything || listed.has(t.name) }));\n\t\tconst key = JSON.stringify([grantId, everything, tools]);\n\t\tif (\n\t\t\tlast.current?.key !== key ||\n\t\t\tlast.current.snapshot.allowedTools !== allowed\n\t\t)\n\t\t\tlast.current = {\n\t\t\t\tkey,\n\t\t\t\tsnapshot: { tools, everything, allowedTools: allowed },\n\t\t\t};\n\t\treturn last.current.snapshot;\n\t};\n\tconst getServerSnapshot = () => {\n\t\tif (server.current?.allowedTools !== allowed)\n\t\t\tserver.current = { tools: [], everything: false, allowedTools: allowed };\n\t\treturn server.current;\n\t};\n\treturn useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n\n/** Options of `useTool`: `RegisterToolOptions` without the signal (the hook has its own). */\nexport type UseToolOptions = Omit<RegisterToolOptions, \"signal\">;\n\n/**\n * Registers a tool while the component is mounted (with an `AbortSignal`,\n * aborted on unmount). `execute` is always the latest one, so a new closure\n * on each render does not register again; the tool is registered again only\n * when its name, title, description, input or output schema or annotations\n * change, or `options.callers` or `options.exposedTo` (a tool allowed until reload stays allowed when it is\n * registered again unchanged). A duplicate name or an invalid tool is thrown\n * from the component's next render, for an error boundary.\n */\nexport function useTool<Input extends object = Record<string, unknown>>(\n\ttool: Tool<Input>,\n\toptions: UseToolOptions = {},\n): void {\n\tconst mcp = useTabMcp();\n\tconst latest = useRef(tool);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = tool;\n\t});\n\tconst [failure, setFailure] = useState<{ error: unknown } | undefined>();\n\tif (failure !== undefined) throw failure.error;\n\tconst shape = JSON.stringify([\n\t\ttool.name,\n\t\ttool.title,\n\t\ttool.description,\n\t\ttool.inputSchema,\n\t\ttool.outputSchema,\n\t\ttool.annotations,\n\t\toptions.callers,\n\t\toptions.exposedTo,\n\t]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: `shape` stands for the tool and its options; `execute` is read through the ref\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\t\tconst { execute: _, ...fields } = latest.current;\n\t\tmcp\n\t\t\t.registerTool(\n\t\t\t\t{\n\t\t\t\t\t...fields,\n\t\t\t\t\texecute: (input: Input, options) =>\n\t\t\t\t\t\tlatest.current.execute(input, options),\n\t\t\t\t},\n\t\t\t\t{ ...options, signal: controller.signal },\n\t\t\t)\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (!controller.signal.aborted) setFailure({ error });\n\t\t\t});\n\t\treturn () => controller.abort();\n\t}, [mcp, shape]);\n}\n\n/** A tool call of an AI app, as `useToolCalls()` lists it. */\nexport interface ToolCallRecord extends ToolCallStart {\n\t/** When it started, `Date.now()`. */\n\tstartedAt: number;\n\t/** How it ended; missing while it runs. */\n\tend?: ToolCallEnd;\n}\n\nexport interface UseToolCallsOptions {\n\t/** How many calls to keep; default 20. */\n\tlimit?: number;\n}\n\n/**\n * The recent tool calls of AI apps since the component mounted, newest\n * first, each with its end once it is over: for an activity view.\n */\nexport function useToolCalls(\n\toptions: UseToolCallsOptions = {},\n): readonly ToolCallRecord[] {\n\tconst mcp = useTabMcp();\n\tconst limit = Math.max(0, options.limit ?? 20);\n\tconst [calls, setCalls] = useState<readonly ToolCallRecord[]>(EMPTY);\n\tuseEffect(() => {\n\t\tconst started = (event: TabMcpEventMap[\"toolcall\"]) => {\n\t\t\tconst record: ToolCallRecord = { ...event.detail, startedAt: Date.now() };\n\t\t\tsetCalls((list) => [record, ...list].slice(0, limit));\n\t\t};\n\t\tconst ended = (event: TabMcpEventMap[\"toolcallend\"]) => {\n\t\t\tconst end = event.detail;\n\t\t\tsetCalls((list) =>\n\t\t\t\tlist.some((r) => r.id === end.id)\n\t\t\t\t\t? list.map((r) => (r.id === end.id ? { ...r, end } : r))\n\t\t\t\t\t: list,\n\t\t\t);\n\t\t};\n\t\tmcp.addEventListener(\"toolcall\", started);\n\t\tmcp.addEventListener(\"toolcallend\", ended);\n\t\tsetCalls((list) => (list.length > limit ? list.slice(0, limit) : list));\n\t\treturn () => {\n\t\t\tmcp.removeEventListener(\"toolcall\", started);\n\t\t\tmcp.removeEventListener(\"toolcallend\", ended);\n\t\t};\n\t}, [mcp, limit]);\n\treturn calls;\n}\n\n/** Props of `ConnectButton`: a button's, with `children` that may depend on the state. */\nexport interface ConnectButtonProps\n\textends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"type\"> {\n\t/** The label; default: the state (\"Connect your AI app\", \"AI app connected\"). */\n\tchildren?: ReactNode | ((state: TabMcpSnapshot) => ReactNode);\n}\n\n/** Failed reconnect attempts after which the default label says the connection is lost. */\nconst LOST_AFTER_ATTEMPTS = 3;\n\n/**\n * `ConnectButton`'s texts in English: the same as these keys of `STRINGS`\n * (a test keeps them equal), here so that a page loads not the whole table\n * of `./strings` with the button, only these few texts (review of PR 181).\n * @internal\n */\nexport const BUTTON_TEXTS = {\n\tlang: \"en\",\n\tconnectTitle: \"Connect your AI app\",\n\tconnecting: \"Connecting…\",\n\treconnecting: \"Connection lost. Reconnecting…\",\n\tbuttonReconnecting: \"Reconnecting…\",\n\tbuttonConnected: { one: \"AI app connected\", other: \"{n} AI apps connected\" },\n};\ntype ButtonTexts = Pick<DialogStrings, keyof typeof BUTTON_TEXTS>;\n\n/** The button's texts: the `TabMcp`'s `ui.strings` where they are of the right kind. */\nfunction buttonTexts(strings: Partial<DialogStrings> | undefined): ButtonTexts {\n\tconst s: Record<string, unknown> = { ...BUTTON_TEXTS };\n\tfor (const [key, english] of Object.entries(BUTTON_TEXTS)) {\n\t\tconst value: unknown = strings?.[key as keyof ButtonTexts];\n\t\tif (\n\t\t\ttypeof english === \"string\" ? typeof value === \"string\" : isPlural(value)\n\t\t)\n\t\t\ts[key] = value;\n\t}\n\treturn s as ButtonTexts;\n}\n\n/** The default label of `ConnectButton`, in the texts of the `TabMcp`'s `ui.strings`. */\nfunction connectLabel(state: TabMcpSnapshot, s: ButtonTexts): string {\n\tif (state.state === \"connected\" && state.grants.length > 0)\n\t\treturn plural(s.buttonConnected, state.grants.length, s);\n\tif (state.state === \"reconnecting\")\n\t\treturn (state.reconnecting?.attempt ?? 0) > LOST_AFTER_ATTEMPTS\n\t\t\t? s.reconnecting\n\t\t\t: s.buttonReconnecting;\n\tif (state.state === \"connecting\") return s.connecting;\n\treturn s.connectTitle;\n}\n\n/**\n * A button that opens the library's \"Connect your AI app\" dialog\n * (`showConnectDialog()`), labelled with the state. `data-state` is\n * `disconnected`, `connecting`, `connected` or `reconnecting`, for styling.\n * An `onClick` that calls `event.preventDefault()` keeps the dialog closed.\n * Renders nothing for a `TabMcp` without a relay: there is nothing to\n * connect.\n */\nexport function ConnectButton({\n\tchildren,\n\tonClick,\n\t...rest\n}: ConnectButtonProps): ReactElement | null {\n\tconst mcp = useTabMcp();\n\tconst state = useTabMcpState();\n\tif (!mcp.hasRelay) return null;\n\tconst label =\n\t\tchildren === undefined\n\t\t\t? connectLabel(state, buttonTexts(mcp._ui?.strings))\n\t\t\t: typeof children === \"function\"\n\t\t\t\t? children(state)\n\t\t\t\t: children;\n\treturn createElement(\n\t\t\"button\",\n\t\t{\n\t\t\ttype: \"button\",\n\t\t\t\"data-state\": state.state,\n\t\t\t...rest,\n\t\t\tonClick: (event: MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\t\t\t\tif (event.defaultPrevented) return;\n\t\t\t\tmcp.showConnectDialog().catch((error: unknown) => {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tlabel,\n\t);\n}\n",
|
|
5
|
+
"\"use client\";\n/**\n * `@ractive-ch/tab-mcp-client/react`: React bindings for single-page apps\n * (iteration 9). One `TabMcp` per `<TabMcpProvider>`, hooks for its state,\n * its tools and the calls of AI apps, and a button that opens the connect\n * dialog. `react` (18.3 or 19) is an optional peer dependency; the core\n * entry stays free of it.\n */\n\nimport {\n\ttype ButtonHTMLAttributes,\n\tcreateContext,\n\tcreateElement,\n\ttype MouseEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseInsertionEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedTools,\n} from \"./allowed.ts\";\nimport {\n\ttype BrowserExtension,\n\ttype ConfirmRequest,\n\ttype ConnectionState,\n\ttype Grant,\n\ttype IdentityAssertionRequest,\n\ttype IdentityState,\n\ttype PairingCode,\n\ttype ReconnectingInfo,\n\ttype RegisterToolOptions,\n\ttype SessionInfo,\n\tTabMcp,\n\ttype TabMcpEventMap,\n\ttype TabMcpOptions,\n\ttype Tool,\n\ttype ToolCallEnd,\n\ttype ToolCallStart,\n} from \"./index.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport { isPlural, plural } from \"./text.ts\";\n\n/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */\nexport interface TabMcpSnapshot {\n\tstate: ConnectionState;\n\t/** The session while connected; `session.address` is the MCP address to give to AI apps. */\n\tsession: SessionInfo | undefined;\n\t/** The AI apps connected to this address. */\n\tgrants: readonly Grant[];\n\t/** The pairing code to show, while the connect dialog is open. */\n\tpairingCode: PairingCode | undefined;\n\t/** Identity binding: until when a sign-in pairs the page (`TabMcp.pairingUntil`). */\n\tpairingUntil: string | undefined;\n\t/** Who the relay knows as the page's user (identity binding). */\n\tidentity: IdentityState;\n\t/** Why the relay refused the identity (`identity: \"refused\"`). */\n\tidentityMessage: string | undefined;\n\t/** While `state` is `reconnecting`: the next attempt and when it starts. */\n\treconnecting: ReconnectingInfo | undefined;\n\t/** Names of the registered tools. */\n\ttools: readonly string[];\n\t/**\n\t * The tab-mcp browser extension while it serves the page, with the AI\n\t * apps connected through it (`TabMcp.extension`, `webmcp: true`).\n\t */\n\textension: BrowserExtension | undefined;\n}\n\nconst EMPTY: readonly never[] = Object.freeze([]);\n\n/** What the server renders, and what hydration starts from. */\nconst SERVER_SNAPSHOT: TabMcpSnapshot = Object.freeze({\n\tstate: \"disconnected\",\n\tsession: undefined,\n\tgrants: EMPTY,\n\tpairingCode: undefined,\n\tpairingUntil: undefined,\n\tidentity: \"none\",\n\tidentityMessage: undefined,\n\treconnecting: undefined,\n\ttools: EMPTY,\n\textension: undefined,\n});\n\nconst STATE_EVENTS = [\n\t\"statechange\",\n\t\"grantschange\",\n\t\"pairingcode\",\n\t\"pairinguntil\",\n\t\"identitychange\",\n\t\"toolschange\",\n\t\"extensionchange\",\n] as const satisfies readonly (keyof TabMcpEventMap)[];\n\n/** The external store of one `TabMcp`: a snapshot that changes only with the instance. */\nclass Store {\n\treadonly #mcp: TabMcp;\n\treadonly #listeners = new Set<() => void>();\n\t#snapshot: TabMcpSnapshot;\n\n\tconstructor(mcp: TabMcp) {\n\t\tthis.#mcp = mcp;\n\t\tthis.#snapshot = this.#read(SERVER_SNAPSHOT);\n\t\tconst update = () => {\n\t\t\tconst next = this.#read(this.#snapshot);\n\t\t\tif (next === this.#snapshot) return;\n\t\t\tthis.#snapshot = next;\n\t\t\tfor (const listener of [...this.#listeners]) listener();\n\t\t};\n\t\tfor (const type of STATE_EVENTS) mcp.addEventListener(type, update);\n\t}\n\n\treadonly subscribe = (listener: () => void): (() => void) => {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t};\n\n\treadonly getSnapshot = (): TabMcpSnapshot => this.#snapshot;\n\n\t/** The current values; `previous` itself when none changed. */\n\t#read(previous: TabMcpSnapshot): TabMcpSnapshot {\n\t\tconst mcp = this.#mcp;\n\t\tconst tools = mcp.tools;\n\t\tconst next: TabMcpSnapshot = {\n\t\t\tstate: mcp.state,\n\t\t\tsession: mcp.session,\n\t\t\tgrants: mcp.grants,\n\t\t\tpairingCode: mcp.pairingCode,\n\t\t\tpairingUntil: mcp.pairingUntil,\n\t\t\tidentity: mcp.identity,\n\t\t\tidentityMessage: mcp.identityMessage,\n\t\t\treconnecting: mcp.reconnecting,\n\t\t\ttools:\n\t\t\t\ttools.length === previous.tools.length &&\n\t\t\t\ttools.every((t, i) => t === previous.tools[i])\n\t\t\t\t\t? previous.tools\n\t\t\t\t\t: tools,\n\t\t\textension: mcp.extension,\n\t\t};\n\t\tconst same = (Object.keys(next) as (keyof TabMcpSnapshot)[]).every(\n\t\t\t(key) => next[key] === previous[key],\n\t\t);\n\t\treturn same ? previous : next;\n\t}\n}\n\nconst stores = new WeakMap<TabMcp, Store>();\n\nfunction storeOf(mcp: TabMcp): Store {\n\tlet store = stores.get(mcp);\n\tif (store === undefined) {\n\t\tstore = new Store(mcp);\n\t\tstores.set(mcp, store);\n\t}\n\treturn store;\n}\n\nconst Context = createContext<TabMcp | undefined>(undefined);\n\n/** Props of `TabMcpProvider`: the `TabMcp` options, or an instance of your own. */\nexport type TabMcpProviderProps = (\n\t| (TabMcpOptions & { client?: undefined })\n\t| { client: TabMcp }\n) & { children?: ReactNode };\n\n/**\n * Makes one `TabMcp` for its tree from the props of its first render\n * (`relay` may be left out, as for `TabMcp`). A\n * changed `relay` or `server.name` makes a new instance (and warns); other\n * changes are ignored, but `onConfirm` and `identityAssertion` are always\n * the latest ones (also when added or removed later). Pass `client` to use an instance of your own instead. The\n * provider's own instance is disconnected when the provider unmounts; it\n * never connects on the server.\n */\nexport function TabMcpProvider(props: TabMcpProviderProps): ReactElement {\n\tconst latest = useRef(props);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = props;\n\t});\n\tconst own = props.client === undefined ? props : undefined;\n\tconst relay = own?.relay;\n\tconst serverName = own?.server?.name;\n\tconst create = (): TabMcp => {\n\t\tconst {\n\t\t\tchildren: _,\n\t\t\tclient: __,\n\t\t\t...options\n\t\t} = props as TabMcpOptions & {\n\t\t\tchildren?: ReactNode;\n\t\t\tclient?: undefined;\n\t\t};\n\t\t// Always installed, so that a handler added, changed or removed in a\n\t\t// later render counts: without one, the library's own behaviour.\n\t\tconst handlers = () => latest.current as Partial<TabMcpOptions>;\n\t\tconst onConfirm = (request: ConfirmRequest) => {\n\t\t\tconst ask = handlers().onConfirm;\n\t\t\treturn ask === undefined ? instance.confirmInPage(request) : ask(request);\n\t\t};\n\t\t// Whether the page gave a handler: the WebMCP mirror warns without one.\n\t\tObject.defineProperty(onConfirm, \"own\", {\n\t\t\tget: () => handlers().onConfirm !== undefined,\n\t\t});\n\t\tconst instance: TabMcp = new TabMcp({\n\t\t\t...options,\n\t\t\tonConfirm,\n\t\t\tidentityAssertion: (request: IdentityAssertionRequest) =>\n\t\t\t\thandlers().identityAssertion?.(request) ?? null,\n\t\t});\n\t\treturn instance;\n\t};\n\t// In state, not in `useMemo`, which React may discard and run again. A\n\t// changed relay or server name replaces it while rendering, as React\n\t// recommends for state that follows props.\n\tconst [state, setState] = useState(() =>\n\t\town === undefined ? undefined : { relay, serverName, mcp: create() },\n\t);\n\tlet current = state;\n\tif (own === undefined) {\n\t\tcurrent = undefined;\n\t} else if (\n\t\tcurrent === undefined ||\n\t\tcurrent.relay !== relay ||\n\t\tcurrent.serverName !== serverName\n\t) {\n\t\tcurrent = { relay, serverName, mcp: create() };\n\t}\n\tif (current !== state) setState(current);\n\tconst mcp = props.client ?? (current as { mcp: TabMcp }).mcp;\n\n\tconst previous = useRef<TabMcp | undefined>(undefined);\n\t/** The instance the mounted effect is for; `undefined` after its cleanup. */\n\tconst active = useRef<TabMcp | undefined>(undefined);\n\tuseEffect(() => {\n\t\tif (\n\t\t\tprevious.current !== undefined &&\n\t\t\tprevious.current !== mcp &&\n\t\t\tprops.client === undefined\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"TabMcpProvider: relay or server.name changed, so the page has a new TabMcp; its tools and connection start over\",\n\t\t\t);\n\t\t}\n\t\tprevious.current = mcp;\n\t\tif (props.client !== undefined) return;\n\t\tactive.current = mcp;\n\t\t// Disconnected a moment later, unless the effect ran again for the same\n\t\t// instance meanwhile: StrictMode's simulated unmount and mount would\n\t\t// otherwise cancel a `connect()` that a child's effect started (CU 24).\n\t\treturn () => {\n\t\t\tactive.current = undefined;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (active.current !== mcp) mcp.disconnect();\n\t\t\t});\n\t\t};\n\t}, [mcp, props.client]);\n\n\treturn createElement(Context.Provider, { value: mcp }, props.children);\n}\n\n/** The provider's `TabMcp`, for everything the hooks do not cover. */\nexport function useTabMcp(): TabMcp {\n\tconst mcp = useContext(Context);\n\tif (mcp === undefined)\n\t\tthrow new Error(\"useTabMcp: no <TabMcpProvider> above this component\");\n\treturn mcp;\n}\n\n/**\n * The connection state, address, grants, pairing code, identity,\n * reconnecting and the tab-mcp browser extension of the provider's `TabMcp`. Re-renders only when one of them\n * changes; the server and hydration see `disconnected`.\n */\nexport function useTabMcpState(): TabMcpSnapshot {\n\tconst store = storeOf(useTabMcp());\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getSnapshot,\n\t\t() => SERVER_SNAPSHOT,\n\t);\n}\n\n/** What `useAllowedTools(grantId)` returns: one object per change, the same object otherwise. */\nexport interface AllowedToolsSnapshot {\n\t/** The page's tools that ask, each with whether it runs without asking for this app. */\n\ttools: (AllowedTool & { allowed: boolean })[];\n\t/** \"Always allow everything\" is on for this app. */\n\teverything: boolean;\n\t/** To change them: `allow`, `ask`, `setEverything`, `forget`. */\n\tallowedTools: AllowedTools;\n}\n\n/**\n * The tools that run without asking for one connected AI app\n * (`grant.grantId`), for switches of the page's own: `allowedTools(mcp)` of\n * `@ractive-ch/tab-mcp-client/allowed` as state. Re-renders when they or the\n * tools change; the server and hydration see none.\n */\nexport function useAllowedTools(grantId: string): AllowedToolsSnapshot {\n\tconst allowed = allowedTools(useTabMcp());\n\tconst subscribe = useCallback(\n\t\t(changed: () => void) => allowed.onChange(changed),\n\t\t[allowed],\n\t);\n\tconst last = useRef<{ key: string; snapshot: AllowedToolsSnapshot }>(\n\t\tundefined,\n\t);\n\tconst server = useRef<AllowedToolsSnapshot>(undefined);\n\t// Reads only: a changed tool left the list already.\n\tconst getSnapshot = () => {\n\t\tconst everything = allowed.everything(grantId);\n\t\tconst listed = new Set(allowed.list(grantId));\n\t\tconst tools = allowed\n\t\t\t.tools()\n\t\t\t.map((t) => ({ ...t, allowed: everything || listed.has(t.name) }));\n\t\tconst key = JSON.stringify([grantId, everything, tools]);\n\t\tif (\n\t\t\tlast.current?.key !== key ||\n\t\t\tlast.current.snapshot.allowedTools !== allowed\n\t\t)\n\t\t\tlast.current = {\n\t\t\t\tkey,\n\t\t\t\tsnapshot: { tools, everything, allowedTools: allowed },\n\t\t\t};\n\t\treturn last.current.snapshot;\n\t};\n\tconst getServerSnapshot = () => {\n\t\tif (server.current?.allowedTools !== allowed)\n\t\t\tserver.current = { tools: [], everything: false, allowedTools: allowed };\n\t\treturn server.current;\n\t};\n\treturn useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n\n/** Options of `useTool`: `RegisterToolOptions` without the signal (the hook has its own). */\nexport type UseToolOptions = Omit<RegisterToolOptions, \"signal\">;\n\n/**\n * Registers a tool while the component is mounted (with an `AbortSignal`,\n * aborted on unmount). `execute` is always the latest one, so a new closure\n * on each render does not register again; the tool is registered again only\n * when its name, title, description, input or output schema or annotations\n * change, or `options.callers` or `options.exposedTo` (a tool allowed until reload stays allowed when it is\n * registered again unchanged). A duplicate name or an invalid tool is thrown\n * from the component's next render, for an error boundary.\n */\nexport function useTool<Input extends object = Record<string, unknown>>(\n\ttool: Tool<Input>,\n\toptions: UseToolOptions = {},\n): void {\n\tconst mcp = useTabMcp();\n\tconst latest = useRef(tool);\n\tuseInsertionEffect(() => {\n\t\tlatest.current = tool;\n\t});\n\tconst [failure, setFailure] = useState<{ error: unknown } | undefined>();\n\tif (failure !== undefined) throw failure.error;\n\tconst shape = JSON.stringify([\n\t\ttool.name,\n\t\ttool.title,\n\t\ttool.description,\n\t\ttool.inputSchema,\n\t\ttool.outputSchema,\n\t\ttool.annotations,\n\t\toptions.callers,\n\t\toptions.exposedTo,\n\t]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: `shape` stands for the tool and its options; `execute` is read through the ref\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\t\tconst { execute: _, ...fields } = latest.current;\n\t\tmcp\n\t\t\t.registerTool(\n\t\t\t\t{\n\t\t\t\t\t...fields,\n\t\t\t\t\texecute: (input: Input, options) =>\n\t\t\t\t\t\tlatest.current.execute(input, options),\n\t\t\t\t},\n\t\t\t\t{ ...options, signal: controller.signal },\n\t\t\t)\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tif (!controller.signal.aborted) setFailure({ error });\n\t\t\t});\n\t\treturn () => controller.abort();\n\t}, [mcp, shape]);\n}\n\n/** A tool call of an AI app, as `useToolCalls()` lists it. */\nexport interface ToolCallRecord extends ToolCallStart {\n\t/** When it started, `Date.now()`. */\n\tstartedAt: number;\n\t/** How it ended; missing while it runs. */\n\tend?: ToolCallEnd;\n}\n\nexport interface UseToolCallsOptions {\n\t/** How many calls to keep; default 20. */\n\tlimit?: number;\n}\n\n/**\n * The recent tool calls of AI apps since the component mounted, newest\n * first, each with its end once it is over: for an activity view.\n */\nexport function useToolCalls(\n\toptions: UseToolCallsOptions = {},\n): readonly ToolCallRecord[] {\n\tconst mcp = useTabMcp();\n\tconst limit = Math.max(0, options.limit ?? 20);\n\tconst [calls, setCalls] = useState<readonly ToolCallRecord[]>(EMPTY);\n\tuseEffect(() => {\n\t\tconst started = (event: TabMcpEventMap[\"toolcall\"]) => {\n\t\t\tconst record: ToolCallRecord = { ...event.detail, startedAt: Date.now() };\n\t\t\tsetCalls((list) => [record, ...list].slice(0, limit));\n\t\t};\n\t\tconst ended = (event: TabMcpEventMap[\"toolcallend\"]) => {\n\t\t\tconst end = event.detail;\n\t\t\tsetCalls((list) =>\n\t\t\t\tlist.some((r) => r.id === end.id)\n\t\t\t\t\t? list.map((r) => (r.id === end.id ? { ...r, end } : r))\n\t\t\t\t\t: list,\n\t\t\t);\n\t\t};\n\t\tmcp.addEventListener(\"toolcall\", started);\n\t\tmcp.addEventListener(\"toolcallend\", ended);\n\t\tsetCalls((list) => (list.length > limit ? list.slice(0, limit) : list));\n\t\treturn () => {\n\t\t\tmcp.removeEventListener(\"toolcall\", started);\n\t\t\tmcp.removeEventListener(\"toolcallend\", ended);\n\t\t};\n\t}, [mcp, limit]);\n\treturn calls;\n}\n\n/** Props of `ConnectButton`: a button's, with `children` that may depend on the state. */\nexport interface ConnectButtonProps\n\textends Omit<ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"type\"> {\n\t/** The label; default: the state (\"Connect your AI app\", \"AI app connected\"). */\n\tchildren?: ReactNode | ((state: TabMcpSnapshot) => ReactNode);\n}\n\n/** Failed reconnect attempts after which the default label says the connection is lost. */\nconst LOST_AFTER_ATTEMPTS = 3;\n\n/**\n * `ConnectButton`'s texts in English: the same as these keys of `STRINGS`\n * (a test keeps them equal), here so that a page loads not the whole table\n * of `./strings` with the button, only these few texts (review of PR 181).\n * @internal\n */\nexport const BUTTON_TEXTS = {\n\tlang: \"en\",\n\tconnectTitle: \"Connect your AI app\",\n\tconnecting: \"Connecting…\",\n\treconnecting: \"Connection lost. Reconnecting…\",\n\tbuttonReconnecting: \"Reconnecting…\",\n\tbuttonConnected: { one: \"AI app connected\", other: \"{n} AI apps connected\" },\n};\ntype ButtonTexts = Pick<DialogStrings, keyof typeof BUTTON_TEXTS>;\n\n/** The button's texts: the `TabMcp`'s `ui.strings` where they are of the right kind. */\nfunction buttonTexts(strings: Partial<DialogStrings> | undefined): ButtonTexts {\n\tconst s: Record<string, unknown> = { ...BUTTON_TEXTS };\n\tfor (const [key, english] of Object.entries(BUTTON_TEXTS)) {\n\t\tconst value: unknown = strings?.[key as keyof ButtonTexts];\n\t\tif (\n\t\t\ttypeof english === \"string\" ? typeof value === \"string\" : isPlural(value)\n\t\t)\n\t\t\ts[key] = value;\n\t}\n\treturn s as ButtonTexts;\n}\n\n/** The default label of `ConnectButton`, in the texts of the `TabMcp`'s `ui.strings`. */\nfunction connectLabel(state: TabMcpSnapshot, s: ButtonTexts): string {\n\tif (state.state === \"connected\" && state.grants.length > 0)\n\t\treturn plural(s.buttonConnected, state.grants.length, s);\n\tif (state.state === \"reconnecting\")\n\t\treturn (state.reconnecting?.attempt ?? 0) > LOST_AFTER_ATTEMPTS\n\t\t\t? s.reconnecting\n\t\t\t: s.buttonReconnecting;\n\tif (state.state === \"connecting\") return s.connecting;\n\treturn s.connectTitle;\n}\n\n/**\n * A button that opens the library's \"Connect your AI app\" dialog\n * (`showConnectDialog()`), labelled with the state. `data-state` is\n * `disconnected`, `connecting`, `connected` or `reconnecting`, for styling.\n * An `onClick` that calls `event.preventDefault()` keeps the dialog closed.\n * Renders nothing for a `TabMcp` without a relay: there is nothing to\n * connect.\n */\nexport function ConnectButton({\n\tchildren,\n\tonClick,\n\t...rest\n}: ConnectButtonProps): ReactElement | null {\n\tconst mcp = useTabMcp();\n\tconst state = useTabMcpState();\n\tif (!mcp.hasRelay) return null;\n\tconst label =\n\t\tchildren === undefined\n\t\t\t? connectLabel(state, buttonTexts(mcp._ui?.strings))\n\t\t\t: typeof children === \"function\"\n\t\t\t\t? children(state)\n\t\t\t\t: children;\n\treturn createElement(\n\t\t\"button\",\n\t\t{\n\t\t\ttype: \"button\",\n\t\t\t\"data-state\": state.state,\n\t\t\t...rest,\n\t\t\tonClick: (event: MouseEvent<HTMLButtonElement>) => {\n\t\t\t\tonClick?.(event);\n\t\t\t\tif (event.defaultPrevented) return;\n\t\t\t\tmcp.showConnectDialog().catch((error: unknown) => {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tlabel,\n\t);\n}\n",
|
|
6
6
|
"/**\n * Filling in the texts of `strings.ts`: placeholders, plural forms and lists,\n * by the rules of the texts' language (`Intl`), not by grammar made by hand.\n * No DOM and no texts, so that `./react` can use it without loading the\n * table, as well as the dialogs.\n */\n\nimport type { DialogStrings, PluralText } from \"./strings.ts\";\n\n/** What the helpers need of the texts: their language. */\ntype InLanguage = { lang: string };\n\n/** `template` with its `{name}` placeholders filled in, as text. */\nexport function format(\n\ttemplate: string,\n\tvalues: Record<string, string>,\n): string {\n\treturn template.replace(\n\t\t/\\{(\\w+)\\}/g,\n\t\t(all, key: string) => values[key] ?? all,\n\t);\n}\n\n/**\n * `Intl` objects for the texts' language; a `lang` the browser cannot\n * read (a malformed tag throws) uses English rules instead.\n */\nfunction inLanguage<T>(make: (lang: string) => T, lang: string): T {\n\ttry {\n\t\treturn make(lang);\n\t} catch {\n\t\treturn make(\"en\");\n\t}\n}\n\n/** Whether `value` is a plural text: an object of strings with `other`. */\nexport const isPlural = (value: unknown): value is PluralText =>\n\ttypeof value === \"object\" &&\n\tvalue !== null &&\n\ttypeof (value as { other?: unknown }).other === \"string\" &&\n\tObject.values(value).every((form) => typeof form === \"string\");\n\nconst warned = new WeakSet<object>();\n\n/**\n * A table with texts but no `lang` is taken as English: its plural forms\n * follow English rules and the dialogs say `lang=\"en\"`. Said once per table\n * in the console, as it is almost always a translation that forgot its tag.\n */\nexport function warnWithoutLang(strings: object | undefined): void {\n\tif (strings === undefined || warned.has(strings)) return;\n\tconst texts = Object.entries(strings).filter(\n\t\t([key, value]) => key !== \"lang\" && key !== \"dir\" && value !== undefined,\n\t);\n\tif (texts.length === 0 || typeof (strings as InLanguage).lang === \"string\")\n\t\treturn;\n\twarned.add(strings);\n\tconsole.warn(\n\t\t\"tab-mcp: ui.strings has texts but no lang, so they count as English (plural forms, lists, the dialogs' lang). Add lang, the language tag of the texts.\",\n\t);\n}\n\n/**\n * The form of `text` for the count `n`, by the plural rules of the texts'\n * language, with `{n}` filled in; `other` where the table lacks the form.\n */\nexport function pluralForm(text: PluralText, n: number, s: InLanguage): string {\n\tconst category = inLanguage((l) => new Intl.PluralRules(l), s.lang).select(n);\n\treturn format(text[category] ?? text.other, { n: String(n) });\n}\n\n/** `pluralForm` with the other placeholders filled in too, as text. */\nexport function plural(\n\ttext: PluralText,\n\tn: number,\n\ts: InLanguage,\n\tvalues: Record<string, string> = {},\n): string {\n\treturn format(pluralForm(text, n, s), values);\n}\n\n/** How the texts' language joins a list (\"A, B and C\"). */\nexport function listFormat(s: InLanguage): Intl.ListFormat {\n\treturn inLanguage(\n\t\t(l) => new Intl.ListFormat(l, { type: \"conjunction\" }),\n\t\ts.lang,\n\t);\n}\n\n/** \"A and B\", \"A, B and C\", as the texts' language joins a list. */\nexport function listOf(items: string[], s: InLanguage): string {\n\treturn listFormat(s).format(items);\n}\n\n/**\n * The direction of the texts: their own `dir`, else the one the browser\n * knows for `lang` (`Intl.Locale`'s text info, not in every browser), else\n * left to right.\n */\nexport function directionOf(s: DialogStrings): \"ltr\" | \"rtl\" {\n\tif (s.dir !== undefined) return s.dir;\n\ttry {\n\t\tconst locale = new Intl.Locale(s.lang) as Intl.Locale & {\n\t\t\tgetTextInfo?: () => { direction?: string };\n\t\t\ttextInfo?: { direction?: string };\n\t\t};\n\t\tconst info = locale.getTextInfo?.() ?? locale.textInfo;\n\t\treturn info?.direction === \"rtl\" ? \"rtl\" : \"ltr\";\n\t} catch {\n\t\treturn \"ltr\";\n\t}\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;;AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA;AAAA;AAAA;AAKA;AAAA;AAAA;;;AChBO,SAAS,MAAM,CACrB,UACA,QACS;AAAA,EACT,OAAO,SAAS,QACf,cACA,CAAC,KAAK,QAAgB,OAAO,QAAQ,GACtC;AAAA;AAOD,SAAS,UAAa,CAAC,MAA2B,MAAiB;AAAA,EAClE,IAAI;AAAA,IACH,OAAO,KAAK,IAAI;AAAA,IACf,MAAM;AAAA,IACP,OAAO,KAAK,IAAI;AAAA;AAAA;AAKX,IAAM,WAAW,CAAC,UACxB,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA8B,UAAU,YAChD,OAAO,OAAO,KAAK,EAAE,MAAM,CAAC,SAAS,OAAO,SAAS,QAAQ;AAE9D,IAAM,SAAS,IAAI;AAwBZ,SAAS,UAAU,CAAC,MAAkB,GAAW,GAA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,OAAO,EAAE;AAAA,EAC3C,OAAO,EAAE;AAAA;AAWH,SAAS,aAAa;AAAA,EAC5B;AAAA,EACA;AAAA,KACG;AAAA,GACwC;AAAA,EAC3C,MAAM,MAAM,UAAU;AAAA,EACtB,MAAM,QAAQ,eAAe;AAAA,EAC7B,IAAI,CAAC,IAAI;AAAA,IAAU,OAAO;AAAA,EAC1B,MAAM,QACL,aAAa,YACV,aAAa,OAAO,YAAY,IAAI,KAAK,OAAO,CAAC,IACjD,OAAO,aAAa,aACnB,SAAS,KAAK,IACd;AAAA,EACL,OAAO,cACN,UACA;AAAA,IACC,MAAM;AAAA,IACN,cAAc,MAAM;AAAA,OACjB;AAAA,IACH,SAAS,CAAC,UAAyC;AAAA,MAClD,UAAU,KAAK;AAAA,MACf,IAAI,MAAM;AAAA,QAAkB;AAAA,MAC5B,IAAI,kBAAkB,EAAE,MAAM,CAAC,UAAmB;AAAA,QACjD,QAAQ,MAAM,KAAK;AAAA,OACnB;AAAA;AAAA,EAEH,GACA,KACD;AAAA;",
|
|
9
|
+
"debugId": "0BE3C1AC61208FFB64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/skill/SKILL.md
CHANGED
|
@@ -7,7 +7,7 @@ compatibility: Browser library for any web page (ES modules); the relay needs Bu
|
|
|
7
7
|
|
|
8
8
|
# Add tab-mcp to a web app
|
|
9
9
|
|
|
10
|
-
This skill describes `@ractive-ch/tab-mcp-client` 0.21.0
|
|
10
|
+
This skill describes `@ractive-ch/tab-mcp-client` 0.21.0. The package's
|
|
11
11
|
[README](../README.md)
|
|
12
12
|
is the full reference; read the section you need there when this skill is not enough. Its
|
|
13
13
|
[CHANGELOG](../CHANGELOG.md)
|
|
@@ -49,7 +49,7 @@ Without a bundler, import the self-contained build from a CDN:
|
|
|
49
49
|
|
|
50
50
|
```html
|
|
51
51
|
<script type="module">
|
|
52
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.21.0
|
|
52
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.21.0/cdn/tab-mcp-client.min.js";
|
|
53
53
|
</script>
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -318,7 +318,8 @@ const mcp = new TabMcp({ relay, server, webmcp: true });
|
|
|
318
318
|
await mcp.registerTool(deleteNoteTool); // an AI app is asked; an unvouched WebMCP call is not
|
|
319
319
|
```
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
Whether anyone asks before a tool that asks runs, and who, depends on the caller
|
|
322
|
+
(DEC-215); for some callers nobody does. The last three rows all arrive as
|
|
322
323
|
`client: { kind: "webmcp" }` without `via`; the page cannot tell them apart:
|
|
323
324
|
|
|
324
325
|
| Caller | Can it click in the tab? | Who asks |
|
|
@@ -338,14 +339,17 @@ Who asks before a tool that asks runs (DEC-215). The last three rows all arrive
|
|
|
338
339
|
(since client 0.20, DEC-209): hiding them did not stop an agent that drives the tab, it
|
|
339
340
|
clicked the page's own controls instead, with no question. `callers` without
|
|
340
341
|
`"webmcp"` keeps a tool out (React: `useTool(tool, { callers: ["relay", "local"] })`).
|
|
341
|
-
- The library shows an unvouched WebMCP call no question (since DEC-215
|
|
342
|
+
- The library shows an unvouched WebMCP call no question (since client 0.21, DEC-215;
|
|
343
|
+
0.20 showed its dialog): an agent that
|
|
342
344
|
drives the tab clicked "Allow once" in the dialog itself. For another extension or an
|
|
343
345
|
`exposedTo` origin the dialog was a real check, and it is gone too. Such a tool is
|
|
344
346
|
registered with `consequentialHint: true`, so a caller that heeds it asks its user.
|
|
345
347
|
The page's `onConfirm` still gets the call (`client.kind === "webmcp"`, no `via`):
|
|
346
348
|
decide there in code (refuse, or a rule), never by showing something, which an agent
|
|
347
349
|
can click too. Without `onConfirm` the call runs. A tool that must not run on such a
|
|
348
|
-
caller's word leaves `"webmcp"` out of `callers`, and gets no `exposedTo
|
|
350
|
+
caller's word leaves `"webmcp"` out of `callers`, and gets no `exposedTo` (the library
|
|
351
|
+
warns in the console about a tool that asks with `exposedTo` on a page without
|
|
352
|
+
`onConfirm`).
|
|
349
353
|
- **The tab-mcp browser extension.** With `webmcp: true` the page and the extension
|
|
350
354
|
shake hands. A call the user has just allowed in the extension (asked in its side
|
|
351
355
|
panel, or covered by its "Always allow" switch; the same tool, equal arguments, within
|
|
@@ -408,7 +412,7 @@ Local development (a page on `http://localhost:3000`):
|
|
|
408
412
|
docker run --rm -p 8080:8080 -e NODE_ENV=development \
|
|
409
413
|
-e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
|
|
410
414
|
-e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
|
|
411
|
-
-e TAB_MCP_STORE=memory ractive/tab-mcp:0.13.2
|
|
415
|
+
-e TAB_MCP_STORE=memory ractive/tab-mcp:0.13.2
|
|
412
416
|
```
|
|
413
417
|
|
|
414
418
|
Production: name the image version (pre-releases have no `latest` tag), keep `/data` on
|
|
@@ -418,7 +422,7 @@ a volume, and put the relay behind TLS:
|
|
|
418
422
|
docker run -d -p 127.0.0.1:8080:8080 -v tab-mcp-data:/data \
|
|
419
423
|
-e TAB_MCP_PUBLIC_URL=https://relay.example.com \
|
|
420
424
|
-e TAB_MCP_ALLOWED_ORIGINS=https://app.example.com \
|
|
421
|
-
-e TAB_MCP_TRUST_PROXY=x-real-ip ractive/tab-mcp:0.13.2
|
|
425
|
+
-e TAB_MCP_TRUST_PROXY=x-real-ip ractive/tab-mcp:0.13.2
|
|
422
426
|
```
|
|
423
427
|
|
|
424
428
|
`x-real-ip` fits an nginx proxy that sets `X-Real-IP $remote_addr`; behind Caddy use
|
|
@@ -462,11 +466,11 @@ first-byte limits of CDNs happy. Health check: `GET /healthz`.
|
|
|
462
466
|
Try the pairing flow by hand with Claude Code against a local relay. For automated
|
|
463
467
|
tests of the page's tools, `@ractive-ch/tab-mcp/testing` starts a relay in the test
|
|
464
468
|
process and gives a token without pairing
|
|
465
|
-
([the relay's README](https://github.com/ractive/tab-mcp/tree/relay-v0.13.2
|
|
469
|
+
([the relay's README](https://github.com/ractive/tab-mcp/tree/relay-v0.13.2/packages/tab-mcp#testing-a-pages-tools)).
|
|
466
470
|
Live pages to try are at <https://ractive.ch/tab-mcp/>. The relay's docs cover every
|
|
467
471
|
setting and the proxy details:
|
|
468
|
-
[configuration](https://github.com/ractive/tab-mcp/blob/relay-v0.13.2
|
|
469
|
-
[self-hosting](https://github.com/ractive/tab-mcp/blob/relay-v0.13.2
|
|
472
|
+
[configuration](https://github.com/ractive/tab-mcp/blob/relay-v0.13.2/docs/configuration.md),
|
|
473
|
+
[self-hosting](https://github.com/ractive/tab-mcp/blob/relay-v0.13.2/docs/self-hosting.md),
|
|
470
474
|
[compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md) (which
|
|
471
475
|
AI apps work, kept up to date) and the
|
|
472
476
|
[security policy](https://github.com/ractive/tab-mcp/blob/main/SECURITY.md).
|
|
@@ -55,5 +55,5 @@ function TodoList() {
|
|
|
55
55
|
dialog and labels itself by state.
|
|
56
56
|
- The module starts with `"use client"`: in Next.js's app router the provider renders on
|
|
57
57
|
the client and never connects on the server.
|
|
58
|
-
[examples/react-todo](https://github.com/ractive/tab-mcp/tree/client-v0.21.0
|
|
58
|
+
[examples/react-todo](https://github.com/ractive/tab-mcp/tree/client-v0.21.0/examples/react-todo)
|
|
59
59
|
is a complete app.
|
|
@@ -14,7 +14,7 @@ most 10 minutes after the user opened it: `pairingUntil` (event
|
|
|
14
14
|
Continue button; a custom UI calls `startPairing()` again only from such a click, never
|
|
15
15
|
from a timer. A reconnect the library makes by itself does not start the 10 minutes
|
|
16
16
|
again. The relay's configuration:
|
|
17
|
-
[identity binding](https://github.com/ractive/tab-mcp/blob/relay-v0.13.2
|
|
17
|
+
[identity binding](https://github.com/ractive/tab-mcp/blob/relay-v0.13.2/docs/configuration.md#identity-binding);
|
|
18
18
|
the page's side in full:
|
|
19
19
|
[Identity binding (no code)](../../README.md#identity-binding-no-code).
|
|
20
20
|
|
|
@@ -172,6 +172,24 @@ function mirror(registry, context, call, mcp, app, options, version) {
|
|
|
172
172
|
}
|
|
173
173
|
const mirrors = new Map;
|
|
174
174
|
const warned = new Set;
|
|
175
|
+
const unasked = new Set;
|
|
176
|
+
const warnUnasked = (tool, asks) => {
|
|
177
|
+
try {
|
|
178
|
+
const ask = options.onConfirm;
|
|
179
|
+
const page = globalThis.document?.location?.origin;
|
|
180
|
+
const others = (Array.isArray(tool.exposedTo) ? tool.exposedTo : []).filter((entry) => {
|
|
181
|
+
try {
|
|
182
|
+
return new URL(String(entry)).origin !== page;
|
|
183
|
+
} catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
if (asks !== true || others.length === 0 || ask && ask.own !== false || unasked.has(tool.name))
|
|
188
|
+
return;
|
|
189
|
+
unasked.add(tool.name);
|
|
190
|
+
console.warn(`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(", ")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`);
|
|
191
|
+
} catch {}
|
|
192
|
+
};
|
|
175
193
|
const sync = () => {
|
|
176
194
|
for (const [tool, controller] of mirrors) {
|
|
177
195
|
if (registry.get(tool.name) === tool)
|
|
@@ -200,7 +218,10 @@ function mirror(registry, context, call, mcp, app, options, version) {
|
|
|
200
218
|
outputSchema: tool.outputSchema,
|
|
201
219
|
annotations: hints,
|
|
202
220
|
execute: (input, options) => call(tool, input, options?.signal, handshake?.take(tool, input))
|
|
203
|
-
}, { signal, exposedTo: tool.exposedTo })).
|
|
221
|
+
}, { signal, exposedTo: tool.exposedTo })).then(() => {
|
|
222
|
+
if (!signal.aborted)
|
|
223
|
+
warnUnasked(tool, consequential);
|
|
224
|
+
}).catch((error) => {
|
|
204
225
|
if (signal.aborted)
|
|
205
226
|
return;
|
|
206
227
|
if (warned.has(tool.name))
|
|
@@ -217,5 +238,5 @@ export {
|
|
|
217
238
|
mirror
|
|
218
239
|
};
|
|
219
240
|
|
|
220
|
-
//# debugId=
|
|
221
|
-
//# sourceMappingURL=webmcp-
|
|
241
|
+
//# debugId=CA877CC5C132F0E764756E2164756E21
|
|
242
|
+
//# sourceMappingURL=webmcp-gw6rrbnh.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/handshake.ts", "../src/webmcp.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * The page's side of the handshake with the tab-mcp browser extension\n * (DEC-207), in the WebMCP mirror's chunk: only a page that offers its tools\n * to agents in the browser (`webmcp: true`) takes part.\n *\n * Plain DOM events on `document`, each with a JSON string as `detail`\n * (objects do not cross between a content script's world and the page's in\n * every browser): `tab-mcp-page` from the page, `tab-mcp-extension` from\n * the extension. Every message has `v: 1` and a `type`; a message of\n * another version, an unknown type or a malformed one is ignored, and so\n * are unknown fields.\n *\n * - The page announces itself (`hello`: the library's version, the app id,\n * the AI apps connected to it directly) when it starts, again (`update`)\n * when those apps change, and answers the extension's `hello` with an\n * `update`. It marks `<html data-tab-mcp-handshake>`, so that an\n * extension that starts later (its content script comes at\n * `document_idle`, or with a click) knows it may speak without having\n * heard the `hello`.\n * - The extension says what it is, whether it serves the page now and\n * which AI apps are connected to it (`hello`, `update`), and, right before\n * it runs a page tool the user allowed there, `vouch`: the tool, the exact\n * arguments, a nonce and the AI app; once that call ended or failed,\n * `withdraw` with the nonce, and a vouch still unused is dropped.\n * - Each side cuts the other's list of AI apps to 64 and sends no more.\n *\n * No proof of who sent what: anything that could fake the extension runs in\n * the page already, where it could skip any check. A convenience between\n * two parts the user trusts, not a security boundary.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension, Grant } from \"./types.ts\";\n\n/** From the page to the extension. */\nexport const PAGE_EVENT = \"tab-mcp-page\";\n/** From the extension to the page. */\nexport const EXTENSION_EVENT = \"tab-mcp-extension\";\n/** On `<html>`: this page takes part (for an extension that starts later). */\nexport const MARK = \"data-tab-mcp-handshake\";\n/** A vouch is kept this long (milliseconds), then dropped unused. */\nexport const VOUCH_MS = 2_000;\n/** At most this many vouches wait; beyond, the oldest goes. */\nconst MAX_VOUCHES = 16;\n/** Texts from the extension are taken up to these lengths, apps up to this count either way. */\nconst MAX_TEXT = 256;\nconst MAX_APPS = 64;\n\n/** One `TabMcp` of the page, as the handshake sees it. */\nexport interface HandshakePage {\n\t/** The library's version. */\n\treadonly version: string;\n\treadonly app: string;\n\treadonly registry: ToolRegistry;\n\t/** Vouches are taken for its tools (`trustExtension`). */\n\treadonly trust: boolean;\n\t/** The `TabMcp`: its `grants` and `grantschange`. */\n\treadonly mcp: EventTarget & { readonly grants: readonly Grant[] };\n\t/** The extension's state changed. */\n\tset(extension: BrowserExtension | undefined): void;\n}\n\n/** The AI app a vouched call came from. */\nexport interface VouchedBy {\n\tname: string;\n\thost: string;\n}\n\ninterface Vouch {\n\ttool: RegisteredTool;\n\t/** The arguments, canonical (`canonical`). */\n\targs: string;\n\tnonce: string;\n\tapp: VouchedBy;\n\tat: number;\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === \"string\" && value.length <= MAX_TEXT;\n\n/** An AI app as the extension names it; `undefined` if it is malformed. */\nfunction appOf(value: unknown): VouchedBy | undefined {\n\treturn isObject(value) && text(value[\"name\"]) && text(value[\"host\"])\n\t\t? { name: value[\"name\"], host: value[\"host\"] }\n\t\t: undefined;\n}\n\n/**\n * `value` as JSON with the keys of every object sorted: two argument\n * objects are equal when their canonical forms are.\n */\nexport function canonical(value: unknown): string {\n\treturn (\n\t\tJSON.stringify(value, (_key, v: unknown) =>\n\t\t\tisObject(v)\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n\t\t\t\t\t)\n\t\t\t\t: v,\n\t\t) ?? \"\"\n\t);\n}\n\n/** Monotonic milliseconds: a vouch's age must not follow the wall clock. */\nconst now = () => performance.now();\n\nclass Handshake {\n\treadonly #doc: Document;\n\treadonly #pages: HandshakePage[] = [];\n\t#extension: BrowserExtension | undefined;\n\t#vouches: Vouch[] = [];\n\n\tconstructor(doc: Document) {\n\t\tthis.#doc = doc;\n\t\tdoc.addEventListener(EXTENSION_EVENT, (event) =>\n\t\t\tthis.#heard((event as CustomEvent).detail),\n\t\t);\n\t\tdoc.documentElement?.setAttribute(MARK, \"1\");\n\t}\n\n\tjoin(page: HandshakePage): void {\n\t\tthis.#pages.push(page);\n\t\tif (this.#extension !== undefined) page.set(this.#extension);\n\t\tpage.mcp.addEventListener(\"grantschange\", () => this.#say(page, \"update\"));\n\t\tthis.#say(page, \"hello\");\n\t}\n\n\t#say(page: HandshakePage, type: \"hello\" | \"update\"): void {\n\t\t// The document's own `CustomEvent`: a document may take only events\n\t\t// of its realm.\n\t\tconst Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;\n\t\tthis.#doc.dispatchEvent(\n\t\t\tnew Custom(PAGE_EVENT, {\n\t\t\t\tdetail: JSON.stringify({\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttype,\n\t\t\t\t\tlibrary: page.version,\n\t\t\t\t\tapp: page.app,\n\t\t\t\t\t// Capped as the extension cuts what it hears: more would\n\t\t\t\t\t// not be heard anyway.\n\t\t\t\t\tapps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({\n\t\t\t\t\t\tname: g.client.name,\n\t\t\t\t\t\thost: g.client.host,\n\t\t\t\t\t})),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#heard(detail: unknown): void {\n\t\tlet m: unknown;\n\t\ttry {\n\t\t\tm = typeof detail === \"string\" ? JSON.parse(detail) : undefined;\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isObject(m) || m[\"v\"] !== 1) return;\n\t\tif (m[\"type\"] === \"vouch\") this.#vouch(m);\n\t\t// The call it was for ended or never reached the page: an unused vouch\n\t\t// must not wait its 2 s for another caller.\n\t\telse if (m[\"type\"] === \"withdraw\")\n\t\t\tthis.#vouches = this.#vouches.filter((v) => v.nonce !== m[\"nonce\"]);\n\t\telse if (m[\"type\"] === \"hello\" || m[\"type\"] === \"update\") {\n\t\t\tconst extension = extensionOf(m);\n\t\t\tif (extension === null) return;\n\t\t\tif (canonical(extension) !== canonical(this.#extension)) {\n\t\t\t\tthis.#extension = extension;\n\t\t\t\tfor (const page of this.#pages) page.set(extension);\n\t\t\t}\n\t\t\tif (m[\"type\"] === \"hello\")\n\t\t\t\tfor (const page of this.#pages) this.#say(page, \"update\");\n\t\t}\n\t}\n\n\t/**\n\t * A vouch, kept for the tool registered under its name now, by a page\n\t * that takes vouches: a tool registered anew after this does not get it.\n\t */\n\t#vouch(m: Record<string, unknown>): void {\n\t\tconst app = appOf(m[\"app\"]);\n\t\tconst name = m[\"tool\"];\n\t\tconst nonce = m[\"nonce\"];\n\t\tif (\n\t\t\tapp === undefined ||\n\t\t\ttypeof name !== \"string\" ||\n\t\t\ttypeof nonce !== \"string\" ||\n\t\t\t!isObject(m[\"arguments\"])\n\t\t)\n\t\t\treturn;\n\t\tthis.#drop();\n\t\t// The same vouch heard twice counts once.\n\t\tif (this.#vouches.some((v) => v.nonce === nonce)) return;\n\t\tfor (const page of this.#pages) {\n\t\t\tconst tool = page.trust ? page.registry.get(name) : undefined;\n\t\t\tif (tool === undefined) continue;\n\t\t\tthis.#vouches.push({\n\t\t\t\ttool,\n\t\t\t\targs: canonical(m[\"arguments\"]),\n\t\t\t\tnonce,\n\t\t\t\tapp,\n\t\t\t\tat: now(),\n\t\t\t});\n\t\t\tif (this.#vouches.length > MAX_VOUCHES) this.#vouches.shift();\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Forget the vouches older than `VOUCH_MS`. */\n\t#drop(): void {\n\t\tconst t = now();\n\t\tthis.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);\n\t}\n\n\t/**\n\t * The vouch for this call of `tool` with `input`, used up; `undefined`\n\t * if there is none (the call is asked as without the extension).\n\t */\n\ttake(tool: RegisteredTool, input: unknown): VouchedBy | undefined {\n\t\tthis.#drop();\n\t\tconst args = canonical(input);\n\t\tconst i = this.#vouches.findIndex(\n\t\t\t(v) => v.tool === tool && v.args === args,\n\t\t);\n\t\treturn i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;\n\t}\n}\n\n/**\n * The extension's state from its `hello` or `update`: `undefined` when it\n * does not serve the page now, `null` when the message is malformed.\n */\nfunction extensionOf(\n\tm: Record<string, unknown>,\n): BrowserExtension | undefined | null {\n\tif (m[\"on\"] !== true) return m[\"on\"] === false ? undefined : null;\n\tconst { name, version, apps } = m;\n\tif (!text(name) || !text(version) || !Array.isArray(apps)) return null;\n\tconst list = apps.slice(0, MAX_APPS).map(appOf);\n\tif (list.some((a) => a === undefined)) return null;\n\treturn Object.freeze({\n\t\tname,\n\t\tversion,\n\t\tapps: Object.freeze(list.map((a) => Object.freeze(a as VouchedBy))),\n\t\twhileInFront: m[\"whileInFront\"] !== false,\n\t});\n}\n\nconst handshakes = new WeakMap<Document, Handshake>();\n\n/**\n * The handshake of the page's top-level document, which `page` joins; the\n * extension speaks only to the top frame. `undefined` in a frame or\n * without a document.\n */\nexport function joinHandshake(page: HandshakePage): Handshake | undefined {\n\tconst doc = globalThis.document;\n\tif (doc === undefined || globalThis.top !== globalThis.window)\n\t\treturn undefined;\n\tlet handshake = handshakes.get(doc);\n\tif (handshake === undefined) {\n\t\thandshake = new Handshake(doc);\n\t\thandshakes.set(doc, handshake);\n\t}\n\thandshake.join(page);\n\treturn handshake;\n}\n",
|
|
6
|
-
"/**\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. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.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/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\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: every tool, unless its `callers` leave `\"webmcp\"` out (DEC-165,\n * DEC-209). A tool that asks is marked `consequentialHint`, so that the agent\n * asks its user; MCP's `destructiveHint` counts as `consequentialHint`\n * (DEC-143). The page's `onConfirm` decides such a call, never the library's\n * dialog (DEC-215). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`), `version` the library's. The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; no call is vouched for.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\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\") ?? true)) continue;\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\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\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"
|
|
6
|
+
"/**\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. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.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/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\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: every tool, unless its `callers` leave `\"webmcp\"` out (DEC-165,\n * DEC-209). A tool that asks is marked `consequentialHint`, so that the agent\n * asks its user; MCP's `destructiveHint` counts as `consequentialHint`\n * (DEC-143). The page's `onConfirm` decides such a call, never the library's\n * dialog (DEC-215). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`, and `onConfirm` for the warning below), `version` the\n * library's. A tool that asks, mirrored with an `exposedTo` that names\n * other origins on a page without `onConfirm`, is warned about once per\n * name (`warnUnasked`): documents of those origins can run it, and the\n * library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean; onConfirm?: unknown },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; no call is vouched for.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst unasked = new Set<string>();\n\t/**\n\t * The warning about a tool that asks with `exposedTo` (DEC-215), once its\n\t * native registration succeeded (so Chrome accepted every origin), once\n\t * per name. Decided then: a handler the page removes later is not\n\t * caught. Never throws, whatever `exposedTo` holds.\n\t */\n\tconst warnUnasked = (tool: RegisteredTool, asks: boolean | undefined) => {\n\t\ttry {\n\t\t\t// React's provider always passes a handler; `own` says whether the\n\t\t\t// page gave one.\n\t\t\tconst ask = options.onConfirm as { own?: boolean } | undefined;\n\t\t\tconst page = globalThis.document?.location?.origin;\n\t\t\tconst others = (\n\t\t\t\tArray.isArray(tool.exposedTo) ? tool.exposedTo : []\n\t\t\t).filter((entry: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn new URL(String(entry)).origin !== page;\n\t\t\t\t} catch {\n\t\t\t\t\treturn false; // the browser refuses it anyway\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (\n\t\t\t\tasks !== true ||\n\t\t\t\tothers.length === 0 ||\n\t\t\t\t(ask && ask.own !== false) ||\n\t\t\t\tunasked.has(tool.name)\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tunasked.add(tool.name);\n\t\t\tconsole.warn(\n\t\t\t\t`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(\", \")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// a warning never stops the mirror\n\t\t}\n\t};\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\") ?? true)) continue;\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\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\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.then(() => {\n\t\t\t\t\tif (!signal.aborted) warnUnasked(tool, consequential);\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"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";AAmCO,IAAM,aAAa;AAEnB,IAAM,kBAAkB;AAExB,IAAM,OAAO;AAEb,IAAM,WAAW;AAExB,IAAM,cAAc;AAEpB,IAAM,WAAW;AACjB,IAAM,WAAW;AA+BjB,IAAM,WAAW,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,IAAM,OAAO,CAAC,UACb,OAAO,UAAU,YAAY,MAAM,UAAU;AAG9C,SAAS,KAAK,CAAC,OAAuC;AAAA,EACr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