@ractive-ch/tab-mcp-client 0.9.1 → 0.11.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 +86 -19
- package/THIRD-PARTY-NOTICES.txt +1 -1
- package/cdn/connection-8zhj84k2.min.js +11 -0
- package/cdn/connection-8zhj84k2.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-0wa4gyh3.min.js +86 -0
- package/cdn/ui-0wa4gyh3.min.js.map +11 -0
- package/{connection-eqqkev02.js → connection-c0vttra5.js} +21 -5
- package/{connection-eqqkev02.js.map → connection-c0vttra5.js.map} +4 -4
- package/index.d.ts +1 -1
- package/index.js +6 -6
- package/index.js.map +4 -4
- package/package.json +2 -2
- package/protocol.d.ts +3 -1
- 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 +15 -3
- package/{ui-xjr9vzga.js → ui-50jse8y7.js} +207 -58
- package/ui-50jse8y7.js.map +11 -0
- package/ui.d.ts +17 -5
- 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-6cdy3wps.min.js +0 -75
- package/cdn/ui-6cdy3wps.min.js.map +0 -11
- package/connecting.md +0 -77
- package/ui-xjr9vzga.js.map +0 -11
|
@@ -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\tPairingCode,\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-success: var(--tab-mcp-success, light-dark(#1a7f37, #6fdd8b));\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, .tab-mcp-success-next) { 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-success { display: flex; align-items: center; gap: 0.875rem; padding: 1rem; background: color-mix(in srgb, var(--_tab-mcp-success) 10%, transparent); border: 1px solid color-mix(in srgb, var(--_tab-mcp-success) 45%, transparent); border-radius: var(--_tab-mcp-small-radius); }\n.tab-mcp-success-icon { flex: none; width: 2.75rem; height: 2.75rem; color: var(--_tab-mcp-success); }\n.tab-mcp-success-text { display: grid; gap: 0.125rem; min-width: 0; }\n.tab-mcp-success-title { font-size: 1.125em; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }\n.tab-mcp-setup { display: flex; flex-direction: column; gap: 1rem; }\n.tab-mcp-setup-toggle { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem 1rem; text-align: start; font-weight: 600; border-color: var(--_tab-mcp-line); }\n.tab-mcp-setup-toggle::before { content: \"\"; flex: none; width: 0.45em; height: 0.45em; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateX(-0.1em) rotate(-45deg); }\n.tab-mcp-setup-toggle:where([aria-expanded=\"true\"])::before { transform: translateY(-0.15em) rotate(45deg); }\n.tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }\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; } .tab-mcp-success-icon { animation: tab-mcp-pop 0.4s cubic-bezier(0.3, 1.4, 0.6, 1); } }\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@keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }\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/**\n * The labels of the apps behind these grants, each once: an app can hold\n * more than one grant (paired twice), and is still one app.\n */\nfunction appLabels(grants: readonly Grant[]): string[] {\n\treturn [...new Set(grants.map((g) => clientLabel(g.client)))];\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 * How long a used code stays \"Code used\" before its replacement is shown: the\n * AI app connects a moment after the code was entered (its token request), and\n * a new code in plain view meanwhile looks as if it did not work. Only when\n * the relay says the code was used (`reason: \"used\"`); a relay that does not\n * say why gets the new code shown at once.\n */\nexport const CODE_USED_WAIT_MS = 10_000;\n\nconst SVG = \"http://www.w3.org/2000/svg\";\n\n/** A check mark in a tinted disk, in the text colour (`currentColor`). */\nfunction checkIcon(doc: Document): SVGSVGElement {\n\tconst set = (node: Element, attributes: Record<string, string>) => {\n\t\tfor (const [key, value] of Object.entries(attributes))\n\t\t\tnode.setAttribute(key, value);\n\t};\n\tconst svg = doc.createElementNS(SVG, \"svg\");\n\tset(svg, {\n\t\tclass: \"tab-mcp-success-icon\",\n\t\tviewBox: \"0 0 48 48\",\n\t\twidth: \"44\",\n\t\theight: \"44\",\n\t\t\"aria-hidden\": \"true\",\n\t\tfocusable: \"false\",\n\t});\n\tconst disk = doc.createElementNS(SVG, \"circle\");\n\tset(disk, {\n\t\tcx: \"24\",\n\t\tcy: \"24\",\n\t\tr: \"24\",\n\t\tfill: \"currentColor\",\n\t\t\"fill-opacity\": \"0.16\",\n\t});\n\tconst check = doc.createElementNS(SVG, \"path\");\n\tset(check, {\n\t\td: \"M14 24.5l7 7 13-14\",\n\t\tfill: \"none\",\n\t\tstroke: \"currentColor\",\n\t\t\"stroke-width\": \"4\",\n\t\t\"stroke-linecap\": \"round\",\n\t\t\"stroke-linejoin\": \"round\",\n\t});\n\tsvg.append(disk, check);\n\treturn svg;\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 * is connected, only a small Close (and Escape) close it. Once one is (it\n * pairs here, or was paired when the dialog opened), a confirmation with a\n * check mark leads, the setup moves behind \"Connect another app\" and Done is\n * the primary button. New address asks first when it would disconnect\n * connected apps (`newAddress()` revokes them). When the page loses its\n * address (`replaced`), this dialog closes and `replacedNotice` says why,\n * from then on also while it is closed. Its nodes are built once and shown or\n * hidden, not rebuilt on a change, so nothing flickers and focus stays.\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} ` : text;\n\t};\n\n\t// The confirmation once an app is connected: what happened, what next.\n\tconst successId = `tab-mcp-${++counter}-success`;\n\tconst successTitle = el(doc, \"p\", { className: \"tab-mcp-success-title\" });\n\tconst successNext = el(doc, \"p\", { className: \"tab-mcp-success-next\" });\n\tconst success = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-success\", id: successId },\n\t\tcheckIcon(doc),\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-success-text\" },\n\t\t\tsuccessTitle,\n\t\t\tsuccessNext,\n\t\t),\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, until an\n\t// app is connected (then Done is).\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\t// In the code's place while the AI app finishes connecting with it.\n\tconst codeUsed = el(doc, \"span\", { className: \"tab-mcp-code-used\" });\n\tcodeUsed.hidden = true;\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\tcodeUsed,\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\t// Everything for adding the page to an AI app. Once one is connected, it\n\t// is behind \"Connect another app\", closed: the next code is not news.\n\tconst setupId = `tab-mcp-${++counter}-setup`;\n\tconst setup = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-setup\", id: setupId },\n\t\taddressBox,\n\t\tconfirmBox,\n\t\tcodeLine,\n\t\tsignInLine,\n\t\thelp,\n\t);\n\t// Whether the user opened it while an app is connected.\n\tlet expanded = false;\n\tconst setupToggle = button(\n\t\tdoc,\n\t\t\"Connect another app\",\n\t\t() => {\n\t\t\texpanded = !expanded;\n\t\t\trenderView(false);\n\t\t},\n\t\t\"tab-mcp-setup-toggle\",\n\t);\n\tsetupToggle.setAttribute(\"aria-controls\", setupId);\n\n\tconst appList = el(doc, \"ul\");\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\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\tappsNote,\n\t);\n\n\t// Until an app is connected, closing it is not the next step: a small\n\t// Close at the end, saying what closing does (the code stops, the address\n\t// stays). Once one is, 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\n\tdialog.append(success, status, apps, setupToggle, setup, actions, live);\n\tsuccess.hidden = true;\n\tsetupToggle.hidden = true;\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// Grants of apps that connected while this dialog is open (since the last\n\t// new address), and are still connected: the confirmation names them.\n\tconst pairedGrants = new Set<string>();\n\t// Whether the dialog shows the connected state: an app is connected.\n\tlet connectedView = false;\n\t// Whether a code is shown (or \"Code used\" in its place).\n\tlet codeShown = false;\n\t// The visible button that closes the dialog.\n\tconst closer = () => (connectedView ? done : close);\n\t// Where focus starts: Done once connected, else the address's Copy.\n\tconst start = () => (connectedView ? done : copy);\n\t/** Whether focus was on a control that is no longer shown, or no longer there. */\n\tconst focusLost = (focused: Element | null): boolean =>\n\t\tfocused !== null &&\n\t\tfocused !== dialog &&\n\t\tfocused !== doc.body &&\n\t\t(!focused.isConnected ||\n\t\t\t(dialog.contains(focused) && focused.closest(\"[hidden]\") !== null));\n\t/**\n\t * Shows the setup or the connected state. `paired`: an app just connected\n\t * here, so the setup closes again (unless the New address question is\n\t * open in it) and the confirmation is announced.\n\t */\n\tconst renderView = (paired: boolean, focused = doc.activeElement) => {\n\t\tconnectedView =\n\t\t\t!renewing && mcp.state === \"connected\" && mcp.grants.length > 0;\n\t\tif (paired && confirmBox.hidden) expanded = false;\n\t\tif (connectedView) {\n\t\t\tconst here = mcp.grants.filter((g) => pairedGrants.has(g.grantId));\n\t\t\tconst names = appLabels(here.length > 0 ? here : mcp.grants);\n\t\t\tconst one = names.length === 1;\n\t\t\tsuccessTitle.textContent = `${listOf(names)} ${one ? \"is\" : \"are\"} connected`;\n\t\t\tsuccessNext.textContent = `You can close this now and ask ${one ? \"it\" : \"them\"} to use the tools of this page.`;\n\t\t\tdialog.setAttribute(\"aria-describedby\", successId);\n\t\t} else dialog.removeAttribute(\"aria-describedby\");\n\t\tsuccess.hidden = !connectedView;\n\t\t// The confirmation says it; the status line is for the setup.\n\t\tstatus.hidden = connectedView;\n\t\tsetupToggle.hidden = !connectedView;\n\t\tsetupToggle.setAttribute(\"aria-expanded\", String(expanded));\n\t\tsetup.hidden = connectedView && !expanded;\n\t\tcopy.classList.toggle(\"tab-mcp-primary\", !connectedView);\n\t\t// The note is about the code: only while one is shown and none connected.\n\t\tcloseNote.hidden = connectedView || !codeShown;\n\t\tclose.hidden = connectedView;\n\t\tdone.hidden = !connectedView;\n\t\t// Focus never stays on a control that was just hidden or removed.\n\t\tif (focusLost(focused)) closer().focus();\n\t\tif (paired && connectedView)\n\t\t\tannounce(`${successTitle.textContent}. ${successNext.textContent}`);\n\t};\n\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = appLabels(mcp.grants);\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\tpairedGrants.clear();\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\trenderView(false);\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\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\trenderView(false);\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\trenderView(false);\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\t// The address the help's commands were made for.\n\tlet stepsFor: string | undefined;\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\trenderView(false);\n\t\t\treturn;\n\t\t}\n\t\t// The same address again (a reconnect): it stays as it is.\n\t\tif (address.value !== session.address) {\n\t\t\taddress.value = session.address;\n\t\t\tresetCopy();\n\t\t}\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\trenderView(false);\n\t\t// Opened before the session was known: start at Done or the address's Copy.\n\t\tif (doc.activeElement === dialog) start().focus();\n\t\tif (stepsFor === session.address) return;\n\t\tstepsFor = session.address;\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\n\t// The code shown, and the wait after it was used (until the app connects).\n\tlet shownCode: PairingCode | undefined;\n\tlet usedTimer: ReturnType<typeof setTimeout> | undefined;\n\tconst stopWaiting = () => {\n\t\tclearTimeout(usedTimer);\n\t\tusedTimer = undefined;\n\t};\n\t// The wait is over (the app connected, or none did): the next code shows.\n\tconst endWait = () => {\n\t\tstopWaiting();\n\t\tshownCode = mcp.pairingCode;\n\t\trenderCode();\n\t};\n\tconst renderCode = () => {\n\t\tconst focused = doc.activeElement;\n\t\tconst current = mcp.pairingCode;\n\t\tconst oidc = mcp.session?.pairing === \"oidc\";\n\t\tif (current === undefined) stopWaiting();\n\t\telse if (current.code !== shownCode?.code) {\n\t\t\tif (current.reason === \"used\") {\n\t\t\t\t// Entered just now: no new code in plain view while the AI app\n\t\t\t\t// connects; it shows if none does.\n\t\t\t\tif (usedTimer === undefined) {\n\t\t\t\t\tusedTimer = setTimeout(endWait, CODE_USED_WAIT_MS);\n\t\t\t\t\tannounce(\"Code used. Waiting for your AI app…\");\n\t\t\t\t}\n\t\t\t} else if (usedTimer !== undefined) {\n\t\t\t\t// Locked or expired meanwhile: the user needs this one now.\n\t\t\t\tstopWaiting();\n\t\t\t}\n\t\t}\n\t\tconst used = usedTimer !== undefined;\n\t\tif (!used) {\n\t\t\t// A new code is not copied yet.\n\t\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\t\tcode.textContent = current?.code ?? \"\";\n\t\t\tshownCode = current;\n\t\t}\n\t\tcodeSentence.hidden = used;\n\t\tcopyCode.hidden = used;\n\t\tcodeUsed.hidden = !used;\n\t\tcodeUsed.textContent = used ? \"Code used. Waiting for your AI app…\" : \"\";\n\t\tcodeLine.hidden = oidc || current === undefined;\n\t\tsignInLine.hidden = !oidc;\n\t\tcodeShown = !codeLine.hidden;\n\t\tcloseNote.hidden = connectedView || !codeShown;\n\t\t// The code's Copy had the focus: to the button that closes.\n\t\tif (focusLost(focused)) closer().focus();\n\t};\n\n\t// One item per grant, kept while the grant is: a change adds or removes\n\t// items, and a focused Disconnect keeps its focus.\n\tconst items = new Map<\n\t\tstring,\n\t\t{ item: HTMLLIElement; disconnect: HTMLButtonElement }\n\t>();\n\tconst appItem = (grant: Grant) => {\n\t\tconst disconnect = button(\n\t\t\tdoc,\n\t\t\t\"Disconnect\",\n\t\t\t() => {\n\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t},\n\t\t\t\"tab-mcp-disconnect\",\n\t\t\t\"danger\",\n\t\t);\n\t\tconst item = el(\n\t\t\tdoc,\n\t\t\t\"li\",\n\t\t\t{},\n\t\t\tel(doc, \"span\", {\n\t\t\t\tclassName: \"tab-mcp-app\",\n\t\t\t\ttext: `${clientLabel(grant.client)} connected `,\n\t\t\t}),\n\t\t\tdisconnect,\n\t\t);\n\t\treturn { item, disconnect };\n\t};\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\tlet paired = false;\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\tpaired = true;\n\t\t}\n\t\tconst ids = new Set(mcp.grants.map((g) => g.grantId));\n\t\tfor (const id of pairedGrants) if (!ids.has(id)) pairedGrants.delete(id);\n\t\t// Read before an item goes: a removed Disconnect may have had it.\n\t\tconst focused = doc.activeElement;\n\t\tfor (const [id, { item }] of items) {\n\t\t\tif (ids.has(id)) continue;\n\t\t\titem.remove();\n\t\t\titems.delete(id);\n\t\t}\n\t\t// Only the relay can revoke, so only while connected.\n\t\tconst connected = mcp.state === \"connected\";\n\t\tmcp.grants.forEach((grant, i) => {\n\t\t\tlet entry = items.get(grant.grantId);\n\t\t\tif (entry === undefined) {\n\t\t\t\tentry = appItem(grant);\n\t\t\t\titems.set(grant.grantId, entry);\n\t\t\t}\n\t\t\tentry.disconnect.disabled = !connected;\n\t\t\tif (appList.children[i] !== entry.item)\n\t\t\t\tappList.insertBefore(entry.item, appList.children[i] ?? null);\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\t// It connected: no \"Code used\" any more, the next code is ready.\n\t\tif (paired && usedTimer !== undefined) endWait();\n\t\t// Focus went to the body with a removed item: it was there.\n\t\tconst now = doc.activeElement;\n\t\trenderView(paired, now === null || now === doc.body ? focused : now);\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\tstopWaiting();\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 Done once connected, else at the address's Copy; until the\n\t\t// address is there, at the dialog itself (its title is read out), not\n\t\t// at Close.\n\t\tif (connectedView || !addressBox.hidden) start().focus();\n\t\telse dialog.focus();\n\t});\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": "AAMO,MAAM,EAAc,CACjB,GAAS,IAAI,IAEtB,GAAG,CAAC,EAAiB,EAAuB,CAC3C,OAAO,KAAK,GAAO,IAAI,CAAO,GAAG,IAAI,CAAI,IAAM,GAGhD,GAAG,CAAC,EAAiB,EAAoB,CACxC,IAAM,EAAQ,KAAK,GAAO,IAAI,CAAO,GAAK,IAAI,IAC9C,EAAM,IAAI,CAAI,EACd,KAAK,GAAO,IAAI,EAAS,CAAK,EAI/B,UAAU,CAAC,EAAkC,CAC5C,IAAM,EAAO,IAAI,IAAI,CAAQ,EAC7B,QAAW,KAAW,KAAK,GAAO,KAAK,EACtC,GAAI,CAAC,EAAK,IAAI,CAAO,EAAG,KAAK,GAAO,OAAO,CAAO,EAKpD,SAAS,CAAC,EAA+B,CACxC,IAAM,EAAO,IAAI,IAAI,CAAK,EAC1B,QAAW,KAAS,KAAK,GAAO,OAAO,EACtC,QAAW,KAAQ,EAAO,GAAI,CAAC,EAAK,IAAI,CAAI,EAAG,EAAM,OAAO,CAAI,EAGnE,CCdA,IAAI,EAAU,EAEd,SAAS,CAAyC,CACjD,EACA,EACA,EAA4D,CAAC,KAC1D,EACwB,CAC3B,IAAM,EAAO,EAAI,cAAc,CAAG,EAClC,GAAI,EAAM,YAAc,OAAW,EAAK,UAAY,EAAM,UAC1D,GAAI,EAAM,KAAO,OAAW,EAAK,GAAK,EAAM,GAC5C,GAAI,EAAM,OAAS,OAAW,EAAK,YAAc,EAAM,KAEvD,OADA,EAAK,OAAO,GAAG,CAAQ,EAChB,EAQR,SAAS,CAAM,CACd,EACA,EACA,EACA,EACA,EACoB,CACpB,IAAM,EAAO,EAAG,EAAK,SAAU,CAAE,MAAK,CAAC,EAEvC,GADA,EAAK,KAAO,SACR,IAAc,OAAW,EAAK,UAAU,IAAI,CAA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,GAAc,EAAK,CAAG,EACtB,EAAI,iBAAiB,cAAe,CAAU,EAC9C,EAAI,iBAAiB,eAAgB,CAAY,EACjD,EAAI,iBAAiB,YAAa,EAAW,EAC7C,EAAI,iBAAiB,eAAgB,EAAc,EACnD,EAAI,iBAAiB,WAAY,EAAU,EAC3C,EAAI,KAAK,OAAO,CAAM,EACtB,EAAI,aAAa,EACjB,EAAa,EACb,EAAW,EACX,EAAc,EAAI,OAAO,EACzB,EAAW,KACV,CAAC,IAAY,EAAc,CAAO,EAClC,CAAC,IAAmB,CACnB,EAAO,YAAc,sBAAsB,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,IAElG,EAEO,IAAI,QAAQ,CAAC,IAAY,CAoB/B,GAnBA,EAAO,iBACN,QACA,IAAM,CACL,GAAY,EACZ,EAAI,YAAY,EAChB,EAAI,oBAAoB,cAAe,CAAU,EACjD,EAAI,oBAAoB,eAAgB,CAAY,EACpD,EAAI,oBAAoB,YAAa,EAAW,EAChD,EAAI,oBAAoB,eAAgB,EAAc,EACtD,EAAI,oBAAoB,WAAY,EAAU,EAC9C,EAAO,OAAO,EACd,EAAQ,GAET,CAAE,KAAM,EAAK,CACd,EACA,EAAO,UAAU,EAIb,GAAiB,CAAC,EAAW,OAAQ,GAAM,EAAE,MAAM,EACvD,KAAK,EAAO,MAAM,EAClB",
|
|
9
|
+
"debugId": "0E9614E5BB974C0864756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -628,6 +628,7 @@ function createMcpHandler(options) {
|
|
|
628
628
|
|
|
629
629
|
// src/protocol.ts
|
|
630
630
|
var SUBPROTOCOL = "tab-mcp.v1";
|
|
631
|
+
var CODE_REASONS = new Set(["start", "used", "locked", "expired"]);
|
|
631
632
|
function isObject2(v) {
|
|
632
633
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
633
634
|
}
|
|
@@ -674,8 +675,19 @@ function parseRelayMessage(text) {
|
|
|
674
675
|
return str(v["id"]) && str(v["method"]) && str(v["path"]) && isStringRecord(v["headers"]) && str(v["body"]) && isObject2(v["grant"]) && str(v["grant"]["grantId"]) && str(v["grant"]["clientId"]) ? v : undefined;
|
|
675
676
|
case "http.cancel":
|
|
676
677
|
return str(v["id"]) ? v : undefined;
|
|
677
|
-
case "pairing.code":
|
|
678
|
-
|
|
678
|
+
case "pairing.code": {
|
|
679
|
+
if (!str(v["code"]) || !str(v["expiresAt"]))
|
|
680
|
+
return;
|
|
681
|
+
const message = {
|
|
682
|
+
type: "pairing.code",
|
|
683
|
+
code: v["code"],
|
|
684
|
+
expiresAt: v["expiresAt"]
|
|
685
|
+
};
|
|
686
|
+
const reason = v["reason"];
|
|
687
|
+
if (typeof reason === "string" && CODE_REASONS.has(reason))
|
|
688
|
+
message.reason = reason;
|
|
689
|
+
return message;
|
|
690
|
+
}
|
|
679
691
|
case "grant.added":
|
|
680
692
|
return isGrant(v["grant"]) ? v : undefined;
|
|
681
693
|
case "grant.removed":
|
|
@@ -1073,7 +1085,11 @@ function openConnection(host, url, secret, revokeAll = false) {
|
|
|
1073
1085
|
inflight.delete(message.id);
|
|
1074
1086
|
return;
|
|
1075
1087
|
case "pairing.code":
|
|
1076
|
-
host.pairingCode({ code: message.code, expiresAt: message.expiresAt }
|
|
1088
|
+
host.pairingCode(message.reason === undefined ? { code: message.code, expiresAt: message.expiresAt } : {
|
|
1089
|
+
code: message.code,
|
|
1090
|
+
expiresAt: message.expiresAt,
|
|
1091
|
+
reason: message.reason
|
|
1092
|
+
});
|
|
1077
1093
|
return;
|
|
1078
1094
|
case "grant.added":
|
|
1079
1095
|
host.grantAdded(message.grant);
|
|
@@ -1180,5 +1196,5 @@ export {
|
|
|
1180
1196
|
withAddress
|
|
1181
1197
|
};
|
|
1182
1198
|
|
|
1183
|
-
//# debugId=
|
|
1184
|
-
//# sourceMappingURL=connection-
|
|
1199
|
+
//# debugId=5DA3B6EF0C625FEB64756E2164756E21
|
|
1200
|
+
//# sourceMappingURL=connection-c0vttra5.js.map
|