@ractive-ch/tab-mcp-client 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -12
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/cdn/connection-9w0rx0vf.min.js +11 -0
- package/cdn/connection-9w0rx0vf.min.js.map +21 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +4 -4
- package/cdn/{ui-cssy9seq.min.js → ui-406jbpym.min.js} +11 -8
- package/cdn/ui-406jbpym.min.js.map +11 -0
- package/connection-eqqkev02.js.map +1 -1
- package/index.js +5 -5
- package/index.js.map +4 -4
- package/package.json +2 -2
- package/react.d.ts +1 -1
- package/react.js +3 -2
- package/react.js.map +3 -3
- package/tab-mcp.d.ts +1 -1
- package/types.d.ts +7 -3
- package/{ui-zyst9kn6.js → ui-57hyd701.js} +9 -6
- package/ui-57hyd701.js.map +11 -0
- package/ui.d.ts +1 -1
- package/version.d.ts +1 -1
- package/cdn/connection-0x5mr3te.min.js +0 -11
- package/cdn/connection-0x5mr3te.min.js.map +0 -21
- package/cdn/ui-cssy9seq.min.js.map +0 -11
- package/ui-zyst9kn6.js.map +0 -11
package/react.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/react.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 DependencyList,\n\ttype MouseEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseInsertionEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport {\n\ttype ConfirmRequest,\n\ttype ConnectionState,\n\ttype Grant,\n\ttype IdentityAssertionRequest,\n\ttype IdentityState,\n\ttype PairingCode,\n\ttype ReconnectingInfo,\n\ttype SessionInfo,\n\tTabMcp,\n\ttype TabMcpEventMap,\n\ttype TabMcpOptions,\n\ttype Tool,\n\ttype ToolCallEnd,\n\ttype ToolCallStart,\n} from \"./index.ts\";\n\n/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */\nexport interface TabMcpSnapshot {\n\tstate: ConnectionState;\n\t/** The MCP address to give to AI apps, while connected. */\n\taddress: string | undefined;\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/** 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 the library connects again by itself after the connection broke. */\n\treconnecting: ReconnectingInfo | undefined;\n\t/** Names of the registered tools. */\n\ttools: readonly string[];\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\taddress: undefined,\n\tsession: undefined,\n\tgrants: EMPTY,\n\tpairingCode: undefined,\n\tidentity: \"none\",\n\tidentityMessage: undefined,\n\treconnecting: undefined,\n\ttools: EMPTY,\n});\n\nconst STATE_EVENTS = [\n\t\"statechange\",\n\t\"connected\",\n\t\"disconnected\",\n\t\"grantschange\",\n\t\"pairingcode\",\n\t\"identitychange\",\n\t\"reconnecting\",\n\t\"toolschange\",\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\taddress: mcp.address,\n\t\t\tsession: mcp.session,\n\t\t\tgrants: mcp.grants,\n\t\t\tpairingCode: mcp.pairingCode,\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};\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. 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\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\treturn () => mcp.disconnect();\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 and\n * reconnecting 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/**\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 schema or annotations change, or\n * one of `deps`. A duplicate name or an invalid tool is thrown from the\n * component's next render, for an error boundary.\n */\nexport function useTool(tool: Tool, deps: DependencyList = EMPTY): 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.annotations,\n\t]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: `shape` and `deps` stand for the tool; `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, options) => latest.current.execute(input, options),\n\t\t\t\t},\n\t\t\t\t{ 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, ...deps]);\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/** The default label of `ConnectButton`. */\nexport function connectLabel(state: TabMcpSnapshot): string {\n\tif (state.state === \"connected\" && state.grants.length > 0)\n\t\treturn state.grants.length === 1\n\t\t\t? \"AI app connected\"\n\t\t\t: `${state.grants.length} AI apps connected`;\n\tif (state.reconnecting !== undefined) return \"Reconnecting…\";\n\tif (state.state === \"connecting\") return \"Connecting…\";\n\treturn \"Connect your AI app\";\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 */\nexport function ConnectButton({\n\tchildren,\n\tonClick,\n\t...rest\n}: ConnectButtonProps): ReactElement {\n\tconst mcp = useTabMcp();\n\tconst state = useTabMcpState();\n\tconst label =\n\t\tchildren === undefined\n\t\t\t? connectLabel(state)\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\":\n\t\t\t\tstate.reconnecting !== undefined && state.state !== \"connected\"\n\t\t\t\t\t? \"reconnecting\"\n\t\t\t\t\t: 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 DependencyList,\n\ttype MouseEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseInsertionEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport {\n\ttype ConfirmRequest,\n\ttype ConnectionState,\n\ttype Grant,\n\ttype IdentityAssertionRequest,\n\ttype IdentityState,\n\ttype PairingCode,\n\ttype ReconnectingInfo,\n\ttype SessionInfo,\n\tTabMcp,\n\ttype TabMcpEventMap,\n\ttype TabMcpOptions,\n\ttype Tool,\n\ttype ToolCallEnd,\n\ttype ToolCallStart,\n} from \"./index.ts\";\n\n/** What `useTabMcpState()` returns: one object per change, the same object otherwise. */\nexport interface TabMcpSnapshot {\n\tstate: ConnectionState;\n\t/** The MCP address to give to AI apps, while connected. */\n\taddress: string | undefined;\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/** 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 the library connects again by itself after the connection broke. */\n\treconnecting: ReconnectingInfo | undefined;\n\t/** Names of the registered tools. */\n\ttools: readonly string[];\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\taddress: undefined,\n\tsession: undefined,\n\tgrants: EMPTY,\n\tpairingCode: undefined,\n\tidentity: \"none\",\n\tidentityMessage: undefined,\n\treconnecting: undefined,\n\ttools: EMPTY,\n});\n\nconst STATE_EVENTS = [\n\t\"statechange\",\n\t\"connected\",\n\t\"disconnected\",\n\t\"grantschange\",\n\t\"pairingcode\",\n\t\"identitychange\",\n\t\"reconnecting\",\n\t\"toolschange\",\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\taddress: mcp.address,\n\t\t\tsession: mcp.session,\n\t\t\tgrants: mcp.grants,\n\t\t\tpairingCode: mcp.pairingCode,\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};\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. 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\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\treturn () => mcp.disconnect();\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 and\n * reconnecting 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/**\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 schema or annotations change, or\n * one of `deps`. A duplicate name or an invalid tool is thrown from the\n * component's next render, for an error boundary.\n */\nexport function useTool<Input extends object = Record<string, unknown>>(\n\ttool: Tool<Input>,\n\tdeps: DependencyList = EMPTY,\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.annotations,\n\t]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: `shape` and `deps` stand for the tool; `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{ 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, ...deps]);\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/** The default label of `ConnectButton`. */\nexport function connectLabel(state: TabMcpSnapshot): string {\n\tif (state.state === \"connected\" && state.grants.length > 0)\n\t\treturn state.grants.length === 1\n\t\t\t? \"AI app connected\"\n\t\t\t: `${state.grants.length} AI apps connected`;\n\tif (state.reconnecting !== undefined)\n\t\treturn state.reconnecting.attempt > LOST_AFTER_ATTEMPTS\n\t\t\t? \"Connection lost, retrying…\"\n\t\t\t: \"Reconnecting…\";\n\tif (state.state === \"connecting\") return \"Connecting…\";\n\treturn \"Connect your AI app\";\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 */\nexport function ConnectButton({\n\tchildren,\n\tonClick,\n\t...rest\n}: ConnectButtonProps): ReactElement {\n\tconst mcp = useTabMcp();\n\tconst state = useTabMcpState();\n\tconst label =\n\t\tchildren === undefined\n\t\t\t? connectLabel(state)\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\":\n\t\t\t\tstate.reconnecting !== undefined && state.state !== \"connected\"\n\t\t\t\t\t? \"reconnecting\"\n\t\t\t\t\t: 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\tlab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UAAU,sBACjC,+BACA;AAAA,EACJ,IAAI,MAAM,UAAU;AAAA,IAAc,OAAO;AAAA,EACzC,OAAO;AAAA;AASD,SAAS,aAAa;AAAA,EAC5B;AAAA,EACA;AAAA,KACG;AAAA,GACiC;AAAA,EACpC,MAAM,MAAM,UAAU;AAAA,EACtB,MAAM,QAAQ,eAAe;AAAA,EAC7B,MAAM,QACL,aAAa,YACV,aAAa,KAAK,IAClB,OAAO,aAAa,aACnB,SAAS,KAAK,IACd;AAAA,EACL,OAAO,cACN,UACA;AAAA,IACC,MAAM;AAAA,IACN,cACC,MAAM,iBAAiB,aAAa,MAAM,UAAU,cACjD,iBACA,MAAM;AAAA,OACP;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;",
|
|
8
|
+
"debugId": "323C4F6539CF68C364756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/tab-mcp.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class TabMcp extends EventTarget {
|
|
|
27
27
|
* aborting `options.signal` unregisters it. Rejects with a `TypeError` for
|
|
28
28
|
* an invalid tool and an `InvalidStateError` for a duplicate name.
|
|
29
29
|
*/
|
|
30
|
-
registerTool(tool: Tool
|
|
30
|
+
registerTool<Input extends object = Record<string, unknown>>(tool: Tool<Input>, options?: RegisterToolOptions): Promise<void>;
|
|
31
31
|
/** Names of the registered tools. */
|
|
32
32
|
get tools(): readonly string[];
|
|
33
33
|
get state(): ConnectionState;
|
package/types.d.ts
CHANGED
|
@@ -44,8 +44,12 @@ export interface ToolExecuteOptions {
|
|
|
44
44
|
/** Who is calling. */
|
|
45
45
|
client: ToolCallClient;
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* A tool in the WebMCP shape (`document.modelContext.registerTool`). `Input`
|
|
49
|
+
* types `execute`'s first argument; the library checks the arguments against
|
|
50
|
+
* `inputSchema` before it calls `execute`, so keep the two in step.
|
|
51
|
+
*/
|
|
52
|
+
export interface Tool<Input extends object = Record<string, unknown>> {
|
|
49
53
|
/** 1–128 characters of `A–Z a–z 0–9 _ - .`. */
|
|
50
54
|
name: string;
|
|
51
55
|
title?: string;
|
|
@@ -54,7 +58,7 @@ export interface Tool {
|
|
|
54
58
|
/** JSON Schema of the input object; defaults to `{ "type": "object" }`. */
|
|
55
59
|
inputSchema?: JsonSchema;
|
|
56
60
|
/** Runs the tool. Its return value becomes the result (DEC-023). */
|
|
57
|
-
execute: (input:
|
|
61
|
+
execute: (input: Input, options: ToolExecuteOptions) => unknown;
|
|
58
62
|
annotations?: ToolAnnotations;
|
|
59
63
|
}
|
|
60
64
|
/** Options of `registerTool`. */
|
|
@@ -58,7 +58,7 @@ var DIALOG_CSS = `.tab-mcp-dialog {
|
|
|
58
58
|
--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));
|
|
59
59
|
--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
60
60
|
--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);
|
|
61
|
-
box-sizing: border-box; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
|
|
61
|
+
box-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
|
|
62
62
|
font: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);
|
|
63
63
|
border: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);
|
|
64
64
|
padding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));
|
|
@@ -94,9 +94,12 @@ html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-
|
|
|
94
94
|
.tab-mcp-code :where(br) { display: none; }
|
|
95
95
|
.tab-mcp-code :where(small) { grid-column: 1 / -1; }
|
|
96
96
|
.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
|
|
97
|
-
.tab-mcp-help
|
|
97
|
+
.tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
98
|
+
.tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }
|
|
99
|
+
.tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }
|
|
100
|
+
.tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }
|
|
98
101
|
.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
|
|
99
|
-
.tab-mcp-help :where(ul) { margin-top: 0.75rem; gap: 0.75rem; }
|
|
102
|
+
.tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }
|
|
100
103
|
.tab-mcp-help :where(li) { overflow-wrap: anywhere; }
|
|
101
104
|
.tab-mcp-help :where(strong) { display: block; font-weight: 600; }
|
|
102
105
|
.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }
|
|
@@ -314,7 +317,7 @@ function commandAddress(address) {
|
|
|
314
317
|
return;
|
|
315
318
|
}
|
|
316
319
|
}
|
|
317
|
-
var GUIDE = "https://
|
|
320
|
+
var GUIDE = "https://ractive.ch/tab-mcp/connect/";
|
|
318
321
|
var CODEX_FEATURE = "mcp_2026_07_28";
|
|
319
322
|
function instructions(name, address) {
|
|
320
323
|
const n = commandName(name);
|
|
@@ -663,5 +666,5 @@ export {
|
|
|
663
666
|
showConnectDialog
|
|
664
667
|
};
|
|
665
668
|
|
|
666
|
-
//# debugId=
|
|
667
|
-
//# sourceMappingURL=ui-
|
|
669
|
+
//# debugId=BF9126D2E275582F64756E2164756E21
|
|
670
|
+
//# sourceMappingURL=ui-57hyd701.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/always-allowed.ts", "../src/ui.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The tools a user chose \"Always allow\" for, per grant (AI app). Kept in\n * memory for the page's lifetime; an entry goes when its grant goes or its\n * tool is unregistered, so a re-paired app or a new tool under the same name\n * is asked again.\n */\nexport class AlwaysAllowed {\n\treadonly #tools = new Map<string, Set<string>>();\n\n\thas(grantId: string, tool: string): boolean {\n\t\treturn this.#tools.get(grantId)?.has(tool) === true;\n\t}\n\n\tadd(grantId: string, tool: string): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Set();\n\t\ttools.add(tool);\n\t\tthis.#tools.set(grantId, tools);\n\t}\n\n\t/** Forget every grant not in `grantIds`. */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tfor (const grantId of this.#tools.keys()) {\n\t\t\tif (!keep.has(grantId)) this.#tools.delete(grantId);\n\t\t}\n\t}\n\n\t/** Forget every tool not in `names`. */\n\tkeepTools(names: Iterable<string>): void {\n\t\tconst keep = new Set(names);\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools) if (!keep.has(tool)) tools.delete(tool);\n\t\t}\n\t}\n}\n",
|
|
6
|
+
"/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, all text set with `textContent`, styled by one constructed\n * stylesheet (`DIALOG_CSS`) that pages adjust through `--tab-mcp-*` custom\n * properties or their own CSS. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\n/**\n * A button. `className` is its own class; `kind` marks the one next step\n * (`tab-mcp-primary`) or one that disconnects (`tab-mcp-danger`); without\n * one it is a plain, outlined button.\n */\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n\tclassName?: string,\n\tkind?: \"primary\" | \"danger\",\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tif (className !== undefined) node.classList.add(className);\n\tif (kind !== undefined) node.classList.add(`tab-mcp-${kind}`);\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/**\n * The look of both dialogs. Every selector has the specificity of one class\n * (the rest is in `:where()`), so rules of the page for elements, such as\n * `button { … }` or a reset's `* { border-width: 0 }`, do not change the\n * dialogs. The rules for states (hover, focus, disabled) and the primary\n * and danger buttons add two elements (`html dialog.…`, `html button.…`),\n * so `button:hover`, `button:focus` or `button:disabled` of the page do not\n * either. A rule with two classes, such as `.tab-mcp-dialog .tab-mcp-primary`,\n * wins over all of them. The `--tab-mcp-*`\n * custom properties (on `:root` or on `.tab-mcp-dialog`) change single\n * values; the library only reads them. The defaults use system colours and the\n * page's `color-scheme`, so the dialogs follow its light or dark scheme. The\n * `--_tab-mcp-*` properties are internal. Order matters among equals.\n */\nexport const DIALOG_CSS = `.tab-mcp-dialog {\n--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);\n--_tab-mcp-bg: var(--tab-mcp-background, Canvas);\n--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));\n--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);\n--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));\n--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));\n--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);\nbox-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;\nfont: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);\nborder: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);\npadding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));\n}\n.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }\n.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }\n.tab-mcp-dialog :where([hidden]) { display: none !important; }\nhtml dialog.tab-mcp-dialog:where(:focus) { outline: none; }\n.tab-mcp-dialog :where(*) { box-sizing: border-box; }\n.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }\n.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }\n.tab-mcp-dialog :where(small) { font-size: 0.875em; }\n.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note) { color: var(--_tab-mcp-muted); }\nhtml dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }\n.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }\nhtml dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }\nhtml dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }\nhtml button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }\nhtml button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }\nhtml button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }\n.tab-mcp-copy { min-width: 6em; }\n.tab-mcp-close { font-size: 0.875em; }\n.tab-mcp-status { margin-top: -0.5rem; }\n.tab-mcp-description:where(:empty) { display: none; }\n.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }\n.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }\n.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }\n.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code > :where(span) { font-weight: 600; }\n.tab-mcp-code :where(br) { display: none; }\n.tab-mcp-code :where(small) { grid-column: 1 / -1; }\n.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }\n.tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }\n.tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }\n.tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }\n.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }\n.tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }\n.tab-mcp-help :where(li) { overflow-wrap: anywhere; }\n.tab-mcp-help :where(strong) { display: block; font-weight: 600; }\n.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }\n.tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-command-note { display: block; margin-top: 0.375rem; }\n.tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }\n.tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }\n.tab-mcp-apps-note { margin-top: 0.5rem; }\n.tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }\n.tab-mcp-close-note { flex: 1 1 12rem; }\n.tab-mcp-confirm :where(p bdi) { font-weight: 600; }\n.tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-always-note { font-size: 0.875em; }\n@media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }\n@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } }\n@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }\n@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }\n`;\n\nconst sheets = new WeakMap<Document, CSSStyleSheet>();\n\n/**\n * Adopts `DIALOG_CSS` into the document once, next to the page's own adopted\n * sheets. A constructed stylesheet needs no `style-src` exception under a\n * strict CSP. Where constructed stylesheets are not supported, the dialogs\n * keep the browser's default look and work the same.\n */\nfunction adoptStyles(doc: Document): void {\n\ttry {\n\t\tlet sheet = sheets.get(doc);\n\t\tif (sheet === undefined) {\n\t\t\tconst Sheet = (doc.defaultView as (Window & typeof globalThis) | null)\n\t\t\t\t?.CSSStyleSheet;\n\t\t\tif (Sheet === undefined || !Array.isArray(doc.adoptedStyleSheets)) return;\n\t\t\tsheet = new Sheet();\n\t\t\tsheet.replaceSync(DIALOG_CSS);\n\t\t\tsheets.set(doc, sheet);\n\t\t}\n\t\t// The page may have replaced the list since.\n\t\tif (!doc.adoptedStyleSheets.includes(sheet))\n\t\t\tdoc.adoptedStyleSheets = [...doc.adoptedStyleSheets, sheet];\n\t} catch {\n\t\t// Not supported: the default look.\n\t}\n}\n\n/**\n * A Copy button for `value()`, read at click time. Shows \"Copied\" once the\n * clipboard took it; without a clipboard (or when it refuses) `select()` puts\n * the text in the selection for Ctrl+C instead. `noun` names it for assistive\n * technology (\"Copy code\"), as the dialog has more than one Copy; `announce`\n * says what happened (\"Code copied\", or that the text is selected).\n */\nfunction copyButton(\n\tdoc: Document,\n\tnoun: string,\n\tvalue: () => string,\n\tselect: () => void,\n\tannounce: (text: string) => void,\n\tclassName: string,\n\tkind?: \"primary\",\n): { button: HTMLButtonElement; reset: () => void } {\n\tconst node = button(\n\t\tdoc,\n\t\t\"Copy\",\n\t\t() => {\n\t\t\tconst done = () => {\n\t\t\t\tnode.textContent = \"Copied\";\n\t\t\t\tnode.setAttribute(\"aria-label\", `Copied ${noun}`);\n\t\t\t\tannounce(`${noun[0]?.toUpperCase()}${noun.slice(1)} copied`);\n\t\t\t};\n\t\t\tconst selected = () => {\n\t\t\t\tselect();\n\t\t\t\tannounce(\"Selected: copy it with Ctrl+C or ⌘C\");\n\t\t\t};\n\t\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t\t?.clipboard;\n\t\t\tif (clipboard !== undefined)\n\t\t\t\tclipboard.writeText(value()).then(done, selected);\n\t\t\telse selected();\n\t\t},\n\t\tclassName,\n\t\tkind,\n\t);\n\t// The same width for \"Copy\" and \"Copied\": nothing moves.\n\tnode.classList.add(\"tab-mcp-copy\");\n\tconst reset = () => {\n\t\tnode.textContent = \"Copy\";\n\t\tnode.setAttribute(\"aria-label\", `Copy ${noun}`);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\tadoptStyles(doc);\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\n/**\n * Characters that are invisible or change the direction of the text around\n * them: format characters (bidi controls and isolates, zero-width ones, tags),\n * the other default-ignorable ones (fillers, variation selectors), private-use\n * and unassigned code points, C1 controls, and line and paragraph separators.\n */\nconst INVISIBLE =\n\t/[\\p{Cf}\\p{Default_Ignorable_Code_Point}\\p{Co}\\p{Cn}\\u0080-\\u009F\\u2028\\u2029]/gu;\n\n/** Each such character as `\\uXXXX` (a pair for one beyond U+FFFF), as JSON would write it. */\nfunction visible(text: string): string {\n\treturn text.replace(INVISIBLE, (ch) => {\n\t\tlet escaped = \"\";\n\t\tfor (let i = 0; i < ch.length; i++)\n\t\t\tescaped += `\\\\u${ch.charCodeAt(i).toString(16).toUpperCase().padStart(4, \"0\")}`;\n\t\treturn escaped;\n\t});\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = visible(client.host || client.id);\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${visible(client.name)} (${host})`\n\t\t: host;\n}\n\n/** A name in a sentence, isolated so that it cannot reorder the words around it. */\nfunction name(doc: Document, text: string): HTMLElement {\n\tconst node = el(doc, \"bdi\", { text });\n\tnode.dir = \"ltr\";\n\treturn node;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) Invisible and\n * direction characters are shown as escapes, so the text is still JSON for\n * the same arguments; the tool gets them unchanged. `undefined` when they\n * cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn visible(JSON.stringify(args, null, 2));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/** `allowDelayMs` as a usable delay: the default unless a number of ms, never below the floor. */\nfunction allowDelay(ms: number | undefined): number {\n\tconst value =\n\t\ttypeof ms === \"number\" && Number.isFinite(ms) && ms < 2 ** 31\n\t\t\t? ms\n\t\t\t: ALLOW_DELAY_MS;\n\treturn Math.max(MIN_ALLOW_DELAY_MS, value);\n}\n\n/**\n * Ask whether a consequential tool may run. \"Always allow\" is offered only\n * with `alwaysAllow` (DEC-096). \"Allow\" and \"Always allow\" stay disabled\n * until the page has been visible and focused for `allowDelayMs` (default\n * 750, at least 500) while the dialog is open, so a click meant for the page,\n * or the click that brings the tab or window back, cannot approve. Leaving\n * the page disables them again. Everything else (Don't allow, Escape, an\n * aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number | undefined; alwaysAllow?: boolean } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = allowDelay(options.allowDelayMs);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog, heading } = newDialog(doc, \"tab-mcp-confirm\", \"\");\n\theading.append(\"Allow \", name(doc, title), \"?\");\n\tconst client = clientLabel(request.client);\n\t// The safe choice is the default: focused, and the one that stands out.\n\tconst deny = button(\n\t\tdoc,\n\t\t\"Don't allow\",\n\t\t() => dialog.close(\"deny\"),\n\t\t\"tab-mcp-deny\",\n\t\t\"primary\",\n\t);\n\tconst allow = button(\n\t\tdoc,\n\t\t\"Allow\",\n\t\t() => {\n\t\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t\t},\n\t\t\"tab-mcp-allow\",\n\t);\n\t// The approving buttons: Allow, and Always allow when the page offers it.\n\tconst approve = [allow];\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t);\n\tconst extra: HTMLElement[] = [];\n\tif (options.alwaysAllow === true) {\n\t\tconst always = button(\n\t\t\tdoc,\n\t\t\t\"Always allow\",\n\t\t\t() => {\n\t\t\t\tif (!always.disabled) dialog.close(\"always\");\n\t\t\t},\n\t\t\t\"tab-mcp-always\",\n\t\t);\n\t\tapprove.push(always);\n\t\tactions.append(\" \", always);\n\t\textra.push(\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"p\",\n\t\t\t\t{ className: \"tab-mcp-always-note\" },\n\t\t\t\t\"Always allow: \",\n\t\t\t\tname(doc, title),\n\t\t\t\t\" runs without asking for \",\n\t\t\t\tname(doc, client),\n\t\t\t\t\" until you reload this page or disconnect it.\",\n\t\t\t),\n\t\t);\n\t}\n\tconst enable = (on: boolean) => {\n\t\tfor (const b of approve) b.disabled = !on;\n\t};\n\tenable(false);\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tfor (const node of [...approve, ...extra]) node.hidden = true;\n\t}\n\targs.dir = \"ltr\";\n\t// Inline, so the arguments stay readable in full without the stylesheet:\n\t// wrapped (also a long word, at 360 px), scrolling when long.\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"overflow-wrap\", \"anywhere\");\n\targs.style.setProperty(\n\t\t\"max-height\",\n\t\t\"var(--tab-mcp-arguments-height, 12rem)\",\n\t);\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"p\",\n\t\t\t{},\n\t\t\tname(doc, client),\n\t\t\t\" wants to run \",\n\t\t\tname(doc, title),\n\t\t\t\".\",\n\t\t),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\t...extra,\n\t);\n\tdoc.body.append(dialog);\n\tconst view = doc.defaultView;\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t// The delay counts only while the user can see the page: tools are\n\t\t// called while the user is in the AI app, so the dialog often opens in\n\t\t// a background tab or window. Any change starts it again from zero (DEC-087).\n\t\tconst arm = (event?: Event) => {\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t\tenable(false);\n\t\t\tif (\n\t\t\t\tevent?.type === \"blur\" ||\n\t\t\t\tdoc.visibilityState === \"hidden\" ||\n\t\t\t\t!doc.hasFocus()\n\t\t\t)\n\t\t\t\treturn;\n\t\t\ttimer = setTimeout(() => enable(true), delay);\n\t\t};\n\t\tdoc.addEventListener(\"visibilitychange\", arm);\n\t\tview?.addEventListener(\"focus\", arm);\n\t\tview?.addEventListener(\"blur\", arm);\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tdoc.removeEventListener(\"visibilitychange\", arm);\n\t\t\t\tview?.removeEventListener(\"focus\", arm);\n\t\t\t\tview?.removeEventListener(\"blur\", arm);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\tarm();\n\t});\n}\n\n/** The tools a user chose \"Always allow\" for, per `TabMcp`. */\nconst allowedAlways = new WeakMap<TabMcp, AlwaysAllowed>();\n\n/**\n * `TabMcp.confirmInPage`: the confirmation, and the tools allowed always. An\n * entry goes when its grant goes or its tool is unregistered, so a re-paired\n * app or a new tool under the same name is asked again.\n */\nexport function confirmInPage(\n\tmcp: TabMcp,\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number | undefined; alwaysAllow?: boolean },\n): Promise<boolean> {\n\tconst { grantId } = request.client;\n\tconst tool = request.tool.name;\n\tif (allowedAlways.get(mcp)?.has(grantId, tool)) return Promise.resolve(true);\n\treturn confirmDialog(request, doc, options).then((answer) => {\n\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\tif (answer === \"always\" && mcp.grants.some((g) => g.grantId === grantId)) {\n\t\t\tlet allowed = allowedAlways.get(mcp);\n\t\t\tif (allowed === undefined) {\n\t\t\t\tconst kept = new AlwaysAllowed();\n\t\t\t\tmcp.addEventListener(\"grantschange\", (e) =>\n\t\t\t\t\tkept.keepGrants(e.detail.grants.map((g) => g.grantId)),\n\t\t\t\t);\n\t\t\t\tmcp.addEventListener(\"toolschange\", (e) =>\n\t\t\t\t\tkept.keepTools(e.detail.tools),\n\t\t\t\t);\n\t\t\t\tallowedAlways.set(mcp, kept);\n\t\t\t\tallowed = kept;\n\t\t\t}\n\t\t\tallowed.add(grantId, tool);\n\t\t}\n\t\treturn answer !== \"deny\";\n\t});\n}\n\n/**\n * The server's name as a label that every shell (POSIX shells, PowerShell,\n * cmd.exe) reads as one plain word, so it needs no quoting: letters without\n * their marks (\"Bücher\" → \"bucher\"), lower case, each run of anything but\n * a-z, 0-9, _ and - as one \"-\", no \"-\" at either end (no option), at most 40\n * characters; \"tools\" when nothing is left. The page names its server, but\n * the command runs in the user's shell: nothing of the name may be quoted\n * text (review of PR 34).\n */\nexport function commandName(name: string): string {\n\tconst label = 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(/-{2,}/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 40)\n\t\t.replace(/-+$/, \"\");\n\treturn label === \"\" ? \"tools\" : label;\n}\n\n/**\n * The address for a command, only when all of it is plain in every shell\n * (http or https, letters, digits and . : [ ] / _ ~ -); else `undefined`, and\n * the help shows the steps without commands. The relay's addresses are.\n */\nexport function commandAddress(address: string): string | undefined {\n\ttry {\n\t\tconst href = new URL(address).href;\n\t\treturn /^https?:\\/\\/[A-Za-z0-9.:[\\]/_~-]+$/.test(href) ? href : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The guide for every AI app (its source is on ractive.ch). */\nconst GUIDE = \"https://ractive.ch/tab-mcp/connect/\";\n\n/** Codex's feature for MCP 2026-07-28, which the relay speaks; off by default in Codex 0.163. */\nconst CODEX_FEATURE = \"mcp_2026_07_28\";\n\n/**\n * Per AI app: its name, what to do, a command to run (one per line), and a\n * note after it, alternating text and code. `name` is the page's server name.\n */\nexport function instructions(\n\tname: string,\n\taddress: string,\n): [string, string, (string | undefined)?, string[]?][] {\n\tconst n = commandName(name);\n\tconst a = commandAddress(address);\n\treturn [\n\t\t[\n\t\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t\t],\n\t\t[\n\t\t\t\"ChatGPT\",\n\t\t\t\"On chatgpt.com: Plugins, add an MCP server with the address. In the Mac app: Settings → Plugins → MCPs → Add, type Streamable HTTP; it needs the Codex feature below.\",\n\t\t],\n\t\ta === undefined\n\t\t\t? [\"Claude Code\", \"Add the address with claude mcp add --transport http.\"]\n\t\t\t: [\"Claude Code\", \"Run:\", `claude mcp add --transport http ${n} ${a}`],\n\t\t[\n\t\t\t\"Codex\",\n\t\t\t...((a === undefined\n\t\t\t\t? [\n\t\t\t\t\t\t`Run codex features enable ${CODEX_FEATURE}, then add the address with codex mcp add --url.`,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t]\n\t\t\t\t: [\n\t\t\t\t\t\t\"Run:\",\n\t\t\t\t\t\t`codex features enable ${CODEX_FEATURE}\\ncodex mcp add ${n} --url ${a}`,\n\t\t\t\t\t]) as [string, string | undefined]),\n\t\t\t[\n\t\t\t\t\"Start a new chat in Codex after it connects. The first line turns on a feature for all of Codex's MCP servers; \",\n\t\t\t\t`codex features disable ${CODEX_FEATURE}`,\n\t\t\t\t\" turns it off.\",\n\t\t\t],\n\t\t],\n\t];\n}\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/** The document of the connect dialog per `TabMcp`, once it was opened. */\nconst watched = new WeakMap<TabMcp, Document>();\n\n/**\n * Once a page has opened the connect dialog, the default UI also says when\n * the page loses its address (`replaced`), in that dialog's document.\n */\nfunction watchReplaced(mcp: TabMcp, doc: Document): void {\n\tconst known = watched.has(mcp);\n\twatched.set(mcp, doc);\n\tif (known) return;\n\tmcp.addEventListener(\"replaced\", (event) => {\n\t\tconst current = watched.get(mcp);\n\t\t// Not when the page already went on (a New address or connect since).\n\t\tif (current !== undefined && mcp.state === \"disconnected\")\n\t\t\treplacedNotice(mcp, current, event.detail.sibling);\n\t});\n}\n\n/**\n * Says that the page lost its address (`replaced`, DEC-095). A sibling tab\n * that announced it: \"Opened in another tab\", nothing to do. Otherwise a\n * warning that another tab or program took over, with \"New address\", which\n * takes the address back, disconnects its apps, connects with a new one and\n * opens the connect dialog to add it to the AI apps again.\n */\nexport function replacedNotice(\n\tmcp: TabMcp,\n\tdoc: Document,\n\tsibling: boolean,\n): void {\n\t(\n\t\tdoc.querySelector(\"dialog.tab-mcp-replaced\") as HTMLDialogElement | null\n\t)?.close();\n\tconst { dialog } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-replaced\",\n\t\tsibling\n\t\t\t? \"Opened in another tab\"\n\t\t\t: \"Another tab or program took over this page\",\n\t);\n\tconst status = el(doc, \"p\", { className: \"tab-mcp-status\" });\n\tstatus.setAttribute(\"role\", \"status\");\n\tstatus.hidden = true;\n\tconst close = button(\n\t\tdoc,\n\t\t\"Close\",\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-replaced-close\",\n\t\tsibling ? \"primary\" : undefined,\n\t);\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\tlet first = close;\n\tif (!sibling) {\n\t\tconst fresh = button(\n\t\t\tdoc,\n\t\t\t\"New address\",\n\t\t\t() => {\n\t\t\t\tfresh.disabled = true;\n\t\t\t\tstatus.hidden = false;\n\t\t\t\tstatus.textContent = \"Getting a new address…\";\n\t\t\t\tmcp.newAddress().then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdialog.close();\n\t\t\t\t\t\tmcp.showConnectDialog({ document: doc }).catch(() => {});\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tfresh.disabled = false;\n\t\t\t\t\t\tstatus.textContent =\n\t\t\t\t\t\t\t(error as { reason?: unknown } | null)?.reason === \"replaced\"\n\t\t\t\t\t\t\t\t? \"It was taken over again before its AI apps were disconnected. Try again.\"\n\t\t\t\t\t\t\t\t: `Could not connect: ${error instanceof Error ? error.message : String(error)}. Try again, or close this.`;\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"tab-mcp-new-address\",\n\t\t\t\"primary\",\n\t\t);\n\t\tactions.append(\" \", fresh);\n\t\tfirst = fresh;\n\t}\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: sibling\n\t\t\t\t? \"This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.\"\n\t\t\t\t: \"Your AI apps now reach that tab or program instead of this page. If you did not open this page in another tab or browser, someone may have copied its address. A new address disconnects every AI app from the old one; then add the new address to your AI apps again.\",\n\t\t}),\n\t\tstatus,\n\t\tactions,\n\t);\n\tdialog.addEventListener(\"close\", () => dialog.remove(), { once: true });\n\tdoc.body.append(dialog);\n\tdialog.showModal();\n\tfirst.focus();\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code (with Copy) while the relay sends one,\n * and the connected apps with Disconnect. Pairing is on while it is open, so\n * closing it ends the code; the connection and the address stay. Until an app\n * connects, only a small Close (and Escape) close it; then a Done. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them). When the page loses its address (`replaced`), this dialog closes and\n * `replacedNotice` says why, from then on also while it is closed.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n\tserverName = \"tools\",\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\t// Focusable from script only, for the moment before the address is shown.\n\tdialog.tabIndex = -1;\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\t// What a Copy did, for assistive technology only; out of sight, also\n\t// without the stylesheet. The same message twice is still a change.\n\tconst live = el(doc, \"span\", { className: \"tab-mcp-announce\" });\n\tlive.setAttribute(\"aria-live\", \"polite\");\n\tfor (const [property, value] of [\n\t\t[\"position\", \"absolute\"],\n\t\t[\"width\", \"1px\"],\n\t\t[\"height\", \"1px\"],\n\t\t[\"overflow\", \"hidden\"],\n\t\t[\"clip-path\", \"inset(50%)\"],\n\t\t[\"white-space\", \"nowrap\"],\n\t])\n\t\tlive.style.setProperty(property as string, value as string);\n\tconst announce = (text: string) => {\n\t\tlive.textContent = live.textContent === text ? `${text}\\u00a0` : text;\n\t};\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\t// Copying the address is the first step: the primary button.\n\tconst { button: copy, reset: resetCopy } = copyButton(\n\t\tdoc,\n\t\t\"address\",\n\t\t() => address.value,\n\t\t() => address.select(),\n\t\tannounce,\n\t\t\"tab-mcp-address-copy\",\n\t\t\"primary\",\n\t);\n\tconst fresh = button(\n\t\tdoc,\n\t\t\"New address\",\n\t\t() => askNewAddress(),\n\t\t\"tab-mcp-new-address\",\n\t);\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(\n\t\tdoc,\n\t\t\"Disconnect and get new address\",\n\t\t() => getNewAddress(),\n\t\t\"tab-mcp-new-address-confirm\",\n\t\t\"danger\",\n\t);\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\t// Large, in a monospace font: a new code takes the same room.\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\t// One click selects the whole code; it stays plain, selectable text.\n\tcode.style.setProperty(\"user-select\", \"all\");\n\tcode.style.setProperty(\"-webkit-user-select\", \"all\");\n\t// Reads the code shown at click time, so a rotated code is copied as shown.\n\tconst { button: copyCode, reset: resetCopyCode } = copyButton(\n\t\tdoc,\n\t\t\"code\",\n\t\t() => code.textContent ?? \"\",\n\t\t() => doc.getSelection()?.selectAllChildren(code),\n\t\tannounce,\n\t\t\"tab-mcp-code-copy\",\n\t);\n\t// Only the sentence with the code is announced when the code changes,\n\t// not its Copy button's \"Copied\".\n\tconst codeSentence = el(doc, \"span\", {}, \"When asked, enter the code \", code);\n\tcodeSentence.setAttribute(\"aria-live\", \"polite\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\t\" \",\n\t\tcopyCode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\t// Identity binding: no code, the same account at the AI app's sign-in.\n\tconst signInLine = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-sign-in\",\n\t\ttext: \"When your AI app asks, sign in with the account you use on this page. No code is needed.\",\n\t});\n\n\tconst steps = el(doc, \"ul\");\n\tconst guide = el(doc, \"a\", {\n\t\ttext: \"Step by step, and what to do when it fails\",\n\t});\n\tguide.href = GUIDE;\n\tguide.target = \"_blank\";\n\tguide.rel = \"noopener noreferrer\";\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: \"How do I add it?\" }),\n\t\tsteps,\n\t\tel(doc, \"p\", { className: \"tab-mcp-guide\" }, guide),\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\t// Until an app connects in this dialog, closing it is not the next step:\n\t// a small Close at the end, saying what closing does (the code stops, the\n\t// address stays). Once one connects, a prominent Done replaces both.\n\tconst closeNote = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-close-note\",\n\t\ttext: \"Closing this stops the code. The address stays the same: to connect later, open this again from the page.\",\n\t});\n\tconst close = button(doc, \"Close\", () => dialog.close(), \"tab-mcp-close\");\n\tconst done = button(\n\t\tdoc,\n\t\t\"Done\",\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-done\",\n\t\t\"primary\",\n\t);\n\tdone.hidden = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tcloseNote,\n\t\t\" \",\n\t\tclose,\n\t\tdone,\n\t);\n\t// The note on the left, the button at the far right, apart from the code.\n\t// An app connected while this dialog is open (since the last new address),\n\t// and still connected: the grants that made it so.\n\tlet paired = false;\n\tconst pairedGrants = new Set<string>();\n\t// The note is about the code: only while one is shown and nothing paired.\n\tconst renderCloseNote = () => {\n\t\tcloseNote.hidden = paired || codeLine.hidden;\n\t};\n\tconst setPaired = (value: boolean) => {\n\t\tpaired = value;\n\t\tif (!paired) pairedGrants.clear();\n\t\tconst focused = doc.activeElement;\n\t\trenderCloseNote();\n\t\tclose.hidden = paired;\n\t\tdone.hidden = !paired;\n\t\t// Focus never stays on a control that was just hidden.\n\t\tif (paired && focused === close) done.focus();\n\t\tif (!paired && focused === done) close.focus();\n\t};\n\t// The visible button that closes the dialog.\n\tconst closer = () => (paired ? done : close);\n\n\tdialog.append(\n\t\tstatus,\n\t\taddressBox,\n\t\tconfirmBox,\n\t\tcodeLine,\n\t\tsignInLine,\n\t\thelp,\n\t\tapps,\n\t\tactions,\n\t\tlive,\n\t);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\tsignInLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// The apps are disconnected: the next one has to pair again.\n\t\tsetPaired(false);\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tcopy.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tresetCopy();\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\t// Opened before the session was known: start at the address's Copy.\n\t\tif (doc.activeElement === dialog) copy.focus();\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...instructions(serverName, session.address).map(\n\t\t\t\t([app, how, command, note]) => {\n\t\t\t\t\tconst item = el(\n\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\"li\",\n\t\t\t\t\t\t{},\n\t\t\t\t\t\tel(doc, \"strong\", { text: `${app}:` }),\n\t\t\t\t\t\t` ${how}`,\n\t\t\t\t\t);\n\t\t\t\t\tif (command !== undefined) {\n\t\t\t\t\t\t// A block with its own Copy, like the code.\n\t\t\t\t\t\tconst text = el(doc, \"pre\", { text: command });\n\t\t\t\t\t\ttext.dir = \"ltr\";\n\t\t\t\t\t\tconst { button: copyCommand } = copyButton(\n\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t`${app} command`,\n\t\t\t\t\t\t\t() => text.textContent ?? \"\",\n\t\t\t\t\t\t\t() => doc.getSelection()?.selectAllChildren(text),\n\t\t\t\t\t\t\tannounce,\n\t\t\t\t\t\t\t\"tab-mcp-command-copy\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"div\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command\" },\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tcopyCommand,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (note !== undefined)\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"small\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command-note\" },\n\t\t\t\t\t\t\t\t...note.map((part, i) =>\n\t\t\t\t\t\t\t\t\ti % 2 === 1 ? el(doc, \"code\", { text: part }) : part,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\treturn item;\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tconst oidc = mcp.session?.pairing === \"oidc\";\n\t\t// A new code is not copied yet.\n\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = oidc || current === undefined;\n\t\tsignInLine.hidden = !oidc;\n\t\trenderCloseNote();\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\t// Grants that come with a (new) session were there before; only the ones\n\t// added during a session are new connections.\n\tlet session = mcp.session;\n\tconst renderGrants = () => {\n\t\tif (mcp.session !== session) {\n\t\t\tsession = mcp.session;\n\t\t\tfor (const grant of mcp.grants) known.add(grant.grantId);\n\t\t}\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t\tpairedGrants.add(grant.grantId);\n\t\t\tif (!paired) setPaired(true);\n\t\t}\n\t\t// The app that connected here is gone again (Disconnect, or revoked):\n\t\t// back to Close and the note, the code still runs.\n\t\tif (paired && !mcp.grants.some((g) => pairedGrants.has(g.grantId))) {\n\t\t\tsetPaired(false);\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"Disconnect\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t\t},\n\t\t\t\t\t\"tab-mcp-disconnect\",\n\t\t\t\t\t\"danger\",\n\t\t\t\t);\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"span\", {\n\t\t\t\t\t\tclassName: \"tab-mcp-app\",\n\t\t\t\t\t\ttext: `${clientLabel(grant.client)} connected `,\n\t\t\t\t\t}),\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\n\t// The address was taken over: the notice says so instead of this dialog.\n\tconst onReplaced = () => dialog.close();\n\twatchReplaced(mcp, doc);\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tmcp.addEventListener(\"replaced\", onReplaced);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\tmcp.removeEventListener(\"replaced\", onReplaced);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\t// Start at the address's Copy; until the address is there, at the\n\t\t// dialog itself (its title is read out), not at Close.\n\t\tif (!addressBox.hidden) copy.focus();\n\t\telse dialog.focus();\n\t});\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAMO,MAAM,cAAc;AAAA,EACjB,SAAS,IAAI;AAAA,EAEtB,GAAG,CAAC,SAAiB,MAAuB;AA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AAAA,EAC7C,IAAI,iBAAiB,gBAAgB,cAAc;AAAA,EACnD,IAAI,iBAAiB,YAAY,UAAU;AAAA,EAC3C,IAAI,KAAK,OAAO,MAAM;AAAA,EACtB,IAAI,aAAa;AAAA,EACjB,aAAa;AAAA,EACb,WAAW;AAAA,EACX,cAAc,IAAI,OAAO;AAAA,EACzB,WAAW,KACV,CAAC,YAAY,cAAc,OAAO,GAClC,CAAC,UAAmB;AAAA,IACnB,OAAO,cAAc,sBAAsB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,GAElG;AAAA,EAEA,OAAO,IAAI,QAAQ,CAAC,YAAY;AAAA,IAC/B,OAAO,iBACN,SACA,MAAM;AAAA,MACL,IAAI,YAAY;AAAA,MAChB,IAAI,oBAAoB,eAAe,UAAU;AAAA,MACjD,IAAI,oBAAoB,gBAAgB,YAAY;AAAA,MACpD,IAAI,oBAAoB,aAAa,WAAW;AAAA,MAChD,IAAI,oBAAoB,gBAAgB,cAAc;AAAA,MACtD,IAAI,oBAAoB,YAAY,UAAU;AAAA,MAC9C,OAAO,OAAO;AAAA,MACd,QAAQ;AAAA,OAET,EAAE,MAAM,KAAK,CACd;AAAA,IACA,OAAO,UAAU;AAAA,IAGjB,IAAI,CAAC,WAAW;AAAA,MAAQ,KAAK,MAAM;AAAA,IACnC;AAAA,MAAK,OAAO,MAAM;AAAA,GAClB;AAAA;",
|
|
9
|
+
"debugId": "BF9126D2E275582F64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/ui.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type { ConfirmRequest, SessionInfo } from "./types.js";
|
|
|
22
22
|
* page's `color-scheme`, so the dialogs follow its light or dark scheme. The
|
|
23
23
|
* `--_tab-mcp-*` properties are internal. Order matters among equals.
|
|
24
24
|
*/
|
|
25
|
-
export declare const DIALOG_CSS = ".tab-mcp-dialog {\n--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);\n--_tab-mcp-bg: var(--tab-mcp-background, Canvas);\n--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));\n--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);\n--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));\n--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));\n--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);\nbox-sizing: border-box; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;\nfont: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);\nborder: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);\npadding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));\n}\n.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }\n.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }\n.tab-mcp-dialog :where([hidden]) { display: none !important; }\nhtml dialog.tab-mcp-dialog:where(:focus) { outline: none; }\n.tab-mcp-dialog :where(*) { box-sizing: border-box; }\n.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }\n.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }\n.tab-mcp-dialog :where(small) { font-size: 0.875em; }\n.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note) { color: var(--_tab-mcp-muted); }\nhtml dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }\n.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }\nhtml dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }\nhtml dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }\nhtml button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }\nhtml button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }\nhtml button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }\n.tab-mcp-copy { min-width: 6em; }\n.tab-mcp-close { font-size: 0.875em; }\n.tab-mcp-status { margin-top: -0.5rem; }\n.tab-mcp-description:where(:empty) { display: none; }\n.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }\n.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }\n.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }\n.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code > :where(span) { font-weight: 600; }\n.tab-mcp-code :where(br) { display: none; }\n.tab-mcp-code :where(small) { grid-column: 1 / -1; }\n.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }\n.tab-mcp-help :where(summary) {
|
|
25
|
+
export declare const DIALOG_CSS = ".tab-mcp-dialog {\n--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);\n--_tab-mcp-bg: var(--tab-mcp-background, Canvas);\n--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));\n--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);\n--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));\n--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));\n--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);\nbox-sizing: border-box; margin: auto; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;\nfont: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);\nborder: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);\npadding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));\n}\n.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }\n.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }\n.tab-mcp-dialog :where([hidden]) { display: none !important; }\nhtml dialog.tab-mcp-dialog:where(:focus) { outline: none; }\n.tab-mcp-dialog :where(*) { box-sizing: border-box; }\n.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }\n.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }\n.tab-mcp-dialog :where(small) { font-size: 0.875em; }\n.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note) { color: var(--_tab-mcp-muted); }\nhtml dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }\n.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }\nhtml dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }\nhtml dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }\nhtml button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }\nhtml button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }\nhtml button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }\n.tab-mcp-copy { min-width: 6em; }\n.tab-mcp-close { font-size: 0.875em; }\n.tab-mcp-status { margin-top: -0.5rem; }\n.tab-mcp-description:where(:empty) { display: none; }\n.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }\n.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }\n.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }\n.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-code > :where(span) { font-weight: 600; }\n.tab-mcp-code :where(br) { display: none; }\n.tab-mcp-code :where(small) { grid-column: 1 / -1; }\n.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }\n.tab-mcp-help { border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-help :where(summary) { padding: 0.75rem 1rem; font-weight: 600; cursor: pointer; }\n.tab-mcp-help > :where(:not(summary)) { margin-inline: 1rem; }\n.tab-mcp-help > :where(:last-child:not(summary)) { margin-bottom: 1rem; }\n.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }\n.tab-mcp-help :where(ul) { margin-top: 0.25rem; margin-bottom: 0.75rem; gap: 0.75rem; }\n.tab-mcp-help :where(li) { overflow-wrap: anywhere; }\n.tab-mcp-help :where(strong) { display: block; font-weight: 600; }\n.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }\n.tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-command-note { display: block; margin-top: 0.375rem; }\n.tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }\n.tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }\n.tab-mcp-apps-note { margin-top: 0.5rem; }\n.tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }\n.tab-mcp-close-note { flex: 1 1 12rem; }\n.tab-mcp-confirm :where(p bdi) { font-weight: 600; }\n.tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-always-note { font-size: 0.875em; }\n@media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }\n@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } }\n@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }\n@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }\n";
|
|
26
26
|
/** How long "Allow" stays disabled after the confirmation opens, and the floor. */
|
|
27
27
|
export declare const ALLOW_DELAY_MS = 750;
|
|
28
28
|
export declare const MIN_ALLOW_DELAY_MS = 500;
|
package/version.d.ts
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
var at=/^(?:\d{1,4}x\d{1,4}|any)$/;function ut(e){let{src:t,mimeType:r,sizes:s,theme:i}=e;if(typeof t!=="string")return;let d=/^https?:/i.test(t)&&t.length<=2048,o=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!d&&!o)return;let u={src:t};if(typeof r==="string"&&/^image\/[\w.+-]+$/i.test(r))u.mimeType=r.toLowerCase();let x=Array.isArray(s)?s.map((O)=>String(O).toLowerCase()).filter((O)=>at.test(O)):[];if(x.length>0)u.sizes=x;if(i==="light"||i==="dark")u.theme=i;return u}function xe(e){let t=[];for(let r of e){let s=typeof r==="object"&&r!==null?ut(r):void 0;if(s!==void 0)t.push(s);if(t.length===8)break}return t}function Ne(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return xe([...t??[]].filter((r)=>r.getAttribute("href")?.trim()).map((r)=>{let s={src:r.href};if(r.type)s.mimeType=r.type;let i=r.getAttribute("sizes");if(i)s.sizes=i.trim().split(/\s+/);let d=/prefers-color-scheme:\s*(light|dark)/i.exec(r.media);if(d)s.theme=d[1]?.toLowerCase();return s}))}catch{return[]}}function ae(e,t){let r=typeof e;if(r!==typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;let s=e.length;if(s!==t.length)return!1;for(let i=0;i<s;i++)if(!ae(e[i],t[i]))return!1;return!0}if(r==="object"){if(!e||!t)return e===t;let s=Object.keys(e),i=Object.keys(t);if(s.length!==i.length)return!1;for(let o of s)if(!ae(e[o],t[o]))return!1;return!0}return e===t}function U(e){return encodeURI(lt(e))}function lt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var ft={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},ct={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},pt={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},mt=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function ee(e,t=Object.create(null),r=mt,s=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let d=e.$id||e.id;if(d){let o=new URL(d,r.href);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",s==="")r=o;else ee(e,t,r)}}else if(e!==!0&&e!==!1)return t;let i=r.href+(s?"#"+s:"");if(t[i]!==void 0)throw Error(`Duplicate schema URI "${i}".`);if(t[i]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:i});if(e.$ref&&e.__absolute_ref__===void 0){let d=new URL(e.$ref,r.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:d.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let d=new URL(e.$recursiveRef,r.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:d.href})}if(e.$anchor){let d=new URL("#"+e.$anchor,r.href);t[d.href]=e}for(let d in e){if(pt[d])continue;let o=`${s}/${U(d)}`,u=e[d];if(Array.isArray(u)){if(ft[d]){let x=u.length;for(let O=0;O<x;O++)ee(u[O],t,r,`${o}/${O}`)}}else if(ct[d])for(let x in u)ee(u[x],t,r,`${o}/${U(x)}`);else ee(u,t,r,o)}return t}var yt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,gt=[0,31,28,31,30,31,30,31,31,30,31,30,31],ht=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,$t=/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,bt=/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][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-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,Rt=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,It=/^(?:\/(?:[^~/]|~0|~1)*)*$/,xt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Tt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,_t=(e)=>{if(e[0]==='"')return!1;let[t,r,...s]=e.split("@");if(!t||!r||s.length!==0||t.length>64||r.length>253)return!1;if(t[0]==="."||t.endsWith(".")||t.includes(".."))return!1;if(!/^[a-z0-9.-]+$/i.test(r)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t))return!1;return r.split(".").every((i)=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(i))},vt=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,St=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,Mt=(e)=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function Y(e){return e.test.bind(e)}var Te={date:je,time:qe.bind(void 0,!1),"date-time":At,duration:Mt,uri:Nt,"uri-reference":Y(bt),"uri-template":Y(wt),url:Y(kt),email:_t,hostname:Y($t),ipv4:Y(vt),ipv6:Y(St),regex:qt,uuid:Y(Rt),"json-pointer":Y(It),"json-pointer-uri-fragment":Y(xt),"relative-json-pointer":Y(Tt)};function Et(e){return e%4===0&&(e%100!==0||e%400===0)}function je(e){let t=e.match(yt);if(!t)return!1;let r=+t[1],s=+t[2],i=+t[3];return s>=1&&s<=12&&i>=1&&i<=(s==2&&Et(r)?29:gt[s])}function qe(e,t){let r=t.match(ht);if(!r)return!1;let s=+r[1],i=+r[2],d=+r[3],o=!!r[5];return(s<=23&&i<=59&&d<=59||s==23&&i==59&&d==60)&&(!e||o)}var Ot=/t|\s/i;function At(e){let t=e.split(Ot);return t.length==2&&je(t[0])&&qe(!0,t[1])}var Pt=/\/|:/,Ct=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Nt(e){return Pt.test(e)&&Ct.test(e)}var jt=/[^\\]\\Z/;function qt(e){if(jt.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function ze(e){let t=0,r=e.length,s=0,i;while(s<r)if(t++,i=e.charCodeAt(s++),i>=55296&&i<=56319&&s<r){if(i=e.charCodeAt(s),(i&64512)==56320)s++}return t}function E(e,t,r="2019-09",s=ee(t),i=!0,d=null,o="#",u="#",x=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let O=typeof e,v;switch(O){case"boolean":case"number":case"string":v=O;break;case"object":if(e===null)v="null";else if(Array.isArray(e))v="array";else v="object";break;default:throw Error(`Instances of "${O}" type are not supported.`)}let{$ref:B,$recursiveRef:D,$recursiveAnchor:V,type:C,const:G,enum:W,required:Q,not:L,anyOf:A,allOf:l,oneOf:g,if:R,then:T,else:y,format:n,properties:h,patternProperties:p,additionalProperties:S,unevaluatedProperties:_,minProperties:N,maxProperties:P,propertyNames:K,dependentRequired:z,dependentSchemas:j,dependencies:H,prefixItems:fe,items:re,additionalItems:Me,unevaluatedItems:Ee,contains:Oe,minContains:X,maxContains:me,minItems:Re,maxItems:Ie,uniqueItems:it,minimum:ne,maximum:oe,exclusiveMinimum:ce,exclusiveMaximum:pe,multipleOf:ye,minLength:ge,maxLength:he,pattern:Ae,__absolute_ref__:$e,__absolute_recursive_ref__:dt}=t,f=[];if(V===!0&&d===null)d=t;if(D==="#"){let b=d===null?s[dt]:d,m=`${u}/$recursiveRef`,I=E(e,d===null?t:d,r,s,i,b,o,m,x);if(!I.valid)f.push({instanceLocation:o,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(B!==void 0){let m=s[$e||B];if(m===void 0){let a=`Unresolved $ref "${B}".`;if($e&&$e!==B)a+=` Absolute URI "${$e}".`;throw a+=`
|
|
2
|
-
Known schemas:
|
|
3
|
-
- ${Object.keys(s).join(`
|
|
4
|
-
- `)}`,Error(a)}let I=`${u}/$ref`,c=E(e,m,r,s,i,d,o,I,x);if(!c.valid)f.push({instanceLocation:o,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...c.errors);if(r==="4"||r==="7")return{valid:f.length===0,errors:f}}if(Array.isArray(C)){let b=C.length,m=!1;for(let I=0;I<b;I++)if(v===C[I]||C[I]==="integer"&&v==="number"&&e%1===0&&e===e){m=!0;break}if(!m)f.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${v}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(v!=="number"||e%1||e!==e)f.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${v}" is invalid. Expected "${C}".`})}else if(C!==void 0&&v!==C)f.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${v}" is invalid. Expected "${C}".`});if(G!==void 0){if(v==="object"||v==="array"){if(!ae(e,G))f.push({instanceLocation:o,keyword:"const",keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}else if(e!==G)f.push({instanceLocation:o,keyword:"const",keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}if(W!==void 0){if(v==="object"||v==="array"){if(!W.some((b)=>ae(e,b)))f.push({instanceLocation:o,keyword:"enum",keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(W)}.`})}else if(!W.some((b)=>e===b))f.push({instanceLocation:o,keyword:"enum",keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(W)}.`})}if(L!==void 0){let b=`${u}/not`;if(E(e,L,r,s,i,d,o,b).valid)f.push({instanceLocation:o,keyword:"not",keywordLocation:b,error:'Instance matched "not" schema.'})}let be=[];if(A!==void 0){let b=`${u}/anyOf`,m=f.length,I=!1;for(let c=0;c<A.length;c++){let a=A[c],k=Object.create(x),w=E(e,a,r,s,i,V===!0?d:null,o,`${b}/${c}`,k);if(f.push(...w.errors),I=I||w.valid,w.valid)be.push(k)}if(I)f.length=m;else f.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:b,error:"Instance does not match any subschemas."})}if(l!==void 0){let b=`${u}/allOf`,m=f.length,I=!0;for(let c=0;c<l.length;c++){let a=l[c],k=Object.create(x),w=E(e,a,r,s,i,V===!0?d:null,o,`${b}/${c}`,k);if(f.push(...w.errors),I=I&&w.valid,w.valid)be.push(k)}if(I)f.length=m;else f.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:b,error:"Instance does not match every subschema."})}if(g!==void 0){let b=`${u}/oneOf`,m=f.length,I=g.filter((c,a)=>{let k=Object.create(x),w=E(e,c,r,s,i,V===!0?d:null,o,`${b}/${a}`,k);if(f.push(...w.errors),w.valid)be.push(k);return w.valid}).length;if(I===1)f.length=m;else f.splice(m,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:b,error:`Instance does not match exactly one subschema (${I} matches).`})}if(v==="object"||v==="array")Object.assign(x,...be);if(R!==void 0){let b=`${u}/if`;if(E(e,R,r,s,i,d,o,b,x).valid){if(T!==void 0){let I=E(e,T,r,s,i,d,o,`${u}/then`,x);if(!I.valid)f.push({instanceLocation:o,keyword:"if",keywordLocation:b,error:'Instance does not match "then" schema.'},...I.errors)}}else if(y!==void 0){let I=E(e,y,r,s,i,d,o,`${u}/else`,x);if(!I.valid)f.push({instanceLocation:o,keyword:"if",keywordLocation:b,error:'Instance does not match "else" schema.'},...I.errors)}}if(v==="object"){if(Q!==void 0){for(let c of Q)if(!(c in e))f.push({instanceLocation:o,keyword:"required",keywordLocation:`${u}/required`,error:`Instance does not have required property "${c}".`})}let b=Object.keys(e);if(N!==void 0&&b.length<N)f.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${u}/minProperties`,error:`Instance does not have at least ${N} properties.`});if(P!==void 0&&b.length>P)f.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${u}/maxProperties`,error:`Instance does not have at least ${P} properties.`});if(K!==void 0){let c=`${u}/propertyNames`;for(let a in e){let k=`${o}/${U(a)}`,w=E(a,K,r,s,i,d,k,c);if(!w.valid)f.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:c,error:`Property name "${a}" does not match schema.`},...w.errors)}}if(z!==void 0){let c=`${u}/dependantRequired`;for(let a in z)if(a in e){let k=z[a];for(let w of k)if(!(w in e))f.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:c,error:`Instance has "${a}" but does not have "${w}".`})}}if(j!==void 0)for(let c in j){let a=`${u}/dependentSchemas`;if(c in e){let k=E(e,j[c],r,s,i,d,o,`${a}/${U(c)}`,x);if(!k.valid)f.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:a,error:`Instance has "${c}" but does not match dependant schema.`},...k.errors)}}if(H!==void 0){let c=`${u}/dependencies`;for(let a in H)if(a in e){let k=H[a];if(Array.isArray(k)){for(let w of k)if(!(w in e))f.push({instanceLocation:o,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not have "${w}".`})}else{let w=E(e,k,r,s,i,d,o,`${c}/${U(a)}`);if(!w.valid)f.push({instanceLocation:o,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not match dependant schema.`},...w.errors)}}}let m=Object.create(null),I=!1;if(h!==void 0){let c=`${u}/properties`;for(let a in h){if(!(a in e))continue;let k=`${o}/${U(a)}`,w=E(e[a],h[a],r,s,i,d,k,`${c}/${U(a)}`);if(w.valid)x[a]=m[a]=!0;else if(I=i,f.push({instanceLocation:o,keyword:"properties",keywordLocation:c,error:`Property "${a}" does not match schema.`},...w.errors),I)break}}if(!I&&p!==void 0){let c=`${u}/patternProperties`;for(let a in p){let k=new RegExp(a,"u"),w=p[a];for(let J in e){if(!k.test(J))continue;let Pe=`${o}/${U(J)}`,Ce=E(e[J],w,r,s,i,d,Pe,`${c}/${U(a)}`);if(Ce.valid)x[J]=m[J]=!0;else I=i,f.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:c,error:`Property "${J}" matches pattern "${a}" but does not match associated schema.`},...Ce.errors)}}}if(!I&&S!==void 0){let c=`${u}/additionalProperties`;for(let a in e){if(m[a])continue;let k=`${o}/${U(a)}`,w=E(e[a],S,r,s,i,d,k,c);if(w.valid)x[a]=!0;else I=i,f.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:c,error:`Property "${a}" does not match additional properties schema.`},...w.errors)}}else if(!I&&_!==void 0){let c=`${u}/unevaluatedProperties`;for(let a in e)if(!x[a]){let k=`${o}/${U(a)}`,w=E(e[a],_,r,s,i,d,k,c);if(w.valid)x[a]=!0;else f.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:c,error:`Property "${a}" does not match unevaluated properties schema.`},...w.errors)}}}else if(v==="array"){if(Ie!==void 0&&e.length>Ie)f.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${u}/maxItems`,error:`Array has too many items (${e.length} > ${Ie}).`});if(Re!==void 0&&e.length<Re)f.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${u}/minItems`,error:`Array has too few items (${e.length} < ${Re}).`});let b=e.length,m=0,I=!1;if(fe!==void 0){let c=`${u}/prefixItems`,a=Math.min(fe.length,b);for(;m<a;m++){let k=E(e[m],fe[m],r,s,i,d,`${o}/${m}`,`${c}/${m}`);if(x[m]=!0,!k.valid){if(I=i,f.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:c,error:"Items did not match schema."},...k.errors),I)break}}}if(re!==void 0){let c=`${u}/items`;if(Array.isArray(re)){let a=Math.min(re.length,b);for(;m<a;m++){let k=E(e[m],re[m],r,s,i,d,`${o}/${m}`,`${c}/${m}`);if(x[m]=!0,!k.valid){if(I=i,f.push({instanceLocation:o,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...k.errors),I)break}}}else for(;m<b;m++){let a=E(e[m],re,r,s,i,d,`${o}/${m}`,c);if(x[m]=!0,!a.valid){if(I=i,f.push({instanceLocation:o,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...a.errors),I)break}}if(!I&&Me!==void 0){let a=`${u}/additionalItems`;for(;m<b;m++){let k=E(e[m],Me,r,s,i,d,`${o}/${m}`,a);if(x[m]=!0,!k.valid)I=i,f.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:a,error:"Items did not match additional items schema."},...k.errors)}}}if(Oe!==void 0)if(b===0&&X===void 0)f.push({instanceLocation:o,keyword:"contains",keywordLocation:`${u}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(X!==void 0&&b<X)f.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${u}/minContains`,error:`Array has less items (${b}) than minContains (${X}).`});else{let c=`${u}/contains`,a=f.length,k=0;for(let w=0;w<b;w++){let J=E(e[w],Oe,r,s,i,d,`${o}/${w}`,c);if(J.valid)x[w]=!0,k++;else f.push(...J.errors)}if(k>=(X||0))f.length=a;if(X===void 0&&me===void 0&&k===0)f.splice(a,0,{instanceLocation:o,keyword:"contains",keywordLocation:c,error:"Array does not contain item matching schema."});else if(X!==void 0&&k<X)f.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${u}/minContains`,error:`Array must contain at least ${X} items matching schema. Only ${k} items were found.`});else if(me!==void 0&&k>me)f.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${u}/maxContains`,error:`Array may contain at most ${me} items matching schema. ${k} items were found.`})}if(!I&&Ee!==void 0){let c=`${u}/unevaluatedItems`;for(m;m<b;m++){if(x[m])continue;let a=E(e[m],Ee,r,s,i,d,`${o}/${m}`,c);if(x[m]=!0,!a.valid)f.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:c,error:"Items did not match unevaluated items schema."},...a.errors)}}if(it)for(let c=0;c<b;c++){let a=e[c],k=typeof a==="object"&&a!==null;for(let w=0;w<b;w++){if(c===w)continue;let J=e[w];if(a===J||k&&(typeof J==="object"&&J!==null)&&ae(a,J))f.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${u}/uniqueItems`,error:`Duplicate items at indexes ${c} and ${w}.`}),c=Number.MAX_SAFE_INTEGER,w=Number.MAX_SAFE_INTEGER}}}else if(v==="number"){if(r==="4"){if(ne!==void 0&&(ce===!0&&e<=ne||e<ne))f.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${u}/minimum`,error:`${e} is less than ${ce?"or equal to ":""} ${ne}.`});if(oe!==void 0&&(pe===!0&&e>=oe||e>oe))f.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${u}/maximum`,error:`${e} is greater than ${pe?"or equal to ":""} ${oe}.`})}else{if(ne!==void 0&&e<ne)f.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${u}/minimum`,error:`${e} is less than ${ne}.`});if(oe!==void 0&&e>oe)f.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${u}/maximum`,error:`${e} is greater than ${oe}.`});if(ce!==void 0&&e<=ce)f.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${u}/exclusiveMinimum`,error:`${e} is less than ${ce}.`});if(pe!==void 0&&e>=pe)f.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${u}/exclusiveMaximum`,error:`${e} is greater than or equal to ${pe}.`})}if(ye!==void 0){let b=e%ye;if(Math.abs(0-b)>=0.00000011920929&&Math.abs(ye-b)>=0.00000011920929)f.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${u}/multipleOf`,error:`${e} is not a multiple of ${ye}.`})}}else if(v==="string"){let b=ge===void 0&&he===void 0?0:ze(e);if(ge!==void 0&&b<ge)f.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${u}/minLength`,error:`String is too short (${b} < ${ge}).`});if(he!==void 0&&b>he)f.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${u}/maxLength`,error:`String is too long (${b} > ${he}).`});if(Ae!==void 0&&!new RegExp(Ae,"u").test(e))f.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${u}/pattern`,error:"String does not match pattern."});if(n!==void 0&&Te[n]&&!Te[n](e))f.push({instanceLocation:o,keyword:"format",keywordLocation:`${u}/format`,error:`String does not match format "${n}".`})}return{valid:f.length===0,errors:f}}var Je="ch.ractive.tab-mcp/annotations",zt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Ht=["destructiveHint","idempotentHint","openWorldHint"];function Ue(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let i of Ht){let d=e[i];if(d!==void 0)t[i]=d}let r={};for(let i of zt){let d=e[i];if(d!==void 0)r[i]=d}let s={};if(Object.keys(t).length>0)s.annotations=t;if(Object.keys(r).length>0)s.meta=r;return s}function Z(e){return{content:[{type:"text",text:e}],isError:!0}}function He(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Be(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(He(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return Z("The tool returned a value that is not JSON.");let r={content:[{type:"text",text:t}]};if(He(e))r.structuredContent=e;return r}function De(e){let t=e instanceof Error?e.message:String(e);return Z(t||"The tool failed.")}var se="2026-07-28",te="io.modelcontextprotocol/protocolVersion",we="io.modelcontextprotocol/clientCapabilities",Ve="io.modelcontextprotocol/clientInfo",Ge="io.modelcontextprotocol/serverInfo",_e="io.modelcontextprotocol/subscriptionId",Jt=-32020,We=-32022,Ut=0,Ke=new WeakMap;function ve(e){let t=Ke.get(e);if(t!==void 0)return t;let r=e.inputSchema,s;try{s=ee(r)}catch(d){let o=d instanceof Error?d.message:String(d);throw Error(o.split(`
|
|
5
|
-
`)[0])}for(let d of Object.values(s)){if(typeof d!=="object"||d.$ref===void 0)continue;let o=d.__absolute_ref__;if(s[o??d.$ref]===void 0)throw Error(`$ref ${JSON.stringify(d.$ref)} does not resolve`)}let i=(d)=>E(d,r,"2020-12",s,!1);return Ke.set(e,i),i}function Ye(e,t,r=""){let s=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${s}${r}`)}function Bt(e){let t=[];for(let r of e.list())try{ve(r)}catch(s){e.remove(r),t.push(Ye(r.name,s,"; the tool was unregistered"))}return e.setCompiler((r)=>{try{ve(r)}catch(s){throw Ye(r.name,s)}}),t}function Fe(e){try{return structuredClone(e)}catch{return e}}var Dt=new TextEncoder;function ie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Se(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function q(e,t,r,s,i){let d={code:r,message:s};if(i!==void 0)d.data=i;return Se(e,{jsonrpc:"2.0",id:t,error:d})}function F(e,t,r){return q(400,e,Jt,`Bad Request: the request headers and body disagree: ${r}`,{mismatch:{header:t,body:r}})}function ue(e){return Dt.encode(`event: message
|
|
6
|
-
data: ${JSON.stringify(e)}
|
|
7
|
-
|
|
8
|
-
`)}var Xe={"content-type":"text/event-stream","cache-control":"no-cache"};function Vt(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function Gt(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let r=atob(t),s=Uint8Array.from(r,(i)=>i.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(s)}catch{return}}function Wt(e){if(!(te in e))return{key:te,problem:"missing"};if(!(we in e))return{key:we,problem:"missing"};if(typeof e[te]!=="string")return{key:te,problem:"expected a protocol version string"};if(!ie(e[we]))return{key:we,problem:"expected an object"};let t=e[Ve];if(t!==void 0&&!(ie(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ve,problem:"expected {name, version}"};return}function Kt(e){let t=e.notifications;return ie(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Ze(e){let{tools:t,server:r}=e,s={name:r.name,version:r.version};if(r.title!==void 0)s.title=r.title;let i=xe(r.icons??[]),d=i.length>0?{...s,icons:i}:s,o=new Set,u=!1,x=(l={})=>({...l,[Ge]:s});function O(l,g,R=x()){return{jsonrpc:"2.0",id:l,result:{...g,resultType:"complete",_meta:R}}}function v(l,g){let R;try{R=ve(l)(g)}catch(y){let n=y instanceof Error?y.message:String(y);return`The input schema of tool ${l.name} cannot be used: ${n}`}if(R.valid)return;let T=R.errors.filter((y)=>y.keyword!=="properties"&&y.keyword!=="$ref").map((y)=>`${y.instanceLocation} ${y.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${l.name}: ${T||"the arguments do not match the schema"}`}function B(){return t.list().map((l)=>{let g={name:l.name};if(l.title!==void 0)g.title=l.title;g.description=l.description,g.inputSchema=l.inputSchema;let{annotations:R,meta:T}=Ue(l.annotations);if(R!==void 0)g.annotations=R;if(T!==void 0)g._meta={[Je]:T};return g})}let D=(l)=>({kind:"invalid",message:l});async function V(l,g,R){let T=l.name;if(typeof T!=="string")return D("Invalid params: name must be a string");let y=t.get(T);if(y===void 0)return D(`Tool ${T} not found`);let n=l.arguments??{};if(!ie(n))return D("Invalid params: arguments must be an object");let h=e.client(R),p={id:++Ut,tool:y.name,arguments:Fe(n),client:{...h}};if(y.title!==void 0)p.title=y.title;let S=Date.now();e.observe?.start(p);let _="error",N=Z("Internal error");try{[_,N]=await C(y,n,g,h)}finally{e.observe?.end({id:p.id,tool:y.name,client:{...h},outcome:_,result:Fe(N),durationMs:Date.now()-S})}return{kind:"result",result:N}}async function C(l,g,R,T){let y=v(l,g);if(y!==void 0)return["error",Z(y)];if(l.annotations.consequentialHint===!0){let h={tool:{name:l.name,description:l.description},arguments:g,client:T,signal:R};if(l.title!==void 0)h.tool.title=l.title;let p=!1;try{p=await e.confirm(h)}catch{p=!1}if(!p)return[R.aborted?"cancelled":"declined",Z("The user declined")]}if(R.aborted)return["cancelled",Z("Cancelled")];if(t.get(l.name)!==l)return["error",Z("The tool is no longer available")];let n;try{n=Be(await l.execute(g,{signal:R,client:T}))}catch(h){n=De(h)}if(R.aborted)return["cancelled",n];return[n.isError===!0?"error":"ok",n]}function G(l,g,R,T){let y=new ReadableStream({start:(n)=>{let h=(p)=>{if(R.aborted)return;let S;try{S=ue(p)}catch{S=ue(O(l,Z("The tool returned a result that is not JSON.")))}try{n.enqueue(S),n.close()}catch{}};V(g,R,T).then((p)=>h(p.kind==="invalid"?{jsonrpc:"2.0",id:l,error:{code:-32602,message:p.message}}:O(l,p.result)),()=>h({jsonrpc:"2.0",id:l,error:{code:-32603,message:"Internal error"}}))}});return new Response(y,{status:200,headers:Xe})}function W(l,g,R){let T=Kt(g),y={jsonrpc:"2.0",id:l,result:{resultType:"complete",_meta:x({[_e]:l})}},n,h=new ReadableStream({start:(p)=>{if(p.enqueue(ue({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:T,_meta:{[_e]:l}}})),Object.keys(T).length===0){p.enqueue(ue(y)),p.close();return}let S={id:l,send:(_)=>{try{p.enqueue(ue(_))}catch{o.delete(S)}},end:()=>{o.delete(S);try{p.enqueue(ue(y)),p.close()}catch{}}};n=S,o.add(S),R.addEventListener("abort",()=>{o.delete(S);try{p.close()}catch{}})},cancel:()=>{if(n!==void 0)o.delete(n)}});return new Response(h,{status:200,headers:Xe})}function Q(l,g){if(Array.isArray(g))return q(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!ie(g)||g.jsonrpc!=="2.0")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:R,id:T}=g;if(typeof R!=="string")return"result"in g||"error"in g?q(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let y=l.headers.get("mcp-protocol-version"),n=l.headers.get("mcp-method"),h=ie(g.params)?g.params:{},p=ie(h._meta)?h._meta:void 0,S=p!==void 0&&te in p,_=typeof p?.[te]==="string"?p[te]:void 0,N=y!==null&&y>=se;if(T===void 0){if(_!==void 0&&y!==null&&y!==_)return F(null,y,`the notification envelope names protocol version ${_} but the MCP-Protocol-Version header names ${y}`);if((S||N)&&n!==null&&n!==R)return F(null,n,`the notification body names method ${R} but the Mcp-Method header names ${n}`);return"notification"}if(typeof T!=="string"&&typeof T!=="number")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let P=T;if(!S||R==="initialize"&&(_===void 0||_<se)){if(R==="initialize"){if(N)return F(P,y,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let z=typeof h.protocolVersion==="string"?h.protocolVersion:void 0;return L(P,z)}if(N){let z=p===void 0?["_meta"]:[te];return q(400,P,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${y}, but the request is missing the required per-request envelope key(s): ${z.join(", ")}`,{envelope:{missing:z}})}return L(P,y??void 0)}let K=Wt(p);if(K!==void 0)return q(400,P,-32602,`Invalid _meta envelope for protocol revision ${se}: ${K.key}: ${K.problem}`,{envelope:K});if(y!==null&&_!==void 0&&y!==_)return F(P,y,`the body envelope names protocol version ${_} but the MCP-Protocol-Version header names ${y}`);if(n!==null&&n!==R)return F(P,n,`the body names method ${R} but the Mcp-Method header names ${n}`);if(_!==se)return L(P,_);if(y===null)return F(P,"(missing)",`the body envelope names protocol version ${_} but the required MCP-Protocol-Version header is absent`);if(n===null)return F(P,"(missing)",`the body names method ${R} but the required Mcp-Method header is absent`);if(R==="tools/call"&&typeof h.name==="string"){let z=h.name,j=l.headers.get("mcp-name");if(j===null)return F(P,"(missing)",`the body carries params.name="${z}" but the required Mcp-Name header is absent`);let H=Gt(j);if(H===void 0)return F(P,j,"the Mcp-Name header carries an invalid Base64 sentinel value");if(H!==z)return F(P,j,`the body carries params.name="${z}" but the Mcp-Name header names "${H}"`)}return{id:P,method:R,params:h}}function L(l,g){return g===void 0?q(400,l,We,"Unsupported protocol version: the request did not name a protocol version",{supported:[se]}):q(400,l,We,`Unsupported protocol version: ${g}`,{supported:[se],requested:g})}async function A(l,g){if(l.method.toUpperCase()!=="POST")return q(405,null,-32000,"Method not allowed.");if(!Vt(l.headers.get("content-type")))return q(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let R;try{R=JSON.parse(g.body??await l.text())}catch{return q(400,null,-32700,"Parse error: the request body is not valid JSON")}let T=Q(l,R);if(T instanceof Response)return T;if(T==="notification")return new Response(null,{status:202});let{id:y,method:n,params:h}=T;switch(n){case"server/discover":{let p={supportedVersions:[se],capabilities:{tools:{listChanged:!0}}};if(r.instructions!==void 0)p.instructions=r.instructions;return p.ttlMs=0,p.cacheScope="private",Se(200,O(y,p,{[Ge]:d}))}case"tools/list":return Se(200,O(y,{tools:B(),ttlMs:0,cacheScope:"private"}));case"tools/call":return G(y,h,l.signal,g.grant);case"subscriptions/listen":return W(y,h,l.signal);default:return q(404,y,-32601,"Method not found")}}return{handle:(l,g)=>A(l,g).catch(()=>q(500,null,-32603,"Internal server error")),toolsChanged(){if(u)return;u=!0,queueMicrotask(()=>{u=!1;for(let l of[...o])l.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[_e]:l.id}}})})},close(){for(let l of[...o])l.end()}}}var ke="tab-mcp.v1";function le(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var M=(e)=>typeof e==="string";function Qe(e){if(!le(e)||!M(e.grantId)||!M(e.createdAt))return!1;let t=e.client;return le(t)&&M(t.id)&&M(t.name)&&M(t.host)}function Yt(e){if(!le(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Ft(e){return le(e)&&Object.values(e).every(M)}function Le(e){let t;try{t=JSON.parse(e)}catch{return}if(!le(t))return;switch(t.type){case"session":return M(t.sessionId)&&M(t.address)&&M(t.origin)&&M(t.expiresAt)&&Yt(t.limits)&&Array.isArray(t.grants)&&t.grants.every(Qe)&&(t.appName===void 0||M(t.appName))&&(t.pairing===void 0||M(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:M(t.reason)?t.reason:""};case"http.request":return M(t.id)&&M(t.method)&&M(t.path)&&Ft(t.headers)&&M(t.body)&&le(t.grant)&&M(t.grant.grantId)&&M(t.grant.clientId)?t:void 0;case"http.cancel":return M(t.id)?t:void 0;case"pairing.code":return M(t.code)&&M(t.expiresAt)?t:void 0;case"grant.added":return Qe(t.grant)?t:void 0;case"grant.removed":return M(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:M(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return M(t.code)?t:void 0;default:return}}function Xt(e){let t="",r=0,s=0;for(let i of e){r=r<<8|i,s+=8;while(s>=5)s-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[r>>>s&31];r&=(1<<s)-1}if(s>0)t+="abcdefghijklmnopqrstuvwxyz234567"[r<<5-s&31];return t}async function Zt(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let r=await t.digest("SHA-256",new TextEncoder().encode(e));return Xt(new Uint8Array(r))}catch{return}}function Qt(e,t){if(t===void 0)return e;let r=new URL(e);return r.searchParams.set("a",t),r.href}var Lt=15000,et={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited",4009:"policy"},tt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var er=["content-type","cache-control"];function tr(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function rr(e){try{let t=JSON.parse(e);if(typeof t!=="object"||t===null||typeof t.type!=="string")return;return typeof t.id==="string"?{type:t.type,id:t.id}:{type:t.type}}catch{return}}var nr=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),nt=512,ot=6,st=64,or=nt+ot*st;function sr(e){let t=Math.floor((e-nt)/ot);return t>=st?t:void 0}function*rt(e,t){let r=0;while(r<e.length){let s=Math.min(r+t,e.length),i=e.charCodeAt(s-1);if(s<e.length&&i>=55296&&i<=56319)s+=s-1>r?-1:1;yield e.slice(r,s),r=s}}var ir=1e4,dr=1000;function ar(e){let t,r=Number.NEGATIVE_INFINITY,s;try{if(e!==void 0&&typeof BroadcastChannel==="function")t=new BroadcastChannel(e),t.onmessage=(i)=>{if(i.data?.type!=="claimed")return;r=Date.now(),s?.()}}catch{t=void 0}return{claimed(){try{t?.postMessage({type:"claimed"})}catch{}},heard(){if(Date.now()-r<=ir)return Promise.resolve(!0);if(t===void 0)return Promise.resolve(!1);return new Promise((i)=>{let d=setTimeout(()=>i(!1),dr);s=()=>{clearTimeout(d),i(!0)}})},close(){t?.close()}}}function Ar(e,t,r,s=!1){let i=new WebSocket(t,ke),d=new Map,o="opening",u,x=65536,O,v=0,B=ar(e.tabs),D,V,C,G=new Promise((n,h)=>{V=n,C=h});G.catch(()=>{});let W=setTimeout(()=>{g(de("The relay did not answer in time.","network"))},Lt),Q=Ze({tools:e.registry,server:{...e.server,icons:e.server.icons??Ne()},confirm:(n)=>e.confirm(n),client:(n)=>e.clientFor(n),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}),L=e.registry.onChange(()=>Q.toolsChanged());function A(n){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(n)),!0}catch{return!1}}function l(){if(v<=0)return;clearTimeout(O),O=setTimeout(()=>{u??="heartbeat",R(4003);try{i.close()}catch{}},v*2.5)}function g(n){if(o!=="opening")return;R(0),C(n);try{i.close()}catch{}}function R(n){if(o==="closed")return;let h=o==="ready";o="closed",clearTimeout(W),clearTimeout(O),L();for(let p of d.values())p.abort();if(d.clear(),Q.close(),h){let p=u??et[n]??(n===1006?"network":"closed");if(C(de("The address was taken over again before its AI apps were disconnected.",p)),e.closed(p,n),p==="replaced"){B.heard().then((S)=>{B.close(),e.replaced({sibling:S})});return}}B.close()}async function T(n){let h=new AbortController;d.set(n.id,h);let p=()=>o==="ready"&&d.get(n.id)===h&&!h.signal.aborted;try{let S=new Request(`https://tab.invalid${n.path}`,{method:n.method,headers:n.headers,signal:h.signal}),_=await Q.handle(S,{grant:n.grant,body:n.body});if(!p()){await _.body?.cancel().catch(()=>{});return}let N={};for(let j of er){let H=_.headers.get(j);if(H!==null)N[j]=H}if(!(N["content-type"]??"").startsWith("text/event-stream")||_.body===null){let j=await _.text();if(!p())return;if(j.length<=x){A({type:"http.response",id:n.id,status:_.status,headers:N,body:j});return}A({type:"http.response.start",id:n.id,status:_.status,headers:N});for(let H of rt(j,x)){if(!p())break;A({type:"http.response.chunk",id:n.id,data:H})}if(p())A({type:"http.response.end",id:n.id});return}A({type:"http.response.start",id:n.id,status:_.status,headers:N});let K=_.body.getReader(),z=new TextDecoder;h.signal.addEventListener("abort",()=>{K.cancel().catch(()=>{})});for(;;){let{done:j,value:H}=await K.read();if(j||!p())break;let fe=z.decode(H,{stream:!0});for(let re of rt(fe,x))A({type:"http.response.chunk",id:n.id,data:re})}if(p())A({type:"http.response.end",id:n.id})}catch(S){if(p())e.error(S instanceof Error?S:Error(String(S))),A({type:"http.response",id:n.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(d.get(n.id)===h)d.delete(n.id)}}function y(n){if(o==="opening"){if(n.type==="session"){let h=sr(n.limits.maxMessageBytes);if(h===void 0){g(de(`The relay's message limit (${n.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${or}.`,"policy"));return}x=h,o="ready",clearTimeout(W),v=n.limits.heartbeatMs,l(),B.claimed();let p=e.sessionStarted(n);if(s&&n.grants.length>0){D={left:new Set(n.grants.map((S)=>S.grantId)),session:p},A({type:"grants.revokeAll"});return}V(p)}else if(n.type==="error")g(de(`The relay refused the connection: ${n.message||n.code}`,n.code==="rate_limited"?"rate_limited":"policy"));else if(n.type==="bye")g(de(`The relay ended the connection: ${n.reason}`,tt[n.reason]??"closed"));return}if(o!=="ready")return;switch(n.type){case"ping":l(),A({type:"pong",t:n.t});return;case"http.request":T(n);return;case"http.cancel":d.get(n.id)?.abort(),d.delete(n.id);return;case"pairing.code":e.pairingCode({code:n.code,expiresAt:n.expiresAt});return;case"grant.added":e.grantAdded(n.grant);return;case"grant.removed":if(e.grantRemoved(n.grantId),D?.left.delete(n.grantId),D?.left.size===0)V(D.session);return;case"identity.bound":e.identityResult(!0,n.round);return;case"bye":if(u=tt[n.reason]??"closed",u==="replaced")R(4005);return;case"error":if(n.code==="identity_refused"){e.identityResult(!1,typeof n.round==="number"?n.round:void 0,n.message);return}e.error(Error(`Relay error ${n.code}: ${n.message}`));return;case"session":return}}return i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==ke){g(de(`The relay speaks ${i.protocol}, not ${ke}.`,"policy"));return}let n={type:"hello",library:e.library,page:{title:tr()},secret:r};if(e.appName!==void 0)n.app={name:e.appName};if(s)n.revokeAll=!0;A(n)}),i.addEventListener("message",(n)=>{if(typeof n.data!=="string")return;let h=Le(n.data);if(h!==void 0){if(o==="ready")l();y(h);return}let p=rr(n.data);if(p?.id!==void 0)A(nr.has(p.type)?{type:"error",code:"bad_message",message:`malformed ${p.type}`,id:p.id}:{type:"error",code:"unknown_type",message:`unknown type ${p.type}`,id:p.id})}),i.addEventListener("close",(n)=>{if(o==="opening"){R(n.code);let h=n.code===1006||n.code===1002;C(de(h?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${n.code}${n.reason?`: ${n.reason}`:""}).`,et[n.code]??(h?"network":"closed")));return}R(n.code)}),{ready:G,send:A,close(n){if(o==="closed")return;if(o==="opening"){g(new DOMException("The connection was cancelled","AbortError"));return}u=n,A({type:"bye",reason:"user"}),R(1000);try{i.close(1000,"bye")}catch{}}}}export{Zt as addressIdOf,Bt as compileRegistry,Ar as openConnection,Qt as withAddress};
|
|
9
|
-
|
|
10
|
-
//# debugId=0B1EE263FE9616FD64756E2164756E21
|
|
11
|
-
//# sourceMappingURL=connection-0x5mr3te.min.js.map
|