@ractive-ch/tab-mcp-client 0.18.1 → 0.19.0-rc.2

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/README.md +360 -68
  3. package/allowed.d.ts +2 -2
  4. package/allowed.js.map +1 -1
  5. package/always-allowed.d.ts +15 -15
  6. package/cdn/allowed.min.js +2 -2
  7. package/cdn/allowed.min.js.map +2 -2
  8. package/cdn/confirm-ba3dkf9p.min.js +4 -0
  9. package/cdn/confirm-ba3dkf9p.min.js.map +10 -0
  10. package/cdn/connect-my0pbqd7.min.js +6 -0
  11. package/cdn/connect-my0pbqd7.min.js.map +12 -0
  12. package/cdn/connection-yf2x9zz2.min.js +17 -0
  13. package/cdn/{connection-0xqwz17v.min.js.map → connection-yf2x9zz2.min.js.map} +5 -5
  14. package/cdn/strings.min.js +4 -0
  15. package/cdn/strings.min.js.map +9 -0
  16. package/cdn/{tab-mcp-client-2vx9mcww.min.js → tab-mcp-client-8r6h3wza.min.js} +9 -8
  17. package/cdn/tab-mcp-client-8r6h3wza.min.js.map +11 -0
  18. package/cdn/tab-mcp-client-nnxcwrxp.min.js +5 -0
  19. package/cdn/tab-mcp-client-nnxcwrxp.min.js.map +11 -0
  20. package/cdn/{tab-mcp-client-5j3brdf3.min.js → tab-mcp-client-q758jr4g.min.js} +4 -4
  21. package/cdn/tab-mcp-client-q758jr4g.min.js.map +10 -0
  22. package/cdn/tab-mcp-client.min.js +3 -3
  23. package/cdn/tab-mcp-client.min.js.map +4 -4
  24. package/cdn/webmcp-84k58gsw.min.js +4 -0
  25. package/cdn/webmcp-84k58gsw.min.js.map +11 -0
  26. package/{confirm-bqfdrx3f.js → confirm-hymzwx3b.js} +7 -5
  27. package/confirm-hymzwx3b.js.map +10 -0
  28. package/confirm.d.ts +2 -2
  29. package/{connect-ztsgybpq.js → connect-fhtjdmf3.js} +75 -37
  30. package/connect-fhtjdmf3.js.map +10 -0
  31. package/connect.d.ts +7 -6
  32. package/{connection-gang7f5x.js → connection-73fbg99k.js} +70 -8
  33. package/connection-73fbg99k.js.map +16 -0
  34. package/connection.d.ts +23 -2
  35. package/dialog.d.ts +19 -9
  36. package/extension.d.ts +373 -0
  37. package/extension.js +415 -0
  38. package/extension.js.map +10 -0
  39. package/handshake.d.ts +82 -0
  40. package/index-00p8b969.js +221 -0
  41. package/index-00p8b969.js.map +11 -0
  42. package/index-1tssct09.js +58 -0
  43. package/index-1tssct09.js.map +11 -0
  44. package/{index-c1c266tm.js → index-7qqhn3zv.js} +28 -110
  45. package/index-7qqhn3zv.js.map +10 -0
  46. package/index-s31xrfa2.js.map +1 -1
  47. package/index.d.ts +1 -1
  48. package/index.js +59 -64
  49. package/index.js.map +4 -4
  50. package/internal.d.ts +2 -0
  51. package/mcp.d.ts +5 -3
  52. package/package.json +11 -2
  53. package/protocol.d.ts +11 -1
  54. package/react.d.ts +11 -4
  55. package/react.js +57 -10
  56. package/react.js.map +5 -4
  57. package/secret.d.ts +1 -1
  58. package/setup.d.ts +4 -1
  59. package/setup.js +3 -2
  60. package/setup.js.map +1 -1
  61. package/strings.d.ts +149 -28
  62. package/strings.js +13 -0
  63. package/strings.js.map +9 -0
  64. package/tab-mcp.d.ts +30 -7
  65. package/text.d.ts +39 -0
  66. package/types.d.ts +76 -17
  67. package/webmcp-d2ec3v3g.js +221 -0
  68. package/webmcp-d2ec3v3g.js.map +11 -0
  69. package/webmcp.d.ts +17 -4
  70. package/cdn/confirm-d722a9eb.min.js +0 -4
  71. package/cdn/confirm-d722a9eb.min.js.map +0 -10
  72. package/cdn/connect-x6ws6wqt.min.js +0 -6
  73. package/cdn/connect-x6ws6wqt.min.js.map +0 -12
  74. package/cdn/connection-0xqwz17v.min.js +0 -17
  75. package/cdn/tab-mcp-client-2vx9mcww.min.js.map +0 -12
  76. package/cdn/tab-mcp-client-5j3brdf3.min.js.map +0 -10
  77. package/cdn/webmcp-khy4f5rj.min.js +0 -4
  78. package/cdn/webmcp-khy4f5rj.min.js.map +0 -10
  79. package/confirm-bqfdrx3f.js.map +0 -10
  80. package/connect-ztsgybpq.js.map +0 -10
  81. package/connection-gang7f5x.js.map +0 -16
  82. package/index-5jyqehpk.js +0 -63
  83. package/index-5jyqehpk.js.map +0 -11
  84. package/index-c1c266tm.js.map +0 -11
  85. package/webmcp-zq1enyz0.js +0 -57
  86. package/webmcp-zq1enyz0.js.map +0 -10
