@ractive-ch/tab-mcp-client 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -5
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +2 -2
- package/cdn/ui-dv7pxk0b.min.js +4 -0
- package/cdn/ui-dv7pxk0b.min.js.map +10 -0
- package/index.js +5 -5
- package/index.js.map +2 -2
- package/package.json +1 -1
- package/{ui-wrm46a0a.js → ui-g1k2g5hm.js} +94 -19
- package/ui-g1k2g5hm.js.map +10 -0
- package/ui.d.ts +4 -2
- package/version.d.ts +1 -1
- package/cdn/ui-zmrhb8xg.min.js +0 -4
- package/cdn/ui-zmrhb8xg.min.js.map +0 -10
- package/ui-wrm46a0a.js.map +0 -10
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ relay. The page connects to the relay and gets an address. The user adds that ad
|
|
|
6
6
|
their AI app and types a pairing code from the page; the AI app then calls the page's
|
|
7
7
|
tools while the tab stays open. Nothing is installed on the user's computer.
|
|
8
8
|
|
|
9
|
-
**Status: 0.
|
|
9
|
+
**Status: 0.3.0.** Until 1.0, a new minor version can still change the API. Which AI apps
|
|
10
10
|
work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
|
|
11
11
|
|
|
12
12
|
## You need a relay
|
|
@@ -22,7 +22,7 @@ docker run --rm -p 8080:8080 \
|
|
|
22
22
|
-e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
|
|
23
23
|
-e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
|
|
24
24
|
-e TAB_MCP_STORE=memory \
|
|
25
|
-
ractive/tab-mcp:0.1
|
|
25
|
+
ractive/tab-mcp:0.2.1
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
For production, see
|
|
@@ -38,7 +38,7 @@ Or without a bundler, from a CDN as an ES module:
|
|
|
38
38
|
|
|
39
39
|
```html
|
|
40
40
|
<script type="module">
|
|
41
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
41
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.3.0/cdn/tab-mcp-client.min.js";
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -116,8 +116,15 @@ const mcp = new TabMcp({
|
|
|
116
116
|
2. The dialog shows the address and short instructions for Claude, ChatGPT and Claude
|
|
117
117
|
Code. The user adds the address to their AI app.
|
|
118
118
|
3. The AI app opens the relay's sign-in page in the browser. The dialog shows a 6-digit
|
|
119
|
-
code, which the user types there. The code changes every
|
|
120
|
-
|
|
119
|
+
code with a Copy button, which the user types or pastes there. The code changes every
|
|
120
|
+
2 minutes and after each use.
|
|
121
|
+
4. The dialog announces and lists the connected app with a Disconnect button, and shows
|
|
122
|
+
"Done" to close it.
|
|
123
|
+
|
|
124
|
+
Until an app connects, the dialog offers no prominent button under the code: only a small
|
|
125
|
+
"Close" at the bottom (and Escape). Closing it stops the code (`stopPairing()`); the page
|
|
126
|
+
stays connected and the address stays the same, so calling `showConnectDialog()` again
|
|
127
|
+
shows the same address with a new code.
|
|
121
128
|
|
|
122
129
|
The address stays the same across visits: the library keeps a secret per relay in
|
|
123
130
|
`localStorage`. "New address" in the dialog calls `newAddress()`, which disconnects every
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var b,g,u,p=(e,n)=>{for(var[t,o,i]of b||[])for(var r=[e],a=globalThis,s=a.document,c,h,f,d,l;h=r.pop();)if(!g[h]&&(f=o[h])){g[h]=1;for(d=1;d<f.length;d++)r.push(i[f[d]]);if(!n&&h!==e&&(c=s&&s.head)){if(u===void 0)u=(d=s.querySelector("meta[property=csp-nonce]"))&&(d.nonce||d.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",u)l.nonce=u;l.href=new a.URL(f[0],t),c.appendChild(l)}}},O=(e,n,t,o)=>{for(var i={},r=0;r<n.length;r++)i[n[r]]=t[r];(b||=[]).push([e,i,n]),g||={},p(n[o],1)};O(import.meta.url,["
|
|
2
|
-
class m{#e=new Map;has(e,n){return this.#e.get(e)?.has(n)===!0}add(e,n){let t=this.#e.get(e)??new Set;t.add(n),this.#e.set(e,t)}keepGrants(e){let n=new Set(e);for(let t of this.#e.keys())if(!n.has(t))this.#e.delete(t)}keepTools(e){let n=new Set(e);for(let t of this.#e.values())for(let o of t)if(!n.has(o))t.delete(o)}}var A=/^[A-Za-z0-9_.-]{1,128}$/;function y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function S(e,n=0){if(n>64||typeof e!=="object"||e===null)return!1;if(!Array.isArray(e)&&"x-mcp-header"in e)return!0;return Object.values(e).some((t)=>S(t,n+1))}function R(e,n){let t=e;for(let o of n.split("/").slice(1)){let i=decodeURIComponent(o).replaceAll("~1","/").replaceAll("~0","~");if(typeof t!=="object"||t===null||!Object.hasOwn(t,i))return;t=t[i]}return t}function M(e){let n=new Set,t=[],o=[],i=(r,a)=>{if(a>64||typeof r!=="object"||r===null)return;if(!Array.isArray(r)){let s=r;if(typeof s.$anchor==="string")n.add(s.$anchor);if(typeof s.$ref==="string")t.push(s.$ref);if(typeof s.pattern==="string")o.push(s.pattern);let c=s.patternProperties;if(typeof c==="object"&&c!==null)o.push(...Object.keys(c))}for(let s of Object.values(r))i(s,a+1)};i(e,0);for(let r of o)try{new RegExp(r,"u")}catch{return`pattern ${JSON.stringify(r)} is not a valid regular expression`}for(let r of t){if(!r.startsWith("#"))return`$ref ${JSON.stringify(r)} points outside the schema`;let a=r.slice(1);if(!(a===""||(a.startsWith("/")?R(e,a)!==void 0:n.has(a))))return`$ref ${JSON.stringify(r)} does not resolve`}return}function I(e){if(!y(e))throw TypeError("registerTool: the tool must be an object");let{name:n,title:t,description:o,inputSchema:i,execute:r,annotations:a}=e;if(typeof n!=="string"||!A.test(n))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(n)})`);if(typeof o!=="string"||o.trim()==="")throw TypeError(`registerTool: tool ${n} needs a description`);if(t!==void 0&&typeof t!=="string")throw TypeError(`registerTool: the title of ${n} must be a string`);if(typeof r!=="function")throw TypeError(`registerTool: tool ${n} needs an execute function`);let s=i??{type:"object"};if(!y(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${n} must be a JSON Schema object with "type": "object"`);if(S(s))throw TypeError(`registerTool: ${n} uses x-mcp-header, which tab-mcp does not support`);let c=M(s);if(c!==void 0)throw TypeError(`registerTool: the inputSchema of ${n}: ${c}`);let h;try{h=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${n} must be JSON`)}if(a!==void 0&&!y(a))throw TypeError(`registerTool: the annotations of ${n} must be an object`);let f={};for(let[d,l]of Object.entries(a??{}))if(typeof l==="boolean")f[d]=l;return{name:n,title:t,description:o,inputSchema:h,annotations:f,execute:r}}class v{#e=new Map;#r=new Set;register(e,n={}){let t=I(e),{signal:o}=n;if(o?.aborted)return;if(this.#e.has(t.name))throw new DOMException(`registerTool: a tool named ${t.name} is already registered`,"InvalidStateError");this.#e.set(t.name,t),o?.addEventListener("abort",()=>{if(this.#e.get(t.name)===t)this.#e.delete(t.name),this.#i()},{once:!0}),this.#i()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#r.add(e),()=>this.#r.delete(e)}#i(){for(let e of[...this.#r])e()}}var x=/^[A-Za-z0-9_-]{43}$/;function L(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function k(){return L(crypto.getRandomValues(new Uint8Array(32)))}function P(e){return typeof e==="string"&&x.test(e)}function N(){try{return globalThis.localStorage??null}catch{return null}}class w{#e;#r;#i;constructor(e,n){this.#e=e===void 0?N():e,this.#r=n}get(){let e=null;try{e=this.#e?.getItem(this.#r)??null}catch{}if(P(e))return this.#i=e,e;return this.#i??this.rotate()}rotate(){let e=k();this.#i=e;try{this.#e?.setItem(this.#r,e)}catch{}return e}}var E="@ractive-ch/tab-mcp-client",T="0.
|
|
1
|
+
var b,g,u,p=(e,n)=>{for(var[t,o,i]of b||[])for(var r=[e],a=globalThis,s=a.document,c,h,f,d,l;h=r.pop();)if(!g[h]&&(f=o[h])){g[h]=1;for(d=1;d<f.length;d++)r.push(i[f[d]]);if(!n&&h!==e&&(c=s&&s.head)){if(u===void 0)u=(d=s.querySelector("meta[property=csp-nonce]"))&&(d.nonce||d.getAttribute("nonce"))||"";if(l=s.createElement("link"),l.rel="modulepreload",l.crossOrigin="",u)l.nonce=u;l.href=new a.URL(f[0],t),c.appendChild(l)}}},O=(e,n,t,o)=>{for(var i={},r=0;r<n.length;r++)i[n[r]]=t[r];(b||=[]).push([e,i,n]),g||={},p(n[o],1)};O(import.meta.url,["c08b1fs0","5ehqkmw1","dv7pxk0b"],[["./tab-mcp-client.min.js"],["./connection-5ehqkmw1.min.js"],["./ui-dv7pxk0b.min.js"]],0);
|
|
2
|
+
class m{#e=new Map;has(e,n){return this.#e.get(e)?.has(n)===!0}add(e,n){let t=this.#e.get(e)??new Set;t.add(n),this.#e.set(e,t)}keepGrants(e){let n=new Set(e);for(let t of this.#e.keys())if(!n.has(t))this.#e.delete(t)}keepTools(e){let n=new Set(e);for(let t of this.#e.values())for(let o of t)if(!n.has(o))t.delete(o)}}var A=/^[A-Za-z0-9_.-]{1,128}$/;function y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function S(e,n=0){if(n>64||typeof e!=="object"||e===null)return!1;if(!Array.isArray(e)&&"x-mcp-header"in e)return!0;return Object.values(e).some((t)=>S(t,n+1))}function R(e,n){let t=e;for(let o of n.split("/").slice(1)){let i=decodeURIComponent(o).replaceAll("~1","/").replaceAll("~0","~");if(typeof t!=="object"||t===null||!Object.hasOwn(t,i))return;t=t[i]}return t}function M(e){let n=new Set,t=[],o=[],i=(r,a)=>{if(a>64||typeof r!=="object"||r===null)return;if(!Array.isArray(r)){let s=r;if(typeof s.$anchor==="string")n.add(s.$anchor);if(typeof s.$ref==="string")t.push(s.$ref);if(typeof s.pattern==="string")o.push(s.pattern);let c=s.patternProperties;if(typeof c==="object"&&c!==null)o.push(...Object.keys(c))}for(let s of Object.values(r))i(s,a+1)};i(e,0);for(let r of o)try{new RegExp(r,"u")}catch{return`pattern ${JSON.stringify(r)} is not a valid regular expression`}for(let r of t){if(!r.startsWith("#"))return`$ref ${JSON.stringify(r)} points outside the schema`;let a=r.slice(1);if(!(a===""||(a.startsWith("/")?R(e,a)!==void 0:n.has(a))))return`$ref ${JSON.stringify(r)} does not resolve`}return}function I(e){if(!y(e))throw TypeError("registerTool: the tool must be an object");let{name:n,title:t,description:o,inputSchema:i,execute:r,annotations:a}=e;if(typeof n!=="string"||!A.test(n))throw TypeError(`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, "_", "-" or "." (got ${JSON.stringify(n)})`);if(typeof o!=="string"||o.trim()==="")throw TypeError(`registerTool: tool ${n} needs a description`);if(t!==void 0&&typeof t!=="string")throw TypeError(`registerTool: the title of ${n} must be a string`);if(typeof r!=="function")throw TypeError(`registerTool: tool ${n} needs an execute function`);let s=i??{type:"object"};if(!y(s)||s.type!=="object")throw TypeError(`registerTool: the inputSchema of ${n} must be a JSON Schema object with "type": "object"`);if(S(s))throw TypeError(`registerTool: ${n} uses x-mcp-header, which tab-mcp does not support`);let c=M(s);if(c!==void 0)throw TypeError(`registerTool: the inputSchema of ${n}: ${c}`);let h;try{h=JSON.parse(JSON.stringify(s))}catch{throw TypeError(`registerTool: the inputSchema of ${n} must be JSON`)}if(a!==void 0&&!y(a))throw TypeError(`registerTool: the annotations of ${n} must be an object`);let f={};for(let[d,l]of Object.entries(a??{}))if(typeof l==="boolean")f[d]=l;return{name:n,title:t,description:o,inputSchema:h,annotations:f,execute:r}}class v{#e=new Map;#r=new Set;register(e,n={}){let t=I(e),{signal:o}=n;if(o?.aborted)return;if(this.#e.has(t.name))throw new DOMException(`registerTool: a tool named ${t.name} is already registered`,"InvalidStateError");this.#e.set(t.name,t),o?.addEventListener("abort",()=>{if(this.#e.get(t.name)===t)this.#e.delete(t.name),this.#i()},{once:!0}),this.#i()}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}onChange(e){return this.#r.add(e),()=>this.#r.delete(e)}#i(){for(let e of[...this.#r])e()}}var x=/^[A-Za-z0-9_-]{43}$/;function L(e){return btoa(String.fromCharCode(...e)).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"")}function k(){return L(crypto.getRandomValues(new Uint8Array(32)))}function P(e){return typeof e==="string"&&x.test(e)}function N(){try{return globalThis.localStorage??null}catch{return null}}class w{#e;#r;#i;constructor(e,n){this.#e=e===void 0?N():e,this.#r=n}get(){let e=null;try{e=this.#e?.getItem(this.#r)??null}catch{}if(P(e))return this.#i=e,e;return this.#i??this.rotate()}rotate(){let e=k();this.#i=e;try{this.#e?.setItem(this.#r,e)}catch{}return e}}var E="@ractive-ch/tab-mcp-client",T="0.3.0";var j=new Set(["localhost","127.0.0.1","[::1]"]);function D(e){return typeof e==="string"&&e.trim().length>0&&e.length<=64&&![...e].some((n)=>{let t=n.codePointAt(0)??0;return t<32||t>=127&&t<=159})}function J(e){let n;try{n=new URL(e)}catch{throw TypeError(`TabMcp: relay is not a URL: ${e}`)}let t=n.protocol==="https:"||n.protocol==="wss:";if(!t&&n.protocol!=="http:"&&n.protocol!=="ws:")throw TypeError(`TabMcp: relay must be an https: or wss: URL: ${e}`);if(!t&&!j.has(n.hostname))throw TypeError(`TabMcp: relay must use https: or wss: (http: only for localhost): ${e}`);let o=`${t?"https:":"http:"}//${n.host}`,i=n.pathname.replace(/\/+$/,"");return n.protocol=t?"wss:":"ws:",n.pathname=i.endsWith("/tab")?i:`${i}/tab`,n.search="",n.hash="",{url:n.href,origin:o}}function K(e){try{return new URL(e).host}catch{return""}}function G(e){let n={sessionId:e.sessionId,address:e.address,origin:e.origin,expiresAt:e.expiresAt,limits:e.limits};if(e.appName!==void 0)n.appName=e.appName;return n}class C extends EventTarget{#e=new v;#r;#i;#u;#v;#w;#p;#t="disconnected";#s;#d=[];#h=new m;#c=!1;#g;#n;#a;#m=0;constructor(e){super();let{url:n,origin:t}=J(e.relay),{server:o,appName:i}=e;if(typeof o?.name!=="string"||typeof o.version!=="string")throw TypeError("TabMcp: server needs a name and a version");if(i!==void 0&&!D(i))throw TypeError("TabMcp: appName must be 1-64 characters without control characters");this.#w=n,this.#r={...o},this.#i=i,this.#u=e.onConfirm,this.#v=e.confirmDelayMs,this.#p=new w(e.storage,e.storageKey??`tab-mcp:secret:${t}`),this.#e.onChange(()=>{let r=this.tools;this.#h.keepTools(r),this.#o("toolschange",{tools:r})})}registerTool(e,n={}){try{this.#e.register(e,n)}catch(t){return Promise.reject(t)}return Promise.resolve()}get tools(){return this.#e.list().map((e)=>e.name)}get state(){return this.#t}get session(){return this.#s}get address(){return this.#s?.address}get appName(){return this.#s?.appName??this.#i}get grants(){return this.#d}get pairing(){return this.#c}get pairingCode(){return this.#g}connect(e={}){if(this.#t==="connected"&&this.#s!==void 0)return Promise.resolve(this.#s);if(this.#a!==void 0)return this.#a;let n=globalThis.navigator?.userActivation;if(e.resume!==!0&&n!==void 0&&!n.isActive)return Promise.reject(new DOMException("connect() must be called from a user action, such as a click","NotAllowedError"));this.#l("connecting");let t=this.#b(this.#m);return this.#a=t,t.then(()=>{if(this.#a===t)this.#a=void 0},()=>{if(this.#a!==t)return;this.#a=void 0,this.#n=void 0,this.#l("disconnected")}),t}async#b(e){let{openConnection:n}=await (p("5ehqkmw1"),import("./connection-5ehqkmw1.min.js"));if(e!==this.#m)throw new DOMException("The connection was cancelled","AbortError");let t={},o=n(this.#E(t),this.#w,this.#p.get());return t.connection=o,this.#n=o,o.ready}disconnect(){this.#T("user")}newAddress(){let e=this.#t!=="disconnected";if(this.#t==="connected")this.#n?.send({type:"grants.revokeAll"});return this.#T("new_address"),this.#p.rotate(),e?this.connect():Promise.resolve(void 0)}#T(e){this.#m++;let n=this.#n,t=this.#t==="connected";if(this.#n=void 0,this.#a=void 0,n?.close(e),this.#t==="disconnected")return;if(this.#s=void 0,this.#f(void 0),this.#l("disconnected"),t)this.#o("disconnected",{reason:e,code:1000})}startPairing(){if(this.#c)return;if(this.#c=!0,this.#t==="connected")this.#n?.send({type:"pairing.start"})}stopPairing(){if(!this.#c)return;if(this.#c=!1,this.#t==="connected")this.#n?.send({type:"pairing.stop"});this.#f(void 0)}revoke(e){if(this.#t!=="connected")return!1;return this.#n?.send({type:"grant.revoke",grantId:e})===!0}async showConnectDialog(e={}){let n=this.connect();n.catch(()=>{});let{showConnectDialog:t}=await (p("dv7pxk0b"),import("./ui-dv7pxk0b.min.js"));await t(this,n,e.document??globalThis.document)}addEventListener(e,n,t){super.addEventListener(e,n,t)}removeEventListener(e,n,t){super.removeEventListener(e,n,t)}#o(e,n){this.dispatchEvent(new CustomEvent(e,{detail:n}))}#l(e){if(this.#t===e)return;this.#t=e,this.#o("statechange",{state:e})}#f(e){if(this.#g===void 0&&e===void 0)return;this.#g=e,this.#o("pairingcode",e??null)}#y(e){this.#d=e,this.#h.keepGrants(e.map((n)=>n.grantId)),this.#o("grantschange",{grants:e})}#S(e){if(this.#u!==void 0){let i=this.#u;return Promise.resolve().then(()=>i(e)).then((r)=>r===!0)}let{grantId:n}=e.client;if(this.#h.has(n,e.tool.name))return Promise.resolve(!0);let t=globalThis.document;if(t===void 0)return Promise.resolve(!1);let o=this.#v;return (p("dv7pxk0b"),import("./ui-dv7pxk0b.min.js")).then((i)=>i.confirmDialog(e,t,o===void 0?{}:{allowDelayMs:o})).then((i)=>{if(i==="always"&&this.#d.some((r)=>r.grantId===n))this.#h.add(n,e.tool.name);return i!=="deny"})}#E(e){let n=()=>e.connection!==void 0&&this.#n===e.connection;return{registry:this.#e,server:this.#r,appName:this.#i,library:{name:E,version:T},confirm:(t)=>this.#S(t),toolCallStarted:(t)=>this.#o("toolcall",t),toolCallEnded:(t)=>this.#o("toolcallend",t),clientFor:(t)=>{let o=this.#d.find((r)=>r.grantId===t.grantId),i={grantId:t.grantId,id:t.clientId,host:K(t.clientId)};if(o!==void 0)i.name=o.client.name;return i},sessionStarted:(t)=>{let o=G(t);if(!n())return o;if(this.#s=o,this.#l("connected"),this.#y([...t.grants]),this.#c)this.#n?.send({type:"pairing.start"});return this.#o("connected",o),o},pairingCode:(t)=>{if(n()&&this.#c)this.#f(t)},grantAdded:(t)=>{if(!n())return;this.#y([...this.#d.filter((o)=>o.grantId!==t.grantId),t])},grantRemoved:(t)=>{if(!n())return;this.#y(this.#d.filter((o)=>o.grantId!==t))},replaced:()=>{if(n())this.#o("replaced",null)},error:(t)=>{if(n())this.#o("error",{error:t})},closed:(t,o)=>{if(!n())return;this.#n=void 0,this.#s=void 0,this.#f(void 0),this.#l("disconnected"),this.#o("disconnected",{reason:t,code:o})}}}}export{C as TabMcp,T as VERSION};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=A7CB4912FC7DF68F64756E2164756E21
|
|
5
5
|
//# sourceMappingURL=tab-mcp-client.min.js.map
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"/**\n * The tools a user chose \"Always allow\" for, per grant (AI app). Kept in\n * memory for the page's lifetime; an entry goes when its grant goes or its\n * tool is unregistered, so a re-paired app or a new tool under the same name\n * is asked again.\n */\nexport class AlwaysAllowed {\n\treadonly #tools = new Map<string, Set<string>>();\n\n\thas(grantId: string, tool: string): boolean {\n\t\treturn this.#tools.get(grantId)?.has(tool) === true;\n\t}\n\n\tadd(grantId: string, tool: string): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Set();\n\t\ttools.add(tool);\n\t\tthis.#tools.set(grantId, tools);\n\t}\n\n\t/** Forget every grant not in `grantIds`. */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tfor (const grantId of this.#tools.keys()) {\n\t\t\tif (!keep.has(grantId)) this.#tools.delete(grantId);\n\t\t}\n\t}\n\n\t/** Forget every tool not in `names`. */\n\tkeepTools(names: Iterable<string>): void {\n\t\tconst keep = new Set(names);\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools) if (!keep.has(tool)) tools.delete(tool);\n\t\t}\n\t}\n}\n",
|
|
6
6
|
"/**\n * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`\n * (DEC-010). Part of the eagerly loaded core.\n */\n\nimport type {\n\tJsonSchema,\n\tRegisterToolOptions,\n\tTool,\n\tToolAnnotations,\n} from \"./types.ts\";\n\nconst NAME = /^[A-Za-z0-9_.-]{1,128}$/;\n\n/** A validated tool as the registry keeps it. */\nexport interface RegisteredTool {\n\treadonly name: string;\n\treadonly title: string | undefined;\n\treadonly description: string;\n\treadonly inputSchema: JsonSchema;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** `x-mcp-header` makes the relay validate headers it does not know; not supported in v1. */\nfunction usesMcpHeader(schema: unknown, depth = 0): boolean {\n\tif (depth > 64 || typeof schema !== \"object\" || schema === null) return false;\n\tif (!Array.isArray(schema) && \"x-mcp-header\" in schema) return true;\n\treturn Object.values(schema).some((v) => usesMcpHeader(v, depth + 1));\n}\n\n/** A JSON pointer (`/a/b~1c`) inside `root`, or `undefined`. */\nfunction resolvePointer(root: unknown, pointer: string): unknown {\n\tlet node: unknown = root;\n\tfor (const raw of pointer.split(\"/\").slice(1)) {\n\t\tconst key = decodeURIComponent(raw)\n\t\t\t.replaceAll(\"~1\", \"/\")\n\t\t\t.replaceAll(\"~0\", \"~\");\n\t\tif (typeof node !== \"object\" || node === null || !Object.hasOwn(node, key))\n\t\t\treturn undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node;\n}\n\n/**\n * What the validator (loaded only on `connect()`) would throw on later, found\n * now so that a bad schema fails registration: patterns that are not\n * regular expressions, and `$ref`s that do not resolve inside the schema.\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tif (this.#tools.get(registered.name) === registered) {\n\t\t\t\t\tthis.#tools.delete(registered.name);\n\t\t\t\t\tthis.#changed();\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
|
|
7
7
|
"/**\n * The address secret (DEC-027): 32 random bytes as base64url without padding,\n * kept in `localStorage`. The relay derives the stable address from it.\n */\n\nimport type { SecretStorage } from \"./types.ts\";\n\nconst SECRET = /^[A-Za-z0-9_-]{43}$/;\n/** base64url without padding. */\nexport function base64url(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nexport function newSecret(): string {\n\treturn base64url(crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport function isSecret(value: unknown): value is string {\n\treturn typeof value === \"string\" && SECRET.test(value);\n}\n\n/** `localStorage`, or `null` where it is missing or blocked. */\nfunction defaultStorage(): SecretStorage | null {\n\ttry {\n\t\tconst storage = (globalThis as { localStorage?: SecretStorage })\n\t\t\t.localStorage;\n\t\treturn storage ?? null;\n\t} catch {\n\t\treturn null; // SecurityError: storage blocked for this page\n\t}\n}\n\n/** Reads, creates and rotates the secret; falls back to memory without storage. */\nexport class SecretStore {\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t#memory: string | undefined;\n\n\tconstructor(storage: SecretStorage | null | undefined, key: string) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t}\n\n\t/** The current secret; storage first, so a rotation in another tab is seen. */\n\tget(): string {\n\t\tlet stored: string | null = null;\n\t\ttry {\n\t\t\tstored = this.#storage?.getItem(this.#key) ?? null;\n\t\t} catch {\n\t\t\t// unreadable: use a page-lifetime secret\n\t\t}\n\t\tif (isSecret(stored)) {\n\t\t\tthis.#memory = stored;\n\t\t\treturn stored;\n\t\t}\n\t\treturn this.#memory ?? this.rotate();\n\t}\n\n\t/** Make and keep a new secret (a new address). */\n\trotate(): string {\n\t\tconst secret = newSecret();\n\t\tthis.#memory = secret;\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t\treturn secret;\n\t}\n}\n",
|
|
8
|
-
"/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.
|
|
8
|
+
"/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.3.0\";\n",
|
|
9
9
|
"/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tPairingCode,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * Never reconnects by itself.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\n\t\t};\n\t}\n}\n"
|
|
10
10
|
],
|
|
11
11
|
"mappings": ";AAMO,MAAM,CAAc,CACjB,GAAS,IAAI,IAEtB,GAAG,CAAC,EAAiB,EAAuB,CAC3C,OAAO,KAAK,GAAO,IAAI,CAAO,GAAG,IAAI,CAAI,IAAM,GAGhD,GAAG,CAAC,EAAiB,EAAoB,CACxC,IAAM,EAAQ,KAAK,GAAO,IAAI,CAAO,GAAK,IAAI,IAC9C,EAAM,IAAI,CAAI,EACd,KAAK,GAAO,IAAI,EAAS,CAAK,EAI/B,UAAU,CAAC,EAAkC,CAC5C,IAAM,EAAO,IAAI,IAAI,CAAQ,EAC7B,QAAW,KAAW,KAAK,GAAO,KAAK,EACtC,GAAI,CAAC,EAAK,IAAI,CAAO,EAAG,KAAK,GAAO,OAAO,CAAO,EAKpD,SAAS,CAAC,EAA+B,CACxC,IAAM,EAAO,IAAI,IAA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if(t.className!==void 0)a.className=t.className;if(t.id!==void 0)a.id=t.id;if(t.text!==void 0)a.textContent=t.text;return a.append(...o),a}function g(e,r,t){let o=s(e,"button",{text:r});return o.type="button",o.addEventListener("click",t),o}function Z(e,r,t,o){let a=g(e,"Copy",()=>{let p=()=>{a.textContent="Copied",a.setAttribute("aria-label",`Copied ${r}`)},l=e.defaultView?.navigator?.clipboard;if(l!==void 0)l.writeText(t()).then(p,o);else o()}),i=()=>{a.textContent="Copy",a.setAttribute("aria-label",`Copy ${r}`)};return i(),{button:a,reset:i}}function q(e,r,t){let o=`tab-mcp-${++B}`,a=s(e,"dialog",{className:`tab-mcp-dialog ${r}`});a.setAttribute("aria-labelledby",`${o}-title`);let i=a.style;i.setProperty("max-width","var(--tab-mcp-max-width, 34rem)"),i.setProperty("font","var(--tab-mcp-font, inherit)"),i.setProperty("color","var(--tab-mcp-color, CanvasText)"),i.setProperty("background","var(--tab-mcp-background, Canvas)"),i.setProperty("border","var(--tab-mcp-border, 1px solid GrayText)"),i.setProperty("border-radius","var(--tab-mcp-radius, 0.5rem)"),i.setProperty("padding","var(--tab-mcp-padding, 1rem 1.25rem)");let p=s(e,"h2",{id:`${o}-title`,text:t});return p.style.setProperty("margin-top","0"),p.style.setProperty("font-size","var(--tab-mcp-title-size, 1.25em)"),a.append(p),{dialog:a,heading:p}}function P(e){let r=e.host||e.id;return e.name!==void 0&&e.name!==""?`${e.name} (${r})`:r}function ae(e){try{return JSON.stringify(e,null,2)}catch{return}}var oe=750,re=500;function le(e,r,t={}){let o=Math.max(re,t.allowDelayMs??oe);if(e.signal.aborted)return Promise.resolve("deny");let a=e.tool.title??e.tool.name,{dialog:i}=q(r,"tab-mcp-confirm",`Allow ${a}?`),p=g(r,"Don't allow",()=>i.close("deny")),l=g(r,"Allow",()=>{if(!l.disabled)i.close("allow")}),u=g(r,"Always allow",()=>{if(!u.disabled)i.close("always")});l.disabled=!0,u.disabled=!0;let H=s(r,"div",{className:"tab-mcp-actions"},p," ",l," ",u),y=s(r,"p",{className:"tab-mcp-always-note",text:`Always allow: ${a} runs without asking for ${P(e.client)} until you reload this page or disconnect it.`}),h=ae(e.arguments),b=s(r,"pre",{className:"tab-mcp-arguments",text:h??"The arguments cannot be shown, so this call cannot be allowed."});if(h===void 0)l.hidden=!0,u.hidden=!0,y.hidden=!0;return b.style.setProperty("white-space","pre-wrap"),b.style.setProperty("max-height","12rem"),b.style.setProperty("overflow","auto"),b.hidden=Object.keys(e.arguments).length===0,i.append(s(r,"p",{text:`${P(e.client)} wants to run ${a}.`}),s(r,"p",{className:"tab-mcp-description",text:e.tool.description}),b,H,y),r.body.append(i),new Promise((E)=>{let N=()=>i.close("deny");e.signal.addEventListener("abort",N,{once:!0});let A;i.addEventListener("close",()=>{clearTimeout(A),e.signal.removeEventListener("abort",N);let c=i.returnValue;i.remove(),E(c==="allow"||c==="always"?c:"deny")},{once:!0}),i.showModal(),p.focus(),A=setTimeout(()=>{l.disabled=!1,u.disabled=!1},o)})}var ie=[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."],["Claude Code","Run: claude mcp add --transport http tools ADDRESS"]];function de(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function ce(e,r,t){let{dialog:o}=q(t,"tab-mcp-connect","Connect your AI app");o.tabIndex=-1,o.style.setProperty("outline","none");let a=s(t,"p",{className:"tab-mcp-status",text:"Connecting…"});a.setAttribute("role","status");let i=`tab-mcp-${++B}-address`,p=s(t,"label",{text:"Add this address to your AI app:"});p.htmlFor=i;let l=s(t,"input",{id:i,className:"tab-mcp-address-input"});l.readOnly=!0,l.style.setProperty("width","100%"),l.style.setProperty("font-family","var(--tab-mcp-mono, monospace)");let{button:u,reset:H}=Z(t,"address",()=>l.value,()=>l.select());u.className="tab-mcp-address-copy";let y=g(t,"New address",()=>ne());y.className="tab-mcp-new-address";let h=s(t,"div",{className:"tab-mcp-address"},p,l," ",u," ",y),b=`tab-mcp-${++B}-new-address`,E=s(t,"p",{id:b}),N=g(t,"Cancel",()=>{c.hidden=!0,y.focus()}),A=g(t,"Disconnect and get new address",()=>J());A.className="tab-mcp-new-address-confirm";let c=s(t,"div",{className:"tab-mcp-new-address-question"},E,s(t,"div",{className:"tab-mcp-actions"},N," ",A));c.setAttribute("role","group"),c.setAttribute("aria-labelledby",b),c.hidden=!0;let m=s(t,"strong",{className:"tab-mcp-code-value"});m.style.setProperty("font-size","var(--tab-mcp-code-size, 1.5em)"),m.style.setProperty("letter-spacing","0.1em"),m.style.setProperty("font-family","var(--tab-mcp-mono, monospace)"),m.style.setProperty("user-select","all"),m.style.setProperty("-webkit-user-select","all");let{button:j,reset:ee}=Z(t,"code",()=>m.textContent??"",()=>t.getSelection()?.selectAllChildren(m));j.className="tab-mcp-code-copy";let K=s(t,"span",{},"When asked, enter the code ",m);K.setAttribute("aria-live","polite");let T=s(t,"p",{className:"tab-mcp-code"},K," ",j,s(t,"br"),s(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."})),W=s(t,"ul"),D=s(t,"details",{className:"tab-mcp-help"},s(t,"summary",{text:"How do I add it?"}),W),V=s(t,"ul"),L=s(t,"div",{className:"tab-mcp-apps"},s(t,"h3",{text:"Connected"}),V),R=s(t,"small",{className:"tab-mcp-close-note",text:"Closing this stops the code. The address stays the same: to connect later, open this again from the page."}),w=g(t,"Close",()=>o.close());w.className="tab-mcp-close",w.style.setProperty("font-size","0.875em");let v=g(t,"Done",()=>o.close());v.className="tab-mcp-done",v.style.setProperty("font-weight","bold"),v.hidden=!0;let C=s(t,"div",{className:"tab-mcp-actions"},R," ",w,v);C.style.setProperty("display","flex"),C.style.setProperty("align-items","center"),C.style.setProperty("justify-content","flex-end"),C.style.setProperty("gap","0.75rem"),C.style.setProperty("margin-top","1rem"),R.style.setProperty("flex","1");let f=!1,G=new Set,Y=()=>{R.hidden=f||T.hidden},O=(n)=>{if(f=n,!f)G.clear();let d=t.activeElement;if(Y(),w.hidden=f,v.hidden=!f,f&&d===w)v.focus();if(!f&&d===v)w.focus()},te=()=>f?v:w;o.append(a,h,c,T,D,L,C),h.hidden=!0,T.hidden=!0,D.hidden=!0,L.hidden=!0;let I=!1,F=()=>{let n=e.grants.map((d)=>P(d.client));if(n.length===0)return!1;return E.textContent=`A new address disconnects ${de(n)}. To use this page again, add the new address to ${n.length===1?"it":"them"}.`,!0},ne=()=>{if(e.state!=="connected")return;if(!F()){J();return}c.hidden=!1,N.focus()},J=()=>{O(!1),w.focus(),c.hidden=!0,I=!0,a.textContent="Getting a new address…",e.newAddress().then(()=>{I=!1,a.textContent="This is a new address. Add it to your AI app again.",u.focus()},(n)=>{I=!1,a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}. Close this and connect again.`,te().focus()})},S=(n)=>{if(n===void 0){h.hidden=!0,c.hidden=!0,D.hidden=!0;return}l.value=n.address,H();let d=n.appName??e.appName;if(!I)a.textContent=d!==void 0?`${d} is ready for your AI app.`:"This page is ready for your AI app.";if(y.disabled=e.state!=="connected",h.hidden=!1,t.activeElement===o)u.focus();D.hidden=!1,W.replaceChildren(...ie.map(([k,se])=>s(t,"li",{},s(t,"strong",{text:k}),`: ${se.replace("ADDRESS",n.address)}`)))},M=()=>{let n=e.pairingCode;if(m.textContent!==(n?.code??""))ee();m.textContent=n?.code??"",T.hidden=n===void 0,Y()},_=s(t,"p",{className:"tab-mcp-apps-note"});L.append(_);let z=new Set(e.grants.map((n)=>n.grantId)),Q=e.session,x=()=>{if(e.session!==Q){Q=e.session;for(let d of e.grants)z.add(d.grantId)}for(let d of e.grants){if(z.has(d.grantId))continue;if(z.add(d.grantId),a.textContent=`${P(d.client)} is connected.`,G.add(d.grantId),!f)O(!0)}if(f&&!e.grants.some((d)=>G.has(d.grantId)))O(!1);let n=e.state==="connected";if(V.replaceChildren(...e.grants.map((d)=>{let k=g(t,"Disconnect",()=>{if(!e.revoke(d.grantId))x()});return k.disabled=!n,s(t,"li",{},`${P(d.client)} connected `,k)})),_.textContent=n?"":"To disconnect an app, connect this page again first.",_.hidden=n,L.hidden=e.grants.length===0,!c.hidden&&!F())c.hidden=!0,y.focus()},U=(n)=>{if(n.detail.reason!=="new_address")a.textContent="Disconnected. AI apps can use this page again after you connect.";S(void 0),x(),M()},X=()=>{S(e.session),x()};return e.addEventListener("pairingcode",M),e.addEventListener("grantschange",x),e.addEventListener("connected",X),e.addEventListener("disconnected",U),t.body.append(o),e.startPairing(),x(),M(),S(e.session),r.then((n)=>S(n),(n)=>{a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}`}),new Promise((n)=>{if(o.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",M),e.removeEventListener("grantschange",x),e.removeEventListener("connected",X),e.removeEventListener("disconnected",U),o.remove(),n()},{once:!0}),o.showModal(),!h.hidden)u.focus();else o.focus()})}export{le as confirmDialog,ce as showConnectDialog};
|
|
2
|
+
|
|
3
|
+
//# debugId=81C6BE1CC64FC5A564756E2164756E21
|
|
4
|
+
//# sourceMappingURL=ui-dv7pxk0b.min.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ui.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/**\n * A Copy button for `value()`, read at click time. Shows \"Copied\" once the\n * clipboard took it; without a clipboard (or when it refuses) `select()` puts\n * the text in the selection for Ctrl+C instead. `noun` names it for assistive\n * technology (\"Copy code\"), as the dialog has more than one Copy.\n */\nfunction copyButton(\n\tdoc: Document,\n\tnoun: string,\n\tvalue: () => string,\n\tselect: () => void,\n): { button: HTMLButtonElement; reset: () => void } {\n\tconst node = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tnode.textContent = \"Copied\";\n\t\t\tnode.setAttribute(\"aria-label\", `Copied ${noun}`);\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(value()).then(done, select);\n\t\telse select();\n\t});\n\tconst reset = () => {\n\t\tnode.textContent = \"Copy\";\n\t\tnode.setAttribute(\"aria-label\", `Copy ${noun}`);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn JSON.stringify(args, null, 2);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/**\n * Ask whether a consequential tool may run. \"Allow\" and \"Always allow\" stay\n * disabled for `allowDelayMs` (default 750, at least 500) after the dialog\n * opens, so a click meant for the page cannot approve. Everything else\n * (Don't allow, Escape, an aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tconst always = button(doc, \"Always allow\", () => {\n\t\tif (!always.disabled) dialog.close(\"always\");\n\t});\n\tallow.disabled = true;\n\talways.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t\t\" \",\n\t\talways,\n\t);\n\tconst alwaysNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-always-note\",\n\t\ttext: `Always allow: ${title} runs without asking for ${clientLabel(request.client)} until you reload this page or disconnect it.`,\n\t});\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tallow.hidden = true;\n\t\talways.hidden = true;\n\t\talwaysNote.hidden = true;\n\t}\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\n\t\t}),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\talwaysNote,\n\t);\n\tdoc.body.append(dialog);\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t\talways.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code (with Copy) while the relay sends one,\n * and the connected apps with Disconnect. Pairing is on while it is open, so\n * closing it ends the code; the connection and the address stay. Until an app\n * connects, only a small Close (and Escape) close it; then a Done. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\t// Focusable from script only, for the moment before the address is shown.\n\tdialog.tabIndex = -1;\n\tdialog.style.setProperty(\"outline\", \"none\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst { button: copy, reset: resetCopy } = copyButton(\n\t\tdoc,\n\t\t\"address\",\n\t\t() => address.value,\n\t\t() => address.select(),\n\t);\n\tcopy.className = \"tab-mcp-address-copy\";\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tcode.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\t// One click selects the whole code; it stays plain, selectable text.\n\tcode.style.setProperty(\"user-select\", \"all\");\n\tcode.style.setProperty(\"-webkit-user-select\", \"all\");\n\t// Reads the code shown at click time, so a rotated code is copied as shown.\n\tconst { button: copyCode, reset: resetCopyCode } = copyButton(\n\t\tdoc,\n\t\t\"code\",\n\t\t() => code.textContent ?? \"\",\n\t\t() => doc.getSelection()?.selectAllChildren(code),\n\t);\n\tcopyCode.className = \"tab-mcp-code-copy\";\n\t// Only the sentence with the code is announced when the code changes,\n\t// not its Copy button's \"Copied\".\n\tconst codeSentence = el(doc, \"span\", {}, \"When asked, enter the code \", code);\n\tcodeSentence.setAttribute(\"aria-live\", \"polite\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\t\" \",\n\t\tcopyCode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\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: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\t// Until an app connects in this dialog, closing it is not the next step:\n\t// a small Close at the end, saying what closing does (the code stops, the\n\t// address stays). Once one connects, a prominent Done replaces both.\n\tconst closeNote = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-close-note\",\n\t\ttext: \"Closing this stops the code. The address stays the same: to connect later, open this again from the page.\",\n\t});\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tclose.className = \"tab-mcp-close\";\n\tclose.style.setProperty(\"font-size\", \"0.875em\");\n\tconst done = button(doc, \"Done\", () => dialog.close());\n\tdone.className = \"tab-mcp-done\";\n\tdone.style.setProperty(\"font-weight\", \"bold\");\n\tdone.hidden = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tcloseNote,\n\t\t\" \",\n\t\tclose,\n\t\tdone,\n\t);\n\t// The note on the left, the button at the far right, apart from the code.\n\tactions.style.setProperty(\"display\", \"flex\");\n\tactions.style.setProperty(\"align-items\", \"center\");\n\tactions.style.setProperty(\"justify-content\", \"flex-end\");\n\tactions.style.setProperty(\"gap\", \"0.75rem\");\n\tactions.style.setProperty(\"margin-top\", \"1rem\");\n\tcloseNote.style.setProperty(\"flex\", \"1\");\n\t// An app connected while this dialog is open (since the last new address),\n\t// and still connected: the grants that made it so.\n\tlet paired = false;\n\tconst pairedGrants = new Set<string>();\n\t// The note is about the code: only while one is shown and nothing paired.\n\tconst renderCloseNote = () => {\n\t\tcloseNote.hidden = paired || codeLine.hidden;\n\t};\n\tconst setPaired = (value: boolean) => {\n\t\tpaired = value;\n\t\tif (!paired) pairedGrants.clear();\n\t\tconst focused = doc.activeElement;\n\t\trenderCloseNote();\n\t\tclose.hidden = paired;\n\t\tdone.hidden = !paired;\n\t\t// Focus never stays on a control that was just hidden.\n\t\tif (paired && focused === close) done.focus();\n\t\tif (!paired && focused === done) close.focus();\n\t};\n\t// The visible button that closes the dialog.\n\tconst closer = () => (paired ? done : close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// The apps are disconnected: the next one has to pair again.\n\t\tsetPaired(false);\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tcopy.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tresetCopy();\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\t// Opened before the session was known: start at the address's Copy.\n\t\tif (doc.activeElement === dialog) copy.focus();\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\t// A new code is not copied yet.\n\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t\trenderCloseNote();\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\t// Grants that come with a (new) session were there before; only the ones\n\t// added during a session are new connections.\n\tlet session = mcp.session;\n\tconst renderGrants = () => {\n\t\tif (mcp.session !== session) {\n\t\t\tsession = mcp.session;\n\t\t\tfor (const grant of mcp.grants) known.add(grant.grantId);\n\t\t}\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t\tpairedGrants.add(grant.grantId);\n\t\t\tif (!paired) setPaired(true);\n\t\t}\n\t\t// The app that connected here is gone again (Disconnect, or revoked):\n\t\t// back to Close and the note, the code still runs.\n\t\tif (paired && !mcp.grants.some((g) => pairedGrants.has(g.grantId))) {\n\t\t\tsetPaired(false);\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\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 the address's Copy; until the address is there, at the\n\t\t// dialog itself (its title is read out), not at Close.\n\t\tif (!addressBox.hidden) copy.focus();\n\t\telse dialog.focus();\n\t});\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAiBA,IAAI,EAAU,EAEd,SAAS,CAAyC,CACjD,EACA,EACA,EAA4D,CAAC,KAC1D,EACwB,CAC3B,IAAM,EAAO,EAAI,cAAc,CAAG,EAClC,GAAI,EAAM,YAAc,OAAW,EAAK,UAAY,EAAM,UAC1D,GAAI,EAAM,KAAO,OAAW,EAAK,GAAK,EAAM,GAC5C,GAAI,EAAM,OAAS,OAAW,EAAK,YAAc,EAAM,KAEvD,OADA,EAAK,OAAO,GAAG,CAAQ,EAChB,EAGR,SAAS,CAAM,CACd,EACA,EACA,EACoB,CACpB,IAAM,EAAO,EAAG,EAAK,SAAU,CAAE,MAAK,CAAC,EAGvC,OAFA,EAAK,KAAO,SACZ,EAAK,iBAAiB,QAAS,CAAO,EAC/B,EASR,SAAS,CAAU,CAClB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AAO,EACd,EAAQ,GAET,CAAE,KAAM,EAAK,CACd,EACA,EAAO,UAAU,EAGb,CAAC,EAAW,OAAQ,EAAK,MAAM,EAC9B,OAAO,MAAM,EAClB",
|
|
8
|
+
"debugId": "81C6BE1CC64FC5A564756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __chunks = (base, ids, nodes, entry) => {
|
|
|
28
28
|
__chunkSeen ||= {};
|
|
29
29
|
__preload(ids[entry], 1);
|
|
30
30
|
};
|
|
31
|
-
__chunks(import.meta.url,["
|
|
31
|
+
__chunks(import.meta.url,["jcfs1ek1","ag7eyd36","g1k2g5hm"],[["./index.js"],["./connection-ag7eyd36.js"],["./ui-g1k2g5hm.js"]],0);
|
|
32
32
|
|
|
33
33
|
// src/always-allowed.ts
|
|
34
34
|
class AlwaysAllowed {
|
|
@@ -258,7 +258,7 @@ class SecretStore {
|
|
|
258
258
|
|
|
259
259
|
// src/version.ts
|
|
260
260
|
var LIBRARY_NAME = "@ractive-ch/tab-mcp-client";
|
|
261
|
-
var VERSION = "0.
|
|
261
|
+
var VERSION = "0.3.0";
|
|
262
262
|
|
|
263
263
|
// src/tab-mcp.ts
|
|
264
264
|
var LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -466,7 +466,7 @@ class TabMcp extends EventTarget {
|
|
|
466
466
|
async showConnectDialog(options = {}) {
|
|
467
467
|
const connecting = this.connect();
|
|
468
468
|
connecting.catch(() => {});
|
|
469
|
-
const { showConnectDialog } = await (__preload("
|
|
469
|
+
const { showConnectDialog } = await (__preload("g1k2g5hm"), import("./ui-g1k2g5hm.js"));
|
|
470
470
|
await showConnectDialog(this, connecting, options.document ?? globalThis.document);
|
|
471
471
|
}
|
|
472
472
|
addEventListener(type, listener, options) {
|
|
@@ -507,7 +507,7 @@ class TabMcp extends EventTarget {
|
|
|
507
507
|
if (doc === undefined)
|
|
508
508
|
return Promise.resolve(false);
|
|
509
509
|
const delay = this.#confirmDelayMs;
|
|
510
|
-
return (__preload("
|
|
510
|
+
return (__preload("g1k2g5hm"), import("./ui-g1k2g5hm.js")).then((ui) => ui.confirmDialog(request, doc, delay === undefined ? {} : { allowDelayMs: delay })).then((answer) => {
|
|
511
511
|
if (answer === "always" && this.#grants.some((g) => g.grantId === grantId))
|
|
512
512
|
this.#alwaysAllowed.add(grantId, request.tool.name);
|
|
513
513
|
return answer !== "deny";
|
|
@@ -588,5 +588,5 @@ export {
|
|
|
588
588
|
VERSION
|
|
589
589
|
};
|
|
590
590
|
|
|
591
|
-
//# debugId=
|
|
591
|
+
//# debugId=BC5CBAEE1DA9DD7C64756E2164756E21
|
|
592
592
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"/**\n * The tools a user chose \"Always allow\" for, per grant (AI app). Kept in\n * memory for the page's lifetime; an entry goes when its grant goes or its\n * tool is unregistered, so a re-paired app or a new tool under the same name\n * is asked again.\n */\nexport class AlwaysAllowed {\n\treadonly #tools = new Map<string, Set<string>>();\n\n\thas(grantId: string, tool: string): boolean {\n\t\treturn this.#tools.get(grantId)?.has(tool) === true;\n\t}\n\n\tadd(grantId: string, tool: string): void {\n\t\tconst tools = this.#tools.get(grantId) ?? new Set();\n\t\ttools.add(tool);\n\t\tthis.#tools.set(grantId, tools);\n\t}\n\n\t/** Forget every grant not in `grantIds`. */\n\tkeepGrants(grantIds: Iterable<string>): void {\n\t\tconst keep = new Set(grantIds);\n\t\tfor (const grantId of this.#tools.keys()) {\n\t\t\tif (!keep.has(grantId)) this.#tools.delete(grantId);\n\t\t}\n\t}\n\n\t/** Forget every tool not in `names`. */\n\tkeepTools(names: Iterable<string>): void {\n\t\tconst keep = new Set(names);\n\t\tfor (const tools of this.#tools.values()) {\n\t\t\tfor (const tool of tools) if (!keep.has(tool)) tools.delete(tool);\n\t\t}\n\t}\n}\n",
|
|
6
6
|
"/**\n * The tool registry, mirroring WebMCP's `registerTool(tool, { signal })`\n * (DEC-010). Part of the eagerly loaded core.\n */\n\nimport type {\n\tJsonSchema,\n\tRegisterToolOptions,\n\tTool,\n\tToolAnnotations,\n} from \"./types.ts\";\n\nconst NAME = /^[A-Za-z0-9_.-]{1,128}$/;\n\n/** A validated tool as the registry keeps it. */\nexport interface RegisteredTool {\n\treadonly name: string;\n\treadonly title: string | undefined;\n\treadonly description: string;\n\treadonly inputSchema: JsonSchema;\n\treadonly annotations: ToolAnnotations;\n\treadonly execute: Tool[\"execute\"];\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** `x-mcp-header` makes the relay validate headers it does not know; not supported in v1. */\nfunction usesMcpHeader(schema: unknown, depth = 0): boolean {\n\tif (depth > 64 || typeof schema !== \"object\" || schema === null) return false;\n\tif (!Array.isArray(schema) && \"x-mcp-header\" in schema) return true;\n\treturn Object.values(schema).some((v) => usesMcpHeader(v, depth + 1));\n}\n\n/** A JSON pointer (`/a/b~1c`) inside `root`, or `undefined`. */\nfunction resolvePointer(root: unknown, pointer: string): unknown {\n\tlet node: unknown = root;\n\tfor (const raw of pointer.split(\"/\").slice(1)) {\n\t\tconst key = decodeURIComponent(raw)\n\t\t\t.replaceAll(\"~1\", \"/\")\n\t\t\t.replaceAll(\"~0\", \"~\");\n\t\tif (typeof node !== \"object\" || node === null || !Object.hasOwn(node, key))\n\t\t\treturn undefined;\n\t\tnode = (node as Record<string, unknown>)[key];\n\t}\n\treturn node;\n}\n\n/**\n * What the validator (loaded only on `connect()`) would throw on later, found\n * now so that a bad schema fails registration: patterns that are not\n * regular expressions, and `$ref`s that do not resolve inside the schema.\n */\nfunction schemaProblem(root: unknown): string | undefined {\n\tconst anchors = new Set<string>();\n\tconst refs: string[] = [];\n\tconst patterns: string[] = [];\n\tconst walk = (node: unknown, depth: number): void => {\n\t\tif (depth > 64 || typeof node !== \"object\" || node === null) return;\n\t\tif (!Array.isArray(node)) {\n\t\t\tconst o = node as Record<string, unknown>;\n\t\t\tif (typeof o[\"$anchor\"] === \"string\") anchors.add(o[\"$anchor\"]);\n\t\t\tif (typeof o[\"$ref\"] === \"string\") refs.push(o[\"$ref\"]);\n\t\t\tif (typeof o[\"pattern\"] === \"string\") patterns.push(o[\"pattern\"]);\n\t\t\tconst pp = o[\"patternProperties\"];\n\t\t\tif (typeof pp === \"object\" && pp !== null)\n\t\t\t\tpatterns.push(...Object.keys(pp));\n\t\t}\n\t\tfor (const v of Object.values(node)) walk(v, depth + 1);\n\t};\n\twalk(root, 0);\n\tfor (const p of patterns) {\n\t\ttry {\n\t\t\tnew RegExp(p, \"u\");\n\t\t} catch {\n\t\t\treturn `pattern ${JSON.stringify(p)} is not a valid regular expression`;\n\t\t}\n\t}\n\tfor (const ref of refs) {\n\t\tif (!ref.startsWith(\"#\"))\n\t\t\treturn `$ref ${JSON.stringify(ref)} points outside the schema`;\n\t\tconst target = ref.slice(1);\n\t\tconst found =\n\t\t\ttarget === \"\" ||\n\t\t\t(target.startsWith(\"/\")\n\t\t\t\t? resolvePointer(root, target) !== undefined\n\t\t\t\t: anchors.has(target));\n\t\tif (!found) return `$ref ${JSON.stringify(ref)} does not resolve`;\n\t}\n\treturn undefined;\n}\n\n/** Validate a tool; throws a `TypeError` naming the problem. */\nexport function validateTool(tool: Tool): RegisteredTool {\n\tif (!isPlainObject(tool))\n\t\tthrow new TypeError(\"registerTool: the tool must be an object\");\n\tconst { name, title, description, inputSchema, execute, annotations } = tool;\n\tif (typeof name !== \"string\" || !NAME.test(name)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the name must be 1–128 characters of A–Z, a–z, 0–9, \"_\", \"-\" or \".\" (got ${JSON.stringify(name)})`,\n\t\t);\n\t}\n\tif (typeof description !== \"string\" || description.trim() === \"\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs a description`);\n\t}\n\tif (title !== undefined && typeof title !== \"string\") {\n\t\tthrow new TypeError(`registerTool: the title of ${name} must be a string`);\n\t}\n\tif (typeof execute !== \"function\") {\n\t\tthrow new TypeError(`registerTool: tool ${name} needs an execute function`);\n\t}\n\tconst schema = inputSchema ?? { type: \"object\" };\n\tif (!isPlainObject(schema) || schema[\"type\"] !== \"object\") {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be a JSON Schema object with \"type\": \"object\"`,\n\t\t);\n\t}\n\tif (usesMcpHeader(schema)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: ${name} uses x-mcp-header, which tab-mcp does not support`,\n\t\t);\n\t}\n\tconst problem = schemaProblem(schema);\n\tif (problem !== undefined) {\n\t\tthrow new TypeError(`registerTool: the inputSchema of ${name}: ${problem}`);\n\t}\n\tlet copied: JsonSchema;\n\ttry {\n\t\tcopied = JSON.parse(JSON.stringify(schema)) as JsonSchema;\n\t} catch {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the inputSchema of ${name} must be JSON`,\n\t\t);\n\t}\n\tif (annotations !== undefined && !isPlainObject(annotations)) {\n\t\tthrow new TypeError(\n\t\t\t`registerTool: the annotations of ${name} must be an object`,\n\t\t);\n\t}\n\tconst hints: ToolAnnotations = {};\n\tfor (const [key, value] of Object.entries(annotations ?? {})) {\n\t\tif (typeof value === \"boolean\")\n\t\t\t(hints as Record<string, boolean>)[key] = value;\n\t}\n\treturn {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tinputSchema: copied,\n\t\tannotations: hints,\n\t\texecute,\n\t};\n}\n\nexport class ToolRegistry {\n\treadonly #tools = new Map<string, RegisteredTool>();\n\treadonly #listeners = new Set<() => void>();\n\n\t/**\n\t * Register a tool; throws `TypeError` for an invalid tool and an\n\t * `InvalidStateError` `DOMException` for a duplicate name.\n\t */\n\tregister(tool: Tool, options: RegisterToolOptions = {}): void {\n\t\tconst registered = validateTool(tool);\n\t\tconst { signal } = options;\n\t\tif (signal?.aborted) return;\n\t\tif (this.#tools.has(registered.name)) {\n\t\t\tthrow new DOMException(\n\t\t\t\t`registerTool: a tool named ${registered.name} is already registered`,\n\t\t\t\t\"InvalidStateError\",\n\t\t\t);\n\t\t}\n\t\tthis.#tools.set(registered.name, registered);\n\t\tsignal?.addEventListener(\n\t\t\t\"abort\",\n\t\t\t() => {\n\t\t\t\tif (this.#tools.get(registered.name) === registered) {\n\t\t\t\t\tthis.#tools.delete(registered.name);\n\t\t\t\t\tthis.#changed();\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tthis.#changed();\n\t}\n\n\tget(name: string): RegisteredTool | undefined {\n\t\treturn this.#tools.get(name);\n\t}\n\n\t/** Tools in registration order. */\n\tlist(): RegisteredTool[] {\n\t\treturn [...this.#tools.values()];\n\t}\n\n\t/** Listen for changes; returns a function that stops listening. */\n\tonChange(listener: () => void): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t#changed(): void {\n\t\tfor (const listener of [...this.#listeners]) listener();\n\t}\n}\n",
|
|
7
7
|
"/**\n * The address secret (DEC-027): 32 random bytes as base64url without padding,\n * kept in `localStorage`. The relay derives the stable address from it.\n */\n\nimport type { SecretStorage } from \"./types.ts\";\n\nconst SECRET = /^[A-Za-z0-9_-]{43}$/;\n/** base64url without padding. */\nexport function base64url(bytes: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...bytes))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.replace(/=+$/, \"\");\n}\n\nexport function newSecret(): string {\n\treturn base64url(crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport function isSecret(value: unknown): value is string {\n\treturn typeof value === \"string\" && SECRET.test(value);\n}\n\n/** `localStorage`, or `null` where it is missing or blocked. */\nfunction defaultStorage(): SecretStorage | null {\n\ttry {\n\t\tconst storage = (globalThis as { localStorage?: SecretStorage })\n\t\t\t.localStorage;\n\t\treturn storage ?? null;\n\t} catch {\n\t\treturn null; // SecurityError: storage blocked for this page\n\t}\n}\n\n/** Reads, creates and rotates the secret; falls back to memory without storage. */\nexport class SecretStore {\n\treadonly #storage: SecretStorage | null;\n\treadonly #key: string;\n\t#memory: string | undefined;\n\n\tconstructor(storage: SecretStorage | null | undefined, key: string) {\n\t\tthis.#storage = storage === undefined ? defaultStorage() : storage;\n\t\tthis.#key = key;\n\t}\n\n\t/** The current secret; storage first, so a rotation in another tab is seen. */\n\tget(): string {\n\t\tlet stored: string | null = null;\n\t\ttry {\n\t\t\tstored = this.#storage?.getItem(this.#key) ?? null;\n\t\t} catch {\n\t\t\t// unreadable: use a page-lifetime secret\n\t\t}\n\t\tif (isSecret(stored)) {\n\t\t\tthis.#memory = stored;\n\t\t\treturn stored;\n\t\t}\n\t\treturn this.#memory ?? this.rotate();\n\t}\n\n\t/** Make and keep a new secret (a new address). */\n\trotate(): string {\n\t\tconst secret = newSecret();\n\t\tthis.#memory = secret;\n\t\ttry {\n\t\t\tthis.#storage?.setItem(this.#key, secret);\n\t\t} catch {\n\t\t\t// quota or blocked: the secret lives as long as the page\n\t\t}\n\t\treturn secret;\n\t}\n}\n",
|
|
8
|
-
"/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.
|
|
8
|
+
"/** The library's name and version, sent in `hello` (a test keeps it equal to package.json). */\nexport const LIBRARY_NAME = \"@ractive-ch/tab-mcp-client\";\nexport const VERSION = \"0.3.0\";\n",
|
|
9
9
|
"/**\n * `TabMcp`: the eagerly loaded core (DEC-035). It holds the tool registry, the\n * events, the pairing state and the address secret; `connect()` loads the\n * connection and the MCP handler with a dynamic `import()`.\n */\n\nimport { AlwaysAllowed } from \"./always-allowed.ts\";\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport type { GrantRef, SessionMessage } from \"./protocol.ts\";\nimport { ToolRegistry } from \"./registry.ts\";\nimport { SecretStore } from \"./secret.ts\";\nimport type {\n\tConfirmHandler,\n\tConfirmRequest,\n\tConnectionState,\n\tConnectOptions,\n\tDisconnectReason,\n\tGrant,\n\tPairingCode,\n\tRegisterToolOptions,\n\tServerInfo,\n\tSessionInfo,\n\tTabMcpEventMap,\n\tTabMcpOptions,\n\tTool,\n\tToolCallClient,\n} from \"./types.ts\";\nimport { LIBRARY_NAME, VERSION } from \"./version.ts\";\n\nconst LOOPBACK = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\"]);\n\n/** What the relay accepts as `hello.app.name` (protocol: session). */\nfunction isAppName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 64 &&\n\t\t![...value].some((ch) => {\n\t\t\tconst c = ch.codePointAt(0) ?? 0;\n\t\t\treturn c < 0x20 || (c >= 0x7f && c <= 0x9f);\n\t\t})\n\t);\n}\n\n/** `wss://host/tab` for a relay given as `https://host`, `wss://host` or with `/tab`. */\nexport function tabUrl(relay: string): { url: string; origin: string } {\n\tlet u: URL;\n\ttry {\n\t\tu = new URL(relay);\n\t} catch {\n\t\tthrow new TypeError(`TabMcp: relay is not a URL: ${relay}`);\n\t}\n\tconst secure = u.protocol === \"https:\" || u.protocol === \"wss:\";\n\tif (!secure && u.protocol !== \"http:\" && u.protocol !== \"ws:\") {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must be an https: or wss: URL: ${relay}`,\n\t\t);\n\t}\n\t// The secret travels in hello: never in clear text beyond this machine.\n\tif (!secure && !LOOPBACK.has(u.hostname)) {\n\t\tthrow new TypeError(\n\t\t\t`TabMcp: relay must use https: or wss: (http: only for localhost): ${relay}`,\n\t\t);\n\t}\n\tconst origin = `${secure ? \"https:\" : \"http:\"}//${u.host}`;\n\tconst path = u.pathname.replace(/\\/+$/, \"\");\n\tu.protocol = secure ? \"wss:\" : \"ws:\";\n\tu.pathname = path.endsWith(\"/tab\") ? path : `${path}/tab`;\n\tu.search = \"\";\n\tu.hash = \"\";\n\treturn { url: u.href, origin };\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction sessionInfo(m: SessionMessage): SessionInfo {\n\tconst info: SessionInfo = {\n\t\tsessionId: m.sessionId,\n\t\taddress: m.address,\n\t\torigin: m.origin,\n\t\texpiresAt: m.expiresAt,\n\t\tlimits: m.limits,\n\t};\n\tif (m.appName !== undefined) info.appName = m.appName;\n\treturn info;\n}\n\ntype Listener<K extends keyof TabMcpEventMap> = (\n\tevent: TabMcpEventMap[K],\n) => void;\n\n/**\n * Offers a page's tools to AI apps through a tab-mcp relay.\n *\n * ```ts\n * const mcp = new TabMcp({ relay: \"https://relay.example\", server: { name: \"Calculator\", version: \"1.0.0\" } });\n * mcp.registerTool({ name: \"add\", description: \"Add two numbers\", execute: ({ a, b }) => Number(a) + Number(b) });\n * button.onclick = () => mcp.showConnectDialog();\n * ```\n */\nexport class TabMcp extends EventTarget {\n\treadonly #registry = new ToolRegistry();\n\treadonly #server: ServerInfo;\n\treadonly #appName: string | undefined;\n\treadonly #onConfirm: ConfirmHandler | undefined;\n\treadonly #confirmDelayMs: number | undefined;\n\treadonly #relayUrl: string;\n\treadonly #secrets: SecretStore;\n\t#state: ConnectionState = \"disconnected\";\n\t#session: SessionInfo | undefined;\n\t#grants: Grant[] = [];\n\treadonly #alwaysAllowed = new AlwaysAllowed();\n\t#pairing = false;\n\t#pairingCode: PairingCode | undefined;\n\t#connection: ConnectionHandle | undefined;\n\t#connecting: Promise<SessionInfo> | undefined;\n\t/** Incremented when a connection ends or is cancelled. */\n\t#generation = 0;\n\n\tconstructor(options: TabMcpOptions) {\n\t\tsuper();\n\t\tconst { url, origin } = tabUrl(options.relay);\n\t\tconst { server, appName } = options;\n\t\tif (\n\t\t\ttypeof server?.name !== \"string\" ||\n\t\t\ttypeof server.version !== \"string\"\n\t\t) {\n\t\t\tthrow new TypeError(\"TabMcp: server needs a name and a version\");\n\t\t}\n\t\tif (appName !== undefined && !isAppName(appName)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"TabMcp: appName must be 1-64 characters without control characters\",\n\t\t\t);\n\t\t}\n\t\tthis.#relayUrl = url;\n\t\tthis.#server = { ...server };\n\t\tthis.#appName = appName;\n\t\tthis.#onConfirm = options.onConfirm;\n\t\tthis.#confirmDelayMs = options.confirmDelayMs;\n\t\tthis.#secrets = new SecretStore(\n\t\t\toptions.storage,\n\t\t\toptions.storageKey ?? `tab-mcp:secret:${origin}`,\n\t\t);\n\t\tthis.#registry.onChange(() => {\n\t\t\tconst tools = this.tools;\n\t\t\tthis.#alwaysAllowed.keepTools(tools);\n\t\t\tthis.#emit(\"toolschange\", { tools });\n\t\t});\n\t}\n\n\t/**\n\t * Register a tool (WebMCP shape). Allowed before and after `connect()`;\n\t * aborting `options.signal` unregisters it. Rejects with a `TypeError` for\n\t * an invalid tool and an `InvalidStateError` for a duplicate name.\n\t */\n\tregisterTool(tool: Tool, options: RegisterToolOptions = {}): Promise<void> {\n\t\ttry {\n\t\t\tthis.#registry.register(tool, options);\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn Promise.resolve();\n\t}\n\n\t/** Names of the registered tools. */\n\tget tools(): readonly string[] {\n\t\treturn this.#registry.list().map((t) => t.name);\n\t}\n\n\tget state(): ConnectionState {\n\t\treturn this.#state;\n\t}\n\n\t/** The current session, while connected. */\n\tget session(): SessionInfo | undefined {\n\t\treturn this.#session;\n\t}\n\n\t/** The MCP address to give to AI apps, while connected. */\n\tget address(): string | undefined {\n\t\treturn this.#session?.address;\n\t}\n\n\t/** The app name AI apps see when pairing: the relay's (`session.appName`), else the page's own. */\n\tget appName(): string | undefined {\n\t\treturn this.#session?.appName ?? this.#appName;\n\t}\n\n\t/** The AI apps connected to this address. */\n\tget grants(): readonly Grant[] {\n\t\treturn this.#grants;\n\t}\n\n\t/** Whether pairing is on (`startPairing()`). */\n\tget pairing(): boolean {\n\t\treturn this.#pairing;\n\t}\n\n\t/** The pairing code to show, if the relay sent one. */\n\tget pairingCode(): PairingCode | undefined {\n\t\treturn this.#pairingCode;\n\t}\n\n\t/**\n\t * Connect to the relay: loads the connection and MCP handler, opens the\n\t * WebSocket, resolves with the session. Call it from a user action (a\n\t * click): where browsers track user activation it is refused otherwise,\n\t * unless `options.resume` says the user already chose to keep AI access on.\n\t * Never reconnects by itself.\n\t */\n\tconnect(options: ConnectOptions = {}): Promise<SessionInfo> {\n\t\tif (this.#state === \"connected\" && this.#session !== undefined) {\n\t\t\treturn Promise.resolve(this.#session);\n\t\t}\n\t\tif (this.#connecting !== undefined) return this.#connecting;\n\t\tconst activation = (\n\t\t\tglobalThis.navigator as\n\t\t\t\t| { userActivation?: { isActive: boolean } }\n\t\t\t\t| undefined\n\t\t)?.userActivation;\n\t\tif (\n\t\t\toptions.resume !== true &&\n\t\t\tactivation !== undefined &&\n\t\t\t!activation.isActive\n\t\t) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew DOMException(\n\t\t\t\t\t\"connect() must be called from a user action, such as a click\",\n\t\t\t\t\t\"NotAllowedError\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tthis.#setState(\"connecting\");\n\t\tconst connecting = this.#open(this.#generation);\n\t\tthis.#connecting = connecting;\n\t\tconnecting.then(\n\t\t\t() => {\n\t\t\t\tif (this.#connecting === connecting) this.#connecting = undefined;\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (this.#connecting !== connecting) return; // superseded\n\t\t\t\tthis.#connecting = undefined;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t},\n\t\t);\n\t\treturn connecting;\n\t}\n\n\tasync #open(generation: number): Promise<SessionInfo> {\n\t\tconst { openConnection } = await import(\"./connection.ts\");\n\t\tif (generation !== this.#generation) {\n\t\t\tthrow new DOMException(\"The connection was cancelled\", \"AbortError\");\n\t\t}\n\t\tconst ref: { connection?: ConnectionHandle } = {};\n\t\tconst connection = openConnection(\n\t\t\tthis.#host(ref),\n\t\t\tthis.#relayUrl,\n\t\t\tthis.#secrets.get(),\n\t\t);\n\t\tref.connection = connection;\n\t\tthis.#connection = connection;\n\t\treturn connection.ready;\n\t}\n\n\t/** End the session (`bye`). Grants stay: AI apps work again after the next `connect()`. */\n\tdisconnect(): void {\n\t\tthis.#end(\"user\");\n\t}\n\n\t/**\n\t * A new address: revokes every connected app of the old one (while\n\t * connected), makes a new secret, and connects again if it was connected or\n\t * connecting. Call it from a user action.\n\t */\n\tnewAddress(): Promise<SessionInfo | undefined> {\n\t\tconst wasOn = this.#state !== \"disconnected\";\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"grants.revokeAll\" });\n\t\tthis.#end(\"new_address\");\n\t\tthis.#secrets.rotate();\n\t\treturn wasOn ? this.connect() : Promise.resolve(undefined);\n\t}\n\n\t/** Close the connection (or cancel connecting) and report it at once. */\n\t#end(reason: DisconnectReason): void {\n\t\tthis.#generation++;\n\t\tconst connection = this.#connection;\n\t\tconst wasConnected = this.#state === \"connected\";\n\t\tthis.#connection = undefined;\n\t\tthis.#connecting = undefined;\n\t\tconnection?.close(reason); // its callbacks are stale from here on\n\t\tif (this.#state === \"disconnected\") return;\n\t\tthis.#session = undefined;\n\t\tthis.#setPairingCode(undefined);\n\t\tthis.#setState(\"disconnected\");\n\t\tif (wasConnected) this.#emit(\"disconnected\", { reason, code: 1000 });\n\t}\n\n\t/** The pairing dialog opened: ask the relay for codes (DEC-028). */\n\tstartPairing(): void {\n\t\tif (this.#pairing) return;\n\t\tthis.#pairing = true;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.start\" });\n\t}\n\n\t/** The pairing dialog closed: the code becomes invalid. */\n\tstopPairing(): void {\n\t\tif (!this.#pairing) return;\n\t\tthis.#pairing = false;\n\t\tif (this.#state === \"connected\")\n\t\t\tthis.#connection?.send({ type: \"pairing.stop\" });\n\t\tthis.#setPairingCode(undefined);\n\t}\n\n\t/**\n\t * Disconnect one AI app: its tokens stop working at once. Works only while\n\t * connected (the relay does it); returns `false` when it could not be sent.\n\t */\n\trevoke(grantId: string): boolean {\n\t\tif (this.#state !== \"connected\") return false;\n\t\treturn this.#connection?.send({ type: \"grant.revoke\", grantId }) === true;\n\t}\n\n\t/**\n\t * Open the default \"Connect your AI app\" dialog; connects first if needed\n\t * (call it from a click). Resolves when the dialog closes. Pages with their\n\t * own UI use the events and methods instead.\n\t */\n\tasync showConnectDialog(\n\t\toptions: { document?: Document } = {},\n\t): Promise<void> {\n\t\tconst connecting = this.connect();\n\t\tconnecting.catch(() => {}); // the dialog shows the error\n\t\tconst { showConnectDialog } = await import(\"./ui.ts\");\n\t\tawait showConnectDialog(\n\t\t\tthis,\n\t\t\tconnecting,\n\t\t\toptions.document ?? globalThis.document,\n\t\t);\n\t}\n\n\toverride addEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void;\n\toverride addEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | AddEventListenerOptions,\n\t): void {\n\t\tsuper.addEventListener(type, listener, options);\n\t}\n\n\toverride removeEventListener<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tlistener: Listener<K> | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void;\n\toverride removeEventListener(\n\t\ttype: string,\n\t\tlistener: EventListenerOrEventListenerObject | null,\n\t\toptions?: boolean | EventListenerOptions,\n\t): void {\n\t\tsuper.removeEventListener(type, listener, options);\n\t}\n\n\t#emit<K extends keyof TabMcpEventMap>(\n\t\ttype: K,\n\t\tdetail: TabMcpEventMap[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(new CustomEvent(type, { detail }));\n\t}\n\n\t#setState(state: ConnectionState): void {\n\t\tif (this.#state === state) return;\n\t\tthis.#state = state;\n\t\tthis.#emit(\"statechange\", { state });\n\t}\n\n\t#setPairingCode(code: PairingCode | undefined): void {\n\t\tif (this.#pairingCode === undefined && code === undefined) return;\n\t\tthis.#pairingCode = code;\n\t\tthis.#emit(\"pairingcode\", code ?? null);\n\t}\n\n\t#setGrants(grants: Grant[]): void {\n\t\tthis.#grants = grants;\n\t\tthis.#alwaysAllowed.keepGrants(grants.map((g) => g.grantId));\n\t\tthis.#emit(\"grantschange\", { grants });\n\t}\n\n\t#confirm(request: ConfirmRequest): Promise<boolean> {\n\t\tif (this.#onConfirm !== undefined) {\n\t\t\tconst ask = this.#onConfirm;\n\t\t\treturn Promise.resolve()\n\t\t\t\t.then(() => ask(request))\n\t\t\t\t.then((allowed) => allowed === true);\n\t\t}\n\t\tconst { grantId } = request.client;\n\t\tif (this.#alwaysAllowed.has(grantId, request.tool.name))\n\t\t\treturn Promise.resolve(true);\n\t\tconst doc = globalThis.document as Document | undefined;\n\t\tif (doc === undefined) return Promise.resolve(false); // nobody to ask: decline\n\t\tconst delay = this.#confirmDelayMs;\n\t\treturn import(\"./ui.ts\")\n\t\t\t.then((ui) =>\n\t\t\t\tui.confirmDialog(\n\t\t\t\t\trequest,\n\t\t\t\t\tdoc,\n\t\t\t\t\tdelay === undefined ? {} : { allowDelayMs: delay },\n\t\t\t\t),\n\t\t\t)\n\t\t\t.then((answer) => {\n\t\t\t\t// Only while the grant is still there: a revoked app gets nothing.\n\t\t\t\tif (\n\t\t\t\t\tanswer === \"always\" &&\n\t\t\t\t\tthis.#grants.some((g) => g.grantId === grantId)\n\t\t\t\t)\n\t\t\t\t\tthis.#alwaysAllowed.add(grantId, request.tool.name);\n\t\t\t\treturn answer !== \"deny\";\n\t\t\t});\n\t}\n\n\t/** The callbacks of one connection; once it is not current they are ignored. */\n\t#host(ref: { connection?: ConnectionHandle }): ConnectionHost {\n\t\tconst current = () =>\n\t\t\tref.connection !== undefined && this.#connection === ref.connection;\n\t\treturn {\n\t\t\tregistry: this.#registry,\n\t\t\tserver: this.#server,\n\t\t\tappName: this.#appName,\n\t\t\tlibrary: { name: LIBRARY_NAME, version: VERSION },\n\t\t\tconfirm: (request) => this.#confirm(request),\n\t\t\t// Both always, even from a connection that is no longer current: a\n\t\t\t// call that started must end, and every end has its start.\n\t\t\ttoolCallStarted: (call) => this.#emit(\"toolcall\", call),\n\t\t\ttoolCallEnded: (call) => this.#emit(\"toolcallend\", call),\n\t\t\tclientFor: (grant: GrantRef): ToolCallClient => {\n\t\t\t\tconst known = this.#grants.find((g) => g.grantId === grant.grantId);\n\t\t\t\tconst client: ToolCallClient = {\n\t\t\t\t\tgrantId: grant.grantId,\n\t\t\t\t\tid: grant.clientId,\n\t\t\t\t\thost: hostOf(grant.clientId),\n\t\t\t\t};\n\t\t\t\tif (known !== undefined) client.name = known.client.name;\n\t\t\t\treturn client;\n\t\t\t},\n\t\t\tsessionStarted: (m) => {\n\t\t\t\tconst session = sessionInfo(m);\n\t\t\t\tif (!current()) return session;\n\t\t\t\tthis.#session = session;\n\t\t\t\tthis.#setState(\"connected\");\n\t\t\t\tthis.#setGrants([...m.grants]);\n\t\t\t\tif (this.#pairing) this.#connection?.send({ type: \"pairing.start\" });\n\t\t\t\tthis.#emit(\"connected\", session);\n\t\t\t\treturn session;\n\t\t\t},\n\t\t\tpairingCode: (code) => {\n\t\t\t\tif (current() && this.#pairing) this.#setPairingCode(code);\n\t\t\t},\n\t\t\tgrantAdded: (grant) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants([\n\t\t\t\t\t...this.#grants.filter((g) => g.grantId !== grant.grantId),\n\t\t\t\t\tgrant,\n\t\t\t\t]);\n\t\t\t},\n\t\t\tgrantRemoved: (grantId) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#setGrants(this.#grants.filter((g) => g.grantId !== grantId));\n\t\t\t},\n\t\t\treplaced: () => {\n\t\t\t\tif (current()) this.#emit(\"replaced\", null);\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tif (current()) this.#emit(\"error\", { error });\n\t\t\t},\n\t\t\tclosed: (reason: DisconnectReason, code: number) => {\n\t\t\t\tif (!current()) return;\n\t\t\t\tthis.#connection = undefined;\n\t\t\t\tthis.#session = undefined;\n\t\t\t\tthis.#setPairingCode(undefined);\n\t\t\t\tthis.#setState(\"disconnected\");\n\t\t\t\tthis.#emit(\"disconnected\", { reason, code });\n\t\t\t},\n\t\t};\n\t}\n}\n"
|
|
10
10
|
],
|
|
11
11
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,MAAM,cAAc;AAAA,EACjB,SAAS,IAAI;AAAA,EAEtB,GAAG,CAAC,SAAiB,MAAuB;AAAA,IAC3C,OAAO,KAAK,OAAO,IAAI,OAAO,GAAG,IAAI,IAAI,MAAM;AAAA;AAAA,EAGhD,GAAG,CAAC,SAAiB,MAAoB;AAAA,IACxC,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK,IAAI;AAAA,IAC9C,MAAM,IAAI,IAAI;AAAA,IACd,KAAK,OAAO,IAAI,SAAS,KAAK;AAAA;AAAA,EAI/B,UAAU,CAAC,UAAkC;AAAA,IAC5C,MAAM,OAAO,IAAI,IAAI,QAAQ;AAAA,IAC7B,WAAW,WAAW,KAAK,OAAO,KAAK,GAAG;AAAA,MACzC,IAAI,CAAC,KAAK,IAAI,OAAO;AAAA,QAAG,KAAK,OAAO,OAAO,OAAO;AAAA,IACnD;AAAA;AAAA,EAID,SAAS,CAAC,OAA+B;AAAA,IACxC,MAAM,OAAO,IAAI,IAAI,KAAK;AAAA,IAC1B,WAAW,SAAS,KAAK,OAAO,OAAO,GAAG;AAAA,M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W;AAAA,UACf,GAAG,KAAK,QAAQ,OAAO,CAAC,MAAM,EAAE,YAAY,MAAM,OAAO;AAAA,UACzD;AAAA,QACD,CAAC;AAAA;AAAA,MAEF,cAAc,CAAC,YAAY;AAAA,QAC1B,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAChB,KAAK,WAAW,KAAK,QAAQ,OAAO,CAAC,MAAM,EAAE,YAAY,OAAO,CAAC;AAAA;AAAA,MAElE,UAAU,MAAM;AAAA,QACf,IAAI,QAAQ;AAAA,UAAG,KAAK,MAAM,YAAY,IAAI;AAAA;AAAA,MAE3C,OAAO,CAAC,UAAU;AAAA,QACjB,IAAI,QAAQ;AAAA,UAAG,KAAK,MAAM,SAAS,EAAE,MAAM,CAAC;AAAA;AAAA,MAE7C,QAAQ,CAAC,QAA0B,SAAiB;AAAA,QACnD,IAAI,CAAC,QAAQ;AAAA,UAAG;AAAA,QAChB,KAAK,cAAc;AAAA,QACnB,KAAK,WAAW;AAAA,QAChB,KAAK,gBAAgB,SAAS;AAAA,QAC9B,KAAK,UAAU,cAAc;AAAA,QAC7B,KAAK,MAAM,gBAAgB,EAAE,QAAQ,KAAK,CAAC;AAAA;AAAA,IAE7C;AAAA;AAEF;",
|
|
12
|
-
"debugId": "
|
|
12
|
+
"debugId": "BC5CBAEE1DA9DD7C64756E2164756E21",
|
|
13
13
|
"names": []
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -17,6 +17,25 @@ function button(doc, text, onClick) {
|
|
|
17
17
|
node.addEventListener("click", onClick);
|
|
18
18
|
return node;
|
|
19
19
|
}
|
|
20
|
+
function copyButton(doc, noun, value, select) {
|
|
21
|
+
const node = button(doc, "Copy", () => {
|
|
22
|
+
const done = () => {
|
|
23
|
+
node.textContent = "Copied";
|
|
24
|
+
node.setAttribute("aria-label", `Copied ${noun}`);
|
|
25
|
+
};
|
|
26
|
+
const clipboard = doc.defaultView?.navigator?.clipboard;
|
|
27
|
+
if (clipboard !== undefined)
|
|
28
|
+
clipboard.writeText(value()).then(done, select);
|
|
29
|
+
else
|
|
30
|
+
select();
|
|
31
|
+
});
|
|
32
|
+
const reset = () => {
|
|
33
|
+
node.textContent = "Copy";
|
|
34
|
+
node.setAttribute("aria-label", `Copy ${noun}`);
|
|
35
|
+
};
|
|
36
|
+
reset();
|
|
37
|
+
return { button: node, reset };
|
|
38
|
+
}
|
|
20
39
|
function newDialog(doc, className, title) {
|
|
21
40
|
const id = `tab-mcp-${++counter}`;
|
|
22
41
|
const dialog = el(doc, "dialog", {
|
|
@@ -128,6 +147,8 @@ function listOf(items) {
|
|
|
128
147
|
}
|
|
129
148
|
function showConnectDialog(mcp, connecting, doc) {
|
|
130
149
|
const { dialog } = newDialog(doc, "tab-mcp-connect", "Connect your AI app");
|
|
150
|
+
dialog.tabIndex = -1;
|
|
151
|
+
dialog.style.setProperty("outline", "none");
|
|
131
152
|
const status = el(doc, "p", {
|
|
132
153
|
className: "tab-mcp-status",
|
|
133
154
|
text: "Connecting…"
|
|
@@ -143,16 +164,8 @@ function showConnectDialog(mcp, connecting, doc) {
|
|
|
143
164
|
address.readOnly = true;
|
|
144
165
|
address.style.setProperty("width", "100%");
|
|
145
166
|
address.style.setProperty("font-family", "var(--tab-mcp-mono, monospace)");
|
|
146
|
-
const copy =
|
|
147
|
-
|
|
148
|
-
copy.textContent = "Copied";
|
|
149
|
-
};
|
|
150
|
-
const clipboard = doc.defaultView?.navigator?.clipboard;
|
|
151
|
-
if (clipboard !== undefined)
|
|
152
|
-
clipboard.writeText(address.value).then(done, () => address.select());
|
|
153
|
-
else
|
|
154
|
-
address.select();
|
|
155
|
-
});
|
|
167
|
+
const { button: copy, reset: resetCopy } = copyButton(doc, "address", () => address.value, () => address.select());
|
|
168
|
+
copy.className = "tab-mcp-address-copy";
|
|
156
169
|
const fresh = button(doc, "New address", () => askNewAddress());
|
|
157
170
|
fresh.className = "tab-mcp-new-address";
|
|
158
171
|
const addressBox = el(doc, "div", { className: "tab-mcp-address" }, label, address, " ", copy, " ", fresh);
|
|
@@ -171,17 +184,58 @@ function showConnectDialog(mcp, connecting, doc) {
|
|
|
171
184
|
const code = el(doc, "strong", { className: "tab-mcp-code-value" });
|
|
172
185
|
code.style.setProperty("font-size", "var(--tab-mcp-code-size, 1.5em)");
|
|
173
186
|
code.style.setProperty("letter-spacing", "0.1em");
|
|
174
|
-
|
|
187
|
+
code.style.setProperty("font-family", "var(--tab-mcp-mono, monospace)");
|
|
188
|
+
code.style.setProperty("user-select", "all");
|
|
189
|
+
code.style.setProperty("-webkit-user-select", "all");
|
|
190
|
+
const { button: copyCode, reset: resetCopyCode } = copyButton(doc, "code", () => code.textContent ?? "", () => doc.getSelection()?.selectAllChildren(code));
|
|
191
|
+
copyCode.className = "tab-mcp-code-copy";
|
|
192
|
+
const codeSentence = el(doc, "span", {}, "When asked, enter the code ", code);
|
|
193
|
+
codeSentence.setAttribute("aria-live", "polite");
|
|
194
|
+
const codeLine = el(doc, "p", { className: "tab-mcp-code" }, codeSentence, " ", copyCode, el(doc, "br"), el(doc, "small", {
|
|
175
195
|
className: "tab-mcp-code-note",
|
|
176
196
|
text: "A new code appears every 2 minutes and after each use."
|
|
177
197
|
}));
|
|
178
|
-
codeLine.setAttribute("aria-live", "polite");
|
|
179
198
|
const steps = el(doc, "ul");
|
|
180
199
|
const help = el(doc, "details", { className: "tab-mcp-help" }, el(doc, "summary", { text: "How do I add it?" }), steps);
|
|
181
200
|
const appList = el(doc, "ul");
|
|
182
201
|
const apps = el(doc, "div", { className: "tab-mcp-apps" }, el(doc, "h3", { text: "Connected" }), appList);
|
|
202
|
+
const closeNote = el(doc, "small", {
|
|
203
|
+
className: "tab-mcp-close-note",
|
|
204
|
+
text: "Closing this stops the code. The address stays the same: to connect later, open this again from the page."
|
|
205
|
+
});
|
|
183
206
|
const close = button(doc, "Close", () => dialog.close());
|
|
184
|
-
|
|
207
|
+
close.className = "tab-mcp-close";
|
|
208
|
+
close.style.setProperty("font-size", "0.875em");
|
|
209
|
+
const done = button(doc, "Done", () => dialog.close());
|
|
210
|
+
done.className = "tab-mcp-done";
|
|
211
|
+
done.style.setProperty("font-weight", "bold");
|
|
212
|
+
done.hidden = true;
|
|
213
|
+
const actions = el(doc, "div", { className: "tab-mcp-actions" }, closeNote, " ", close, done);
|
|
214
|
+
actions.style.setProperty("display", "flex");
|
|
215
|
+
actions.style.setProperty("align-items", "center");
|
|
216
|
+
actions.style.setProperty("justify-content", "flex-end");
|
|
217
|
+
actions.style.setProperty("gap", "0.75rem");
|
|
218
|
+
actions.style.setProperty("margin-top", "1rem");
|
|
219
|
+
closeNote.style.setProperty("flex", "1");
|
|
220
|
+
let paired = false;
|
|
221
|
+
const pairedGrants = new Set;
|
|
222
|
+
const renderCloseNote = () => {
|
|
223
|
+
closeNote.hidden = paired || codeLine.hidden;
|
|
224
|
+
};
|
|
225
|
+
const setPaired = (value) => {
|
|
226
|
+
paired = value;
|
|
227
|
+
if (!paired)
|
|
228
|
+
pairedGrants.clear();
|
|
229
|
+
const focused = doc.activeElement;
|
|
230
|
+
renderCloseNote();
|
|
231
|
+
close.hidden = paired;
|
|
232
|
+
done.hidden = !paired;
|
|
233
|
+
if (paired && focused === close)
|
|
234
|
+
done.focus();
|
|
235
|
+
if (!paired && focused === done)
|
|
236
|
+
close.focus();
|
|
237
|
+
};
|
|
238
|
+
const closer = () => paired ? done : close;
|
|
185
239
|
dialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);
|
|
186
240
|
addressBox.hidden = true;
|
|
187
241
|
codeLine.hidden = true;
|
|
@@ -206,6 +260,7 @@ function showConnectDialog(mcp, connecting, doc) {
|
|
|
206
260
|
cancelNew.focus();
|
|
207
261
|
};
|
|
208
262
|
const getNewAddress = () => {
|
|
263
|
+
setPaired(false);
|
|
209
264
|
close.focus();
|
|
210
265
|
confirmBox.hidden = true;
|
|
211
266
|
renewing = true;
|
|
@@ -213,11 +268,11 @@ function showConnectDialog(mcp, connecting, doc) {
|
|
|
213
268
|
mcp.newAddress().then(() => {
|
|
214
269
|
renewing = false;
|
|
215
270
|
status.textContent = "This is a new address. Add it to your AI app again.";
|
|
216
|
-
|
|
271
|
+
copy.focus();
|
|
217
272
|
}, (error) => {
|
|
218
273
|
renewing = false;
|
|
219
274
|
status.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;
|
|
220
|
-
|
|
275
|
+
closer().focus();
|
|
221
276
|
});
|
|
222
277
|
};
|
|
223
278
|
const renderSession = (session) => {
|
|
@@ -228,29 +283,46 @@ function showConnectDialog(mcp, connecting, doc) {
|
|
|
228
283
|
return;
|
|
229
284
|
}
|
|
230
285
|
address.value = session.address;
|
|
231
|
-
|
|
286
|
+
resetCopy();
|
|
232
287
|
const appName = session.appName ?? mcp.appName;
|
|
233
288
|
if (!renewing)
|
|
234
289
|
status.textContent = appName !== undefined ? `${appName} is ready for your AI app.` : "This page is ready for your AI app.";
|
|
235
290
|
fresh.disabled = mcp.state !== "connected";
|
|
236
291
|
addressBox.hidden = false;
|
|
292
|
+
if (doc.activeElement === dialog)
|
|
293
|
+
copy.focus();
|
|
237
294
|
help.hidden = false;
|
|
238
295
|
steps.replaceChildren(...INSTRUCTIONS.map(([app, how]) => el(doc, "li", {}, el(doc, "strong", { text: app }), `: ${how.replace("ADDRESS", session.address)}`)));
|
|
239
296
|
};
|
|
240
297
|
const renderCode = () => {
|
|
241
298
|
const current = mcp.pairingCode;
|
|
299
|
+
if (code.textContent !== (current?.code ?? ""))
|
|
300
|
+
resetCopyCode();
|
|
242
301
|
code.textContent = current?.code ?? "";
|
|
243
302
|
codeLine.hidden = current === undefined;
|
|
303
|
+
renderCloseNote();
|
|
244
304
|
};
|
|
245
305
|
const appsNote = el(doc, "p", { className: "tab-mcp-apps-note" });
|
|
246
306
|
apps.append(appsNote);
|
|
247
307
|
const known = new Set(mcp.grants.map((g) => g.grantId));
|
|
308
|
+
let session = mcp.session;
|
|
248
309
|
const renderGrants = () => {
|
|
310
|
+
if (mcp.session !== session) {
|
|
311
|
+
session = mcp.session;
|
|
312
|
+
for (const grant of mcp.grants)
|
|
313
|
+
known.add(grant.grantId);
|
|
314
|
+
}
|
|
249
315
|
for (const grant of mcp.grants) {
|
|
250
316
|
if (known.has(grant.grantId))
|
|
251
317
|
continue;
|
|
252
318
|
known.add(grant.grantId);
|
|
253
319
|
status.textContent = `${clientLabel(grant.client)} is connected.`;
|
|
320
|
+
pairedGrants.add(grant.grantId);
|
|
321
|
+
if (!paired)
|
|
322
|
+
setPaired(true);
|
|
323
|
+
}
|
|
324
|
+
if (paired && !mcp.grants.some((g) => pairedGrants.has(g.grantId))) {
|
|
325
|
+
setPaired(false);
|
|
254
326
|
}
|
|
255
327
|
const connected = mcp.state === "connected";
|
|
256
328
|
appList.replaceChildren(...mcp.grants.map((grant) => {
|
|
@@ -303,7 +375,10 @@ function showConnectDialog(mcp, connecting, doc) {
|
|
|
303
375
|
resolve();
|
|
304
376
|
}, { once: true });
|
|
305
377
|
dialog.showModal();
|
|
306
|
-
|
|
378
|
+
if (!addressBox.hidden)
|
|
379
|
+
copy.focus();
|
|
380
|
+
else
|
|
381
|
+
dialog.focus();
|
|
307
382
|
});
|
|
308
383
|
}
|
|
309
384
|
export {
|
|
@@ -311,5 +386,5 @@ export {
|
|
|
311
386
|
showConnectDialog
|
|
312
387
|
};
|
|
313
388
|
|
|
314
|
-
//# debugId=
|
|
315
|
-
//# sourceMappingURL=ui-
|
|
389
|
+
//# debugId=7945246CA610C8F364756E2164756E21
|
|
390
|
+
//# sourceMappingURL=ui-g1k2g5hm.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ui.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\n/**\n * A Copy button for `value()`, read at click time. Shows \"Copied\" once the\n * clipboard took it; without a clipboard (or when it refuses) `select()` puts\n * the text in the selection for Ctrl+C instead. `noun` names it for assistive\n * technology (\"Copy code\"), as the dialog has more than one Copy.\n */\nfunction copyButton(\n\tdoc: Document,\n\tnoun: string,\n\tvalue: () => string,\n\tselect: () => void,\n): { button: HTMLButtonElement; reset: () => void } {\n\tconst node = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tnode.textContent = \"Copied\";\n\t\t\tnode.setAttribute(\"aria-label\", `Copied ${noun}`);\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(value()).then(done, select);\n\t\telse select();\n\t});\n\tconst reset = () => {\n\t\tnode.textContent = \"Copy\";\n\t\tnode.setAttribute(\"aria-label\", `Copy ${noun}`);\n\t};\n\treset();\n\treturn { button: node, reset };\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn JSON.stringify(args, null, 2);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/**\n * Ask whether a consequential tool may run. \"Allow\" and \"Always allow\" stay\n * disabled for `allowDelayMs` (default 750, at least 500) after the dialog\n * opens, so a click meant for the page cannot approve. Everything else\n * (Don't allow, Escape, an aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tconst always = button(doc, \"Always allow\", () => {\n\t\tif (!always.disabled) dialog.close(\"always\");\n\t});\n\tallow.disabled = true;\n\talways.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t\t\" \",\n\t\talways,\n\t);\n\tconst alwaysNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-always-note\",\n\t\ttext: `Always allow: ${title} runs without asking for ${clientLabel(request.client)} until you reload this page or disconnect it.`,\n\t});\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tallow.hidden = true;\n\t\talways.hidden = true;\n\t\talwaysNote.hidden = true;\n\t}\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\n\t\t}),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\talwaysNote,\n\t);\n\tdoc.body.append(dialog);\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t\talways.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code (with Copy) while the relay sends one,\n * and the connected apps with Disconnect. Pairing is on while it is open, so\n * closing it ends the code; the connection and the address stay. Until an app\n * connects, only a small Close (and Escape) close it; then a Done. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\t// Focusable from script only, for the moment before the address is shown.\n\tdialog.tabIndex = -1;\n\tdialog.style.setProperty(\"outline\", \"none\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst { button: copy, reset: resetCopy } = copyButton(\n\t\tdoc,\n\t\t\"address\",\n\t\t() => address.value,\n\t\t() => address.select(),\n\t);\n\tcopy.className = \"tab-mcp-address-copy\";\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tcode.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\t// One click selects the whole code; it stays plain, selectable text.\n\tcode.style.setProperty(\"user-select\", \"all\");\n\tcode.style.setProperty(\"-webkit-user-select\", \"all\");\n\t// Reads the code shown at click time, so a rotated code is copied as shown.\n\tconst { button: copyCode, reset: resetCopyCode } = copyButton(\n\t\tdoc,\n\t\t\"code\",\n\t\t() => code.textContent ?? \"\",\n\t\t() => doc.getSelection()?.selectAllChildren(code),\n\t);\n\tcopyCode.className = \"tab-mcp-code-copy\";\n\t// Only the sentence with the code is announced when the code changes,\n\t// not its Copy button's \"Copied\".\n\tconst codeSentence = el(doc, \"span\", {}, \"When asked, enter the code \", code);\n\tcodeSentence.setAttribute(\"aria-live\", \"polite\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\tcodeSentence,\n\t\t\" \",\n\t\tcopyCode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\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: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\t// Until an app connects in this dialog, closing it is not the next step:\n\t// a small Close at the end, saying what closing does (the code stops, the\n\t// address stays). Once one connects, a prominent Done replaces both.\n\tconst closeNote = el(doc, \"small\", {\n\t\tclassName: \"tab-mcp-close-note\",\n\t\ttext: \"Closing this stops the code. The address stays the same: to connect later, open this again from the page.\",\n\t});\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tclose.className = \"tab-mcp-close\";\n\tclose.style.setProperty(\"font-size\", \"0.875em\");\n\tconst done = button(doc, \"Done\", () => dialog.close());\n\tdone.className = \"tab-mcp-done\";\n\tdone.style.setProperty(\"font-weight\", \"bold\");\n\tdone.hidden = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tcloseNote,\n\t\t\" \",\n\t\tclose,\n\t\tdone,\n\t);\n\t// The note on the left, the button at the far right, apart from the code.\n\tactions.style.setProperty(\"display\", \"flex\");\n\tactions.style.setProperty(\"align-items\", \"center\");\n\tactions.style.setProperty(\"justify-content\", \"flex-end\");\n\tactions.style.setProperty(\"gap\", \"0.75rem\");\n\tactions.style.setProperty(\"margin-top\", \"1rem\");\n\tcloseNote.style.setProperty(\"flex\", \"1\");\n\t// An app connected while this dialog is open (since the last new address),\n\t// and still connected: the grants that made it so.\n\tlet paired = false;\n\tconst pairedGrants = new Set<string>();\n\t// The note is about the code: only while one is shown and nothing paired.\n\tconst renderCloseNote = () => {\n\t\tcloseNote.hidden = paired || codeLine.hidden;\n\t};\n\tconst setPaired = (value: boolean) => {\n\t\tpaired = value;\n\t\tif (!paired) pairedGrants.clear();\n\t\tconst focused = doc.activeElement;\n\t\trenderCloseNote();\n\t\tclose.hidden = paired;\n\t\tdone.hidden = !paired;\n\t\t// Focus never stays on a control that was just hidden.\n\t\tif (paired && focused === close) done.focus();\n\t\tif (!paired && focused === done) close.focus();\n\t};\n\t// The visible button that closes the dialog.\n\tconst closer = () => (paired ? done : close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// The apps are disconnected: the next one has to pair again.\n\t\tsetPaired(false);\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tcopy.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tcloser().focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tresetCopy();\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\t// Opened before the session was known: start at the address's Copy.\n\t\tif (doc.activeElement === dialog) copy.focus();\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\t// A new code is not copied yet.\n\t\tif (code.textContent !== (current?.code ?? \"\")) resetCopyCode();\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t\trenderCloseNote();\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\t// Grants that come with a (new) session were there before; only the ones\n\t// added during a session are new connections.\n\tlet session = mcp.session;\n\tconst renderGrants = () => {\n\t\tif (mcp.session !== session) {\n\t\t\tsession = mcp.session;\n\t\t\tfor (const grant of mcp.grants) known.add(grant.grantId);\n\t\t}\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t\tpairedGrants.add(grant.grantId);\n\t\t\tif (!paired) setPaired(true);\n\t\t}\n\t\t// The app that connected here is gone again (Disconnect, or revoked):\n\t\t// back to Close and the note, the code still runs.\n\t\tif (paired && !mcp.grants.some((g) => pairedGrants.has(g.grantId))) {\n\t\t\tsetPaired(false);\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\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 the address's Copy; until the address is there, at the\n\t\t// dialog itself (its title is read out), not at Close.\n\t\tif (!addressBox.hidden) copy.focus();\n\t\telse dialog.focus();\n\t});\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAiBA,IAAI,UAAU;AAEd,SAAS,EAAyC,CACjD,KACA,KACA,QAA4D,CAAC,MAC1D,UACwB;AAAA,EAC3B,MAAM,OAAO,IAAI,cAAc,GAAG;AAAA,EAClC,IAAI,MAAM,cAAc;AAAA,IAAW,KAAK,YAAY,MAAM;AAAA,EAC1D,IAAI,MAAM,OAAO;AAAA,IAAW,KAAK,KAAK,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,MACL,IAAI,YAAY;AAAA,MAChB,IAAI,oBAAoB,eAAe,UAAU;AAAA,MACjD,IAAI,oBAAoB,gBAAgB,YAAY;AAAA,MACpD,IAAI,oBAAoB,aAAa,WAAW;AAAA,MAChD,IAAI,oBAAoB,gBAAgB,cAAc;AAAA,MACtD,OAAO,OAAO;AAAA,MACd,QAAQ;AAAA,OAET,EAAE,MAAM,KAAK,CACd;AAAA,IACA,OAAO,UAAU;AAAA,IAGjB,IAAI,CAAC,WAAW;AAAA,MAAQ,KAAK,MAAM;AAAA,IAC9B;AAAA,aAAO,MAAM;AAAA,GAClB;AAAA;",
|
|
8
|
+
"debugId": "7945246CA610C8F364756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/ui.d.ts
CHANGED
|
@@ -23,8 +23,10 @@ export declare function confirmDialog(request: ConfirmRequest, doc: Document, op
|
|
|
23
23
|
}): Promise<ConfirmAnswer>;
|
|
24
24
|
/**
|
|
25
25
|
* The "Connect your AI app" dialog: the address with Copy and New address,
|
|
26
|
-
* short instructions, the pairing code while the relay sends one,
|
|
27
|
-
* connected apps with Disconnect. Pairing is on while it is open
|
|
26
|
+
* short instructions, the pairing code (with Copy) while the relay sends one,
|
|
27
|
+
* and the connected apps with Disconnect. Pairing is on while it is open, so
|
|
28
|
+
* closing it ends the code; the connection and the address stay. Until an app
|
|
29
|
+
* connects, only a small Close (and Escape) close it; then a Done. New address
|
|
28
30
|
* asks first when it would disconnect connected apps (`newAddress()` revokes
|
|
29
31
|
* them).
|
|
30
32
|
*/
|
package/version.d.ts
CHANGED
package/cdn/ui-zmrhb8xg.min.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
var M=0;function s(e,o,t={},...i){let a=e.createElement(o);if(t.className!==void 0)a.className=t.className;if(t.id!==void 0)a.id=t.id;if(t.text!==void 0)a.textContent=t.text;return a.append(...i),a}function m(e,o,t){let i=s(e,"button",{text:o});return i.type="button",i.addEventListener("click",t),i}function B(e,o,t){let i=`tab-mcp-${++M}`,a=s(e,"dialog",{className:`tab-mcp-dialog ${o}`});a.setAttribute("aria-labelledby",`${i}-title`);let r=a.style;r.setProperty("max-width","var(--tab-mcp-max-width, 34rem)"),r.setProperty("font","var(--tab-mcp-font, inherit)"),r.setProperty("color","var(--tab-mcp-color, CanvasText)"),r.setProperty("background","var(--tab-mcp-background, Canvas)"),r.setProperty("border","var(--tab-mcp-border, 1px solid GrayText)"),r.setProperty("border-radius","var(--tab-mcp-radius, 0.5rem)"),r.setProperty("padding","var(--tab-mcp-padding, 1rem 1.25rem)");let p=s(e,"h2",{id:`${i}-title`,text:t});return p.style.setProperty("margin-top","0"),p.style.setProperty("font-size","var(--tab-mcp-title-size, 1.25em)"),a.append(p),{dialog:a,heading:p}}function x(e){let o=e.host||e.id;return e.name!==void 0&&e.name!==""?`${e.name} (${o})`:o}function V(e){try{return JSON.stringify(e,null,2)}catch{return}}var Y=750,F=500;function U(e,o,t={}){let i=Math.max(F,t.allowDelayMs??Y);if(e.signal.aborted)return Promise.resolve("deny");let a=e.tool.title??e.tool.name,{dialog:r}=B(o,"tab-mcp-confirm",`Allow ${a}?`),p=m(o,"Don't allow",()=>r.close("deny")),d=m(o,"Allow",()=>{if(!d.disabled)r.close("allow")}),u=m(o,"Always allow",()=>{if(!u.disabled)r.close("always")});d.disabled=!0,u.disabled=!0;let h=s(o,"div",{className:"tab-mcp-actions"},p," ",d," ",u),b=s(o,"p",{className:"tab-mcp-always-note",text:`Always allow: ${a} runs without asking for ${x(e.client)} until you reload this page or disconnect it.`}),w=V(e.arguments),g=s(o,"pre",{className:"tab-mcp-arguments",text:w??"The arguments cannot be shown, so this call cannot be allowed."});if(w===void 0)d.hidden=!0,u.hidden=!0,b.hidden=!0;return g.style.setProperty("white-space","pre-wrap"),g.style.setProperty("max-height","12rem"),g.style.setProperty("overflow","auto"),g.hidden=Object.keys(e.arguments).length===0,r.append(s(o,"p",{text:`${x(e.client)} wants to run ${a}.`}),s(o,"p",{className:"tab-mcp-description",text:e.tool.description}),g,h,b),o.body.append(r),new Promise((N)=>{let v=()=>r.close("deny");e.signal.addEventListener("abort",v,{once:!0});let l;r.addEventListener("close",()=>{clearTimeout(l),e.signal.removeEventListener("abort",v);let f=r.returnValue;r.remove(),N(f==="allow"||f==="always"?f:"deny")},{once:!0}),r.showModal(),p.focus(),l=setTimeout(()=>{d.disabled=!1,u.disabled=!1},i)})}var J=[["Claude (claude.ai and the desktop app)","Settings → Connectors → Add custom connector, then paste the address."],["ChatGPT","Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address."],["Claude Code","Run: claude mcp add --transport http tools ADDRESS"]];function Q(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function X(e,o,t){let{dialog:i}=B(t,"tab-mcp-connect","Connect your AI app"),a=s(t,"p",{className:"tab-mcp-status",text:"Connecting…"});a.setAttribute("role","status");let r=`tab-mcp-${++M}-address`,p=s(t,"label",{text:"Add this address to your AI app:"});p.htmlFor=r;let d=s(t,"input",{id:r,className:"tab-mcp-address-input"});d.readOnly=!0,d.style.setProperty("width","100%"),d.style.setProperty("font-family","var(--tab-mcp-mono, monospace)");let u=m(t,"Copy",()=>{let n=()=>{u.textContent="Copied"},c=t.defaultView?.navigator?.clipboard;if(c!==void 0)c.writeText(d.value).then(n,()=>d.select());else d.select()}),h=m(t,"New address",()=>W());h.className="tab-mcp-new-address";let b=s(t,"div",{className:"tab-mcp-address"},p,d," ",u," ",h),w=`tab-mcp-${++M}-new-address`,g=s(t,"p",{id:w}),N=m(t,"Cancel",()=>{l.hidden=!0,h.focus()}),v=m(t,"Disconnect and get new address",()=>O());v.className="tab-mcp-new-address-confirm";let l=s(t,"div",{className:"tab-mcp-new-address-question"},g,s(t,"div",{className:"tab-mcp-actions"},N," ",v));l.setAttribute("role","group"),l.setAttribute("aria-labelledby",w),l.hidden=!0;let f=s(t,"strong",{className:"tab-mcp-code-value"});f.style.setProperty("font-size","var(--tab-mcp-code-size, 1.5em)"),f.style.setProperty("letter-spacing","0.1em");let A=s(t,"p",{className:"tab-mcp-code"},"When asked, enter the code ",f,s(t,"br"),s(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."}));A.setAttribute("aria-live","polite");let k=s(t,"ul"),L=s(t,"details",{className:"tab-mcp-help"},s(t,"summary",{text:"How do I add it?"}),k),R=s(t,"ul"),T=s(t,"div",{className:"tab-mcp-apps"},s(t,"h3",{text:"Connected"}),R),C=m(t,"Close",()=>i.close()),K=s(t,"div",{className:"tab-mcp-actions"},C);i.append(a,b,l,A,L,T,K),b.hidden=!0,A.hidden=!0,L.hidden=!0,T.hidden=!0;let D=!1,H=()=>{let n=e.grants.map((c)=>x(c.client));if(n.length===0)return!1;return g.textContent=`A new address disconnects ${Q(n)}. To use this page again, add the new address to ${n.length===1?"it":"them"}.`,!0},W=()=>{if(e.state!=="connected")return;if(!H()){O();return}l.hidden=!1,N.focus()},O=()=>{C.focus(),l.hidden=!0,D=!0,a.textContent="Getting a new address…",e.newAddress().then(()=>{D=!1,a.textContent="This is a new address. Add it to your AI app again.",C.focus()},(n)=>{D=!1,a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}. Close this and connect again.`,C.focus()})},E=(n)=>{if(n===void 0){b.hidden=!0,l.hidden=!0,L.hidden=!0;return}d.value=n.address,u.textContent="Copy";let c=n.appName??e.appName;if(!D)a.textContent=c!==void 0?`${c} is ready for your AI app.`:"This page is ready for your AI app.";h.disabled=e.state!=="connected",b.hidden=!1,L.hidden=!1,k.replaceChildren(...J.map(([I,j])=>s(t,"li",{},s(t,"strong",{text:I}),`: ${j.replace("ADDRESS",n.address)}`)))},P=()=>{let n=e.pairingCode;f.textContent=n?.code??"",A.hidden=n===void 0},S=s(t,"p",{className:"tab-mcp-apps-note"});T.append(S);let G=new Set(e.grants.map((n)=>n.grantId)),y=()=>{for(let c of e.grants){if(G.has(c.grantId))continue;G.add(c.grantId),a.textContent=`${x(c.client)} is connected.`}let n=e.state==="connected";if(R.replaceChildren(...e.grants.map((c)=>{let I=m(t,"Disconnect",()=>{if(!e.revoke(c.grantId))y()});return I.disabled=!n,s(t,"li",{},`${x(c.client)} connected `,I)})),S.textContent=n?"":"To disconnect an app, connect this page again first.",S.hidden=n,T.hidden=e.grants.length===0,!l.hidden&&!H())l.hidden=!0,h.focus()},_=(n)=>{if(n.detail.reason!=="new_address")a.textContent="Disconnected. AI apps can use this page again after you connect.";E(void 0),y(),P()},z=()=>{E(e.session),y()};return e.addEventListener("pairingcode",P),e.addEventListener("grantschange",y),e.addEventListener("connected",z),e.addEventListener("disconnected",_),t.body.append(i),e.startPairing(),y(),P(),E(e.session),o.then((n)=>E(n),(n)=>{a.textContent=`Could not connect: ${n instanceof Error?n.message:String(n)}`}),new Promise((n)=>{i.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",P),e.removeEventListener("grantschange",y),e.removeEventListener("connected",z),e.removeEventListener("disconnected",_),i.remove(),n()},{once:!0}),i.showModal(),C.focus()})}export{U as confirmDialog,X as showConnectDialog};
|
|
2
|
-
|
|
3
|
-
//# debugId=B932565F1A8EDC6A64756E2164756E21
|
|
4
|
-
//# sourceMappingURL=ui-zmrhb8xg.min.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/ui.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn JSON.stringify(args, null, 2);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/**\n * Ask whether a consequential tool may run. \"Allow\" and \"Always allow\" stay\n * disabled for `allowDelayMs` (default 750, at least 500) after the dialog\n * opens, so a click meant for the page cannot approve. Everything else\n * (Don't allow, Escape, an aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tconst always = button(doc, \"Always allow\", () => {\n\t\tif (!always.disabled) dialog.close(\"always\");\n\t});\n\tallow.disabled = true;\n\talways.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t\t\" \",\n\t\talways,\n\t);\n\tconst alwaysNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-always-note\",\n\t\ttext: `Always allow: ${title} runs without asking for ${clientLabel(request.client)} until you reload this page or disconnect it.`,\n\t});\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tallow.hidden = true;\n\t\talways.hidden = true;\n\t\talwaysNote.hidden = true;\n\t}\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\n\t\t}),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\talwaysNote,\n\t);\n\tdoc.body.append(dialog);\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t\talways.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code while the relay sends one, and the\n * connected apps with Disconnect. Pairing is on while it is open. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\n\t});\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\tcodeLine.setAttribute(\"aria-live\", \"polite\");\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: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tclose.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tclose.focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tcopy.textContent = \"Copy\";\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\tconst renderGrants = () => {\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\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\tclose.focus();\n\t});\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": "AAiBA,IAAI,EAAU,EAEd,SAAS,CAAyC,CACjD,EACA,EACA,EAA4D,CAAC,KAC1D,EACwB,CAC3B,IAAM,EAAO,EAAI,cAAc,CAAG,EAClC,GAAI,EAAM,YAAc,OAAW,EAAK,UAAY,EAAM,UAC1D,GAAI,EAAM,KAAO,OAAW,EAAK,GAAK,EAAM,GAC5C,GAAI,EAAM,OAAS,OAAW,EAAK,YAAc,EAAM,KAEvD,OADA,EAAK,OAAO,GAAG,CAAQ,EAChB,EAGR,SAAS,CAAM,CACd,EACA,EACA,EACoB,CACpB,IAAM,EAAO,EAAG,EAAK,SAAU,CAAE,MAAK,CAAC,EAGvC,OAFA,EAAK,KAAO,SACZ,EAAK,iBAAiB,QAAS,CAAO,EAC/B,EAGR,SAAS,CAAS,CACjB,EACA,EACA,EAC6D,CAC7D,IAAM,EAAK,WAAW,EAAE,IAClB,EAAS,EAAG,EAAK,SAAU,CAChC,UAAW,kBAAkB,GAC9B,CAAC,EACD,EAAO,aAAa,kBAAmB,GAAG,SAAU,EAEpD,IAAM,EAAQ,EAAO,MACrB,EAAM,YAAY,YAAa,iCAAiC,EAChE,EAAM,YAAY,OAAQ,8BAA8B,EACxD,EAAM,YAAY,QAAS,kCAAkC,EAC7D,EAAM,YAAY,aAAc,mCAAmC,EACnE,EAAM,YAAY,SAAU,2CAA2C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AoB,cAAe,CAAU,EACjD,EAAI,oBAAoB,eAAgB,CAAY,EACpD,EAAI,oBAAoB,YAAa,CAAW,EAChD,EAAI,oBAAoB,eAAgB,CAAc,EACtD,EAAO,OAAO,EACd,EAAQ,GAET,CAAE,KAAM,EAAK,CACd,EACA,EAAO,UAAU,EACjB,EAAM,MAAM,EACZ",
|
|
8
|
-
"debugId": "B932565F1A8EDC6A64756E2164756E21",
|
|
9
|
-
"names": []
|
|
10
|
-
}
|
package/ui-wrm46a0a.js.map
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/ui.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * The default UI, loaded on demand: the \"Connect your AI app\" dialog\n * (DEC-028) and the confirmation of consequential tools. Plain `<dialog>`\n * elements, no styles beyond a few CSS custom properties (`--tab-mcp-*`), all\n * text set with `textContent`. Pages with their own UI use the events and\n * methods of `TabMcp` instead.\n */\n\nimport type { TabMcp } from \"./tab-mcp.ts\";\nimport type {\n\tConfirmRequest,\n\tDisconnectDetail,\n\tGrant,\n\tSessionInfo,\n\tToolCallClient,\n} from \"./types.ts\";\n\nlet counter = 0;\n\nfunction el<K extends keyof HTMLElementTagNameMap>(\n\tdoc: Document,\n\ttag: K,\n\tprops: { className?: string; text?: string; id?: string } = {},\n\t...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n\tconst node = doc.createElement(tag);\n\tif (props.className !== undefined) node.className = props.className;\n\tif (props.id !== undefined) node.id = props.id;\n\tif (props.text !== undefined) node.textContent = props.text;\n\tnode.append(...children);\n\treturn node;\n}\n\nfunction button(\n\tdoc: Document,\n\ttext: string,\n\tonClick: () => void,\n): HTMLButtonElement {\n\tconst node = el(doc, \"button\", { text });\n\tnode.type = \"button\";\n\tnode.addEventListener(\"click\", onClick);\n\treturn node;\n}\n\nfunction newDialog(\n\tdoc: Document,\n\tclassName: string,\n\ttitle: string,\n): { dialog: HTMLDialogElement; heading: HTMLHeadingElement } {\n\tconst id = `tab-mcp-${++counter}`;\n\tconst dialog = el(doc, \"dialog\", {\n\t\tclassName: `tab-mcp-dialog ${className}`,\n\t});\n\tdialog.setAttribute(\"aria-labelledby\", `${id}-title`);\n\t// CSSOM properties are allowed under a strict CSP (no inline style attribute).\n\tconst style = dialog.style;\n\tstyle.setProperty(\"max-width\", \"var(--tab-mcp-max-width, 34rem)\");\n\tstyle.setProperty(\"font\", \"var(--tab-mcp-font, inherit)\");\n\tstyle.setProperty(\"color\", \"var(--tab-mcp-color, CanvasText)\");\n\tstyle.setProperty(\"background\", \"var(--tab-mcp-background, Canvas)\");\n\tstyle.setProperty(\"border\", \"var(--tab-mcp-border, 1px solid GrayText)\");\n\tstyle.setProperty(\"border-radius\", \"var(--tab-mcp-radius, 0.5rem)\");\n\tstyle.setProperty(\"padding\", \"var(--tab-mcp-padding, 1rem 1.25rem)\");\n\tconst heading = el(doc, \"h2\", { id: `${id}-title`, text: title });\n\theading.style.setProperty(\"margin-top\", \"0\");\n\theading.style.setProperty(\"font-size\", \"var(--tab-mcp-title-size, 1.25em)\");\n\tdialog.append(heading);\n\treturn { dialog, heading };\n}\n\nfunction clientLabel(client: ToolCallClient | Grant[\"client\"]): string {\n\tconst host = client.host || client.id;\n\treturn client.name !== undefined && client.name !== \"\"\n\t\t? `${client.name} (${host})`\n\t\t: host;\n}\n\n/**\n * The arguments as text, in full: what the user approves must be visible.\n * (The relay caps a request at 1 MiB, so this stays bounded.) `undefined`\n * when they cannot be shown, and then \"Allow\" is not offered.\n */\nfunction showArguments(args: Record<string, unknown>): string | undefined {\n\ttry {\n\t\treturn JSON.stringify(args, null, 2);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** How long \"Allow\" stays disabled after the confirmation opens, and the floor. */\nexport const ALLOW_DELAY_MS = 750;\nexport const MIN_ALLOW_DELAY_MS = 500;\n\n/** The user's answer: \"always\" allows this tool for this AI app from now on. */\nexport type ConfirmAnswer = \"allow\" | \"always\" | \"deny\";\n\n/**\n * Ask whether a consequential tool may run. \"Allow\" and \"Always allow\" stay\n * disabled for `allowDelayMs` (default 750, at least 500) after the dialog\n * opens, so a click meant for the page cannot approve. Everything else\n * (Don't allow, Escape, an aborted call) is \"deny\".\n */\nexport function confirmDialog(\n\trequest: ConfirmRequest,\n\tdoc: Document,\n\toptions: { allowDelayMs?: number } = {},\n): Promise<ConfirmAnswer> {\n\tconst delay = Math.max(\n\t\tMIN_ALLOW_DELAY_MS,\n\t\toptions.allowDelayMs ?? ALLOW_DELAY_MS,\n\t);\n\tif (request.signal.aborted) return Promise.resolve(\"deny\");\n\tconst title = request.tool.title ?? request.tool.name;\n\tconst { dialog } = newDialog(doc, \"tab-mcp-confirm\", `Allow ${title}?`);\n\tconst deny = button(doc, \"Don't allow\", () => dialog.close(\"deny\"));\n\tconst allow = button(doc, \"Allow\", () => {\n\t\tif (!allow.disabled) dialog.close(\"allow\");\n\t});\n\tconst always = button(doc, \"Always allow\", () => {\n\t\tif (!always.disabled) dialog.close(\"always\");\n\t});\n\tallow.disabled = true;\n\talways.disabled = true;\n\tconst actions = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-actions\" },\n\t\tdeny,\n\t\t\" \",\n\t\tallow,\n\t\t\" \",\n\t\talways,\n\t);\n\tconst alwaysNote = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-always-note\",\n\t\ttext: `Always allow: ${title} runs without asking for ${clientLabel(request.client)} until you reload this page or disconnect it.`,\n\t});\n\tconst shown = showArguments(request.arguments);\n\tconst args = el(doc, \"pre\", {\n\t\tclassName: \"tab-mcp-arguments\",\n\t\ttext:\n\t\t\tshown ?? \"The arguments cannot be shown, so this call cannot be allowed.\",\n\t});\n\tif (shown === undefined) {\n\t\tallow.hidden = true;\n\t\talways.hidden = true;\n\t\talwaysNote.hidden = true;\n\t}\n\targs.style.setProperty(\"white-space\", \"pre-wrap\");\n\targs.style.setProperty(\"max-height\", \"12rem\");\n\targs.style.setProperty(\"overflow\", \"auto\");\n\targs.hidden = Object.keys(request.arguments).length === 0;\n\tdialog.append(\n\t\tel(doc, \"p\", {\n\t\t\ttext: `${clientLabel(request.client)} wants to run ${title}.`,\n\t\t}),\n\t\tel(doc, \"p\", {\n\t\t\tclassName: \"tab-mcp-description\",\n\t\t\ttext: request.tool.description,\n\t\t}),\n\t\targs,\n\t\tactions,\n\t\talwaysNote,\n\t);\n\tdoc.body.append(dialog);\n\treturn new Promise((resolve) => {\n\t\tconst onAbort = () => dialog.close(\"deny\");\n\t\trequest.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\trequest.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tconst value = dialog.returnValue;\n\t\t\t\tdialog.remove();\n\t\t\t\tresolve(value === \"allow\" || value === \"always\" ? value : \"deny\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\tdialog.showModal();\n\t\tdeny.focus(); // the safe choice is the default\n\t\t// Counted from when the dialog is shown, not from when it was built.\n\t\ttimer = setTimeout(() => {\n\t\t\tallow.disabled = false;\n\t\t\talways.disabled = false;\n\t\t}, delay);\n\t});\n}\n\nconst INSTRUCTIONS: [string, string][] = [\n\t[\n\t\t\"Claude (claude.ai and the desktop app)\",\n\t\t\"Settings → Connectors → Add custom connector, then paste the address.\",\n\t],\n\t[\n\t\t\"ChatGPT\",\n\t\t\"Settings → Apps and connectors → Advanced settings: turn on developer mode, then Create and paste the address.\",\n\t],\n\t[\"Claude Code\", \"Run: claude mcp add --transport http tools ADDRESS\"],\n];\n\n/** \"A and B\", \"A, B and C\". */\nfunction listOf(items: string[]): string {\n\treturn items.length < 2\n\t\t? (items[0] ?? \"\")\n\t\t: `${items.slice(0, -1).join(\", \")} and ${items.at(-1)}`;\n}\n\n/**\n * The \"Connect your AI app\" dialog: the address with Copy and New address,\n * short instructions, the pairing code while the relay sends one, and the\n * connected apps with Disconnect. Pairing is on while it is open. New address\n * asks first when it would disconnect connected apps (`newAddress()` revokes\n * them).\n */\nexport function showConnectDialog(\n\tmcp: TabMcp,\n\tconnecting: Promise<SessionInfo>,\n\tdoc: Document,\n): Promise<void> {\n\tconst { dialog } = newDialog(doc, \"tab-mcp-connect\", \"Connect your AI app\");\n\tconst status = el(doc, \"p\", {\n\t\tclassName: \"tab-mcp-status\",\n\t\ttext: \"Connecting…\",\n\t});\n\tstatus.setAttribute(\"role\", \"status\");\n\n\tconst addressId = `tab-mcp-${++counter}-address`;\n\tconst label = el(doc, \"label\", { text: \"Add this address to your AI app:\" });\n\tlabel.htmlFor = addressId;\n\tconst address = el(doc, \"input\", {\n\t\tid: addressId,\n\t\tclassName: \"tab-mcp-address-input\",\n\t});\n\taddress.readOnly = true;\n\taddress.style.setProperty(\"width\", \"100%\");\n\taddress.style.setProperty(\"font-family\", \"var(--tab-mcp-mono, monospace)\");\n\tconst copy = button(doc, \"Copy\", () => {\n\t\tconst done = () => {\n\t\t\tcopy.textContent = \"Copied\";\n\t\t};\n\t\tconst clipboard = (doc.defaultView?.navigator as Navigator | undefined)\n\t\t\t?.clipboard;\n\t\tif (clipboard !== undefined)\n\t\t\tclipboard.writeText(address.value).then(done, () => address.select());\n\t\telse address.select();\n\t});\n\tconst fresh = button(doc, \"New address\", () => askNewAddress());\n\tfresh.className = \"tab-mcp-new-address\";\n\tconst addressBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-address\" },\n\t\tlabel,\n\t\taddress,\n\t\t\" \",\n\t\tcopy,\n\t\t\" \",\n\t\tfresh,\n\t);\n\n\t// Asked in the dialog before New address disconnects connected apps.\n\tconst confirmId = `tab-mcp-${++counter}-new-address`;\n\tconst confirmText = el(doc, \"p\", { id: confirmId });\n\tconst cancelNew = button(doc, \"Cancel\", () => {\n\t\tconfirmBox.hidden = true;\n\t\tfresh.focus();\n\t});\n\tconst confirmNew = button(doc, \"Disconnect and get new address\", () =>\n\t\tgetNewAddress(),\n\t);\n\tconfirmNew.className = \"tab-mcp-new-address-confirm\";\n\tconst confirmBox = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-new-address-question\" },\n\t\tconfirmText,\n\t\tel(\n\t\t\tdoc,\n\t\t\t\"div\",\n\t\t\t{ className: \"tab-mcp-actions\" },\n\t\t\tcancelNew,\n\t\t\t\" \",\n\t\t\tconfirmNew,\n\t\t),\n\t);\n\tconfirmBox.setAttribute(\"role\", \"group\");\n\tconfirmBox.setAttribute(\"aria-labelledby\", confirmId);\n\tconfirmBox.hidden = true;\n\n\tconst code = el(doc, \"strong\", { className: \"tab-mcp-code-value\" });\n\tcode.style.setProperty(\"font-size\", \"var(--tab-mcp-code-size, 1.5em)\");\n\tcode.style.setProperty(\"letter-spacing\", \"0.1em\");\n\tconst codeLine = el(\n\t\tdoc,\n\t\t\"p\",\n\t\t{ className: \"tab-mcp-code\" },\n\t\t\"When asked, enter the code \",\n\t\tcode,\n\t\tel(doc, \"br\"),\n\t\tel(doc, \"small\", {\n\t\t\tclassName: \"tab-mcp-code-note\",\n\t\t\ttext: \"A new code appears every 2 minutes and after each use.\",\n\t\t}),\n\t);\n\tcodeLine.setAttribute(\"aria-live\", \"polite\");\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: \"How do I add it?\" }),\n\t\tsteps,\n\t);\n\n\tconst appList = el(doc, \"ul\");\n\tconst apps = el(\n\t\tdoc,\n\t\t\"div\",\n\t\t{ className: \"tab-mcp-apps\" },\n\t\tel(doc, \"h3\", { text: \"Connected\" }),\n\t\tappList,\n\t);\n\n\tconst close = button(doc, \"Close\", () => dialog.close());\n\tconst actions = el(doc, \"div\", { className: \"tab-mcp-actions\" }, close);\n\n\tdialog.append(status, addressBox, confirmBox, codeLine, help, apps, actions);\n\taddressBox.hidden = true;\n\tcodeLine.hidden = true;\n\thelp.hidden = true;\n\tapps.hidden = true;\n\n\t// Set while New address waits for the new session.\n\tlet renewing = false;\n\t// The question names the apps connected now; pairing goes on while it is open.\n\tconst renderQuestion = (): boolean => {\n\t\tconst names = mcp.grants.map((g) => clientLabel(g.client));\n\t\tif (names.length === 0) return false;\n\t\tconfirmText.textContent = `A new address disconnects ${listOf(names)}. To use this page again, add the new address to ${names.length === 1 ? \"it\" : \"them\"}.`;\n\t\treturn true;\n\t};\n\tconst askNewAddress = () => {\n\t\tif (mcp.state !== \"connected\") return;\n\t\tif (!renderQuestion()) {\n\t\t\tgetNewAddress();\n\t\t\treturn;\n\t\t}\n\t\tconfirmBox.hidden = false;\n\t\tcancelNew.focus(); // the safe choice is the default\n\t};\n\tconst getNewAddress = () => {\n\t\t// Focus moves before the focused control is hidden.\n\t\tclose.focus();\n\t\tconfirmBox.hidden = true;\n\t\trenewing = true;\n\t\tstatus.textContent = \"Getting a new address…\";\n\t\t// Called from the click, so the reconnect has the user action it needs.\n\t\tmcp.newAddress().then(\n\t\t\t() => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent =\n\t\t\t\t\t\"This is a new address. Add it to your AI app again.\";\n\t\t\t\tclose.focus();\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\trenewing = false;\n\t\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}. Close this and connect again.`;\n\t\t\t\tclose.focus();\n\t\t\t},\n\t\t);\n\t};\n\tconst renderSession = (session: SessionInfo | undefined) => {\n\t\tif (session === undefined) {\n\t\t\taddressBox.hidden = true;\n\t\t\tconfirmBox.hidden = true;\n\t\t\thelp.hidden = true;\n\t\t\treturn;\n\t\t}\n\t\taddress.value = session.address;\n\t\tcopy.textContent = \"Copy\";\n\t\tconst appName = session.appName ?? mcp.appName;\n\t\tif (!renewing)\n\t\t\tstatus.textContent =\n\t\t\t\tappName !== undefined\n\t\t\t\t\t? `${appName} is ready for your AI app.`\n\t\t\t\t\t: \"This page is ready for your AI app.\";\n\t\tfresh.disabled = mcp.state !== \"connected\";\n\t\taddressBox.hidden = false;\n\t\thelp.hidden = false;\n\t\tsteps.replaceChildren(\n\t\t\t...INSTRUCTIONS.map(([app, how]) =>\n\t\t\t\tel(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\tel(doc, \"strong\", { text: app }),\n\t\t\t\t\t`: ${how.replace(\"ADDRESS\", session.address)}`,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\tconst renderCode = () => {\n\t\tconst current = mcp.pairingCode;\n\t\tcode.textContent = current?.code ?? \"\";\n\t\tcodeLine.hidden = current === undefined;\n\t};\n\tconst appsNote = el(doc, \"p\", { className: \"tab-mcp-apps-note\" });\n\tapps.append(appsNote);\n\t// Grants that were there when the dialog opened; a new one is announced.\n\tconst known = new Set(mcp.grants.map((g) => g.grantId));\n\tconst renderGrants = () => {\n\t\tfor (const grant of mcp.grants) {\n\t\t\tif (known.has(grant.grantId)) continue;\n\t\t\tknown.add(grant.grantId);\n\t\t\tstatus.textContent = `${clientLabel(grant.client)} is connected.`;\n\t\t}\n\t\tconst connected = mcp.state === \"connected\";\n\t\tappList.replaceChildren(\n\t\t\t...mcp.grants.map((grant) => {\n\t\t\t\tconst disconnect = button(doc, \"Disconnect\", () => {\n\t\t\t\t\tif (!mcp.revoke(grant.grantId)) renderGrants();\n\t\t\t\t});\n\t\t\t\t// Only the relay can revoke, so only while connected.\n\t\t\t\tdisconnect.disabled = !connected;\n\t\t\t\treturn el(\n\t\t\t\t\tdoc,\n\t\t\t\t\t\"li\",\n\t\t\t\t\t{},\n\t\t\t\t\t`${clientLabel(grant.client)} connected `,\n\t\t\t\t\tdisconnect,\n\t\t\t\t);\n\t\t\t}),\n\t\t);\n\t\tappsNote.textContent = connected\n\t\t\t? \"\"\n\t\t\t: \"To disconnect an app, connect this page again first.\";\n\t\tappsNote.hidden = connected;\n\t\tapps.hidden = mcp.grants.length === 0;\n\t\tif (!confirmBox.hidden && !renderQuestion()) {\n\t\t\t// Nobody left to disconnect: no question needed.\n\t\t\tconfirmBox.hidden = true;\n\t\t\tfresh.focus();\n\t\t}\n\t};\n\tconst onDisconnected = (event: CustomEvent<DisconnectDetail>) => {\n\t\tif (event.detail.reason !== \"new_address\")\n\t\t\tstatus.textContent =\n\t\t\t\t\"Disconnected. AI apps can use this page again after you connect.\";\n\t\trenderSession(undefined);\n\t\trenderGrants();\n\t\trenderCode();\n\t};\n\tconst onConnected = () => {\n\t\trenderSession(mcp.session);\n\t\trenderGrants();\n\t};\n\n\tmcp.addEventListener(\"pairingcode\", renderCode);\n\tmcp.addEventListener(\"grantschange\", renderGrants);\n\tmcp.addEventListener(\"connected\", onConnected);\n\tmcp.addEventListener(\"disconnected\", onDisconnected);\n\tdoc.body.append(dialog);\n\tmcp.startPairing();\n\trenderGrants();\n\trenderCode();\n\trenderSession(mcp.session);\n\tconnecting.then(\n\t\t(session) => renderSession(session),\n\t\t(error: unknown) => {\n\t\t\tstatus.textContent = `Could not connect: ${error instanceof Error ? error.message : String(error)}`;\n\t\t},\n\t);\n\n\treturn new Promise((resolve) => {\n\t\tdialog.addEventListener(\n\t\t\t\"close\",\n\t\t\t() => {\n\t\t\t\tmcp.stopPairing();\n\t\t\t\tmcp.removeEventListener(\"pairingcode\", renderCode);\n\t\t\t\tmcp.removeEventListener(\"grantschange\", renderGrants);\n\t\t\t\tmcp.removeEventListener(\"connected\", onConnected);\n\t\t\t\tmcp.removeEventListener(\"disconnected\", onDisconnected);\n\t\t\t\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\tclose.focus();\n\t});\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";AAiBA,IAAI,UAAU;AAEd,SAAS,EAAyC,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