@ractive-ch/tab-mcp-client 0.18.1 → 0.19.0-rc.1
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 +160 -0
- package/README.md +348 -68
- package/allowed.d.ts +2 -2
- package/allowed.js.map +1 -1
- package/always-allowed.d.ts +15 -15
- package/cdn/allowed.min.js +2 -2
- package/cdn/allowed.min.js.map +2 -2
- package/cdn/confirm-ba3dkf9p.min.js +4 -0
- package/cdn/confirm-ba3dkf9p.min.js.map +10 -0
- package/cdn/connect-my0pbqd7.min.js +6 -0
- package/cdn/connect-my0pbqd7.min.js.map +12 -0
- package/cdn/connection-yf2x9zz2.min.js +17 -0
- package/cdn/{connection-0xqwz17v.min.js.map → connection-yf2x9zz2.min.js.map} +5 -5
- package/cdn/strings.min.js +4 -0
- package/cdn/strings.min.js.map +9 -0
- package/cdn/{tab-mcp-client-2vx9mcww.min.js → tab-mcp-client-8r6h3wza.min.js} +9 -8
- package/cdn/tab-mcp-client-8r6h3wza.min.js.map +11 -0
- package/cdn/tab-mcp-client-nnxcwrxp.min.js +5 -0
- package/cdn/tab-mcp-client-nnxcwrxp.min.js.map +11 -0
- package/cdn/{tab-mcp-client-5j3brdf3.min.js → tab-mcp-client-q758jr4g.min.js} +4 -4
- package/cdn/tab-mcp-client-q758jr4g.min.js.map +10 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +4 -4
- package/cdn/webmcp-84k58gsw.min.js +4 -0
- package/cdn/webmcp-84k58gsw.min.js.map +11 -0
- package/{confirm-bqfdrx3f.js → confirm-hymzwx3b.js} +7 -5
- package/confirm-hymzwx3b.js.map +10 -0
- package/confirm.d.ts +2 -2
- package/{connect-ztsgybpq.js → connect-fhtjdmf3.js} +75 -37
- package/connect-fhtjdmf3.js.map +10 -0
- package/connect.d.ts +7 -6
- package/{connection-gang7f5x.js → connection-73fbg99k.js} +70 -8
- package/connection-73fbg99k.js.map +16 -0
- package/connection.d.ts +23 -2
- package/dialog.d.ts +19 -9
- package/extension.d.ts +347 -0
- package/extension.js +394 -0
- package/extension.js.map +10 -0
- package/handshake.d.ts +82 -0
- package/index-00p8b969.js +221 -0
- package/index-00p8b969.js.map +11 -0
- package/index-1tssct09.js +58 -0
- package/index-1tssct09.js.map +11 -0
- package/{index-c1c266tm.js → index-7qqhn3zv.js} +28 -110
- package/index-7qqhn3zv.js.map +10 -0
- package/index-s31xrfa2.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +59 -64
- package/index.js.map +4 -4
- package/internal.d.ts +2 -0
- package/mcp.d.ts +5 -3
- package/package.json +11 -2
- package/protocol.d.ts +11 -1
- package/react.d.ts +11 -4
- package/react.js +57 -10
- package/react.js.map +5 -4
- package/secret.d.ts +1 -1
- package/setup.d.ts +4 -1
- package/setup.js +3 -2
- package/setup.js.map +1 -1
- package/strings.d.ts +149 -28
- package/strings.js +13 -0
- package/strings.js.map +9 -0
- package/tab-mcp.d.ts +30 -7
- package/text.d.ts +39 -0
- package/types.d.ts +76 -17
- package/webmcp-d2ec3v3g.js +221 -0
- package/webmcp-d2ec3v3g.js.map +11 -0
- package/webmcp.d.ts +17 -4
- package/cdn/confirm-d722a9eb.min.js +0 -4
- package/cdn/confirm-d722a9eb.min.js.map +0 -10
- package/cdn/connect-x6ws6wqt.min.js +0 -6
- package/cdn/connect-x6ws6wqt.min.js.map +0 -12
- package/cdn/connection-0xqwz17v.min.js +0 -17
- package/cdn/tab-mcp-client-2vx9mcww.min.js.map +0 -12
- package/cdn/tab-mcp-client-5j3brdf3.min.js.map +0 -10
- package/cdn/webmcp-khy4f5rj.min.js +0 -4
- package/cdn/webmcp-khy4f5rj.min.js.map +0 -10
- package/confirm-bqfdrx3f.js.map +0 -10
- package/connect-ztsgybpq.js.map +0 -10
- package/connection-gang7f5x.js.map +0 -16
- package/index-5jyqehpk.js +0 -63
- package/index-5jyqehpk.js.map +0 -11
- package/index-c1c266tm.js.map +0 -11
- package/webmcp-zq1enyz0.js +0 -57
- package/webmcp-zq1enyz0.js.map +0 -10
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import{n,m,g,h,c}from"./tab-mcp-client-nnxcwrxp.min.js";var H=/(?![\t\n ])[\p{Cc}\p{Cf}\p{Default_Ignorable_Code_Point}\p{Co}\p{Cn}\p{Cs}\p{Zl}\p{Zp}\p{Zs}\u{2800}]/gu;function M(o){return o.replace(H,(b)=>{let u="";for(let w=0;w<b.length;w++)u+=`\\u${b.charCodeAt(w).toString(16).toUpperCase().padStart(4,"0")}`;return u})}var I=0;function i(){return`tab-mcp-${++I}`}function a(o){return c(o?.strings)}function r(o,b,u){return b.split(/\{(\w+)\}/).map((w,v)=>{if(v%2===0)return w;let x=u[w];if(x===void 0)return`{${w}}`;return typeof x==="string"?L(o,x):x})}function e(o,b,u={},...w){let v=o.createElement(b);if(u.className!==void 0)v.className=u.className;if(u.id!==void 0)v.id=u.id;if(u.text!==void 0)v.textContent=u.text;return v.append(...w),v}function t(o,b,u,w,v){let x=e(o,"button",{text:b});if(x.type="button",w!==void 0)x.classList.add(w);if(v!==void 0)x.classList.add(`tab-mcp-${v}`);return x.addEventListener("click",u),x}function L(o,b){let u=e(o,"bdi",{text:b});return u.dir="ltr",u}function j(o,b,u,w){let v=e(o,"span",{},...g(w).formatToParts(u).map((x)=>x.type==="element"?L(o,x.value):x.value));return r(o,m(b,u.length,w),{apps:v})}var E=new WeakMap;function p(o,b,u,w,v){let x=w.length===0?"":[m(u,w.length,v),...w].join(`
|
|
2
|
+
`);if((E.get(b)??"")===x)return;E.set(b,x),b.replaceChildren(...w.length===0?[]:j(o,u,w,v))}var s=M;function d(o,b){if("kind"in o&&o.kind==="webmcp")return b.clientWebMcp;if("kind"in o&&o.kind==="local")return n(b.clientLocal,{name:s(o.name??o.id)});let u=s(o.host||o.id);return o.name!==void 0&&o.name!==""?n(b.clientRelay,{name:s(o.name),host:u}):u}var O=`.tab-mcp-dialog {
|
|
2
3
|
--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);
|
|
3
4
|
--_tab-mcp-bg: var(--tab-mcp-background, Canvas);
|
|
4
5
|
--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));
|
|
@@ -82,9 +83,9 @@ html dialog.tab-mcp-dialog :where(.tab-mcp-switch > input:disabled) { opacity: 0
|
|
|
82
83
|
.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); }
|
|
83
84
|
.tab-mcp-setup-toggle:where([aria-expanded="true"])::before { transform: translateY(-0.15em) rotate(45deg); }
|
|
84
85
|
.tab-mcp-code-used { display: flex; align-items: center; min-height: calc(var(--tab-mcp-code-size, 2em) * 1.2); }
|
|
85
|
-
.tab-mcp-
|
|
86
|
-
.tab-mcp-
|
|
87
|
-
.tab-mcp-
|
|
86
|
+
.tab-mcp-disconnect-all-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
|
|
87
|
+
.tab-mcp-disconnect-all-row > :where(small) { flex: 1 1 14rem; color: var(--_tab-mcp-muted); }
|
|
88
|
+
.tab-mcp-disconnect-all-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); }
|
|
88
89
|
.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }
|
|
89
90
|
.tab-mcp-close-note { flex: 1 1 12rem; }
|
|
90
91
|
.tab-mcp-confirm :where(p bdi) { font-weight: 600; }
|
|
@@ -95,8 +96,8 @@ html dialog.tab-mcp-dialog :where(.tab-mcp-switch > input:disabled) { opacity: 0
|
|
|
95
96
|
@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } .tab-mcp-switch > :where(input) { forced-color-adjust: none; background: Canvas; border-color: ButtonText; } .tab-mcp-switch > :where(input)::before { forced-color-adjust: none; background: ButtonText; } .tab-mcp-switch > :where(input:checked) { background: Highlight; } .tab-mcp-switch > :where(input:checked)::before { background: HighlightText; } }
|
|
96
97
|
@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
|
|
97
98
|
@keyframes tab-mcp-pop { from { opacity: 0; transform: scale(0.4); } }
|
|
98
|
-
`,
|
|
99
|
-
export{i,a,
|
|
99
|
+
`,z=new WeakMap;function A(o){try{let b=z.get(o);if(b===void 0){let u=o.defaultView?.CSSStyleSheet;if(u===void 0||!Array.isArray(o.adoptedStyleSheets))return;b=new u,b.replaceSync(O),z.set(o,b)}if(!o.adoptedStyleSheets.includes(b))o.adoptedStyleSheets=[...o.adoptedStyleSheets,b]}catch{}}function l(o,b,u,...w){let v=i(),x=e(o,"dialog",{className:`tab-mcp-dialog ${b}`});x.setAttribute("aria-labelledby",`${v}-title`),x.lang=u.lang,x.dir=h(u),A(o);let k=e(o,"h2",{id:`${v}-title`},...w);return x.append(k),{dialog:x,heading:k,id:v}}var B=2000,P=8000;function R(o,b){let u=o.defaultView;if(u?.matchMedia?.("(pointer: coarse)").matches===!0)return b.selected;let w=u?.navigator.platform??"";return/^(Mac|iP)/.test(w)?b.pressMac:b.pressOther}function f(o,b,u,w,v,x,k,N){let S,D=(_,C)=>{y.textContent=_,y.removeAttribute("aria-label"),x(_),clearTimeout(S),S=setTimeout(T,C)},y=t(o,b.copy,()=>{let _=o.defaultView?.navigator?.clipboard,C=()=>{v(),D(R(o,b),P)};if(_!==void 0)_.writeText(w()).then(()=>D(b.copied,B),C);else C()},k,N);y.classList.add("tab-mcp-copy");let T=()=>{clearTimeout(S),S=void 0,y.textContent=b.copy,y.setAttribute("aria-label",u)};return T(),{button:y,reset:T}}
|
|
100
|
+
export{i,a,r,e,t,p,s,d,l,f};
|
|
100
101
|
|
|
101
|
-
//# debugId=
|
|
102
|
-
//# sourceMappingURL=tab-mcp-client-
|
|
102
|
+
//# debugId=EC11A9A2F9C2157B64756E2164756E21
|
|
103
|
+
//# sourceMappingURL=tab-mcp-client-8r6h3wza.min.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/visible.ts", "../../src/dialog.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Text an AI app or a page wrote, made safe to show to the user before they\n * approve something: characters that are invisible, blank or turn the text's\n * direction are written as escapes, so the text cannot look like something\n * else. Shared by the library's confirmation dialog and the tab-mcp browser extension.\n */\n\n/**\n * Characters that are invisible, blank or change the direction of the text\n * around them: controls (C0 and C1, but tab and line feed, which are only\n * JSON's layout), format characters (bidi controls and isolates, zero-width\n * ones, tags), the other default-ignorable ones (variation selectors, U+034F,\n * the Hangul fillers), private-use, unassigned and lone surrogate code\n * points, line and paragraph separators, every space but the plain one\n * (U+00A0, U+2007, U+3000…) and the Braille blank (U+2800).\n */\nconst INVISIBLE =\n\t/(?![\\t\\n ])[\\p{Cc}\\p{Cf}\\p{Default_Ignorable_Code_Point}\\p{Co}\\p{Cn}\\p{Cs}\\p{Zl}\\p{Zp}\\p{Zs}\\u{2800}]/gu;\n\n/**\n * `text` with each such character as `\\uXXXX` (a surrogate pair for one\n * beyond U+FFFF), as JSON would write it: JSON stays JSON for the same value.\n */\nexport function escapeInvisible(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",
|
|
6
|
+
"/**\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, type PluralText, withEnglish } from \"./strings.ts\";\nimport { directionOf, format, listFormat, pluralForm } from \"./text.ts\";\nimport type { DialogOptions, Grant, ToolCallClient } from \"./types.ts\";\nimport { escapeInvisible } from \"./visible.ts\";\n\nexport { format, listOf, plural } from \"./text.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 (`ui.strings`) where it gave them, else English. */\nexport function stringsOf(options: DialogOptions | undefined): DialogStrings {\n\treturn withEnglish(options?.strings);\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/**\n * The form of `text` for the number of `names`, with `{apps}` the names as\n * the texts' language lists them (\"A, B and C\"), each name isolated like\n * every other name in a dialog, as nodes.\n */\nexport function pluralNames(\n\tdoc: Document,\n\ttext: PluralText,\n\tnames: string[],\n\ts: DialogStrings,\n): (Node | string)[] {\n\tconst list = el(\n\t\tdoc,\n\t\t\"span\",\n\t\t{},\n\t\t...listFormat(s)\n\t\t\t.formatToParts(names)\n\t\t\t.map((part) =>\n\t\t\t\tpart.type === \"element\" ? name(doc, part.value) : part.value,\n\t\t\t),\n\t);\n\treturn fill(doc, pluralForm(text, names.length, s), { apps: list });\n}\n\n/** What each element shows through `showNames`, so that it is made only on a change. */\nconst shownNames = new WeakMap<Element, string>();\n\n/**\n * `node` says `text` for `names` (`pluralNames`), or nothing when there are\n * none. Its nodes are made again only when the words change: a render that\n * changes nothing removes nothing (a screen reader keeps its place).\n */\nexport function showNames(\n\tdoc: Document,\n\tnode: Element,\n\ttext: PluralText,\n\tnames: string[],\n\ts: DialogStrings,\n): void {\n\tconst key =\n\t\tnames.length === 0\n\t\t\t? \"\"\n\t\t\t: [pluralForm(text, names.length, s), ...names].join(\"\\n\");\n\tif ((shownNames.get(node) ?? \"\") === key) return;\n\tshownNames.set(node, key);\n\tnode.replaceChildren(\n\t\t...(names.length === 0 ? [] : pluralNames(doc, text, names, s)),\n\t);\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/**\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) { 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: grid; flex-basis: 100%; gap: 0.25rem; padding-top: 0.5rem; border-top: 1px solid var(--_tab-mcp-line); font-size: 0.875em; overflow-wrap: anywhere; }\n.tab-mcp-allowed-title { font-weight: 600; color: var(--_tab-mcp-muted); }\n.tab-mcp-switches { display: grid; gap: 0.125rem; }\n.tab-mcp-switch { display: flex; align-items: center; gap: 0.625rem; min-height: 2rem; cursor: pointer; }\n.tab-mcp-switch > :where(input) { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 2.25rem; height: 1.25rem; margin: 0; padding: 0; border: 1px solid var(--_tab-mcp-line); border-radius: 0.625rem; background: var(--_tab-mcp-surface); cursor: pointer; }\n.tab-mcp-switch > :where(input)::before { content: \"\"; position: absolute; top: 2px; left: 2px; width: calc(1.25rem - 6px); height: calc(1.25rem - 6px); border-radius: 50%; background: var(--_tab-mcp-muted); }\n.tab-mcp-switch > :where(input:checked) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); border-color: transparent; }\n.tab-mcp-switch > :where(input:checked)::before { left: calc(100% - 1.25rem + 4px); background: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); }\nhtml dialog.tab-mcp-dialog :where(.tab-mcp-switch > input:disabled) { opacity: 0.45; cursor: not-allowed; }\n.tab-mcp-destructive { color: var(--_tab-mcp-danger); }\n.tab-mcp-everything { font-weight: 600; }\n.tab-mcp-everything-note { color: var(--_tab-mcp-muted); }\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-disconnect-all-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }\n.tab-mcp-disconnect-all-row > :where(small) { flex: 1 1 14rem; color: var(--_tab-mcp-muted); }\n.tab-mcp-disconnect-all-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); } .tab-mcp-switch > :where(input)::before { transition: left 0.15s ease-out; } }\n@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } .tab-mcp-switch > :where(input) { forced-color-adjust: none; background: Canvas; border-color: ButtonText; } .tab-mcp-switch > :where(input)::before { forced-color-adjust: none; background: ButtonText; } .tab-mcp-switch > :where(input:checked) { background: Highlight; } .tab-mcp-switch > :where(input:checked)::before { background: HighlightText; } }\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` of the strings, and\n * `dir` or the direction of that language), whatever the page's: read out\n * 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 = directionOf(s);\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"
|
|
7
|
+
],
|
|
8
|
+
"mappings": "wDAgBA,IAAM,EACL,0GAMM,SAAS,CAAe,CAAC,EAAsB,CACrD,OAAO,EAAK,QAAQ,EAAW,CAAC,IAAO,CACtC,IAAI,EAAU,GACd,QAAS,EAAI,EAAG,EAAI,EAAG,OAAQ,IAC9B,GAAW,MAAM,EAAG,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,EAAG,GAAG,IAC7E,OAAO,EACP,ECdF,IAAI,EAAU,EAGP,SAAS,CAAM,EAAW,CAChC,MAAO,WAAW,EAAE,IAId,SAAS,CAAS,CAAC,EAAmD,CAC5E,OAAO,EAAY,GAAS,OAAO,EAQ7B,SAAS,CAAI,CACnB,EACA,EACA,EACoB,CACpB,OAAO,EAAS,MAAM,WAAW,EAAE,IAAI,CAAC,EAAM,IAAM,CACnD,GAAI,EAAI,IAAM,EAAG,OAAO,EACxB,IAAM,EAAQ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O,CAAE,GAEvB,EAAO,EACZ,EACA,EAAE,KACF,IAAM,CACL,IAAM,EAAa,EAAI,aAAa,WACjC,UACG,EAAW,IAAM,CACtB,EAAO,EACP,EAAI,EAAY,EAAK,CAAC,EAAG,CAAW,GAErC,GAAI,IAAc,OACjB,EACE,UAAU,EAAM,CAAC,EACjB,KAAK,IAAM,EAAI,EAAE,OAAQ,CAAS,EAAG,CAAQ,EAChD,KAAK,EAAS,GAEf,EACA,CACD,EAEA,EAAK,UAAU,IAAI,cAAc,EACjC,IAAM,EAAQ,IAAM,CACnB,aAAa,CAAK,EAClB,EAAQ,OACR,EAAK,YAAc,EAAE,KACrB,EAAK,aAAa,aAAc,CAAK,GAGtC,OADA,EAAM,EACC,CAAE,OAAQ,EAAM,OAAM",
|
|
9
|
+
"debugId": "EC11A9A2F9C2157B64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function n(e,t){return e.replace(/\{(\w+)\}/g,(a,o)=>t[o]??a)}function f(e,t){try{return e(t)}catch{return e("en")}}var w=(e)=>typeof e==="object"&&e!==null&&typeof e.other==="string"&&Object.values(e).every((t)=>typeof t==="string"),p=new WeakSet;function A(e){if(e===void 0||p.has(e))return;if(Object.entries(e).filter(([a,o])=>a!=="lang"&&a!=="dir"&&o!==void 0).length===0||typeof e.lang==="string")return;p.add(e),console.warn("tab-mcp: ui.strings has texts but no lang, so they count as English (plural forms, lists, the dialogs' lang). Add lang, the language tag of the texts.")}function m(e,t,a){let o=f((r)=>new Intl.PluralRules(r),a.lang).select(t);return n(e[o]??e.other,{n:String(t)})}function u(e,t,a,o={}){return n(m(e,t,a),o)}function g(e){return f((t)=>new Intl.ListFormat(t,{type:"conjunction"}),e.lang)}function h(e){if(e.dir!==void 0)return e.dir;try{let t=new Intl.Locale(e.lang);return(t.getTextInfo?.()??t.textInfo)?.direction==="rtl"?"rtl":"ltr"}catch{return"ltr"}}var C={lang:"en",confirmTitle:"Allow {tool}?",confirmWho:"{client} wants to run {tool}.",deny:"Don't allow",allow:"Allow once",alwaysAllow:"Always allow",alwaysAllowNote:"Always allow: {tool} will run for {client} without asking, with any arguments, until you disconnect {client} from this page.",allowUntilReload:"Allow until reload",allowUntilReloadNote:"Allow until reload: {tool} will run for {client} without asking, with any arguments, until you reload this page or disconnect {client}.",argumentsHidden:"The arguments cannot be shown, so this call cannot be allowed.",scrollToAllow:"Scroll to the end of the arguments to allow this call.",waiting:{one:"{n} more call is waiting after this one.",other:"{n} more calls are waiting after this one."},titlePrefix:"Allow? – ",clientWebMcp:"An agent in this browser",clientLocal:"{name} (this site's assistant)",clientRelay:"{name} ({host})",copy:"Copy",copied:"Copied",pressMac:"Press ⌘C",pressOther:"Press Ctrl+C",selected:"Selected",copyAddress:"Copy address",copyCode:"Copy code",copyCommand:"Copy {app} command",connectTitle:"Connect your AI app",viaExtension:{one:"{apps} is connected through the tab-mcp browser extension.",other:"{apps} are connected through the tab-mcp browser extension."},viaExtensionInFront:{one:"{apps} is connected through the tab-mcp browser extension, while this tab is in front.",other:"{apps} are connected through the tab-mcp browser extension, while this tab is in front."},connecting:"Connecting…",connectAgain:"Connect again",reconnecting:"Connection lost. Reconnecting…",notConnected:"Not connected.",unreachable:"Could not connect. Check your internet connection.",rateLimited:"Too many attempts. Wait a minute, then connect again.",refused:"The connection was refused.",ended:"The session ended.",lost:"The connection was lost.",closed:"The connection was closed.",disconnected:"Disconnected.",checkingSignIn:"Checking your sign-in…",signInFirst:"Sign in to this page first.",signInRefused:"Your sign-in on this page was not accepted.",signInRefusedWhy:"Your sign-in on this page was not accepted ({reason}).",readyApp:"{app} is ready for your AI app.",readyPage:"This page is ready for your AI app.",addressLabel:"Add this address to your AI app:",help:"How do I add it?",guide:"Step by step, and what to do when it fails",codeSentence:"When asked, type the code {code}",codeNote:"The code changes every 2 minutes and after each use.",codeUsed:"Code used. Waiting for your AI app…",signIn:"When your AI app asks, sign in with the account you use on this page. No code is needed.",signInUntil:"Your AI app can connect until {time}.",signInTimeUp:"The time to connect your AI app is up. To connect it now, continue.",continuePairing:"Continue",disconnectAll:"Disconnect all apps",disconnectAllNote:"An AI app is connected that should not be? This disconnects every AI app from this page; each one has to connect again.",disconnectAllQuestion:{one:"This disconnects {apps}. To use this page with it again, connect it again.",other:"This disconnects {apps}. To use this page with them again, connect them again."},disconnectAllConfirm:"Disconnect all apps",cancel:"Cancel",disconnectingAll:"Disconnecting…",disconnectAllDone:"Every AI app is disconnected. Connect yours again.",connected:{one:"{apps} is connected",other:"{apps} are connected"},connectedNext:{one:"You can close this now and ask it to use the tools of this page.",other:"You can close this now and ask them to use the tools of this page."},connectAnother:"Connect another AI app",connectedHeading:"Connected AI apps",appConnected:"{app} connected",disconnect:"Disconnect",disconnectApp:"Disconnect {app}",disconnectNote:"To disconnect an AI app, connect this page again first.",storeUnavailable:"The relay could not save this. Try again.",disconnectFailed:"Could not disconnect the AI app. Try again.",destructive:"destructive",allowToolApp:"{tool} runs without asking for {app}",allowDestructiveToolApp:"{tool} (destructive) runs without asking for {app}",allowEverything:"Always allow everything",allowEverythingApp:"Always allow everything for {app}",allowEverythingNote:"Every tool of this page runs for {app} without asking, with any arguments: also tools you have not seen yet and ones that delete or overwrite, until you disconnect {app}.",allowEverythingUntilReloadNote:"Every tool of this page runs for {app} without asking, with any arguments: also tools you have not seen yet and ones that delete or overwrite, until you reload this page or disconnect {app}.",closeNote:"Closing this ends the code. To connect an AI app later, open this again from the page.",close:"Close",done:"Done",setupClaudeApp:"Claude (claude.ai and the desktop app)",setupClaude:"Settings → Connectors → Add custom connector, then paste the address.",setupChatGpt:"On chatgpt.com: Plugins, add an MCP server with the address, then Connect. The Mac app needs more steps: see the guide.",setupRun:"Run:",setupClaudeCode:"Add the address with claude mcp add --transport http.",setupClaudeCodeNote:"Then type {command} in Claude Code and choose Authenticate.",setupCodex:"Run codex features enable {feature}, then add the address with codex mcp add --url and sign in with codex mcp login.",setupCodexNote:"The last line opens the sign-in that asks for the code. Start a new chat in Codex after it connects.",buttonReconnecting:"Reconnecting…",buttonConnected:{one:"AI app connected",other:"{n} AI apps connected"},replacedSiblingTitle:"Opened in another tab",replacedSibling:"This page is open in another tab, and your AI apps now use that one. To use them here, connect this page again.",replacedTitle:"Another tab or program took over this page",replaced:"Your AI apps now use that tab or program instead of this page. If you did not open this page in another tab or window of this browser, someone may have copied this page's saved connection. “Disconnect all apps” ends that; then connect your AI apps again.",takenOverAgain:"It was taken over again before its AI apps were disconnected. Try again.",tryAgainOrClose:"{reason} Try again, or close this."},y=C;function c(e){A(e);let t={...y};for(let[a,o]of Object.entries(e??{})){let r=t[a];if(a==="dir"?o==="ltr"||o==="rtl":typeof r==="string"?typeof o==="string":r!==void 0&&w(o))t[a]=o}return t}function l(e){let t=e.toLowerCase().split("-")[0]??"";try{let{script:a,region:o}=new Intl.Locale(e).maximize();return{language:t,...a===void 0?{}:{script:a},...o===void 0?{}:{region:o}}}catch{return{language:t}}}function I(e,t){let a=e.find((i)=>i.toLowerCase()===t.toLowerCase());if(a!==void 0)return a;let o=l(t),r=(i)=>{let s=l(i);return(s.script!==void 0&&s.script===o.script?4:0)+(s.region!==void 0&&s.region===o.region?2:0)+(i.toLowerCase()===o.language?1:0)};return e.filter((i)=>l(i).language===o.language).sort((i,s)=>r(s)-r(i)||(i<s?-1:i>s?1:0))[0]}async function b(e,t=globalThis.navigator?.languages??[]){let a=Object.keys(e);for(let o of t){let r=I(a,o);if(r!==void 0)try{let i=await e[r](),s=typeof i==="object"&&i!==null&&"default"in i?i.default:i;if(typeof s!=="object"||s===null)throw TypeError(`not a table of texts: ${String(s)}`);let d=s;return{...d,lang:d.lang??r}}catch(i){console.warn(`tab-mcp: could not load the texts for ${r}; English instead.`,i);return}if(l(o).language==="en")return}return}
|
|
2
|
+
export{n,m,u,g,h,y,c,b};
|
|
3
|
+
|
|
4
|
+
//# debugId=E4D5AB09F0FE9C1E64756E2164756E21
|
|
5
|
+
//# sourceMappingURL=tab-mcp-client-nnxcwrxp.min.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/text.ts", "../../src/strings.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Filling in the texts of `strings.ts`: placeholders, plural forms and lists,\n * by the rules of the texts' language (`Intl`), not by grammar made by hand.\n * No DOM and no texts, so that `./react` can use it without loading the\n * table, as well as the dialogs.\n */\n\nimport type { DialogStrings, PluralText } from \"./strings.ts\";\n\n/** What the helpers need of the texts: their language. */\ntype InLanguage = { lang: string };\n\n/** `template` with its `{name}` placeholders filled in, as text. */\nexport function format(\n\ttemplate: string,\n\tvalues: Record<string, string>,\n): string {\n\treturn template.replace(\n\t\t/\\{(\\w+)\\}/g,\n\t\t(all, key: string) => values[key] ?? all,\n\t);\n}\n\n/**\n * `Intl` objects for the texts' language; a `lang` the browser cannot\n * read (a malformed tag throws) uses English rules instead.\n */\nfunction inLanguage<T>(make: (lang: string) => T, lang: string): T {\n\ttry {\n\t\treturn make(lang);\n\t} catch {\n\t\treturn make(\"en\");\n\t}\n}\n\n/** Whether `value` is a plural text: an object of strings with `other`. */\nexport const isPlural = (value: unknown): value is PluralText =>\n\ttypeof value === \"object\" &&\n\tvalue !== null &&\n\ttypeof (value as { other?: unknown }).other === \"string\" &&\n\tObject.values(value).every((form) => typeof form === \"string\");\n\nconst warned = new WeakSet<object>();\n\n/**\n * A table with texts but no `lang` is taken as English: its plural forms\n * follow English rules and the dialogs say `lang=\"en\"`. Said once per table\n * in the console, as it is almost always a translation that forgot its tag.\n */\nexport function warnWithoutLang(strings: object | undefined): void {\n\tif (strings === undefined || warned.has(strings)) return;\n\tconst texts = Object.entries(strings).filter(\n\t\t([key, value]) => key !== \"lang\" && key !== \"dir\" && value !== undefined,\n\t);\n\tif (texts.length === 0 || typeof (strings as InLanguage).lang === \"string\")\n\t\treturn;\n\twarned.add(strings);\n\tconsole.warn(\n\t\t\"tab-mcp: ui.strings has texts but no lang, so they count as English (plural forms, lists, the dialogs' lang). Add lang, the language tag of the texts.\",\n\t);\n}\n\n/**\n * The form of `text` for the count `n`, by the plural rules of the texts'\n * language, with `{n}` filled in; `other` where the table lacks the form.\n */\nexport function pluralForm(text: PluralText, n: number, s: InLanguage): string {\n\tconst category = inLanguage((l) => new Intl.PluralRules(l), s.lang).select(n);\n\treturn format(text[category] ?? text.other, { n: String(n) });\n}\n\n/** `pluralForm` with the other placeholders filled in too, as text. */\nexport function plural(\n\ttext: PluralText,\n\tn: number,\n\ts: InLanguage,\n\tvalues: Record<string, string> = {},\n): string {\n\treturn format(pluralForm(text, n, s), values);\n}\n\n/** How the texts' language joins a list (\"A, B and C\"). */\nexport function listFormat(s: InLanguage): Intl.ListFormat {\n\treturn inLanguage(\n\t\t(l) => new Intl.ListFormat(l, { type: \"conjunction\" }),\n\t\ts.lang,\n\t);\n}\n\n/** \"A and B\", \"A, B and C\", as the texts' language joins a list. */\nexport function listOf(items: string[], s: InLanguage): string {\n\treturn listFormat(s).format(items);\n}\n\n/**\n * The direction of the texts: their own `dir`, else the one the browser\n * knows for `lang` (`Intl.Locale`'s text info, not in every browser), else\n * left to right.\n */\nexport function directionOf(s: DialogStrings): \"ltr\" | \"rtl\" {\n\tif (s.dir !== undefined) return s.dir;\n\ttry {\n\t\tconst locale = new Intl.Locale(s.lang) as Intl.Locale & {\n\t\t\tgetTextInfo?: () => { direction?: string };\n\t\t\ttextInfo?: { direction?: string };\n\t\t};\n\t\tconst info = locale.getTextInfo?.() ?? locale.textInfo;\n\t\treturn info?.direction === \"rtl\" ? \"rtl\" : \"ltr\";\n\t} catch {\n\t\treturn \"ltr\";\n\t}\n}\n",
|
|
6
|
+
"/**\n * `@ractive-ch/tab-mcp-client/strings`: every text the library can show to\n * a person, in English, in one table (`STRINGS`), `pickStrings` to choose\n * a page's own translation by the user's languages, and `withEnglish` for\n * a page that shows these texts in its own UI. The package ships English only;\n * a page passes its own table once, as `ui.strings` of `TabMcp` (or of\n * `<TabMcpProvider>`), and every missing key stays English.\n *\n * `{name}` is a placeholder the library fills in: names of tools and AI\n * apps (isolated, so that they cannot reorder the sentence), the code,\n * counts. A text that depends on a count is a {@link PluralText}, one form\n * per plural category of the language (`Intl.PluralRules`). Lists of names\n * are joined by `Intl.ListFormat`. Both follow `lang`, the language of the\n * texts, which the dialogs also set on themselves with its direction.\n *\n * Texts an AI app reads (tool results, refusals) are not here: they stay\n * English on purpose, as the AI app quotes them back in its own words.\n */\n\nimport { isPlural, warnWithoutLang } from \"./text.ts\";\n\n/**\n * A text that depends on a count `{n}` (or on the number of names in a\n * list): one form per plural category the language has, as\n * `Intl.PluralRules` names them. `other` is required; English needs `one`\n * and `other`, Polish `one`, `few`, `many` and `other`, Japanese only\n * `other`. A category the table lacks uses `other`.\n */\nexport type PluralText = { other: string } & {\n\t[category in Intl.LDMLPluralRule]?: string;\n};\n\nconst english = {\n\t/**\n\t * The language of the texts (a BCP 47 tag): set on every dialog, and the\n\t * language `Intl.PluralRules` and `Intl.ListFormat` follow.\n\t */\n\tlang: \"en\",\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 once\",\n\t/** `alwaysAllow: true`: kept until the AI app is disconnected. */\n\talwaysAllow: \"Always allow\",\n\talwaysAllowNote:\n\t\t\"Always allow: {tool} will run for {client} without asking, with any arguments, until you disconnect {client} from this page.\",\n\t/** `alwaysAllow: \"until-reload\"`, or kept in memory only (`storage: null`). */\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\twaiting: {\n\t\tone: \"{n} more call is waiting after this one.\",\n\t\tother: \"{n} more calls are waiting after this one.\",\n\t},\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; its title is also `ConnectButton`'s label.\n\tconnectTitle: \"Connect your AI app\",\n\t/**\n\t * At the top, while AI apps reach the page through the tab-mcp browser\n\t * extension (`TabMcp.extension`, DEC-207); `…InFront` when the extension\n\t * serves only the tab in front, as it does. `{apps}`: their names, as a\n\t * list.\n\t */\n\tviaExtension: {\n\t\tone: \"{apps} is connected through the tab-mcp browser extension.\",\n\t\tother: \"{apps} are connected through the tab-mcp browser extension.\",\n\t},\n\tviaExtensionInFront: {\n\t\tone: \"{apps} is connected through the tab-mcp browser extension, while this tab is in front.\",\n\t\tother:\n\t\t\t\"{apps} are connected through the tab-mcp browser extension, while this tab is in front.\",\n\t},\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, type the code {code}\",\n\tcodeNote: \"The code changes 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\t/** Under `signIn`: until when the relay pairs a sign-in (`{time}`: hours and minutes). */\n\tsignInUntil: \"Your AI app can connect until {time}.\",\n\t/** The status once that time is up; Continue starts it again. */\n\tsignInTimeUp:\n\t\t\"The time to connect your AI app is up. To connect it now, continue.\",\n\tcontinuePairing: \"Continue\",\n\tdisconnectAll: \"Disconnect all apps\",\n\tdisconnectAllNote:\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.\",\n\t/** `{apps}`: the AI apps it disconnects, as a list. */\n\tdisconnectAllQuestion: {\n\t\tone: \"This disconnects {apps}. To use this page with it again, connect it again.\",\n\t\tother:\n\t\t\t\"This disconnects {apps}. To use this page with them again, connect them again.\",\n\t},\n\t/** Repeats the button that asked. */\n\tdisconnectAllConfirm: \"Disconnect all apps\",\n\tcancel: \"Cancel\",\n\tdisconnectingAll: \"Disconnecting…\",\n\tdisconnectAllDone: \"Every AI app is disconnected. Connect yours again.\",\n\t/** `{apps}`: the connected AI apps, as a list. */\n\tconnected: { one: \"{apps} is connected\", other: \"{apps} are connected\" },\n\tconnectedNext: {\n\t\tone: \"You can close this now and ask it to use the tools of this page.\",\n\t\tother: \"You can close this now and ask them to use the tools of this page.\",\n\t},\n\tconnectAnother: \"Connect another AI app\",\n\tconnectedHeading: \"Connected AI apps\",\n\tappConnected: \"{app} connected\",\n\tdisconnect: \"Disconnect\",\n\tdisconnectApp: \"Disconnect {app}\",\n\tdisconnectNote: \"To disconnect an AI 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 AI app. Try again.\",\n\t// Under a connected AI app: a switch per tool that asks, and one for all,\n\t// headed by the confirmation's own label (`alwaysAllow` or\n\t// `allowUntilReload`), so that the button and its switches read alike.\n\t/** After a tool's name: it may delete or overwrite (`destructiveHint`). */\n\tdestructive: \"destructive\",\n\t/** A tool's switch, as read out: starts with what it shows (WCAG 2.5.3). */\n\tallowToolApp: \"{tool} runs without asking for {app}\",\n\tallowDestructiveToolApp: \"{tool} (destructive) runs without asking for {app}\",\n\tallowEverything: \"Always allow everything\",\n\tallowEverythingApp: \"Always allow everything for {app}\",\n\t/** Kept until the AI app is disconnected (`alwaysAllow: true`). */\n\tallowEverythingNote:\n\t\t\"Every tool of this page runs for {app} without asking, with any arguments: also tools you have not seen yet and ones that delete or overwrite, until you disconnect {app}.\",\n\t/** Kept in memory only (`alwaysAllow: \"until-reload\"`, `storage: null`). */\n\tallowEverythingUntilReloadNote:\n\t\t\"Every tool of this page runs for {app} without asking, with any arguments: also tools you have not seen yet and ones that delete or overwrite, until you reload this page or disconnect {app}.\",\n\tcloseNote:\n\t\t\"Closing this ends the code. To connect an AI app later, open this again from the page.\",\n\tclose: \"Close\",\n\tdone: \"Done\",\n\n\t// The steps under \"How do I add it?\" (`setupInstructions`).\n\tsetupClaudeApp: \"Claude (claude.ai and the desktop app)\",\n\tsetupClaude:\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\tsetupChatGpt:\n\t\t\"On chatgpt.com: Plugins, add an MCP server with the address, then Connect. The Mac app needs more steps: see the guide.\",\n\t/** Before a command to run in a terminal. */\n\tsetupRun: \"Run:\",\n\t/** Without a command (an address a shell would not read as plain). */\n\tsetupClaudeCode: \"Add the address with claude mcp add --transport http.\",\n\t/** `{command}`: `/mcp`, shown as code. */\n\tsetupClaudeCodeNote:\n\t\t\"Then type {command} in Claude Code and choose Authenticate.\",\n\t/** Without a command; `{feature}`: the Codex feature to turn on. */\n\tsetupCodex:\n\t\t\"Run codex features enable {feature}, then add the address with codex mcp add --url and sign in with codex mcp login.\",\n\tsetupCodexNote:\n\t\t\"The last line opens the sign-in that asks for the code. Start a new chat in Codex after it connects.\",\n\n\t// `ConnectButton` of `./react`; otherwise it says `connectTitle`,\n\t// `connecting` or, after a few failed attempts, `reconnecting`.\n\t/** While reconnecting, before it says the connection is lost. */\n\tbuttonReconnecting: \"Reconnecting…\",\n\tbuttonConnected: { one: \"AI app connected\", other: \"{n} AI apps connected\" },\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 use that tab or program instead of this page. If you did not open this page in another tab or window of this browser, someone may have copied this page's saved connection. “Disconnect all apps” ends that; then connect your AI apps again.\",\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/**\n * The texts of the library, key by key: each a string, or a\n * {@link PluralText} where it depends on a count. `dir` is the direction of\n * the texts; without it, the dialogs take it from `lang` where the browser\n * knows it (`Intl.Locale`), else left to right: set `dir: \"rtl\"` for a\n * right-to-left language to be sure.\n *\n * Type a translation as `DialogStrings` and the type check names every key\n * it lacks or misspells, also after an upgrade added one; as\n * `Partial<DialogStrings>` it may leave keys out (they stay English).\n */\nexport type DialogStrings = {\n\t[K in keyof typeof english]: (typeof english)[K] extends string\n\t\t? string\n\t\t: PluralText;\n} & { dir?: \"ltr\" | \"rtl\" };\n\n/** The English texts, the defaults for every key. */\nexport const STRINGS: DialogStrings = english;\n\n/**\n * Every text: `strings` where it has one of the right kind, English for\n * the rest. A missing translation (`undefined`), an unknown key or a plain\n * string where the English text has plural forms keeps the English text:\n * a table from an older version still works, only less translated. A table\n * with texts but no `lang` counts as English, and the console says so once.\n */\nexport function withEnglish(\n\tstrings: Partial<DialogStrings> | undefined,\n): DialogStrings {\n\twarnWithoutLang(strings);\n\tconst s: Record<string, unknown> = { ...STRINGS };\n\tfor (const [key, value] of Object.entries(strings ?? {})) {\n\t\tconst english = s[key];\n\t\tif (\n\t\t\tkey === \"dir\"\n\t\t\t\t? value === \"ltr\" || value === \"rtl\"\n\t\t\t\t: typeof english === \"string\"\n\t\t\t\t\t? typeof value === \"string\"\n\t\t\t\t\t: english !== undefined && isPlural(value)\n\t\t)\n\t\t\ts[key] = value;\n\t}\n\treturn s as DialogStrings;\n}\n\n/** A table of texts, or a module whose default export is one. */\ntype Loaded = Partial<DialogStrings> | { default: Partial<DialogStrings> };\n\n/** A tag's language, script and region, as the browser fills them in. */\nfunction subtags(tag: string): {\n\tlanguage: string;\n\tscript?: string;\n\tregion?: string;\n} {\n\tconst language = tag.toLowerCase().split(\"-\")[0] ?? \"\";\n\ttry {\n\t\tconst { script, region } = new Intl.Locale(tag).maximize();\n\t\treturn {\n\t\t\tlanguage,\n\t\t\t...(script === undefined ? {} : { script }),\n\t\t\t...(region === undefined ? {} : { region }),\n\t\t};\n\t} catch {\n\t\treturn { language };\n\t}\n}\n\n/**\n * Of the tags in `tags`, the one for the user's language `wanted`: the same\n * tag; else, among those of the same language, the one with the same script\n * (`zh-TW` is written `Hant`, so it takes `zh-Hant` over `zh-Hans` or `zh`),\n * then the same region, then the language alone (`de-CH` takes `de` over\n * `de-AT`), then the first in alphabetical order. The browser's likely\n * subtags (`Intl.Locale.maximize`) fill in what a tag leaves out.\n */\nfunction matchTag(tags: string[], wanted: string): string | undefined {\n\tconst exact = tags.find((t) => t.toLowerCase() === wanted.toLowerCase());\n\tif (exact !== undefined) return exact;\n\tconst want = subtags(wanted);\n\tconst score = (tag: string) => {\n\t\tconst has = subtags(tag);\n\t\treturn (\n\t\t\t(has.script !== undefined && has.script === want.script ? 4 : 0) +\n\t\t\t(has.region !== undefined && has.region === want.region ? 2 : 0) +\n\t\t\t(tag.toLowerCase() === want.language ? 1 : 0)\n\t\t);\n\t};\n\treturn tags\n\t\t.filter((t) => subtags(t).language === want.language)\n\t\t.sort((a, b) => score(b) - score(a) || (a < b ? -1 : a > b ? 1 : 0))[0];\n}\n\n/**\n * The page's own table for the user's language, loaded only once chosen:\n * `tables` maps language tags (`\"de\"`, `\"pt-BR\"`, `\"zh-Hant\"`) to functions\n * that load one, such as `() => import(\"./tab-mcp.de.ts\")`. The user's\n * languages (`navigator.languages`, most preferred first) are tried in\n * order; each takes the same tag, else a table of the same language: the\n * same script first, then the same region, then the language alone, then\n * the first in alphabetical order. English is built in: a user who prefers\n * English before any of the tables, or none of them, gets `undefined`,\n * which keeps the English texts. The table comes with `lang` set to the\n * matched tag unless it has its own.\n *\n * It never rejects: a table that fails to load (a chunk gone after a\n * deploy, offline) or is not an object is said in the console and gives\n * `undefined`, so the page still starts, in English.\n *\n * ```ts\n * const strings = await pickStrings({ de: () => import(\"./tab-mcp.de.ts\") });\n * const mcp = new TabMcp({ relay, server, ui: { strings } });\n * ```\n */\nexport async function pickStrings(\n\ttables: Record<string, () => Promise<Loaded>>,\n\tlanguages: readonly string[] = globalThis.navigator?.languages ?? [],\n): Promise<Partial<DialogStrings> | undefined> {\n\tconst tags = Object.keys(tables);\n\tfor (const wanted of languages) {\n\t\tconst tag = matchTag(tags, wanted);\n\t\tif (tag !== undefined) {\n\t\t\ttry {\n\t\t\t\tconst loaded: unknown = await (tables[tag] as () => Promise<Loaded>)();\n\t\t\t\tconst table: unknown =\n\t\t\t\t\ttypeof loaded === \"object\" && loaded !== null && \"default\" in loaded\n\t\t\t\t\t\t? loaded.default\n\t\t\t\t\t\t: loaded;\n\t\t\t\tif (typeof table !== \"object\" || table === null)\n\t\t\t\t\tthrow new TypeError(`not a table of texts: ${String(table)}`);\n\t\t\t\tconst texts = table as Partial<DialogStrings>;\n\t\t\t\treturn { ...texts, lang: texts.lang ?? tag };\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`tab-mcp: could not load the texts for ${tag}; English instead.`,\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t\t// English is built in: the user reads it before any later language.\n\t\tif (subtags(wanted).language === \"en\") return undefined;\n\t}\n\treturn undefined;\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": "AAaO,SAAS,CAAM,CACrB,EACA,EACS,CACT,OAAO,EAAS,QACf,aACA,CAAC,EAAK,IAAgB,EAAO,IAAQ,CACtC,EAOD,SAAS,CAAa,CAAC,EAA2B,EAAiB,CAClE,GAAI,CACH,OAAO,EAAK,CAAI,EACf,KAAM,CACP,OAAO,EAAK,IAAI,GAKX,IAAM,EAAW,CAAC,IACxB,OAAO,IAAU,UACjB,IAAU,MACV,OAAQ,EAA8B,QAAU,UAChD,OAAO,OAAO,CAAK,EAAE,MAAM,CAAC,IAAS,OAAO,IAAS,QAAQ,EAExD,EAAS,IAAI,QAOZ,SAAS,CAAe,CAAC,EAAmC,CAClE,GAAI,IAAY,QAAa,EAAO,IAAI,CAAO,EAAG,OAIlD,GAHc,OAAO,QAAQ,CAAO,EAAE,OACrC,EAAE,EAAK,KAAW,IAAQ,QAAU,IAAQ,OAAS,IAAU,MAChE,EACU,SAAW,GAAK,OAAQ,EAAuB,OAAS,SACjE,OACD,EAAO,IAAI,CAAO,EAClB,QAAQ,KACP,wJACD,EAOM,SAAS,CAAU,CAAC,EAAkB,EAAW,EAAuB,CAC9E,IAAM,EAAW,EAAW,CAAC,IAAM,IAAI,KAAK,YAAY,CAAC,EAAG,EAAE,IAAI,EAAE,OAAO,CAAC,EAC5E,OA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AAQ,KACP,yCAAyC,sBACzC,CACD,EACA,OAIF,GAAI,EAAQ,CAAM,EAAE,WAAa,KAAM,OAExC",
|
|
9
|
+
"debugId": "E4D5AB09F0FE9C1E64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function m(e){if(e===void 0)return"";let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619)>>>0;return t.toString(16)}var d=(e)=>typeof e==="string";function T(e){let t={secret:"",grants:new Map},n;try{n=JSON.parse(e)}catch{return t}let s=n;if(!d(s?.secret)||!Array.isArray(s.grants))return t;let
|
|
2
|
-
export{
|
|
1
|
+
function m(e){if(e===void 0)return"";let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619)>>>0;return t.toString(16)}var d=(e)=>typeof e==="string";function T(e){let t={secret:"",grants:new Map},n;try{n=JSON.parse(e)}catch{return t}let s=n;if(!d(s?.secret)||!Array.isArray(s.grants))return t;let r=new Map;for(let i of s.grants){let l=i;if(!d(l?.grantId)||typeof l.everything!=="boolean"||!Array.isArray(l.tools))return t;let g=[];for(let w of l.tools){let a=w;if(!d(a?.name)||!d(a.description)||a.title!==void 0&&!d(a.title))return t;g.push(c(a))}r.set(l.grantId,{everything:l.everything,tools:g})}return{secret:s.secret,grants:r}}function k(e){return JSON.stringify({secret:e.secret,grants:[...e.grants].map(([t,n])=>({grantId:t,...n}))})}function c(e){let t={name:e.name,description:e.description};if(e.title!==void 0)t.title=e.title;return t}var y=(e,t)=>e.title===t.title&&e.description===t.description,f=(e,t)=>t===void 0||y(e,t),S={list:()=>[],get:()=>{return},onChange:()=>()=>{}},h=(e)=>typeof e==="function";function b(e){if(!Array.isArray(e)||e.length!==3)return!1;let[t,n,s]=e,r=t,i=n;return["register","list","get","onChange"].every((l)=>h(r?.[l]))&&(i===void 0||h(i?.current))&&[void 0,!0,!1,"until-reload"].includes(s)}function v(e){let t=e._allowed;return b(t)?t:[S,void 0,void 0]}class p{kept;offered;#f;#o;#d;#n;#r;#t={secret:"",grants:new Map};#g=!1;#i=new Set;#l;constructor(e){let[t,n,s]=v(e);this.#f=e,this.#o=t,this.#d=()=>m(n?.current()),this.#n=s==="until-reload"?null:n?.storage??null,this.#r=`${n?.key}#allowed`,this.kept=this.#n!==null,this.offered=s===!0||s==="until-reload"}tools=()=>this.#o.list().filter((e)=>e.annotations.consequentialHint===!0&&(e.callers?.includes("relay")??!0)).map((e)=>{let t={name:e.name,description:e.description,destructive:e.annotations.destructiveHint===!0};if(e.title!==void 0)t.title=e.title;return t});list=(e)=>(this.#e().get(e)?.tools??[]).filter((t)=>f(t,this.#o.get(t.name))).map((t)=>t.name);has=(e,t)=>{let n=this.#o.get(t);return this.#a(e)&&(this.everything(e)||n!==void 0&&this.allows(e,n))};allows(e,t){if(!this.#a(e))return!1;let n=this.#e().get(e);if(n===void 0)return!1;if(n.everything)return!0;let s=n.tools.find((r)=>r.name===t.name);return s!==void 0&&y(s,t)}allow=(e,t)=>{let n=this.tools().find((s)=>s.name===t);if(n!==void 0)this.keep(e,n)};keep(e,t){if(!this.#a(e))return;let n=this.#e(),s=n.get(e)??{everything:!1,tools:[]};s.tools=[...s.tools.filter((r)=>r.name!==t.name),c(t)],n.set(e,s),this.#s(n)}ask=(e,t)=>{let n=this.#e(),s=n.get(e);if(s===void 0)return;let r=s.tools.filter((i)=>i.name!==t);if(!s.everything&&r.length===s.tools.length)return;if(s.everything=!1,s.tools=r,r.length===0)n.delete(e);this.#s(n)};everything=(e)=>this.#e().get(e)?.everything===!0;setEverything=(e,t)=>{if(t&&!this.#a(e))return;let n=this.#e(),s=n.get(e)??{everything:!1,tools:[]};if(s.everything===t)return;if(s.everything=t,t||s.tools.length>0)n.set(e,s);else n.delete(e);this.#s(n)};forget=(e)=>{let t=this.#e();if(t.delete(e))this.#s(t)};keepGrants(e){let t=new Set(e),n=this.#e(),s=this.#t.grants!==n&&this.#t.grants.size>0;for(let r of[...n.keys()])if(!t.has(r))s=n.delete(r)||s;if(s)this.#s(n)}toolsChanged(){let e=this.#e(),t=!1;for(let[n,s]of[...e]){let r=s.tools.filter((i)=>f(i,this.#o.get(i.name)));if(r.length===s.tools.length)continue;if(t=!0,s.tools=r,!s.everything&&r.length===0)e.delete(n)}if(t)this.#s(e);else this.#h()}onChange=(e)=>(this.#i.add(e),this.#u(),()=>{if(this.#i.delete(e),this.#i.size===0)this.#l?.(),this.#l=void 0});#u(){if(this.#l!==void 0||this.#n===null)return;let e=globalThis,t=(n)=>{if(n.key===this.#r)this.toolsChanged()};e.addEventListener?.("storage",t),this.#l=()=>e.removeEventListener?.("storage",t)}#a(e){return this.#f.grants.some((t)=>t.grantId===e)}#e(){if(this.#n!==null&&!this.#g)try{let e=this.#n.getItem(this.#r);if(e!==null)this.#t=T(e)}catch{}return this.#t.secret===this.#d()?this.#t.grants:new Map}#s(e){this.#t={secret:this.#d(),grants:e};try{this.#n?.setItem(this.#r,k(this.#t)),this.#g=!1}catch{this.#g=!0}this.#h()}#h(){for(let e of[...this.#i])e()}}var u=new WeakMap;function o(e){let t=u.get(e);if(t!==void 0)return t;let n=new p(e);if(u.set(e,n),e.addEventListener?.("grantschange",()=>n.keepGrants(e.grants.map((s)=>s.grantId))),v(e)[0].onChange(()=>n.toolsChanged()),n.toolsChanged(),"session"in e&&e.session!==void 0)n.keepGrants(e.grants.map((s)=>s.grantId));return n}
|
|
2
|
+
export{o};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
5
|
-
//# sourceMappingURL=tab-mcp-client-
|
|
4
|
+
//# debugId=059799CB9B5EA9ED64756E2164756E21
|
|
5
|
+
//# sourceMappingURL=tab-mcp-client-q758jr4g.min.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/always-allowed.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The tools that run without asking, per AI app (grant), DEC-096 and\n * DEC-200: the ones the user allowed one by one, each with what the user\n * saw of it (title and description; a tool that changed since is asked\n * again and leaves the list), and \"everything\", which covers every tool of\n * the page, also ones the user has not seen.\n *\n * Kept in the page's `storage` under the secret's key with `#allowed`, so\n * that they outlive a reload; in memory with `alwaysAllow: \"until-reload\"`,\n * with `storage: null` and without a relay. Storage is read first on every\n * question, so that a change in another tab of the same address counts at\n * once (only one tab at a time holds the connection, DEC-095).\n *\n * An allowance ends with its grant, and only on what the relay says: the\n * grants of a new session, a removed grant, `disconnectAll()` (the relay\n * revoked them all). A dropped connection, or a page that has not connected\n * yet, keeps them: `grantschange` does not fire then. They also belong to\n * the address secret they were made under, so a new secret (`disconnectAll()`\n * here or in another tab) ends them even where nothing listened.\n *\n * Out of the core: the confirmation (`confirm.ts`, which the core loads for\n * every consequential call), the connect dialog and\n * `@ractive-ch/tab-mcp-client/allowed` import it.\n */\n\nimport type { ToolRegistry } from \"./registry.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type { ConfirmRequest, SecretStorage } from \"./types.ts\";\n\n/** What the user saw of a tool: its name, title and description. */\ntype ToolSeen = ConfirmRequest[\"tool\"];\n/** A tool as the registry or a call names it. */\ntype ToolNow = {\n\tname: string;\n\ttitle?: string | undefined;\n\tdescription: string;\n};\n\n/** A tool that asks before it runs, for a page's switch. */\nexport interface AllowedTool {\n\tname: string;\n\ttitle?: string;\n\tdescription: string;\n\t/** Marked `destructiveHint`: it may delete or overwrite. */\n\tdestructive: boolean;\n}\n\n/**\n * The tools that run without asking, per connected AI app (`Grant.grantId`),\n * for a page that draws its own switches: `allowedTools(mcp)` of\n * `@ractive-ch/tab-mcp-client/allowed`. The library's dialogs use the same.\n * The methods are bound: `const { allow } = allowedTools(mcp)` works. The\n * queries (`tools`, `list`, `has`, `everything`) only read: safe while\n * drawing.\n */\nexport interface AllowedTools {\n\t/**\n\t * `true`: kept in the page's `storage` until the AI app is disconnected;\n\t * `false`: in memory, until the page is reloaded or the AI app is\n\t * disconnected (`alwaysAllow: \"until-reload\"`, `storage: null`).\n\t */\n\treadonly kept: boolean;\n\t/**\n\t * The page's tools that ask before they run (`consequentialHint`, callable\n\t * by AI apps through the relay), in the order registered.\n\t */\n\ttools(): AllowedTool[];\n\t/**\n\t * The names of the tools allowed one by one for this AI app, in the order\n\t * allowed; also one that is not registered right now (it runs without\n\t * asking again once it is back unchanged). One registered now with another\n\t * title or description than the user allowed is not in it (it asks).\n\t */\n\tlist(grantId: string): string[];\n\t/**\n\t * Whether a call of this tool by this AI app runs without asking now: the\n\t * AI app is in `mcp.grants`, and \"everything\" is on or the tool is allowed\n\t * and registered unchanged.\n\t */\n\thas(grantId: string, name: string): boolean;\n\t/**\n\t * Allow one tool for this AI app from now on, as it is registered now (its\n\t * title and description). Nothing happens for an AI app that is not in\n\t * `mcp.grants` or a tool that is not in `tools()`.\n\t */\n\tallow(grantId: string, name: string): void;\n\t/**\n\t * Ask again before this AI app runs this tool. While \"everything\" is on for\n\t * the AI app, that goes off too (asking again errs towards asking); the\n\t * other tools allowed one by one stay allowed.\n\t */\n\task(grantId: string, name: string): void;\n\t/** Whether \"Always allow everything\" is on for this AI app. */\n\teverything(grantId: string): boolean;\n\t/**\n\t * \"Always allow everything\" for this AI app: every tool runs\n\t * without asking, with any arguments, also tools registered later, changed\n\t * ones and destructive ones. Turning it on does nothing for an AI app that\n\t * is not in `mcp.grants`.\n\t */\n\tsetEverything(grantId: string, on: boolean): void;\n\t/** Ask again for everything of this AI app: its tools and \"everything\". */\n\tforget(grantId: string): void;\n\t/**\n\t * Calls `listener` on every change of the allowances (also one in\n\t * another tab of the same address) and of `tools()`; returns what stops it.\n\t */\n\tonChange(listener: () => void): () => void;\n}\n\n/** One app's allowances. */\ninterface Entry {\n\teverything: boolean;\n\t/** In the order allowed; `title` and `description` as the user saw them. */\n\ttools: ToolSeen[];\n}\n\n/** What is kept: the grants' entries and the secret they belong to. */\ninterface State {\n\t/** {@link fingerprint} of the address secret. */\n\tsecret: string;\n\tgrants: Map<string, Entry>;\n}\n\n/**\n * A short fingerprint of the address secret (FNV-1a, 32 bits): enough to\n * tell that the secret changed, too short to say anything about it.\n */\nfunction fingerprint(secret: string | undefined): string {\n\tif (secret === undefined) return \"\";\n\tlet hash = 0x811c9dc5;\n\tfor (let i = 0; i < secret.length; i++)\n\t\thash = Math.imul(hash ^ secret.charCodeAt(i), 0x01000193) >>> 0;\n\treturn hash.toString(16);\n}\n\nconst isString = (v: unknown): v is string => typeof v === \"string\";\n\n/**\n * The kept text as a state; anything that is not exactly what\n * {@link serialize} writes allows nothing.\n */\nfunction parse(text: string): State {\n\tconst none: State = { secret: \"\", grants: new Map() };\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(text);\n\t} catch {\n\t\treturn none;\n\t}\n\tconst v = value as { secret?: unknown; grants?: unknown } | null;\n\tif (!isString(v?.secret) || !Array.isArray(v.grants)) return none;\n\tconst grants = new Map<string, Entry>();\n\tfor (const g of v.grants as unknown[]) {\n\t\tconst e = g as {\n\t\t\tgrantId?: unknown;\n\t\t\teverything?: unknown;\n\t\t\ttools?: unknown;\n\t\t} | null;\n\t\tif (\n\t\t\t!isString(e?.grantId) ||\n\t\t\ttypeof e.everything !== \"boolean\" ||\n\t\t\t!Array.isArray(e.tools)\n\t\t)\n\t\t\treturn none;\n\t\tconst tools: ToolSeen[] = [];\n\t\tfor (const t of e.tools as unknown[]) {\n\t\t\tconst tool = t as Partial<Record<keyof ToolSeen, unknown>> | null;\n\t\t\tif (\n\t\t\t\t!isString(tool?.name) ||\n\t\t\t\t!isString(tool.description) ||\n\t\t\t\t(tool.title !== undefined && !isString(tool.title))\n\t\t\t)\n\t\t\t\treturn none;\n\t\t\ttools.push(seenOf(tool as ToolSeen));\n\t\t}\n\t\tgrants.set(e.grantId, { everything: e.everything, tools });\n\t}\n\treturn { secret: v.secret, grants };\n}\n\n/** Grant ids, tool names and what the user saw of each: no arguments, no results. */\nfunction serialize(state: State): string {\n\treturn JSON.stringify({\n\t\tsecret: state.secret,\n\t\tgrants: [...state.grants].map(([grantId, e]) => ({ grantId, ...e })),\n\t});\n}\n\n/** Only what the user saw, as plain strings. */\nfunction seenOf(tool: ToolSeen): ToolSeen {\n\tconst seen: ToolSeen = { name: tool.name, description: tool.description };\n\tif (tool.title !== undefined) seen.title = tool.title;\n\treturn seen;\n}\n\nconst sameSeen = (a: ToolSeen, b: ToolNow) =>\n\ta.title === b.title && a.description === b.description;\n\n/**\n * Whether a tool allowed as `kept` still counts against what is registered\n * now (`now`, `undefined` when it is not): unchanged, or not registered. The\n * one rule for drawing (`list`) and for deciding (`has`).\n */\nconst counts = (kept: ToolSeen, now: ToolNow | undefined) =>\n\tnow === undefined || sameSeen(kept, now);\n\n/**\n * A caller's own stand-in for a `TabMcp` in the confirmation chunk's\n * `confirmInPage` (a desktop app with an MCP endpoint of its own, say): the\n * AI apps it allows for, and optionally `grantschange` events (with\n * `detail.grants`) when they change. Its allowances live in memory, for\n * those grants only, until the page is reloaded.\n */\nexport interface ConfirmHost {\n\treadonly grants: readonly { readonly grantId: string }[];\n\taddEventListener?(type: string, listener: (event: Event) => void): void;\n}\n\n/** What the allowances read of their host's tools. */\ntype ToolsOf = Pick<ToolRegistry, \"list\" | \"get\" | \"onChange\">;\n\n/** A stand-in has no tools to list: a tool is allowed as its question showed it. */\nconst NO_TOOLS: ToolsOf = {\n\tlist: () => [],\n\tget: () => undefined,\n\tonChange: () => () => {},\n};\n\nconst isFunction = (v: unknown) => typeof v === \"function\";\n\n/**\n * Whether `value` is what a `TabMcp`'s `_allowed` is: its registry (with\n * `register`), its secret store or none, its `alwaysAllow`. Anything else\n * (a stand-in that copied part of it, as some did for 0.18.0) is a stand-in.\n */\nfunction isInternals(value: unknown): value is TabMcp[\"_allowed\"] {\n\tif (!Array.isArray(value) || value.length !== 3) return false;\n\tconst [registry, secrets, alwaysAllow] = value as unknown[];\n\tconst r = registry as Partial<Record<string, unknown>> | null;\n\tconst s = secrets as { current?: unknown } | null | undefined;\n\treturn (\n\t\t[\"register\", \"list\", \"get\", \"onChange\"].every((k) => isFunction(r?.[k])) &&\n\t\t(s === undefined || isFunction(s?.current)) &&\n\t\t[undefined, true, false, \"until-reload\"].includes(alwaysAllow as never)\n\t);\n}\n\n/** The host's tools, secret store and `alwaysAllow`: a `TabMcp`'s, or none for a stand-in. */\nfunction internalsOf(\n\thost: TabMcp | ConfirmHost,\n): TabMcp[\"_allowed\"] | [ToolsOf, undefined, undefined] {\n\tconst internals = (host as { _allowed?: unknown })._allowed;\n\treturn isInternals(internals) ? internals : [NO_TOOLS, undefined, undefined];\n}\n\n/**\n * The allowances of one `TabMcp` (or a caller's stand-in, `ConfirmHost`).\n * The public methods are arrow fields, so that they work taken off the\n * object; the queries never write.\n */\nexport class Allowances implements AllowedTools {\n\treadonly kept: boolean;\n\t/** The library's dialogs offer allowing (`alwaysAllow` on). */\n\treadonly offered: boolean;\n\treadonly #mcp: TabMcp | ConfirmHost;\n\treadonly #registry: ToolsOf;\n\treadonly #secret: () => string;\n\t/** `null`: in memory only. */\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t#memory: State = { secret: \"\", grants: new Map() };\n\t/**\n\t * The last write to storage failed (quota, blocked): memory holds what the\n\t * user chose, for the page's lifetime, and storage is not read over it\n\t * until a write succeeds again.\n\t */\n\t#unsaved = false;\n\treadonly #listeners = new Set<() => void>();\n\t#unwatch: (() => void) | undefined;\n\n\tconstructor(mcp: TabMcp | ConfirmHost) {\n\t\tconst [registry, secrets, alwaysAllow] = internalsOf(mcp);\n\t\tthis.#mcp = mcp;\n\t\tthis.#registry = registry;\n\t\tthis.#secret = () => fingerprint(secrets?.current());\n\t\tthis.#storage =\n\t\t\talwaysAllow === \"until-reload\" ? null : (secrets?.storage ?? null);\n\t\tthis.#key = `${secrets?.key}#allowed`;\n\t\tthis.kept = this.#storage !== null;\n\t\tthis.offered = alwaysAllow === true || alwaysAllow === \"until-reload\";\n\t}\n\n\treadonly tools = (): AllowedTool[] =>\n\t\tthis.#registry\n\t\t\t.list()\n\t\t\t.filter(\n\t\t\t\t(t) =>\n\t\t\t\t\tt.annotations.consequentialHint === true &&\n\t\t\t\t\t(t.callers?.includes(\"relay\") ?? true),\n\t\t\t)\n\t\t\t.map((t) => {\n\t\t\t\tconst tool: AllowedTool = {\n\t\t\t\t\tname: t.name,\n\t\t\t\t\tdescription: t.description,\n\t\t\t\t\tdestructive: t.annotations.destructiveHint === true,\n\t\t\t\t};\n\t\t\t\tif (t.title !== undefined) tool.title = t.title;\n\t\t\t\treturn tool;\n\t\t\t});\n\n\treadonly list = (grantId: string): string[] =>\n\t\t(this.#read().get(grantId)?.tools ?? [])\n\t\t\t.filter((t) => counts(t, this.#registry.get(t.name)))\n\t\t\t.map((t) => t.name);\n\n\treadonly has = (grantId: string, name: string): boolean => {\n\t\tconst tool = this.#registry.get(name);\n\t\treturn (\n\t\t\tthis.#granted(grantId) &&\n\t\t\t(this.everything(grantId) ||\n\t\t\t\t(tool !== undefined && this.allows(grantId, tool)))\n\t\t);\n\t};\n\n\t/**\n\t * Whether this call runs without asking: \"everything\", or this tool as\n\t * the user saw it. Only reads: a tool that changed since asks, and leaves\n\t * the list when the registry or another tab's change is seen\n\t * (`toolsChanged`).\n\t */\n\tallows(grantId: string, tool: ToolNow): boolean {\n\t\t// Only for an app the host lists at this moment: a stand-in may drop\n\t\t// one from `grants` without an event, and for a `TabMcp` a call comes\n\t\t// only while the relay's list is current, so it costs nothing there.\n\t\tif (!this.#granted(grantId)) return false;\n\t\tconst entry = this.#read().get(grantId);\n\t\tif (entry === undefined) return false;\n\t\tif (entry.everything) return true;\n\t\tconst kept = entry.tools.find((t) => t.name === tool.name);\n\t\treturn kept !== undefined && sameSeen(kept, tool);\n\t}\n\n\treadonly allow = (grantId: string, name: string): void => {\n\t\tconst tool = this.tools().find((t) => t.name === name);\n\t\tif (tool !== undefined) this.keep(grantId, tool);\n\t};\n\n\t/** Allow `tool` as the user saw it, for an app the relay still lists. */\n\tkeep(grantId: string, tool: ToolSeen): void {\n\t\tif (!this.#granted(grantId)) return;\n\t\tconst grants = this.#read();\n\t\tconst entry = grants.get(grantId) ?? { everything: false, tools: [] };\n\t\tentry.tools = [\n\t\t\t...entry.tools.filter((t) => t.name !== tool.name),\n\t\t\tseenOf(tool),\n\t\t];\n\t\tgrants.set(grantId, entry);\n\t\tthis.#write(grants);\n\t}\n\n\treadonly ask = (grantId: string, name: string): void => {\n\t\tconst grants = this.#read();\n\t\tconst entry = grants.get(grantId);\n\t\tif (entry === undefined) return;\n\t\tconst tools = entry.tools.filter((t) => t.name !== name);\n\t\t// Under \"everything\" this tool ran without asking too: asking again\n\t\t// for it turns that off; the tools allowed one by one stay.\n\t\tif (!entry.everything && tools.length === entry.tools.length) return;\n\t\tentry.everything = false;\n\t\tentry.tools = tools;\n\t\tif (tools.length === 0) grants.delete(grantId);\n\t\tthis.#write(grants);\n\t};\n\n\treadonly everything = (grantId: string): boolean =>\n\t\tthis.#read().get(grantId)?.everything === true;\n\n\treadonly setEverything = (grantId: string, on: boolean): void => {\n\t\tif (on && !this.#granted(grantId)) return;\n\t\tconst grants = this.#read();\n\t\tconst entry = grants.get(grantId) ?? { everything: false, tools: [] };\n\t\tif (entry.everything === on) return;\n\t\tentry.everything = on;\n\t\tif (on || entry.tools.length > 0) grants.set(grantId, entry);\n\t\telse grants.delete(grantId);\n\t\tthis.#write(grants);\n\t};\n\n\treadonly forget = (grantId: string): void => {\n\t\tconst grants = this.#read();\n\t\tif (grants.delete(grantId)) this.#write(grants);\n\t};\n\n\t/**\n\t * Only the grants the relay lists now: the others ended. What was kept\n\t * under another secret is dropped from storage too (it allowed nothing\n\t * already).\n\t */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tconst grants = this.#read();\n\t\t// Kept under another secret: nothing to write unless something was kept.\n\t\tlet changed =\n\t\t\tthis.#memory.grants !== grants && this.#memory.grants.size > 0;\n\t\tfor (const grantId of [...grants.keys()])\n\t\t\tif (!keep.has(grantId)) changed = grants.delete(grantId) || changed;\n\t\tif (changed) this.#write(grants);\n\t}\n\n\t/**\n\t * The registry changed, or another tab changed the allowances: a tool\n\t * registered with another title or description than the user saw leaves\n\t * every list. One that is not registered stays (a reload registers them\n\t * all again, a page may offer some only on some views). Tells the\n\t * listeners in any case.\n\t */\n\ttoolsChanged(): void {\n\t\tconst grants = this.#read();\n\t\tlet changed = false;\n\t\tfor (const [grantId, entry] of [...grants]) {\n\t\t\tconst tools = entry.tools.filter((t) =>\n\t\t\t\tcounts(t, this.#registry.get(t.name)),\n\t\t\t);\n\t\t\tif (tools.length === entry.tools.length) continue;\n\t\t\tchanged = true;\n\t\t\tentry.tools = tools;\n\t\t\tif (!entry.everything && tools.length === 0) grants.delete(grantId);\n\t\t}\n\t\tif (changed) this.#write(grants);\n\t\telse this.#changed();\n\t}\n\n\treadonly onChange = (listener: () => void): (() => void) => {\n\t\tthis.#listeners.add(listener);\n\t\tthis.#watch();\n\t\treturn () => {\n\t\t\tthis.#listeners.delete(listener);\n\t\t\tif (this.#listeners.size === 0) {\n\t\t\t\tthis.#unwatch?.();\n\t\t\t\tthis.#unwatch = undefined;\n\t\t\t}\n\t\t};\n\t};\n\n\t/**\n\t * Another tab changed them: clean up against this page's tools and tell\n\t * the listeners (only while there are some).\n\t */\n\t#watch(): void {\n\t\tif (this.#unwatch !== undefined || this.#storage === null) return;\n\t\tconst g = globalThis as Partial<EventTarget>;\n\t\tconst changed = (event: Event) => {\n\t\t\tif ((event as StorageEvent).key === this.#key) this.toolsChanged();\n\t\t};\n\t\tg.addEventListener?.(\"storage\", changed);\n\t\tthis.#unwatch = () => g.removeEventListener?.(\"storage\", changed);\n\t}\n\n\t#granted(grantId: string): boolean {\n\t\treturn this.#mcp.grants.some((g) => g.grantId === grantId);\n\t}\n\n\t/**\n\t * The allowances now: storage first, so that another tab's change counts;\n\t * memory where storage cannot be read or the last write to it failed.\n\t * None once the secret changed.\n\t */\n\t#read(): Map<string, Entry> {\n\t\tif (this.#storage !== null && !this.#unsaved) {\n\t\t\ttry {\n\t\t\t\tconst text = this.#storage.getItem(this.#key);\n\t\t\t\tif (text !== null) this.#memory = parse(text);\n\t\t\t} catch {\n\t\t\t\t// unreadable: what this page kept in memory\n\t\t\t}\n\t\t}\n\t\treturn this.#memory.secret === this.#secret()\n\t\t\t? this.#memory.grants\n\t\t\t: new Map();\n\t}\n\n\t#write(grants: Map<string, Entry>): void {\n\t\tthis.#memory = { secret: this.#secret(), grants };\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, serialize(this.#memory));\n\t\t\tthis.#unsaved = false;\n\t\t} catch {\n\t\t\t// quota or blocked: kept in memory for the page's lifetime\n\t\t\tthis.#unsaved = true;\n\t\t}\n\t\tthis.#changed();\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n\n/** The allowances per `TabMcp` or stand-in. */\nconst allowances = new WeakMap<TabMcp | ConfirmHost, Allowances>();\n\n/**\n * The allowances of `mcp`, made on first use. They follow its grants (only\n * when the relay names them, see above; a stand-in's `grantschange`) and\n * its tools.\n */\nexport function allowedFor(mcp: TabMcp | ConfirmHost): Allowances {\n\tconst kept = allowances.get(mcp);\n\tif (kept !== undefined) return kept;\n\tconst made = new Allowances(mcp);\n\tallowances.set(mcp, made);\n\t// Against the host's grants as they are now, whatever the event carries\n\t// (a stand-in may send a plain Event; a TabMcp's detail is its grants).\n\tmcp.addEventListener?.(\"grantschange\", () =>\n\t\tmade.keepGrants(mcp.grants.map((g) => g.grantId)),\n\t);\n\tinternalsOf(mcp)[0].onChange(() => made.toolsChanged());\n\tmade.toolsChanged(); // tools may have changed since the last page kept them\n\t// Made while connected: the grants are the relay's, the others ended.\n\tif (\"session\" in mcp && mcp.session !== undefined)\n\t\tmade.keepGrants(mcp.grants.map((g) => g.grantId));\n\treturn made;\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAgIA,S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function g(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var D=/^(default|examples|const|enum)$/,j=/^(properties|patternProperties|\$defs|definitions|dependentSchemas)$/;function R(e,t,n=0,i=!1){if(n>64||typeof e!=="object"||e===null)return;if(i||=Array.isArray(e),!i)t(e);for(let[r,o]of Object.entries(e))if(i||!D.test(r))R(o,t,n+1,!i&&j.test(r))}function N(e,t){let n=e;for(let i of t.split("/").slice(1)){let r;try{r=decodeURIComponent(i)}catch{return}if(r=r.replaceAll("~1","/").replaceAll("~0","~"),typeof n!=="object"||n===null||!Object.hasOwn(n,r))return;n=n[r]}return n}function H(e){let t=new Set,n=[],i=[],r=!1;if(R(e,(o)=>{if(typeof o.$anchor==="string")t.add(o.$anchor);if(typeof o.$ref==="string")n.push(o.$ref);if(typeof o.pattern==="string")i.push(o.pattern);let s=o.patternProperties;if(g(s))i.push(...Object.keys(s));if("x-mcp-header"in o)r=!0}),r)return"x-mcp-header is not supported by tab-mcp";for(let o of i)try{new RegExp(o,"u")}catch{return`pattern ${JSON.stringify(o)} is not a valid regular expression`}for(let o of n){if(!o.startsWith("#"))return`$ref ${JSON.stringify(o)} points outside the schema`;let s=o.slice(1);if(!(s===""||(s.startsWith("/")?N(e,s)!==void 0:t.has(s))))return`$ref ${JSON.stringify(o)} does not resolve`}return}function _(e){if(!g(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:n,description:i,inputSchema:r,outputSchema:o,execute:s,annotations:a}=e;if(typeof t!=="string"||!L.test(t))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(t)})`);if(typeof i!=="string"||i.trim()==="")throw TypeError(`registerTool: tool ${t} needs a description`);if(n!==void 0&&typeof n!=="string")throw TypeError(`registerTool: the title of ${t} must be a string`);if(typeof s!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let c=(l,h)=>{if(!g(l)||l.type!=="object")throw TypeError(`registerTool: the ${h} of ${t} must be a JSON Schema object with "type": "object"`);let y;try{y=JSON.parse(JSON.stringify(l))}catch{throw TypeError(`registerTool: the ${h} of ${t} must be JSON`)}let C=H(y);if(C!==void 0)throw TypeError(`registerTool: the ${h} of ${t}: ${C}`);return y},d=c(r??{type:"object"},"inputSchema");if(a!==void 0&&!g(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let u={};for(let[l,h]of Object.entries(a??{}))if(typeof h==="boolean")u[l]=h;else if(h!==void 0&&/Hint$|^debugging$/.test(l))throw TypeError(`registerTool: ${l} of ${t} must be a boolean`);return{name:t,title:n,description:i,inputSchema:d,outputSchema:o===void 0?void 0:c(o,"outputSchema"),annotations:u,execute:s}}class w{#e=new Map;#d=new Set;#m;register(e,t={}){let{signal:n,exposedTo:i}=t,r=t.callers&&[...t.callers];if("webmcp"in t||r?.some((s)=>!/^(relay|local|webmcp)$/.test(s)))throw TypeError('registerTool: callers must be "relay", "local" or "webmcp"; option webmcp is gone');let o={..._(e),callers:r,exposedTo:i};if(n?.throwIfAborted(),this.#e.has(o.name))throw new DOMException(`registerTool: a tool named ${o.name} is already registered`,"InvalidStateError");this.#m?.(o),this.#e.set(o.name,o),n?.addEventListener("abort",()=>this.remove(o),{once:!0}),this.#y()}setCompiler(e){this.#m??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),this.#y()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#d.add(e),()=>this.#d.delete(e)}#y(){for(let e of[...this.#d])e()}}var z=/^[A-Za-z0-9_-]{43}$/;function J(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function K(){return J(crypto.getRandomValues(new Uint8Array(32)))}function G(e){return typeof e==="string"&&z.test(e)}function U(){try{return globalThis.localStorage??null}catch{return null}}class b{storage;key;#e;constructor(e,t){this.storage=e===void 0?U():e,this.key=t}current(){let e=null;try{e=this.storage?.getItem(this.key)??null}catch{}if(G(e))return this.#e=e,e;return this.#e}rotate(){let e=K();this.#e=e;try{this.storage?.setItem(this.key,e)}catch{}return e}}var I="0.18.1";var M="@ractive-ch/tab-mcp-client",T=I;function q(){try{return Object.getOwnPropertyDescriptor(Document.prototype,"modelContext")?.get?.call(document)}catch{return}}var V=new Set(["localhost","127.0.0.1","[::1]"]),S={reconnectDelaysMs:[5000,1e4,20000,40000,60000],answerTimeoutMs:15000},P=new Set(["network","heartbeat","shutdown"]);function B(e){return Object.freeze({...e,client:Object.freeze({...e.client})})}function F(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((t)=>{let n=t.codePointAt(0)??0;return n<32||n>=127&&n<=159})}var Y=/^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;function Z(e){return e.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,32).replace(/-$/,"")}function Q(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let n=t.protocol==="https:"||t.protocol==="wss:";if(!n&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!n&&!V.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let i=`${n?"https:":"http:"}//${t.host}`,r=t.pathname.replace(/\/+$/,"");return t.protocol=n?"wss:":"ws:",t.pathname=r.endsWith("/tab")?r:`${r}/tab`,t.search="",t.hash="",{url:t.href,origin:i}}function X(e){try{return new URL(e).host}catch{return""}}function ee(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,pairing:e.pairing==="oidc"?"oidc":"code",expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}function m(){return Promise.reject(TypeError("TabMcp: this TabMcp has no relay"))}function A(e,t){return Object.assign(Object(e),{addressChanged:t})}function E(){return Promise.reject(new DOMException("TabMcp: not connected","InvalidStateError"))}class x extends EventTarget{#e=new w;#d;#m;#y;#R;#j;#I;#v;#p;#N;#w=!1;#b;#M;#T="none";#P;#s=0;#i="disconnected";#a;#l=Object.freeze([]);#g=!1;#A;#t;#r;#h=0;#H;#u;#f;#S;#E;#x={registry:this.#e,confirm:(e)=>this.#q(e),ownConfirm:()=>!!this.#R,toolCallStarted:(e)=>this.#n("toolcall",e),toolCallEnded:(e)=>this.#n("toolcallend",e)};constructor(e){super();let{server:t,appName:n}=e,i=e.relay===void 0?void 0:Q(e.relay);if(typeof t?.name!=="string"||typeof t.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(n!==void 0&&!F(n))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");let r=e.app??Z(t.name);if(e.app!==void 0?typeof r!=="string"||!Y.test(r):i&&r==="")throw TypeError(e.app!==void 0?"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");if(this.#m=r,this.#v=i?.url,this.#d={...t},this.#y=n,this.#R=e.onConfirm,this.#j=e.alwaysAllow,this.#I=e.ui,this.#M=e.identityAssertion,this.#H=e.reconnect!==!1,i!==void 0){let s=e.storageKey??`tab-mcp:secret:${i.origin}:${encodeURIComponent(t.name)}`;this.#p=new b(e.storage,s),this.#N=e.storage===null?void 0:`${s}#tabs`}this.#e.onChange(()=>this.#n("toolschange",{tools:this.tools}));let o=e.webmcp===!0?q():void 0;if(o!==void 0)(f("khy4f5rj"),import("./webmcp-khy4f5rj.min.js")).then((s)=>s.mirror(this.#e,o,(a,c,d)=>this.#L().then((u)=>u.callFromWebMcp(this.#x,a,c,d))),(s)=>console.warn("tab-mcp: no tools are offered through WebMCP:",s))}registerTool(e,t={}){try{this.#e.register(e,t)}catch(n){return Promise.reject(n)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#i}get session(){return this.#a}get grants(){return this.#l}get reconnecting(){return this.#u}get identity(){return this.#T}get identityMessage(){return this.#P}refreshIdentity(){let e=this.#a,t=this.#M;if(t===void 0)return Promise.reject(TypeError("TabMcp: no identityAssertion"));if(e===void 0)return E();let n=++this.#s,i=this.#t;this.#o("pending");let r=setTimeout(()=>{if(n!==this.#s||this.#T!=="pending")return;this.#s++,this.#o("none")},S.answerTimeoutMs);return new Promise((o)=>{let s=(a)=>{let{identity:c}=a.detail;if(c==="pending")return;this.removeEventListener("identitychange",s),clearTimeout(r),o(c)};this.addEventListener("identitychange",s),Promise.resolve().then(()=>t({address:e.address,sessionId:e.sessionId})).then((a)=>{if(n!==this.#s||this.#t!==i)return;if(typeof a!=="string"||a===""){this.#o("none");return}if(i?.send({type:"identity",assertion:a,round:n})!==!0)this.#o("none")},(a)=>{if(n!==this.#s)return;this.#n("error",{error:a instanceof Error?a:Error(String(a))}),this.#o("none")})})}signOut(){return this.#s++,this.#o("none"),this.#a?.pairing==="oidc"?this.#K({type:"identity.logout"},()=>!this.#l.length):E()}get pairingCode(){return this.#A}connect(e={}){if(this.#v===void 0)return m();if(this.#i==="connected"&&this.#a!==void 0)return Promise.resolve(this.#a);if(this.#r!==void 0)return this.#r;if(this.#u!==void 0)return this.#D();let t=globalThis.navigator?.userActivation;if(e.resume!==!0&&t!==void 0&&!t.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));return this.#b?this.#b.then(()=>this.connect({resume:!0})):this.#k()}#k(){if(!this.#u)this.#c("connecting");let e=this.#_(this.#h);return this.#r=e,e.then(()=>{if(this.#r===e)this.#r=void 0},()=>{if(this.#r!==e)return;if(this.#r=void 0,this.#t=void 0,!this.#u)this.#c("disconnected")}),e}async#L(){let e=await (f("0xqwz17v"),import("./connection-0xqwz17v.min.js"));for(let t of e.compileRegistry(this.#e))this.#n("error",{error:t});return e}async#_(e,t){let{openConnection:n,addressIdOf:i}=await this.#L(),r=this.#v;if(r===void 0||this.#p===void 0)return m();let o=t??this.#p.current()??this.#p.rotate(),s=await i(o);if(e!==this.#h)throw new DOMException("The connection was cancelled","AbortError");let a={},c=n(this.#V(a),r,o,{address:s,revokeAll:!!t});if(!t)a.connection=c;return this.#t=c,c.ready}get hasRelay(){return this.#v!==void 0}serve(e,t){return this.#L().then((n)=>n.servePort({...this.#x,server:this.#d,error:(i)=>this.#n("error",{error:i})},e,t))}disconnect(){this.#z("user")}newAddress(){let e=this.#p;if(!e)return m();return this.#b??=this.#G(e).finally(()=>{this.#b=void 0})}async#G(e){let t=this.#i!=="disconnected"||this.#w,n=e.current();this.#z("new_address");let i=this.#h;if(n){this.#c("connecting");try{await this.#_(i,n)}catch(r){if(i===this.#h)this.#c("disconnected"),this.#w=t;throw A(r,!1)}finally{if(i===this.#h)this.#t?.close("new_address"),this.#t=void 0}}if(e.rotate(),this.#O([]),t)await this.#k().catch((r)=>{throw A(r,!0)});else this.#c("disconnected")}#z(e){this.#$(),this.#w=!1,this.#h++;let t=this.#t;if(this.#t=void 0,this.#r=void 0,t?.close(e),this.#i==="disconnected")return;this.#a=void 0,this.#C(void 0),this.#s++,this.#o("none"),this.#c("disconnected",e)}#J(e,t){let n=S.reconnectDelaysMs,i=(n[Math.min(t,n.length)-1]??0)*(0.8+0.4*Math.random());clearTimeout(this.#f),this.#f=setTimeout(()=>{this.#D().catch(()=>{})},i),this.#U(),this.#u={reason:e,attempt:t,at:Date.now()+i},this.#c("reconnecting",t>1?void 0:e)}#D(){if(clearTimeout(this.#f),this.#f=void 0,this.#r!==void 0)return this.#r;let e=this.#k();return e.catch((t)=>{let n=this.#u;if(n===void 0||this.#r!==void 0)return;let i=t?.reason;if(i===void 0||P.has(i)){this.#J(n.reason,n.attempt+1);return}if(this.#$(),this.#i="disconnected",this.#n("error",{error:t instanceof Error?t:Error(String(t))}),this.#i==="disconnected")this.#n("statechange",{state:"disconnected"})}),e}#U(){if(this.#S!==void 0)return;let e=globalThis,t=globalThis.document,n=()=>{if(this.#f!==void 0)this.#D().catch(()=>{})},i=()=>{if(t?.visibilityState!=="hidden")n()};t?.addEventListener("visibilitychange",i),e.addEventListener?.("online",n),this.#S=()=>{t?.removeEventListener("visibilitychange",i),e.removeEventListener?.("online",n)}}#$(){clearTimeout(this.#f),this.#f=void 0,this.#S?.(),this.#S=void 0,this.#u=void 0}startPairing(){if(this.#g)return;if(this.#g=!0,this.#i==="connected")this.#t?.send({type:"pairing.start"})}stopPairing(){if(!this.#g)return;if(this.#g=!1,this.#i==="connected")this.#t?.send({type:"pairing.stop"});this.#C(void 0)}revoke(e){let t=()=>!this.#l.some((n)=>n.grantId===e);return t()?Promise.resolve():this.#K({type:"grant.revoke",grantId:e},t)}#K(e,t){if(!this.#a||this.#t?.send(e)!==!0)return E();return new Promise((n,i)=>{let r=["grantschange","statechange","error"],o=(c)=>{clearTimeout(a);for(let d of r)this.removeEventListener(d,s);if(c)i(c);else n()},s=(c)=>{let d=c?.detail?.error;if(t())o();else if((d?.code==="store_unavailable"||d?.code==="unknown_id")&&(d.for===void 0||d.for===e.type&&d.grantId===e.grantId))o(d);else if(this.#i!=="connected")o(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},a=setTimeout(()=>o(new DOMException("TabMcp: the relay did not answer","TimeoutError")),S.answerTimeoutMs);for(let c of r)this.addEventListener(c,s);s()})}showConnectDialog(e={}){if(this.#v===void 0)return m();let t=e.document??globalThis.document,n=this.#E;if(n!==void 0)return n.doc===t?n.shown:Promise.reject(new DOMException("showConnectDialog: the dialog is already open in another document","InvalidStateError"));let i=this.#W(t).finally(()=>{if(this.#E?.shown===i)this.#E=void 0});return this.#E={doc:t,shown:i},i}async#W(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:n}=await (f("x6ws6wqt"),import("./connect-x6ws6wqt.min.js"));await n(this,t,e,this.#d.name,this.#I)}addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}#n(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#c(e,t){if(this.#i===e&&e!=="reconnecting")return;this.#i=e,this.#n("statechange",t?{state:e,reason:t}:{state:e})}#o(e,t){if(this.#T===e&&t===void 0)return;this.#T=e,this.#P=e==="refused"?t:void 0,this.#n("identitychange",{identity:e,identityMessage:this.#P})}#C(e){if(this.#A===void 0&&e===void 0)return;this.#A=e,this.#n("pairingcode",{pairingCode:e})}#O(e){this.#l=Object.freeze(e.map(B)),this.#n("grantschange",{grants:this.#l})}#q(e){let t=this.#R;return (f("d722a9eb"),import("./confirm-d722a9eb.min.js")).then((n)=>n.confirmCall(this,e,t),()=>t?.(e)??!1)}get _allowed(){return[this.#e,this.#p,this.#j]}confirmInPage(e,t={}){let n=t.document??globalThis.document;if(n===void 0)return Promise.resolve(!1);return (f("d722a9eb"),import("./confirm-d722a9eb.min.js")).then((i)=>i.confirmInPage(this,e,n,{ui:this.#I}))}#V(e){let t=()=>e.connection!==void 0&&this.#t===e.connection,n=!1;return{...this.#x,server:this.#d,app:this.#m,appName:this.#y,tabs:this.#N,library:{name:M,version:T},clientFor:(i)=>{let r=this.#l.find((s)=>s.grantId===i.grantId),o={kind:"relay",grantId:i.grantId,id:i.clientId,host:X(i.clientId)};if(r!==void 0)o.name=r.client.name;return o},sessionStarted:(i)=>{let r=ee(i);if(!t())return r;if(this.#a=r,this.#w=!1,this.#$(),this.#O([...i.grants]),this.#g)this.#t?.send({type:"pairing.start"});if(this.#c("connected"),r.pairing==="oidc"&&this.#M)this.refreshIdentity();return r},pairingCode:(i)=>{if(t()&&this.#g)this.#C(i)},grantAdded:(i)=>{if(!t())return;this.#O([...this.#l.filter((r)=>r.grantId!==i.grantId),i])},grantRemoved:(i)=>{if(!t())return;this.#O(this.#l.filter((r)=>r.grantId!==i))},replaced:(i)=>{if(n)this.#n("replaced",i)},identityResult:(i,r,o)=>{if(!t())return;if(r!==this.#s)return;if(i)this.#o("bound");else this.#o("refused",o??"")},error:(i)=>{if(t())this.#n("error",{error:i})},closed:(i)=>{if(!t())return;if(i==="replaced")this.#w=n=!0;this.#t=void 0,this.#a=void 0;let r=this.#h;if(this.#C(void 0),this.#s++,this.#o("none"),r!==this.#h)return;if(this.#H&&P.has(i))this.#J(i,1);else this.#c("disconnected",i)}}}}export{x as TabMcp,T as VERSION};
|
|
1
|
+
var O,v,p,f=(e,t)=>{for(var[i,n,r]of O||[])for(var o=[e],s=globalThis,a=s.document,d,h,u,c,l;h=o.pop();)if(!v[h]&&(u=n[h])){v[h]=1;for(c=1;c<u.length;c++)o.push(r[u[c]]);if(!t&&h!==e&&(d=a&&a.head)){if(p===void 0)p=(c=a.querySelector("meta[property=csp-nonce]"))&&(c.nonce||c.getAttribute("nonce"))||"";if(l=a.createElement("link"),l.rel="modulepreload",l.crossOrigin="",p)l.nonce=p;l.href=new s.URL(u[0],i),d.appendChild(l)}}},k=(e,t,i,n)=>{for(var r={},o=0;o<t.length;o++)r[t[o]]=i[o];(O||=[]).push([e,r,t]),v||={},f(t[n],1)};k(import.meta.url,["nt8c9azk","84k58gsw","yf2x9zz2","my0pbqd7","ba3dkf9p","nnxcwrxp","8r6h3wza","q758jr4g"],[["./tab-mcp-client.min.js"],["./webmcp-84k58gsw.min.js"],["./connection-yf2x9zz2.min.js"],["./connect-my0pbqd7.min.js",5,6,7],["./confirm-ba3dkf9p.min.js",5,6,7],["./tab-mcp-client-nnxcwrxp.min.js"],["./tab-mcp-client-8r6h3wza.min.js",5],["./tab-mcp-client-q758jr4g.min.js"]],0);
|
|
2
|
+
var D=/^[A-Za-z0-9_.-]{1,128}$/;function g(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var L=/^(default|examples|const|enum)$/,j=/^(properties|patternProperties|\$defs|definitions|dependentSchemas)$/;function R(e,t,i=0,n=!1){if(i>64||typeof e!=="object"||e===null)return;if(n||=Array.isArray(e),!n)t(e);for(let[r,o]of Object.entries(e))if(n||!L.test(r))R(o,t,i+1,!n&&j.test(r))}function N(e,t){let i=e;for(let n of t.split("/").slice(1)){let r;try{r=decodeURIComponent(n)}catch{return}if(r=r.replaceAll("~1","/").replaceAll("~0","~"),typeof i!=="object"||i===null||!Object.hasOwn(i,r))return;i=i[r]}return i}function H(e){let t=new Set,i=[],n=[],r=!1;if(R(e,(o)=>{if(typeof o.$anchor==="string")t.add(o.$anchor);if(typeof o.$ref==="string")i.push(o.$ref);if(typeof o.pattern==="string")n.push(o.pattern);let s=o.patternProperties;if(g(s))n.push(...Object.keys(s));if("x-mcp-header"in o)r=!0}),r)return"x-mcp-header is not supported by tab-mcp";for(let o of n)try{new RegExp(o,"u")}catch{return`pattern ${JSON.stringify(o)} is not a valid regular expression`}for(let o of i){if(!o.startsWith("#"))return`$ref ${JSON.stringify(o)} points outside the schema`;let s=o.slice(1);if(!(s===""||(s.startsWith("/")?N(e,s)!==void 0:t.has(s))))return`$ref ${JSON.stringify(o)} does not resolve`}return}function z(e){if(!g(e))throw TypeError("registerTool: the tool must be an object");let{name:t,title:i,description:n,inputSchema:r,outputSchema:o,execute:s,annotations:a}=e;if(typeof t!=="string"||!D.test(t))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(t)})`);if(typeof n!=="string"||n.trim()==="")throw TypeError(`registerTool: tool ${t} needs a description`);if(i!==void 0&&typeof i!=="string")throw TypeError(`registerTool: the title of ${t} must be a string`);if(typeof s!=="function")throw TypeError(`registerTool: tool ${t} needs an execute function`);let d=(c,l)=>{if(!g(c)||c.type!=="object")throw TypeError(`registerTool: the ${l} of ${t} must be a JSON Schema object with "type": "object"`);let w;try{w=JSON.parse(JSON.stringify(c))}catch{throw TypeError(`registerTool: the ${l} of ${t} must be JSON`)}let C=H(w);if(C!==void 0)throw TypeError(`registerTool: the ${l} of ${t}: ${C}`);return w},h=d(r??{type:"object"},"inputSchema");if(a!==void 0&&!g(a))throw TypeError(`registerTool: the annotations of ${t} must be an object`);let u={};for(let[c,l]of Object.entries(a??{}))if(typeof l==="boolean")u[c]=l;else if(l!==void 0&&/Hint$|^debugging$/.test(c))throw TypeError(`registerTool: ${c} of ${t} must be a boolean`);return{name:t,title:i,description:n,inputSchema:h,outputSchema:o===void 0?void 0:d(o,"outputSchema"),annotations:u,execute:s}}class b{#e=new Map;#d=new Set;#m;register(e,t={}){let{signal:i,exposedTo:n}=t,r=t.callers&&[...t.callers];if("webmcp"in t||r?.some((s)=>!/^(relay|local|webmcp)$/.test(s)))throw TypeError('registerTool: callers must be "relay", "local" or "webmcp"; option webmcp is gone');let o={...z(e),callers:r,exposedTo:n};if(i?.throwIfAborted(),this.#e.has(o.name))throw new DOMException(`registerTool: a tool named ${o.name} is already registered`,"InvalidStateError");this.#m?.(o),this.#e.set(o.name,o),i?.addEventListener("abort",()=>this.remove(o),{once:!0}),this.#y()}setCompiler(e){this.#m??=e}remove(e){if(this.#e.get(e.name)!==e)return;this.#e.delete(e.name),this.#y()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#d.add(e),()=>this.#d.delete(e)}#y(){for(let e of[...this.#d])e()}}var _=/^[A-Za-z0-9_-]{43}$/;function J(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function K(){return J(crypto.getRandomValues(new Uint8Array(32)))}function G(e){return typeof e==="string"&&_.test(e)}function U(){try{return globalThis.localStorage??null}catch{return null}}class T{storage;key;#e;constructor(e,t){this.storage=e===void 0?U():e,this.key=t}current(){let e=null;try{e=this.storage?.getItem(this.key)??null}catch{}if(G(e))return this.#e=e,e;return this.#e}rotate(){let e=K();this.#e=e;try{this.storage?.setItem(this.key,e)}catch{}return e}}var I="0.19.0-rc.1";var M="@ractive-ch/tab-mcp-client",m=I;function B(){try{return Object.getOwnPropertyDescriptor(Document.prototype,"modelContext")?.get?.call(document)}catch{return}}var q=new Set(["localhost","127.0.0.1","[::1]"]),S={reconnectDelaysMs:[5000,1e4,20000,40000,60000],answerTimeoutMs:15000},P=new Set(["network","heartbeat","shutdown"]);function V(e){return Object.freeze({...e,client:Object.freeze({...e.client})})}function F(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((t)=>{let i=t.codePointAt(0)??0;return i<32||i>=127&&i<=159})}var Y=/^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$/;function Z(e){return e.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,32).replace(/-$/,"")}function Q(e){let t;try{t=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let i=t.protocol==="https:"||t.protocol==="wss:";if(!i&&t.protocol!=="http:"&&t.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!i&&!q.has(t.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let n=`${i?"https:":"http:"}//${t.host}`,r=t.pathname.replace(/\/+$/,"");return t.protocol=i?"wss:":"ws:",t.pathname=r.endsWith("/tab")?r:`${r}/tab`,t.search="",t.hash="",{url:t.href,origin:n}}function X(e){try{return new URL(e).host}catch{return""}}function ee(e){let t={sessionId:e.sessionId,address:e.address,origin:e.origin,pairing:e.pairing==="oidc"?"oidc":"code",expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)t.appName=e.appName;return t}function y(){return Promise.reject(TypeError("TabMcp: this TabMcp has no relay"))}function x(e,t){return Object.assign(Object(e),{secretChanged:t})}function E(){return Promise.reject(new DOMException("TabMcp: not connected","InvalidStateError"))}class A extends EventTarget{#e=new b;#d;#m;#y;#R;#J;#b;#w;#g;#K;#v=!1;#T;#I;#S="none";#M;#a=0;#i="disconnected";#o;#l=Object.freeze([]);#f=!1;#P;#x;#A=!1;#k=!1;#n;#r;#h=0;#G;#u;#p;#$;#D;#E;#L={registry:this.#e,confirm:(e)=>this.#X(e),ownConfirm:()=>!!this.#R,toolCallStarted:(e)=>this.#t("toolcall",e),toolCallEnded:(e)=>this.#t("toolcallend",e)};constructor(e){super();let{server:t,appName:i}=e,n=e.relay===void 0?void 0:Q(e.relay);if(typeof t?.name!=="string"||typeof t.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(i!==void 0&&!F(i))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");let r=e.app??Z(t.name);if(e.app!==void 0?typeof r!=="string"||!Y.test(r):n&&r==="")throw TypeError(e.app!==void 0?"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");if(this.#m=r,this.#w=n?.url,this.#d={...t},this.#y=i,this.#R=e.onConfirm,this.#J=e.alwaysAllow,this.#b=e.ui,this.#I=e.identityAssertion,this.#G=e.reconnect!==!1,n!==void 0){let s=e.storageKey??`tab-mcp:secret:${n.origin}:${encodeURIComponent(t.name)}`;this.#g=new T(e.storage,s),this.#K=e.storage===null?void 0:`${s}#tabs`}this.#e.onChange(()=>this.#t("toolschange",{tools:this.tools}));let o=e.webmcp===!0?B():void 0;if(o!==void 0)(f("84k58gsw"),import("./webmcp-84k58gsw.min.js")).then((s)=>s.mirror(this.#e,o,(a,d,h,u)=>this.#N().then((c)=>c.callFromWebMcp(this.#L,a,d,h,u)),this,r,e,m),(s)=>console.warn("tab-mcp: no tools are offered through WebMCP:",s))}registerTool(e,t={}){try{this.#e.register(e,t)}catch(i){return Promise.reject(i)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#i}get session(){return this.#o}get grants(){return this.#l}get reconnecting(){return this.#u}get identity(){return this.#S}get identityMessage(){return this.#M}refreshIdentity(){let e=this.#o,t=this.#I;if(t===void 0)return Promise.reject(TypeError("TabMcp: no identityAssertion"));if(e===void 0)return E();let i=++this.#a,n=this.#n;this.#s("pending");let r=setTimeout(()=>{if(i!==this.#a||this.#S!=="pending")return;this.#a++,this.#s("none")},S.answerTimeoutMs);return new Promise((o)=>{let s=(a)=>{let{identity:d}=a.detail;if(d==="pending")return;this.removeEventListener("identitychange",s),clearTimeout(r),o(d)};this.addEventListener("identitychange",s),Promise.resolve().then(()=>t({address:e.address,sessionId:e.sessionId})).then((a)=>{if(i!==this.#a||this.#n!==n)return;if(typeof a!=="string"||a===""){this.#s("none");return}if(n?.send({type:"identity",assertion:a,round:i})!==!0)this.#s("none")},(a)=>{if(i!==this.#a)return;this.#t("error",{error:a instanceof Error?a:Error(String(a))}),this.#s("none")})})}signOut(){return this.#a++,this.#s("none"),this.#o?.pairing==="oidc"?this.#V({type:"identity.logout"},()=>!this.#l.length):E()}get pairingCode(){return this.#P}get pairingUntil(){return this.#x}connect(e={}){if(this.#w===void 0)return y();if(this.#i==="connected"&&this.#o!==void 0)return Promise.resolve(this.#o);if(this.#u!==void 0)return this.#k||=e.resume!==!0,this.#H();if(this.#r!==void 0)return this.#r;let t=globalThis.navigator?.userActivation;if(e.resume!==!0&&t!==void 0&&!t.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));return this.#T?this.#T.then(()=>this.connect({resume:!0})):this.#j()}#j(){if(!this.#u)this.#c("connecting");let e=this.#U(this.#h);return this.#r=e,e.then(()=>{if(this.#r===e)this.#r=void 0},()=>{if(this.#r!==e)return;if(this.#r=void 0,this.#n=void 0,!this.#u)this.#c("disconnected")}),e}async#N(){let e=await (f("yf2x9zz2"),import("./connection-yf2x9zz2.min.js"));for(let t of e.compileRegistry(this.#e))this.#t("error",{error:t});return this.#D=e,e}async#U(e,t){let{openConnection:i,addressIdOf:n}=await this.#N(),r=this.#w;if(r===void 0||this.#g===void 0)return y();let o=t??this.#g.current()??this.#g.rotate(),s=await n(o);if(e!==this.#h)throw new DOMException("The connection was cancelled","AbortError");let a={},d=i(this.#ee(a),r,o,{address:s,revokeAll:!!t});if(!t)a.connection=d;return this.#n=d,d.ready}get hasRelay(){return this.#w!==void 0}serve(e,t){return this.#N().then((i)=>i.servePort({...this.#L,server:this.#d,error:(n)=>this.#t("error",{error:n})},e,t))}disconnect(){this.#W("user")}disconnectAll(){let e=this.#g;if(!e)return y();return this.#T??=this.#Y(e).finally(()=>{this.#T=void 0})}async#Y(e){let t=this.#i!=="disconnected"||this.#v,i=e.current();this.#W("disconnect_all");let n=this.#h;if(i){this.#c("connecting");try{await this.#U(n,i)}catch(r){if(n===this.#h)this.#c("disconnected"),this.#v=t;throw x(r,!1)}finally{if(n===this.#h)this.#n?.close("disconnect_all"),this.#n=void 0}}if(e.rotate(),this.#O([]),t)await this.#j().catch((r)=>{throw x(r,!0)});else this.#c("disconnected")}#W(e){this.#z(),this.#v=!1,this.#h++;let t=this.#n;if(this.#n=void 0,this.#r=void 0,t?.close(e),this.#i==="disconnected")return;this.#o=void 0,this.#_(),this.#a++,this.#s("none"),this.#c("disconnected",e)}#B(e,t){let i=S.reconnectDelaysMs,n=(i[Math.min(t,i.length)-1]??0)*(0.8+0.4*Math.random());clearTimeout(this.#p),this.#p=setTimeout(()=>{this.#H().catch(()=>{})},n),this.#Z(),this.#u={reason:e,attempt:t,at:Date.now()+n},this.#c("reconnecting",t>1?void 0:e)}#H(){if(clearTimeout(this.#p),this.#p=void 0,this.#r!==void 0)return this.#r;let e=this.#j();return e.catch((t)=>{let i=this.#u;if(i===void 0||this.#r!==void 0)return;let n=t?.reason;if(n===void 0||P.has(n)){this.#B(i.reason,i.attempt+1);return}if(this.#z(),this.#i="disconnected",this.#t("error",{error:t instanceof Error?t:Error(String(t))}),this.#i==="disconnected")this.#t("statechange",{state:"disconnected"})}),e}#Z(){this.#$??=this.#D?.onWake(()=>{if(this.#p!==void 0)this.#H().catch(()=>{})})}#z(){clearTimeout(this.#p),this.#p=void 0,this.#$?.(),this.#$=void 0,this.#u=void 0}startPairing(){if(this.#f=!0,this.#A=!1,this.#i==="connected")this.#q()}#q(){this.#C(void 0),this.#A=this.#o?.pairing==="oidc",this.#n?.send({type:"pairing.start"})}stopPairing(){if(!this.#f)return;if(this.#f=!1,this.#i==="connected")this.#n?.send({type:"pairing.stop"});this.#_()}#_(){this.#F(void 0),this.#C(void 0)}revoke(e){let t=()=>!this.#l.some((i)=>i.grantId===e);return t()?Promise.resolve():this.#V({type:"grant.revoke",grantId:e},t)}#V(e,t){return!this.#o||this.#n?.send(e)!==!0?E():this.#D.answer(this,e,t,()=>this.#i==="connected",S.answerTimeoutMs)}showConnectDialog(e={}){if(this.#w===void 0)return y();let t=e.document??globalThis.document,i=this.#E;if(i!==void 0)return i.doc===t?i.shown:Promise.reject(new DOMException("showConnectDialog: the dialog is already open in another document","InvalidStateError"));let n=this.#Q(t).finally(()=>{if(this.#E?.shown===n)this.#E=void 0});return this.#E={doc:t,shown:n},n}async#Q(e){let t=this.connect();t.catch(()=>{});let{showConnectDialog:i}=await (f("my0pbqd7"),import("./connect-my0pbqd7.min.js"));await i(this,t,e,this.#d.name,this.#b)}addEventListener(e,t,i){super.addEventListener(e,t,i)}removeEventListener(e,t,i){super.removeEventListener(e,t,i)}#t(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}#c(e,t){if(this.#i===e&&e!=="reconnecting")return;this.#i=e,this.#t("statechange",t?{state:e,reason:t}:{state:e})}#s(e,t){if(this.#S===e&&t===void 0)return;this.#S=e,this.#M=e==="refused"?t:void 0,this.#t("identitychange",{identity:e,identityMessage:this.#M})}#F(e){if(this.#P===void 0&&e===void 0)return;this.#P=e,this.#t("pairingcode",{pairingCode:e})}#C(e){if(this.#x===e)return;this.#x=e,this.#t("pairinguntil",{pairingUntil:e})}#O(e){this.#l=Object.freeze(e.map(V)),this.#t("grantschange",{grants:this.#l})}#X(e){let t=this.#R;return (f("ba3dkf9p"),import("./confirm-ba3dkf9p.min.js")).then((i)=>i.confirmCall(this,e,t),()=>t?.(e)??!1)}get _allowed(){return[this.#e,this.#g,this.#J]}get _ui(){return this.#b}confirmInPage(e,t={}){let i=t.document??globalThis.document;if(i===void 0)return Promise.resolve(!1);return (f("ba3dkf9p"),import("./confirm-ba3dkf9p.min.js")).then((n)=>n.confirmInPage(this,e,i,{ui:this.#b}))}#ee(e){let t=()=>e.connection!==void 0&&this.#n===e.connection,i=!1;return{...this.#L,server:this.#d,app:this.#m,appName:this.#y,tabs:this.#K,library:{name:M,version:m},clientFor:(n)=>{let r=this.#l.find((s)=>s.grantId===n.grantId),o={kind:"relay",grantId:n.grantId,id:n.clientId,host:X(n.clientId)};if(r!==void 0)o.name=r.client.name;return o},sessionStarted:(n)=>{let r=ee(n);if(!t())return r;this.#o=r,this.#v=!1;let o=this.#f&&this.#u&&!this.#k&&this.#A&&r.pairing==="oidc";if(this.#k=!1,this.#z(),this.#O([...n.grants]),o)this.#C(new Date().toISOString());else if(this.#f)this.#q();if(this.#c("connected"),r.pairing==="oidc"&&this.#I)this.refreshIdentity();return r},pairingCode:(n)=>{if(t()&&this.#f)this.#F(n)},pairingOpen:(n)=>{if(t()&&this.#f)this.#C(n)},grantAdded:(n)=>{if(!t())return;this.#O([...this.#l.filter((r)=>r.grantId!==n.grantId),n])},grantRemoved:(n)=>{if(!t())return;this.#O(this.#l.filter((r)=>r.grantId!==n))},replaced:(n)=>{if(i)this.#t("replaced",n)},identityResult:(n,r,o)=>{if(!t())return;if(r!==this.#a)return;if(n)this.#s("bound");else this.#s("refused",o??"")},error:(n)=>{if(t())this.#t("error",{error:n})},closed:(n)=>{if(!t())return;if(n==="replaced")this.#v=i=!0;this.#n=void 0,this.#o=void 0;let r=this.#h;if(this.#_(),this.#a++,this.#s("none"),r!==this.#h)return;if(this.#G&&P.has(n))this.#B(n,1);else this.#c("disconnected",n)}}}}export{A as TabMcp,m as VERSION};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=40F361DB62742BD364756E2164756E21
|
|
5
5
|
//# sourceMappingURL=tab-mcp-client.min.js.map
|