package/allowed.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,
3
3
  * per connected AI app, for a page that draws its own switches ("always
4
- * allow this tool", "allow everything, no questions asked"). The library's
4
+ * allow this tool", "always allow everything"). The library's
5
5
  * dialogs use the same allowances. An entry of its own, out of the core
6
6
  * (DEC-200).
7
7
  *
@@ -22,7 +22,7 @@ export type { AllowedTool, AllowedTools };
22
22
  * call. Kept in its `storage` next to the address secret until the app is
23
23
  * disconnected (in memory with `storage: null` or `alwaysAllow:
24
24
  * "until-reload"`); they end with the app's grant, as the relay reports it,
25
- * and with `newAddress()`. A call they allow runs without asking, with the
25
+ * and with `disconnectAll()`. A call they allow runs without asking, with the
26
26
  * library's dialog and with the page's own `onConfirm` alike.
27
27
  */
28
28
  export declare function allowedTools(mcp: TabMcp): AllowedTools;
package/allowed.js.map CHANGED
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/allowed.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,\n * per connected AI app, for a page that draws its own switches (\"always\n * allow this tool\", \"allow everything, no questions asked\"). The library's\n * dialogs use the same allowances. An entry of its own, out of the core\n * (DEC-200).\n *\n * ```ts\n * import { allowedTools } from \"@ractive-ch/tab-mcp-client/allowed\";\n * const allowed = allowedTools(mcp);\n * for (const tool of allowed.tools()) {\n * box.checked = allowed.has(grant.grantId, tool.name);\n * box.onchange = () => box.checked ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name);\n * }\n * ```\n */\n\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedFor,\n} from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\n\nexport type { AllowedTool, AllowedTools };\n\n/**\n * The allowances of `mcp`: one object per `TabMcp`, the same for every\n * call. Kept in its `storage` next to the address secret until the app is\n * disconnected (in memory with `storage: null` or `alwaysAllow:\n * \"until-reload\"`); they end with the app's grant, as the relay reports it,\n * and with `newAddress()`. A call they allow runs without asking, with the\n * library's dialog and with the page's own `onConfirm` alike.\n */\nexport function allowedTools(mcp: TabMcp): AllowedTools {\n\treturn allowedFor(mcp);\n}\n"
5
+ "/**\n * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,\n * per connected AI app, for a page that draws its own switches (\"always\n * allow this tool\", \"always allow everything\"). The library's\n * dialogs use the same allowances. An entry of its own, out of the core\n * (DEC-200).\n *\n * ```ts\n * import { allowedTools } from \"@ractive-ch/tab-mcp-client/allowed\";\n * const allowed = allowedTools(mcp);\n * for (const tool of allowed.tools()) {\n * box.checked = allowed.has(grant.grantId, tool.name);\n * box.onchange = () => box.checked ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name);\n * }\n * ```\n */\n\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedFor,\n} from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\n\nexport type { AllowedTool, AllowedTools };\n\n/**\n * The allowances of `mcp`: one object per `TabMcp`, the same for every\n * call. Kept in its `storage` next to the address secret until the app is\n * disconnected (in memory with `storage: null` or `alwaysAllow:\n * \"until-reload\"`); they end with the app's grant, as the relay reports it,\n * and with `disconnectAll()`. A call they allow runs without asking, with the\n * library's dialog and with the page's own `onConfirm` alike.\n */\nexport function allowedTools(mcp: TabMcp): AllowedTools {\n\treturn allowedFor(mcp);\n}\n"
6
6
  ],
7
7
  "mappings": ";;;;;AAkCO,SAAS,YAAY,CAAC,KAA2B;AAAA,EACvD,OAAO,WAAW,GAAG;AAAA;",
8
8
  "debugId": "F620A76B3CA348AE64756E2164756E21",
@@ -12,10 +12,10 @@
12
12
  * once (only one tab at a time holds the connection, DEC-095).
13
13
  *
14
14
  * An allowance ends with its grant, and only on what the relay says: the
15
- * grants of a new session, a removed grant, `newAddress()` (the relay
15
+ * grants of a new session, a removed grant, `disconnectAll()` (the relay
16
16
  * revoked them all). A dropped connection, or a page that has not connected
17
17
  * yet, keeps them: `grantschange` does not fire then. They also belong to
18
- * the address secret they were made under, so a new secret (`newAddress()`
18
+ * the address secret they were made under, so a new secret (`disconnectAll()`
19
19
  * here or in another tab) ends them even where nothing listened.
20
20
  *
21
21
  * Out of the core: the confirmation (`confirm.ts`, which the core loads for
@@ -50,8 +50,8 @@ export interface AllowedTool {
50
50
  */
51
51
  export interface AllowedTools {
52
52
  /**
53
- * `true`: kept in the page's `storage` until the app is disconnected;
54
- * `false`: in memory, until the page is reloaded or the app is
53
+ * `true`: kept in the page's `storage` until the AI app is disconnected;
54
+ * `false`: in memory, until the page is reloaded or the AI app is
55
55
  * disconnected (`alwaysAllow: "until-reload"`, `storage: null`).
56
56
  */
57
57
  readonly kept: boolean;
@@ -61,40 +61,40 @@ export interface AllowedTools {
61
61
  */
62
62
  tools(): AllowedTool[];
63
63
  /**
64
- * The names of the tools allowed one by one for this app, in the order
64
+ * The names of the tools allowed one by one for this AI app, in the order
65
65
  * allowed; also one that is not registered right now (it runs without
66
66
  * asking again once it is back unchanged). One registered now with another
67
67
  * title or description than the user allowed is not in it (it asks).
68
68
  */
69
69
  list(grantId: string): string[];
70
70
  /**
71
- * Whether a call of this tool by this app runs without asking now: the
72
- * app is in `mcp.grants`, and "everything" is on or the tool is allowed
71
+ * Whether a call of this tool by this AI app runs without asking now: the
72
+ * AI app is in `mcp.grants`, and "everything" is on or the tool is allowed
73
73
  * and registered unchanged.
74
74
  */
75
75
  has(grantId: string, name: string): boolean;
76
76
  /**
77
- * Allow one tool for this app from now on, as it is registered now (its
78
- * title and description). Nothing happens for an app that is not in
77
+ * Allow one tool for this AI app from now on, as it is registered now (its
78
+ * title and description). Nothing happens for an AI app that is not in
79
79
  * `mcp.grants` or a tool that is not in `tools()`.
80
80
  */
81
81
  allow(grantId: string, name: string): void;
82
82
  /**
83
- * Ask again before this app runs this tool. While "everything" is on for
84
- * the app, that goes off too (asking again errs towards asking); the
83
+ * Ask again before this AI app runs this tool. While "everything" is on for
84
+ * the AI app, that goes off too (asking again errs towards asking); the
85
85
  * other tools allowed one by one stay allowed.
86
86
  */
87
87
  ask(grantId: string, name: string): void;
88
- /** Whether "Allow everything, no questions asked" is on for this app. */
88
+ /** Whether "Always allow everything" is on for this AI app. */
89
89
  everything(grantId: string): boolean;
90
90
  /**
91
- * "Allow everything, no questions asked" for this app: every tool runs
91
+ * "Always allow everything" for this AI app: every tool runs
92
92
  * without asking, with any arguments, also tools registered later, changed
93
- * ones and destructive ones. Turning it on does nothing for an app that
93
+ * ones and destructive ones. Turning it on does nothing for an AI app that
94
94
  * is not in `mcp.grants`.
95
95
  */
96
96
  setEverything(grantId: string, on: boolean): void;
97
- /** Ask again for everything of this app: its tools and "everything". */
97
+ /** Ask again for everything of this AI app: its tools and "everything". */
98
98
  forget(grantId: string): void;
99
99
  /**
100
100
  * Calls `listener` on every change of the allowances (also one in
@@ -1,4 +1,4 @@
1
- import{r}from"./tab-mcp-client-5j3brdf3.min.js";function e(o){return r(o)}export{e as allowedTools};
1
+ import{o}from"./tab-mcp-client-q758jr4g.min.js";function t(l){return o(l)}export{t as allowedTools};
2
2
 
3
- //# debugId=276A38D7EC2846AF64756E2164756E21
3
+ //# debugId=93CCDDB92040487964756E2164756E21
4
4
  //# sourceMappingURL=allowed.min.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/allowed.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,\n * per connected AI app, for a page that draws its own switches (\"always\n * allow this tool\", \"allow everything, no questions asked\"). The library's\n * dialogs use the same allowances. An entry of its own, out of the core\n * (DEC-200).\n *\n * ```ts\n * import { allowedTools } from \"@ractive-ch/tab-mcp-client/allowed\";\n * const allowed = allowedTools(mcp);\n * for (const tool of allowed.tools()) {\n * box.checked = allowed.has(grant.grantId, tool.name);\n * box.onchange = () => box.checked ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name);\n * }\n * ```\n */\n\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedFor,\n} from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\n\nexport type { AllowedTool, AllowedTools };\n\n/**\n * The allowances of `mcp`: one object per `TabMcp`, the same for every\n * call. Kept in its `storage` next to the address secret until the app is\n * disconnected (in memory with `storage: null` or `alwaysAllow:\n * \"until-reload\"`); they end with the app's grant, as the relay reports it,\n * and with `newAddress()`. A call they allow runs without asking, with the\n * library's dialog and with the page's own `onConfirm` alike.\n */\nexport function allowedTools(mcp: TabMcp): AllowedTools {\n\treturn allowedFor(mcp);\n}\n"
5
+ "/**\n * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,\n * per connected AI app, for a page that draws its own switches (\"always\n * allow this tool\", \"always allow everything\"). The library's\n * dialogs use the same allowances. An entry of its own, out of the core\n * (DEC-200).\n *\n * ```ts\n * import { allowedTools } from \"@ractive-ch/tab-mcp-client/allowed\";\n * const allowed = allowedTools(mcp);\n * for (const tool of allowed.tools()) {\n * box.checked = allowed.has(grant.grantId, tool.name);\n * box.onchange = () => box.checked ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name);\n * }\n * ```\n */\n\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedFor,\n} from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\n\nexport type { AllowedTool, AllowedTools };\n\n/**\n * The allowances of `mcp`: one object per `TabMcp`, the same for every\n * call. Kept in its `storage` next to the address secret until the app is\n * disconnected (in memory with `storage: null` or `alwaysAllow:\n * \"until-reload\"`); they end with the app's grant, as the relay reports it,\n * and with `disconnectAll()`. A call they allow runs without asking, with the\n * library's dialog and with the page's own `onConfirm` alike.\n */\nexport function allowedTools(mcp: TabMcp): AllowedTools {\n\treturn allowedFor(mcp);\n}\n"
6
6
  ],
7
7
  "mappings": "gDAkCO,SAAS,CAAY,CAAC,EAA2B,CACvD,OAAO,EAAW,CAAG",
8
- "debugId": "276A38D7EC2846AF64756E2164756E21",
8
+ "debugId": "93CCDDB92040487964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -0,0 +1,4 @@
1
+ import{u}from"./tab-mcp-client-nnxcwrxp.min.js";import{a,r,e,t,s,d,l}from"./tab-mcp-client-8r6h3wza.min.js";import{o}from"./tab-mcp-client-q758jr4g.min.js";function ee(f){try{return s(JSON.stringify(f,null,2))}catch{return}}var ne=750,te=500,J=new WeakMap;function K(f,n,b={}){if(f.signal.aborted)return Promise.resolve("deny");let g=J.get(n);if(g===void 0)g={shown:!1,waiting:[]},J.set(n,g);let c=g,i=()=>{let h=c.waiting.shift();c.shown=h!==void 0,h?.(),c.changed?.()},L=()=>{try{return ie(f,n,b,c,i)}catch(h){return i(),Promise.reject(h)}};if(!c.shown)return c.shown=!0,L();return new Promise((h)=>{let v=()=>{if(f.signal.removeEventListener("abort",E),b.allowedNow?.()===!0){h("allow"),i();return}h(L())},E=()=>{c.waiting.splice(c.waiting.indexOf(v),1),c.changed?.(),h("deny")};f.signal.addEventListener("abort",E,{once:!0}),c.waiting.push(v),c.changed?.()})}function ie(f,n,b,g,c){let i=b.strings??a(void 0),L=b.allowDelayMs??ne,h=f.tool.title??f.tool.name,v=d(f.client,i),E={tool:h,client:v},{dialog:m,id:C}=l(n,"tab-mcp-confirm",i,...r(n,i.confirmTitle,E)),I=e(n,"p",{className:"tab-mcp-waiting"}),S=()=>{let p=g.waiting.length;I.hidden=p===0,I.textContent=u(i.waiting,p,i)};g.changed=S,S();let z=t(n,i.deny,()=>m.close("deny"),"tab-mcp-deny","primary"),B=(p,j,R)=>{let A=t(n,p,()=>{if(!A.disabled)m.close(j)},R);return A},k=[B(i.allow,"allow","tab-mcp-allow")],W=[],Q=b.alwaysAllow;if(Q===!0||Q==="until-reload"){let p=Q===!0;k.unshift(B(p?i.alwaysAllow:i.allowUntilReload,"always","tab-mcp-always")),W.push(e(n,"p",{className:"tab-mcp-always-note"},...r(n,p?i.alwaysAllowNote:i.allowUntilReloadNote,E)))}let Y=e(n,"div",{className:"tab-mcp-actions"},z,...k.flatMap((p)=>[" ",p])),N=!1,U=!1,M=()=>{for(let p of k)p.disabled=!(N&&U)};M();let T=ee(f.arguments),y=e(n,"pre",{className:"tab-mcp-arguments",id:`${C}-arguments`,text:T??i.argumentsHidden});if(T===void 0)for(let p of[...k,...W])p.hidden=!0;y.dir="ltr",y.style.setProperty("white-space","pre-wrap"),y.style.setProperty("overflow-wrap","anywhere"),y.style.setProperty("max-height","var(--tab-mcp-arguments-height, min(50vh, 24rem))"),y.style.setProperty("overflow","auto"),y.hidden=Object.keys(f.arguments).length===0;let O=e(n,"p",{className:"tab-mcp-scroll-note",text:i.scrollToAllow});O.hidden=!0;let _=e(n,"p",{id:`${C}-who`},...r(n,i.confirmWho,E));m.setAttribute("aria-describedby",T!==void 0&&!y.hidden&&T.length<=te?`${_.id} ${y.id}`:_.id),m.append(_,e(n,"p",{className:"tab-mcp-description",text:f.tool.description}),y,O,Y,...W,I),n.body.append(m);let x=n.defaultView;return new Promise((p,j)=>{let R=()=>m.close("deny");f.signal.addEventListener("abort",R,{once:!0});let A,P,F=()=>{if(P!==void 0&&n.title===P.shown)n.title=P.page;P=void 0},X=()=>{if(n.visibilityState!=="hidden")F();else if(P===void 0)P={page:n.title,shown:`${i.titlePrefix}${n.title}`},n.title=P.shown},D=(w)=>{if(w?.type==="close"&&w.target===m)return;if(X(),clearTimeout(A),A=void 0,N=!1,M(),w?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;A=setTimeout(()=>{N=!0,M()},L)},H=()=>{if(U)return;if(y.scrollTop+y.clientHeight<y.scrollHeight-2){O.hidden=!1,y.tabIndex=0;return}U=!0,O.hidden=!0,M()},V=(w)=>{if(N)return;let q=w.target?.localName==="button";if(w.key==="Escape"||q&&(w.key==="Enter"||w.key===" "))w.preventDefault()},Z=(w)=>{if(!N)w.preventDefault()};n.addEventListener("visibilitychange",D),n.addEventListener("close",D,!0),x?.addEventListener("focus",D),x?.addEventListener("blur",D),x?.addEventListener("resize",H),y.addEventListener("scroll",H),m.addEventListener("keydown",V),m.addEventListener("keyup",V),m.addEventListener("cancel",Z);let G=()=>{if(clearTimeout(A),F(),n.removeEventListener("visibilitychange",D),n.removeEventListener("close",D,!0),x?.removeEventListener("focus",D),x?.removeEventListener("blur",D),x?.removeEventListener("resize",H),f.signal.removeEventListener("abort",R),m.remove(),g.changed===S)g.changed=void 0};m.addEventListener("close",()=>{let w=m.returnValue;G(),p(w==="allow"||w==="always"?w:"deny"),c()},{once:!0});try{m.showModal()}catch(w){G(),j(w),c();return}z.focus(),D(),H()})}function ae(f,n,b,g={}){let{client:c}=n,i=a(g.ui),{allowDelayMs:L}=g;if(c.kind!=="relay")return K(n,b,{strings:i,allowDelayMs:L}).then((C)=>C==="allow");let{grantId:h}=c,v=o(f),E=()=>v.allows(h,n.tool);if(E())return Promise.resolve(!0);let m=g.alwaysAllow??v.offered;return K(n,b,{strings:i,allowDelayMs:L,alwaysAllow:m!==!1&&(m===!0&&v.kept?!0:"until-reload"),allowedNow:E}).then((C)=>{if(C==="always")v.keep(h,n.tool);return C!=="deny"})}function se(f,n,b){let{client:g}=n;if(g.kind==="relay"&&o(f).allows(g.grantId,n.tool))return Promise.resolve(!0);if(b===void 0)return f.confirmInPage(n);return Promise.resolve().then(()=>b(n)).then((c)=>c==="unanswered"?c:c===!0)}export{se as confirmCall,ae as confirmInPage};
2
+
3
+ //# debugId=219E3EE7F5DA6FA064756E2164756E21
4
+ //# sourceMappingURL=confirm-ba3dkf9p.min.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/confirm.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The confirmation of consequential tools, loaded on demand: a `<dialog>`\n * per call, one shown at a time per document, and Always allow (or Allow\n * until reload) for the tools a user allows (`always-allowed.ts`).\n */\n\nimport { allowedFor, type ConfirmHost } from \"./always-allowed.ts\";\nimport {\n\tbutton,\n\tclientLabel,\n\tel,\n\tfill,\n\tnewDialog,\n\tplural,\n\tstringsOf,\n\tvisible,\n} from \"./dialog.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmAnswer,\n\tConfirmHandler,\n\tConfirmRequest,\n\tDialogOptions,\n} from \"./types.ts\";\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) Invisible and\n * direction characters are shown as escapes, so the text is still JSON for\n * the same arguments; the tool gets them unchanged. `undefined` when they\n * cannot be shown, and then \"Allow once\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn visible(JSON.stringify(args, null, 2));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * How long \"Allow once\" stays disabled after the confirmation is shown, while the\n * page is visible and focused (CU 17: a constant; tests pass `allowDelayMs`).\n */\nexport const ALLOW_DELAY_MS = 750;\n\n/** The user's answer: \"always\" allows this tool for this AI app (Always allow, or until reload). */\nexport type DialogAnswer = \"allow\" | \"always\" | \"deny\";\n\n/** Arguments up to this many characters are read out with the question. */\nconst DESCRIBED_ARGUMENTS = 500;\n\n/** Options of `confirmDialog`. */\nexport interface ConfirmDialogOptions {\n\t/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */\n\tallowDelayMs?: number | undefined;\n\t/**\n\t * Offer a third button: `true` \"Always allow\" (kept until the app is\n\t * disconnected), `\"until-reload\"` \"Allow until reload\" (kept in memory).\n\t */\n\talwaysAllow?: boolean | \"until-reload\" | undefined;\n\t/** Asked when a waiting call's turn comes: `true` answers \"allow\" unseen. */\n\tallowedNow?: () => boolean;\n\tstrings?: DialogStrings;\n}\n\n/**\n * The confirmations of one document: one is shown at a time, the others\n * wait in order, so that the click that answered one cannot answer the next\n * (each starts its own delay when it is shown).\n */\ninterface ConfirmQueue {\n\tshown: boolean;\n\twaiting: (() => void)[];\n\t/** Updates the shown dialog's line about the calls that wait. */\n\tchanged?: (() => void) | undefined;\n}\n\nconst queues = new WeakMap<Document, ConfirmQueue>();\n\n/**\n * Ask whether a consequential tool may run. \"Always allow\" (or \"Allow until\n * reload\") is offered only with `alwaysAllow` (DEC-096, DEC-200); never\n * \"allow everything\": that is a deliberate act in the connect dialog, not\n * an answer to one question. One confirmation is shown at a time per\n * document; the others wait their turn, and a call cancelled while it waits\n * is never shown. \"Allow once\" and \"Always allow\" stay disabled until the\n * page has been visible and focused for 750 ms while the dialog is open and\n * is the top one, so a click meant for the page, the click that brings the\n * tab or window back, or the one that closed another dialog, cannot\n * approve; leaving the page disables them again. They also wait until the\n * arguments have been scrolled to their end. Before the delay has run out,\n * Enter or Space on a button and Escape are ignored, so typing meant for the\n * page cannot refuse either. Everything else (Don't allow, Escape, an\n * aborted call) is \"deny\". `allowedNow` is asked when a waiting call's turn\n * comes: `true` (the user allowed it meanwhile) answers \"allow\"\n * without showing it.\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions = {},\n): Promise<DialogAnswer> {\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tlet queue = queues.get(doc);\n\tif (queue === undefined) {\n\t\tqueue = { shown: false, waiting: [] };\n\t\tqueues.set(doc, queue);\n\t}\n\tconst q = queue;\n\t/** The shown confirmation closed: the next one, if any. */\n\tconst next = () => {\n\t\tconst start = q.waiting.shift();\n\t\tq.shown = start !== undefined;\n\t\tstart?.();\n\t\tq.changed?.();\n\t};\n\tconst show = () => {\n\t\ttry {\n\t\t\treturn showConfirm(request, doc, options, q, next);\n\t\t} catch (error) {\n\t\t\tnext(); // not shown: the queue goes on\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t};\n\tif (!q.shown) {\n\t\tq.shown = true;\n\t\treturn show();\n\t}\n\treturn new Promise((resolve) => {\n\t\tconst start = () => {\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tif (options.allowedNow?.() === true) {\n\t\t\t\tresolve(\"allow\");\n\t\t\t\tnext();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(show());\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tq.waiting.splice(q.waiting.indexOf(start), 1);\n\t\t\tq.changed?.();\n\t\t\tresolve(\"deny\");\n\t\t};\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tq.waiting.push(start);\n\t\tq.changed?.();\n\t});\n}\n\n/** `confirmDialog` once it is this request's turn; calls `next` when it closes. */\nfunction showConfirm(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmDialogOptions,\n\tqueue: ConfirmQueue,\n\tnext: () => void,\n): Promise<DialogAnswer> {\n\tconst s = options.strings ?? stringsOf(undefined);\n\tconst delay = options.allowDelayMs ?? ALLOW_DELAY_MS;\n\tconst tool = request.tool.title ?? request.tool.name;\n\tconst client = clientLabel(request.client, s);\n\tconst names = { tool, client };\n\tconst { dialog, id } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-confirm\",\n\t\ts,\n\t\t...fill(doc, s.confirmTitle, names),\n\t);\n\tconst waiting = el(doc, \"p\", { className: \"tab-mcp-waiting\" });\n\tconst showWaiting = () => {\n\t\tconst n = queue.waiting.length;\n\t\twaiting.hidden = n === 0;\n\t\twaiting.textContent = plural(s.waiting, n, s);\n\t};\n\tqueue.changed = showWaiting;\n\tshowWaiting();\n\t// The safe choice is the default: focused, and the one that stands out.\n\tconst deny = button(\n\t\tdoc,\n\t\ts.deny,\n\t\t() => dialog.close(\"deny\"),\n\t\t\"tab-mcp-deny\",\n\t\t\"primary\",\n\t);\n\tconst approving = (text: string, answer: DialogAnswer, className: string) => {\n\t\tconst node = button(\n\t\t\tdoc,\n\t\t\ttext,\n\t\t\t() => {\n\t\t\t\tif (!node.disabled) dialog.close(answer);\n\t\t\t},\n\t\t\tclassName,\n\t\t);\n\t\treturn node;\n\t};\n\t// The approving buttons: Allow, and Always allow (or Allow until reload)\n\t// when the page offers it, saying how long it lasts.\n\tconst approve = [approving(s.allow, \"allow\", \"tab-mcp-allow\")];\n\tconst extra: HTMLElement[] = [];\n\tconst mode = options.alwaysAllow;\n\tif (mode === true || mode === \"until-reload\") {\n\t\tconst kept = mode === true;\n\t\t// Left of Allow: not where most platforms put the default (CU 11).\n\t\tapprove.unshift(\n\t\t\tapproving(\n\t\t\t\tkept ? s.alwaysAllow : s.allowUntilReload,\n\t\t\t\t\"always\",\n\t\t\t\t\"tab-mcp-always\",\n\t\t\t),\n\t\t);\n\t\textra.push(\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"p\",\n\t\t\t\t{ className: \"tab-mcp-always-note\" },\n\t\t\t\t...fill(doc, kept ? s.alwaysAllowNote : s.allowUntilReloadNote, names),\n\t\t\t),\n\t\t);\n\t}\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t...approve.flatMap((b) => [\" \", b]),\n\t);\n\t// Approving needs both: the delay ran out while the user saw the page\n\t// (`settled`), and the arguments were seen to their end (`seen`).\n\tlet settled = false;\n\tlet seen = false;\n\tconst enable = () => {\n\t\tfor (const b of approve) b.disabled = !(settled && seen);\n\t};\n\tenable();\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\tid: `${id}-arguments`,\n\t\ttext: shown ?? s.argumentsHidden,\n\t});\n\tif (shown === undefined) {\n\t\tfor (const node of [...approve, ...extra]) node.hidden = true;\n\t}\n\targs.dir = \"ltr\";\n\t// Inline, so the arguments stay readable in full without the stylesheet:\n\t// wrapped (also a long word, at 360 px), scrolling when long.\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"overflow-wrap\", \"anywhere\");\n\targs.style.setProperty(\n\t\t\"max-height\",\n\t\t\"var(--tab-mcp-arguments-height, min(50vh, 24rem))\",\n\t);\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\t// The caller chooses the order of the keys, so what matters may come\n\t// last: below the end of the box, the user is told, and Allow waits.\n\tconst scrollNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-scroll-note\",\n\t\ttext: s.scrollToAllow,\n\t});\n\tscrollNote.hidden = true;\n\tconst who = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ id: `${id}-who` },\n\t\t...fill(doc, s.confirmWho, names),\n\t);\n\tdialog.setAttribute(\n\t\t\"aria-describedby\",\n\t\tshown !== undefined && !args.hidden && shown.length <= DESCRIBED_ARGUMENTS\n\t\t\t? `${who.id} ${args.id}`\n\t\t\t: who.id,\n\t);\n\tdialog.append(\n\t\twho,\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tscrollNote,\n\t\tactions,\n\t\t...extra,\n\t\twaiting,\n\t);\n\tdoc.body.append(dialog);\n\tconst view = doc.defaultView;\n\treturn new Promise((resolve, reject) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t// In a hidden tab, the tab's title says that the page asks (CU 9): the\n\t\t// AI app waits meanwhile. Put back when the tab is shown or the dialog\n\t\t// closes, unless the page changed its title since.\n\t\tlet title: { page: string; shown: string } | undefined;\n\t\tconst untitle = () => {\n\t\t\tif (title !== undefined && doc.title === title.shown)\n\t\t\t\tdoc.title = title.page;\n\t\t\ttitle = undefined;\n\t\t};\n\t\tconst retitle = () => {\n\t\t\tif (doc.visibilityState !== \"hidden\") untitle();\n\t\t\telse if (title === undefined) {\n\t\t\t\ttitle = { page: doc.title, shown: `${s.titlePrefix}${doc.title}` };\n\t\t\t\tdoc.title = title.shown;\n\t\t\t}\n\t\t};\n\t\t// The delay counts only while the user can see the page: tools are\n\t\t// called while the user is in the AI app, so the dialog often opens in\n\t\t// a background tab or window. Any change starts it again from zero\n\t\t// (DEC-087), and so does another dialog of the page that closes over\n\t\t// this one.\n\t\tconst arm = (event?: Event) => {\n\t\t\tif (event?.type === \"close\" && event.target === dialog) return;\n\t\t\tretitle();\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t\tsettled = false;\n\t\t\tenable();\n\t\t\tif (\n\t\t\t\tevent?.type === \"blur\" ||\n\t\t\t\tdoc.visibilityState === \"hidden\" ||\n\t\t\t\t!doc.hasFocus()\n\t\t\t)\n\t\t\t\treturn;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tsettled = true;\n\t\t\t\tenable();\n\t\t\t}, delay);\n\t\t};\n\t\t// Scrolled to the end, or nothing to scroll (also without layout).\n\t\tconst check = () => {\n\t\t\tif (seen) return;\n\t\t\tif (args.scrollTop + args.clientHeight < args.scrollHeight - 2) {\n\t\t\t\tscrollNote.hidden = false;\n\t\t\t\targs.tabIndex = 0; // to scroll it with the keyboard\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tseen = true;\n\t\t\tscrollNote.hidden = true;\n\t\t\tenable();\n\t\t};\n\t\t// Not answered by a key before the delay has run out.\n\t\tconst guard = (event: KeyboardEvent) => {\n\t\t\tif (settled) return;\n\t\t\tconst onButton = (event.target as Element | null)?.localName === \"button\";\n\t\t\tif (\n\t\t\t\tevent.key === \"Escape\" ||\n\t\t\t\t(onButton && (event.key === \"Enter\" || event.key === \" \"))\n\t\t\t)\n\t\t\t\tevent.preventDefault();\n\t\t};\n\t\tconst onCancel = (event: Event) => {\n\t\t\tif (!settled) event.preventDefault();\n\t\t};\n\t\tdoc.addEventListener(\"visibilitychange\", arm);\n\t\tdoc.addEventListener(\"close\", arm, true); // `close` does not bubble\n\t\tview?.addEventListener(\"focus\", arm);\n\t\tview?.addEventListener(\"blur\", arm);\n\t\tview?.addEventListener(\"resize\", check);\n\t\targs.addEventListener(\"scroll\", check);\n\t\tdialog.addEventListener(\"keydown\", guard);\n\t\tdialog.addEventListener(\"keyup\", guard);\n\t\tdialog.addEventListener(\"cancel\", onCancel);\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tuntitle();\n\t\t\tdoc.removeEventListener(\"visibilitychange\", arm);\n\t\t\tdoc.removeEventListener(\"close\", arm, true);\n\t\t\tview?.removeEventListener(\"focus\", arm);\n\t\t\tview?.removeEventListener(\"blur\", arm);\n\t\t\tview?.removeEventListener(\"resize\", check);\n\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tdialog.remove();\n\t\t\tif (queue.changed === showWaiting) queue.changed = undefined;\n\t\t};\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tcleanup();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t\tnext();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\ttry {\n\t\t\tdialog.showModal();\n\t\t} catch (error) {\n\t\t\t// Never shown, so never closed: the queue must not wait for it.\n\t\t\tcleanup();\n\t\t\treject(error);\n\t\t\tnext();\n\t\t\treturn;\n\t\t}\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\tarm();\n\t\tcheck();\n\t});\n}\n\n/** Options of this chunk's `confirmInPage`. */\nexport interface ConfirmInPageOptions {\n\t/**\n\t * The third button, for an AI app through the relay (`kind: \"relay\"`):\n\t * `true` \"Always allow\" (kept in the `TabMcp`'s `storage`; \"Allow until\n\t * reload\" where it is kept in memory, as for a stand-in), `\"until-reload\"`\n\t * \"Allow until reload\", `false` none. Default: the `TabMcp`'s\n\t * `alwaysAllow`; none for a stand-in.\n\t */\n\talwaysAllow?: boolean | \"until-reload\" | undefined;\n\t/** Texts of the dialog, as `TabMcpOptions.ui`. */\n\tui?: DialogOptions | undefined;\n\t/** Tests only: another delay than {@link ALLOW_DELAY_MS}. */\n\tallowDelayMs?: number | undefined;\n}\n\n/**\n * `TabMcp.confirmInPage`: the confirmation, and the tools the user allowed\n * (`always-allowed.ts`), which run unasked. Only for an AI app through the\n * relay: an agent in the browser and a served port have no identity to\n * remember an answer for (DEC-115, DEC-124).\n *\n * Code that loads this chunk itself may pass a stand-in of its own for\n * `mcp` (`ConfirmHost`: `grants`, optionally `grantschange` events). Its\n * allowances live in memory, for its grants only, until the page is\n * reloaded, and exist only where the caller offers them with\n * `options.alwaysAllow`; without it nothing is allowed and nothing is kept.\n */\nexport function confirmInPage(\n\tmcp: TabMcp | ConfirmHost,\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: ConfirmInPageOptions = {},\n): Promise<boolean> {\n\tconst { client } = request;\n\tconst strings = stringsOf(options.ui);\n\tconst { allowDelayMs } = options;\n\tif (client.kind !== \"relay\")\n\t\treturn confirmDialog(request, doc, { strings, allowDelayMs }).then(\n\t\t\t(answer) => answer === \"allow\",\n\t\t);\n\tconst { grantId } = client;\n\tconst allowed = allowedFor(mcp);\n\tconst allowedNow = () => allowed.allows(grantId, request.tool);\n\tif (allowedNow()) return Promise.resolve(true);\n\tconst offer = options.alwaysAllow ?? allowed.offered;\n\t// Asked again when its turn comes: the call before it in the queue may\n\t// have been allowed meanwhile.\n\treturn confirmDialog(request, doc, {\n\t\tstrings,\n\t\tallowDelayMs,\n\t\t// \"Always\" only where it outlives a reload.\n\t\talwaysAllow:\n\t\t\toffer !== false &&\n\t\t\t(offer === true && allowed.kept ? true : \"until-reload\"),\n\t\tallowedNow,\n\t}).then((answer) => {\n\t\t// Only while the grant is still there: a revoked app gets nothing\n\t\t// (`keep` checks).\n\t\tif (answer === \"always\") allowed.keep(grantId, request.tool);\n\t\treturn answer !== \"deny\";\n\t});\n}\n\n/**\n * The core's question about a consequential call: an AI app's call that the\n * user allowed runs without asking, with the dialog and with the page's own\n * `onConfirm` alike; any other goes to `onConfirm`, else to the dialog.\n * Only AI apps through the relay have a grant to allow for.\n */\nexport function confirmCall(\n\tmcp: TabMcp,\n\trequest: ConfirmRequest,\n\tonConfirm: ConfirmHandler | undefined,\n): Promise<ConfirmAnswer> {\n\tconst { client } = request;\n\tif (\n\t\tclient.kind === \"relay\" &&\n\t\tallowedFor(mcp).allows(client.grantId, request.tool)\n\t)\n\t\treturn Promise.resolve(true);\n\tif (onConfirm === undefined) return mcp.confirmInPage(request);\n\t// Anything but true or \"unanswered\" is a refusal.\n\treturn Promise.resolve()\n\t\t.then(() => onConfirm(request))\n\t\t.then((answer) => (answer === \"unanswered\" ? answer : answer === true));\n}\n"
6
+ ],
7
+ "mappings": "4JAiCA,SAAS,EAAa,CAAC,EAAmD,CACzE,GAAI,CACH,OAAO,EAAQ,KAAK,UAAU,EAAM,KAAM,CAAC,CAAC,EAC3C,KAAM,CACP,QAQK,IAAM,GAAiB,IAMxB,GAAsB,IA4BtB,EAAS,IAAI,QAoBZ,SAAS,CAAa,CAC5B,EACA,EACA,EAAgC,CAAC,EACT,CACxB,GAAI,EAAQ,OAAO,QAAS,OAAO,QAAQ,QAAQ,MAAM,EACzD,IAAI,EAAQ,EAAO,IAAI,CAAG,EAC1B,GAAI,IAAU,OACb,EAAQ,CAAE,MAAO,GAAO,QAAS,CAAC,CAAE,EACpC,EAAO,IAAI,EAAK,CAAK,EAEtB,IAAM,EAAI,EAEJ,EAAO,IAAM,CAClB,IAAM,EAAQ,EA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./tab-mcp-client-8r6h3wza.min.js";import{o}from"./tab-mcp-client-q758jr4g.min.js";function st(h){let b=h.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"");return b===""?"tools":b}function it(h){try{let b=new URL(h).href;return/^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(b)?b:void 0}catch{return}}var ct="https://ractive.ch/tab-mcp/connect/",at="mcp_2026_07_28";function rt(h,b,m){let N=c(m),w=st(h),g=it(b),S=(E)=>g===void 0?{}:{text:N.setupRun,command:E};return[{id:"claude",app:N.setupClaudeApp,text:N.setupClaude},{id:"chatgpt",app:"ChatGPT",text:N.setupChatGpt},{id:"claude-code",app:"Claude Code",text:N.setupClaudeCode,...S(`claude mcp add --transport http ${w} ${g}`),note:ot(N.setupClaudeCodeNote,{command:"/mcp"})},{id:"codex",app:"Codex",text:N.setupCodex.replace("{feature}",at),...S(`codex features enable ${at}
2
+ codex mcp add ${w} --url ${g}
3
+ codex mcp login ${w}`),note:ot(N.setupCodexNote,{})}]}function ot(h,b){return h.split(/\{(\w+)\}/).map((m,N)=>{let w=N%2===1?b[m]:void 0;return w===void 0?{text:N%2===1?`{${m}}`:m}:{code:w}}).filter((m)=>!("text"in m)||m.text!=="")}function lt(h,b,m){let N=e(h,"input");return N.type="checkbox",N.setAttribute("role","switch"),N.addEventListener("change",()=>m(N.checked)),{label:e(h,"label",{className:"tab-mcp-switch"},N,b),input:N}}function Nt(h,b,m,N,w){let g=e(h,"p",{className:"tab-mcp-allowed-title",id:`${i()}-allowed`,text:m.kept?b.alwaysAllow:b.allowUntilReload}),S=e(h,"div",{className:"tab-mcp-switches"}),E=lt(h,e(h,"span",{text:b.allowEverything}),(_)=>{if(!_||m.offered)m.setEverything(N,_);F()});E.label.classList.add("tab-mcp-everything"),E.input.setAttribute("aria-label",n(b.allowEverythingApp,{app:w}));let U=e(h,"small",{className:"tab-mcp-everything-note",id:`${g.id}-note`},...r(h,m.kept?b.allowEverythingNote:b.allowEverythingUntilReloadNote,{app:w}));E.input.setAttribute("aria-describedby",U.id);let T=e(h,"div",{className:"tab-mcp-allowed"});T.setAttribute("role","group"),T.setAttribute("aria-labelledby",g.id);let L=new Map,F=()=>{let _=m.everything(N),j=m.list(N),ie=new Set(j),J=new Map(m.tools().map((y)=>[y.name,y])),q=[];if(m.offered)for(let y of J.values())q.push({name:y.name,shown:y.title??y.name,destructive:y.destructive,offOnly:!1});for(let y of j){if(m.offered&&J.has(y))continue;let M=J.get(y);q.push({name:y,shown:M?.title??y,destructive:M?.destructive===!0,offOnly:!0})}let re=m.offered||_;if(T.hidden=q.length===0&&!_,T.hidden)return;if(!T.hasChildNodes())T.append(g,S,E.label,U);let le=new Set(q.map((y)=>y.name));for(let[y,{label:M}]of L){if(le.has(y))continue;M.remove(),L.delete(y)}q.forEach((y,M)=>{let O=L.get(y.name);if(O===void 0){let K=e(h,"span"),Y=e(h,"small",{className:"tab-mcp-destructive",text:b.destructive});O={...lt(h,e(h,"span",{},K," ",Y),(de)=>{if(!de)m.ask(N,y.name);else if(L.get(y.name)?.offOnly===!1)m.allow(N,y.name);F()}),name:K,mark:Y,offOnly:y.offOnly},L.set(y.name,O)}O.offOnly=y.offOnly;let z=s(y.shown);if(O.name.textContent=z,O.mark.hidden=!y.destructive,O.input.setAttribute("aria-label",n(y.destructive?b.allowDestructiveToolApp:b.allowToolApp,{tool:z,app:w})),O.input.checked=_||ie.has(y.name),O.input.disabled=_,S.children[M]!==O.label)S.insertBefore(O.label,S.children[M]??null)}),E.label.hidden=U.hidden=!re,E.input.checked=_};return{box:T,render:F}}function Ct(h,b){return[...new Set(h.map((m)=>d(m.client,b)))]}function ce(h,b){console.warn("tab-mcp: could not connect.",h);let m=h?.reason;if(m===void 0)return b.notConnected;if(m==="network")return b.unreachable;if(m==="rate_limited")return b.rateLimited;return b.refused}function Et(h,b){switch(h){case"expired":case"idle":return b.ended;case"user":return b.disconnected;case"network":case"heartbeat":case"shutdown":return b.lost;case"rate_limited":return b.rateLimited;default:return b.closed}}function At(h,b){switch(h.identity){case"bound":return;case"pending":return b.checkingSignIn;case"refused":return h.identityMessage?n(b.signInRefusedWhy,{reason:h.identityMessage}):b.signInRefused;default:return b.signInFirst}}var Pe=new WeakMap;function St(h,b,m){let N=Pe.has(h);if(Pe.set(h,m===void 0?{doc:b}:{doc:b,ui:m}),N)return;h.addEventListener("replaced",(w)=>{let g=Pe.get(h);if(g!==void 0&&h.state==="disconnected")Tt(h,g.doc,w.detail.sibling,g.ui)})}function Tt(h,b,m,N){let w=a(N);b.querySelector("dialog.tab-mcp-replaced")?.close();let{dialog:g}=l(b,"tab-mcp-replaced",w,m?w.replacedSiblingTitle:w.replacedTitle),S=e(b,"p",{className:"tab-mcp-status"});S.setAttribute("role","status"),S.hidden=!0;let E=t(b,w.close,()=>g.close(),"tab-mcp-replaced-close",m?"primary":void 0),U=e(b,"div",{className:"tab-mcp-actions"},E),T=E;if(!m){let L=t(b,w.disconnectAll,()=>{L.disabled=!0,S.hidden=!1,S.textContent=w.disconnectingAll,h.disconnectAll().then(()=>{g.close(),h.showConnectDialog({document:b}).catch(()=>{})},(F)=>{L.disabled=!1,S.textContent=F?.reason==="replaced"?w.takenOverAgain:n(w.tryAgainOrClose,{reason:ce(F,w)})})},"tab-mcp-disconnect-all","primary");U.append(" ",L),T=L}g.append(e(b,"p",{className:"tab-mcp-description",text:m?w.replacedSibling:w.replaced}),S,U),g.addEventListener("close",()=>g.remove(),{once:!0}),b.body.append(g),g.showModal(),T.focus()}var Lt=1e4;function $t(h,b,m,N="tools",w){let g=a(w),S=o(h),{dialog:E}=l(m,"tab-mcp-connect",g,g.connectTitle);E.tabIndex=-1;let U=e(m,"p",{className:"tab-mcp-status"});U.setAttribute("role","status");let T=e(m,"span",{className:"tab-mcp-announce"});T.setAttribute("aria-live","polite");for(let[v,x]of[["position","absolute"],["width","1px"],["height","1px"],["overflow","hidden"],["clip-path","inset(50%)"],["white-space","nowrap"]])T.style.setProperty(v,x);let L=(v)=>{T.textContent=T.textContent===v?`${v} `:v},F=e(m,"p",{className:"tab-mcp-via-extension"}),_=`${i()}-success`,j=e(m,"p",{className:"tab-mcp-success-title"}),ie=e(m,"p",{className:"tab-mcp-success-next"}),J=e(m,"span",{className:"tab-mcp-success-icon"});J.setAttribute("aria-hidden","true");let q=e(m,"div",{className:"tab-mcp-success",id:_},J,e(m,"div",{className:"tab-mcp-success-text"},j,ie)),re=`${i()}-address`,le=e(m,"label",{text:g.addressLabel});le.htmlFor=re;let y=e(m,"input",{id:re,className:"tab-mcp-address-input"});y.readOnly=!0;let{button:M,reset:O}=f(m,g,g.copyAddress,()=>y.value,()=>y.select(),L,"tab-mcp-address-copy","primary"),z=e(m,"div",{className:"tab-mcp-address"},le,y," ",M),K=t(m,g.disconnectAll,()=>vt(),"tab-mcp-disconnect-all"),Y=e(m,"div",{className:"tab-mcp-disconnect-all-row"},e(m,"small",{text:g.disconnectAllNote})," ",K),we=`${i()}-disconnect-all`,de=e(m,"p",{id:we}),Ue=t(m,g.cancel,()=>{X=!1,C(),K.focus()}),dt=t(m,g.disconnectAllConfirm,()=>Xe(),"tab-mcp-disconnect-all-confirm","danger"),ae=e(m,"div",{className:"tab-mcp-disconnect-all-question"},de,e(m,"div",{className:"tab-mcp-actions"},Ue," ",dt));ae.setAttribute("role","group"),ae.setAttribute("aria-labelledby",we);let Q=e(m,"strong",{className:"tab-mcp-code-value"});Q.style.setProperty("user-select","all"),Q.style.setProperty("-webkit-user-select","all");let{button:$e,reset:ut}=f(m,g,g.copyCode,()=>Q.textContent??"",()=>m.getSelection()?.selectAllChildren(Q),L,"tab-mcp-code-copy"),Ne=e(m,"span",{},...r(m,g.codeSentence,{code:Q}));Ne.setAttribute("aria-live","polite");let Ce=e(m,"span",{className:"tab-mcp-code-used"}),Ee=e(m,"p",{className:"tab-mcp-code"},Ne,Ce," ",$e,e(m,"br"),e(m,"small",{className:"tab-mcp-code-note",text:g.codeNote})),Ae=e(m,"small",{className:"tab-mcp-sign-in-until"}),pt=(v)=>{let x=new Date(v);try{return x.toLocaleTimeString(g.lang,{hour:"numeric",minute:"2-digit"})}catch{return x.toLocaleTimeString()}},_e=e(m,"p",{className:"tab-mcp-sign-in"},g.signIn,e(m,"br"),Ae),Re=t(m,g.continuePairing,()=>h.startPairing(),"tab-mcp-continue","primary"),Fe=e(m,"span",{text:g.signInTimeUp}),He=e(m,"p",{className:"tab-mcp-time-up"},Fe," ",Re),Be=e(m,"ul"),Se=e(m,"details",{className:"tab-mcp-help"},e(m,"summary",{text:g.help}),Be),Ge=w?.setup?.guide===void 0?ct:w.setup.guide;if(Ge!==null){let v=e(m,"a",{text:g.guide});v.href=Ge,v.target="_blank",v.rel="noopener noreferrer",Se.append(e(m,"p",{className:"tab-mcp-guide"},v))}let mt=w?.setup?.instructions??((v,x)=>rt(v,x,g)),qe=`${i()}-setup`,Te=e(m,"div",{className:"tab-mcp-setup",id:qe},z,Se,Ee,_e,He,Y,ae),ue=t(m,g.connectAnother,()=>{oe=!oe,C()},"tab-mcp-setup-toggle");ue.setAttribute("aria-controls",qe);let pe=e(m,"ul"),me=e(m,"p",{className:"tab-mcp-apps-note"});me.setAttribute("role","status");let ze=e(m,"div",{className:"tab-mcp-apps"},e(m,"h3",{text:g.connectedHeading}),pe,me),We=e(m,"small",{className:"tab-mcp-close-note",text:g.closeNote}),V=t(m,g.close,()=>E.close(),"tab-mcp-close"),fe=t(m,g.done,()=>E.close(),"tab-mcp-done","primary"),ee=t(m,g.connectAgain,()=>{W=void 0,h.connect().then(()=>{if(m.activeElement===V)he().focus()},(v)=>{if(W=ce(v,g),C(),m.activeElement===V&&!ee.hidden)ee.focus()}),C()},"tab-mcp-retry","primary"),ft=e(m,"div",{className:"tab-mcp-actions"},We," ",V,ee,fe);E.append(F,q,U,ze,ue,Te,ft,T);let oe=!1,X=!1,te=!1,ne=!1,W,ge,Ke=new Set(h.grants.map((v)=>v.grantId)),Qe,Le,H,De,D=!1,Ve=()=>D?fe:ee.hidden?V:ee,he=()=>D?fe:M,be=new Map,gt=(v)=>{let x=d(v.client,g),A=t(m,g.disconnect,()=>{ge=void 0,h.revoke(v.grantId).catch((B)=>{if(h.state==="connected")ge=B?.code==="store_unavailable"?g.storeUnavailable:g.disconnectFailed;C()}),C()},"tab-mcp-disconnect","danger");A.setAttribute("aria-label",n(g.disconnectApp,{app:x}));let P=Nt(m,g,S,v.grantId,x);return{item:e(m,"li",{},e(m,"span",{className:"tab-mcp-app"},n(g.appConnected,{app:x}))," ",A,P.box),disconnect:A,renderAllowed:P.render}},ht=(v)=>{if(Qe===v.address)return;Qe=v.address,Be.replaceChildren(...mt(N,v.address).map(({app:x,text:A,command:P,note:I})=>{let B=e(m,"li",{},e(m,"strong",{text:`${x}:`}),` ${A}`);if(P!==void 0){let R=e(m,"pre",{text:P});R.dir="ltr";let{button:G}=f(m,g,n(g.copyCommand,{app:x}),()=>R.textContent??"",()=>m.getSelection()?.selectAllChildren(R),L,"tab-mcp-command-copy");B.append(e(m,"div",{className:"tab-mcp-command"},R,G))}if(I!==void 0)B.append(e(m,"small",{className:"tab-mcp-command-note"},...I.map((R)=>("code"in R)?e(m,"code",{text:R.code}):R.text)));return B}))},bt=(v)=>{let x=h.pairingCode;if(x===void 0||v)clearTimeout(H),H=void 0;else if(x.code!==Le?.code){if(x.reason==="used"){if(H===void 0)H=setTimeout(()=>{H=void 0,Le=h.pairingCode,C()},Lt),L(g.codeUsed)}else if(H!==void 0)clearTimeout(H),H=void 0}let A=H!==void 0;if(!A){if(Q.textContent!==(x?.code??""))ut();Q.textContent=x?.code??"",Le=x}return Ne.hidden=A,$e.hidden=A,Ce.hidden=!A,Ce.textContent=A?g.codeUsed:"",x!==void 0},C=()=>{let v=m.activeElement,{state:x,session:A,grants:P}=h,I=x==="connected",B=A?.pairing==="oidc",R=B?At(h,g):void 0,G=A!==void 0&&R===void 0,se=B?h.pairingUntil:void 0,ke=se===void 0?1:Date.parse(se)-Date.now(),Me=I&&G&&ke<=0;clearTimeout(De),De=ke>0&&se!==void 0?setTimeout(C,Math.min(ke,60000)):void 0;let Ye=new Set(P.map((k)=>k.grantId)),Oe=I&&P.some((k)=>!Ke.has(k.grantId));if(Ke=Ye,Oe){if(ne=!1,!X)oe=!1}let ye=Ct(P,g);if(ye.length===0||!G)X=!1;if(D=!te&&I&&P.length>0,p(m,j,g.connected,ye,g),ie.textContent=u(g.connectedNext,ye.length,g),D)E.setAttribute("aria-describedby",_);else E.removeAttribute("aria-describedby");q.hidden=!D;let et=h.extension,tt=[...new Set((et?.apps??[]).map((k)=>d({id:k.host,name:k.name,host:k.host},g)))];if(F.hidden=tt.length===0,p(m,F,et?.whileInFront?g.viaExtensionInFront:g.viaExtension,tt,g),I)W=void 0;let nt=A?.appName;U.textContent=te?g.disconnectingAll:x==="connecting"?g.connecting:x==="reconnecting"?g.reconnecting:!I?W??g.notConnected:R??(Me?g.signInTimeUp:ne?g.disconnectAllDone:nt!==void 0?n(g.readyApp,{app:nt}):g.readyPage),U.hidden=D;let xt=!z.hidden;if(G&&y.value!==A.address)y.value=A.address,O();if(G)ht(A);if(z.hidden=Se.hidden=Y.hidden=!G,K.disabled=!I,ae.hidden=!X,X)p(m,de,g.disconnectAllQuestion,ye,g);let wt=bt(Oe);Ee.hidden=B||!wt||!I,_e.hidden=!B||h.identity!=="bound"||Me,Ae.textContent=se===void 0?"":n(g.signInUntil,{time:pt(se)}),Ae.hidden=se===void 0,He.hidden=!Me,Fe.hidden=!D,ue.hidden=!D,ue.setAttribute("aria-expanded",String(oe)),Te.hidden=D&&!oe,M.classList.toggle("tab-mcp-primary",!D);for(let[k,{item:xe}]of be){if(Ye.has(k))continue;xe.remove(),be.delete(k)}if(P.forEach((k,xe)=>{let Z=be.get(k.grantId);if(Z===void 0)Z=gt(k),be.set(k.grantId,Z);if(Z.disconnect.disabled=!I,Z.renderAllowed(),pe.children[xe]!==Z.item)pe.insertBefore(Z.item,pe.children[xe]??null)}),me.textContent=I?ge??"":g.disconnectNote,me.hidden=I&&ge===void 0,ze.hidden=P.length===0,We.hidden=D||Ee.hidden,V.hidden=D,fe.hidden=!D,ee.hidden=te||x!=="disconnected"&&x!=="reconnecting",v!==null&&v!==E&&v!==m.body&&(!v.isConnected||E.contains(v)&&v.closest("[hidden]")!==null))(ae.contains(v)&&!Y.hidden?K:v===Re&&!Te.hidden?he():Ve()).focus();else if(m.activeElement===E&&(D||G))he().focus();else if(ne&&G&&!xt&&m.activeElement===V)M.focus();if(Oe&&D)L(`${j.textContent}. ${ie.textContent}`)},vt=()=>{if(h.state!=="connected")return;if(h.grants.length===0){Xe();return}X=!0,C(),Ue.focus()},Xe=()=>{te=!0,ne=!1,V.focus(),X=!1,C(),h.disconnectAll().then(()=>{if(te=!1,ne=!0,C(),!z.hidden)M.focus()},(v)=>{te=!1,W=ce(v,g),C(),Ve().focus()})},ve,Ie=h.state==="reconnecting",Ze=(v)=>{let{error:x}=v.detail;if(Ie&&x.reason!==void 0)ve=x},je=(v)=>{let{state:x,reason:A}=v.detail;if(A!==void 0&&A!=="disconnect_all")W=Et(A,g),ne=!1;if(x==="disconnected"&&Ie)W=ve===void 0?g.disconnected:ce(ve,g);Ie=x==="reconnecting",ve=void 0,C()},Je=()=>E.close();St(h,m,w);let yt=S.onChange(C);return h.addEventListener("statechange",je),h.addEventListener("pairingcode",C),h.addEventListener("pairinguntil",C),m.addEventListener("visibilitychange",C),h.addEventListener("grantschange",C),h.addEventListener("identitychange",C),h.addEventListener("extensionchange",C),h.addEventListener("error",Ze),h.addEventListener("replaced",Je),m.body.append(E),h.startPairing(),C(),b.then(C,(v)=>{W=ce(v,g),C()}),new Promise((v)=>{if(E.addEventListener("close",()=>{clearTimeout(H),clearTimeout(De),h.stopPairing(),yt(),h.removeEventListener("statechange",je),h.removeEventListener("pairingcode",C),h.removeEventListener("pairinguntil",C),m.removeEventListener("visibilitychange",C),h.removeEventListener("grantschange",C),h.removeEventListener("identitychange",C),h.removeEventListener("extensionchange",C),h.removeEventListener("error",Ze),h.removeEventListener("replaced",Je),E.remove(),v()},{once:!0}),E.showModal(),D||!z.hidden)he().focus();else E.focus()})}export{$t as showConnectDialog};
4
+
5
+ //# debugId=7195A35AE77F393F64756E2164756E21
6
+ //# sourceMappingURL=connect-my0pbqd7.min.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/command.ts", "../../src/setup.ts", "../../src/connect.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The server's name and the address as words for the setup commands\n * (`setup.ts`), plain in every shell. Internal: not part of an entry.\n */\n\n/**\n * The server's name as a label that every shell (POSIX shells, PowerShell,\n * cmd.exe) reads as one plain word, so it needs no quoting: letters without\n * their marks (\"Bücher\" → \"bucher\"), lower case, each run of anything but\n * a-z, 0-9, _ and - as one \"-\", no \"-\" at either end (no option), at most 40\n * characters; \"tools\" when nothing is left. The page names its server, but\n * the command runs in the user's shell: nothing of the name may be quoted\n * text (review of PR 34).\n */\nexport function commandName(name: string): string {\n\tconst label = name\n\t\t.normalize(\"NFKD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_-]+/g, \"-\")\n\t\t.replace(/-{2,}/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\t\t.slice(0, 40)\n\t\t.replace(/-+$/, \"\");\n\treturn label === \"\" ? \"tools\" : label;\n}\n\n/**\n * The address for a command, only when all of it is plain in every shell\n * (http or https, letters, digits and . : [ ] / _ ~ -); else `undefined`, and\n * the help shows the steps without commands. The relay's addresses are.\n */\nexport function commandAddress(address: string): string | undefined {\n\ttry {\n\t\tconst href = new URL(address).href;\n\t\treturn /^https?:\\/\\/[A-Za-z0-9.:[\\]/_~-]+$/.test(href) ? href : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n",
6
+ "/**\n * `@ractive-ch/tab-mcp-client/setup`: how to add a page's address to each AI\n * app, the steps the connect dialog shows under \"How do I add it?\", for pages\n * and extensions that show them in their own UI. Plain data, no DOM. An entry\n * of its own, out of the core (DEC-118).\n */\n\nimport { commandAddress, commandName } from \"./command.ts\";\nimport { type DialogStrings, withEnglish } from \"./strings.ts\";\nimport type { SetupNotePart, SetupStep } from \"./types.ts\";\n\nexport type { SetupNotePart, SetupStep };\n\n/** The guide for every AI app, step by step and what to do when it fails (its source is on ractive.ch). */\nexport const SETUP_GUIDE = \"https://ractive.ch/tab-mcp/connect/\";\n\n/** Codex's feature for MCP 2026-07-28, which the relay speaks; off by default in Codex 0.163. */\nconst CODEX_FEATURE = \"mcp_2026_07_28\";\n\n/**\n * The steps for one AI app. All strings are plain text (set them with\n * `textContent`). `command`, where present, is safe to show and to run: the\n * server's name and the address in it are words that every shell (POSIX\n * shells, PowerShell, cmd.exe) reads as plain, with nothing to quote. It is\n * absent for apps without a command, and when the address is not\n * shell-plain (only http or https, letters, digits and `. : [ ] / _ ~ -`);\n * then `text` names the command instead. The relay's addresses are\n * shell-plain.\n */\nexport interface SetupInstruction extends SetupStep {\n\t/** Which app, stable across versions: `claude`, `chatgpt`, `claude-code` or `codex`. */\n\tid: \"claude\" | \"chatgpt\" | \"claude-code\" | \"codex\";\n}\n\n/**\n * The steps to add `address` (the page's MCP address from the relay) to\n * Claude, ChatGPT, Claude Code and Codex, in that order. `serverName` is the\n * page's `server.name`; the commands name the server by it, reduced to a\n * shell-plain label (lower case, letters without marks, each run of other\n * characters as `-`, at most 40 characters, `tools` if nothing is left).\n * End the list with a link to {@link SETUP_GUIDE}: the steps here are the\n * minimum (CU 20), the guide has the rest and follows the apps' menus.\n * `strings` translates the texts (the `setup…` keys of `./strings`, the\n * same table as the dialogs' `ui.strings`); missing keys stay English.\n */\nexport function setupInstructions(\n\tserverName: string,\n\taddress: string,\n\tstrings?: Partial<DialogStrings>,\n): SetupInstruction[] {\n\tconst s = withEnglish(strings);\n\tconst n = commandName(serverName);\n\tconst a = commandAddress(address);\n\tconst run = (command: string) =>\n\t\ta === undefined ? {} : { text: s.setupRun, command };\n\treturn [\n\t\t{ id: \"claude\", app: s.setupClaudeApp, text: s.setupClaude },\n\t\t{ id: \"chatgpt\", app: \"ChatGPT\", text: s.setupChatGpt },\n\t\t{\n\t\t\tid: \"claude-code\",\n\t\t\tapp: \"Claude Code\",\n\t\t\ttext: s.setupClaudeCode,\n\t\t\t...run(`claude mcp add --transport http ${n} ${a}`),\n\t\t\t// The command only adds the server; the sign-in that asks for the\n\t\t\t// code starts in Claude Code (CU 6).\n\t\t\tnote: noteOf(s.setupClaudeCodeNote, { command: \"/mcp\" }),\n\t\t},\n\t\t{\n\t\t\tid: \"codex\",\n\t\t\tapp: \"Codex\",\n\t\t\ttext: s.setupCodex.replace(\"{feature}\", CODEX_FEATURE),\n\t\t\t...run(\n\t\t\t\t`codex features enable ${CODEX_FEATURE}\\ncodex mcp add ${n} --url ${a}\\ncodex mcp login ${n}`,\n\t\t\t),\n\t\t\tnote: noteOf(s.setupCodexNote, {}),\n\t\t},\n\t];\n}\n\n/** `template` as note parts: its text, and each `{name}` of `code` as code. */\nfunction noteOf(\n\ttemplate: string,\n\tcode: Record<string, string>,\n): SetupNotePart[] {\n\treturn template\n\t\t.split(/\\{(\\w+)\\}/)\n\t\t.map((part, i): SetupNotePart => {\n\t\t\tconst value = i % 2 === 1 ? code[part] : undefined;\n\t\t\treturn value === undefined\n\t\t\t\t? { text: i % 2 === 1 ? `{${part}}` : part }\n\t\t\t\t: { code: value };\n\t\t})\n\t\t.filter((part) => !(\"text\" in part) || part.text !== \"\");\n}\n",
7
+ "/**\n * The \"Connect your AI app\" dialog (DEC-028) and the notice that the page\n * lost its address, loaded on demand when a page opens the dialog.\n */\n\nimport { type Allowances, allowedFor } from \"./always-allowed.ts\";\nimport {\n\tbutton,\n\tclientLabel,\n\tcopyButton,\n\tel,\n\tfill,\n\tformat,\n\tnewDialog,\n\tnextId,\n\tplural,\n\tshowNames,\n\tstringsOf,\n\tvisible,\n} from \"./dialog.ts\";\nimport { SETUP_GUIDE, setupInstructions } from \"./setup.ts\";\nimport type { DialogStrings } from \"./strings.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tDialogOptions,\n\tDisconnectReason,\n\tGrant,\n\tPairingCode,\n\tSessionInfo,\n\tStateChangeDetail,\n} from \"./types.ts\";\n\n/** A switch: a checkbox with `role=\"switch\"` in its label, which a click on the text turns too. */\nfunction switchOf(\n\tdoc: Document,\n\ttext: HTMLElement,\n\tonToggle: (on: boolean) => void,\n): { label: HTMLLabelElement; input: HTMLInputElement } {\n\tconst input = el(doc, \"input\");\n\tinput.type = \"checkbox\";\n\tinput.setAttribute(\"role\", \"switch\");\n\tinput.addEventListener(\"change\", () => onToggle(input.checked));\n\tconst label = el(doc, \"label\", { className: \"tab-mcp-switch\" }, input, text);\n\treturn { label, input };\n}\n\n/**\n * Under a connected app, the switches for what runs without asking. With\n * `alwaysAllow` (`offered`): a switch per tool that asks (its title or\n * name, destructive ones marked) and \"Always allow everything\" with what it\n * means, under the confirmation's own label (\"Always allow\", or \"Allow\n * until reload\" when nothing is kept), so the button and the switches it\n * turns on read alike. Without it, only what is allowed now, as switches that\n * can only be turned off (\"everything\" only while it is on): the user sees\n * what runs without asking and can end it, and is never offered more than\n * the page chose to offer. Tools allowed but not registered right now are\n * listed by name, also only to turn off. Each switch's accessible name names\n * the app: the list has one set per app. `render` updates it in place, so a\n * focused switch keeps its focus.\n */\nfunction allowedSwitches(\n\tdoc: Document,\n\ts: DialogStrings,\n\tallowed: Allowances,\n\tgrantId: string,\n\tapp: string,\n): { box: HTMLElement; render: () => void } {\n\tconst title = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-allowed-title\",\n\t\tid: `${nextId()}-allowed`,\n\t\ttext: allowed.kept ? s.alwaysAllow : s.allowUntilReload,\n\t});\n\tconst list = el(doc, \"div\", { className: \"tab-mcp-switches\" });\n\t// Turning on only where the page offers it; the store decides the rest.\n\tconst all = switchOf(\n\t\tdoc,\n\t\tel(doc, \"span\", { text: s.allowEverything }),\n\t\t(on) => {\n\t\t\tif (!on || allowed.offered) allowed.setEverything(grantId, on);\n\t\t\trender();\n\t\t},\n\t);\n\tall.label.classList.add(\"tab-mcp-everything\");\n\tall.input.setAttribute(\"aria-label\", format(s.allowEverythingApp, { app }));\n\tconst note = el(\n\t\tdoc,\n\t\t\"small\",\n\t\t{ className: \"tab-mcp-everything-note\", id: `${title.id}-note` },\n\t\t...fill(\n\t\t\tdoc,\n\t\t\tallowed.kept ? s.allowEverythingNote : s.allowEverythingUntilReloadNote,\n\t\t\t{ app },\n\t\t),\n\t);\n\tall.input.setAttribute(\"aria-describedby\", note.id);\n\t// Filled when first shown: a page without it has no switches in its DOM.\n\tconst box = el(doc, \"div\", { className: \"tab-mcp-allowed\" });\n\tbox.setAttribute(\"role\", \"group\");\n\tbox.setAttribute(\"aria-labelledby\", title.id);\n\tconst switches = new Map<\n\t\tstring,\n\t\tReturnType<typeof switchOf> & {\n\t\t\tname: HTMLElement;\n\t\t\tmark: HTMLElement;\n\t\t\toffOnly: boolean;\n\t\t}\n\t>();\n\tconst render = () => {\n\t\tconst everything = allowed.everything(grantId);\n\t\tconst listed = allowed.list(grantId);\n\t\tconst on = new Set(listed);\n\t\tconst asking = new Map(allowed.tools().map((t) => [t.name, t]));\n\t\tconst rows: {\n\t\t\tname: string;\n\t\t\tshown: string;\n\t\t\tdestructive: boolean;\n\t\t\toffOnly: boolean;\n\t\t}[] = [];\n\t\tif (allowed.offered)\n\t\t\tfor (const t of asking.values())\n\t\t\t\trows.push({\n\t\t\t\t\tname: t.name,\n\t\t\t\t\tshown: t.title ?? t.name,\n\t\t\t\t\tdestructive: t.destructive,\n\t\t\t\t\toffOnly: false,\n\t\t\t\t});\n\t\tfor (const name of listed) {\n\t\t\tif (allowed.offered && asking.has(name)) continue;\n\t\t\tconst t = asking.get(name);\n\t\t\trows.push({\n\t\t\t\tname,\n\t\t\t\tshown: t?.title ?? name,\n\t\t\t\tdestructive: t?.destructive === true,\n\t\t\t\toffOnly: true,\n\t\t\t});\n\t\t}\n\t\tconst showAll = allowed.offered || everything;\n\t\tbox.hidden = rows.length === 0 && !everything;\n\t\tif (box.hidden) return;\n\t\tif (!box.hasChildNodes()) box.append(title, list, all.label, note);\n\t\tconst names = new Set(rows.map((r) => r.name));\n\t\tfor (const [name, { label }] of switches) {\n\t\t\tif (names.has(name)) continue;\n\t\t\tlabel.remove();\n\t\t\tswitches.delete(name);\n\t\t}\n\t\trows.forEach((row, i) => {\n\t\t\tlet entry = switches.get(row.name);\n\t\t\tif (entry === undefined) {\n\t\t\t\tconst name = el(doc, \"span\");\n\t\t\t\tconst mark = el(doc, \"small\", {\n\t\t\t\t\tclassName: \"tab-mcp-destructive\",\n\t\t\t\t\ttext: s.destructive,\n\t\t\t\t});\n\t\t\t\tconst made = switchOf(\n\t\t\t\t\tdoc,\n\t\t\t\t\tel(doc, \"span\", {}, name, \" \", mark),\n\t\t\t\t\t(turnedOn) => {\n\t\t\t\t\t\tif (!turnedOn) allowed.ask(grantId, row.name);\n\t\t\t\t\t\telse if (switches.get(row.name)?.offOnly === false)\n\t\t\t\t\t\t\tallowed.allow(grantId, row.name);\n\t\t\t\t\t\trender(); // also when nothing changed: the switch says the truth\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\tentry = { ...made, name, mark, offOnly: row.offOnly };\n\t\t\t\tswitches.set(row.name, entry);\n\t\t\t}\n\t\t\tentry.offOnly = row.offOnly;\n\t\t\tconst shown = visible(row.shown);\n\t\t\tentry.name.textContent = shown;\n\t\t\tentry.mark.hidden = !row.destructive;\n\t\t\tentry.input.setAttribute(\n\t\t\t\t\"aria-label\",\n\t\t\t\tformat(row.destructive ? s.allowDestructiveToolApp : s.allowToolApp, {\n\t\t\t\t\ttool: shown,\n\t\t\t\t\tapp,\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// What runs without asking now: also every tool under \"everything\".\n\t\t\tentry.input.checked = everything || on.has(row.name);\n\t\t\tentry.input.disabled = everything;\n\t\t\tif (list.children[i] !== entry.label)\n\t\t\t\tlist.insertBefore(entry.label, list.children[i] ?? null);\n\t\t});\n\t\tall.label.hidden = note.hidden = !showAll;\n\t\tall.input.checked = everything;\n\t};\n\treturn { box, render };\n}\n\n/**\n * The labels of the apps behind these grants, each once: an app can hold\n * more than one grant (paired twice), and is still one app.\n */\nfunction appLabels(grants: readonly Grant[], s: DialogStrings): string[] {\n\treturn [...new Set(grants.map((g) => clientLabel(g.client, s)))];\n}\n\n/**\n * Why connecting failed, in the user's words (CU 4). The error itself, with\n * the relay's wording, goes to the console. Without a `reason` it never\n * started (no user action, cancelled): just not connected.\n */\nfunction connectFailure(error: unknown, s: DialogStrings): string {\n\tconsole.warn(\"tab-mcp: could not connect.\", error);\n\tconst reason = (error as { reason?: DisconnectReason } | null)?.reason;\n\tif (reason === undefined) return s.notConnected;\n\tif (reason === \"network\") return s.unreachable;\n\tif (reason === \"rate_limited\") return s.rateLimited;\n\treturn s.refused;\n}\n\n/** Why the page was disconnected, in the user's words (CU 4). */\nfunction disconnectedText(reason: DisconnectReason, s: DialogStrings): string {\n\tswitch (reason) {\n\t\tcase \"expired\":\n\t\tcase \"idle\":\n\t\t\treturn s.ended;\n\t\tcase \"user\":\n\t\t\treturn s.disconnected;\n\t\tcase \"network\":\n\t\tcase \"heartbeat\":\n\t\tcase \"shutdown\":\n\t\t\treturn s.lost;\n\t\tcase \"rate_limited\":\n\t\t\treturn s.rateLimited;\n\t\tdefault:\n\t\t\treturn s.closed;\n\t}\n}\n\n/**\n * With identity binding: what stands between the user and the address until\n * the relay knows who is signed in (CU 7). `undefined` once it does.\n */\nfunction signInText(mcp: TabMcp, s: DialogStrings): string | undefined {\n\tswitch (mcp.identity) {\n\t\tcase \"bound\":\n\t\t\treturn undefined;\n\t\tcase \"pending\":\n\t\t\treturn s.checkingSignIn;\n\t\tcase \"refused\":\n\t\t\treturn mcp.identityMessage\n\t\t\t\t? format(s.signInRefusedWhy, { reason: mcp.identityMessage })\n\t\t\t\t: s.signInRefused;\n\t\tdefault:\n\t\t\treturn s.signInFirst;\n\t}\n}\n\n/** The document and texts of the connect dialog per `TabMcp`, once it was opened. */\nconst watched = new WeakMap<TabMcp, { doc: Document; ui?: DialogOptions }>();\n\n/**\n * Once a page has opened the connect dialog, the default UI also says when\n * the page loses its address (`replaced`), in that dialog's document.\n */\nfunction watchReplaced(mcp: TabMcp, doc: Document, ui?: DialogOptions): void {\n\tconst known = watched.has(mcp);\n\twatched.set(mcp, ui === undefined ? { doc } : { doc, ui });\n\tif (known) return;\n\tmcp.addEventListener(\"replaced\", (event) => {\n\t\tconst current = watched.get(mcp);\n\t\t// Not when the page already went on (`disconnectAll()` or `connect()` since).\n\t\tif (current !== undefined && mcp.state === \"disconnected\")\n\t\t\treplacedNotice(mcp, current.doc, event.detail.sibling, current.ui);\n\t});\n}\n\n/**\n * Says that the page lost its address (`replaced`, DEC-095). A sibling tab\n * that announced it: \"Opened in another tab\", nothing to do. Otherwise a\n * warning that another tab or program took over, with \"Disconnect all apps\"\n * (`disconnectAll()`), which takes the page back, disconnects its apps,\n * connects with a new secret and opens the connect dialog to connect the AI\n * apps again.\n */\nexport function replacedNotice(\n\tmcp: TabMcp,\n\tdoc: Document,\n\tsibling: boolean,\n\tui?: DialogOptions,\n): void {\n\tconst s = stringsOf(ui);\n\t(\n\t\tdoc.querySelector(\"dialog.tab-mcp-replaced\") as HTMLDialogElement | null\n\t)?.close();\n\tconst { dialog } = newDialog(\n\t\tdoc,\n\t\t\"tab-mcp-replaced\",\n\t\ts,\n\t\tsibling ? s.replacedSiblingTitle : s.replacedTitle,\n\t);\n\tconst status = el(doc, \"p\", { className: \"tab-mcp-status\" });\n\tstatus.setAttribute(\"role\", \"status\");\n\tstatus.hidden = true;\n\tconst close = button(\n\t\tdoc,\n\t\ts.close,\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-replaced-close\",\n\t\tsibling ? \"primary\" : undefined,\n\t);\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\tlet first = close;\n\tif (!sibling) {\n\t\tconst fresh = button(\n\t\t\tdoc,\n\t\t\ts.disconnectAll,\n\t\t\t() => {\n\t\t\t\tfresh.disabled = true;\n\t\t\t\tstatus.hidden = false;\n\t\t\t\tstatus.textContent = s.disconnectingAll;\n\t\t\t\tmcp.disconnectAll().then(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdialog.close();\n\t\t\t\t\t\tmcp.showConnectDialog({ document: doc }).catch(() => {});\n\t\t\t\t\t},\n\t\t\t\t\t(error: unknown) => {\n\t\t\t\t\t\tfresh.disabled = false;\n\t\t\t\t\t\tstatus.textContent =\n\t\t\t\t\t\t\t(error as { reason?: unknown } | null)?.reason === \"replaced\"\n\t\t\t\t\t\t\t\t? s.takenOverAgain\n\t\t\t\t\t\t\t\t: format(s.tryAgainOrClose, {\n\t\t\t\t\t\t\t\t\t\treason: connectFailure(error, s),\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\t\"tab-mcp-disconnect-all\",\n\t\t\t\"primary\",\n\t\t);\n\t\tactions.append(\" \", fresh);\n\t\tfirst = fresh;\n\t}\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: sibling ? s.replacedSibling : s.replaced,\n\t\t}),\n\t\tstatus,\n\t\tactions,\n\t);\n\tdialog.addEventListener(\"close\", () => dialog.remove(), { once: true });\n\tdoc.body.append(dialog);\n\tdialog.showModal();\n\tfirst.focus();\n}\n\n/**\n * How long a used code stays \"Code used\" before its replacement is shown: the\n * AI app connects a moment after the code was entered (its token request), and\n * a new code in plain view meanwhile looks as if it did not work. Only when\n * the relay says the code was used (`reason: \"used\"`); a relay that does not\n * say why gets the new code shown at once.\n */\nexport const CODE_USED_WAIT_MS = 10_000;\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy, how to add it,\n * the pairing code (with Copy) while the relay sends one, Disconnect all apps, and\n * the connected apps with Disconnect (and, for each, switches for the tools\n * that run without asking). Pairing is on while it is open, so closing it\n * ends the code; the connection and the address stay. Until an app is\n * connected, only a small Close (and Escape) close it. Once one is, a\n * confirmation leads, the setup moves behind \"Connect another AI app\" and\n * Done is the primary button. Disconnect all apps asks first when it would\n * disconnect connected apps. When the page loses its address (`replaced`),\n * this dialog closes and `replacedNotice` says why, from then on also while\n * it is closed.\n *\n * Its nodes are built once; one `render()` derives what is shown from `mcp`\n * and a few flags of its own after every change, so nothing flickers and\n * focus stays, or moves to the next step when its control was hidden.\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n\tserverName = \"tools\",\n\tui?: DialogOptions,\n): Promise<void> {\n\tconst s = stringsOf(ui);\n\tconst allowed = allowedFor(mcp);\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", s, s.connectTitle);\n\t// Focusable from script only, for the moment before the address is shown.\n\tdialog.tabIndex = -1;\n\tconst status = el(doc, \"p\", { className: \"tab-mcp-status\" });\n\tstatus.setAttribute(\"role\", \"status\");\n\t// What a Copy did, for assistive technology only; out of sight, also\n\t// without the stylesheet. The same message twice is still a change.\n\tconst live = el(doc, \"span\", { className: \"tab-mcp-announce\" });\n\tlive.setAttribute(\"aria-live\", \"polite\");\n\tfor (const [property, value] of [\n\t\t[\"position\", \"absolute\"],\n\t\t[\"width\", \"1px\"],\n\t\t[\"height\", \"1px\"],\n\t\t[\"overflow\", \"hidden\"],\n\t\t[\"clip-path\", \"inset(50%)\"],\n\t\t[\"white-space\", \"nowrap\"],\n\t] as const)\n\t\tlive.style.setProperty(property, value);\n\tconst announce = (text: string) => {\n\t\tlive.textContent = live.textContent === text ? `${text} ` : text;\n\t};\n\n\t// AI apps that reach the page through the tab-mcp browser extension\n\t// (DEC-207): said first, as the user may not need to connect at all.\n\t// Everything else stays: a phone or another browser still connects here.\n\tconst viaExtension = el(doc, \"p\", { className: \"tab-mcp-via-extension\" });\n\n\t// The confirmation once an app is connected: what happened, what next.\n\tconst successId = `${nextId()}-success`;\n\tconst successTitle = el(doc, \"p\", { className: \"tab-mcp-success-title\" });\n\tconst successNext = el(doc, \"p\", { className: \"tab-mcp-success-next\" });\n\t// A check mark in a tinted disk, drawn by the stylesheet (CU 19).\n\tconst check = el(doc, \"span\", { className: \"tab-mcp-success-icon\" });\n\tcheck.setAttribute(\"aria-hidden\", \"true\");\n\tconst success = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-success\", id: successId },\n\t\tcheck,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-success-text\" },\n\t\t\tsuccessTitle,\n\t\t\tsuccessNext,\n\t\t),\n\t);\n\n\tconst addressId = `${nextId()}-address`;\n\tconst label = el(doc, \"label\", { text: s.addressLabel });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\t// Copying the address is the first step: the primary button, until an\n\t// app is connected (then Done is).\n\tconst { button: copy, reset: resetCopy } = copyButton(\n\t\tdoc,\n\t\ts,\n\t\ts.copyAddress,\n\t\t() => address.value,\n\t\t() => address.select(),\n\t\tannounce,\n\t\t\"tab-mcp-address-copy\",\n\t\t\"primary\",\n\t);\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t);\n\n\t// Not next to Copy, and saying what it does (CU 23): with no AI app\n\t// connected it makes a new secret at once (the address stays), which\n\t// also ends what a pasted address could reach.\n\tconst fresh = button(\n\t\tdoc,\n\t\ts.disconnectAll,\n\t\t() => askDisconnectAll(),\n\t\t\"tab-mcp-disconnect-all\",\n\t);\n\tconst freshBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-disconnect-all-row\" },\n\t\tel(doc, \"small\", { text: s.disconnectAllNote }),\n\t\t\" \",\n\t\tfresh,\n\t);\n\t// Asked in the dialog before Disconnect all apps disconnects connected apps.\n\tconst questionId = `${nextId()}-disconnect-all`;\n\tconst questionText = el(doc, \"p\", { id: questionId });\n\tconst cancelNew = button(doc, s.cancel, () => {\n\t\tasking = false;\n\t\trender();\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(\n\t\tdoc,\n\t\ts.disconnectAllConfirm,\n\t\t() => runDisconnectAll(),\n\t\t\"tab-mcp-disconnect-all-confirm\",\n\t\t\"danger\",\n\t);\n\tconst question = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-disconnect-all-question\" },\n\t\tquestionText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tquestion.setAttribute(\"role\", \"group\");\n\tquestion.setAttribute(\"aria-labelledby\", questionId);\n\n\t// Large, in a monospace font: a new code takes the same room.\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\t// One click selects the whole code; it stays plain, selectable text.\n\tcode.style.setProperty(\"user-select\", \"all\");\n\tcode.style.setProperty(\"-webkit-user-select\", \"all\");\n\t// Reads the code shown at click time, so a rotated code is copied as shown.\n\tconst { button: copyCode, reset: resetCopyCode } = copyButton(\n\t\tdoc,\n\t\ts,\n\t\ts.copyCode,\n\t\t() => code.textContent ?? \"\",\n\t\t() => doc.getSelection()?.selectAllChildren(code),\n\t\tannounce,\n\t\t\"tab-mcp-code-copy\",\n\t);\n\t// Only the sentence with the code is announced when the code changes,\n\t// not its Copy button's \"Copied\".\n\tconst codeSentence = el(\n\t\tdoc,\n\t\t\"span\",\n\t\t{},\n\t\t...fill(doc, s.codeSentence, { code }),\n\t);\n\tcodeSentence.setAttribute(\"aria-live\", \"polite\");\n\t// In the code's place while the AI app finishes connecting with it.\n\tconst codeUsed = el(doc, \"span\", { className: \"tab-mcp-code-used\" });\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\tcodeUsed,\n\t\t\" \",\n\t\tcopyCode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", { className: \"tab-mcp-code-note\", text: s.codeNote }),\n\t);\n\t// Identity binding: no code, the same account at the AI app's sign-in,\n\t// until the time the relay gave (DEC-202); then Continue.\n\tconst signInUntil = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-sign-in-until\",\n\t});\n\t/** The time of `iso` in hours and minutes, as the dialog's language writes it. */\n\tconst timeOf = (iso: string) => {\n\t\tconst time = new Date(iso);\n\t\ttry {\n\t\t\treturn time.toLocaleTimeString(s.lang, {\n\t\t\t\thour: \"numeric\",\n\t\t\t\tminute: \"2-digit\",\n\t\t\t});\n\t\t} catch {\n\t\t\treturn time.toLocaleTimeString(); // a `lang` the browser does not know\n\t\t}\n\t};\n\tconst signInLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-sign-in\" },\n\t\ts.signIn,\n\t\tel(doc, \"br\"),\n\t\tsignInUntil,\n\t);\n\tconst more = button(\n\t\tdoc,\n\t\ts.continuePairing,\n\t\t() => mcp.startPairing(),\n\t\t\"tab-mcp-continue\",\n\t\t\"primary\",\n\t);\n\tconst timeUpText = el(doc, \"span\", { text: s.signInTimeUp });\n\tconst timeUp = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-time-up\" },\n\t\ttimeUpText,\n\t\t\" \",\n\t\tmore,\n\t);\n\n\tconst steps = el(doc, \"ul\");\n\tconst help = el(\n\t\tdoc,\n\t\t\"details\",\n\t\t{ className: \"tab-mcp-help\" },\n\t\tel(doc, \"summary\", { text: s.help }),\n\t\tsteps,\n\t);\n\tconst guideUrl =\n\t\tui?.setup?.guide === undefined ? SETUP_GUIDE : ui.setup.guide;\n\tif (guideUrl !== null) {\n\t\tconst guide = el(doc, \"a\", { text: s.guide });\n\t\tguide.href = guideUrl;\n\t\tguide.target = \"_blank\";\n\t\tguide.rel = \"noopener noreferrer\";\n\t\thelp.append(el(doc, \"p\", { className: \"tab-mcp-guide\" }, guide));\n\t}\n\tconst instructions =\n\t\tui?.setup?.instructions ??\n\t\t((name: string, address: string) => setupInstructions(name, address, s));\n\n\t// Everything for adding the page to an AI app. Once one is connected, it\n\t// is behind \"Connect another AI app\", closed: the next code is not news.\n\t// Where to paste the address comes right after it, the code after that\n\t// (CU 23); Disconnect all apps last. The help stays closed (DEC-147).\n\tconst setupId = `${nextId()}-setup`;\n\tconst setup = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-setup\", id: setupId },\n\t\taddressBox,\n\t\thelp,\n\t\tcodeLine,\n\t\tsignInLine,\n\t\ttimeUp,\n\t\tfreshBox,\n\t\tquestion,\n\t);\n\tconst setupToggle = button(\n\t\tdoc,\n\t\ts.connectAnother,\n\t\t() => {\n\t\t\texpanded = !expanded;\n\t\t\trender();\n\t\t},\n\t\t\"tab-mcp-setup-toggle\",\n\t);\n\tsetupToggle.setAttribute(\"aria-controls\", setupId);\n\n\tconst appList = el(doc, \"ul\");\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tappsNote.setAttribute(\"role\", \"status\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: s.connectedHeading }),\n\t\tappList,\n\t\tappsNote,\n\t);\n\n\t// Until an app is connected, closing it is not the next step: a small\n\t// Close at the end, saying what closing does (the code stops, the address\n\t// stays). Once one is, a prominent Done replaces both.\n\tconst closeNote = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-close-note\",\n\t\ttext: s.closeNote,\n\t});\n\tconst close = button(doc, s.close, () => dialog.close(), \"tab-mcp-close\");\n\tconst done = button(\n\t\tdoc,\n\t\ts.done,\n\t\t() => dialog.close(),\n\t\t\"tab-mcp-done\",\n\t\t\"primary\",\n\t);\n\t// While not connected (it failed, the session ended, it reconnects): the\n\t// next step, from a click, so it has the user action it needs (CU 4).\n\t// While reconnecting, connect() makes the next attempt at once.\n\tconst retry = button(\n\t\tdoc,\n\t\ts.connectAgain,\n\t\t() => {\n\t\t\tmessage = undefined;\n\t\t\tmcp.connect().then(\n\t\t\t\t() => {\n\t\t\t\t\tif (doc.activeElement === close) start().focus();\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tmessage = connectFailure(error, s);\n\t\t\t\t\trender();\n\t\t\t\t\t// Focus went to Close while it connected: back to Connect\n\t\t\t\t\t// again, so a second Enter tries again instead of closing.\n\t\t\t\t\tif (doc.activeElement === close && !retry.hidden) retry.focus();\n\t\t\t\t},\n\t\t\t);\n\t\t\trender();\n\t\t},\n\t\t\"tab-mcp-retry\",\n\t\t\"primary\",\n\t);\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tcloseNote,\n\t\t\" \",\n\t\tclose,\n\t\tretry,\n\t\tdone,\n\t);\n\tdialog.append(\n\t\tviaExtension,\n\t\tsuccess,\n\t\tstatus,\n\t\tapps,\n\t\tsetupToggle,\n\t\tsetup,\n\t\tactions,\n\t\tlive,\n\t);\n\n\t// The dialog's own state; the rest is read from `mcp` in `render()`.\n\t/** The setup is open while an app is connected. */\n\tlet expanded = false;\n\t/** The Disconnect all apps question is open. */\n\tlet asking = false;\n\t/** Disconnect all apps waits for the new session. */\n\tlet renewing = false;\n\t/** Disconnect all apps got its session; until an app pairs or it disconnects. */\n\tlet renewed = false;\n\t/** Why it is not connected, in the user's words, while it is not. */\n\tlet message: string | undefined;\n\t/** Why the last Disconnect failed, while connected. */\n\tlet appsProblem: string | undefined;\n\t/** The grants of the last render: a new one is an app that just paired. */\n\tlet grantsSeen = new Set(mcp.grants.map((g) => g.grantId));\n\t/** The address the help's steps were made for. */\n\tlet stepsFor: string | undefined;\n\t/** The code shown, and the wait after it was used (until the app connects). */\n\tlet shownCode: PairingCode | undefined;\n\tlet usedTimer: ReturnType<typeof setTimeout> | undefined;\n\t/** Renders again when the time for a sign-in is up. */\n\tlet untilTimer: ReturnType<typeof setTimeout> | undefined;\n\t/** Shown in the connected state. */\n\tlet connectedView = false;\n\n\t// Where focus goes when its control was hidden: the next step (Done or\n\t// Connect again), else Close.\n\tconst closer = () => (connectedView ? done : retry.hidden ? close : retry);\n\t// Where focus starts: Done once connected, else the address's Copy.\n\tconst start = () => (connectedView ? done : copy);\n\n\t// One item per grant, kept while the grant is: a focused Disconnect keeps\n\t// its focus. Under it, the switches for what runs without asking.\n\tconst items = new Map<\n\t\tstring,\n\t\t{\n\t\t\titem: HTMLLIElement;\n\t\t\tdisconnect: HTMLButtonElement;\n\t\t\trenderAllowed: () => void;\n\t\t}\n\t>();\n\tconst appItem = (grant: Grant) => {\n\t\tconst app = clientLabel(grant.client, s);\n\t\tconst disconnect = button(\n\t\t\tdoc,\n\t\t\ts.disconnect,\n\t\t\t() => {\n\t\t\t\tappsProblem = undefined;\n\t\t\t\tmcp.revoke(grant.grantId).catch((error: unknown) => {\n\t\t\t\t\t// Not connected any more: the note says so already.\n\t\t\t\t\tif (mcp.state === \"connected\")\n\t\t\t\t\t\tappsProblem =\n\t\t\t\t\t\t\t(error as { code?: unknown } | null)?.code === \"store_unavailable\"\n\t\t\t\t\t\t\t\t? s.storeUnavailable\n\t\t\t\t\t\t\t\t: s.disconnectFailed;\n\t\t\t\t\trender();\n\t\t\t\t});\n\t\t\t\trender();\n\t\t\t},\n\t\t\t\"tab-mcp-disconnect\",\n\t\t\t\"danger\",\n\t\t);\n\t\t// One name per button: each list item has its own Disconnect.\n\t\tdisconnect.setAttribute(\"aria-label\", format(s.disconnectApp, { app }));\n\t\tconst switches = allowedSwitches(doc, s, allowed, grant.grantId, app);\n\t\tconst item = el(\n\t\t\tdoc,\n\t\t\t\"li\",\n\t\t\t{},\n\t\t\tel(\n\t\t\t\tdoc,\n\t\t\t\t\"span\",\n\t\t\t\t{ className: \"tab-mcp-app\" },\n\t\t\t\tformat(s.appConnected, { app }),\n\t\t\t),\n\t\t\t\" \",\n\t\t\tdisconnect,\n\t\t\tswitches.box,\n\t\t);\n\t\treturn { item, disconnect, renderAllowed: switches.render };\n\t};\n\n\t/** The steps for `address` in the help, made again when it changes. */\n\tconst renderSteps = (session: SessionInfo) => {\n\t\tif (stepsFor === session.address) return;\n\t\tstepsFor = session.address;\n\t\tsteps.replaceChildren(\n\t\t\t...instructions(serverName, session.address).map(\n\t\t\t\t({ app, text: how, command, note }) => {\n\t\t\t\t\tconst item = el(\n\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\"li\",\n\t\t\t\t\t\t{},\n\t\t\t\t\t\tel(doc, \"strong\", { text: `${app}:` }),\n\t\t\t\t\t\t` ${how}`,\n\t\t\t\t\t);\n\t\t\t\t\tif (command !== undefined) {\n\t\t\t\t\t\t// A block with its own Copy, like the code.\n\t\t\t\t\t\tconst text = el(doc, \"pre\", { text: command });\n\t\t\t\t\t\ttext.dir = \"ltr\";\n\t\t\t\t\t\tconst { button: copyCommand } = copyButton(\n\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\ts,\n\t\t\t\t\t\t\tformat(s.copyCommand, { app }),\n\t\t\t\t\t\t\t() => text.textContent ?? \"\",\n\t\t\t\t\t\t\t() => doc.getSelection()?.selectAllChildren(text),\n\t\t\t\t\t\t\tannounce,\n\t\t\t\t\t\t\t\"tab-mcp-command-copy\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"div\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command\" },\n\t\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\t\tcopyCommand,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (note !== undefined)\n\t\t\t\t\t\titem.append(\n\t\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\"small\",\n\t\t\t\t\t\t\t\t{ className: \"tab-mcp-command-note\" },\n\t\t\t\t\t\t\t\t...note.map((part) =>\n\t\t\t\t\t\t\t\t\t\"code\" in part\n\t\t\t\t\t\t\t\t\t\t? el(doc, \"code\", { text: part.code })\n\t\t\t\t\t\t\t\t\t\t: part.text,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\treturn item;\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t};\n\n\t/** The pairing code, or \"Code used\" in its place while the AI app connects. */\n\tconst renderCode = (paired: boolean) => {\n\t\tconst current = mcp.pairingCode;\n\t\tif (current === undefined || paired) {\n\t\t\t// None any more, or the app connected: the next code shows.\n\t\t\tclearTimeout(usedTimer);\n\t\t\tusedTimer = undefined;\n\t\t} else if (current.code !== shownCode?.code) {\n\t\t\tif (current.reason === \"used\") {\n\t\t\t\t// Entered just now: no new code in plain view while the AI app\n\t\t\t\t// connects; it shows if none does.\n\t\t\t\tif (usedTimer === undefined) {\n\t\t\t\t\tusedTimer = setTimeout(() => {\n\t\t\t\t\t\t// No app came: the code shows (unless another came meanwhile).\n\t\t\t\t\t\tusedTimer = undefined;\n\t\t\t\t\t\tshownCode = mcp.pairingCode;\n\t\t\t\t\t\trender();\n\t\t\t\t\t}, CODE_USED_WAIT_MS);\n\t\t\t\t\tannounce(s.codeUsed);\n\t\t\t\t}\n\t\t\t} else if (usedTimer !== undefined) {\n\t\t\t\t// Expired meanwhile: the user needs this one now.\n\t\t\t\tclearTimeout(usedTimer);\n\t\t\t\tusedTimer = undefined;\n\t\t\t}\n\t\t}\n\t\tconst used = usedTimer !== undefined;\n\t\tif (!used) {\n\t\t\t// A new code is not copied yet.\n\t\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\t\tcode.textContent = current?.code ?? \"\";\n\t\t\tshownCode = current;\n\t\t}\n\t\tcodeSentence.hidden = used;\n\t\tcopyCode.hidden = used;\n\t\tcodeUsed.hidden = !used;\n\t\tcodeUsed.textContent = used ? s.codeUsed : \"\";\n\t\treturn current !== undefined;\n\t};\n\n\t/** Shows what `mcp` and the flags say; keeps the focus on a shown control. */\n\tconst render = () => {\n\t\tconst focused = doc.activeElement;\n\t\tconst { state, session, grants } = mcp;\n\t\tconst connected = state === \"connected\";\n\t\tconst oidc = session?.pairing === \"oidc\";\n\t\t// With identity binding, the address is of no use until the relay\n\t\t// knows who is signed in to the page: the status says what is missing.\n\t\tconst signIn = oidc ? signInText(mcp, s) : undefined;\n\t\tconst shown = session !== undefined && signIn === undefined;\n\t\t// A sign-in pairs the page only until the relay's time (DEC-202): then\n\t\t// the dialog says so and offers Continue. Without one (a relay up to\n\t\t// 0.12.1, or no answer yet) it shows what it showed before.\n\t\tconst until = oidc ? mcp.pairingUntil : undefined;\n\t\tconst left = until === undefined ? 1 : Date.parse(until) - Date.now();\n\t\tconst over = connected && shown && left <= 0;\n\t\tclearTimeout(untilTimer);\n\t\t// At most a minute ahead, so that a throttled timer is not the only\n\t\t// chance to see the end.\n\t\tuntilTimer =\n\t\t\tleft > 0 && until !== undefined\n\t\t\t\t? setTimeout(render, Math.min(left, 60_000))\n\t\t\t\t: undefined;\n\n\t\t// An app that paired just now: the setup closes again (unless the\n\t\t// Disconnect all apps question is open in it), and the confirmation is\n\t\t// announced.\n\t\tconst ids = new Set(grants.map((g) => g.grantId));\n\t\tconst paired = connected && grants.some((g) => !grantsSeen.has(g.grantId));\n\t\tgrantsSeen = ids;\n\t\tif (paired) {\n\t\t\trenewed = false;\n\t\t\tif (!asking) expanded = false;\n\t\t}\n\t\t// Nobody left to disconnect: no question needed.\n\t\tconst names = appLabels(grants, s);\n\t\tif (names.length === 0 || !shown) asking = false;\n\n\t\tconnectedView = !renewing && connected && grants.length > 0;\n\t\tshowNames(doc, successTitle, s.connected, names, s);\n\t\tsuccessNext.textContent = plural(s.connectedNext, names.length, s);\n\t\tif (connectedView) dialog.setAttribute(\"aria-describedby\", successId);\n\t\telse dialog.removeAttribute(\"aria-describedby\");\n\t\tsuccess.hidden = !connectedView;\n\n\t\t// Each app once, named as the connected apps are.\n\t\tconst extension = mcp.extension;\n\t\tconst via = [\n\t\t\t...new Set(\n\t\t\t\t(extension?.apps ?? []).map((a) =>\n\t\t\t\t\tclientLabel({ id: a.host, name: a.name, host: a.host }, s),\n\t\t\t\t),\n\t\t\t),\n\t\t];\n\t\tviaExtension.hidden = via.length === 0;\n\t\tshowNames(\n\t\t\tdoc,\n\t\t\tviaExtension,\n\t\t\textension?.whileInFront ? s.viaExtensionInFront : s.viaExtension,\n\t\t\tvia,\n\t\t\ts,\n\t\t);\n\n\t\t// The status line is for the setup; the confirmation says it otherwise.\n\t\tif (connected) message = undefined;\n\t\tconst appName = session?.appName;\n\t\tstatus.textContent = renewing\n\t\t\t? s.disconnectingAll\n\t\t\t: state === \"connecting\"\n\t\t\t\t? s.connecting\n\t\t\t\t: state === \"reconnecting\"\n\t\t\t\t\t? s.reconnecting\n\t\t\t\t\t: !connected\n\t\t\t\t\t\t? (message ?? s.notConnected)\n\t\t\t\t\t\t: (signIn ??\n\t\t\t\t\t\t\t(over\n\t\t\t\t\t\t\t\t? s.signInTimeUp\n\t\t\t\t\t\t\t\t: renewed\n\t\t\t\t\t\t\t\t\t? s.disconnectAllDone\n\t\t\t\t\t\t\t\t\t: appName !== undefined\n\t\t\t\t\t\t\t\t\t\t? format(s.readyApp, { app: appName })\n\t\t\t\t\t\t\t\t\t\t: s.readyPage));\n\t\tstatus.hidden = connectedView;\n\n\t\t// The address, its help and Disconnect all apps.\n\t\tconst addressShownBefore = !addressBox.hidden;\n\t\tif (shown && address.value !== session.address) {\n\t\t\taddress.value = session.address;\n\t\t\tresetCopy();\n\t\t}\n\t\tif (shown) renderSteps(session);\n\t\taddressBox.hidden = help.hidden = freshBox.hidden = !shown;\n\t\tfresh.disabled = !connected;\n\t\tquestion.hidden = !asking;\n\t\tif (asking) showNames(doc, questionText, s.disconnectAllQuestion, names, s);\n\t\tconst hasCode = renderCode(paired);\n\t\tcodeLine.hidden = oidc || !hasCode || !connected;\n\t\tsignInLine.hidden = !oidc || mcp.identity !== \"bound\" || over;\n\t\tsignInUntil.textContent =\n\t\t\tuntil === undefined ? \"\" : format(s.signInUntil, { time: timeOf(until) });\n\t\tsignInUntil.hidden = until === undefined;\n\t\ttimeUp.hidden = !over;\n\t\t// With an app connected the status is hidden: the reason goes here.\n\t\ttimeUpText.hidden = !connectedView;\n\n\t\tsetupToggle.hidden = !connectedView;\n\t\tsetupToggle.setAttribute(\"aria-expanded\", String(expanded));\n\t\tsetup.hidden = connectedView && !expanded;\n\t\tcopy.classList.toggle(\"tab-mcp-primary\", !connectedView);\n\n\t\t// The connected apps; only the relay can revoke, so only while connected.\n\t\tfor (const [id, { item }] of items) {\n\t\t\tif (ids.has(id)) continue;\n\t\t\titem.remove();\n\t\t\titems.delete(id);\n\t\t}\n\t\tgrants.forEach((grant, i) => {\n\t\t\tlet entry = items.get(grant.grantId);\n\t\t\tif (entry === undefined) {\n\t\t\t\tentry = appItem(grant);\n\t\t\t\titems.set(grant.grantId, entry);\n\t\t\t}\n\t\t\tentry.disconnect.disabled = !connected;\n\t\t\tentry.renderAllowed();\n\t\t\tif (appList.children[i] !== entry.item)\n\t\t\t\tappList.insertBefore(entry.item, appList.children[i] ?? null);\n\t\t});\n\t\tappsNote.textContent = connected ? (appsProblem ?? \"\") : s.disconnectNote;\n\t\tappsNote.hidden = connected && appsProblem === undefined;\n\t\tapps.hidden = grants.length === 0;\n\n\t\t// The note is about the code: only while one is shown and none connected.\n\t\tcloseNote.hidden = connectedView || codeLine.hidden;\n\t\tclose.hidden = connectedView;\n\t\tdone.hidden = !connectedView;\n\t\tretry.hidden =\n\t\t\trenewing || (state !== \"disconnected\" && state !== \"reconnecting\");\n\n\t\t// Focus never stays on a control that was hidden or removed; from the\n\t\t// Disconnect all apps question that closed, back to its button; from\n\t\t// Continue, once the relay took it, to the start.\n\t\tif (\n\t\t\tfocused !== null &&\n\t\t\tfocused !== dialog &&\n\t\t\tfocused !== doc.body &&\n\t\t\t(!focused.isConnected ||\n\t\t\t\t(dialog.contains(focused) && focused.closest(\"[hidden]\") !== null))\n\t\t)\n\t\t\t(question.contains(focused) && !freshBox.hidden\n\t\t\t\t? fresh\n\t\t\t\t: focused === more && !setup.hidden\n\t\t\t\t\t? start()\n\t\t\t\t\t: closer()\n\t\t\t).focus();\n\t\t// The address showed only now: start there (or at Done), or, after a\n\t\t// Disconnect all apps, at its Copy.\n\t\telse if (doc.activeElement === dialog && (connectedView || shown))\n\t\t\tstart().focus();\n\t\telse if (\n\t\t\trenewed &&\n\t\t\tshown &&\n\t\t\t!addressShownBefore &&\n\t\t\tdoc.activeElement === close\n\t\t)\n\t\t\tcopy.focus();\n\t\tif (paired && connectedView)\n\t\t\tannounce(`${successTitle.textContent}. ${successNext.textContent}`);\n\t};\n\n\tconst askDisconnectAll = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (mcp.grants.length === 0) {\n\t\t\trunDisconnectAll();\n\t\t\treturn;\n\t\t}\n\t\tasking = true;\n\t\trender();\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst runDisconnectAll = () => {\n\t\trenewing = true;\n\t\trenewed = false;\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tasking = false;\n\t\trender();\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.disconnectAll().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\trenewed = true;\n\t\t\t\trender();\n\t\t\t\t// At its Copy once the address shows again (with identity binding\n\t\t\t\t// maybe only later: `render()` moves it then).\n\t\t\t\tif (!addressBox.hidden) copy.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tmessage = connectFailure(error, s);\n\t\t\t\trender();\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\n\t// A refusal that stops reconnecting comes as `error` (with its `reason`)\n\t// just before the `statechange` to `disconnected`: that says why it stopped.\n\tlet stoppedBy: unknown;\n\tlet wasReconnecting = mcp.state === \"reconnecting\";\n\tconst onError = (event: CustomEvent<{ error: Error }>) => {\n\t\tconst { error } = event.detail;\n\t\tif (wasReconnecting && (error as { reason?: unknown }).reason !== undefined)\n\t\t\tstoppedBy = error;\n\t};\n\tconst onState = (event: CustomEvent<StateChangeDetail>) => {\n\t\tconst { state, reason } = event.detail;\n\t\tif (reason !== undefined && reason !== \"disconnect_all\") {\n\t\t\tmessage = disconnectedText(reason, s);\n\t\t\trenewed = false;\n\t\t}\n\t\t// Refused, or ended by the page (`disconnect()`) while it waited.\n\t\tif (state === \"disconnected\" && wasReconnecting)\n\t\t\tmessage =\n\t\t\t\tstoppedBy === undefined ? s.disconnected : connectFailure(stoppedBy, s);\n\t\twasReconnecting = state === \"reconnecting\";\n\t\tstoppedBy = undefined;\n\t\trender();\n\t};\n\n\t// The address was taken over: the notice says so instead of this dialog.\n\tconst onReplaced = () => dialog.close();\n\twatchReplaced(mcp, doc, ui);\n\tconst stopAllowed = allowed.onChange(render);\n\tmcp.addEventListener(\"statechange\", onState);\n\tmcp.addEventListener(\"pairingcode\", render);\n\tmcp.addEventListener(\"pairinguntil\", render);\n\t// A tab in the background may not have run the timer: look again.\n\tdoc.addEventListener(\"visibilitychange\", render);\n\tmcp.addEventListener(\"grantschange\", render);\n\tmcp.addEventListener(\"identitychange\", render);\n\tmcp.addEventListener(\"extensionchange\", render);\n\tmcp.addEventListener(\"error\", onError);\n\tmcp.addEventListener(\"replaced\", onReplaced);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trender();\n\tconnecting.then(render, (error: unknown) => {\n\t\tmessage = connectFailure(error, s);\n\t\trender();\n\t});\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(usedTimer);\n\t\t\t\tclearTimeout(untilTimer);\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tstopAllowed();\n\t\t\t\tmcp.removeEventListener(\"statechange\", onState);\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", render);\n\t\t\t\tmcp.removeEventListener(\"pairinguntil\", render);\n\t\t\t\tdoc.removeEventListener(\"visibilitychange\", render);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", render);\n\t\t\t\tmcp.removeEventListener(\"identitychange\", render);\n\t\t\t\tmcp.removeEventListener(\"extensionchange\", render);\n\t\t\t\tmcp.removeEventListener(\"error\", onError);\n\t\t\t\tmcp.removeEventListener(\"replaced\", onReplaced);\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve();\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\t// Start at Done once connected, else at the address's Copy; until the\n\t\t// address is there, at the dialog itself (its title is read out), not\n\t\t// at Close.\n\t\tif (connectedView || !addressBox.hidden) start().focus();\n\t\telse dialog.focus();\n\t});\n}\n"
8
+ ],
9
+ "mappings": "sKAcO,SAAS,EAAW,CAAC,EAAsB,CACjD,IAAM,EAAQ,EACZ,UAAU,MAAM,EAChB,QAAQ,UAAW,EAAE,EACrB,YAAY,EACZ,QAAQ,gBAAiB,GAAG,EAC5B,QAAQ,SAAU,GAAG,EACrB,QAAQ,WAAY,EAAE,EACtB,MAAM,EAAG,EAAE,EACX,QAAQ,MAAO,EAAE,EACnB,OAAO,IAAU,GAAK,QAAU,EAQ1B,SAAS,EAAc,CAAC,EAAqC,CACnE,GAAI,CACH,IAAM,EAAO,IAAI,IAAI,CAAO,EAAE,KAC9B,MAAO,qCAAqC,KAAK,CAAI,EAAI,EAAO,OAC/D,KAAM,CACP,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AC,IAAmB,CAC3C,EAAU,GAAe,EAAO,CAAC,EACjC,EAAO,EACP,EAEM,IAAI,QAAQ,CAAC,IAAY,CA0B/B,GAzBA,EAAO,iBACN,QACA,IAAM,CACL,aAAa,CAAS,EACtB,aAAa,EAAU,EACvB,EAAI,YAAY,EAChB,GAAY,EACZ,EAAI,oBAAoB,cAAe,EAAO,EAC9C,EAAI,oBAAoB,cAAe,CAAM,EAC7C,EAAI,oBAAoB,eAAgB,CAAM,EAC9C,EAAI,oBAAoB,mBAAoB,CAAM,EAClD,EAAI,oBAAoB,eAAgB,CAAM,EAC9C,EAAI,oBAAoB,iBAAkB,CAAM,EAChD,EAAI,oBAAoB,kBAAmB,CAAM,EACjD,EAAI,oBAAoB,QAAS,EAAO,EACxC,EAAI,oBAAoB,WAAY,EAAU,EAC9C,EAAO,OAAO,EACd,EAAQ,GAET,CAAE,KAAM,EAAK,CACd,EACA,EAAO,UAAU,EAIb,GAAiB,CAAC,EAAW,OAAQ,GAAM,EAAE,MAAM,EACvD,KAAK,EAAO,MAAM,EAClB",
10
+ "debugId": "7195A35AE77F393F64756E2164756E21",
11
+ "names": []
12
+ }
@@ -0,0 +1,17 @@
1
+ var Ct=/^(?:\d{1,4}x\d{1,4}|any)$/;function Et(e){let{src:t,mimeType:n,sizes:r,theme:s}=e;if(typeof t!=="string")return;let i=/^https?:/i.test(t)&&t.length<=2048,o=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!i&&!o)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let u=Array.isArray(r)?r.map((y)=>String(y).toLowerCase()).filter((y)=>Ct.test(y)):[];if(u.length>0)a.sizes=u;if(s==="light"||s==="dark")a.theme=s;return a}function Se(e){let t=[];for(let n of e){let r=typeof n==="object"&&n!==null?Et(n):void 0;if(r!==void 0)t.push(r);if(t.length===8)break}return t}function be(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return Se([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let r={src:n.href};if(n.type)r.mimeType=n.type;let s=n.getAttribute("sizes");if(s)r.sizes=s.trim().split(/\s+/);let i=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(i)r.theme=i[1]?.toLowerCase();return r}))}catch{return[]}}function ue(e,t){let n=typeof e;if(n!==typeof t)return!1;let r=Array.isArray(e),s=Array.isArray(t);if(r!==s)return!1;if(r){let i=e.length;if(i!==t.length)return!1;for(let o=0;o<i;o++)if(!ue(e[o],t[o]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let u of i){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!ue(e[u],t[u]))return!1}return!0}return e===t}function J(e){return encodeURI(St(e)).replace(/#/g,"%23")}function St(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var At=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,Ot=/^%[0-9A-Fa-f]{2}$/,Pt=/^[A-Za-z0-9._~-]$/;function Nt(e){let t="";for(let n=0;n<e.length;){let r=e[n],s=e.slice(n,n+3);if(r==="%"&&Ot.test(s)){let o=String.fromCharCode(parseInt(s.slice(1),16));t+=Pt.test(o)?o:s.toUpperCase(),n+=3;continue}let i=String.fromCodePoint(e.codePointAt(n));t+=At.test(i)?i:encodeURIComponent(i),n+=i.length}return t}function $e(e,t){let n=new URL(e,t.href);return n.hash=n.hash?Nt(n.hash.slice(1)):"",n}var jt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},qt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},Ht={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},zt=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function Z(e,t=Object.create(null),n=zt,r=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let i=e.$id||e.id;if(i){let o=$e(i,n);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",r==="")n=o;else Z(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(r?"#"+r:"");if(t[s]!==void 0&&t[s]!==e)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let i=$e(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:i.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let i=$e(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:i.href})}if(e.$anchor){let i=$e("#"+e.$anchor,n);t[i.href]=e}for(let i in e){if(Ht[i])continue;let o=`${r}/${J(i)}`,a=e[i];if(Array.isArray(a)){if(jt[i]){let u=a.length;for(let y=0;y<u;y++)Z(a[y],t,n,`${o}/${y}`)}}else if(qt[i])for(let u in a)Z(a[u],t,n,`${o}/${J(u)}`);else Z(a,t,n,o)}return t}var Dt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Bt=[0,31,28,31,30,31,30,31,31,30,31,30,31],Jt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,Xe=/^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/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e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Zt=(e)=>{let t=e.match(Xt);if(!t)return!1;let n=t[1],r=t[2];if(!n||!r||n.length>64||r.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(r.startsWith("[")&&r.endsWith("]")){let s=r.slice(1,-1);if(/^ipv6:/i.test(s))return Qe.test(s.slice(5));return Ze.test(s)}return Xe.test(r)},Ze=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Qe=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,Qt=(e)=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e);function G(e){return e.test.bind(e)}var Ae={date:Le,time:et.bind(void 0,!0),"date-time":tn,duration:Qt,uri:on,"uri-reference":G(Ut),"uri-template":G(Vt),url:G(Gt),email:Zt,hostname:G(Xe),ipv4:G(Ze),ipv6:G(Qe),regex:an,uuid:G(Wt),"json-pointer":G(Ft),"json-pointer-uri-fragment":G(Kt),"relative-json-pointer":G(Yt)};function Lt(e){return e%4===0&&(e%100!==0||e%400===0)}function Le(e){let t=e.match(Dt);if(!t)return!1;let n=t[1],r=t[2],s=t[3];if(!n||!r||!s)return!1;let i=+n,o=+r,a=+s,u=o==2&&Lt(i)?29:Bt[o];return o>=1&&o<=12&&a>=1&&u!==void 0&&a<=u}function et(e,t){let n=t.match(Jt);if(!n)return!1;let r=n[1],s=n[2],i=n[3];if(!r||!s||!i)return!1;let o=+r,a=+s,u=+i,y=n[5],b=n[6],_=+(n[7]??0),A=+(n[8]??0);if(o>23||a>59||u>60||_>23||A>59||e&&y===void 0)return!1;if(u<60)return!0;let D=b==="+"?1:b==="-"?-1:0;return(o*60+a-D*(_*60+A)+1440)%1440===1439}var en=/t|\s/i;function tn(e){let[t,n,r]=e.split(en);return t!==void 0&&n!==void 0&&r===void 0&&Le(t)&&et(!0,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;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function on(e){return nn.test(e)&&rn.test(e)}var sn=/[^\\]\\Z/;function an(e){if(sn.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function tt(e){let t=0,n=e.length,r=0,s;while(r<n)if(t++,s=e.charCodeAt(r++),s>=55296&&s<=56319&&r<n){if(s=e.charCodeAt(r),(s&64512)==56320)r++}return t}function oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function nt(e){let t=Math.abs(e).toString().split("e"),n=t[0],r=t[1]??"0",s=n.indexOf("."),i=s===-1?0:n.length-s-1;return[BigInt(n.replace(".","")),Number(r)-i]}function dn(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,r]=nt(e),[s,i]=nt(t),o=r-i;if(o>=0)return n*10n**BigInt(o)%s===0n;return n%(s*10n**BigInt(-o))===0n}function N(e,t,n="2019-09",r=Z(t),s=!0,i=null,o="#",a="#",u=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let y=typeof e,b;switch(y){case"boolean":case"number":case"string":b=y;break;case"object":if(e===null)b="null";else if(Array.isArray(e))b="array";else b="object";break;default:throw Error(`Instances of "${y}" type are not supported.`)}let{$ref:_,$recursiveRef:A,$recursiveAnchor:D,type:C,const:O,enum:j,required:U,not:f,anyOf:g,allOf:h,oneOf:v,if:w,then:R,else:S,format:E,properties:d,patternProperties:M,additionalProperties:q,unevaluatedProperties:H,minProperties:X,maxProperties:V,propertyNames:ee,dependentRequired:te,dependentSchemas:Ue,dependencies:Re,prefixItems:Ie,items:ce,additionalItems:Ve,unevaluatedItems:Ge,contains:We,minContains:K,maxContains:Me,minItems:_e,maxItems:Ce,uniqueItems:Mt,minimum:ne,maximum:re,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Ee,minLength:ye,maxLength:ge,pattern:Fe,__absolute_ref__:he,__absolute_recursive_ref__:_t}=t,c=[];if(D===!0&&i===null)i=t;if(A==="#"){let k=i===null?r[_t]:i,m=`${a}/$recursiveRef`,I=N(e,i===null?t:i,n,r,s,k,o,m,u);if(!I.valid)c.push({instanceLocation:o,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(_!==void 0){let m=r[he||_];if(m===void 0){let l=`Unresolved $ref "${_}".`;if(he&&he!==_)l+=` Absolute URI "${he}".`;throw l+=`
2
+ Known schemas:
3
+ - ${Object.keys(r).join(`
4
+ - `)}`,Error(l)}let I=`${a}/$ref`,p=N(e,m,n,r,s,i,o,I,u);if(!p.valid)c.push({instanceLocation:o,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...p.errors);if(n==="4"||n==="7")return{valid:c.length===0,errors:c}}if(Array.isArray(C)){let k=C.length,m=!1;for(let I=0;I<k;I++)if(b===C[I]||C[I]==="integer"&&b==="number"&&e%1===0&&e===e){m=!0;break}if(!m)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${b}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(b!=="number"||e%1||e!==e)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${b}" is invalid. Expected "${C}".`})}else if(C!==void 0&&b!==C)c.push({instanceLocation:o,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${b}" is invalid. Expected "${C}".`});if(O!==void 0){if(b==="object"||b==="array"){if(!ue(e,O))c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}else if(e!==O)c.push({instanceLocation:o,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(O)}.`})}if(j!==void 0){if(b==="object"||b==="array"){if(!j.some((k)=>ue(e,k)))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(j)}.`})}else if(!j.some((k)=>e===k))c.push({instanceLocation:o,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(j)}.`})}if(f!==void 0){let k=`${a}/not`;if(N(e,f,n,r,s,i,o,k).valid)c.push({instanceLocation:o,keyword:"not",keywordLocation:k,error:'Instance matched "not" schema.'})}let we=[];if(g!==void 0){let k=`${a}/anyOf`,m=c.length,I=!1;for(let[p,l]of g.entries()){let T=Object.create(u),x=N(e,l,n,r,s,D===!0?i:null,o,`${k}/${p}`,T);if(c.push(...x.errors),I=I||x.valid,x.valid)we.push(T)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:k,error:"Instance does not match any subschemas."})}if(h!==void 0){let k=`${a}/allOf`,m=c.length,I=!0;for(let[p,l]of h.entries()){let T=Object.create(u),x=N(e,l,n,r,s,D===!0?i:null,o,`${k}/${p}`,T);if(c.push(...x.errors),I=I&&x.valid,x.valid)we.push(T)}if(I)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:k,error:"Instance does not match every subschema."})}if(v!==void 0){let k=`${a}/oneOf`,m=c.length,I=v.filter((p,l)=>{let T=Object.create(u),x=N(e,p,n,r,s,D===!0?i:null,o,`${k}/${l}`,T);if(c.push(...x.errors),x.valid)we.push(T);return x.valid}).length;if(I===1)c.length=m;else c.splice(m,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:k,error:`Instance does not match exactly one subschema (${I} matches).`})}if(b==="object"||b==="array")Object.assign(u,...we);if(w!==void 0){let k=`${a}/if`,m=Object.create(null);if(N(e,w,n,r,s,i,o,k,m).valid){if(Object.assign(u,m),R!==void 0){let p=N(e,R,n,r,s,i,o,`${a}/then`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:k,error:'Instance does not match "then" schema.'},...p.errors)}}else if(S!==void 0){let p=N(e,S,n,r,s,i,o,`${a}/else`,u);if(!p.valid)c.push({instanceLocation:o,keyword:"if",keywordLocation:k,error:'Instance does not match "else" schema.'},...p.errors)}}if(b==="object"){if(U!==void 0){for(let p of U)if(!oe(e,p))c.push({instanceLocation:o,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${p}".`})}let k=Object.keys(e);if(X!==void 0&&k.length<X)c.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${X} properties.`});if(V!==void 0&&k.length>V)c.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${V} properties.`});if(ee!==void 0){let p=`${a}/propertyNames`;for(let l in e){let T=`${o}/${J(l)}`,x=N(l,ee,n,r,s,i,T,p);if(!x.valid)c.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:p,error:`Property name "${l}" does not match schema.`},...x.errors)}}if(te!==void 0){let p=`${a}/dependantRequired`;for(let l in te)if(oe(e,l)){let T=te[l];for(let x of T)if(!oe(e,x))c.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${l}" but does not have "${x}".`})}}if(Ue!==void 0)for(let[p,l]of Object.entries(Ue)){let T=`${a}/dependentSchemas`;if(oe(e,p)){let x=N(e,l,n,r,s,i,o,`${T}/${J(p)}`,u);if(!x.valid)c.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:T,error:`Instance has "${p}" but does not match dependant schema.`},...x.errors)}}if(Re!==void 0){let p=`${a}/dependencies`;for(let l in Re)if(oe(e,l)){let T=Re[l];if(Array.isArray(T)){for(let x of T)if(!oe(e,x))c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not have "${x}".`})}else{let x=N(e,T,n,r,s,i,o,`${p}/${J(l)}`);if(!x.valid)c.push({instanceLocation:o,keyword:"dependencies",keywordLocation:p,error:`Instance has "${l}" but does not match dependant schema.`},...x.errors)}}}let m=Object.create(null),I=!1;if(d!==void 0){let p=`${a}/properties`;for(let[l,T]of Object.entries(d)){if(!oe(e,l))continue;let x=`${o}/${J(l)}`,z=N(e[l],T,n,r,s,i,x,`${p}/${J(l)}`);if(m[l]=!0,z.valid)u[l]=!0;else if(I=s,c.push({instanceLocation:o,keyword:"properties",keywordLocation:p,error:`Property "${l}" does not match schema.`},...z.errors),I)break}}if(!I&&M!==void 0){let p=`${a}/patternProperties`;for(let[l,T]of Object.entries(M)){let x=new RegExp(l,"u");for(let z in e){if(!x.test(z))continue;let Ke=`${o}/${J(z)}`,Ye=N(e[z],T,n,r,s,i,Ke,`${p}/${J(l)}`);if(m[z]=!0,Ye.valid)u[z]=!0;else I=s,c.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:p,error:`Property "${z}" matches pattern "${l}" but does not match associated schema.`},...Ye.errors)}}}if(!I&&q!==void 0){let p=`${a}/additionalProperties`;for(let l in e){if(m[l])continue;let T=`${o}/${J(l)}`,x=N(e[l],q,n,r,s,i,T,p);if(x.valid)u[l]=!0;else I=s,c.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:p,error:`Property "${l}" does not match additional properties schema.`},...x.errors)}}else if(!I&&H!==void 0){let p=`${a}/unevaluatedProperties`;for(let l in e)if(!u[l]){let T=`${o}/${J(l)}`,x=N(e[l],H,n,r,s,i,T,p);if(x.valid)u[l]=!0;else c.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${l}" does not match unevaluated properties schema.`},...x.errors)}}}else if(b==="array"){if(Ce!==void 0&&e.length>Ce)c.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${Ce}).`});if(_e!==void 0&&e.length<_e)c.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${_e}).`});let k=e.length,m=0,I=!1;if(Ie!==void 0){let p=`${a}/prefixItems`,l=Math.min(Ie.length,k);for(;m<l;m++){let T=N(e[m],Ie[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!T.valid){if(I=s,c.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...T.errors),I)break}}}if(ce!==void 0){let p=`${a}/items`;if(Array.isArray(ce)){let l=Math.min(ce.length,k);for(;m<l;m++){let T=N(e[m],ce[m],n,r,s,i,`${o}/${m}`,`${p}/${m}`);if(u[m]=!0,!T.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...T.errors),I)break}}}else for(;m<k;m++){let l=N(e[m],ce,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid){if(I=s,c.push({instanceLocation:o,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...l.errors),I)break}}if(!I&&Ve!==void 0){let l=`${a}/additionalItems`;for(;m<k;m++){let T=N(e[m],Ve,n,r,s,i,`${o}/${m}`,l);if(u[m]=!0,!T.valid)I=s,c.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:l,error:"Items did not match additional items schema."},...T.errors)}}}if(We!==void 0)if(k===0&&K===void 0)c.push({instanceLocation:o,keyword:"contains",keywordLocation:`${a}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(K!==void 0&&k<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${k}) than minContains (${K}).`});else{let p=`${a}/contains`,l=c.length,T=0;for(let x=0;x<k;x++){let z=N(e[x],We,n,r,s,i,`${o}/${x}`,p);if(z.valid)u[x]=!0,T++;else c.push(...z.errors)}if(T>=(K||0))c.length=l;if(K===void 0&&T===0)c.splice(l,0,{instanceLocation:o,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(K!==void 0&&T<K)c.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${K} items matching schema. Only ${T} items were found.`});else if(Me!==void 0&&T>Me)c.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Me} items matching schema. ${T} items were found.`})}if(!I&&Ge!==void 0){let p=`${a}/unevaluatedItems`;for(m;m<k;m++){if(u[m])continue;let l=N(e[m],Ge,n,r,s,i,`${o}/${m}`,p);if(u[m]=!0,!l.valid)c.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...l.errors)}}if(Mt)for(let p=0;p<k;p++){let l=e[p],T=typeof l==="object"&&l!==null;for(let x=0;x<k;x++){if(p===x)continue;let z=e[x];if(l===z||T&&(typeof z==="object"&&z!==null)&&ue(l,z))c.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${a}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${x}.`}),p=Number.MAX_SAFE_INTEGER,x=Number.MAX_SAFE_INTEGER}}}else if(b==="number"){if(n==="4"){if(ne!==void 0&&(pe===!0&&e<=ne||e<ne))c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${ne}.`});if(re!==void 0&&(me===!0&&e>=re||e>re))c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${re}.`})}else{if(ne!==void 0&&e<ne)c.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${ne}.`});if(re!==void 0&&e>re)c.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${re}.`});if(pe!==void 0&&e<=pe)c.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)c.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Ee!==void 0){if(!dn(e,Ee))c.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${Ee}.`})}}else if(b==="string"){let k=ye===void 0&&ge===void 0?0:tt(e);if(ye!==void 0&&k<ye)c.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${k} < ${ye}).`});if(ge!==void 0&&k>ge)c.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${k} > ${ge}).`});if(Fe!==void 0&&!new RegExp(Fe,"u").test(e))c.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(E!==void 0&&Ae[E]&&!Ae[E](e))c.push({instanceLocation:o,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${E}".`})}return{valid:c.length===0,errors:c}}var rt="ch.ractive.tab-mcp/annotations",un=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],ln=["destructiveHint","idempotentHint","openWorldHint"];function ot(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let s of ln){let i=e[s];if(i!==void 0)t[s]=i}let n={};for(let s of un){let i=e[s];if(i!==void 0)n[s]=i}let r={};if(Object.keys(t).length>0)r.annotations=t;if(Object.keys(n).length>0)r.meta=n;return r}function st(e){let t=e._meta??{},n=t["ch.ractive.tab-mcp/annotations"];return{...e,_meta:{...t,["ch.ractive.tab-mcp/annotations"]:{...Y(n)?n:{},untrustedContentHint:!0}}}}function se(e){return{content:[{type:"text",text:e}],isError:!0}}function Y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var le=(e)=>typeof e==="string";function fn(e){if(!Y(e))return!1;switch(e.type){case"text":return le(e.text);case"image":case"audio":return le(e.data)&&le(e.mimeType);case"resource_link":return le(e.uri)&&le(e.name);case"resource":return Y(e.resource)&&le(e.resource.uri);default:return!1}}var cn=new Set(["content","structuredContent","isError","_meta","resultType"]);function it(e){if(!Y(e)||!Array.isArray(e.content))return!1;let{content:t,isError:n,structuredContent:r,_meta:s}=e;return(t.length>0?t.every(fn):Object.keys(e).every((i)=>cn.has(i)))&&(n===void 0||typeof n==="boolean")&&(r===void 0||Y(r))&&(s===void 0||Y(s))}function at(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(it(e))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return se("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]},r=JSON.parse(t);if(Y(r))n.structuredContent=r;return n}function Oe(e,t=!1){return e.content.map((n)=>Y(n)&&n.type==="text"&&typeof n.text==="string"?n.text:t?`[${Y(n)?String(n.type):"A"} content left out: WebMCP results are text.]`:"").filter((n)=>n!=="").join(`
5
+ `)}function dt(e){if(it(e))return e.structuredContent??(Oe(e,!0)||"Done.");return e===void 0?"Done.":e}function ut(e){let t=e instanceof Error?e.message:String(e);return se(t||"The tool failed.")}var ie="2026-07-28",Q="io.modelcontextprotocol/protocolVersion",xe="io.modelcontextprotocol/clientCapabilities",lt="io.modelcontextprotocol/clientInfo",ft="io.modelcontextprotocol/serverInfo",Pe="io.modelcontextprotocol/subscriptionId",pn=-32020,ct=-32022,mn="The page may ask the user to allow each call, usually in the page's browser tab.",yn=0,pt=new WeakMap;function Ne(e){let t=pt.get(e);if(t!==void 0)return t;let n=e.inputSchema,r;try{r=Z(n)}catch(i){let o=i instanceof Error?i.message:String(i);throw Error(o.split(`
6
+ `)[0])}for(let i of Object.values(r)){if(typeof i!=="object"||i.$ref===void 0)continue;let o=i.__absolute_ref__;if(r[o??i.$ref]===void 0)throw Error(`$ref ${JSON.stringify(i.$ref)} does not resolve`)}let s=(i)=>N(i,n,"2020-12",r,!1);return pt.set(e,s),s}function mt(e,t,n=""){let r=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${r}${n}`)}function gn(e){let t=[];for(let n of e.list())try{Ne(n)}catch(r){e.remove(n),t.push(mt(n.name,r,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Ne(n)}catch(r){throw mt(n.name,r)}}),t}function yt(e){try{return structuredClone(e)}catch{return e}}var hn=new TextEncoder;function L(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function je(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function B(e,t,n,r,s){let i={code:n,message:r};if(s!==void 0)i.data=s;return je(e,{jsonrpc:"2.0",id:t,error:i})}function W(e,t,n){return B(400,e,pn,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function ae(e){return hn.encode(`event: message
7
+ data: ${JSON.stringify(e)}
8
+
9
+ `)}var gt={"content-type":"text/event-stream","cache-control":"no-cache"};function wn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function bn(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let n=atob(t),r=Uint8Array.from(n,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(r)}catch{return}}function $n(e){if(!(Q in e))return{key:Q,problem:"missing"};if(!(xe in e))return{key:xe,problem:"missing"};if(typeof e[Q]!=="string")return{key:Q,problem:"expected a protocol version string"};if(!L(e[xe]))return{key:xe,problem:"expected an object"};let t=e[lt];if(t!==void 0&&!(L(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:lt,problem:"expected {name, version}"};return}function xn(e){let t=e.notifications;return L(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function vn(e,t){let n;try{n=Ne(e)(t)}catch(s){let i=s instanceof Error?s.message:String(s);return`The input schema of tool ${e.name} cannot be used: ${i}`}if(n.valid)return;let r=n.errors.filter((s)=>s.keyword!=="properties"&&s.keyword!=="$ref").map((s)=>`${s.instanceLocation} ${s.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${r||"the arguments do not match the schema"}`}async function ht(e,t,n,r,s,i){let o={id:++yn,tool:t.name,arguments:yt(n),client:{...s}};if(t.title!==void 0)o.title=t.title;let a=Date.now();e.observe?.start(o);let u={outcome:"error",result:se("Internal error")};try{if(u=await kn(e,t,n,r,s),t.annotations.untrustedContentHint===!0)u.result=st(u.result);let y=r.aborted?void 0:i?.(u.result);if(y!==void 0)u={outcome:"error",result:y}}finally{e.observe?.end({id:o.id,tool:t.name,client:{...s},outcome:u.outcome,result:yt(u.result),durationMs:Date.now()-a})}return u}var Tn="The user was asked and did not answer.";async function kn(e,t,n,r,s){let i=(y,b,_)=>({outcome:y,result:se(b),stop:_}),o=vn(t,n);if(o!==void 0)return i("error",o,"invalid");let a=new Promise((y,b)=>{if(r.aborted)b(r.reason);r.addEventListener("abort",()=>b(r.reason))});if(a.catch(()=>{}),t.annotations.consequentialHint===!0){let y={tool:{name:t.name,description:t.description},arguments:n,client:s,signal:r};if(t.title!==void 0)y.tool.title=t.title;let b=!1;try{b=await Promise.race([e.confirm(y),a])}catch{b=!1}if(b!==!0){if(r.aborted)return i("cancelled","The call was cancelled.","cancelled");return b==="unanswered"?i("unanswered",Tn,"unanswered"):i("declined","The user did not allow this call.","declined")}}if(r.aborted)return i("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return i("error","The tool is no longer available","gone");let u;try{let y=await Promise.race([t.execute(n,{signal:r,client:s}),a]);u={outcome:"ok",result:at(y),returned:{value:y}}}catch(y){u={outcome:"error",result:ut(y)}}if(r.aborted)return{...u,outcome:"cancelled",stop:"cancelled"};if(u.result.isError===!0)u.outcome="error";return u}async function qe(e,t,n,r,s){let i=(u)=>({error:u}),o=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return i(o);if(!L(n))return i("The input must be an object.");let a=await ht(e,t,n,r instanceof AbortSignal?r:new AbortController().signal,s);if(a.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(a.stop==="declined")return i(`The user did not allow ${t.name} to run.`);if(a.stop==="unanswered")return i(`The user did not answer whether ${t.name} may run.`);if(a.stop==="gone")return i(o);if(a.result.isError===!0)return i(Oe(a.result)||"The tool failed.");return dt(a.returned?.value)}function ve(e){let{tools:t,server:n}=e,r={name:n.name,version:n.version};if(n.title!==void 0)r.title=n.title;let s=Se(n.icons??[]),i=s.length>0?{...r,icons:s}:r,o=new Set,a=!1,u=(f={})=>({...f,[ft]:r});function y(f,g,h=u()){return{jsonrpc:"2.0",id:f,result:{...g,resultType:"complete",_meta:h}}}function b(){return t.list().map((f)=>{let g={name:f.name};if(f.title!==void 0)g.title=f.title;if(g.description=f.annotations.consequentialHint===!0&&!e.ownConfirm?`${f.description} ${mn}`:f.description,g.inputSchema=f.inputSchema,f.outputSchema!==void 0)g.outputSchema=f.outputSchema;let{annotations:h,meta:v}=ot(f.annotations);if(h!==void 0)g.annotations=h;if(v!==void 0)g._meta={[rt]:v};return g})}let _=(f)=>({kind:"invalid",message:f});async function A(f,g,h,v){let w=f.name;if(typeof w!=="string")return _("Invalid params: name must be a string");let R=t.get(w);if(R===void 0)return _(`Tool ${w} not found`);let S=f.arguments??{};if(!L(S))return _("Invalid params: arguments must be an object");return{kind:"result",result:(await ht(e,R,S,g,e.client(h),v)).result}}function D(f,g,h,v){let w=(d)=>ae(y(f,d,u(d._meta))),R,S=(d)=>{let M;try{M=w(d)}catch{return se("The tool returned a result that is not JSON.")}let q=e.maxBodyBytes?.();if(q!==void 0&&M.byteLength>q)return se(`The result is ${M.byteLength} bytes; the relay passes on at most ${q}.`);R={result:d,event:M};return},E=new ReadableStream({start:(d)=>{let M=(q)=>{if(h.aborted)return;try{d.enqueue(q()),d.close()}catch{}};A(g,h,v,S).then((q)=>M(()=>q.kind==="invalid"?ae({jsonrpc:"2.0",id:f,error:{code:-32602,message:q.message}}):q.result===R?.result?R.event:w(q.result)),()=>M(()=>ae({jsonrpc:"2.0",id:f,error:{code:-32603,message:"Internal error"}})))}});return new Response(E,{status:200,headers:gt})}function C(f,g,h){let v=xn(g),w={jsonrpc:"2.0",id:f,result:{resultType:"complete",_meta:u({[Pe]:f})}},R,S=new ReadableStream({start:(E)=>{if(E.enqueue(ae({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:v,_meta:{[Pe]:f}}})),Object.keys(v).length===0){E.enqueue(ae(w)),E.close();return}let d={id:f,send:(M)=>{try{E.enqueue(ae(M))}catch{o.delete(d)}},end:()=>{o.delete(d);try{E.enqueue(ae(w)),E.close()}catch{}}};R=d,o.add(d),h.addEventListener("abort",()=>{o.delete(d);try{E.close()}catch{}})},cancel:()=>{if(R!==void 0)o.delete(R)}});return new Response(S,{status:200,headers:gt})}function O(f,g){if(Array.isArray(g))return B(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!L(g)||g.jsonrpc!=="2.0")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:h,id:v}=g;if(typeof h!=="string")return"result"in g||"error"in g?B(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let w=f.headers.get("mcp-protocol-version"),R=f.headers.get("mcp-method"),S=L(g.params)?g.params:{},E=L(S._meta)?S._meta:void 0,d=E!==void 0&&Q in E,M=typeof E?.[Q]==="string"?E[Q]:void 0,q=w!==null&&w>=ie;if(v===void 0){if(M!==void 0&&w!==null&&w!==M)return W(null,w,`the notification envelope names protocol version ${M} but the MCP-Protocol-Version header names ${w}`);if((d||q)&&R!==null&&R!==h)return W(null,R,`the notification body names method ${h} but the Mcp-Method header names ${R}`);return"notification"}if(typeof v!=="string"&&typeof v!=="number")return B(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let H=v;if(!d||h==="initialize"&&(M===void 0||M<ie)){if(h==="initialize"){if(q)return W(H,w,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let V=typeof S.protocolVersion==="string"?S.protocolVersion:void 0;return j(H,V)}if(q){let V=E===void 0?["_meta"]:[Q];return B(400,H,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${w}, but the request is missing the required per-request envelope key(s): ${V.join(", ")}`,{envelope:{missing:V}})}return j(H,w??void 0)}let X=$n(E);if(X!==void 0)return B(400,H,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${X.key}: ${X.problem}`,{envelope:X});if(w!==null&&M!==void 0&&w!==M)return W(H,w,`the body envelope names protocol version ${M} but the MCP-Protocol-Version header names ${w}`);if(R!==null&&R!==h)return W(H,R,`the body names method ${h} but the Mcp-Method header names ${R}`);if(M!==ie)return j(H,M);if(w===null)return W(H,"(missing)",`the body envelope names protocol version ${M} but the required MCP-Protocol-Version header is absent`);if(R===null)return W(H,"(missing)",`the body names method ${h} but the required Mcp-Method header is absent`);if(h==="tools/call"&&typeof S.name==="string"){let V=S.name,ee=f.headers.get("mcp-name");if(ee===null)return W(H,"(missing)",`the body carries params.name="${V}" but the required Mcp-Name header is absent`);let te=bn(ee);if(te===void 0)return W(H,ee,"the Mcp-Name header carries an invalid Base64 sentinel value");if(te!==V)return W(H,ee,`the body carries params.name="${V}" but the Mcp-Name header names "${te}"`)}return{id:H,method:h,params:S}}function j(f,g){return g===void 0?B(400,f,ct,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):B(400,f,ct,`Unsupported protocol version: ${g}`,{supported:[ie],requested:g})}async function U(f,g){if(f.method.toUpperCase()!=="POST")return B(405,null,-32000,"Method not allowed.");if(!wn(f.headers.get("content-type")))return B(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let h;try{h=JSON.parse(g.body??await f.text())}catch{return B(400,null,-32700,"Parse error: the request body is not valid JSON")}let v=O(f,h);if(v instanceof Response)return v;if(v==="notification")return new Response(null,{status:202});let{id:w,method:R,params:S}=v;switch(R){case"server/discover":{let E={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)E.instructions=n.instructions;return E.ttlMs=0,E.cacheScope="private",je(200,y(w,E,{[ft]:i}))}case"tools/list":return je(200,y(w,{tools:b(),ttlMs:0,cacheScope:"private"}));case"tools/call":return D(w,S,f.signal,g.grant);case"subscriptions/listen":return C(w,S,f.signal);default:return B(404,w,-32601,"Method not found")}}return{handle:(f,g)=>U(f,g).catch(()=>B(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let f of[...o])f.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Pe]:f.id}}})})},close(){for(let f of[...o])f.end()}}}var Te="tab-mcp.v1",Rn=new Set(["start","used","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var P=(e)=>typeof e==="string";function wt(e){if(!fe(e)||!P(e.grantId)||!P(e.createdAt))return!1;let t=e.client;return fe(t)&&P(t.id)&&P(t.name)&&P(t.host)}function In(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Mn(e){return fe(e)&&Object.values(e).every(P)}function bt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return P(t.sessionId)&&P(t.address)&&P(t.origin)&&P(t.expiresAt)&&In(t.limits)&&Array.isArray(t.grants)&&t.grants.every(wt)&&(t.appName===void 0||P(t.appName))&&(t.pairing===void 0||P(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:P(t.reason)?t.reason:""};case"http.request":return P(t.id)&&P(t.method)&&P(t.path)&&Mn(t.headers)&&P(t.body)&&fe(t.grant)&&P(t.grant.grantId)&&P(t.grant.clientId)?t:void 0;case"http.cancel":return P(t.id)?t:void 0;case"pairing.code":{if(!P(t.code)||!P(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},r=t.reason;if(typeof r==="string"&&Rn.has(r))n.reason=r;return n}case"pairing.open":{let n=t.expiresInMs;if(typeof n==="number"&&Number.isFinite(n)&&n>=0&&n<=2147483647)return{type:"pairing.open",expiresAt:new Date(Date.now()+n).toISOString()};return P(t.expiresAt)&&!Number.isNaN(Date.parse(t.expiresAt))?{type:"pairing.open",expiresAt:t.expiresAt}:void 0}case"grant.added":return wt(t.grant)?t:void 0;case"grant.removed":return P(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:P(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return P(t.code)?t:void 0;default:return}}function _n(e,t){let n=(r)=>r&&(r.callers?.includes(t)??!0);return{list:()=>e.list().filter(n),get:(r)=>{let s=e.get(r);return n(s)?s:void 0}}}function Be(e,t,n){let r=t.list();return e.onChange(()=>{let s=t.list();if(s.length===r.length&&s.every((i,o)=>i===r[o]))return;r=s,n()})}function ke(e,t){return{tools:t==="webmcp"?e.registry:_n(e.registry,t),confirm:(n)=>e.confirm(n),ownConfirm:e.ownConfirm(),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}}var Cn=["content-type","cache-control"];function*De(e,t){let n=0;while(n<e.length){let r=Math.min(n+t,e.length),s=e.charCodeAt(r-1);if(r<e.length&&s>=55296&&s<=56319)r+=r-1>n?-1:1;yield e.slice(n,r),n=r}}var En=-31002,Sn="The page did not answer in time.";function An(e){try{let t=JSON.parse(e)?.id;return typeof t==="string"||typeof t==="number"?t:null}catch{return null}}function Je(e){let{handler:t,send:n,timeoutMs:r}=e,s=new Map,i=!1;async function o(a){let u=new AbortController;s.get(a.id)?.abort(),s.set(a.id,u);let y=()=>!i&&s.get(a.id)===u&&!u.signal.aborted,b=!1,_="",A=Object.entries(a.headers).some(([C,O])=>C.toLowerCase()==="mcp-method"&&O==="subscriptions/listen"),D=r===void 0||A?void 0:setTimeout(()=>{if(!y())return;u.abort();let C=JSON.stringify({jsonrpc:"2.0",id:An(a.body),error:{code:En,message:Sn}});if(!b){n({type:"http.response",id:a.id,status:200,headers:{"content-type":"application/json"},body:C});return}if(_===""||_===`
10
+
11
+ `)n({type:"http.response.chunk",id:a.id,data:`event: message
12
+ data: ${C}
13
+
14
+ `});n({type:"http.response.end",id:a.id})},r);try{let C=new Request(`https://tab.invalid${a.path}`,{method:a.method,headers:a.headers,signal:u.signal}),O=await t.handle(C,{grant:a.grant,body:a.body});if(!y()){await O.body?.cancel().catch(()=>{});return}let j={};for(let v of Cn){let w=O.headers.get(v);if(w!==null)j[v]=w}let U=(j["content-type"]??"").startsWith("text/event-stream"),f=e.maxChunk();if(!U||O.body===null){let v=await O.text();if(!y())return;if(v.length<=f){n({type:"http.response",id:a.id,status:O.status,headers:j,body:v});return}n({type:"http.response.start",id:a.id,status:O.status,headers:j});for(let w of De(v,f)){if(!y())break;n({type:"http.response.chunk",id:a.id,data:w})}if(y())n({type:"http.response.end",id:a.id});return}n({type:"http.response.start",id:a.id,status:O.status,headers:j}),b=!0;let g=O.body.getReader(),h=new TextDecoder;u.signal.addEventListener("abort",()=>{g.cancel().catch(()=>{})});for(;;){let{done:v,value:w}=await g.read();if(v||!y())break;let R=h.decode(w,{stream:!0});if(R!=="")_=(_+R).slice(-2);for(let S of De(R,f))n({type:"http.response.chunk",id:a.id,data:S})}if(y())n({type:"http.response.end",id:a.id})}catch(C){if(y())e.error(C instanceof Error?C:Error(String(C))),n({type:"http.response",id:a.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(clearTimeout(D),s.get(a.id)===u)s.delete(a.id)}}return{request(a){if(!i)o(a)},cancel(a){s.get(a)?.abort(),s.delete(a)},close(){if(i)return;i=!0;for(let a of s.values())a.abort();s.clear()}}}var On=65536,$t=64,Pn=300000,xt=128,He=new WeakSet,Nn=0,F=(e)=>typeof e==="string";function ze(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function jn(e,t,n){let r=n?.client;if(!ze(r)||!F(r.id)||r.id===""||r.name!==void 0&&!F(r.name))throw TypeError("serve: client needs an id (and may have a name)");let s=n.maxChunk??On;if(!Number.isInteger(s)||s<$t)throw TypeError(`serve: maxChunk must be a whole number of at least ${$t}`);let i=n.requestTimeoutMs??Pn;if(typeof i!=="number"||!(i>0)||i>=2147483648)throw TypeError("serve: requestTimeoutMs must be milliseconds above 0 and below 2^31");let o=n.onConfirm;if(o!==void 0&&typeof o!=="function")throw TypeError("serve: onConfirm must be a function");if(typeof t?.postMessage!=="function"||!("onmessage"in t))throw TypeError("serve: the port needs postMessage and onmessage");if(He.has(t))throw new DOMException("serve: this port is served already; close that first","InvalidStateError");let a={kind:"local",id:r.id};if(r.name!==void 0&&r.name!=="")a.name=r.name;let u={grantId:`local:${++Nn}`,clientId:r.id,scopes:["tools"]},y=!1,b=(g)=>{if(y)return!1;try{return t.postMessage(g),!0}catch{return!1}},_=ke(e,"local");if(o!==void 0)_.confirm=(g)=>Promise.resolve().then(()=>o(g)).then((h)=>h==="unanswered"?h:h===!0),_.ownConfirm=!0;let A=ve({..._,server:{...e.server,icons:e.server.icons??be()},client:()=>({...a})}),D=Be(e.registry,_.tools,()=>A.toolsChanged()),C=Je({handler:A,send:b,maxChunk:()=>s,error:(g)=>e.error(g),timeoutMs:i}),O=(g,h)=>{let v={type:"error",code:"bad_message",message:g};if(F(h)&&h.length<=xt)v.id=h;b(v)},j=(g)=>{if(y)return;let h=g?.data;if(!ze(h)||!F(h.type)){O("not a message");return}let v=h.id;switch(h.type){case"http.request":{let{method:w,path:R,headers:S,body:E}=h;if(!F(v)||v===""||v.length>xt||!F(w)||!F(R)||!R.startsWith("/")||!ze(S)||!Object.values(S).every(F)||!F(E)){O("malformed http.request",v);return}C.request({type:"http.request",id:v,method:w,path:R,headers:S,body:E,grant:u});return}case"http.cancel":if(F(v))C.cancel(v);else O("malformed http.cancel");return;case"error":return;default:O(`unexpected ${h.type.slice(0,64)}`,v)}},U=t,f=()=>{if(y)return;if(n.signal?.removeEventListener("abort",f),U.removeEventListener?.("close",f),D(),C.close(),A.close(),He.delete(t))b({type:"bye",reason:"closed"});if(y=!0,t.onmessage===j)t.onmessage=null};if(n.signal?.aborted===!0)return f(),{close:f};return n.signal?.addEventListener("abort",f),U.addEventListener?.("close",f),He.add(t),t.onmessage=j,{close:f}}function qn(e){let t="",n=0,r=0;for(let s of e){n=n<<8|s,r+=8;while(r>=5)r-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>r&31];n&=(1<<r)-1}if(r>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-r&31];return t}async function Hn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return qn(new Uint8Array(n))}catch{return}}function wr(e,t,n,r,s){let i=ke(e,"webmcp");return s===void 0?qe(i,t,n,r,{kind:"webmcp"}):qe({...i,confirm:()=>Promise.resolve(!0)},t,n,r,{kind:"webmcp",via:"tab-mcp-extension",name:s.name,host:s.host})}var zn=15000,vt={1000:"closed",1001:"shutdown",1008:"policy",1009:"too_large",1011:"shutdown",1012:"shutdown",1013:"shutdown",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},Tt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var kt=512,Rt=6,It=64,Dn=kt+Rt*It;function Bn(e){let t=Math.floor((e-kt)/Rt);return t>=It?t:void 0}var Jn=1e4,Un=1000;function Vn(e,t){let n,r=!1,s=Number.NEGATIVE_INFINITY,i;try{if(e!==void 0&&typeof BroadcastChannel==="function")n=new BroadcastChannel(e),n.onmessage=(o)=>{let a=o.data;if(!r||a?.type!=="claimed"||a.address!==void 0&&a.address!==t)return;s=Date.now(),i?.()}}catch{n=void 0}return{claimed(){r=!0;try{n?.postMessage({type:"claimed",address:t})}catch{}},heard(){if(Date.now()-s<=Jn)return Promise.resolve(!0);if(n===void 0)return Promise.resolve(!1);return new Promise((o)=>{let a=setTimeout(()=>o(!1),Un);i=()=>{clearTimeout(a),o(!0)}})},close(){n?.close()}}}function br(e,t,n,r,s){return new Promise((i,o)=>{let a=["grantschange","statechange","error"],u=(_)=>{clearTimeout(b);for(let A of a)e.removeEventListener(A,y);if(_)o(_);else i()},y=(_)=>{let A=_?.detail?.error;if(n())u();else if((A?.code==="store_unavailable"||A?.code==="unknown_id")&&(A.for===void 0||A.for===t.type&&A.grantId===t.grantId))u(A);else if(!r())u(new DOMException("TabMcp: the session ended before the relay answered","NetworkError"))},b=setTimeout(()=>u(new DOMException("TabMcp: the relay did not answer","TimeoutError")),s);for(let _ of a)e.addEventListener(_,y);y()})}function $r(e){let t=globalThis,n=globalThis.document,r=()=>{if(n?.visibilityState!=="hidden")e()};return n?.addEventListener("visibilitychange",r),t.addEventListener?.("online",e),()=>{n?.removeEventListener("visibilitychange",r),t.removeEventListener?.("online",e)}}function xr(e,t,n,r={}){let s=r.revokeAll===!0,i=new WebSocket(t,Te),o="opening",a,u=65536,y,b,_=0,A=Vn(e.tabs,r.address),D,C,O=new Promise((d,M)=>{D=d,C=M});O.catch(()=>{});let j=setTimeout(()=>{w(de("The relay did not answer in time.","network"))},zn),U=ke(e,"relay"),f=ve({...U,server:{...e.server,icons:e.server.icons??be()},client:(d)=>e.clientFor(d),maxBodyBytes:()=>y}),g=Be(e.registry,U.tools,()=>f.toolsChanged());function h(d){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(d)),!0}catch{return!1}}function v(){if(_<=0)return;clearTimeout(b),b=setTimeout(()=>{a??="heartbeat",R(4003);try{i.close()}catch{}},_*2.5)}function w(d){if(o!=="opening")return;R(0),C(d);try{i.close()}catch{}}function R(d){if(o==="closed")return;let M=o==="ready";if(o="closed",clearTimeout(j),clearTimeout(b),g(),S.close(),f.close(),M){let q=a??vt[d]??(d===1006?"network":"closed");if(e.closed(q,d),q==="replaced"){A.heard().then((H)=>{A.close(),e.replaced({sibling:H})});return}}A.close()}let S=Je({handler:f,send:h,maxChunk:()=>u,error:(d)=>e.error(d)});function E(d){if(o==="opening"){if(d.type==="session"){let M=Bn(d.limits.maxMessageBytes);if(M===void 0){w(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Dn}.`,"policy"));return}if(s&&d.grants.length>0){w(de("The relay did not revoke the address's grants (it needs tab-mcp 0.5 or later).","policy"));return}u=M,y=d.limits.maxBodyBytes,o="ready",clearTimeout(j),_=d.limits.heartbeatMs,v(),A.claimed(),D(e.sessionStarted(d))}else if(d.type==="error")w(de(`The relay refused the connection: ${d.message||d.code}`,d.code==="rate_limited"?"rate_limited":"policy"));else if(d.type==="bye")w(de(`The relay ended the connection: ${d.reason}`,Tt[d.reason]??"closed"));return}if(o!=="ready")return;switch(d.type){case"ping":v(),h({type:"pong",t:d.t});return;case"http.request":S.request(d);return;case"http.cancel":S.cancel(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"pairing.open":e.pairingOpen(d.expiresAt);return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":e.grantRemoved(d.grantId);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(a=Tt[d.reason]??"closed",a==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}if(d.code==="unknown_id"&&d.for==="grant.revoke"&&typeof d.grantId==="string")e.grantRemoved(d.grantId);e.error(Object.assign(Error(`Relay error ${d.code}: ${d.message}`),{code:d.code},typeof d.for==="string"?{for:d.for}:{},typeof d.grantId==="string"?{grantId:d.grantId}:{}));return;case"session":return}}return i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==Te){w(de(`The relay speaks ${i.protocol}, not ${Te}.`,"policy"));return}h({type:"hello",library:e.library,app:e.appName===void 0?{id:e.app}:{id:e.app,name:e.appName},secret:n,...s?{revokeAll:!0}:{}})}),i.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let M=bt(d.data);if(M===void 0)return;if(o==="ready")v();E(M)}),i.addEventListener("close",(d)=>{if(o==="opening"){R(d.code);let M=d.code===1006||d.code===1002;C(de(M?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${d.code}${d.reason?`: ${d.reason}`:""}).`,vt[d.code]??(M?"network":"closed")));return}R(d.code)}),{ready:O,send:h,close(d){if(o==="closed")return;if(o==="opening"){w(new DOMException("The connection was cancelled","AbortError"));return}a=d,h({type:"bye",reason:"user"}),R(1000);try{i.close(1000,"bye")}catch{}}}}export{Dn as MIN_MESSAGE_BYTES,Un as SIBLING_GRACE_MS,Jn as SIBLING_WINDOW_MS,Hn as addressIdOf,br as answer,wr as callFromWebMcp,Bn as chunkSize,gn as compileRegistry,$r as onWake,xr as openConnection,De as pieces,jn as servePort};
15
+
16
+ //# debugId=3578394AFE2A6D2164756E2164756E21
17
+ //# sourceMappingURL=connection-yf2x9zz2.min.js.map