@ractive-ch/tab-mcp-client 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +538 -126
- package/always-allowed.d.ts +25 -6
- package/cdn/confirm-y30cx7e1.min.js +4 -0
- package/cdn/confirm-y30cx7e1.min.js.map +10 -0
- package/cdn/connect-bbhj2y7w.min.js +6 -0
- package/cdn/connect-bbhj2y7w.min.js.map +12 -0
- package/cdn/connection-0y7ngtq7.min.js +17 -0
- package/cdn/connection-0y7ngtq7.min.js.map +22 -0
- package/cdn/index-vt5zk9me.min.js +91 -0
- package/cdn/index-vt5zk9me.min.js.map +13 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +6 -6
- package/confirm-fgnjgd08.js +263 -0
- package/confirm-fgnjgd08.js.map +10 -0
- package/confirm.d.ts +54 -0
- package/connect-8jpb0k29.js +484 -0
- package/connect-8jpb0k29.js.map +10 -0
- package/connect.d.ts +40 -0
- package/{connection-eqsag07j.js → connection-1d8rxgbq.js} +515 -242
- package/connection-1d8rxgbq.js.map +16 -0
- package/connection.d.ts +9 -9
- package/dialog.d.ts +83 -0
- package/{index-nmn1j689.js → index-5jyqehpk.js} +14 -10
- package/index-5jyqehpk.js.map +11 -0
- package/index-jnz7w9xa.js +392 -0
- package/index-jnz7w9xa.js.map +12 -0
- package/index.d.ts +1 -1
- package/index.js +285 -244
- package/index.js.map +6 -6
- package/mapping.d.ts +37 -4
- package/mcp.d.ts +23 -8
- package/package.json +5 -1
- package/react.d.ts +13 -12
- package/react.js +20 -14
- package/react.js.map +3 -3
- package/registry.d.ts +12 -5
- package/secret.d.ts +5 -2
- package/serve.d.ts +68 -0
- package/setup.d.ts +15 -25
- package/setup.js +1 -1
- package/strings.d.ts +107 -0
- package/tab-mcp.d.ts +76 -36
- package/tunnel.d.ts +74 -0
- package/tunnel.js +263 -0
- package/tunnel.js.map +10 -0
- package/types.d.ts +206 -73
- package/webmcp.d.ts +13 -18
- package/cdn/connection-dweyrdbn.min.js +0 -12
- package/cdn/connection-dweyrdbn.min.js.map +0 -21
- package/cdn/ui-5zecjy7s.min.js +0 -86
- package/cdn/ui-5zecjy7s.min.js.map +0 -14
- package/connection-eqsag07j.js.map +0 -15
- package/index-nmn1j689.js.map +0 -11
- package/ui-4qv8d1a3.js +0 -781
- package/ui-4qv8d1a3.js.map +0 -11
- package/ui.d.ts +0 -83
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/confirm.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The confirmation of consequential tools, loaded on demand: a `<dialog>`\n * per call, one shown at a time per document, and the tools a user allowed\n * until reload (`always-allowed.ts`).\n */\n\nimport { allowedFor } from \"./always-allowed.ts\";\nimport {\n\tbutton,\n\tclientLabel,\n\tel,\n\tfill,\n\tformat,\n\tnewDialog,\n\tstringsOf,\n\tvisible,\n} from \"./dialog.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type { ConfirmRequest, DialogOptions } from \"./types.ts\";\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/**\n * How long \"Allow\" stays disabled after the confirmation is shown, while the\n * page is visible and focused (CU 17: a constant; tests pass `allowDelayMs`).\n */\nexport const ALLOW_DELAY_MS = 750;\n\n/** The user's answer: \"always\" allows this tool for this AI app until reload. */\nexport type DialogAnswer = \"allow\" | \"always\" | \"deny\";\n\n/** Arguments up to this many characters are read out with the question. */\nconst DESCRIBED_ARGUMENTS = 500;\n\n/** Options of `confirmDialog`. */\nexport interface ConfirmDialogOptions {\n\t/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */\n\tallowDelayMs?: number | undefined;\n\t/** Offer \"Allow until reload\". */\n\talwaysAllow?: boolean | undefined;\n\t/** Asked when a waiting call's turn comes: `true` answers \"allow\" unseen. */\n\tallowedNow?: () => boolean;\n\tstrings?: DialogStrings;\n}\n\n/**\n * The confirmations of one document: one is shown at a time, the others\n * wait in order, so that the click that answered one cannot answer the next\n * (each starts its own delay when it is shown).\n */\ninterface ConfirmQueue {\n\tshown: boolean;\n\twaiting: (() => void)[];\n\t/** Updates the shown dialog's line about the calls that wait. */\n\tchanged?: (() => void) | undefined;\n}\n\nconst queues = new WeakMap<Document, ConfirmQueue>();\n\n/**\n * Ask whether a consequential tool may run. \"Allow until reload\" is offered\n * only with `alwaysAllow` (DEC-096). One confirmation is shown at a time per\n * document; the others wait their turn, and a call cancelled while it waits\n * is never shown. \"Allow\" and \"Allow until reload\" stay disabled until the\n * page has been visible and focused for 750 ms while the dialog is open and\n * is the top one, so a click meant for the page, the click that brings the\n * tab or window back, or the one that closed another dialog, cannot\n * approve; leaving the page disables them again. They also wait until the\n * arguments have been scrolled to their end. Before the delay has run out,\n * Enter or Space on a button and Escape are ignored, so typing meant for the\n * page cannot refuse either. Everything else (Don't allow, Escape, an\n * aborted call) is \"deny\". `allowedNow` is asked when a waiting call's turn\n * comes: `true` (the user allowed it until reload meanwhile) answers \"allow\"\n * without showing it.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions = {},\n): Promise<DialogAnswer> {\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tlet queue = queues.get(doc);\n\tif (queue === undefined) {\n\t\tqueue = { shown: false, waiting: [] };\n\t\tqueues.set(doc, queue);\n\t}\n\tconst q = queue;\n\t/** The shown confirmation closed: the next one, if any. */\n\tconst next = () => {\n\t\tconst start = q.waiting.shift();\n\t\tq.shown = start !== undefined;\n\t\tstart?.();\n\t\tq.changed?.();\n\t};\n\tconst show = () => {\n\t\ttry {\n\t\t\treturn showConfirm(request, doc, options, q, next);\n\t\t} catch (error) {\n\t\t\tnext(); // not shown: the queue goes on\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t};\n\tif (!q.shown) {\n\t\tq.shown = true;\n\t\treturn show();\n\t}\n\treturn new Promise((resolve) => {\n\t\tconst start = () => {\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tif (options.allowedNow?.() === true) {\n\t\t\t\tresolve(\"allow\");\n\t\t\t\tnext();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(show());\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tq.waiting.splice(q.waiting.indexOf(start), 1);\n\t\t\tq.changed?.();\n\t\t\tresolve(\"deny\");\n\t\t};\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tq.waiting.push(start);\n\t\tq.changed?.();\n\t});\n}\n\n/** `confirmDialog` once it is this request's turn; calls `next` when it closes. */\nfunction showConfirm(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions,\n\tqueue: ConfirmQueue,\n\tnext: () => void,\n): Promise<DialogAnswer> {\n\tconst s = options.strings ?? stringsOf(undefined);\n\tconst delay = options.allowDelayMs ?? ALLOW_DELAY_MS;\n\tconst tool = request.tool.title ?? request.tool.name;\n\tconst client = clientLabel(request.client, s);\n\tconst names = { tool, client };\n\tconst { dialog, id } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-confirm\",\n\t\ts,\n\t\t...fill(doc, s.confirmTitle, names),\n\t);\n\tconst waiting = el(doc, \"p\", { className: \"tab-mcp-waiting\" });\n\tconst showWaiting = () => {\n\t\tconst n = queue.waiting.length;\n\t\twaiting.hidden = n === 0;\n\t\twaiting.textContent =\n\t\t\tn === 1 ? s.waitingOne : format(s.waitingMany, { n: String(n) });\n\t};\n\tqueue.changed = showWaiting;\n\tshowWaiting();\n\t// The safe choice is the default: focused, and the one that stands out.\n\tconst deny = button(\n\t\tdoc,\n\t\ts.deny,\n\t\t() => dialog.close(\"deny\"),\n\t\t\"tab-mcp-deny\",\n\t\t\"primary\",\n\t);\n\tconst approving = (text: string, answer: DialogAnswer, className: string) => {\n\t\tconst node = button(\n\t\t\tdoc,\n\t\t\ttext,\n\t\t\t() => {\n\t\t\t\tif (!node.disabled) dialog.close(answer);\n\t\t\t},\n\t\t\tclassName,\n\t\t);\n\t\treturn node;\n\t};\n\t// The approving buttons: Allow, and Allow until reload when the page offers it.\n\tconst approve = [approving(s.allow, \"allow\", \"tab-mcp-allow\")];\n\tconst extra: HTMLElement[] = [];\n\tif (options.alwaysAllow === true) {\n\t\t// Left of Allow: not where most platforms put the default (CU 11).\n\t\tapprove.unshift(approving(s.allowUntilReload, \"always\", \"tab-mcp-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...fill(doc, s.allowUntilReloadNote, names),\n\t\t\t),\n\t\t);\n\t}\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t...approve.flatMap((b) => [\" \", b]),\n\t);\n\t// Approving needs both: the delay ran out while the user saw the page\n\t// (`settled`), and the arguments were seen to their end (`seen`).\n\tlet settled = false;\n\tlet seen = false;\n\tconst enable = () => {\n\t\tfor (const b of approve) b.disabled = !(settled && seen);\n\t};\n\tenable();\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\tid: `${id}-arguments`,\n\t\ttext: shown ?? s.argumentsHidden,\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, min(50vh, 24rem))\",\n\t);\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\t// The caller chooses the order of the keys, so what matters may come\n\t// last: below the end of the box, the user is told, and Allow waits.\n\tconst scrollNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-scroll-note\",\n\t\ttext: s.scrollToAllow,\n\t});\n\tscrollNote.hidden = true;\n\tconst who = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ id: `${id}-who` },\n\t\t...fill(doc, s.confirmWho, names),\n\t);\n\tdialog.setAttribute(\n\t\t\"aria-describedby\",\n\t\tshown !== undefined && !args.hidden && shown.length <= DESCRIBED_ARGUMENTS\n\t\t\t? `${who.id} ${args.id}`\n\t\t\t: who.id,\n\t);\n\tdialog.append(\n\t\twho,\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\tscrollNote,\n\t\tactions,\n\t\t...extra,\n\t\twaiting,\n\t);\n\tdoc.body.append(dialog);\n\tconst view = doc.defaultView;\n\treturn new Promise((resolve, reject) => {\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// In a hidden tab, the tab's title says that the page asks (CU 9): the\n\t\t// AI app waits meanwhile. Put back when the tab is shown or the dialog\n\t\t// closes, unless the page changed its title since.\n\t\tlet title: { page: string; shown: string } | undefined;\n\t\tconst untitle = () => {\n\t\t\tif (title !== undefined && doc.title === title.shown)\n\t\t\t\tdoc.title = title.page;\n\t\t\ttitle = undefined;\n\t\t};\n\t\tconst retitle = () => {\n\t\t\tif (doc.visibilityState !== \"hidden\") untitle();\n\t\t\telse if (title === undefined) {\n\t\t\t\ttitle = { page: doc.title, shown: `${s.titlePrefix}${doc.title}` };\n\t\t\t\tdoc.title = title.shown;\n\t\t\t}\n\t\t};\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\n\t\t// (DEC-087), and so does another dialog of the page that closes over\n\t\t// this one.\n\t\tconst arm = (event?: Event) => {\n\t\t\tif (event?.type === \"close\" && event.target === dialog) return;\n\t\t\tretitle();\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t\tsettled = false;\n\t\t\tenable();\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(() => {\n\t\t\t\tsettled = true;\n\t\t\t\tenable();\n\t\t\t}, delay);\n\t\t};\n\t\t// Scrolled to the end, or nothing to scroll (also without layout).\n\t\tconst check = () => {\n\t\t\tif (seen) return;\n\t\t\tif (args.scrollTop + args.clientHeight < args.scrollHeight - 2) {\n\t\t\t\tscrollNote.hidden = false;\n\t\t\t\targs.tabIndex = 0; // to scroll it with the keyboard\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tseen = true;\n\t\t\tscrollNote.hidden = true;\n\t\t\tenable();\n\t\t};\n\t\t// Not answered by a key before the delay has run out.\n\t\tconst guard = (event: KeyboardEvent) => {\n\t\t\tif (settled) return;\n\t\t\tconst onButton = (event.target as Element | null)?.localName === \"button\";\n\t\t\tif (\n\t\t\t\tevent.key === \"Escape\" ||\n\t\t\t\t(onButton && (event.key === \"Enter\" || event.key === \" \"))\n\t\t\t)\n\t\t\t\tevent.preventDefault();\n\t\t};\n\t\tconst onCancel = (event: Event) => {\n\t\t\tif (!settled) event.preventDefault();\n\t\t};\n\t\tdoc.addEventListener(\"visibilitychange\", arm);\n\t\tdoc.addEventListener(\"close\", arm, true); // `close` does not bubble\n\t\tview?.addEventListener(\"focus\", arm);\n\t\tview?.addEventListener(\"blur\", arm);\n\t\tview?.addEventListener(\"resize\", check);\n\t\targs.addEventListener(\"scroll\", check);\n\t\tdialog.addEventListener(\"keydown\", guard);\n\t\tdialog.addEventListener(\"keyup\", guard);\n\t\tdialog.addEventListener(\"cancel\", onCancel);\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tuntitle();\n\t\t\tdoc.removeEventListener(\"visibilitychange\", arm);\n\t\t\tdoc.removeEventListener(\"close\", arm, true);\n\t\t\tview?.removeEventListener(\"focus\", arm);\n\t\t\tview?.removeEventListener(\"blur\", arm);\n\t\t\tview?.removeEventListener(\"resize\", check);\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tdialog.remove();\n\t\t\tif (queue.changed === showWaiting) queue.changed = undefined;\n\t\t};\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tcleanup();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t\tnext();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\ttry {\n\t\t\tdialog.showModal();\n\t\t} catch (error) {\n\t\t\t// Never shown, so never closed: the queue must not wait for it.\n\t\t\tcleanup();\n\t\t\treject(error);\n\t\t\tnext();\n\t\t\treturn;\n\t\t}\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\tcheck();\n\t});\n}\n\n/**\n * `TabMcp.confirmInPage`: the confirmation, and the tools allowed until\n * reload (`always-allowed.ts`). Only for an AI app through the relay: an\n * agent in the browser and a served port have no identity to remember an\n * answer for (DEC-115, DEC-124).\n */\nexport function confirmInPage(\n\tmcp: TabMcp,\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: {\n\t\talwaysAllow?: boolean | undefined;\n\t\tui?: DialogOptions | undefined;\n\t\t/** Tests only. */\n\t\tallowDelayMs?: number | undefined;\n\t} = {},\n): Promise<boolean> {\n\tconst { client } = request;\n\tconst dialogOptions = {\n\t\tstrings: stringsOf(options.ui),\n\t\tallowDelayMs: options.allowDelayMs,\n\t};\n\tif (client.kind !== \"relay\")\n\t\treturn confirmDialog(request, doc, dialogOptions).then(\n\t\t\t(answer) => answer === \"allow\",\n\t\t);\n\tconst { grantId } = client;\n\tconst allowed = allowedFor(mcp);\n\tconst allowedNow = () => allowed.has(grantId, request.tool);\n\tif (allowedNow()) return Promise.resolve(true);\n\t// Asked again when its turn comes: the call before it in the queue may\n\t// have been allowed until reload.\n\treturn confirmDialog(request, doc, {\n\t\t...dialogOptions,\n\t\talwaysAllow: options.alwaysAllow,\n\t\tallowedNow,\n\t}).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\tallowed.add(grantId, request.tool);\n\t\treturn answer !== \"deny\";\n\t});\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;AA4BA,SAAS,aAAa,CAAC,MAAmD;AAAA,EACzE,IAAI;AAAA,IACH,OAAO,QAAQ,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;AAAA,IAC3C,MAAM;AAAA,IACP;AAAA;AAAA;AAQK,IAAM,iBAAiB;AAM9B,IAAM,sBAAsB;AAyB5B,IAAM,SAAS,IAAI;AAkBZ,SAAS,aAAa,CAC5B,SACA,KACA,UAAgC,CAAC,GACT;AAAA,EACxB,IAAI,QAAQ,OAAO;AAAA,IAAS,OAAO,QAAQ,QAAQ,MAAM;AAAA,EACzD,IAAI,QAAQ,OAAO,IAAI,GAAG;AAAA,EAC1B,IAAI,UAAU,WAAW;AAAA,IAC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|
10
|
+
}
|
package/confirm.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The confirmation of consequential tools, loaded on demand: a `<dialog>`
|
|
3
|
+
* per call, one shown at a time per document, and the tools a user allowed
|
|
4
|
+
* until reload (`always-allowed.ts`).
|
|
5
|
+
*/
|
|
6
|
+
import type { DialogStrings } from "./strings.js";
|
|
7
|
+
import type { TabMcp } from "./tab-mcp.js";
|
|
8
|
+
import type { ConfirmRequest, DialogOptions } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* How long "Allow" stays disabled after the confirmation is shown, while the
|
|
11
|
+
* page is visible and focused (CU 17: a constant; tests pass `allowDelayMs`).
|
|
12
|
+
*/
|
|
13
|
+
export declare const ALLOW_DELAY_MS = 750;
|
|
14
|
+
/** The user's answer: "always" allows this tool for this AI app until reload. */
|
|
15
|
+
export type DialogAnswer = "allow" | "always" | "deny";
|
|
16
|
+
/** Options of `confirmDialog`. */
|
|
17
|
+
export interface ConfirmDialogOptions {
|
|
18
|
+
/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */
|
|
19
|
+
allowDelayMs?: number | undefined;
|
|
20
|
+
/** Offer "Allow until reload". */
|
|
21
|
+
alwaysAllow?: boolean | undefined;
|
|
22
|
+
/** Asked when a waiting call's turn comes: `true` answers "allow" unseen. */
|
|
23
|
+
allowedNow?: () => boolean;
|
|
24
|
+
strings?: DialogStrings;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Ask whether a consequential tool may run. "Allow until reload" is offered
|
|
28
|
+
* only with `alwaysAllow` (DEC-096). One confirmation is shown at a time per
|
|
29
|
+
* document; the others wait their turn, and a call cancelled while it waits
|
|
30
|
+
* is never shown. "Allow" and "Allow until reload" stay disabled until the
|
|
31
|
+
* page has been visible and focused for 750 ms while the dialog is open and
|
|
32
|
+
* is the top one, so a click meant for the page, the click that brings the
|
|
33
|
+
* tab or window back, or the one that closed another dialog, cannot
|
|
34
|
+
* approve; leaving the page disables them again. They also wait until the
|
|
35
|
+
* arguments have been scrolled to their end. Before the delay has run out,
|
|
36
|
+
* Enter or Space on a button and Escape are ignored, so typing meant for the
|
|
37
|
+
* page cannot refuse either. Everything else (Don't allow, Escape, an
|
|
38
|
+
* aborted call) is "deny". `allowedNow` is asked when a waiting call's turn
|
|
39
|
+
* comes: `true` (the user allowed it until reload meanwhile) answers "allow"
|
|
40
|
+
* without showing it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function confirmDialog(request: ConfirmRequest, doc: Document, options?: ConfirmDialogOptions): Promise<DialogAnswer>;
|
|
43
|
+
/**
|
|
44
|
+
* `TabMcp.confirmInPage`: the confirmation, and the tools allowed until
|
|
45
|
+
* reload (`always-allowed.ts`). Only for an AI app through the relay: an
|
|
46
|
+
* agent in the browser and a served port have no identity to remember an
|
|
47
|
+
* answer for (DEC-115, DEC-124).
|
|
48
|
+
*/
|
|
49
|
+
export declare function confirmInPage(mcp: TabMcp, request: ConfirmRequest, doc: Document, options?: {
|
|
50
|
+
alwaysAllow?: boolean | undefined;
|
|
51
|
+
ui?: DialogOptions | undefined;
|
|
52
|
+
/** Tests only. */
|
|
53
|
+
allowDelayMs?: number | undefined;
|
|
54
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allowedFor,
|
|
3
|
+
nextId,
|
|
4
|
+
stringsOf,
|
|
5
|
+
format,
|
|
6
|
+
fill,
|
|
7
|
+
el,
|
|
8
|
+
button,
|
|
9
|
+
visible,
|
|
10
|
+
clientLabel,
|
|
11
|
+
listOf,
|
|
12
|
+
newDialog,
|
|
13
|
+
copyButton
|
|
14
|
+
} from "./index-jnz7w9xa.js";
|
|
15
|
+
import"./index-dmh5vm5m.js";
|
|
16
|
+
import {
|
|
17
|
+
SETUP_GUIDE2,
|
|
18
|
+
setupInstructions2
|
|
19
|
+
} from "./index-5jyqehpk.js";
|
|
20
|
+
|
|
21
|
+
// src/connect.ts
|
|
22
|
+
function appLabels(grants, s) {
|
|
23
|
+
return [...new Set(grants.map((g) => clientLabel(g.client, s)))];
|
|
24
|
+
}
|
|
25
|
+
function connectFailure(error, s) {
|
|
26
|
+
console.warn("tab-mcp: could not connect.", error);
|
|
27
|
+
const reason = error?.reason;
|
|
28
|
+
if (reason === undefined)
|
|
29
|
+
return s.notConnected;
|
|
30
|
+
if (reason === "network")
|
|
31
|
+
return s.unreachable;
|
|
32
|
+
if (reason === "rate_limited")
|
|
33
|
+
return s.rateLimited;
|
|
34
|
+
return s.refused;
|
|
35
|
+
}
|
|
36
|
+
function disconnectedText(reason, s) {
|
|
37
|
+
switch (reason) {
|
|
38
|
+
case "expired":
|
|
39
|
+
case "idle":
|
|
40
|
+
return s.ended;
|
|
41
|
+
case "user":
|
|
42
|
+
return s.disconnected;
|
|
43
|
+
case "network":
|
|
44
|
+
case "heartbeat":
|
|
45
|
+
case "shutdown":
|
|
46
|
+
return s.lost;
|
|
47
|
+
case "rate_limited":
|
|
48
|
+
return s.rateLimited;
|
|
49
|
+
default:
|
|
50
|
+
return s.closed;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function signInText(mcp, s) {
|
|
54
|
+
switch (mcp.identity) {
|
|
55
|
+
case "bound":
|
|
56
|
+
return;
|
|
57
|
+
case "pending":
|
|
58
|
+
return s.checkingSignIn;
|
|
59
|
+
case "refused":
|
|
60
|
+
return mcp.identityMessage ? format(s.signInRefusedWhy, { reason: mcp.identityMessage }) : s.signInRefused;
|
|
61
|
+
default:
|
|
62
|
+
return s.signInFirst;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var watched = new WeakMap;
|
|
66
|
+
function watchReplaced(mcp, doc, ui) {
|
|
67
|
+
const known = watched.has(mcp);
|
|
68
|
+
watched.set(mcp, ui === undefined ? { doc } : { doc, ui });
|
|
69
|
+
if (known)
|
|
70
|
+
return;
|
|
71
|
+
mcp.addEventListener("replaced", (event) => {
|
|
72
|
+
const current = watched.get(mcp);
|
|
73
|
+
if (current !== undefined && mcp.state === "disconnected")
|
|
74
|
+
replacedNotice(mcp, current.doc, event.detail.sibling, current.ui);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function replacedNotice(mcp, doc, sibling, ui) {
|
|
78
|
+
const s = stringsOf(ui);
|
|
79
|
+
doc.querySelector("dialog.tab-mcp-replaced")?.close();
|
|
80
|
+
const { dialog } = newDialog(doc, "tab-mcp-replaced", s, sibling ? s.replacedSiblingTitle : s.replacedTitle);
|
|
81
|
+
const status = el(doc, "p", { className: "tab-mcp-status" });
|
|
82
|
+
status.setAttribute("role", "status");
|
|
83
|
+
status.hidden = true;
|
|
84
|
+
const close = button(doc, s.close, () => dialog.close(), "tab-mcp-replaced-close", sibling ? "primary" : undefined);
|
|
85
|
+
const actions = el(doc, "div", { className: "tab-mcp-actions" }, close);
|
|
86
|
+
let first = close;
|
|
87
|
+
if (!sibling) {
|
|
88
|
+
const fresh = button(doc, s.newAddress, () => {
|
|
89
|
+
fresh.disabled = true;
|
|
90
|
+
status.hidden = false;
|
|
91
|
+
status.textContent = s.gettingNewAddress;
|
|
92
|
+
mcp.newAddress().then(() => {
|
|
93
|
+
dialog.close();
|
|
94
|
+
mcp.showConnectDialog({ document: doc }).catch(() => {});
|
|
95
|
+
}, (error) => {
|
|
96
|
+
fresh.disabled = false;
|
|
97
|
+
status.textContent = error?.reason === "replaced" ? s.takenOverAgain : format(s.tryAgainOrClose, {
|
|
98
|
+
reason: connectFailure(error, s)
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}, "tab-mcp-new-address", "primary");
|
|
102
|
+
actions.append(" ", fresh);
|
|
103
|
+
first = fresh;
|
|
104
|
+
}
|
|
105
|
+
dialog.append(el(doc, "p", {
|
|
106
|
+
className: "tab-mcp-description",
|
|
107
|
+
text: sibling ? s.replacedSibling : s.replaced
|
|
108
|
+
}), status, actions);
|
|
109
|
+
dialog.addEventListener("close", () => dialog.remove(), { once: true });
|
|
110
|
+
doc.body.append(dialog);
|
|
111
|
+
dialog.showModal();
|
|
112
|
+
first.focus();
|
|
113
|
+
}
|
|
114
|
+
var CODE_USED_WAIT_MS = 1e4;
|
|
115
|
+
function showConnectDialog(mcp, connecting, doc, serverName = "tools", ui) {
|
|
116
|
+
const s = stringsOf(ui);
|
|
117
|
+
const allowed = allowedFor(mcp);
|
|
118
|
+
const { dialog } = newDialog(doc, "tab-mcp-connect", s, s.connectTitle);
|
|
119
|
+
dialog.tabIndex = -1;
|
|
120
|
+
const status = el(doc, "p", { className: "tab-mcp-status" });
|
|
121
|
+
status.setAttribute("role", "status");
|
|
122
|
+
const live = el(doc, "span", { className: "tab-mcp-announce" });
|
|
123
|
+
live.setAttribute("aria-live", "polite");
|
|
124
|
+
for (const [property, value] of [
|
|
125
|
+
["position", "absolute"],
|
|
126
|
+
["width", "1px"],
|
|
127
|
+
["height", "1px"],
|
|
128
|
+
["overflow", "hidden"],
|
|
129
|
+
["clip-path", "inset(50%)"],
|
|
130
|
+
["white-space", "nowrap"]
|
|
131
|
+
])
|
|
132
|
+
live.style.setProperty(property, value);
|
|
133
|
+
const announce = (text) => {
|
|
134
|
+
live.textContent = live.textContent === text ? `${text} ` : text;
|
|
135
|
+
};
|
|
136
|
+
const successId = `${nextId()}-success`;
|
|
137
|
+
const successTitle = el(doc, "p", { className: "tab-mcp-success-title" });
|
|
138
|
+
const successNext = el(doc, "p", { className: "tab-mcp-success-next" });
|
|
139
|
+
const check = el(doc, "span", { className: "tab-mcp-success-icon" });
|
|
140
|
+
check.setAttribute("aria-hidden", "true");
|
|
141
|
+
const success = el(doc, "div", { className: "tab-mcp-success", id: successId }, check, el(doc, "div", { className: "tab-mcp-success-text" }, successTitle, successNext));
|
|
142
|
+
const addressId = `${nextId()}-address`;
|
|
143
|
+
const label = el(doc, "label", { text: s.addressLabel });
|
|
144
|
+
label.htmlFor = addressId;
|
|
145
|
+
const address = el(doc, "input", {
|
|
146
|
+
id: addressId,
|
|
147
|
+
className: "tab-mcp-address-input"
|
|
148
|
+
});
|
|
149
|
+
address.readOnly = true;
|
|
150
|
+
const { button: copy, reset: resetCopy } = copyButton(doc, s, s.copyAddress, () => address.value, () => address.select(), announce, "tab-mcp-address-copy", "primary");
|
|
151
|
+
const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy);
|
|
152
|
+
const fresh = button(doc, s.newAddress, () => askNewAddress(), "tab-mcp-new-address");
|
|
153
|
+
const freshBox = el(doc, "div", { className: "tab-mcp-new-address-row" }, el(doc, "small", { text: s.newAddressNote }), " ", fresh);
|
|
154
|
+
const questionId = `${nextId()}-new-address`;
|
|
155
|
+
const questionText = el(doc, "p", { id: questionId });
|
|
156
|
+
const cancelNew = button(doc, s.cancel, () => {
|
|
157
|
+
asking = false;
|
|
158
|
+
render();
|
|
159
|
+
fresh.focus();
|
|
160
|
+
});
|
|
161
|
+
const confirmNew = button(doc, s.newAddressConfirm, () => getNewAddress(), "tab-mcp-new-address-confirm", "danger");
|
|
162
|
+
const question = el(doc, "div", { className: "tab-mcp-new-address-question" }, questionText, el(doc, "div", { className: "tab-mcp-actions" }, cancelNew, " ", confirmNew));
|
|
163
|
+
question.setAttribute("role", "group");
|
|
164
|
+
question.setAttribute("aria-labelledby", questionId);
|
|
165
|
+
const code = el(doc, "strong", { className: "tab-mcp-code-value" });
|
|
166
|
+
code.style.setProperty("user-select", "all");
|
|
167
|
+
code.style.setProperty("-webkit-user-select", "all");
|
|
168
|
+
const { button: copyCode, reset: resetCopyCode } = copyButton(doc, s, s.copyCode, () => code.textContent ?? "", () => doc.getSelection()?.selectAllChildren(code), announce, "tab-mcp-code-copy");
|
|
169
|
+
const codeSentence = el(doc, "span", {}, ...fill(doc, s.codeSentence, { code }));
|
|
170
|
+
codeSentence.setAttribute("aria-live", "polite");
|
|
171
|
+
const codeUsed = el(doc, "span", { className: "tab-mcp-code-used" });
|
|
172
|
+
const codeLine = el(doc, "p", { className: "tab-mcp-code" }, codeSentence, codeUsed, " ", copyCode, el(doc, "br"), el(doc, "small", { className: "tab-mcp-code-note", text: s.codeNote }));
|
|
173
|
+
const signInLine = el(doc, "p", {
|
|
174
|
+
className: "tab-mcp-sign-in",
|
|
175
|
+
text: s.signIn
|
|
176
|
+
});
|
|
177
|
+
const steps = el(doc, "ul");
|
|
178
|
+
const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: s.help }), steps);
|
|
179
|
+
const guideUrl = ui?.setup?.guide === undefined ? SETUP_GUIDE2 : ui.setup.guide;
|
|
180
|
+
if (guideUrl !== null) {
|
|
181
|
+
const guide = el(doc, "a", { text: s.guide });
|
|
182
|
+
guide.href = guideUrl;
|
|
183
|
+
guide.target = "_blank";
|
|
184
|
+
guide.rel = "noopener noreferrer";
|
|
185
|
+
help.append(el(doc, "p", { className: "tab-mcp-guide" }, guide));
|
|
186
|
+
}
|
|
187
|
+
const instructions = ui?.setup?.instructions ?? setupInstructions2;
|
|
188
|
+
const setupId = `${nextId()}-setup`;
|
|
189
|
+
const setup = el(doc, "div", { className: "tab-mcp-setup", id: setupId }, addressBox, help, codeLine, signInLine, freshBox, question);
|
|
190
|
+
const setupToggle = button(doc, s.connectAnother, () => {
|
|
191
|
+
expanded = !expanded;
|
|
192
|
+
render();
|
|
193
|
+
}, "tab-mcp-setup-toggle");
|
|
194
|
+
setupToggle.setAttribute("aria-controls", setupId);
|
|
195
|
+
const appList = el(doc, "ul");
|
|
196
|
+
const appsNote = el(doc, "p", { className: "tab-mcp-apps-note" });
|
|
197
|
+
appsNote.setAttribute("role", "status");
|
|
198
|
+
const apps = el(doc, "div", { className: "tab-mcp-apps" }, el(doc, "h3", { text: s.connectedHeading }), appList, appsNote);
|
|
199
|
+
const closeNote = el(doc, "small", {
|
|
200
|
+
className: "tab-mcp-close-note",
|
|
201
|
+
text: s.closeNote
|
|
202
|
+
});
|
|
203
|
+
const close = button(doc, s.close, () => dialog.close(), "tab-mcp-close");
|
|
204
|
+
const done = button(doc, s.done, () => dialog.close(), "tab-mcp-done", "primary");
|
|
205
|
+
const retry = button(doc, s.connectAgain, () => {
|
|
206
|
+
message = undefined;
|
|
207
|
+
mcp.connect().then(() => {
|
|
208
|
+
if (doc.activeElement === close)
|
|
209
|
+
start().focus();
|
|
210
|
+
}, (error) => {
|
|
211
|
+
message = connectFailure(error, s);
|
|
212
|
+
render();
|
|
213
|
+
if (doc.activeElement === close && !retry.hidden)
|
|
214
|
+
retry.focus();
|
|
215
|
+
});
|
|
216
|
+
render();
|
|
217
|
+
}, "tab-mcp-retry", "primary");
|
|
218
|
+
const actions = el(doc, "div", { className: "tab-mcp-actions" }, closeNote, " ", close, retry, done);
|
|
219
|
+
dialog.append(success, status, apps, setupToggle, setup, actions, live);
|
|
220
|
+
let expanded = false;
|
|
221
|
+
let asking = false;
|
|
222
|
+
let renewing = false;
|
|
223
|
+
let renewed = false;
|
|
224
|
+
let message;
|
|
225
|
+
let appsProblem;
|
|
226
|
+
let grantsSeen = new Set(mcp.grants.map((g) => g.grantId));
|
|
227
|
+
let stepsFor;
|
|
228
|
+
let shownCode;
|
|
229
|
+
let usedTimer;
|
|
230
|
+
let connectedView = false;
|
|
231
|
+
const closer = () => connectedView ? done : retry.hidden ? close : retry;
|
|
232
|
+
const start = () => connectedView ? done : copy;
|
|
233
|
+
const items = new Map;
|
|
234
|
+
const appItem = (grant) => {
|
|
235
|
+
const app = clientLabel(grant.client, s);
|
|
236
|
+
const disconnect = button(doc, s.disconnect, () => {
|
|
237
|
+
appsProblem = undefined;
|
|
238
|
+
mcp.revoke(grant.grantId).catch((error) => {
|
|
239
|
+
if (mcp.state === "connected")
|
|
240
|
+
appsProblem = error?.code === "store_unavailable" ? s.storeUnavailable : s.disconnectFailed;
|
|
241
|
+
render();
|
|
242
|
+
});
|
|
243
|
+
render();
|
|
244
|
+
}, "tab-mcp-disconnect", "danger");
|
|
245
|
+
disconnect.setAttribute("aria-label", format(s.disconnectApp, { app }));
|
|
246
|
+
const askAgain = button(doc, s.askAgain, () => allowed.forget(grant.grantId), "tab-mcp-ask-again");
|
|
247
|
+
askAgain.setAttribute("aria-label", format(s.askAgainApp, { app }));
|
|
248
|
+
const allowedText = el(doc, "span");
|
|
249
|
+
const allowedBox = el(doc, "div", { className: "tab-mcp-allowed" }, allowedText, " ", askAgain);
|
|
250
|
+
const item = el(doc, "li", {}, el(doc, "span", { className: "tab-mcp-app" }, format(s.appConnected, { app })), " ", disconnect, allowedBox);
|
|
251
|
+
return { item, disconnect, allowedText, allowedBox };
|
|
252
|
+
};
|
|
253
|
+
const renderSteps = (session) => {
|
|
254
|
+
if (stepsFor === session.address)
|
|
255
|
+
return;
|
|
256
|
+
stepsFor = session.address;
|
|
257
|
+
steps.replaceChildren(...instructions(serverName, session.address).map(({ app, text: how, command, note }) => {
|
|
258
|
+
const item = el(doc, "li", {}, el(doc, "strong", { text: `${app}:` }), ` ${how}`);
|
|
259
|
+
if (command !== undefined) {
|
|
260
|
+
const text = el(doc, "pre", { text: command });
|
|
261
|
+
text.dir = "ltr";
|
|
262
|
+
const { button: copyCommand } = copyButton(doc, s, format(s.copyCommand, { app }), () => text.textContent ?? "", () => doc.getSelection()?.selectAllChildren(text), announce, "tab-mcp-command-copy");
|
|
263
|
+
item.append(el(doc, "div", { className: "tab-mcp-command" }, text, copyCommand));
|
|
264
|
+
}
|
|
265
|
+
if (note !== undefined)
|
|
266
|
+
item.append(el(doc, "small", { className: "tab-mcp-command-note" }, ...note.map((part) => ("code" in part) ? el(doc, "code", { text: part.code }) : part.text)));
|
|
267
|
+
return item;
|
|
268
|
+
}));
|
|
269
|
+
};
|
|
270
|
+
const renderCode = (paired) => {
|
|
271
|
+
const current = mcp.pairingCode;
|
|
272
|
+
if (current === undefined || paired) {
|
|
273
|
+
clearTimeout(usedTimer);
|
|
274
|
+
usedTimer = undefined;
|
|
275
|
+
} else if (current.code !== shownCode?.code) {
|
|
276
|
+
if (current.reason === "used") {
|
|
277
|
+
if (usedTimer === undefined) {
|
|
278
|
+
usedTimer = setTimeout(() => {
|
|
279
|
+
usedTimer = undefined;
|
|
280
|
+
shownCode = mcp.pairingCode;
|
|
281
|
+
render();
|
|
282
|
+
}, CODE_USED_WAIT_MS);
|
|
283
|
+
announce(s.codeUsed);
|
|
284
|
+
}
|
|
285
|
+
} else if (usedTimer !== undefined) {
|
|
286
|
+
clearTimeout(usedTimer);
|
|
287
|
+
usedTimer = undefined;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const used = usedTimer !== undefined;
|
|
291
|
+
if (!used) {
|
|
292
|
+
if (code.textContent !== (current?.code ?? ""))
|
|
293
|
+
resetCopyCode();
|
|
294
|
+
code.textContent = current?.code ?? "";
|
|
295
|
+
shownCode = current;
|
|
296
|
+
}
|
|
297
|
+
codeSentence.hidden = used;
|
|
298
|
+
copyCode.hidden = used;
|
|
299
|
+
codeUsed.hidden = !used;
|
|
300
|
+
codeUsed.textContent = used ? s.codeUsed : "";
|
|
301
|
+
return current !== undefined;
|
|
302
|
+
};
|
|
303
|
+
const render = () => {
|
|
304
|
+
const focused = doc.activeElement;
|
|
305
|
+
const { state, session, grants } = mcp;
|
|
306
|
+
const connected = state === "connected";
|
|
307
|
+
const oidc = session?.pairing === "oidc";
|
|
308
|
+
const signIn = oidc ? signInText(mcp, s) : undefined;
|
|
309
|
+
const shown = session !== undefined && signIn === undefined;
|
|
310
|
+
const ids = new Set(grants.map((g) => g.grantId));
|
|
311
|
+
const paired = connected && grants.some((g) => !grantsSeen.has(g.grantId));
|
|
312
|
+
grantsSeen = ids;
|
|
313
|
+
if (paired) {
|
|
314
|
+
renewed = false;
|
|
315
|
+
if (!asking)
|
|
316
|
+
expanded = false;
|
|
317
|
+
}
|
|
318
|
+
const names = appLabels(grants, s);
|
|
319
|
+
if (names.length === 0 || !shown)
|
|
320
|
+
asking = false;
|
|
321
|
+
connectedView = !renewing && connected && grants.length > 0;
|
|
322
|
+
const one = names.length === 1;
|
|
323
|
+
successTitle.textContent = format(one ? s.connectedOne : s.connectedMany, {
|
|
324
|
+
apps: listOf(names, s)
|
|
325
|
+
});
|
|
326
|
+
successNext.textContent = one ? s.connectedNextOne : s.connectedNextMany;
|
|
327
|
+
if (connectedView)
|
|
328
|
+
dialog.setAttribute("aria-describedby", successId);
|
|
329
|
+
else
|
|
330
|
+
dialog.removeAttribute("aria-describedby");
|
|
331
|
+
success.hidden = !connectedView;
|
|
332
|
+
if (connected)
|
|
333
|
+
message = undefined;
|
|
334
|
+
const appName = session?.appName;
|
|
335
|
+
status.textContent = renewing ? s.gettingNewAddress : state === "connecting" ? s.connecting : state === "reconnecting" ? s.reconnecting : !connected ? message ?? s.notConnected : signIn ?? (renewed ? s.newAddressDone : appName !== undefined ? format(s.readyApp, { app: appName }) : s.readyPage);
|
|
336
|
+
status.hidden = connectedView;
|
|
337
|
+
const addressShownBefore = !addressBox.hidden;
|
|
338
|
+
if (shown && address.value !== session.address) {
|
|
339
|
+
address.value = session.address;
|
|
340
|
+
resetCopy();
|
|
341
|
+
}
|
|
342
|
+
if (shown)
|
|
343
|
+
renderSteps(session);
|
|
344
|
+
addressBox.hidden = help.hidden = freshBox.hidden = !shown;
|
|
345
|
+
fresh.disabled = !connected;
|
|
346
|
+
question.hidden = !asking;
|
|
347
|
+
if (asking)
|
|
348
|
+
questionText.textContent = format(one ? s.newAddressQuestionOne : s.newAddressQuestionMany, { apps: listOf(names, s) });
|
|
349
|
+
const hasCode = renderCode(paired);
|
|
350
|
+
codeLine.hidden = oidc || !hasCode || !connected;
|
|
351
|
+
signInLine.hidden = !oidc || mcp.identity !== "bound";
|
|
352
|
+
setupToggle.hidden = !connectedView;
|
|
353
|
+
setupToggle.setAttribute("aria-expanded", String(expanded));
|
|
354
|
+
setup.hidden = connectedView && !expanded;
|
|
355
|
+
copy.classList.toggle("tab-mcp-primary", !connectedView);
|
|
356
|
+
for (const [id, { item }] of items) {
|
|
357
|
+
if (ids.has(id))
|
|
358
|
+
continue;
|
|
359
|
+
item.remove();
|
|
360
|
+
items.delete(id);
|
|
361
|
+
}
|
|
362
|
+
grants.forEach((grant, i) => {
|
|
363
|
+
let entry = items.get(grant.grantId);
|
|
364
|
+
if (entry === undefined) {
|
|
365
|
+
entry = appItem(grant);
|
|
366
|
+
items.set(grant.grantId, entry);
|
|
367
|
+
}
|
|
368
|
+
entry.disconnect.disabled = !connected;
|
|
369
|
+
const tools = allowed.list(grant.grantId);
|
|
370
|
+
entry.allowedBox.hidden = tools.length === 0;
|
|
371
|
+
entry.allowedText.textContent = format(s.runsWithoutAsking, {
|
|
372
|
+
tools: tools.map(visible).join(", ")
|
|
373
|
+
});
|
|
374
|
+
if (appList.children[i] !== entry.item)
|
|
375
|
+
appList.insertBefore(entry.item, appList.children[i] ?? null);
|
|
376
|
+
});
|
|
377
|
+
appsNote.textContent = connected ? appsProblem ?? "" : s.disconnectNote;
|
|
378
|
+
appsNote.hidden = connected && appsProblem === undefined;
|
|
379
|
+
apps.hidden = grants.length === 0;
|
|
380
|
+
closeNote.hidden = connectedView || codeLine.hidden;
|
|
381
|
+
close.hidden = connectedView;
|
|
382
|
+
done.hidden = !connectedView;
|
|
383
|
+
retry.hidden = renewing || state !== "disconnected" && state !== "reconnecting";
|
|
384
|
+
if (focused !== null && focused !== dialog && focused !== doc.body && (!focused.isConnected || dialog.contains(focused) && focused.closest("[hidden]") !== null))
|
|
385
|
+
(question.contains(focused) && !freshBox.hidden ? fresh : closer()).focus();
|
|
386
|
+
else if (doc.activeElement === dialog && (connectedView || shown))
|
|
387
|
+
start().focus();
|
|
388
|
+
else if (renewed && shown && !addressShownBefore && doc.activeElement === close)
|
|
389
|
+
copy.focus();
|
|
390
|
+
if (paired && connectedView)
|
|
391
|
+
announce(`${successTitle.textContent}. ${successNext.textContent}`);
|
|
392
|
+
};
|
|
393
|
+
const askNewAddress = () => {
|
|
394
|
+
if (mcp.state !== "connected")
|
|
395
|
+
return;
|
|
396
|
+
if (mcp.grants.length === 0) {
|
|
397
|
+
getNewAddress();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
asking = true;
|
|
401
|
+
render();
|
|
402
|
+
cancelNew.focus();
|
|
403
|
+
};
|
|
404
|
+
const getNewAddress = () => {
|
|
405
|
+
renewing = true;
|
|
406
|
+
renewed = false;
|
|
407
|
+
close.focus();
|
|
408
|
+
asking = false;
|
|
409
|
+
render();
|
|
410
|
+
mcp.newAddress().then(() => {
|
|
411
|
+
renewing = false;
|
|
412
|
+
renewed = true;
|
|
413
|
+
render();
|
|
414
|
+
if (!addressBox.hidden)
|
|
415
|
+
copy.focus();
|
|
416
|
+
}, (error) => {
|
|
417
|
+
renewing = false;
|
|
418
|
+
message = connectFailure(error, s);
|
|
419
|
+
render();
|
|
420
|
+
closer().focus();
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
let stoppedBy;
|
|
424
|
+
let wasReconnecting = mcp.state === "reconnecting";
|
|
425
|
+
const onError = (event) => {
|
|
426
|
+
const { error } = event.detail;
|
|
427
|
+
if (wasReconnecting && error.reason !== undefined)
|
|
428
|
+
stoppedBy = error;
|
|
429
|
+
};
|
|
430
|
+
const onState = (event) => {
|
|
431
|
+
const { state, reason } = event.detail;
|
|
432
|
+
if (reason !== undefined && reason !== "new_address") {
|
|
433
|
+
message = disconnectedText(reason, s);
|
|
434
|
+
renewed = false;
|
|
435
|
+
}
|
|
436
|
+
if (state === "disconnected" && wasReconnecting)
|
|
437
|
+
message = stoppedBy === undefined ? s.disconnected : connectFailure(stoppedBy, s);
|
|
438
|
+
wasReconnecting = state === "reconnecting";
|
|
439
|
+
stoppedBy = undefined;
|
|
440
|
+
render();
|
|
441
|
+
};
|
|
442
|
+
const onReplaced = () => dialog.close();
|
|
443
|
+
watchReplaced(mcp, doc, ui);
|
|
444
|
+
const stopAllowed = allowed.onChange(render);
|
|
445
|
+
mcp.addEventListener("statechange", onState);
|
|
446
|
+
mcp.addEventListener("pairingcode", render);
|
|
447
|
+
mcp.addEventListener("grantschange", render);
|
|
448
|
+
mcp.addEventListener("identitychange", render);
|
|
449
|
+
mcp.addEventListener("error", onError);
|
|
450
|
+
mcp.addEventListener("replaced", onReplaced);
|
|
451
|
+
doc.body.append(dialog);
|
|
452
|
+
mcp.startPairing();
|
|
453
|
+
render();
|
|
454
|
+
connecting.then(render, (error) => {
|
|
455
|
+
message = connectFailure(error, s);
|
|
456
|
+
render();
|
|
457
|
+
});
|
|
458
|
+
return new Promise((resolve) => {
|
|
459
|
+
dialog.addEventListener("close", () => {
|
|
460
|
+
clearTimeout(usedTimer);
|
|
461
|
+
mcp.stopPairing();
|
|
462
|
+
stopAllowed();
|
|
463
|
+
mcp.removeEventListener("statechange", onState);
|
|
464
|
+
mcp.removeEventListener("pairingcode", render);
|
|
465
|
+
mcp.removeEventListener("grantschange", render);
|
|
466
|
+
mcp.removeEventListener("identitychange", render);
|
|
467
|
+
mcp.removeEventListener("error", onError);
|
|
468
|
+
mcp.removeEventListener("replaced", onReplaced);
|
|
469
|
+
dialog.remove();
|
|
470
|
+
resolve();
|
|
471
|
+
}, { once: true });
|
|
472
|
+
dialog.showModal();
|
|
473
|
+
if (connectedView || !addressBox.hidden)
|
|
474
|
+
start().focus();
|
|
475
|
+
else
|
|
476
|
+
dialog.focus();
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
export {
|
|
480
|
+
showConnectDialog
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
//# debugId=7DE523796225AEC064756E2164756E21
|
|
484
|
+
//# sourceMappingURL=connect-8jpb0k29.js.map
|