@ractive-ch/tab-mcp-client 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +849 -0
- package/README.md +102 -73
- package/address.d.ts +8 -8
- package/cdn/{confirm-y30cx7e1.min.js → confirm-mqmvsxg1.min.js} +2 -2
- package/cdn/{connect-bbhj2y7w.min.js → connect-c7wn48yp.min.js} +2 -2
- package/cdn/{connect-bbhj2y7w.min.js.map → connect-c7wn48yp.min.js.map} +1 -1
- package/cdn/{connection-w97tf22a.min.js → connection-0xqwz17v.min.js} +7 -7
- package/cdn/{connection-w97tf22a.min.js.map → connection-0xqwz17v.min.js.map} +5 -5
- package/cdn/{index-vt5zk9me.min.js → index-t33bb2g4.min.js} +4 -4
- package/cdn/{index-vt5zk9me.min.js.map → index-t33bb2g4.min.js.map} +4 -4
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +3 -3
- package/{confirm-fgnjgd08.js → confirm-vj2zbq4w.js} +2 -2
- package/{connect-8jpb0k29.js → connect-9pefy0xe.js} +2 -2
- package/{connect-8jpb0k29.js.map → connect-9pefy0xe.js.map} +1 -1
- package/{connection-g91xjjgm.js → connection-gang7f5x.js} +10 -23
- package/{connection-g91xjjgm.js.map → connection-gang7f5x.js.map} +5 -5
- package/connection.d.ts +2 -2
- package/index-dmh5vm5m.js.map +1 -1
- package/{index-jnz7w9xa.js → index-qw8qy5ed.js} +11 -11
- package/{index-jnz7w9xa.js.map → index-qw8qy5ed.js.map} +2 -2
- package/index.js +21 -7
- package/index.js.map +3 -3
- package/internal.d.ts +2 -0
- package/package.json +1 -1
- package/protocol.d.ts +6 -7
- package/strings.d.ts +1 -1
- package/tab-mcp.d.ts +10 -1
- package/types.d.ts +16 -2
- package/visible.d.ts +1 -1
- /package/cdn/{confirm-y30cx7e1.min.js.map → confirm-mqmvsxg1.min.js.map} +0 -0
- /package/{confirm-fgnjgd08.js.map → confirm-vj2zbq4w.js.map} +0 -0
|
@@ -133,14 +133,14 @@ var STRINGS = {
|
|
|
133
133
|
codeNote: "A new code appears every 2 minutes and after each use.",
|
|
134
134
|
codeUsed: "Code used. Waiting for your AI app…",
|
|
135
135
|
signIn: "When your AI app asks, sign in with the account you use on this page. No code is needed.",
|
|
136
|
-
newAddress: "
|
|
137
|
-
newAddressNote: "
|
|
138
|
-
newAddressQuestionOne: "
|
|
139
|
-
newAddressQuestionMany: "
|
|
140
|
-
newAddressConfirm: "Disconnect
|
|
136
|
+
newAddress: "Disconnect all apps",
|
|
137
|
+
newAddressNote: "An AI app is connected that should not be? This disconnects every AI app from this page; each one has to connect again with a new code.",
|
|
138
|
+
newAddressQuestionOne: "This disconnects {apps}. To use this page with it again, connect it again and enter a new code.",
|
|
139
|
+
newAddressQuestionMany: "This disconnects {apps}. To use this page with them again, connect them again and enter a new code.",
|
|
140
|
+
newAddressConfirm: "Disconnect all",
|
|
141
141
|
cancel: "Cancel",
|
|
142
|
-
gettingNewAddress: "
|
|
143
|
-
newAddressDone: "
|
|
142
|
+
gettingNewAddress: "Disconnecting…",
|
|
143
|
+
newAddressDone: "Every AI app is disconnected. Connect yours again.",
|
|
144
144
|
connectedOne: "{apps} is connected",
|
|
145
145
|
connectedMany: "{apps} are connected",
|
|
146
146
|
connectedNextOne: "You can close this now and ask it to use the tools of this page.",
|
|
@@ -156,13 +156,13 @@ var STRINGS = {
|
|
|
156
156
|
runsWithoutAsking: "Runs without asking: {tools}",
|
|
157
157
|
askAgain: "Ask again",
|
|
158
158
|
askAgainApp: "Ask again before {app} runs a tool",
|
|
159
|
-
closeNote: "Closing this stops the code.
|
|
159
|
+
closeNote: "Closing this stops the code. To connect later, open this again from the page.",
|
|
160
160
|
close: "Close",
|
|
161
161
|
done: "Done",
|
|
162
162
|
replacedSiblingTitle: "Opened in another tab",
|
|
163
163
|
replacedSibling: "This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.",
|
|
164
164
|
replacedTitle: "Another tab or program took over this page",
|
|
165
|
-
replaced: "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
|
|
165
|
+
replaced: "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 what this page keeps to connect. “Disconnect all apps” ends that; then connect your AI apps again with a new code.",
|
|
166
166
|
takenOverAgain: "It was taken over again before its AI apps were disconnected. Try again.",
|
|
167
167
|
tryAgainOrClose: "{reason} Try again, or close this."
|
|
168
168
|
};
|
|
@@ -388,5 +388,5 @@ function copyButton(doc, s, label, value, select, announce, className, kind) {
|
|
|
388
388
|
|
|
389
389
|
export { allowedFor, nextId, stringsOf, format, fill, el, button, visible, clientLabel, listOf, newDialog, copyButton };
|
|
390
390
|
|
|
391
|
-
//# debugId=
|
|
392
|
-
//# sourceMappingURL=index-
|
|
391
|
+
//# debugId=D826109AE2BE460264756E2164756E21
|
|
392
|
+
//# sourceMappingURL=index-qw8qy5ed.js.map
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"sources": ["../src/always-allowed.ts", "../src/strings.ts", "../src/dialog.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * The tools a user chose \"Allow until reload\" for, per AI app (grant), kept\n * in memory for the page's lifetime. An entry goes when its grant goes, when\n * the user resets it in the connect dialog, or when its tool is gone. A tool\n * registered again as it was (React's `useTool` does that on a remount) keeps\n * it; one whose title or description changed, what the user saw when\n * allowing it, is asked again.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type { ConfirmRequest } from \"./types.ts\";\n\ntype ToolSeen = ConfirmRequest[\"tool\"];\n\n/** What the user saw of a tool when allowing it. */\nconst seen = (tool: ToolSeen) => JSON.stringify([tool.title, tool.description]);\n\nexport class AlwaysAllowed {\n\t/** Per grant: the tools by name, with what the user saw of each. */\n\treadonly #tools = new Map<\n\t\tstring,\n\t\tMap<string, { seen: string; label: string }>\n\t>();\n\treadonly #listeners = new Set<() => void>();\n\n\thas(grantId: string, tool: ToolSeen): boolean {\n\t\tconst tools = this.#tools.get(grantId);\n\t\tconst allowed = tools?.get(tool.name)?.seen;\n\t\tif (allowed === undefined || allowed === seen(tool)) {\n\t\t\treturn allowed !== undefined;\n\t\t}\n\t\t// The tool changed since: asked again, and no longer listed.\n\t\ttools?.delete(tool.name);\n\t\tthis.#changed();\n\t\treturn false;\n\t}\n\n\tadd(grantId: string, tool: ToolSeen): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Map();\n\t\ttools.set(tool.name, { seen: seen(tool), label: tool.title ?? tool.name });\n\t\tthis.#tools.set(grantId, tools);\n\t\tthis.#changed();\n\t}\n\n\t/** The tools allowed for a grant (title, else name), in the order allowed. */\n\tlist(grantId: string): string[] {\n\t\treturn [...(this.#tools.get(grantId)?.values() ?? [])].map((t) => t.label);\n\t}\n\n\t/** Ask again for every tool of a grant. */\n\tforget(grantId: string): void {\n\t\tif (this.#tools.delete(grantId)) this.#changed();\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.forget(grantId);\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\tlet changed = false;\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools.keys()) {\n\t\t\t\tif (keep.has(tool)) continue;\n\t\t\t\ttools.delete(tool);\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (changed) this.#changed();\n\t}\n\n\t/** Calls `listener` on every change; returns what stops it. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n\n/** The tools allowed until reload, per `TabMcp`. */\nconst allowed = new WeakMap<TabMcp, AlwaysAllowed>();\n\n/**\n * The tools allowed until reload of `mcp`, made on first use. Its grants\n * and tools are followed: a tool's absence counts only after the current\n * task, so that one unregistered and registered again at once (React) keeps\n * its entries.\n */\nexport function allowedFor(mcp: TabMcp): AlwaysAllowed {\n\tconst kept = allowed.get(mcp);\n\tif (kept !== undefined) return kept;\n\tconst made = new AlwaysAllowed();\n\tmcp.addEventListener(\"grantschange\", (e) =>\n\t\tmade.keepGrants(e.detail.grants.map((g) => g.grantId)),\n\t);\n\tlet tools: readonly string[] | undefined;\n\tmcp.addEventListener(\"toolschange\", (e) => {\n\t\tif (tools === undefined)\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tif (tools !== undefined) made.keepTools(tools);\n\t\t\t\ttools = undefined;\n\t\t\t});\n\t\ttools = e.detail.tools;\n\t});\n\tallowed.set(mcp, made);\n\treturn made;\n}\n",
|
|
6
|
-
"/**\n * Every text of the library's dialogs, in one table (CU 5). A page passes\n * its own for some or all keys (`ui: { strings }`); the dialogs use these for\n * the rest. `{name}` is a placeholder the dialog fills in: names of tools\n * and AI apps (isolated, so that they cannot reorder the sentence), the\n * code, counts. Where English needs two forms, there are two keys\n * (`…One` for one, `…Many` for more). `lang` and `dir` are the language and\n * direction of the texts, set on every dialog.\n */\nexport const STRINGS = {\n\tlang: \"en\",\n\tdir: \"ltr\",\n\t/** Between the last two items of a list (\"A, B and C\"). */\n\tand: \"and\",\n\n\t// The confirmation of a consequential tool call.\n\tconfirmTitle: \"Allow {tool}?\",\n\tconfirmWho: \"{client} wants to run {tool}.\",\n\tdeny: \"Don't allow\",\n\tallow: \"Allow\",\n\tallowUntilReload: \"Allow until reload\",\n\tallowUntilReloadNote:\n\t\t\"Allow until reload: {tool} will run for {client} without asking, with any arguments, until you reload this page or disconnect {client}.\",\n\targumentsHidden:\n\t\t\"The arguments cannot be shown, so this call cannot be allowed.\",\n\tscrollToAllow: \"Scroll to the end of the arguments to allow this call.\",\n\twaitingOne: \"1 more call is waiting after this one.\",\n\twaitingMany: \"{n} more calls are waiting after this one.\",\n\t/** Before the page's title while a confirmation waits in a hidden tab. */\n\ttitlePrefix: \"Allow? – \",\n\n\t// How the dialogs name a caller.\n\tclientWebMcp: \"An agent in this browser\",\n\tclientLocal: \"{name} (this site's assistant)\",\n\t/** An AI app through the relay: its name and the host of its client id. */\n\tclientRelay: \"{name} ({host})\",\n\n\t// Copy buttons.\n\tcopy: \"Copy\",\n\tcopied: \"Copied\",\n\t/** On the button after a refused Copy: the text is selected instead. */\n\tpressMac: \"Press ⌘C\",\n\tpressOther: \"Press Ctrl+C\",\n\t/** The same on a touch screen, where there is no key to press. */\n\tselected: \"Selected\",\n\tcopyAddress: \"Copy address\",\n\tcopyCode: \"Copy code\",\n\tcopyCommand: \"Copy {app} command\",\n\n\t// The connect dialog.\n\tconnectTitle: \"Connect your AI app\",\n\tconnecting: \"Connecting…\",\n\tconnectAgain: \"Connect again\",\n\treconnecting: \"Connection lost. Reconnecting…\",\n\tnotConnected: \"Not connected.\",\n\tunreachable: \"Could not connect. Check your internet connection.\",\n\trateLimited: \"Too many attempts. Wait a minute, then connect again.\",\n\trefused: \"The connection was refused.\",\n\tended: \"The session ended.\",\n\tlost: \"The connection was lost.\",\n\tclosed: \"The connection was closed.\",\n\tdisconnected: \"Disconnected.\",\n\tcheckingSignIn: \"Checking your sign-in…\",\n\tsignInFirst: \"Sign in to this page first.\",\n\tsignInRefused: \"Your sign-in on this page was not accepted.\",\n\t/** `{reason}`: the relay's reason, as it gave it. */\n\tsignInRefusedWhy: \"Your sign-in on this page was not accepted ({reason}).\",\n\treadyApp: \"{app} is ready for your AI app.\",\n\treadyPage: \"This page is ready for your AI app.\",\n\taddressLabel: \"Add this address to your AI app:\",\n\thelp: \"How do I add it?\",\n\tguide: \"Step by step, and what to do when it fails\",\n\tcodeSentence: \"When asked, enter the code {code}\",\n\tcodeNote: \"A new code appears every 2 minutes and after each use.\",\n\tcodeUsed: \"Code used. Waiting for your AI app…\",\n\tsignIn:\n\t\t\"When your AI app asks, sign in with the account you use on this page. No code is needed.\",\n\tnewAddress: \"
|
|
6
|
+
"/**\n * Every text of the library's dialogs, in one table (CU 5). A page passes\n * its own for some or all keys (`ui: { strings }`); the dialogs use these for\n * the rest. `{name}` is a placeholder the dialog fills in: names of tools\n * and AI apps (isolated, so that they cannot reorder the sentence), the\n * code, counts. Where English needs two forms, there are two keys\n * (`…One` for one, `…Many` for more). `lang` and `dir` are the language and\n * direction of the texts, set on every dialog.\n */\nexport const STRINGS = {\n\tlang: \"en\",\n\tdir: \"ltr\",\n\t/** Between the last two items of a list (\"A, B and C\"). */\n\tand: \"and\",\n\n\t// The confirmation of a consequential tool call.\n\tconfirmTitle: \"Allow {tool}?\",\n\tconfirmWho: \"{client} wants to run {tool}.\",\n\tdeny: \"Don't allow\",\n\tallow: \"Allow\",\n\tallowUntilReload: \"Allow until reload\",\n\tallowUntilReloadNote:\n\t\t\"Allow until reload: {tool} will run for {client} without asking, with any arguments, until you reload this page or disconnect {client}.\",\n\targumentsHidden:\n\t\t\"The arguments cannot be shown, so this call cannot be allowed.\",\n\tscrollToAllow: \"Scroll to the end of the arguments to allow this call.\",\n\twaitingOne: \"1 more call is waiting after this one.\",\n\twaitingMany: \"{n} more calls are waiting after this one.\",\n\t/** Before the page's title while a confirmation waits in a hidden tab. */\n\ttitlePrefix: \"Allow? – \",\n\n\t// How the dialogs name a caller.\n\tclientWebMcp: \"An agent in this browser\",\n\tclientLocal: \"{name} (this site's assistant)\",\n\t/** An AI app through the relay: its name and the host of its client id. */\n\tclientRelay: \"{name} ({host})\",\n\n\t// Copy buttons.\n\tcopy: \"Copy\",\n\tcopied: \"Copied\",\n\t/** On the button after a refused Copy: the text is selected instead. */\n\tpressMac: \"Press ⌘C\",\n\tpressOther: \"Press Ctrl+C\",\n\t/** The same on a touch screen, where there is no key to press. */\n\tselected: \"Selected\",\n\tcopyAddress: \"Copy address\",\n\tcopyCode: \"Copy code\",\n\tcopyCommand: \"Copy {app} command\",\n\n\t// The connect dialog.\n\tconnectTitle: \"Connect your AI app\",\n\tconnecting: \"Connecting…\",\n\tconnectAgain: \"Connect again\",\n\treconnecting: \"Connection lost. Reconnecting…\",\n\tnotConnected: \"Not connected.\",\n\tunreachable: \"Could not connect. Check your internet connection.\",\n\trateLimited: \"Too many attempts. Wait a minute, then connect again.\",\n\trefused: \"The connection was refused.\",\n\tended: \"The session ended.\",\n\tlost: \"The connection was lost.\",\n\tclosed: \"The connection was closed.\",\n\tdisconnected: \"Disconnected.\",\n\tcheckingSignIn: \"Checking your sign-in…\",\n\tsignInFirst: \"Sign in to this page first.\",\n\tsignInRefused: \"Your sign-in on this page was not accepted.\",\n\t/** `{reason}`: the relay's reason, as it gave it. */\n\tsignInRefusedWhy: \"Your sign-in on this page was not accepted ({reason}).\",\n\treadyApp: \"{app} is ready for your AI app.\",\n\treadyPage: \"This page is ready for your AI app.\",\n\taddressLabel: \"Add this address to your AI app:\",\n\thelp: \"How do I add it?\",\n\tguide: \"Step by step, and what to do when it fails\",\n\tcodeSentence: \"When asked, enter the code {code}\",\n\tcodeNote: \"A new code appears every 2 minutes and after each use.\",\n\tcodeUsed: \"Code used. Waiting for your AI app…\",\n\tsignIn:\n\t\t\"When your AI app asks, sign in with the account you use on this page. No code is needed.\",\n\tnewAddress: \"Disconnect all apps\",\n\tnewAddressNote:\n\t\t\"An AI app is connected that should not be? This disconnects every AI app from this page; each one has to connect again with a new code.\",\n\tnewAddressQuestionOne:\n\t\t\"This disconnects {apps}. To use this page with it again, connect it again and enter a new code.\",\n\tnewAddressQuestionMany:\n\t\t\"This disconnects {apps}. To use this page with them again, connect them again and enter a new code.\",\n\tnewAddressConfirm: \"Disconnect all\",\n\tcancel: \"Cancel\",\n\tgettingNewAddress: \"Disconnecting…\",\n\tnewAddressDone: \"Every AI app is disconnected. Connect yours again.\",\n\tconnectedOne: \"{apps} is connected\",\n\tconnectedMany: \"{apps} are connected\",\n\tconnectedNextOne:\n\t\t\"You can close this now and ask it to use the tools of this page.\",\n\tconnectedNextMany:\n\t\t\"You can close this now and ask them to use the tools of this page.\",\n\tconnectAnother: \"Connect another app\",\n\tconnectedHeading: \"Connected\",\n\tappConnected: \"{app} connected\",\n\tdisconnect: \"Disconnect\",\n\tdisconnectApp: \"Disconnect {app}\",\n\tdisconnectNote: \"To disconnect an app, connect this page again first.\",\n\t/** Disconnect failed: the relay could not save it (`store_unavailable`). */\n\tstoreUnavailable: \"The relay could not save this. Try again.\",\n\t/** Disconnect failed for another reason. */\n\tdisconnectFailed: \"Could not disconnect the app. Try again.\",\n\t/** Under a connected app: the tools allowed until reload for it. */\n\trunsWithoutAsking: \"Runs without asking: {tools}\",\n\taskAgain: \"Ask again\",\n\taskAgainApp: \"Ask again before {app} runs a tool\",\n\tcloseNote:\n\t\t\"Closing this stops the code. To connect later, open this again from the page.\",\n\tclose: \"Close\",\n\tdone: \"Done\",\n\n\t// The notice when another tab or program took over the address.\n\treplacedSiblingTitle: \"Opened in another tab\",\n\treplacedSibling:\n\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\treplacedTitle: \"Another tab or program took over this page\",\n\treplaced:\n\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 what this page keeps to connect. “Disconnect all apps” ends that; then connect your AI apps again with a new code.\",\n\ttakenOverAgain:\n\t\t\"It was taken over again before its AI apps were disconnected. Try again.\",\n\t/** `{reason}`: why disconnecting all apps failed, one of the texts above. */\n\ttryAgainOrClose: \"{reason} Try again, or close this.\",\n};\n\n/** The texts of the dialogs: the keys of {@link STRINGS}, each a string. */\nexport type DialogStrings = { [K in keyof typeof STRINGS]: string };\n",
|
|
7
7
|
"/**\n * What the library's dialogs share: the stylesheet, elements, buttons, the\n * texts (`strings.ts`) and how a caller is named. The confirmation\n * (`confirm.ts`) and the connect dialog (`connect.ts`) are chunks of their\n * own, loaded on demand; pages with their own UI use the events and methods\n * of `TabMcp` instead.\n */\n\nimport { type DialogStrings, STRINGS } from \"./strings.ts\";\nimport type { DialogOptions, Grant, ToolCallClient } from \"./types.ts\";\nimport { escapeInvisible } from \"./visible.ts\";\n\nlet counter = 0;\n\n/** A new id for the elements of one dialog. */\nexport function nextId(): string {\n\treturn `tab-mcp-${++counter}`;\n}\n\n/** The texts: the page's own where it gave them, else the English ones. */\nexport function stringsOf(options: DialogOptions | undefined): DialogStrings {\n\tconst s: DialogStrings = { ...STRINGS };\n\t// Only strings: a missing translation (`undefined`) keeps the English text.\n\tfor (const [key, value] of Object.entries(options?.strings ?? {}))\n\t\tif (typeof value === \"string\" && key in s)\n\t\t\ts[key as keyof DialogStrings] = value;\n\treturn s;\n}\n\n/** `template` with its `{name}` placeholders filled in, as text. */\nexport function format(\n\ttemplate: string,\n\tvalues: Record<string, string>,\n): string {\n\treturn template.replace(\n\t\t/\\{(\\w+)\\}/g,\n\t\t(all, key: string) => values[key] ?? all,\n\t);\n}\n\n/**\n * `template` with its `{name}` placeholders filled in, as nodes: a string\n * value is a name, isolated so that it cannot reorder the words around it\n * (and may stand twice); a node is put in as it is.\n */\nexport function fill(\n\tdoc: Document,\n\ttemplate: string,\n\tvalues: Record<string, string | Node>,\n): (Node | string)[] {\n\treturn template.split(/\\{(\\w+)\\}/).map((part, i) => {\n\t\tif (i % 2 === 0) return part;\n\t\tconst value = values[part];\n\t\tif (value === undefined) return `{${part}}`;\n\t\treturn typeof value === \"string\" ? name(doc, value) : value;\n\t});\n}\n\nexport function 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 */\nexport function 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/** A name in a sentence, isolated so that it cannot reorder the words around it. */\nexport function name(doc: Document, text: string): HTMLElement {\n\tconst node = el(doc, \"bdi\", { text });\n\tnode.dir = \"ltr\";\n\treturn node;\n}\n\n/** Invisible, blank and direction characters as `\\uXXXX` (`visible.ts`). */\nexport const visible: (text: string) => string = escapeInvisible;\n\n/**\n * How the dialogs name a caller: an AI app's name and verified host; for\n * the caller of a served port, the name the page gave it and what it is.\n */\nexport function clientLabel(\n\tclient: ToolCallClient | Grant[\"client\"],\n\ts: DialogStrings,\n): string {\n\tif (\"kind\" in client && client.kind === \"webmcp\") return s.clientWebMcp;\n\tif (\"kind\" in client && client.kind === \"local\")\n\t\treturn format(s.clientLocal, { name: visible(client.name ?? client.id) });\n\tconst host = visible(client.host || client.id);\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? format(s.clientRelay, { name: visible(client.name), host })\n\t\t: host;\n}\n\n/** \"A and B\", \"A, B and C\". */\nexport function listOf(items: string[], s: DialogStrings): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} ${s.and} ${items.at(-1)}`;\n}\n\n/**\n * The look of the 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 page overrides with two classes, `.tab-mcp-dialog .tab-mcp-x`,\n * which wins over all of them; one class does not. 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));\npointer-events: auto;\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; color: inherit; }\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, .tab-mcp-waiting, .tab-mcp-scroll-note, .tab-mcp-allowed) { 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; text-transform: none; letter-spacing: normal; width: auto; 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; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 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 { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }\n.tab-mcp-allowed { display: flex; flex-basis: 100%; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.875em; 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; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; font-size: 1.5em; font-weight: 700; line-height: 1; color: var(--_tab-mcp-success); background: color-mix(in srgb, var(--_tab-mcp-success) 16%, transparent); }\n.tab-mcp-success-icon::before { content: \"\\\\2713\"; }\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-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }\n.tab-mcp-new-address-row > :where(small) { flex: 1 1 14rem; color: var(--_tab-mcp-muted); }\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, .tab-mcp-waiting, .tab-mcp-scroll-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; } .tab-mcp-code { grid-template-columns: minmax(0, 1fr); } .tab-mcp-code > :where(button) { justify-self: start; } }\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 dialog with its heading (`title`, or filled in by the caller). It\n * carries the texts' language and direction (`lang`, `dir` of the\n * strings), whatever the page's: read out with that voice, laid out that way.\n */\nexport function newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ts: DialogStrings,\n\t...title: (Node | string)[]\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement; id: string } {\n\tconst id = nextId();\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\tdialog.lang = s.lang;\n\tdialog.dir = s.dir;\n\tadoptStyles(doc);\n\tconst heading = el(doc, \"h2\", { id: `${id}-title` }, ...title);\n\tdialog.append(heading);\n\treturn { dialog, heading, id };\n}\n\n/** How long a Copy button says \"Copied\", and how long it says to press Ctrl+C. */\nexport const COPIED_MS = 2000;\nexport const SELECTED_MS = 8000;\n\n/** What the button says after a refused Copy, by the user's device. */\nfunction pressToCopy(doc: Document, s: DialogStrings): string {\n\tconst view = doc.defaultView;\n\tif (view?.matchMedia?.(\"(pointer: coarse)\").matches === true)\n\t\treturn s.selected;\n\tconst platform = view?.navigator.platform ?? \"\";\n\treturn /^(Mac|iP)/.test(platform) ? s.pressMac : s.pressOther;\n}\n\n/**\n * A Copy button for `value()`, read at click time. Says \"Copied\" for a\n * moment once the clipboard took it; without a clipboard (or when it refuses)\n * `select()` puts the text in the selection and the button says to press\n * Ctrl+C (⌘C on Apple devices). `label` names it for assistive technology\n * (\"Copy code\"), as the dialog has more than one Copy; while it says what\n * happened, that is its name, and `announce` says it too.\n */\nexport function copyButton(\n\tdoc: Document,\n\ts: DialogStrings,\n\tlabel: string,\n\tvalue: () => string,\n\tselect: () => void,\n\tannounce: (text: string) => void,\n\tclassName: string,\n\tkind?: \"primary\",\n): { button: HTMLButtonElement; reset: () => void } {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst say = (text: string, ms: number) => {\n\t\tnode.textContent = text;\n\t\tnode.removeAttribute(\"aria-label\");\n\t\tannounce(text);\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(reset, ms);\n\t};\n\tconst node = button(\n\t\tdoc,\n\t\ts.copy,\n\t\t() => {\n\t\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t\t?.clipboard;\n\t\t\tconst selected = () => {\n\t\t\t\tselect();\n\t\t\t\tsay(pressToCopy(doc, s), SELECTED_MS);\n\t\t\t};\n\t\t\tif (clipboard !== undefined)\n\t\t\t\tclipboard\n\t\t\t\t\t.writeText(value())\n\t\t\t\t\t.then(() => say(s.copied, COPIED_MS), 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\tclearTimeout(timer);\n\t\ttimer = undefined;\n\t\tnode.textContent = s.copy;\n\t\tnode.setAttribute(\"aria-label\", label);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n"
|
|
8
8
|
],
|
|
9
9
|
"mappings": ";;;;;AAeA,IAAM,OAAO,CAAC,SAAmB,KAAK,UAAU,CAAC,KAAK,OAAO,KAAK,WAAW,CAAC;AAAA;AAEvE,MAAM,cAAc;AAAA,EAEjB,SAAS,IAAI;AAAA,EAIb,aAAa,IAAI;AAAA,EAE1B,GAAG,CAAC,SAAiB,MAAyB;AAAA,IAC7C,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO;AAAA,IACrC,MAAM,UAAU,OAAO,IAAI,KAAK,IAAI,GAAG;AAAA,IACvC,IAAI,YAAY,aAAa,YAAY,KAAK,IAAI,GAAG;AAAA,MACpD,OAAO,YAAY;AAAA,IACpB;AAAA,IAEA,OAAO,OAAO,KAAK,IAAI;AAAA,IACvB,KAAK,SAAS;AAAA,IACd,OAAO;AAAA;AAAA,EAGR,GAAG,CAAC,SAAiB,MAAsB;AAAA,IAC1C,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK,IAAI;AAAA,IAC9C,MAAM,IAAI,KAAK,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,KAAK,SAAS,KAAK,KAAK,CAAC;AAAA,IACzE,KAAK,OAAO,IAAI,SAAS,KAAK;AAAA,IAC9B,KAAK,SAAS;AAAA;AAAA,EAIf,IAAI,CAAC,SAA2B;AAAA,IAC/B,OAAO,CAAC,GAAI,KAAK,OAAO,IAAI,OAA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AAAA,MACtB,OAAO;AAAA,MACP,IAAI,YAAY,KAAK,CAAC,GAAG,WAAW;AAAA;AAAA,IAErC,IAAI,cAAc;AAAA,MACjB,UACE,UAAU,MAAM,CAAC,EACjB,KAAK,MAAM,IAAI,EAAE,QAAQ,SAAS,GAAG,QAAQ;AAAA,IAChD;AAAA,MAAK,SAAS;AAAA,KAEf,WACA,IACD;AAAA,EAEA,KAAK,UAAU,IAAI,cAAc;AAAA,EACjC,MAAM,QAAQ,MAAM;AAAA,IACnB,aAAa,KAAK;AAAA,IAClB,QAAQ;AAAA,IACR,KAAK,cAAc,EAAE;AAAA,IACrB,KAAK,aAAa,cAAc,KAAK;AAAA;AAAA,EAEtC,MAAM;AAAA,EACN,OAAO,EAAE,QAAQ,MAAM,MAAM;AAAA;",
|
|
10
|
-
"debugId": "
|
|
10
|
+
"debugId": "D826109AE2BE460264756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
package/index.js
CHANGED
|
@@ -228,7 +228,7 @@ class SecretStore {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
// package.json
|
|
231
|
-
var version = "0.
|
|
231
|
+
var version = "0.17.0";
|
|
232
232
|
|
|
233
233
|
// src/version.ts
|
|
234
234
|
var LIBRARY_NAME = "@ractive-ch/tab-mcp-client";
|
|
@@ -264,6 +264,10 @@ function isAppName(value) {
|
|
|
264
264
|
return c < 32 || c >= 127 && c <= 159;
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
|
+
var APP_ID = /^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;
|
|
268
|
+
function appIdOf(name) {
|
|
269
|
+
return name.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 32).replace(/-$/, "");
|
|
270
|
+
}
|
|
267
271
|
function tabUrl(relay) {
|
|
268
272
|
let u;
|
|
269
273
|
try {
|
|
@@ -319,6 +323,7 @@ function notConnected() {
|
|
|
319
323
|
class TabMcp extends EventTarget {
|
|
320
324
|
#registry = new ToolRegistry;
|
|
321
325
|
#server;
|
|
326
|
+
#app;
|
|
322
327
|
#appName;
|
|
323
328
|
#onConfirm;
|
|
324
329
|
#alwaysAllow;
|
|
@@ -362,6 +367,11 @@ class TabMcp extends EventTarget {
|
|
|
362
367
|
if (appName !== undefined && !isAppName(appName)) {
|
|
363
368
|
throw new TypeError("TabMcp: appName must be 1-64 characters without control characters");
|
|
364
369
|
}
|
|
370
|
+
const app = options.app ?? appIdOf(server.name);
|
|
371
|
+
if (options.app !== undefined ? typeof app !== "string" || !APP_ID.test(app) : relay && app === "") {
|
|
372
|
+
throw new TypeError(options.app !== undefined ? "TabMcp: app must be 1-32 characters of a-z, 0-9 and -, not starting or ending with -" : "TabMcp: server.name has no letter a-z and no digit to make the address of: set app");
|
|
373
|
+
}
|
|
374
|
+
this.#app = app;
|
|
365
375
|
this.#relayUrl = relay?.url;
|
|
366
376
|
this.#server = { ...server };
|
|
367
377
|
this.#appName = appName;
|
|
@@ -498,13 +508,13 @@ class TabMcp extends EventTarget {
|
|
|
498
508
|
return connecting;
|
|
499
509
|
}
|
|
500
510
|
async#load() {
|
|
501
|
-
const lazy = await import("./connection-
|
|
511
|
+
const lazy = await import("./connection-gang7f5x.js");
|
|
502
512
|
for (const error of lazy.compileRegistry(this.#registry))
|
|
503
513
|
this.#emit("error", { error });
|
|
504
514
|
return lazy;
|
|
505
515
|
}
|
|
506
516
|
async#open(generation, takeBack) {
|
|
507
|
-
const { openConnection, addressIdOf
|
|
517
|
+
const { openConnection, addressIdOf } = await this.#load();
|
|
508
518
|
const relayUrl = this.#relayUrl;
|
|
509
519
|
if (relayUrl === undefined || this.#secrets === undefined)
|
|
510
520
|
return noRelay();
|
|
@@ -514,7 +524,10 @@ class TabMcp extends EventTarget {
|
|
|
514
524
|
throw new DOMException("The connection was cancelled", "AbortError");
|
|
515
525
|
}
|
|
516
526
|
const ref = {};
|
|
517
|
-
const connection = openConnection(this.#host(ref),
|
|
527
|
+
const connection = openConnection(this.#host(ref), relayUrl, secret, {
|
|
528
|
+
address,
|
|
529
|
+
revokeAll: !!takeBack
|
|
530
|
+
});
|
|
518
531
|
if (!takeBack)
|
|
519
532
|
ref.connection = connection;
|
|
520
533
|
this.#connection = connection;
|
|
@@ -717,7 +730,7 @@ class TabMcp extends EventTarget {
|
|
|
717
730
|
async#showConnectDialog(doc) {
|
|
718
731
|
const connecting = this.connect();
|
|
719
732
|
connecting.catch(() => {});
|
|
720
|
-
const { showConnectDialog } = await import("./connect-
|
|
733
|
+
const { showConnectDialog } = await import("./connect-9pefy0xe.js");
|
|
721
734
|
await showConnectDialog(this, connecting, doc, this.#server.name, this.#ui);
|
|
722
735
|
}
|
|
723
736
|
addEventListener(type, listener, options) {
|
|
@@ -766,7 +779,7 @@ class TabMcp extends EventTarget {
|
|
|
766
779
|
const doc = options.document ?? globalThis.document;
|
|
767
780
|
if (doc === undefined)
|
|
768
781
|
return Promise.resolve(false);
|
|
769
|
-
return import("./confirm-
|
|
782
|
+
return import("./confirm-vj2zbq4w.js").then((ui) => ui.confirmInPage(this, request, doc, {
|
|
770
783
|
alwaysAllow: this.#alwaysAllow,
|
|
771
784
|
ui: this.#ui
|
|
772
785
|
}));
|
|
@@ -777,6 +790,7 @@ class TabMcp extends EventTarget {
|
|
|
777
790
|
return {
|
|
778
791
|
...this.#calls,
|
|
779
792
|
server: this.#server,
|
|
793
|
+
app: this.#app,
|
|
780
794
|
appName: this.#appName,
|
|
781
795
|
tabs: this.#tabs,
|
|
782
796
|
library: { name: LIBRARY_NAME, version: VERSION },
|
|
@@ -868,5 +882,5 @@ export {
|
|
|
868
882
|
VERSION
|
|
869
883
|
};
|
|
870
884
|
|
|
871
|
-
//# debugId=
|
|
885
|
+
//# debugId=B5BE98987E47BF2C64756E2164756E21
|
|
872
886
|
//# sourceMappingURL=index.js.map
|