@ractive-ch/tab-mcp-client 0.7.0 → 0.9.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 +93 -11
- package/address.d.ts +14 -0
- package/cdn/connection-0x5mr3te.min.js +11 -0
- package/cdn/connection-0x5mr3te.min.js.map +21 -0
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +5 -6
- package/cdn/ui-cssy9seq.min.js +72 -0
- package/cdn/ui-cssy9seq.min.js.map +11 -0
- package/{connection-p94fg1r9.js → connection-eqqkev02.js} +177 -11
- package/connection-eqqkev02.js.map +15 -0
- package/connection.d.ts +20 -2
- package/icons.d.ts +13 -0
- package/index.d.ts +1 -1
- package/index.js +44 -59
- package/index.js.map +5 -6
- package/internal.d.ts +8 -2
- package/package.json +1 -1
- package/protocol.d.ts +2 -0
- package/tab-mcp.d.ts +7 -3
- package/types.d.ts +47 -2
- package/{ui-gkxbbn8v.js → ui-zyst9kn6.js} +133 -23
- package/ui-zyst9kn6.js.map +11 -0
- package/ui.d.ts +28 -8
- package/version.d.ts +1 -1
- package/cdn/connection-nygehv52.min.js +0 -11
- package/cdn/connection-nygehv52.min.js.map +0 -19
- package/cdn/ui-n9c73wge.min.js +0 -72
- package/cdn/ui-n9c73wge.min.js.map +0 -10
- package/connection-p94fg1r9.js.map +0 -13
- package/ui-gkxbbn8v.js.map +0 -10
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
function oe(e,t){let o=typeof e;if(o!==typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;let s=e.length;if(s!==t.length)return!1;for(let i=0;i<s;i++)if(!oe(e[i],t[i]))return!1;return!0}if(o==="object"){if(!e||!t)return e===t;let s=Object.keys(e),i=Object.keys(t);if(s.length!==i.length)return!1;for(let n of s)if(!oe(e[n],t[n]))return!1;return!0}return e===t}function H(e){return encodeURI(st(e))}function st(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var it={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},dt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},at={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},ut=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function X(e,t=Object.create(null),o=ut,s=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let d=e.$id||e.id;if(d){let n=new URL(d,o.href);if(n.hash.length>1)t[n.href]=e;else if(n.hash="",s==="")o=n;else X(e,t,o)}}else if(e!==!0&&e!==!1)return t;let i=o.href+(s?"#"+s:"");if(t[i]!==void 0)throw Error(`Duplicate schema URI "${i}".`);if(t[i]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:i});if(e.$ref&&e.__absolute_ref__===void 0){let d=new URL(e.$ref,o.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:d.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let d=new URL(e.$recursiveRef,o.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:d.href})}if(e.$anchor){let d=new URL("#"+e.$anchor,o.href);t[d.href]=e}for(let d in e){if(at[d])continue;let n=`${s}/${H(d)}`,l=e[d];if(Array.isArray(l)){if(it[d]){let T=l.length;for(let q=0;q<T;q++)X(l[q],t,o,`${n}/${q}`)}}else if(dt[d])for(let T in l)X(l[T],t,o,`${n}/${H(T)}`);else X(l,t,o,n)}return t}var lt=/^(\d\d\d\d)-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'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,wt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Rt=(e)=>{if(e[0]==='"')return!1;let[t,o,...s]=e.split("@");if(!t||!o||s.length!==0||t.length>64||o.length>253)return!1;if(t[0]==="."||t.endsWith(".")||t.includes(".."))return!1;if(!/^[a-z0-9.-]+$/i.test(o)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t))return!1;return o.split(".").every((i)=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(i))},kt=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,xt=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,Tt=(e)=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function B(e){return e.test.bind(e)}var Te={date:Ce,time:Ne.bind(void 0,!1),"date-time":vt,duration:Tt,uri:Ot,"uri-reference":B(yt),"uri-template":B(mt),url:B(gt),email:Rt,hostname:B(pt),ipv4:B(kt),ipv6:B(xt),regex:At,uuid:B(ht),"json-pointer":B($t),"json-pointer-uri-fragment":B(bt),"relative-json-pointer":B(wt)};function It(e){return e%4===0&&(e%100!==0||e%400===0)}function Ce(e){let t=e.match(lt);if(!t)return!1;let o=+t[1],s=+t[2],i=+t[3];return s>=1&&s<=12&&i>=1&&i<=(s==2&&It(o)?29:ft[s])}function Ne(e,t){let o=t.match(ct);if(!o)return!1;let s=+o[1],i=+o[2],d=+o[3],n=!!o[5];return(s<=23&&i<=59&&d<=59||s==23&&i==59&&d==60)&&(!e||n)}var _t=/t|\s/i;function vt(e){let t=e.split(_t);return t.length==2&&Ce(t[0])&&Ne(!0,t[1])}var Mt=/\/|:/,St=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(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=/[^\\]\\Z/;function At(e){if(Et.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function qe(e){let t=0,o=e.length,s=0,i;while(s<o)if(t++,i=e.charCodeAt(s++),i>=55296&&i<=56319&&s<o){if(i=e.charCodeAt(s),(i&64512)==56320)s++}return t}function O(e,t,o="2019-09",s=X(t),i=!0,d=null,n="#",l="#",T=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:n,keyword:"false",keywordLocation:n,error:"False boolean schema."}]};let q=typeof e,_;switch(q){case"boolean":case"number":case"string":_=q;break;case"object":if(e===null)_="null";else if(Array.isArray(e))_="array";else _="object";break;default:throw Error(`Instances of "${q}" type are not supported.`)}let{$ref:U,$recursiveRef:ne,$recursiveAnchor:G,type:C,const:K,enum:E,required:Z,not:u,anyOf:m,allOf:x,oneOf:I,if:r,then:y,else:b,format:k,properties:v,patternProperties:M,additionalProperties:J,unevaluatedProperties:P,minProperties:V,maxProperties:A,propertyNames:j,dependentRequired:W,dependentSchemas:ae,dependencies:we,prefixItems:Re,items:ue,additionalItems:Me,unevaluatedItems:Se,contains:Oe,minContains:Y,maxContains:ce,minItems:ke,maxItems:xe,uniqueItems:nt,minimum:L,maximum:ee,exclusiveMinimum:le,exclusiveMaximum:fe,multipleOf:pe,minLength:ye,maxLength:me,pattern:Ee,__absolute_ref__:ge,__absolute_recursive_ref__:ot}=t,f=[];if(G===!0&&d===null)d=t;if(ne==="#"){let g=d===null?s[ot]:d,p=`${l}/$recursiveRef`,R=O(e,d===null?t:d,o,s,i,g,n,p,T);if(!R.valid)f.push({instanceLocation:n,keyword:"$recursiveRef",keywordLocation:p,error:"A subschema had errors."},...R.errors)}if(U!==void 0){let p=s[ge||U];if(p===void 0){let a=`Unresolved $ref "${U}".`;if(ge&&ge!==U)a+=` Absolute URI "${ge}".`;throw a+=`
|
|
2
|
-
Known schemas:
|
|
3
|
-
- ${Object.keys(s).join(`
|
|
4
|
-
- `)}`,Error(a)}let R=`${l}/$ref`,c=O(e,p,o,s,i,d,n,R,T);if(!c.valid)f.push({instanceLocation:n,keyword:"$ref",keywordLocation:R,error:"A subschema had errors."},...c.errors);if(o==="4"||o==="7")return{valid:f.length===0,errors:f}}if(Array.isArray(C)){let g=C.length,p=!1;for(let R=0;R<g;R++)if(_===C[R]||C[R]==="integer"&&_==="number"&&e%1===0&&e===e){p=!0;break}if(!p)f.push({instanceLocation:n,keyword:"type",keywordLocation:`${l}/type`,error:`Instance type "${_}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(_!=="number"||e%1||e!==e)f.push({instanceLocation:n,keyword:"type",keywordLocation:`${l}/type`,error:`Instance type "${_}" is invalid. Expected "${C}".`})}else if(C!==void 0&&_!==C)f.push({instanceLocation:n,keyword:"type",keywordLocation:`${l}/type`,error:`Instance type "${_}" is invalid. Expected "${C}".`});if(K!==void 0){if(_==="object"||_==="array"){if(!oe(e,K))f.push({instanceLocation:n,keyword:"const",keywordLocation:`${l}/const`,error:`Instance does not match ${JSON.stringify(K)}.`})}else if(e!==K)f.push({instanceLocation:n,keyword:"const",keywordLocation:`${l}/const`,error:`Instance does not match ${JSON.stringify(K)}.`})}if(E!==void 0){if(_==="object"||_==="array"){if(!E.some((g)=>oe(e,g)))f.push({instanceLocation:n,keyword:"enum",keywordLocation:`${l}/enum`,error:`Instance does not match any of ${JSON.stringify(E)}.`})}else if(!E.some((g)=>e===g))f.push({instanceLocation:n,keyword:"enum",keywordLocation:`${l}/enum`,error:`Instance does not match any of ${JSON.stringify(E)}.`})}if(u!==void 0){let g=`${l}/not`;if(O(e,u,o,s,i,d,n,g).valid)f.push({instanceLocation:n,keyword:"not",keywordLocation:g,error:'Instance matched "not" schema.'})}let he=[];if(m!==void 0){let g=`${l}/anyOf`,p=f.length,R=!1;for(let c=0;c<m.length;c++){let a=m[c],w=Object.create(T),h=O(e,a,o,s,i,G===!0?d:null,n,`${g}/${c}`,w);if(f.push(...h.errors),R=R||h.valid,h.valid)he.push(w)}if(R)f.length=p;else f.splice(p,0,{instanceLocation:n,keyword:"anyOf",keywordLocation:g,error:"Instance does not match any subschemas."})}if(x!==void 0){let g=`${l}/allOf`,p=f.length,R=!0;for(let c=0;c<x.length;c++){let a=x[c],w=Object.create(T),h=O(e,a,o,s,i,G===!0?d:null,n,`${g}/${c}`,w);if(f.push(...h.errors),R=R&&h.valid,h.valid)he.push(w)}if(R)f.length=p;else f.splice(p,0,{instanceLocation:n,keyword:"allOf",keywordLocation:g,error:"Instance does not match every subschema."})}if(I!==void 0){let g=`${l}/oneOf`,p=f.length,R=I.filter((c,a)=>{let w=Object.create(T),h=O(e,c,o,s,i,G===!0?d:null,n,`${g}/${a}`,w);if(f.push(...h.errors),h.valid)he.push(w);return h.valid}).length;if(R===1)f.length=p;else f.splice(p,0,{instanceLocation:n,keyword:"oneOf",keywordLocation:g,error:`Instance does not match exactly one subschema (${R} matches).`})}if(_==="object"||_==="array")Object.assign(T,...he);if(r!==void 0){let g=`${l}/if`;if(O(e,r,o,s,i,d,n,g,T).valid){if(y!==void 0){let R=O(e,y,o,s,i,d,n,`${l}/then`,T);if(!R.valid)f.push({instanceLocation:n,keyword:"if",keywordLocation:g,error:'Instance does not match "then" schema.'},...R.errors)}}else if(b!==void 0){let R=O(e,b,o,s,i,d,n,`${l}/else`,T);if(!R.valid)f.push({instanceLocation:n,keyword:"if",keywordLocation:g,error:'Instance does not match "else" schema.'},...R.errors)}}if(_==="object"){if(Z!==void 0){for(let c of Z)if(!(c in e))f.push({instanceLocation:n,keyword:"required",keywordLocation:`${l}/required`,error:`Instance does not have required property "${c}".`})}let g=Object.keys(e);if(V!==void 0&&g.length<V)f.push({instanceLocation:n,keyword:"minProperties",keywordLocation:`${l}/minProperties`,error:`Instance does not have at least ${V} properties.`});if(A!==void 0&&g.length>A)f.push({instanceLocation:n,keyword:"maxProperties",keywordLocation:`${l}/maxProperties`,error:`Instance does not have at least ${A} properties.`});if(j!==void 0){let c=`${l}/propertyNames`;for(let a in e){let w=`${n}/${H(a)}`,h=O(a,j,o,s,i,d,w,c);if(!h.valid)f.push({instanceLocation:n,keyword:"propertyNames",keywordLocation:c,error:`Property name "${a}" does not match schema.`},...h.errors)}}if(W!==void 0){let c=`${l}/dependantRequired`;for(let a in W)if(a in e){let w=W[a];for(let h of w)if(!(h in e))f.push({instanceLocation:n,keyword:"dependentRequired",keywordLocation:c,error:`Instance has "${a}" but does not have "${h}".`})}}if(ae!==void 0)for(let c in ae){let a=`${l}/dependentSchemas`;if(c in e){let w=O(e,ae[c],o,s,i,d,n,`${a}/${H(c)}`,T);if(!w.valid)f.push({instanceLocation:n,keyword:"dependentSchemas",keywordLocation:a,error:`Instance has "${c}" but does not match dependant schema.`},...w.errors)}}if(we!==void 0){let c=`${l}/dependencies`;for(let a in we)if(a in e){let w=we[a];if(Array.isArray(w)){for(let h of w)if(!(h in e))f.push({instanceLocation:n,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not have "${h}".`})}else{let h=O(e,w,o,s,i,d,n,`${c}/${H(a)}`);if(!h.valid)f.push({instanceLocation:n,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not match dependant schema.`},...h.errors)}}}let p=Object.create(null),R=!1;if(v!==void 0){let c=`${l}/properties`;for(let a in v){if(!(a in e))continue;let w=`${n}/${H(a)}`,h=O(e[a],v[a],o,s,i,d,w,`${c}/${H(a)}`);if(h.valid)T[a]=p[a]=!0;else if(R=i,f.push({instanceLocation:n,keyword:"properties",keywordLocation:c,error:`Property "${a}" does not match schema.`},...h.errors),R)break}}if(!R&&M!==void 0){let c=`${l}/patternProperties`;for(let a in M){let w=new RegExp(a,"u"),h=M[a];for(let z in e){if(!w.test(z))continue;let Ae=`${n}/${H(z)}`,Pe=O(e[z],h,o,s,i,d,Ae,`${c}/${H(a)}`);if(Pe.valid)T[z]=p[z]=!0;else R=i,f.push({instanceLocation:n,keyword:"patternProperties",keywordLocation:c,error:`Property "${z}" matches pattern "${a}" but does not match associated schema.`},...Pe.errors)}}}if(!R&&J!==void 0){let c=`${l}/additionalProperties`;for(let a in e){if(p[a])continue;let w=`${n}/${H(a)}`,h=O(e[a],J,o,s,i,d,w,c);if(h.valid)T[a]=!0;else R=i,f.push({instanceLocation:n,keyword:"additionalProperties",keywordLocation:c,error:`Property "${a}" does not match additional properties schema.`},...h.errors)}}else if(!R&&P!==void 0){let c=`${l}/unevaluatedProperties`;for(let a in e)if(!T[a]){let w=`${n}/${H(a)}`,h=O(e[a],P,o,s,i,d,w,c);if(h.valid)T[a]=!0;else f.push({instanceLocation:n,keyword:"unevaluatedProperties",keywordLocation:c,error:`Property "${a}" does not match unevaluated properties schema.`},...h.errors)}}}else if(_==="array"){if(xe!==void 0&&e.length>xe)f.push({instanceLocation:n,keyword:"maxItems",keywordLocation:`${l}/maxItems`,error:`Array has too many items (${e.length} > ${xe}).`});if(ke!==void 0&&e.length<ke)f.push({instanceLocation:n,keyword:"minItems",keywordLocation:`${l}/minItems`,error:`Array has too few items (${e.length} < ${ke}).`});let g=e.length,p=0,R=!1;if(Re!==void 0){let c=`${l}/prefixItems`,a=Math.min(Re.length,g);for(;p<a;p++){let w=O(e[p],Re[p],o,s,i,d,`${n}/${p}`,`${c}/${p}`);if(T[p]=!0,!w.valid){if(R=i,f.push({instanceLocation:n,keyword:"prefixItems",keywordLocation:c,error:"Items did not match schema."},...w.errors),R)break}}}if(ue!==void 0){let c=`${l}/items`;if(Array.isArray(ue)){let a=Math.min(ue.length,g);for(;p<a;p++){let w=O(e[p],ue[p],o,s,i,d,`${n}/${p}`,`${c}/${p}`);if(T[p]=!0,!w.valid){if(R=i,f.push({instanceLocation:n,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...w.errors),R)break}}}else for(;p<g;p++){let a=O(e[p],ue,o,s,i,d,`${n}/${p}`,c);if(T[p]=!0,!a.valid){if(R=i,f.push({instanceLocation:n,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...a.errors),R)break}}if(!R&&Me!==void 0){let a=`${l}/additionalItems`;for(;p<g;p++){let w=O(e[p],Me,o,s,i,d,`${n}/${p}`,a);if(T[p]=!0,!w.valid)R=i,f.push({instanceLocation:n,keyword:"additionalItems",keywordLocation:a,error:"Items did not match additional items schema."},...w.errors)}}}if(Oe!==void 0)if(g===0&&Y===void 0)f.push({instanceLocation:n,keyword:"contains",keywordLocation:`${l}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(Y!==void 0&&g<Y)f.push({instanceLocation:n,keyword:"minContains",keywordLocation:`${l}/minContains`,error:`Array has less items (${g}) than minContains (${Y}).`});else{let c=`${l}/contains`,a=f.length,w=0;for(let h=0;h<g;h++){let z=O(e[h],Oe,o,s,i,d,`${n}/${h}`,c);if(z.valid)T[h]=!0,w++;else f.push(...z.errors)}if(w>=(Y||0))f.length=a;if(Y===void 0&&ce===void 0&&w===0)f.splice(a,0,{instanceLocation:n,keyword:"contains",keywordLocation:c,error:"Array does not contain item matching schema."});else if(Y!==void 0&&w<Y)f.push({instanceLocation:n,keyword:"minContains",keywordLocation:`${l}/minContains`,error:`Array must contain at least ${Y} items matching schema. Only ${w} items were found.`});else if(ce!==void 0&&w>ce)f.push({instanceLocation:n,keyword:"maxContains",keywordLocation:`${l}/maxContains`,error:`Array may contain at most ${ce} items matching schema. ${w} items were found.`})}if(!R&&Se!==void 0){let c=`${l}/unevaluatedItems`;for(p;p<g;p++){if(T[p])continue;let a=O(e[p],Se,o,s,i,d,`${n}/${p}`,c);if(T[p]=!0,!a.valid)f.push({instanceLocation:n,keyword:"unevaluatedItems",keywordLocation:c,error:"Items did not match unevaluated items schema."},...a.errors)}}if(nt)for(let c=0;c<g;c++){let a=e[c],w=typeof a==="object"&&a!==null;for(let h=0;h<g;h++){if(c===h)continue;let z=e[h];if(a===z||w&&(typeof z==="object"&&z!==null)&&oe(a,z))f.push({instanceLocation:n,keyword:"uniqueItems",keywordLocation:`${l}/uniqueItems`,error:`Duplicate items at indexes ${c} and ${h}.`}),c=Number.MAX_SAFE_INTEGER,h=Number.MAX_SAFE_INTEGER}}}else if(_==="number"){if(o==="4"){if(L!==void 0&&(le===!0&&e<=L||e<L))f.push({instanceLocation:n,keyword:"minimum",keywordLocation:`${l}/minimum`,error:`${e} is less than ${le?"or equal to ":""} ${L}.`});if(ee!==void 0&&(fe===!0&&e>=ee||e>ee))f.push({instanceLocation:n,keyword:"maximum",keywordLocation:`${l}/maximum`,error:`${e} is greater than ${fe?"or equal to ":""} ${ee}.`})}else{if(L!==void 0&&e<L)f.push({instanceLocation:n,keyword:"minimum",keywordLocation:`${l}/minimum`,error:`${e} is less than ${L}.`});if(ee!==void 0&&e>ee)f.push({instanceLocation:n,keyword:"maximum",keywordLocation:`${l}/maximum`,error:`${e} is greater than ${ee}.`});if(le!==void 0&&e<=le)f.push({instanceLocation:n,keyword:"exclusiveMinimum",keywordLocation:`${l}/exclusiveMinimum`,error:`${e} is less than ${le}.`});if(fe!==void 0&&e>=fe)f.push({instanceLocation:n,keyword:"exclusiveMaximum",keywordLocation:`${l}/exclusiveMaximum`,error:`${e} is greater than or equal to ${fe}.`})}if(pe!==void 0){let g=e%pe;if(Math.abs(0-g)>=0.00000011920929&&Math.abs(pe-g)>=0.00000011920929)f.push({instanceLocation:n,keyword:"multipleOf",keywordLocation:`${l}/multipleOf`,error:`${e} is not a multiple of ${pe}.`})}}else if(_==="string"){let g=ye===void 0&&me===void 0?0:qe(e);if(ye!==void 0&&g<ye)f.push({instanceLocation:n,keyword:"minLength",keywordLocation:`${l}/minLength`,error:`String is too short (${g} < ${ye}).`});if(me!==void 0&&g>me)f.push({instanceLocation:n,keyword:"maxLength",keywordLocation:`${l}/maxLength`,error:`String is too long (${g} > ${me}).`});if(Ee!==void 0&&!new RegExp(Ee,"u").test(e))f.push({instanceLocation:n,keyword:"pattern",keywordLocation:`${l}/pattern`,error:"String does not match pattern."});if(k!==void 0&&Te[k]&&!Te[k](e))f.push({instanceLocation:n,keyword:"format",keywordLocation:`${l}/format`,error:`String does not match format "${k}".`})}return{valid:f.length===0,errors:f}}var ze="ch.ractive.tab-mcp/annotations",Pt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Ct=["destructiveHint","idempotentHint","openWorldHint"];function He(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let i of Ct){let d=e[i];if(d!==void 0)t[i]=d}let o={};for(let i of Pt){let d=e[i];if(d!==void 0)o[i]=d}let s={};if(Object.keys(t).length>0)s.annotations=t;if(Object.keys(o).length>0)s.meta=o;return s}function F(e){return{content:[{type:"text",text:e}],isError:!0}}function je(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Je(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(je(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return F("The tool returned a value that is not JSON.");let o={content:[{type:"text",text:t}]};if(je(e))o.structuredContent=e;return o}function Ue(e){let t=e instanceof Error?e.message:String(e);return F(t||"The tool failed.")}var te="2026-07-28",Q="io.modelcontextprotocol/protocolVersion",$e="io.modelcontextprotocol/clientCapabilities",Ve="io.modelcontextprotocol/clientInfo",Nt="io.modelcontextprotocol/serverInfo",Ie="io.modelcontextprotocol/subscriptionId",qt=-32020,Be=-32022,jt=0,De=new WeakMap;function _e(e){let t=De.get(e);if(t!==void 0)return t;let o=e.inputSchema,s;try{s=X(o)}catch(d){let n=d instanceof Error?d.message:String(d);throw Error(n.split(`
|
|
5
|
-
`)[0])}for(let d of Object.values(s)){if(typeof d!=="object"||d.$ref===void 0)continue;let n=d.__absolute_ref__;if(s[n??d.$ref]===void 0)throw Error(`$ref ${JSON.stringify(d.$ref)} does not resolve`)}let i=(d)=>O(d,o,"2020-12",s,!1);return De.set(e,i),i}function Ge(e,t,o=""){let s=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${s}${o}`)}function zt(e){let t=[];for(let o of e.list())try{_e(o)}catch(s){e.remove(o),t.push(Ge(o.name,s,"; the tool was unregistered"))}return e.setCompiler((o)=>{try{_e(o)}catch(s){throw Ge(o.name,s)}}),t}function Ke(e){try{return structuredClone(e)}catch{return e}}var Ht=new TextEncoder;function re(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function ve(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function N(e,t,o,s,i){let d={code:o,message:s};if(i!==void 0)d.data=i;return ve(e,{jsonrpc:"2.0",id:t,error:d})}function D(e,t,o){return N(400,e,qt,`Bad Request: the request headers and body disagree: ${o}`,{mismatch:{header:t,body:o}})}function se(e){return Ht.encode(`event: message
|
|
6
|
-
data: ${JSON.stringify(e)}
|
|
7
|
-
|
|
8
|
-
`)}var We={"content-type":"text/event-stream","cache-control":"no-cache"};function Jt(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function Ut(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let o=atob(t),s=Uint8Array.from(o,(i)=>i.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(s)}catch{return}}function Vt(e){if(!(Q in e))return{key:Q,problem:"missing"};if(!($e in e))return{key:$e,problem:"missing"};if(typeof e[Q]!=="string")return{key:Q,problem:"expected a protocol version string"};if(!re(e[$e]))return{key:$e,problem:"expected an object"};let t=e[Ve];if(t!==void 0&&!(re(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ve,problem:"expected {name, version}"};return}function Bt(e){let t=e.notifications;return re(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Ye(e){let{tools:t,server:o}=e,s={name:o.name,version:o.version};if(o.title!==void 0)s.title=o.title;let i=new Set,d=!1,n=(u={})=>({...u,[Nt]:s});function l(u,m){return{jsonrpc:"2.0",id:u,result:{...m,resultType:"complete",_meta:n()}}}function T(u,m){let x;try{x=_e(u)(m)}catch(r){let y=r instanceof Error?r.message:String(r);return`The input schema of tool ${u.name} cannot be used: ${y}`}if(x.valid)return;let I=x.errors.filter((r)=>r.keyword!=="properties"&&r.keyword!=="$ref").map((r)=>`${r.instanceLocation} ${r.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${u.name}: ${I||"the arguments do not match the schema"}`}function q(){return t.list().map((u)=>{let m={name:u.name};if(u.title!==void 0)m.title=u.title;m.description=u.description,m.inputSchema=u.inputSchema;let{annotations:x,meta:I}=He(u.annotations);if(x!==void 0)m.annotations=x;if(I!==void 0)m._meta={[ze]:I};return m})}let _=(u)=>({kind:"invalid",message:u});async function U(u,m,x){let I=u.name;if(typeof I!=="string")return _("Invalid params: name must be a string");let r=t.get(I);if(r===void 0)return _(`Tool ${I} not found`);let y=u.arguments??{};if(!re(y))return _("Invalid params: arguments must be an object");let b=e.client(x),k={id:++jt,tool:r.name,arguments:Ke(y),client:{...b}};if(r.title!==void 0)k.title=r.title;let v=Date.now();e.observe?.start(k);let M="error",J=F("Internal error");try{[M,J]=await ne(r,y,m,b)}finally{e.observe?.end({id:k.id,tool:r.name,client:{...b},outcome:M,result:Ke(J),durationMs:Date.now()-v})}return{kind:"result",result:J}}async function ne(u,m,x,I){let r=T(u,m);if(r!==void 0)return["error",F(r)];if(u.annotations.consequentialHint===!0){let b={tool:{name:u.name,description:u.description},arguments:m,client:I,signal:x};if(u.title!==void 0)b.tool.title=u.title;let k=!1;try{k=await e.confirm(b)}catch{k=!1}if(!k)return[x.aborted?"cancelled":"declined",F("The user declined")]}if(x.aborted)return["cancelled",F("Cancelled")];if(t.get(u.name)!==u)return["error",F("The tool is no longer available")];let y;try{y=Je(await u.execute(m,{signal:x,client:I}))}catch(b){y=Ue(b)}if(x.aborted)return["cancelled",y];return[y.isError===!0?"error":"ok",y]}function G(u,m,x,I){let r=new ReadableStream({start:(y)=>{let b=(k)=>{if(x.aborted)return;let v;try{v=se(k)}catch{v=se(l(u,F("The tool returned a result that is not JSON.")))}try{y.enqueue(v),y.close()}catch{}};U(m,x,I).then((k)=>b(k.kind==="invalid"?{jsonrpc:"2.0",id:u,error:{code:-32602,message:k.message}}:l(u,k.result)),()=>b({jsonrpc:"2.0",id:u,error:{code:-32603,message:"Internal error"}}))}});return new Response(r,{status:200,headers:We})}function C(u,m,x){let I=Bt(m),r={jsonrpc:"2.0",id:u,result:{resultType:"complete",_meta:n({[Ie]:u})}},y,b=new ReadableStream({start:(k)=>{if(k.enqueue(se({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:I,_meta:{[Ie]:u}}})),Object.keys(I).length===0){k.enqueue(se(r)),k.close();return}let v={id:u,send:(M)=>{try{k.enqueue(se(M))}catch{i.delete(v)}},end:()=>{i.delete(v);try{k.enqueue(se(r)),k.close()}catch{}}};y=v,i.add(v),x.addEventListener("abort",()=>{i.delete(v);try{k.close()}catch{}})},cancel:()=>{if(y!==void 0)i.delete(y)}});return new Response(b,{status:200,headers:We})}function K(u,m){if(Array.isArray(m))return N(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!re(m)||m.jsonrpc!=="2.0")return N(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:x,id:I}=m;if(typeof x!=="string")return"result"in m||"error"in m?N(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):N(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let r=u.headers.get("mcp-protocol-version"),y=u.headers.get("mcp-method"),b=re(m.params)?m.params:{},k=re(b._meta)?b._meta:void 0,v=k!==void 0&&Q in k,M=typeof k?.[Q]==="string"?k[Q]:void 0,J=r!==null&&r>=te;if(I===void 0){if(M!==void 0&&r!==null&&r!==M)return D(null,r,`the notification envelope names protocol version ${M} but the MCP-Protocol-Version header names ${r}`);if((v||J)&&y!==null&&y!==x)return D(null,y,`the notification body names method ${x} but the Mcp-Method header names ${y}`);return"notification"}if(typeof I!=="string"&&typeof I!=="number")return N(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let P=I;if(!v||x==="initialize"&&(M===void 0||M<te)){if(x==="initialize"){if(J)return D(P,r,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let A=typeof b.protocolVersion==="string"?b.protocolVersion:void 0;return E(P,A)}if(J){let A=k===void 0?["_meta"]:[Q];return N(400,P,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${r}, but the request is missing the required per-request envelope key(s): ${A.join(", ")}`,{envelope:{missing:A}})}return E(P,r??void 0)}let V=Vt(k);if(V!==void 0)return N(400,P,-32602,`Invalid _meta envelope for protocol revision ${te}: ${V.key}: ${V.problem}`,{envelope:V});if(r!==null&&M!==void 0&&r!==M)return D(P,r,`the body envelope names protocol version ${M} but the MCP-Protocol-Version header names ${r}`);if(y!==null&&y!==x)return D(P,y,`the body names method ${x} but the Mcp-Method header names ${y}`);if(M!==te)return E(P,M);if(r===null)return D(P,"(missing)",`the body envelope names protocol version ${M} but the required MCP-Protocol-Version header is absent`);if(y===null)return D(P,"(missing)",`the body names method ${x} but the required Mcp-Method header is absent`);if(x==="tools/call"&&typeof b.name==="string"){let A=b.name,j=u.headers.get("mcp-name");if(j===null)return D(P,"(missing)",`the body carries params.name="${A}" but the required Mcp-Name header is absent`);let W=Ut(j);if(W===void 0)return D(P,j,"the Mcp-Name header carries an invalid Base64 sentinel value");if(W!==A)return D(P,j,`the body carries params.name="${A}" but the Mcp-Name header names "${W}"`)}return{id:P,method:x,params:b}}function E(u,m){return m===void 0?N(400,u,Be,"Unsupported protocol version: the request did not name a protocol version",{supported:[te]}):N(400,u,Be,`Unsupported protocol version: ${m}`,{supported:[te],requested:m})}async function Z(u,m){if(u.method.toUpperCase()!=="POST")return N(405,null,-32000,"Method not allowed.");if(!Jt(u.headers.get("content-type")))return N(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let x;try{x=JSON.parse(m.body??await u.text())}catch{return N(400,null,-32700,"Parse error: the request body is not valid JSON")}let I=K(u,x);if(I instanceof Response)return I;if(I==="notification")return new Response(null,{status:202});let{id:r,method:y,params:b}=I;switch(y){case"server/discover":{let k={supportedVersions:[te],capabilities:{tools:{listChanged:!0}}};if(o.instructions!==void 0)k.instructions=o.instructions;return k.ttlMs=0,k.cacheScope="private",ve(200,l(r,k))}case"tools/list":return ve(200,l(r,{tools:q(),ttlMs:0,cacheScope:"private"}));case"tools/call":return G(r,b,u.signal,m.grant);case"subscriptions/listen":return C(r,b,u.signal);default:return N(404,r,-32601,"Method not found")}}return{handle:(u,m)=>Z(u,m).catch(()=>N(500,null,-32603,"Internal server error")),toolsChanged(){if(d)return;d=!0,queueMicrotask(()=>{d=!1;for(let u of[...i])u.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Ie]:u.id}}})})},close(){for(let u of[...i])u.end()}}}var be="tab-mcp.v1";function ie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var S=(e)=>typeof e==="string";function Fe(e){if(!ie(e)||!S(e.grantId)||!S(e.createdAt))return!1;let t=e.client;return ie(t)&&S(t.id)&&S(t.name)&&S(t.host)}function Dt(e){if(!ie(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Gt(e){return ie(e)&&Object.values(e).every(S)}function Ze(e){let t;try{t=JSON.parse(e)}catch{return}if(!ie(t))return;switch(t.type){case"session":return S(t.sessionId)&&S(t.address)&&S(t.origin)&&S(t.expiresAt)&&Dt(t.limits)&&Array.isArray(t.grants)&&t.grants.every(Fe)&&(t.appName===void 0||S(t.appName))&&(t.pairing===void 0||S(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:S(t.reason)?t.reason:""};case"http.request":return S(t.id)&&S(t.method)&&S(t.path)&&Gt(t.headers)&&S(t.body)&&ie(t.grant)&&S(t.grant.grantId)&&S(t.grant.clientId)?t:void 0;case"http.cancel":return S(t.id)?t:void 0;case"pairing.code":return S(t.code)&&S(t.expiresAt)?t:void 0;case"grant.added":return Fe(t.grant)?t:void 0;case"grant.removed":return S(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:S(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return S(t.code)?t:void 0;default:return}}var Kt=15000,Xe={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},Qe={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var Wt=["content-type","cache-control"];function Yt(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function Ft(e){try{let t=JSON.parse(e);if(typeof t!=="object"||t===null||typeof t.type!=="string")return;return typeof t.id==="string"?{type:t.type,id:t.id}:{type:t.type}}catch{return}}var Zt=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),et=512,tt=6,rt=64,Xt=et+tt*rt;function Qt(e){let t=Math.floor((e-et)/tt);return t>=rt?t:void 0}function*Le(e,t){let o=0;while(o<e.length){let s=Math.min(o+t,e.length),i=e.charCodeAt(s-1);if(s<e.length&&i>=55296&&i<=56319)s+=s-1>o?-1:1;yield e.slice(o,s),o=s}}function $r(e,t,o){let s=new WebSocket(t,be),i=new Map,d="opening",n,l=65536,T,q=0,_,U,ne=new Promise((r,y)=>{_=r,U=y});ne.catch(()=>{});let G=setTimeout(()=>{u(de("The relay did not answer in time.","network"))},Kt),C=Ye({tools:e.registry,server:e.server,confirm:(r)=>e.confirm(r),client:(r)=>e.clientFor(r),observe:{start:(r)=>e.toolCallStarted(r),end:(r)=>e.toolCallEnded(r)}}),K=e.registry.onChange(()=>C.toolsChanged());function E(r){if(s.readyState!==WebSocket.OPEN)return!1;try{return s.send(JSON.stringify(r)),!0}catch{return!1}}function Z(){if(q<=0)return;clearTimeout(T),T=setTimeout(()=>{n??="heartbeat",m(4003);try{s.close()}catch{}},q*2.5)}function u(r){if(d!=="opening")return;m(0),U(r);try{s.close()}catch{}}function m(r){if(d==="closed")return;let y=d==="ready";d="closed",clearTimeout(G),clearTimeout(T),K();for(let b of i.values())b.abort();if(i.clear(),C.close(),y){let b=n??Xe[r]??(r===1006?"network":"closed");e.closed(b,r)}}async function x(r){let y=new AbortController;i.set(r.id,y);let b=()=>d==="ready"&&i.get(r.id)===y&&!y.signal.aborted;try{let k=new Request(`https://tab.invalid${r.path}`,{method:r.method,headers:r.headers,signal:y.signal}),v=await C.handle(k,{grant:r.grant,body:r.body});if(!b()){await v.body?.cancel().catch(()=>{});return}let M={};for(let A of Wt){let j=v.headers.get(A);if(j!==null)M[A]=j}if(!(M["content-type"]??"").startsWith("text/event-stream")||v.body===null){let A=await v.text();if(!b())return;if(A.length<=l){E({type:"http.response",id:r.id,status:v.status,headers:M,body:A});return}E({type:"http.response.start",id:r.id,status:v.status,headers:M});for(let j of Le(A,l)){if(!b())break;E({type:"http.response.chunk",id:r.id,data:j})}if(b())E({type:"http.response.end",id:r.id});return}E({type:"http.response.start",id:r.id,status:v.status,headers:M});let P=v.body.getReader(),V=new TextDecoder;y.signal.addEventListener("abort",()=>{P.cancel().catch(()=>{})});for(;;){let{done:A,value:j}=await P.read();if(A||!b())break;let W=V.decode(j,{stream:!0});for(let ae of Le(W,l))E({type:"http.response.chunk",id:r.id,data:ae})}if(b())E({type:"http.response.end",id:r.id})}catch(k){if(b())e.error(k instanceof Error?k:Error(String(k))),E({type:"http.response",id:r.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(i.get(r.id)===y)i.delete(r.id)}}function I(r){if(d==="opening"){if(r.type==="session"){let y=Qt(r.limits.maxMessageBytes);if(y===void 0){u(de(`The relay's message limit (${r.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Xt}.`,"policy"));return}l=y,d="ready",clearTimeout(G),q=r.limits.heartbeatMs,Z(),_(e.sessionStarted(r))}else if(r.type==="error")u(de(`The relay refused the connection: ${r.message||r.code}`,r.code==="rate_limited"?"rate_limited":"policy"));else if(r.type==="bye")u(de(`The relay ended the connection: ${r.reason}`,Qe[r.reason]??"closed"));return}if(d!=="ready")return;switch(r.type){case"ping":Z(),E({type:"pong",t:r.t});return;case"http.request":x(r);return;case"http.cancel":i.get(r.id)?.abort(),i.delete(r.id);return;case"pairing.code":e.pairingCode({code:r.code,expiresAt:r.expiresAt});return;case"grant.added":e.grantAdded(r.grant);return;case"grant.removed":e.grantRemoved(r.grantId);return;case"identity.bound":e.identityResult(!0,r.round);return;case"bye":if(n=Qe[r.reason]??"closed",n==="replaced")e.replaced();return;case"error":if(r.code==="identity_refused"){e.identityResult(!1,typeof r.round==="number"?r.round:void 0,r.message);return}e.error(Error(`Relay error ${r.code}: ${r.message}`));return;case"session":return}}return s.addEventListener("open",()=>{if(s.protocol!==""&&s.protocol!==be){u(de(`The relay speaks ${s.protocol}, not ${be}.`,"policy"));return}let r={type:"hello",library:e.library,page:{title:Yt()},secret:o};if(e.appName!==void 0)r.app={name:e.appName};E(r)}),s.addEventListener("message",(r)=>{if(typeof r.data!=="string")return;let y=Ze(r.data);if(y!==void 0){if(d==="ready")Z();I(y);return}let b=Ft(r.data);if(b?.id!==void 0)E(Zt.has(b.type)?{type:"error",code:"bad_message",message:`malformed ${b.type}`,id:b.id}:{type:"error",code:"unknown_type",message:`unknown type ${b.type}`,id:b.id})}),s.addEventListener("close",(r)=>{if(d==="opening"){m(r.code);let y=r.code===1006||r.code===1002;U(de(y?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${r.code}${r.reason?`: ${r.reason}`:""}).`,Xe[r.code]??(y?"network":"closed")));return}m(r.code)}),{ready:ne,send:E,close(r){if(d==="closed")return;if(d==="opening"){u(new DOMException("The connection was cancelled","AbortError"));return}n=r,E({type:"bye",reason:"user"}),m(1000);try{s.close(1000,"bye")}catch{}}}}export{zt as compileRegistry,$r as openConnection};
|
|
9
|
-
|
|
10
|
-
//# debugId=49574567FC8D9C0964756E2164756E21
|
|
11
|
-
//# sourceMappingURL=connection-nygehv52.min.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js", "../../../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/pointer.js", "../../../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/dereference.js", "../../../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/format.js", "../../../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/ucs2-length.js", "../../../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/validate.js", "../../src/mapping.ts", "../../src/mcp.ts", "../../src/protocol.ts", "../../src/connection.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"export function deepCompareStrict(a, b) {\n const typeofa = typeof a;\n if (typeofa !== typeof b) {\n return false;\n }\n if (Array.isArray(a)) {\n if (!Array.isArray(b)) {\n return false;\n }\n const length = a.length;\n if (length !== b.length) {\n return false;\n }\n for (let i = 0; i < length; i++) {\n if (!deepCompareStrict(a[i], b[i])) {\n return false;\n }\n }\n return true;\n }\n if (typeofa === 'object') {\n if (!a || !b) {\n return a === b;\n }\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n const length = aKeys.length;\n if (length !== bKeys.length) {\n return false;\n }\n for (const k of aKeys) {\n if (!deepCompareStrict(a[k], b[k])) {\n return false;\n }\n }\n return true;\n }\n return a === b;\n}\n",
|
|
6
|
-
"export function encodePointer(p) {\n return encodeURI(escapePointer(p));\n}\nexport function escapePointer(p) {\n return p.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n",
|
|
7
|
-
"import { encodePointer } from './pointer.js';\nexport const schemaKeyword = {\n additionalItems: true,\n unevaluatedItems: true,\n items: true,\n contains: true,\n additionalProperties: true,\n unevaluatedProperties: true,\n propertyNames: true,\n not: true,\n if: true,\n then: true,\n else: true\n};\nexport const schemaArrayKeyword = {\n prefixItems: true,\n items: true,\n allOf: true,\n anyOf: true,\n oneOf: true\n};\nexport const schemaMapKeyword = {\n $defs: true,\n definitions: true,\n properties: true,\n patternProperties: true,\n dependentSchemas: true\n};\nexport const ignoredKeyword = {\n id: true,\n $id: true,\n $ref: true,\n $schema: true,\n $anchor: true,\n $vocabulary: true,\n $comment: true,\n default: true,\n enum: true,\n const: true,\n required: true,\n type: true,\n maximum: true,\n minimum: true,\n exclusiveMaximum: true,\n exclusiveMinimum: true,\n multipleOf: true,\n maxLength: true,\n minLength: true,\n pattern: true,\n format: true,\n maxItems: true,\n minItems: true,\n uniqueItems: true,\n maxProperties: true,\n minProperties: true\n};\nexport let initialBaseURI = typeof self !== 'undefined' &&\n self.location &&\n self.location.origin !== 'null'\n ?\n new URL(self.location.origin + self.location.pathname + location.search)\n : new URL('https://github.com/cfworker');\nexport function dereference(schema, lookup = Object.create(null), baseURI = initialBaseURI, basePointer = '') {\n if (schema && typeof schema === 'object' && !Array.isArray(schema)) {\n const id = schema.$id || schema.id;\n if (id) {\n const url = new URL(id, baseURI.href);\n if (url.hash.length > 1) {\n lookup[url.href] = schema;\n }\n else {\n url.hash = '';\n if (basePointer === '') {\n baseURI = url;\n }\n else {\n dereference(schema, lookup, baseURI);\n }\n }\n }\n }\n else if (schema !== true && schema !== false) {\n return lookup;\n }\n const schemaURI = baseURI.href + (basePointer ? '#' + basePointer : '');\n if (lookup[schemaURI] !== undefined) {\n throw new Error(`Duplicate schema URI \"${schemaURI}\".`);\n }\n lookup[schemaURI] = schema;\n if (schema === true || schema === false) {\n return lookup;\n }\n if (schema.__absolute_uri__ === undefined) {\n Object.defineProperty(schema, '__absolute_uri__', {\n enumerable: false,\n value: schemaURI\n });\n }\n if (schema.$ref && schema.__absolute_ref__ === undefined) {\n const url = new URL(schema.$ref, baseURI.href);\n url.hash = url.hash;\n Object.defineProperty(schema, '__absolute_ref__', {\n enumerable: false,\n value: url.href\n });\n }\n if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === undefined) {\n const url = new URL(schema.$recursiveRef, baseURI.href);\n url.hash = url.hash;\n Object.defineProperty(schema, '__absolute_recursive_ref__', {\n enumerable: false,\n value: url.href\n });\n }\n if (schema.$anchor) {\n const url = new URL('#' + schema.$anchor, baseURI.href);\n lookup[url.href] = schema;\n }\n for (let key in schema) {\n if (ignoredKeyword[key]) {\n continue;\n }\n const keyBase = `${basePointer}/${encodePointer(key)}`;\n const subSchema = schema[key];\n if (Array.isArray(subSchema)) {\n if (schemaArrayKeyword[key]) {\n const length = subSchema.length;\n for (let i = 0; i < length; i++) {\n dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);\n }\n }\n }\n else if (schemaMapKeyword[key]) {\n for (let subKey in subSchema) {\n dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);\n }\n }\n else {\n dereference(subSchema, lookup, baseURI, keyBase);\n }\n }\n return lookup;\n}\n",
|
|
8
|
-
"const DATE = /^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$/;\nconst DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst TIME = /^(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?(z|[+-]\\d\\d(?::?\\d\\d)?)?$/i;\nconst HOSTNAME = /^(?=.{1,253}\\.?$)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a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;\nconst URITEMPLATE = /^(?:(?:[^\\x00-\\x20\"'<>%\\\\^`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i;\nconst URL_ = /^(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u{00a1}-\\u{ffff}0-9]+-?)*[a-z\\u{00a1}-\\u{ffff}0-9]+)(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}0-9]+-?)*[a-z\\u{00a1}-\\u{ffff}0-9]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu;\nconst UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;\nconst JSON_POINTER = /^(?:\\/(?:[^~/]|~0|~1)*)*$/;\nconst JSON_POINTER_URI_FRAGMENT = /^#(?:\\/(?:[a-z0-9_\\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;\nconst RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/;\nconst EMAIL = (input) => {\n if (input[0] === '\"')\n return false;\n const [name, host, ...rest] = input.split('@');\n if (!name ||\n !host ||\n rest.length !== 0 ||\n name.length > 64 ||\n host.length > 253)\n return false;\n if (name[0] === '.' || name.endsWith('.') || name.includes('..'))\n return false;\n if (!/^[a-z0-9.-]+$/i.test(host) ||\n !/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(name))\n return false;\n return host\n .split('.')\n .every(part => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(part));\n};\nconst IPV4 = /^(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$/;\nconst IPV6 = /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))$/i;\nconst DURATION = (input) => input.length > 1 &&\n input.length < 80 &&\n (/^P\\d+([.,]\\d+)?W$/.test(input) ||\n (/^P[\\dYMDTHS]*(\\d[.,]\\d+)?[YMDHS]$/.test(input) &&\n /^P([.,\\d]+Y)?([.,\\d]+M)?([.,\\d]+D)?(T([.,\\d]+H)?([.,\\d]+M)?([.,\\d]+S)?)?$/.test(input)));\nfunction bind(r) {\n return r.test.bind(r);\n}\nexport const format = {\n date,\n time: time.bind(undefined, false),\n 'date-time': date_time,\n duration: DURATION,\n uri,\n 'uri-reference': bind(URIREF),\n 'uri-template': bind(URITEMPLATE),\n url: bind(URL_),\n email: EMAIL,\n hostname: bind(HOSTNAME),\n ipv4: bind(IPV4),\n ipv6: bind(IPV6),\n regex: regex,\n uuid: bind(UUID),\n 'json-pointer': bind(JSON_POINTER),\n 'json-pointer-uri-fragment': bind(JSON_POINTER_URI_FRAGMENT),\n 'relative-json-pointer': bind(RELATIVE_JSON_POINTER)\n};\nfunction isLeapYear(year) {\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\nfunction date(str) {\n const matches = str.match(DATE);\n if (!matches)\n return false;\n const year = +matches[1];\n const month = +matches[2];\n const day = +matches[3];\n return (month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]));\n}\nfunction time(full, str) {\n const matches = str.match(TIME);\n if (!matches)\n return false;\n const hour = +matches[1];\n const minute = +matches[2];\n const second = +matches[3];\n const timeZone = !!matches[5];\n return (((hour <= 23 && minute <= 59 && second <= 59) ||\n (hour == 23 && minute == 59 && second == 60)) &&\n (!full || timeZone));\n}\nconst DATE_TIME_SEPARATOR = /t|\\s/i;\nfunction date_time(str) {\n const dateTime = str.split(DATE_TIME_SEPARATOR);\n return dateTime.length == 2 && date(dateTime[0]) && time(true, dateTime[1]);\n}\nconst NOT_URI_FRAGMENT = /\\/|:/;\nconst URI_PATTERN = /^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\\?(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;\nfunction uri(str) {\n return NOT_URI_FRAGMENT.test(str) && URI_PATTERN.test(str);\n}\nconst Z_ANCHOR = /[^\\\\]\\\\Z/;\nfunction regex(str) {\n if (Z_ANCHOR.test(str))\n return false;\n try {\n new RegExp(str, 'u');\n return true;\n }\n catch (e) {\n return false;\n }\n}\n",
|
|
9
|
-
"export function ucs2length(s) {\n let result = 0;\n let length = s.length;\n let index = 0;\n let charCode;\n while (index < length) {\n result++;\n charCode = s.charCodeAt(index++);\n if (charCode >= 0xd800 && charCode <= 0xdbff && index < length) {\n charCode = s.charCodeAt(index);\n if ((charCode & 0xfc00) == 0xdc00) {\n index++;\n }\n }\n }\n return result;\n}\n",
|
|
10
|
-
"import { deepCompareStrict } from './deep-compare-strict.js';\nimport { dereference } from './dereference.js';\nimport { format } from './format.js';\nimport { encodePointer } from './pointer.js';\nimport { ucs2length } from './ucs2-length.js';\nexport function validate(instance, schema, draft = '2019-09', lookup = dereference(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = '#', schemaLocation = '#', evaluated = Object.create(null)) {\n if (schema === true) {\n return { valid: true, errors: [] };\n }\n if (schema === false) {\n return {\n valid: false,\n errors: [\n {\n instanceLocation,\n keyword: 'false',\n keywordLocation: instanceLocation,\n error: 'False boolean schema.'\n }\n ]\n };\n }\n const rawInstanceType = typeof instance;\n let instanceType;\n switch (rawInstanceType) {\n case 'boolean':\n case 'number':\n case 'string':\n instanceType = rawInstanceType;\n break;\n case 'object':\n if (instance === null) {\n instanceType = 'null';\n }\n else if (Array.isArray(instance)) {\n instanceType = 'array';\n }\n else {\n instanceType = 'object';\n }\n break;\n default:\n throw new Error(`Instances of \"${rawInstanceType}\" type are not supported.`);\n }\n const { $ref, $recursiveRef, $recursiveAnchor, type: $type, const: $const, enum: $enum, required: $required, not: $not, anyOf: $anyOf, allOf: $allOf, oneOf: $oneOf, if: $if, then: $then, else: $else, format: $format, properties: $properties, patternProperties: $patternProperties, additionalProperties: $additionalProperties, unevaluatedProperties: $unevaluatedProperties, minProperties: $minProperties, maxProperties: $maxProperties, propertyNames: $propertyNames, dependentRequired: $dependentRequired, dependentSchemas: $dependentSchemas, dependencies: $dependencies, prefixItems: $prefixItems, items: $items, additionalItems: $additionalItems, unevaluatedItems: $unevaluatedItems, contains: $contains, minContains: $minContains, maxContains: $maxContains, minItems: $minItems, maxItems: $maxItems, uniqueItems: $uniqueItems, minimum: $minimum, maximum: $maximum, exclusiveMinimum: $exclusiveMinimum, exclusiveMaximum: $exclusiveMaximum, multipleOf: $multipleOf, minLength: $minLength, maxLength: $maxLength, pattern: $pattern, __absolute_ref__, __absolute_recursive_ref__ } = schema;\n const errors = [];\n if ($recursiveAnchor === true && recursiveAnchor === null) {\n recursiveAnchor = schema;\n }\n if ($recursiveRef === '#') {\n const refSchema = recursiveAnchor === null\n ? lookup[__absolute_recursive_ref__]\n : recursiveAnchor;\n const keywordLocation = `${schemaLocation}/$recursiveRef`;\n const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);\n if (!result.valid) {\n errors.push({\n instanceLocation,\n keyword: '$recursiveRef',\n keywordLocation,\n error: 'A subschema had errors.'\n }, ...result.errors);\n }\n }\n if ($ref !== undefined) {\n const uri = __absolute_ref__ || $ref;\n const refSchema = lookup[uri];\n if (refSchema === undefined) {\n let message = `Unresolved $ref \"${$ref}\".`;\n if (__absolute_ref__ && __absolute_ref__ !== $ref) {\n message += ` Absolute URI \"${__absolute_ref__}\".`;\n }\n message += `\\nKnown schemas:\\n- ${Object.keys(lookup).join('\\n- ')}`;\n throw new Error(message);\n }\n const keywordLocation = `${schemaLocation}/$ref`;\n const result = validate(instance, refSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated);\n if (!result.valid) {\n errors.push({\n instanceLocation,\n keyword: '$ref',\n keywordLocation,\n error: 'A subschema had errors.'\n }, ...result.errors);\n }\n if (draft === '4' || draft === '7') {\n return { valid: errors.length === 0, errors };\n }\n }\n if (Array.isArray($type)) {\n let length = $type.length;\n let valid = false;\n for (let i = 0; i < length; i++) {\n if (instanceType === $type[i] ||\n ($type[i] === 'integer' &&\n instanceType === 'number' &&\n instance % 1 === 0 &&\n instance === instance)) {\n valid = true;\n break;\n }\n }\n if (!valid) {\n errors.push({\n instanceLocation,\n keyword: 'type',\n keywordLocation: `${schemaLocation}/type`,\n error: `Instance type \"${instanceType}\" is invalid. Expected \"${$type.join('\", \"')}\".`\n });\n }\n }\n else if ($type === 'integer') {\n if (instanceType !== 'number' || instance % 1 || instance !== instance) {\n errors.push({\n instanceLocation,\n keyword: 'type',\n keywordLocation: `${schemaLocation}/type`,\n error: `Instance type \"${instanceType}\" is invalid. Expected \"${$type}\".`\n });\n }\n }\n else if ($type !== undefined && instanceType !== $type) {\n errors.push({\n instanceLocation,\n keyword: 'type',\n keywordLocation: `${schemaLocation}/type`,\n error: `Instance type \"${instanceType}\" is invalid. Expected \"${$type}\".`\n });\n }\n if ($const !== undefined) {\n if (instanceType === 'object' || instanceType === 'array') {\n if (!deepCompareStrict(instance, $const)) {\n errors.push({\n instanceLocation,\n keyword: 'const',\n keywordLocation: `${schemaLocation}/const`,\n error: `Instance does not match ${JSON.stringify($const)}.`\n });\n }\n }\n else if (instance !== $const) {\n errors.push({\n instanceLocation,\n keyword: 'const',\n keywordLocation: `${schemaLocation}/const`,\n error: `Instance does not match ${JSON.stringify($const)}.`\n });\n }\n }\n if ($enum !== undefined) {\n if (instanceType === 'object' || instanceType === 'array') {\n if (!$enum.some(value => deepCompareStrict(instance, value))) {\n errors.push({\n instanceLocation,\n keyword: 'enum',\n keywordLocation: `${schemaLocation}/enum`,\n error: `Instance does not match any of ${JSON.stringify($enum)}.`\n });\n }\n }\n else if (!$enum.some(value => instance === value)) {\n errors.push({\n instanceLocation,\n keyword: 'enum',\n keywordLocation: `${schemaLocation}/enum`,\n error: `Instance does not match any of ${JSON.stringify($enum)}.`\n });\n }\n }\n if ($not !== undefined) {\n const keywordLocation = `${schemaLocation}/not`;\n const result = validate(instance, $not, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation);\n if (result.valid) {\n errors.push({\n instanceLocation,\n keyword: 'not',\n keywordLocation,\n error: 'Instance matched \"not\" schema.'\n });\n }\n }\n let subEvaluateds = [];\n if ($anyOf !== undefined) {\n const keywordLocation = `${schemaLocation}/anyOf`;\n const errorsLength = errors.length;\n let anyValid = false;\n for (let i = 0; i < $anyOf.length; i++) {\n const subSchema = $anyOf[i];\n const subEvaluated = Object.create(evaluated);\n const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);\n errors.push(...result.errors);\n anyValid = anyValid || result.valid;\n if (result.valid) {\n subEvaluateds.push(subEvaluated);\n }\n }\n if (anyValid) {\n errors.length = errorsLength;\n }\n else {\n errors.splice(errorsLength, 0, {\n instanceLocation,\n keyword: 'anyOf',\n keywordLocation,\n error: 'Instance does not match any subschemas.'\n });\n }\n }\n if ($allOf !== undefined) {\n const keywordLocation = `${schemaLocation}/allOf`;\n const errorsLength = errors.length;\n let allValid = true;\n for (let i = 0; i < $allOf.length; i++) {\n const subSchema = $allOf[i];\n const subEvaluated = Object.create(evaluated);\n const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);\n errors.push(...result.errors);\n allValid = allValid && result.valid;\n if (result.valid) {\n subEvaluateds.push(subEvaluated);\n }\n }\n if (allValid) {\n errors.length = errorsLength;\n }\n else {\n errors.splice(errorsLength, 0, {\n instanceLocation,\n keyword: 'allOf',\n keywordLocation,\n error: `Instance does not match every subschema.`\n });\n }\n }\n if ($oneOf !== undefined) {\n const keywordLocation = `${schemaLocation}/oneOf`;\n const errorsLength = errors.length;\n const matches = $oneOf.filter((subSchema, i) => {\n const subEvaluated = Object.create(evaluated);\n const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);\n errors.push(...result.errors);\n if (result.valid) {\n subEvaluateds.push(subEvaluated);\n }\n return result.valid;\n }).length;\n if (matches === 1) {\n errors.length = errorsLength;\n }\n else {\n errors.splice(errorsLength, 0, {\n instanceLocation,\n keyword: 'oneOf',\n keywordLocation,\n error: `Instance does not match exactly one subschema (${matches} matches).`\n });\n }\n }\n if (instanceType === 'object' || instanceType === 'array') {\n Object.assign(evaluated, ...subEvaluateds);\n }\n if ($if !== undefined) {\n const keywordLocation = `${schemaLocation}/if`;\n const conditionResult = validate(instance, $if, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, keywordLocation, evaluated).valid;\n if (conditionResult) {\n if ($then !== undefined) {\n const thenResult = validate(instance, $then, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/then`, evaluated);\n if (!thenResult.valid) {\n errors.push({\n instanceLocation,\n keyword: 'if',\n keywordLocation,\n error: `Instance does not match \"then\" schema.`\n }, ...thenResult.errors);\n }\n }\n }\n else if ($else !== undefined) {\n const elseResult = validate(instance, $else, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${schemaLocation}/else`, evaluated);\n if (!elseResult.valid) {\n errors.push({\n instanceLocation,\n keyword: 'if',\n keywordLocation,\n error: `Instance does not match \"else\" schema.`\n }, ...elseResult.errors);\n }\n }\n }\n if (instanceType === 'object') {\n if ($required !== undefined) {\n for (const key of $required) {\n if (!(key in instance)) {\n errors.push({\n instanceLocation,\n keyword: 'required',\n keywordLocation: `${schemaLocation}/required`,\n error: `Instance does not have required property \"${key}\".`\n });\n }\n }\n }\n const keys = Object.keys(instance);\n if ($minProperties !== undefined && keys.length < $minProperties) {\n errors.push({\n instanceLocation,\n keyword: 'minProperties',\n keywordLocation: `${schemaLocation}/minProperties`,\n error: `Instance does not have at least ${$minProperties} properties.`\n });\n }\n if ($maxProperties !== undefined && keys.length > $maxProperties) {\n errors.push({\n instanceLocation,\n keyword: 'maxProperties',\n keywordLocation: `${schemaLocation}/maxProperties`,\n error: `Instance does not have at least ${$maxProperties} properties.`\n });\n }\n if ($propertyNames !== undefined) {\n const keywordLocation = `${schemaLocation}/propertyNames`;\n for (const key in instance) {\n const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;\n const result = validate(key, $propertyNames, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);\n if (!result.valid) {\n errors.push({\n instanceLocation,\n keyword: 'propertyNames',\n keywordLocation,\n error: `Property name \"${key}\" does not match schema.`\n }, ...result.errors);\n }\n }\n }\n if ($dependentRequired !== undefined) {\n const keywordLocation = `${schemaLocation}/dependantRequired`;\n for (const key in $dependentRequired) {\n if (key in instance) {\n const required = $dependentRequired[key];\n for (const dependantKey of required) {\n if (!(dependantKey in instance)) {\n errors.push({\n instanceLocation,\n keyword: 'dependentRequired',\n keywordLocation,\n error: `Instance has \"${key}\" but does not have \"${dependantKey}\".`\n });\n }\n }\n }\n }\n }\n if ($dependentSchemas !== undefined) {\n for (const key in $dependentSchemas) {\n const keywordLocation = `${schemaLocation}/dependentSchemas`;\n if (key in instance) {\n const result = validate(instance, $dependentSchemas[key], draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`, evaluated);\n if (!result.valid) {\n errors.push({\n instanceLocation,\n keyword: 'dependentSchemas',\n keywordLocation,\n error: `Instance has \"${key}\" but does not match dependant schema.`\n }, ...result.errors);\n }\n }\n }\n }\n if ($dependencies !== undefined) {\n const keywordLocation = `${schemaLocation}/dependencies`;\n for (const key in $dependencies) {\n if (key in instance) {\n const propsOrSchema = $dependencies[key];\n if (Array.isArray(propsOrSchema)) {\n for (const dependantKey of propsOrSchema) {\n if (!(dependantKey in instance)) {\n errors.push({\n instanceLocation,\n keyword: 'dependencies',\n keywordLocation,\n error: `Instance has \"${key}\" but does not have \"${dependantKey}\".`\n });\n }\n }\n }\n else {\n const result = validate(instance, propsOrSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${encodePointer(key)}`);\n if (!result.valid) {\n errors.push({\n instanceLocation,\n keyword: 'dependencies',\n keywordLocation,\n error: `Instance has \"${key}\" but does not match dependant schema.`\n }, ...result.errors);\n }\n }\n }\n }\n }\n const thisEvaluated = Object.create(null);\n let stop = false;\n if ($properties !== undefined) {\n const keywordLocation = `${schemaLocation}/properties`;\n for (const key in $properties) {\n if (!(key in instance)) {\n continue;\n }\n const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;\n const result = validate(instance[key], $properties[key], draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(key)}`);\n if (result.valid) {\n evaluated[key] = thisEvaluated[key] = true;\n }\n else {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'properties',\n keywordLocation,\n error: `Property \"${key}\" does not match schema.`\n }, ...result.errors);\n if (stop)\n break;\n }\n }\n }\n if (!stop && $patternProperties !== undefined) {\n const keywordLocation = `${schemaLocation}/patternProperties`;\n for (const pattern in $patternProperties) {\n const regex = new RegExp(pattern, 'u');\n const subSchema = $patternProperties[pattern];\n for (const key in instance) {\n if (!regex.test(key)) {\n continue;\n }\n const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;\n const result = validate(instance[key], subSchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${encodePointer(pattern)}`);\n if (result.valid) {\n evaluated[key] = thisEvaluated[key] = true;\n }\n else {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'patternProperties',\n keywordLocation,\n error: `Property \"${key}\" matches pattern \"${pattern}\" but does not match associated schema.`\n }, ...result.errors);\n }\n }\n }\n }\n if (!stop && $additionalProperties !== undefined) {\n const keywordLocation = `${schemaLocation}/additionalProperties`;\n for (const key in instance) {\n if (thisEvaluated[key]) {\n continue;\n }\n const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;\n const result = validate(instance[key], $additionalProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);\n if (result.valid) {\n evaluated[key] = true;\n }\n else {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'additionalProperties',\n keywordLocation,\n error: `Property \"${key}\" does not match additional properties schema.`\n }, ...result.errors);\n }\n }\n }\n else if (!stop && $unevaluatedProperties !== undefined) {\n const keywordLocation = `${schemaLocation}/unevaluatedProperties`;\n for (const key in instance) {\n if (!evaluated[key]) {\n const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;\n const result = validate(instance[key], $unevaluatedProperties, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, keywordLocation);\n if (result.valid) {\n evaluated[key] = true;\n }\n else {\n errors.push({\n instanceLocation,\n keyword: 'unevaluatedProperties',\n keywordLocation,\n error: `Property \"${key}\" does not match unevaluated properties schema.`\n }, ...result.errors);\n }\n }\n }\n }\n }\n else if (instanceType === 'array') {\n if ($maxItems !== undefined && instance.length > $maxItems) {\n errors.push({\n instanceLocation,\n keyword: 'maxItems',\n keywordLocation: `${schemaLocation}/maxItems`,\n error: `Array has too many items (${instance.length} > ${$maxItems}).`\n });\n }\n if ($minItems !== undefined && instance.length < $minItems) {\n errors.push({\n instanceLocation,\n keyword: 'minItems',\n keywordLocation: `${schemaLocation}/minItems`,\n error: `Array has too few items (${instance.length} < ${$minItems}).`\n });\n }\n const length = instance.length;\n let i = 0;\n let stop = false;\n if ($prefixItems !== undefined) {\n const keywordLocation = `${schemaLocation}/prefixItems`;\n const length2 = Math.min($prefixItems.length, length);\n for (; i < length2; i++) {\n const result = validate(instance[i], $prefixItems[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);\n evaluated[i] = true;\n if (!result.valid) {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'prefixItems',\n keywordLocation,\n error: `Items did not match schema.`\n }, ...result.errors);\n if (stop)\n break;\n }\n }\n }\n if ($items !== undefined) {\n const keywordLocation = `${schemaLocation}/items`;\n if (Array.isArray($items)) {\n const length2 = Math.min($items.length, length);\n for (; i < length2; i++) {\n const result = validate(instance[i], $items[i], draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, `${keywordLocation}/${i}`);\n evaluated[i] = true;\n if (!result.valid) {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'items',\n keywordLocation,\n error: `Items did not match schema.`\n }, ...result.errors);\n if (stop)\n break;\n }\n }\n }\n else {\n for (; i < length; i++) {\n const result = validate(instance[i], $items, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);\n evaluated[i] = true;\n if (!result.valid) {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'items',\n keywordLocation,\n error: `Items did not match schema.`\n }, ...result.errors);\n if (stop)\n break;\n }\n }\n }\n if (!stop && $additionalItems !== undefined) {\n const keywordLocation = `${schemaLocation}/additionalItems`;\n for (; i < length; i++) {\n const result = validate(instance[i], $additionalItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);\n evaluated[i] = true;\n if (!result.valid) {\n stop = shortCircuit;\n errors.push({\n instanceLocation,\n keyword: 'additionalItems',\n keywordLocation,\n error: `Items did not match additional items schema.`\n }, ...result.errors);\n }\n }\n }\n }\n if ($contains !== undefined) {\n if (length === 0 && $minContains === undefined) {\n errors.push({\n instanceLocation,\n keyword: 'contains',\n keywordLocation: `${schemaLocation}/contains`,\n error: `Array is empty. It must contain at least one item matching the schema.`\n });\n }\n else if ($minContains !== undefined && length < $minContains) {\n errors.push({\n instanceLocation,\n keyword: 'minContains',\n keywordLocation: `${schemaLocation}/minContains`,\n error: `Array has less items (${length}) than minContains (${$minContains}).`\n });\n }\n else {\n const keywordLocation = `${schemaLocation}/contains`;\n const errorsLength = errors.length;\n let contained = 0;\n for (let j = 0; j < length; j++) {\n const result = validate(instance[j], $contains, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${j}`, keywordLocation);\n if (result.valid) {\n evaluated[j] = true;\n contained++;\n }\n else {\n errors.push(...result.errors);\n }\n }\n if (contained >= ($minContains || 0)) {\n errors.length = errorsLength;\n }\n if ($minContains === undefined &&\n $maxContains === undefined &&\n contained === 0) {\n errors.splice(errorsLength, 0, {\n instanceLocation,\n keyword: 'contains',\n keywordLocation,\n error: `Array does not contain item matching schema.`\n });\n }\n else if ($minContains !== undefined && contained < $minContains) {\n errors.push({\n instanceLocation,\n keyword: 'minContains',\n keywordLocation: `${schemaLocation}/minContains`,\n error: `Array must contain at least ${$minContains} items matching schema. Only ${contained} items were found.`\n });\n }\n else if ($maxContains !== undefined && contained > $maxContains) {\n errors.push({\n instanceLocation,\n keyword: 'maxContains',\n keywordLocation: `${schemaLocation}/maxContains`,\n error: `Array may contain at most ${$maxContains} items matching schema. ${contained} items were found.`\n });\n }\n }\n }\n if (!stop && $unevaluatedItems !== undefined) {\n const keywordLocation = `${schemaLocation}/unevaluatedItems`;\n for (i; i < length; i++) {\n if (evaluated[i]) {\n continue;\n }\n const result = validate(instance[i], $unevaluatedItems, draft, lookup, shortCircuit, recursiveAnchor, `${instanceLocation}/${i}`, keywordLocation);\n evaluated[i] = true;\n if (!result.valid) {\n errors.push({\n instanceLocation,\n keyword: 'unevaluatedItems',\n keywordLocation,\n error: `Items did not match unevaluated items schema.`\n }, ...result.errors);\n }\n }\n }\n if ($uniqueItems) {\n for (let j = 0; j < length; j++) {\n const a = instance[j];\n const ao = typeof a === 'object' && a !== null;\n for (let k = 0; k < length; k++) {\n if (j === k) {\n continue;\n }\n const b = instance[k];\n const bo = typeof b === 'object' && b !== null;\n if (a === b || (ao && bo && deepCompareStrict(a, b))) {\n errors.push({\n instanceLocation,\n keyword: 'uniqueItems',\n keywordLocation: `${schemaLocation}/uniqueItems`,\n error: `Duplicate items at indexes ${j} and ${k}.`\n });\n j = Number.MAX_SAFE_INTEGER;\n k = Number.MAX_SAFE_INTEGER;\n }\n }\n }\n }\n }\n else if (instanceType === 'number') {\n if (draft === '4') {\n if ($minimum !== undefined &&\n (($exclusiveMinimum === true && instance <= $minimum) ||\n instance < $minimum)) {\n errors.push({\n instanceLocation,\n keyword: 'minimum',\n keywordLocation: `${schemaLocation}/minimum`,\n error: `${instance} is less than ${$exclusiveMinimum ? 'or equal to ' : ''} ${$minimum}.`\n });\n }\n if ($maximum !== undefined &&\n (($exclusiveMaximum === true && instance >= $maximum) ||\n instance > $maximum)) {\n errors.push({\n instanceLocation,\n keyword: 'maximum',\n keywordLocation: `${schemaLocation}/maximum`,\n error: `${instance} is greater than ${$exclusiveMaximum ? 'or equal to ' : ''} ${$maximum}.`\n });\n }\n }\n else {\n if ($minimum !== undefined && instance < $minimum) {\n errors.push({\n instanceLocation,\n keyword: 'minimum',\n keywordLocation: `${schemaLocation}/minimum`,\n error: `${instance} is less than ${$minimum}.`\n });\n }\n if ($maximum !== undefined && instance > $maximum) {\n errors.push({\n instanceLocation,\n keyword: 'maximum',\n keywordLocation: `${schemaLocation}/maximum`,\n error: `${instance} is greater than ${$maximum}.`\n });\n }\n if ($exclusiveMinimum !== undefined && instance <= $exclusiveMinimum) {\n errors.push({\n instanceLocation,\n keyword: 'exclusiveMinimum',\n keywordLocation: `${schemaLocation}/exclusiveMinimum`,\n error: `${instance} is less than ${$exclusiveMinimum}.`\n });\n }\n if ($exclusiveMaximum !== undefined && instance >= $exclusiveMaximum) {\n errors.push({\n instanceLocation,\n keyword: 'exclusiveMaximum',\n keywordLocation: `${schemaLocation}/exclusiveMaximum`,\n error: `${instance} is greater than or equal to ${$exclusiveMaximum}.`\n });\n }\n }\n if ($multipleOf !== undefined) {\n const remainder = instance % $multipleOf;\n if (Math.abs(0 - remainder) >= 1.1920929e-7 &&\n Math.abs($multipleOf - remainder) >= 1.1920929e-7) {\n errors.push({\n instanceLocation,\n keyword: 'multipleOf',\n keywordLocation: `${schemaLocation}/multipleOf`,\n error: `${instance} is not a multiple of ${$multipleOf}.`\n });\n }\n }\n }\n else if (instanceType === 'string') {\n const length = $minLength === undefined && $maxLength === undefined\n ? 0\n : ucs2length(instance);\n if ($minLength !== undefined && length < $minLength) {\n errors.push({\n instanceLocation,\n keyword: 'minLength',\n keywordLocation: `${schemaLocation}/minLength`,\n error: `String is too short (${length} < ${$minLength}).`\n });\n }\n if ($maxLength !== undefined && length > $maxLength) {\n errors.push({\n instanceLocation,\n keyword: 'maxLength',\n keywordLocation: `${schemaLocation}/maxLength`,\n error: `String is too long (${length} > ${$maxLength}).`\n });\n }\n if ($pattern !== undefined && !new RegExp($pattern, 'u').test(instance)) {\n errors.push({\n instanceLocation,\n keyword: 'pattern',\n keywordLocation: `${schemaLocation}/pattern`,\n error: `String does not match pattern.`\n });\n }\n if ($format !== undefined &&\n format[$format] &&\n !format[$format](instance)) {\n errors.push({\n instanceLocation,\n keyword: 'format',\n keywordLocation: `${schemaLocation}/format`,\n error: `String does not match format \"${$format}\".`\n });\n }\n }\n return { valid: errors.length === 0, errors };\n}\n",
|
|
11
|
-
"/**\n * WebMCP → MCP mapping of annotations (DEC-022) and results (DEC-023).\n */\n\nimport type { ToolAnnotations } from \"./types.ts\";\n\n/** `_meta` key that keeps the original WebMCP hints. */\nexport const ANNOTATIONS_META_KEY = \"ch.ractive.tab-mcp/annotations\";\n\nconst WEBMCP_HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\nconst MCP_ONLY_HINTS = [\n\t\"destructiveHint\",\n\t\"idempotentHint\",\n\t\"openWorldHint\",\n] as const;\n\nexport interface McpToolAnnotations {\n\tannotations?: Record<string, boolean>;\n\tmeta?: Record<string, boolean>;\n}\n\n/** MCP annotations plus the WebMCP originals for `_meta`. */\nexport function mapAnnotations(hints: ToolAnnotations): McpToolAnnotations {\n\tconst annotations: Record<string, boolean> = {};\n\tif (hints.readOnlyHint === true) {\n\t\tannotations[\"readOnlyHint\"] = true;\n\t\tannotations[\"destructiveHint\"] = false;\n\t} else if (hints.readOnlyHint === false) {\n\t\tannotations[\"readOnlyHint\"] = false;\n\t}\n\tif (hints.consequentialHint === true) annotations[\"destructiveHint\"] = true;\n\tif (hints.untrustedContentHint === true) annotations[\"openWorldHint\"] = true;\n\tfor (const key of MCP_ONLY_HINTS) {\n\t\tconst value = hints[key];\n\t\tif (value !== undefined) annotations[key] = value; // MCP hints win\n\t}\n\tconst meta: Record<string, boolean> = {};\n\tfor (const key of WEBMCP_HINTS) {\n\t\tconst value = hints[key];\n\t\tif (value !== undefined) meta[key] = value;\n\t}\n\tconst out: McpToolAnnotations = {};\n\tif (Object.keys(annotations).length > 0) out.annotations = annotations;\n\tif (Object.keys(meta).length > 0) out.meta = meta;\n\treturn out;\n}\n\nexport interface CallToolResult {\n\tcontent: unknown[];\n\tstructuredContent?: Record<string, unknown>;\n\tisError?: boolean;\n\t[key: string]: unknown;\n}\n\nexport function errorResult(message: string): CallToolResult {\n\treturn { content: [{ type: \"text\", text: message }], isError: true };\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/**\n * What `execute` returned → a `CallToolResult`: a string is one text block; an\n * object with a `content` array passes through; `undefined` is an empty\n * result; any other JSON value is a text block with its JSON, plus\n * `structuredContent` when it is an object.\n */\nexport function toCallToolResult(value: unknown): CallToolResult {\n\tif (typeof value === \"string\")\n\t\treturn { content: [{ type: \"text\", text: value }] };\n\tif (value === undefined) return { content: [] };\n\tif (isPlainObject(value) && Array.isArray(value[\"content\"])) {\n\t\treturn value as CallToolResult;\n\t}\n\tlet text: string | undefined;\n\ttry {\n\t\ttext = JSON.stringify(value);\n\t} catch {\n\t\t// cyclic or BigInt\n\t}\n\tif (text === undefined)\n\t\treturn errorResult(\"The tool returned a value that is not JSON.\");\n\tconst result: CallToolResult = { content: [{ type: \"text\", text }] };\n\tif (isPlainObject(value)) result.structuredContent = value;\n\treturn result;\n}\n\n/** A thrown value → an `isError` result with its message. */\nexport function thrownResult(error: unknown): CallToolResult {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn errorResult(message || \"The tool failed.\");\n}\n",
|
|
12
|
-
"/**\n * The tab's MCP server: the stateless 2026-07-28 subset tab-mcp needs\n * (DEC-049), written for the page instead of bundling the SDK. It answers\n * `server/discover`, `tools/list`, `tools/call` (as SSE, DEC-020) and\n * `subscriptions/listen`, and applies the request checks of the 2026-07-28\n * Streamable HTTP transport (content type, JSON-RPC shape, `_meta` envelope,\n * `MCP-Protocol-Version` / `Mcp-Method` / `Mcp-Name`). Status codes and error\n * codes follow the MCP TypeScript SDK's `createMcpHandler`; the conformance\n * tests compare the two.\n */\n\nimport {\n\tdereference,\n\ttype OutputUnit,\n\ttype Schema,\n\tvalidate as validateSchema,\n} from \"@cfworker/json-schema\";\nimport {\n\tANNOTATIONS_META_KEY,\n\ttype CallToolResult,\n\terrorResult,\n\tmapAnnotations,\n\tthrownResult,\n\ttoCallToolResult,\n} from \"./mapping.ts\";\nimport type { GrantRef } from \"./protocol.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type {\n\tConfirmRequest,\n\tServerInfo,\n\tToolCallClient,\n\tToolCallEnd,\n\tToolCallOutcome,\n\tToolCallStart,\n} from \"./types.ts\";\n\nexport const MCP_PROTOCOL_VERSION = \"2026-07-28\";\nconst META_VERSION = \"io.modelcontextprotocol/protocolVersion\";\nconst META_CAPABILITIES = \"io.modelcontextprotocol/clientCapabilities\";\nconst META_CLIENT_INFO = \"io.modelcontextprotocol/clientInfo\";\nconst META_SERVER_INFO = \"io.modelcontextprotocol/serverInfo\";\nconst META_SUBSCRIPTION = \"io.modelcontextprotocol/subscriptionId\";\n\nconst HEADER_MISMATCH = -32020;\nconst UNSUPPORTED_VERSION = -32022;\n\ntype Id = string | number;\ntype Json = Record<string, unknown>;\n\nexport interface ToolSource {\n\tlist(): RegisteredTool[];\n\tget(name: string): RegisteredTool | undefined;\n}\n\nexport interface McpHandlerOptions {\n\ttools: ToolSource;\n\tserver: ServerInfo;\n\t/** Ask the user before a consequential tool runs. */\n\tconfirm(request: ConfirmRequest): Promise<boolean>;\n\t/** The caller of a request, from its grant. */\n\tclient(grant: GrantRef): ToolCallClient;\n\t/** Told about every call of a known tool, as it starts and as it ends. */\n\tobserve?: {\n\t\tstart(call: ToolCallStart): void;\n\t\tend(call: ToolCallEnd): void;\n\t};\n}\n\n/** Tool call ids, unique in the page. */\nlet lastCallId = 0;\n\n/** Checks arguments against a tool's input schema. */\nexport type ArgumentValidator = (args: unknown) => {\n\tvalid: boolean;\n\terrors: OutputUnit[];\n};\n\nconst compiled = new WeakMap<RegisteredTool, ArgumentValidator>();\n\n/**\n * The validator of a tool's input schema, built once per tool. Throws what\n * the validator would throw at call time: a `$ref` that does not resolve\n * (the validator resolves one only when an argument reaches it, against the\n * base of the nearest `$id`), an `$id` that is not a URL, a duplicate one.\n * `compileRegistry` makes the registry call it at registration (DEC-086).\n */\nexport function compileTool(tool: RegisteredTool): ArgumentValidator {\n\tconst known = compiled.get(tool);\n\tif (known !== undefined) return known;\n\tconst schema = tool.inputSchema as Schema;\n\tlet lookup: Record<string, Schema | boolean>;\n\ttry {\n\t\tlookup = dereference(schema);\n\t} catch (error) {\n\t\t// Only the first line: the validator appends the URIs it knows.\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(message.split(\"\\n\")[0]);\n\t}\n\tfor (const node of Object.values(lookup)) {\n\t\tif (typeof node !== \"object\" || node.$ref === undefined) continue;\n\t\tconst absolute = (node as { __absolute_ref__?: string }).__absolute_ref__;\n\t\tif (lookup[absolute ?? node.$ref] === undefined)\n\t\t\tthrow new Error(`$ref ${JSON.stringify(node.$ref)} does not resolve`);\n\t}\n\tconst validator: ArgumentValidator = (args) =>\n\t\tvalidateSchema(args, schema, \"2020-12\", lookup, false);\n\tcompiled.set(tool, validator);\n\treturn validator;\n}\n\nfunction schemaError(name: string, error: unknown, suffix = \"\"): TypeError {\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn new TypeError(\n\t\t`registerTool: the inputSchema of ${name}: ${message}${suffix}`,\n\t);\n}\n\n/**\n * The validator is loaded (on `connect()`): compile the schemas of the tools\n * registered so far, before any AI app lists them, and from now on at\n * registration, so that `registerTool` rejects a schema the validator cannot\n * use. A tool registered before that it refuses is unregistered; the errors\n * are for the page's `error` event.\n */\nexport function compileRegistry(registry: ToolRegistry): TypeError[] {\n\tconst refused: TypeError[] = [];\n\tfor (const tool of registry.list()) {\n\t\ttry {\n\t\t\tcompileTool(tool);\n\t\t} catch (error) {\n\t\t\tregistry.remove(tool);\n\t\t\trefused.push(\n\t\t\t\tschemaError(tool.name, error, \"; the tool was unregistered\"),\n\t\t\t);\n\t\t}\n\t}\n\tregistry.setCompiler((tool) => {\n\t\ttry {\n\t\t\tcompileTool(tool);\n\t\t} catch (error) {\n\t\t\tthrow schemaError(tool.name, error);\n\t\t}\n\t});\n\treturn refused;\n}\n\n/** A deep copy for an event; the value itself when it cannot be cloned. */\nfunction copy<T>(value: T): T {\n\ttry {\n\t\treturn structuredClone(value);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\nexport interface McpRequestContext {\n\tgrant: GrantRef;\n\t/** The body as text when the caller already has it. */\n\tbody?: string;\n}\n\nexport interface McpHandler {\n\thandle(request: Request, context: McpRequestContext): Promise<Response>;\n\t/** The tool list changed: tell the listen streams. */\n\ttoolsChanged(): void;\n\t/** End every listen stream (the session is over). */\n\tclose(): void;\n}\n\nconst encoder = new TextEncoder();\n\nfunction isObject(v: unknown): v is Json {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\nfunction json(status: number, value: unknown): Response {\n\treturn new Response(JSON.stringify(value), {\n\t\tstatus,\n\t\theaders: { \"content-type\": \"application/json\" },\n\t});\n}\n\nfunction rpcError(\n\tstatus: number,\n\tid: Id | null,\n\tcode: number,\n\tmessage: string,\n\tdata?: unknown,\n): Response {\n\tconst error: Json = { code, message };\n\tif (data !== undefined) error[\"data\"] = data;\n\treturn json(status, { jsonrpc: \"2.0\", id, error });\n}\n\nfunction mismatch(id: Id | null, header: string, body: string): Response {\n\treturn rpcError(\n\t\t400,\n\t\tid,\n\t\tHEADER_MISMATCH,\n\t\t`Bad Request: the request headers and body disagree: ${body}`,\n\t\t{\n\t\t\tmismatch: { header, body },\n\t\t},\n\t);\n}\n\nfunction sseEvent(message: unknown): Uint8Array {\n\treturn encoder.encode(`event: message\\ndata: ${JSON.stringify(message)}\\n\\n`);\n}\n\nconst SSE_HEADERS = {\n\t\"content-type\": \"text/event-stream\",\n\t\"cache-control\": \"no-cache\",\n};\n\n/** `application/json`, with or without parameters. */\nfunction isJsonContentType(value: string | null): boolean {\n\treturn (\n\t\t(value ?? \"\").split(\";\")[0]?.trim().toLowerCase() === \"application/json\"\n\t);\n}\n\n/** Decode the `=?base64?…?=` sentinel of SEP-2243 headers; `undefined` if malformed. */\nexport function decodeHeaderValue(value: string): string | undefined {\n\tif (!(value.startsWith(\"=?base64?\") && value.endsWith(\"?=\"))) return value;\n\tconst b64 = value.slice(9, -2);\n\tif (\n\t\t!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(\n\t\t\tb64,\n\t\t)\n\t)\n\t\treturn undefined;\n\ttry {\n\t\tconst bin = atob(b64);\n\t\tconst bytes = Uint8Array.from(bin, (c) => c.charCodeAt(0));\n\t\treturn new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The first problem of a 2026-07-28 `_meta` envelope, or `undefined`. */\nfunction envelopeIssue(\n\tmeta: Json,\n): { key: string; problem: string } | undefined {\n\tif (!(META_VERSION in meta)) return { key: META_VERSION, problem: \"missing\" };\n\tif (!(META_CAPABILITIES in meta))\n\t\treturn { key: META_CAPABILITIES, problem: \"missing\" };\n\tif (typeof meta[META_VERSION] !== \"string\") {\n\t\treturn { key: META_VERSION, problem: \"expected a protocol version string\" };\n\t}\n\tif (!isObject(meta[META_CAPABILITIES]))\n\t\treturn { key: META_CAPABILITIES, problem: \"expected an object\" };\n\tconst info = meta[META_CLIENT_INFO];\n\tif (\n\t\tinfo !== undefined &&\n\t\t!(\n\t\t\tisObject(info) &&\n\t\t\ttypeof info[\"name\"] === \"string\" &&\n\t\t\ttypeof info[\"version\"] === \"string\"\n\t\t)\n\t) {\n\t\treturn { key: META_CLIENT_INFO, problem: \"expected {name, version}\" };\n\t}\n\treturn undefined;\n}\n\n/** Listen streams honour only the tool list (the tab has nothing else). */\nfunction honoured(params: Json): Json {\n\tconst requested = params[\"notifications\"];\n\treturn isObject(requested) && requested[\"toolsListChanged\"] === true\n\t\t? { toolsListChanged: true }\n\t\t: {};\n}\n\nexport function createMcpHandler(options: McpHandlerOptions): McpHandler {\n\tconst { tools, server } = options;\n\tconst serverInfo: Json = { name: server.name, version: server.version };\n\tif (server.title !== undefined) serverInfo[\"title\"] = server.title;\n\tconst listeners = new Set<{\n\t\tid: Id;\n\t\tsend(message: unknown): void;\n\t\tend(): void;\n\t}>();\n\tlet changeQueued = false;\n\n\tconst resultMeta = (extra: Json = {}) => ({\n\t\t...extra,\n\t\t[META_SERVER_INFO]: serverInfo,\n\t});\n\n\tfunction result(id: Id, value: Json): Json {\n\t\treturn {\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid,\n\t\t\tresult: { ...value, resultType: \"complete\", _meta: resultMeta() },\n\t\t};\n\t}\n\n\tfunction validate(tool: RegisteredTool, args: Json): string | undefined {\n\t\tlet outcome: ReturnType<ArgumentValidator>;\n\t\ttry {\n\t\t\toutcome = compileTool(tool)(args);\n\t\t} catch (error) {\n\t\t\t// Refused at registration through `TabMcp`; this is for any other registry.\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\treturn `The input schema of tool ${tool.name} cannot be used: ${message}`;\n\t\t}\n\t\tif (outcome.valid) return undefined;\n\t\tconst detail = outcome.errors\n\t\t\t.filter((e) => e.keyword !== \"properties\" && e.keyword !== \"$ref\")\n\t\t\t.map((e) => `${e.instanceLocation} ${e.error}`)\n\t\t\t.slice(0, 5)\n\t\t\t.join(\"; \");\n\t\treturn `Input validation error: Invalid arguments for tool ${tool.name}: ${detail || \"the arguments do not match the schema\"}`;\n\t}\n\n\tfunction listTools(): Json[] {\n\t\treturn tools.list().map((tool) => {\n\t\t\tconst entry: Json = { name: tool.name };\n\t\t\tif (tool.title !== undefined) entry[\"title\"] = tool.title;\n\t\t\tentry[\"description\"] = tool.description;\n\t\t\tentry[\"inputSchema\"] = tool.inputSchema;\n\t\t\tconst { annotations, meta } = mapAnnotations(tool.annotations);\n\t\t\tif (annotations !== undefined) entry[\"annotations\"] = annotations;\n\t\t\tif (meta !== undefined) entry[\"_meta\"] = { [ANNOTATIONS_META_KEY]: meta };\n\t\t\treturn entry;\n\t\t});\n\t}\n\n\t/**\n\t * A call's outcome: a JSON-RPC error (`invalid`) or a result. Tagged, so\n\t * that a result's own keys never decide which (a tool may return any).\n\t */\n\ttype RunOutcome =\n\t\t| { kind: \"invalid\"; message: string }\n\t\t| { kind: \"result\"; result: CallToolResult };\n\n\tconst invalidParams = (message: string): RunOutcome => ({\n\t\tkind: \"invalid\",\n\t\tmessage,\n\t});\n\n\tasync function runTool(\n\t\tparams: Json,\n\t\tsignal: AbortSignal,\n\t\tgrant: GrantRef,\n\t): Promise<RunOutcome> {\n\t\tconst name = params[\"name\"];\n\t\tif (typeof name !== \"string\")\n\t\t\treturn invalidParams(\"Invalid params: name must be a string\");\n\t\tconst tool = tools.get(name);\n\t\tif (tool === undefined) return invalidParams(`Tool ${name} not found`);\n\t\tconst raw = params[\"arguments\"] ?? {};\n\t\tif (!isObject(raw))\n\t\t\treturn invalidParams(\"Invalid params: arguments must be an object\");\n\t\tconst client = options.client(grant);\n\t\t// Copies: a listener cannot change what the tool gets or the AI app receives.\n\t\tconst call: ToolCallStart = {\n\t\t\tid: ++lastCallId,\n\t\t\ttool: tool.name,\n\t\t\targuments: copy(raw),\n\t\t\tclient: { ...client },\n\t\t};\n\t\tif (tool.title !== undefined) call.title = tool.title;\n\t\tconst started = Date.now();\n\t\toptions.observe?.start(call);\n\t\t// Every start has its end, also when something fails outside the tool.\n\t\tlet outcome: ToolCallOutcome = \"error\";\n\t\tlet res: CallToolResult = errorResult(\"Internal error\");\n\t\ttry {\n\t\t\t[outcome, res] = await decideAndRun(tool, raw, signal, client);\n\t\t} finally {\n\t\t\toptions.observe?.end({\n\t\t\t\tid: call.id,\n\t\t\t\ttool: tool.name,\n\t\t\t\tclient: { ...client },\n\t\t\t\toutcome,\n\t\t\t\tresult: copy(res),\n\t\t\t\tdurationMs: Date.now() - started,\n\t\t\t});\n\t\t}\n\t\treturn { kind: \"result\", result: res };\n\t}\n\n\t/** Validate, confirm and run one call. */\n\tasync function decideAndRun(\n\t\ttool: RegisteredTool,\n\t\traw: Json,\n\t\tsignal: AbortSignal,\n\t\tclient: ToolCallClient,\n\t): Promise<[ToolCallOutcome, CallToolResult]> {\n\t\tconst invalid = validate(tool, raw);\n\t\tif (invalid !== undefined) return [\"error\", errorResult(invalid)];\n\t\tif (tool.annotations.consequentialHint === true) {\n\t\t\tconst question: ConfirmRequest = {\n\t\t\t\ttool: { name: tool.name, description: tool.description },\n\t\t\t\targuments: raw,\n\t\t\t\tclient,\n\t\t\t\tsignal,\n\t\t\t};\n\t\t\tif (tool.title !== undefined) question.tool.title = tool.title;\n\t\t\tlet allowed = false;\n\t\t\ttry {\n\t\t\t\tallowed = await options.confirm(question);\n\t\t\t} catch {\n\t\t\t\tallowed = false;\n\t\t\t}\n\t\t\tif (!allowed)\n\t\t\t\treturn [\n\t\t\t\t\tsignal.aborted ? \"cancelled\" : \"declined\",\n\t\t\t\t\terrorResult(\"The user declined\"),\n\t\t\t\t];\n\t\t}\n\t\tif (signal.aborted) return [\"cancelled\", errorResult(\"Cancelled\")];\n\t\t// Unregistered (or replaced) while the user was asked: not the tool\n\t\t// the user allowed, or one the page still offers.\n\t\tif (tools.get(tool.name) !== tool)\n\t\t\treturn [\"error\", errorResult(\"The tool is no longer available\")];\n\t\tlet res: CallToolResult;\n\t\ttry {\n\t\t\tres = toCallToolResult(await tool.execute(raw, { signal, client }));\n\t\t} catch (error) {\n\t\t\tres = thrownResult(error);\n\t\t}\n\t\t// Cancelled is cancelled, however the tool answered the abort.\n\t\tif (signal.aborted) return [\"cancelled\", res];\n\t\treturn [res.isError === true ? \"error\" : \"ok\", res];\n\t}\n\n\tfunction callTool(\n\t\tid: Id,\n\t\tparams: Json,\n\t\tsignal: AbortSignal,\n\t\tgrant: GrantRef,\n\t): Response {\n\t\tconst stream = new ReadableStream<Uint8Array>({\n\t\t\tstart: (controller) => {\n\t\t\t\t/** Send the one answer and end the stream, whatever happens. */\n\t\t\t\tconst finish = (message: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // nobody listens any more\n\t\t\t\t\tlet event: Uint8Array;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tevent = sseEvent(message);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// e.g. a BigInt or a cycle inside a passed-through result\n\t\t\t\t\t\tevent = sseEvent(\n\t\t\t\t\t\t\tresult(\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\terrorResult(\"The tool returned a result that is not JSON.\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcontroller.enqueue(event);\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// the stream was cancelled meanwhile\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\trunTool(params, signal, grant).then(\n\t\t\t\t\t(outcome) =>\n\t\t\t\t\t\tfinish(\n\t\t\t\t\t\t\toutcome.kind === \"invalid\"\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\terror: { code: -32602, message: outcome.message },\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: result(id, outcome.result),\n\t\t\t\t\t\t),\n\t\t\t\t\t() =>\n\t\t\t\t\t\tfinish({\n\t\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\terror: { code: -32603, message: \"Internal error\" },\n\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t\treturn new Response(stream, { status: 200, headers: SSE_HEADERS });\n\t}\n\n\tfunction listen(id: Id, params: Json, signal: AbortSignal): Response {\n\t\tconst notifications = honoured(params);\n\t\tconst finalResult = {\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid,\n\t\t\tresult: {\n\t\t\t\tresultType: \"complete\",\n\t\t\t\t_meta: resultMeta({ [META_SUBSCRIPTION]: id }),\n\t\t\t},\n\t\t};\n\t\t// This stream's own listener: two AI apps may both use the same id.\n\t\tlet own: { id: Id; send(m: unknown): void; end(): void } | undefined;\n\t\tconst stream = new ReadableStream<Uint8Array>({\n\t\t\tstart: (controller) => {\n\t\t\t\tcontroller.enqueue(\n\t\t\t\t\tsseEvent({\n\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\tmethod: \"notifications/subscriptions/acknowledged\",\n\t\t\t\t\t\tparams: { notifications, _meta: { [META_SUBSCRIPTION]: id } },\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tif (Object.keys(notifications).length === 0) {\n\t\t\t\t\tcontroller.enqueue(sseEvent(finalResult));\n\t\t\t\t\tcontroller.close();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst listener = {\n\t\t\t\t\tid,\n\t\t\t\t\tsend: (message: unknown) => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tcontroller.enqueue(sseEvent(message));\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tend: () => {\n\t\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tcontroller.enqueue(sseEvent(finalResult));\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// already cancelled\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\town = listener;\n\t\t\t\tlisteners.add(listener);\n\t\t\t\tsignal.addEventListener(\"abort\", () => {\n\t\t\t\t\tlisteners.delete(listener);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// already closed\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t\tcancel: () => {\n\t\t\t\tif (own !== undefined) listeners.delete(own);\n\t\t\t},\n\t\t});\n\t\treturn new Response(stream, { status: 200, headers: SSE_HEADERS });\n\t}\n\n\t/** The request checks; a `Response` when the request is refused. */\n\tfunction check(\n\t\trequest: Request,\n\t\tbody: unknown,\n\t): Response | { id: Id; method: string; params: Json } | \"notification\" {\n\t\tif (Array.isArray(body)) {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32600,\n\t\t\t\t\"Bad Request: JSON-RPC batches are not supported by this endpoint\",\n\t\t\t);\n\t\t}\n\t\tif (!isObject(body) || body[\"jsonrpc\"] !== \"2.0\") {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32600,\n\t\t\t\t\"Bad Request: the request body is not a valid JSON-RPC message\",\n\t\t\t);\n\t\t}\n\t\tconst method = body[\"method\"];\n\t\tconst rawId = body[\"id\"];\n\t\tif (typeof method !== \"string\") {\n\t\t\treturn \"result\" in body || \"error\" in body\n\t\t\t\t? rpcError(\n\t\t\t\t\t\t400,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\t-32600,\n\t\t\t\t\t\t\"Bad Request: JSON-RPC responses cannot be posted to this endpoint\",\n\t\t\t\t\t)\n\t\t\t\t: rpcError(\n\t\t\t\t\t\t400,\n\t\t\t\t\t\tnull,\n\t\t\t\t\t\t-32600,\n\t\t\t\t\t\t\"Bad Request: the request body is not a valid JSON-RPC message\",\n\t\t\t\t\t);\n\t\t}\n\t\tconst headerVersion = request.headers.get(\"mcp-protocol-version\");\n\t\tconst headerMethod = request.headers.get(\"mcp-method\");\n\t\tconst params = isObject(body[\"params\"]) ? body[\"params\"] : {};\n\t\tconst meta = isObject(params[\"_meta\"]) ? params[\"_meta\"] : undefined;\n\t\tconst claim = meta !== undefined && META_VERSION in meta;\n\t\tconst claimed =\n\t\t\ttypeof meta?.[META_VERSION] === \"string\"\n\t\t\t\t? (meta[META_VERSION] as string)\n\t\t\t\t: undefined;\n\t\tconst headerModern =\n\t\t\theaderVersion !== null && headerVersion >= MCP_PROTOCOL_VERSION;\n\n\t\tif (rawId === undefined) {\n\t\t\t// A notification: nothing to answer, but the headers must agree.\n\t\t\tif (\n\t\t\t\tclaimed !== undefined &&\n\t\t\t\theaderVersion !== null &&\n\t\t\t\theaderVersion !== claimed\n\t\t\t) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tnull,\n\t\t\t\t\theaderVersion,\n\t\t\t\t\t`the notification envelope names protocol version ${claimed} but the MCP-Protocol-Version header names ${headerVersion}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\t(claim || headerModern) &&\n\t\t\t\theaderMethod !== null &&\n\t\t\t\theaderMethod !== method\n\t\t\t) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tnull,\n\t\t\t\t\theaderMethod,\n\t\t\t\t\t`the notification body names method ${method} but the Mcp-Method header names ${headerMethod}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn \"notification\";\n\t\t}\n\t\tif (typeof rawId !== \"string\" && typeof rawId !== \"number\") {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32600,\n\t\t\t\t\"Bad Request: the request body is not a valid JSON-RPC message\",\n\t\t\t);\n\t\t}\n\t\tconst id = rawId;\n\t\tif (\n\t\t\t!claim ||\n\t\t\t(method === \"initialize\" &&\n\t\t\t\t(claimed === undefined || claimed < MCP_PROTOCOL_VERSION))\n\t\t) {\n\t\t\tif (method === \"initialize\") {\n\t\t\t\tif (headerModern) {\n\t\t\t\t\treturn mismatch(\n\t\t\t\t\t\tid,\n\t\t\t\t\t\theaderVersion,\n\t\t\t\t\t\t\"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst requested =\n\t\t\t\t\ttypeof params[\"protocolVersion\"] === \"string\"\n\t\t\t\t\t\t? params[\"protocolVersion\"]\n\t\t\t\t\t\t: undefined;\n\t\t\t\treturn unsupported(id, requested);\n\t\t\t}\n\t\t\tif (headerModern) {\n\t\t\t\tconst missing = meta === undefined ? [\"_meta\"] : [META_VERSION];\n\t\t\t\treturn rpcError(\n\t\t\t\t\t400,\n\t\t\t\t\tid,\n\t\t\t\t\t-32602,\n\t\t\t\t\t`Invalid params: the MCP-Protocol-Version header names protocol revision ${headerVersion}, but the request is missing the required per-request envelope key(s): ${missing.join(\", \")}`,\n\t\t\t\t\t{ envelope: { missing } },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn unsupported(id, headerVersion ?? undefined);\n\t\t}\n\t\tconst issue = envelopeIssue(meta);\n\t\tif (issue !== undefined) {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tid,\n\t\t\t\t-32602,\n\t\t\t\t`Invalid _meta envelope for protocol revision ${MCP_PROTOCOL_VERSION}: ${issue.key}: ${issue.problem}`,\n\t\t\t\t{ envelope: issue },\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\theaderVersion !== null &&\n\t\t\tclaimed !== undefined &&\n\t\t\theaderVersion !== claimed\n\t\t) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\theaderVersion,\n\t\t\t\t`the body envelope names protocol version ${claimed} but the MCP-Protocol-Version header names ${headerVersion}`,\n\t\t\t);\n\t\t}\n\t\tif (headerMethod !== null && headerMethod !== method) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\theaderMethod,\n\t\t\t\t`the body names method ${method} but the Mcp-Method header names ${headerMethod}`,\n\t\t\t);\n\t\t}\n\t\tif (claimed !== MCP_PROTOCOL_VERSION) return unsupported(id, claimed);\n\t\tif (headerVersion === null) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\t\"(missing)\",\n\t\t\t\t`the body envelope names protocol version ${claimed} but the required MCP-Protocol-Version header is absent`,\n\t\t\t);\n\t\t}\n\t\tif (headerMethod === null) {\n\t\t\treturn mismatch(\n\t\t\t\tid,\n\t\t\t\t\"(missing)\",\n\t\t\t\t`the body names method ${method} but the required Mcp-Method header is absent`,\n\t\t\t);\n\t\t}\n\t\tif (method === \"tools/call\" && typeof params[\"name\"] === \"string\") {\n\t\t\tconst name = params[\"name\"];\n\t\t\tconst header = request.headers.get(\"mcp-name\");\n\t\t\tif (header === null) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tid,\n\t\t\t\t\t\"(missing)\",\n\t\t\t\t\t`the body carries params.name=\"${name}\" but the required Mcp-Name header is absent`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst decoded = decodeHeaderValue(header);\n\t\t\tif (decoded === undefined) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tid,\n\t\t\t\t\theader,\n\t\t\t\t\t\"the Mcp-Name header carries an invalid Base64 sentinel value\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (decoded !== name) {\n\t\t\t\treturn mismatch(\n\t\t\t\t\tid,\n\t\t\t\t\theader,\n\t\t\t\t\t`the body carries params.name=\"${name}\" but the Mcp-Name header names \"${decoded}\"`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn { id, method, params };\n\t}\n\n\tfunction unsupported(id: Id, requested: string | undefined): Response {\n\t\treturn requested === undefined\n\t\t\t? rpcError(\n\t\t\t\t\t400,\n\t\t\t\t\tid,\n\t\t\t\t\tUNSUPPORTED_VERSION,\n\t\t\t\t\t\"Unsupported protocol version: the request did not name a protocol version\",\n\t\t\t\t\t{ supported: [MCP_PROTOCOL_VERSION] },\n\t\t\t\t)\n\t\t\t: rpcError(\n\t\t\t\t\t400,\n\t\t\t\t\tid,\n\t\t\t\t\tUNSUPPORTED_VERSION,\n\t\t\t\t\t`Unsupported protocol version: ${requested}`,\n\t\t\t\t\t{ supported: [MCP_PROTOCOL_VERSION], requested },\n\t\t\t\t);\n\t}\n\n\tasync function handle(\n\t\trequest: Request,\n\t\tcontext: McpRequestContext,\n\t): Promise<Response> {\n\t\tif (request.method.toUpperCase() !== \"POST\")\n\t\t\treturn rpcError(405, null, -32000, \"Method not allowed.\");\n\t\tif (!isJsonContentType(request.headers.get(\"content-type\"))) {\n\t\t\treturn rpcError(\n\t\t\t\t415,\n\t\t\t\tnull,\n\t\t\t\t-32000,\n\t\t\t\t\"Unsupported Media Type: Content-Type must be application/json\",\n\t\t\t);\n\t\t}\n\t\tlet body: unknown;\n\t\ttry {\n\t\t\tbody = JSON.parse(context.body ?? (await request.text()));\n\t\t} catch {\n\t\t\treturn rpcError(\n\t\t\t\t400,\n\t\t\t\tnull,\n\t\t\t\t-32700,\n\t\t\t\t\"Parse error: the request body is not valid JSON\",\n\t\t\t);\n\t\t}\n\t\tconst checked = check(request, body);\n\t\tif (checked instanceof Response) return checked;\n\t\tif (checked === \"notification\") return new Response(null, { status: 202 });\n\t\tconst { id, method, params } = checked;\n\t\tswitch (method) {\n\t\t\tcase \"server/discover\": {\n\t\t\t\tconst discover: Json = {\n\t\t\t\t\tsupportedVersions: [MCP_PROTOCOL_VERSION],\n\t\t\t\t\tcapabilities: { tools: { listChanged: true } },\n\t\t\t\t};\n\t\t\t\tif (server.instructions !== undefined)\n\t\t\t\t\tdiscover[\"instructions\"] = server.instructions;\n\t\t\t\tdiscover[\"ttlMs\"] = 0;\n\t\t\t\tdiscover[\"cacheScope\"] = \"private\";\n\t\t\t\treturn json(200, result(id, discover));\n\t\t\t}\n\t\t\tcase \"tools/list\":\n\t\t\t\treturn json(\n\t\t\t\t\t200,\n\t\t\t\t\tresult(id, { tools: listTools(), ttlMs: 0, cacheScope: \"private\" }),\n\t\t\t\t);\n\t\t\tcase \"tools/call\":\n\t\t\t\treturn callTool(id, params, request.signal, context.grant);\n\t\t\tcase \"subscriptions/listen\":\n\t\t\t\treturn listen(id, params, request.signal);\n\t\t\tdefault:\n\t\t\t\treturn rpcError(404, id, -32601, \"Method not found\");\n\t\t}\n\t}\n\n\treturn {\n\t\thandle: (request, context) =>\n\t\t\thandle(request, context).catch(() =>\n\t\t\t\trpcError(500, null, -32603, \"Internal server error\"),\n\t\t\t),\n\t\ttoolsChanged() {\n\t\t\tif (changeQueued) return;\n\t\t\tchangeQueued = true;\n\t\t\t// Several registrations in one task produce one notification.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tchangeQueued = false;\n\t\t\t\tfor (const listener of [...listeners]) {\n\t\t\t\t\tlistener.send({\n\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\tmethod: \"notifications/tools/list_changed\",\n\t\t\t\t\t\tparams: { _meta: { [META_SUBSCRIPTION]: listener.id } },\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tclose() {\n\t\t\tfor (const listener of [...listeners]) listener.end();\n\t\t},\n\t};\n}\n",
|
|
13
|
-
"/**\n * The tab↔relay protocol, version 1, as the tab speaks it\n * (`kb/design/protocol.md`). Internal: not part of the public API.\n */\n\nimport type { Grant, Limits } from \"./types.ts\";\n\nexport const SUBPROTOCOL = \"tab-mcp.v1\";\n\n/** Who is calling a tunnelled request (the relay's view of the grant). */\nexport interface GrantRef {\n\tgrantId: string;\n\tclientId: string;\n\tscopes: string[];\n}\n\n// Relay → tab\n\nexport interface SessionMessage {\n\ttype: \"session\";\n\tsessionId: string;\n\taddress: string;\n\torigin: string;\n\tappName?: string;\n\t/** How AI apps pair: `code` or `oidc` (identity binding). Older relays omit it. */\n\tpairing?: \"code\" | \"oidc\";\n\texpiresAt: string;\n\tlimits: Limits;\n\tgrants: Grant[];\n}\nexport interface PingMessage {\n\ttype: \"ping\";\n\tt: number;\n}\nexport interface ByeMessage {\n\ttype: \"bye\";\n\treason: string;\n}\nexport interface HttpRequestMessage {\n\ttype: \"http.request\";\n\tid: string;\n\tmethod: string;\n\tpath: string;\n\theaders: Record<string, string>;\n\tbody: string;\n\tgrant: GrantRef;\n}\nexport interface HttpCancelMessage {\n\ttype: \"http.cancel\";\n\tid: string;\n\treason: string;\n}\nexport interface PairingCodeMessage {\n\ttype: \"pairing.code\";\n\tcode: string;\n\texpiresAt: string;\n}\nexport interface GrantAddedMessage {\n\ttype: \"grant.added\";\n\tgrant: Grant;\n}\nexport interface GrantRemovedMessage {\n\ttype: \"grant.removed\";\n\tgrantId: string;\n\treason: string;\n}\nexport interface IdentityBoundMessage {\n\ttype: \"identity.bound\";\n\t/** The `round` of the `identity` this answers. */\n\tround?: number;\n}\nexport interface ErrorMessage {\n\ttype: \"error\";\n\tcode: string;\n\tmessage: string;\n\tid?: string;\n\t/** On `identity_refused`: the `round` of the `identity` it answers. */\n\tround?: number;\n}\nexport type RelayMessage =\n\t| SessionMessage\n\t| PingMessage\n\t| ByeMessage\n\t| HttpRequestMessage\n\t| HttpCancelMessage\n\t| PairingCodeMessage\n\t| GrantAddedMessage\n\t| GrantRemovedMessage\n\t| IdentityBoundMessage\n\t| ErrorMessage;\n\n// Tab → relay\n\nexport type TabMessage =\n\t| {\n\t\t\ttype: \"hello\";\n\t\t\tlibrary: { name: string; version: string };\n\t\t\tpage: { title: string };\n\t\t\tapp?: { name: string };\n\t\t\tsecret: string;\n\t }\n\t| { type: \"pong\"; t: number }\n\t| { type: \"bye\"; reason: string }\n\t| {\n\t\t\ttype: \"http.response\";\n\t\t\tid: string;\n\t\t\tstatus: number;\n\t\t\theaders: Record<string, string>;\n\t\t\tbody: string;\n\t }\n\t| {\n\t\t\ttype: \"http.response.start\";\n\t\t\tid: string;\n\t\t\tstatus: number;\n\t\t\theaders: Record<string, string>;\n\t }\n\t| { type: \"http.response.chunk\"; id: string; data: string }\n\t| { type: \"http.response.end\"; id: string }\n\t| { type: \"pairing.start\" }\n\t| { type: \"pairing.stop\" }\n\t| { type: \"grant.revoke\"; grantId: string }\n\t| { type: \"grants.revokeAll\" }\n\t| { type: \"identity\"; assertion: string; round: number }\n\t| { type: \"identity.logout\" }\n\t| { type: \"error\"; code: string; message: string; id?: string };\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(v: unknown): v is Json {\n\treturn typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\nconst str = (v: unknown): v is string => typeof v === \"string\";\n\nfunction isGrant(v: unknown): v is Grant {\n\tif (!isObject(v) || !str(v[\"grantId\"]) || !str(v[\"createdAt\"])) return false;\n\tconst c = v[\"client\"];\n\treturn isObject(c) && str(c[\"id\"]) && str(c[\"name\"]) && str(c[\"host\"]);\n}\n\nfunction isLimits(v: unknown): v is Limits {\n\tif (!isObject(v)) return false;\n\treturn [\n\t\t\"maxMessageBytes\",\n\t\t\"maxBodyBytes\",\n\t\t\"requestTimeoutMs\",\n\t\t\"idleTimeoutMs\",\n\t\t\"heartbeatMs\",\n\t\t\"keepAliveMs\",\n\t\t\"maxConcurrentRequests\",\n\t].every((k) => typeof v[k] === \"number\");\n}\n\nfunction isStringRecord(v: unknown): v is Record<string, string> {\n\treturn isObject(v) && Object.values(v).every(str);\n}\n\n/**\n * Parse one frame from the relay. Returns `undefined` for anything malformed\n * or unknown; the caller ignores it (forward compatibility).\n */\nexport function parseRelayMessage(text: string): RelayMessage | undefined {\n\tlet v: unknown;\n\ttry {\n\t\tv = JSON.parse(text);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (!isObject(v)) return undefined;\n\tswitch (v[\"type\"]) {\n\t\tcase \"session\":\n\t\t\treturn str(v[\"sessionId\"]) &&\n\t\t\t\tstr(v[\"address\"]) &&\n\t\t\t\tstr(v[\"origin\"]) &&\n\t\t\t\tstr(v[\"expiresAt\"]) &&\n\t\t\t\tisLimits(v[\"limits\"]) &&\n\t\t\t\tArray.isArray(v[\"grants\"]) &&\n\t\t\t\tv[\"grants\"].every(isGrant) &&\n\t\t\t\t(v[\"appName\"] === undefined || str(v[\"appName\"])) &&\n\t\t\t\t(v[\"pairing\"] === undefined || str(v[\"pairing\"]))\n\t\t\t\t? (v as unknown as SessionMessage)\n\t\t\t\t: undefined;\n\t\tcase \"ping\":\n\t\t\treturn typeof v[\"t\"] === \"number\"\n\t\t\t\t? (v as unknown as PingMessage)\n\t\t\t\t: undefined;\n\t\tcase \"bye\":\n\t\t\treturn { type: \"bye\", reason: str(v[\"reason\"]) ? v[\"reason\"] : \"\" };\n\t\tcase \"http.request\":\n\t\t\treturn str(v[\"id\"]) &&\n\t\t\t\tstr(v[\"method\"]) &&\n\t\t\t\tstr(v[\"path\"]) &&\n\t\t\t\tisStringRecord(v[\"headers\"]) &&\n\t\t\t\tstr(v[\"body\"]) &&\n\t\t\t\tisObject(v[\"grant\"]) &&\n\t\t\t\tstr(v[\"grant\"][\"grantId\"]) &&\n\t\t\t\tstr(v[\"grant\"][\"clientId\"])\n\t\t\t\t? (v as unknown as HttpRequestMessage)\n\t\t\t\t: undefined;\n\t\tcase \"http.cancel\":\n\t\t\treturn str(v[\"id\"]) ? (v as unknown as HttpCancelMessage) : undefined;\n\t\tcase \"pairing.code\":\n\t\t\treturn str(v[\"code\"]) && str(v[\"expiresAt\"])\n\t\t\t\t? (v as unknown as PairingCodeMessage)\n\t\t\t\t: undefined;\n\t\tcase \"grant.added\":\n\t\t\treturn isGrant(v[\"grant\"])\n\t\t\t\t? (v as unknown as GrantAddedMessage)\n\t\t\t\t: undefined;\n\t\tcase \"grant.removed\":\n\t\t\treturn str(v[\"grantId\"])\n\t\t\t\t? {\n\t\t\t\t\t\ttype: \"grant.removed\",\n\t\t\t\t\t\tgrantId: v[\"grantId\"],\n\t\t\t\t\t\treason: str(v[\"reason\"]) ? v[\"reason\"] : \"\",\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tcase \"identity.bound\":\n\t\t\treturn typeof v[\"round\"] === \"number\"\n\t\t\t\t? { type: \"identity.bound\", round: v[\"round\"] }\n\t\t\t\t: { type: \"identity.bound\" };\n\t\tcase \"error\":\n\t\t\treturn str(v[\"code\"]) ? (v as unknown as ErrorMessage) : undefined;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n",
|
|
14
|
-
"/**\n * The lazily loaded part (DEC-035): the WebSocket session with the relay, the\n * HTTP tunnel and the MCP handler. Loaded by `TabMcp.connect()`.\n */\n\nimport type { ConnectionHandle, ConnectionHost } from \"./internal.ts\";\nimport { createMcpHandler } from \"./mcp.ts\";\nimport {\n\ttype HttpRequestMessage,\n\tparseRelayMessage,\n\ttype RelayMessage,\n\tSUBPROTOCOL,\n\ttype TabMessage,\n} from \"./protocol.ts\";\nimport type { DisconnectReason, SessionInfo } from \"./types.ts\";\n\n/** For the core: compiles the schemas once this chunk (and the validator) is loaded. */\nexport { compileRegistry } from \"./mcp.ts\";\n\n/** How long `connect()` waits for the relay's `session`. */\nconst CONNECT_TIMEOUT_MS = 15_000;\n\nconst CLOSE_REASONS: Record<number, DisconnectReason> = {\n\t1000: \"closed\",\n\t1008: \"policy\",\n\t1009: \"too_large\",\n\t4001: \"expired\",\n\t4002: \"idle\",\n\t4003: \"heartbeat\",\n\t4004: \"shutdown\",\n\t4005: \"replaced\",\n\t4008: \"rate_limited\",\n};\n\nconst BYE_REASONS: Record<string, DisconnectReason> = {\n\treplaced: \"replaced\",\n\texpired: \"expired\",\n\tidle: \"idle\",\n\tshutdown: \"shutdown\",\n};\n\n/**\n * An error of `ready` that says why the connection did not open, so that\n * reconnecting retries only what may get better (DEC-082).\n */\nfunction refused(message: string, reason: DisconnectReason): Error {\n\treturn Object.assign(new Error(message), { reason });\n}\n\n/** Response headers the relay passes on (it drops the rest). */\nconst RESPONSE_HEADERS = [\"content-type\", \"cache-control\"];\n\nfunction pageTitle(): string {\n\tconst title = (globalThis as { document?: { title?: unknown } }).document\n\t\t?.title;\n\treturn typeof title === \"string\" ? title.slice(0, 300) : \"\";\n}\n\nfunction frameInfo(text: string): { type: string; id?: string } | undefined {\n\ttry {\n\t\tconst v = JSON.parse(text) as Record<string, unknown>;\n\t\tif (typeof v !== \"object\" || v === null || typeof v[\"type\"] !== \"string\")\n\t\t\treturn undefined;\n\t\treturn typeof v[\"id\"] === \"string\"\n\t\t\t? { type: v[\"type\"], id: v[\"id\"] }\n\t\t\t: { type: v[\"type\"] };\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nconst KNOWN_TYPES = new Set([\n\t\"session\",\n\t\"ping\",\n\t\"bye\",\n\t\"http.request\",\n\t\"http.cancel\",\n\t\"pairing.code\",\n\t\"grant.added\",\n\t\"grant.removed\",\n\t\"identity.bound\",\n\t\"error\",\n]);\n\n/**\n * Room for a message's envelope (`http.response` with its headers, or a\n * chunk) with an id of up to 128 characters (protocol limit).\n */\nconst ENVELOPE_BYTES = 512;\n/** Worst case per UTF-16 unit once JSON-encoded as UTF-8: `\\u0001` is 6 bytes. */\nconst WORST_BYTES_PER_UNIT = 6;\nconst MIN_CHUNK_UNITS = 64;\nexport const MIN_MESSAGE_BYTES: number =\n\tENVELOPE_BYTES + WORST_BYTES_PER_UNIT * MIN_CHUNK_UNITS;\n\n/**\n * The largest piece of body text (UTF-16 units) whose message cannot exceed\n * the relay's `maxMessageBytes`; `undefined` if the limit is too small to\n * frame anything useful.\n */\nexport function chunkSize(maxMessageBytes: number): number | undefined {\n\tconst units = Math.floor(\n\t\t(maxMessageBytes - ENVELOPE_BYTES) / WORST_BYTES_PER_UNIT,\n\t);\n\treturn units >= MIN_CHUNK_UNITS ? units : undefined;\n}\n\n/**\n * Split text into pieces of at most `max` UTF-16 units, never between the two\n * halves of a surrogate pair (a lone half would not survive JSON and UTF-8).\n */\nexport function* pieces(text: string, max: number): Generator<string> {\n\tlet i = 0;\n\twhile (i < text.length) {\n\t\tlet end = Math.min(i + max, text.length);\n\t\tconst last = text.charCodeAt(end - 1);\n\t\tif (end < text.length && last >= 0xd800 && last <= 0xdbff) {\n\t\t\tend += end - 1 > i ? -1 : 1; // keep the pair together\n\t\t}\n\t\tyield text.slice(i, end);\n\t\ti = end;\n\t}\n}\n\n/** Open the WebSocket and run the session. */\nexport function openConnection(\n\thost: ConnectionHost,\n\turl: string,\n\tsecret: string,\n): ConnectionHandle {\n\tconst ws = new WebSocket(url, SUBPROTOCOL);\n\tconst inflight = new Map<string, AbortController>();\n\tlet state: \"opening\" | \"ready\" | \"closed\" = \"opening\";\n\tlet byeReason: DisconnectReason | undefined;\n\tlet maxChunk = 64 * 1024;\n\tlet heartbeat: ReturnType<typeof setTimeout> | undefined;\n\tlet heartbeatMs = 0;\n\n\tlet resolveReady!: (session: SessionInfo) => void;\n\tlet rejectReady!: (error: Error) => void;\n\tconst ready = new Promise<SessionInfo>((resolve, reject) => {\n\t\tresolveReady = resolve;\n\t\trejectReady = reject;\n\t});\n\tready.catch(() => {}); // the caller handles it; never an unhandled rejection here\n\tconst connectTimer = setTimeout(() => {\n\t\tfail(refused(\"The relay did not answer in time.\", \"network\"));\n\t}, CONNECT_TIMEOUT_MS);\n\n\tconst handler = createMcpHandler({\n\t\ttools: host.registry,\n\t\tserver: host.server,\n\t\tconfirm: (request) => host.confirm(request),\n\t\tclient: (grant) => host.clientFor(grant),\n\t\tobserve: {\n\t\t\tstart: (call) => host.toolCallStarted(call),\n\t\t\tend: (call) => host.toolCallEnded(call),\n\t\t},\n\t});\n\tconst stopWatching = host.registry.onChange(() => handler.toolsChanged());\n\n\tfunction send(message: TabMessage): boolean {\n\t\tif (ws.readyState !== WebSocket.OPEN) return false;\n\t\ttry {\n\t\t\tws.send(JSON.stringify(message));\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/** Two missed pings mean the connection is dead (protocol: heartbeat). */\n\tfunction armHeartbeat(): void {\n\t\tif (heartbeatMs <= 0) return;\n\t\tclearTimeout(heartbeat);\n\t\theartbeat = setTimeout(() => {\n\t\t\tbyeReason ??= \"heartbeat\";\n\t\t\tfinish(4003);\n\t\t\ttry {\n\t\t\t\tws.close();\n\t\t\t} catch {\n\t\t\t\t// already closing\n\t\t\t}\n\t\t}, heartbeatMs * 2.5);\n\t}\n\n\tfunction fail(error: Error): void {\n\t\tif (state !== \"opening\") return;\n\t\tfinish(0);\n\t\trejectReady(error);\n\t\ttry {\n\t\t\tws.close();\n\t\t} catch {\n\t\t\t// already closed\n\t\t}\n\t}\n\n\t/** The session is over: clean up once and tell the host. */\n\tfunction finish(code: number): void {\n\t\tif (state === \"closed\") return;\n\t\tconst wasReady = state === \"ready\";\n\t\tstate = \"closed\";\n\t\tclearTimeout(connectTimer);\n\t\tclearTimeout(heartbeat);\n\t\tstopWatching();\n\t\tfor (const controller of inflight.values()) controller.abort();\n\t\tinflight.clear();\n\t\thandler.close();\n\t\tif (wasReady) {\n\t\t\tconst reason =\n\t\t\t\tbyeReason ??\n\t\t\t\tCLOSE_REASONS[code] ??\n\t\t\t\t(code === 1006 ? \"network\" : \"closed\");\n\t\t\thost.closed(reason, code);\n\t\t}\n\t}\n\n\tasync function tunnel(msg: HttpRequestMessage): Promise<void> {\n\t\tconst controller = new AbortController();\n\t\tinflight.set(msg.id, controller);\n\t\tconst live = () =>\n\t\t\tstate === \"ready\" &&\n\t\t\tinflight.get(msg.id) === controller &&\n\t\t\t!controller.signal.aborted;\n\t\ttry {\n\t\t\tconst request = new Request(`https://tab.invalid${msg.path}`, {\n\t\t\t\tmethod: msg.method,\n\t\t\t\theaders: msg.headers,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst response = await handler.handle(request, {\n\t\t\t\tgrant: msg.grant,\n\t\t\t\tbody: msg.body,\n\t\t\t});\n\t\t\tif (!live()) {\n\t\t\t\tawait response.body?.cancel().catch(() => {});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst headers: Record<string, string> = {};\n\t\t\tfor (const name of RESPONSE_HEADERS) {\n\t\t\t\tconst value = response.headers.get(name);\n\t\t\t\tif (value !== null) headers[name] = value;\n\t\t\t}\n\t\t\tconst streamed = (headers[\"content-type\"] ?? \"\").startsWith(\n\t\t\t\t\"text/event-stream\",\n\t\t\t);\n\t\t\tif (!streamed || response.body === null) {\n\t\t\t\tconst body = await response.text();\n\t\t\t\tif (!live()) return;\n\t\t\t\tif (body.length <= maxChunk) {\n\t\t\t\t\tsend({\n\t\t\t\t\t\ttype: \"http.response\",\n\t\t\t\t\t\tid: msg.id,\n\t\t\t\t\t\tstatus: response.status,\n\t\t\t\t\t\theaders,\n\t\t\t\t\t\tbody,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Too big for one message: stream it (the relay passes it on whole).\n\t\t\t\tsend({\n\t\t\t\t\ttype: \"http.response.start\",\n\t\t\t\t\tid: msg.id,\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\theaders,\n\t\t\t\t});\n\t\t\t\tfor (const data of pieces(body, maxChunk)) {\n\t\t\t\t\tif (!live()) break;\n\t\t\t\t\tsend({ type: \"http.response.chunk\", id: msg.id, data });\n\t\t\t\t}\n\t\t\t\tif (live()) send({ type: \"http.response.end\", id: msg.id });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsend({\n\t\t\t\ttype: \"http.response.start\",\n\t\t\t\tid: msg.id,\n\t\t\t\tstatus: response.status,\n\t\t\t\theaders,\n\t\t\t});\n\t\t\tconst reader = response.body.getReader();\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tcontroller.signal.addEventListener(\"abort\", () => {\n\t\t\t\treader.cancel().catch(() => {});\n\t\t\t});\n\t\t\tfor (;;) {\n\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\tif (done || !live()) break;\n\t\t\t\tconst text = decoder.decode(value, { stream: true });\n\t\t\t\tfor (const data of pieces(text, maxChunk)) {\n\t\t\t\t\tsend({ type: \"http.response.chunk\", id: msg.id, data });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (live()) send({ type: \"http.response.end\", id: msg.id });\n\t\t} catch (error) {\n\t\t\tif (live()) {\n\t\t\t\thost.error(error instanceof Error ? error : new Error(String(error)));\n\t\t\t\tsend({\n\t\t\t\t\ttype: \"http.response\",\n\t\t\t\t\tid: msg.id,\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\t\t\tid: null,\n\t\t\t\t\t\terror: { code: -32603, message: \"Internal server error\" },\n\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t}\n\t\t} finally {\n\t\t\tif (inflight.get(msg.id) === controller) inflight.delete(msg.id);\n\t\t}\n\t}\n\n\tfunction onMessage(message: RelayMessage): void {\n\t\tif (state === \"opening\") {\n\t\t\tif (message.type === \"session\") {\n\t\t\t\tconst chunk = chunkSize(message.limits.maxMessageBytes);\n\t\t\t\tif (chunk === undefined) {\n\t\t\t\t\tfail(\n\t\t\t\t\t\trefused(\n\t\t\t\t\t\t\t`The relay's message limit (${message.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${MIN_MESSAGE_BYTES}.`,\n\t\t\t\t\t\t\t\"policy\",\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tmaxChunk = chunk;\n\t\t\t\tstate = \"ready\";\n\t\t\t\tclearTimeout(connectTimer);\n\t\t\t\theartbeatMs = message.limits.heartbeatMs;\n\t\t\t\tarmHeartbeat();\n\t\t\t\tresolveReady(host.sessionStarted(message));\n\t\t\t} else if (message.type === \"error\") {\n\t\t\t\tfail(\n\t\t\t\t\trefused(\n\t\t\t\t\t\t`The relay refused the connection: ${message.message || message.code}`,\n\t\t\t\t\t\tmessage.code === \"rate_limited\" ? \"rate_limited\" : \"policy\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t} else if (message.type === \"bye\") {\n\t\t\t\tfail(\n\t\t\t\t\trefused(\n\t\t\t\t\t\t`The relay ended the connection: ${message.reason}`,\n\t\t\t\t\t\tBYE_REASONS[message.reason] ?? \"closed\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (state !== \"ready\") return;\n\t\tswitch (message.type) {\n\t\t\tcase \"ping\":\n\t\t\t\tarmHeartbeat();\n\t\t\t\tsend({ type: \"pong\", t: message.t });\n\t\t\t\treturn;\n\t\t\tcase \"http.request\":\n\t\t\t\tvoid tunnel(message);\n\t\t\t\treturn;\n\t\t\tcase \"http.cancel\":\n\t\t\t\tinflight.get(message.id)?.abort();\n\t\t\t\tinflight.delete(message.id);\n\t\t\t\treturn;\n\t\t\tcase \"pairing.code\":\n\t\t\t\thost.pairingCode({ code: message.code, expiresAt: message.expiresAt });\n\t\t\t\treturn;\n\t\t\tcase \"grant.added\":\n\t\t\t\thost.grantAdded(message.grant);\n\t\t\t\treturn;\n\t\t\tcase \"grant.removed\":\n\t\t\t\thost.grantRemoved(message.grantId);\n\t\t\t\treturn;\n\t\t\tcase \"identity.bound\":\n\t\t\t\thost.identityResult(true, message.round);\n\t\t\t\treturn;\n\t\t\tcase \"bye\":\n\t\t\t\tbyeReason = BYE_REASONS[message.reason] ?? \"closed\";\n\t\t\t\tif (byeReason === \"replaced\") host.replaced();\n\t\t\t\treturn;\n\t\t\tcase \"error\":\n\t\t\t\tif (message.code === \"identity_refused\") {\n\t\t\t\t\thost.identityResult(\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\ttypeof message.round === \"number\" ? message.round : undefined,\n\t\t\t\t\t\tmessage.message,\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\thost.error(\n\t\t\t\t\tnew Error(`Relay error ${message.code}: ${message.message}`),\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\tcase \"session\":\n\t\t\t\treturn; // only once\n\t\t}\n\t}\n\n\tws.addEventListener(\"open\", () => {\n\t\tif (ws.protocol !== \"\" && ws.protocol !== SUBPROTOCOL) {\n\t\t\tfail(\n\t\t\t\trefused(\n\t\t\t\t\t`The relay speaks ${ws.protocol}, not ${SUBPROTOCOL}.`,\n\t\t\t\t\t\"policy\",\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst hello: TabMessage = {\n\t\t\ttype: \"hello\",\n\t\t\tlibrary: host.library,\n\t\t\tpage: { title: pageTitle() },\n\t\t\tsecret,\n\t\t};\n\t\tif (host.appName !== undefined) hello.app = { name: host.appName };\n\t\tsend(hello);\n\t});\n\tws.addEventListener(\"message\", (event: MessageEvent) => {\n\t\tif (typeof event.data !== \"string\") return;\n\t\tconst message = parseRelayMessage(event.data);\n\t\tif (message !== undefined) {\n\t\t\tif (state === \"ready\") armHeartbeat(); // any traffic shows the link is alive\n\t\t\tonMessage(message);\n\t\t\treturn;\n\t\t}\n\t\tconst info = frameInfo(event.data);\n\t\tif (info?.id !== undefined) {\n\t\t\tsend(\n\t\t\t\tKNOWN_TYPES.has(info.type)\n\t\t\t\t\t? {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tcode: \"bad_message\",\n\t\t\t\t\t\t\tmessage: `malformed ${info.type}`,\n\t\t\t\t\t\t\tid: info.id,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tcode: \"unknown_type\",\n\t\t\t\t\t\t\tmessage: `unknown type ${info.type}`,\n\t\t\t\t\t\t\tid: info.id,\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t}\n\t});\n\tws.addEventListener(\"close\", (event: CloseEvent) => {\n\t\tif (state === \"opening\") {\n\t\t\tfinish(event.code);\n\t\t\t// No WebSocket at all: browsers say 1006, Bun 1002. The page cannot\n\t\t\t// tell a refused origin from an unreachable relay (DEC-082).\n\t\t\tconst unreachable = event.code === 1006 || event.code === 1002;\n\t\t\trejectReady(\n\t\t\t\trefused(\n\t\t\t\t\tunreachable\n\t\t\t\t\t\t? \"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).\"\n\t\t\t\t\t\t: `The relay closed the connection (${event.code}${event.reason ? `: ${event.reason}` : \"\"}).`,\n\t\t\t\t\tCLOSE_REASONS[event.code] ?? (unreachable ? \"network\" : \"closed\"),\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tfinish(event.code);\n\t});\n\n\treturn {\n\t\tready,\n\t\tsend,\n\t\tclose(reason: DisconnectReason) {\n\t\t\tif (state === \"closed\") return;\n\t\t\tif (state === \"opening\") {\n\t\t\t\tfail(\n\t\t\t\t\tnew DOMException(\n\t\t\t\t\t\t\"The connection was cancelled\",\n\t\t\t\t\t\t\"AbortError\",\n\t\t\t\t\t) as Error,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbyeReason = reason;\n\t\t\tsend({ type: \"bye\", reason: \"user\" });\n\t\t\tfinish(1000);\n\t\t\ttry {\n\t\t\t\tws.close(1000, \"bye\");\n\t\t\t} catch {\n\t\t\t\t// already closed\n\t\t\t}\n\t\t},\n\t};\n}\n"
|
|
15
|
-
],
|
|
16
|
-
"mappings": "AAAO,SAAS,EAAiB,CAAC,EAAG,EAAG,CACpC,IAAM,EAAU,OAAO,EACvB,GAAI,IAAY,OAAO,EACnB,MAAO,GAEX,GAAI,MAAM,QAAQ,CAAC,EAAG,CAClB,GAAI,CAAC,MAAM,QAAQ,CAAC,EAChB,MAAO,GAEX,IAAM,EAAS,EAAE,OACjB,GAAI,IAAW,EAAE,OACb,MAAO,GAEX,QAAS,EAAI,EAAG,EAAI,EAAQ,IACxB,GAAI,CAAC,GAAkB,EAAE,GAAI,EAAE,EAAE,EAC7B,MAAO,GAGf,MAAO,GAEX,GAAI,IAAY,SAAU,CACtB,GAAI,CAAC,GAAK,CAAC,EACP,OAAO,IAAM,EAEjB,IAAM,EAAQ,OAAO,KAAK,CAAC,EACrB,EAAQ,OAAO,KAAK,CAAC,EAE3B,GADe,EAAM,SACN,EAAM,OACjB,MAAO,GAEX,QAAW,KAAK,EACZ,GAAI,CAAC,GAAkB,EAAE,GAAI,EAAE,EAAE,EAC7B,MAAO,GAGf,MAAO,GAEX,OAAO,IAAM,ECrCV,SAAS,CAAa,CAAC,EAAG,CAC7B,OAAO,UAAU,GAAc,CAAC,CAAC,EAE9B,SAAS,EAAa,CAAC,EAAG,CAC7B,OAAO,EAAE,QAAQ,KAAM,IAAI,EAAE,QAAQ,MAAO,IAAI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,EACC,CACA,KAAM,QACN,KAAM,eACN,QAAS,gBAAgB,EAAK,OAC9B,GAAI,EAAK,EACV,CACH,EAED,EACD,EAAG,iBAAiB,QAAS,CAAC,IAAsB,CACnD,GAAI,IAAU,UAAW,CACxB,EAAO,EAAM,IAAI,EAGjB,IAAM,EAAc,EAAM,OAAS,MAAQ,EAAM,OAAS,KAC1D,EACC,GACC,EACG,+FACA,oCAAoC,EAAM,OAAO,EAAM,OAAS,KAAK,EAAM,SAAW,OACzF,GAAc,EAAM,QAAU,EAAc,UAAY,SACzD,CACD,EACA,OAED,EAAO,EAAM,IAAI,EACjB,EAEM,CACN,SACA,OACA,KAAK,CAAC,EAA0B,CAC/B,GAAI,IAAU,SAAU,OACxB,GAAI,IAAU,UAAW,CACxB,EACC,IAAI,aACH,+BACA,YACD,CACD,EACA,OAED,EAAY,EACZ,EAAK,CAAE,KAAM,MAAO,OAAQ,MAAO,CAAC,EACpC,EAAO,IAAI,EACX,GAAI,CACH,EAAG,MAAM,KAAM,KAAK,EACnB,KAAM,GAIV",
|
|
17
|
-
"debugId": "49574567FC8D9C0964756E2164756E21",
|
|
18
|
-
"names": []
|
|
19
|
-
}
|
package/cdn/ui-n9c73wge.min.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
var J=0;function r(e,n,t={},...d){let s=e.createElement(n);if(t.className!==void 0)s.className=t.className;if(t.id!==void 0)s.id=t.id;if(t.text!==void 0)s.textContent=t.text;return s.append(...d),s}function f(e,n,t,d,s){let o=r(e,"button",{text:n});if(o.type="button",d!==void 0)o.classList.add(d);if(s!==void 0)o.classList.add(`tab-mcp-${s}`);return o.addEventListener("click",t),o}var he=`.tab-mcp-dialog {
|
|
2
|
-
--_tab-mcp-fg: var(--tab-mcp-color, CanvasText);
|
|
3
|
-
--_tab-mcp-bg: var(--tab-mcp-background, Canvas);
|
|
4
|
-
--_tab-mcp-muted: var(--tab-mcp-muted, color-mix(in srgb, var(--_tab-mcp-fg) 72%, transparent));
|
|
5
|
-
--_tab-mcp-line: color-mix(in srgb, var(--_tab-mcp-fg) 22%, transparent);
|
|
6
|
-
--_tab-mcp-surface: var(--tab-mcp-surface, color-mix(in srgb, var(--_tab-mcp-fg) 6%, transparent));
|
|
7
|
-
--_tab-mcp-danger: var(--tab-mcp-danger, light-dark(#b3261e, #ffb4ab));
|
|
8
|
-
--_tab-mcp-mono: var(--tab-mcp-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
9
|
-
--_tab-mcp-small-radius: calc(var(--tab-mcp-radius, 0.75rem) * 0.6);
|
|
10
|
-
box-sizing: border-box; width: calc(100% - 2rem); max-width: var(--tab-mcp-max-width, 34rem); max-height: calc(100% - 2rem); overflow: auto;
|
|
11
|
-
font: var(--tab-mcp-font, inherit); line-height: 1.5; color: var(--_tab-mcp-fg); background: var(--_tab-mcp-bg);
|
|
12
|
-
border: var(--tab-mcp-border, 1px solid var(--_tab-mcp-line)); border-radius: var(--tab-mcp-radius, 0.75rem);
|
|
13
|
-
padding: var(--tab-mcp-padding, clamp(1rem, 5vw, 1.5rem)); box-shadow: var(--tab-mcp-shadow, 0 1rem 3rem rgb(0 0 0 / 0.3));
|
|
14
|
-
}
|
|
15
|
-
.tab-mcp-dialog::backdrop { background: var(--tab-mcp-backdrop, rgb(0 0 0 / 0.4)); }
|
|
16
|
-
.tab-mcp-dialog:where([open]) { display: flex; flex-direction: column; gap: 1rem; }
|
|
17
|
-
.tab-mcp-dialog:where([open]) > * { flex-shrink: 0; }
|
|
18
|
-
.tab-mcp-dialog :where([hidden]) { display: none !important; }
|
|
19
|
-
html dialog.tab-mcp-dialog:where(:focus) { outline: none; }
|
|
20
|
-
.tab-mcp-dialog :where(*) { box-sizing: border-box; }
|
|
21
|
-
.tab-mcp-dialog :where(h2, h3, p, ul, li, pre) { margin: 0; }
|
|
22
|
-
.tab-mcp-dialog :where(h2) { font-size: var(--tab-mcp-title-size, 1.25em); line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
|
|
23
|
-
.tab-mcp-dialog :where(h3) { font-size: 0.875em; font-weight: 600; color: var(--_tab-mcp-muted); margin-bottom: 0.5rem; }
|
|
24
|
-
.tab-mcp-dialog :where(small) { font-size: 0.875em; }
|
|
25
|
-
.tab-mcp-dialog :where(small, .tab-mcp-status, .tab-mcp-description, .tab-mcp-always-note, .tab-mcp-apps-note) { color: var(--_tab-mcp-muted); }
|
|
26
|
-
html dialog.tab-mcp-dialog :where(:focus-visible) { outline: 2px solid var(--tab-mcp-focus, var(--_tab-mcp-fg)); outline-offset: 2px; }
|
|
27
|
-
.tab-mcp-dialog :where(button) { font: inherit; font-size: 0.9375em; line-height: 1.25; min-height: 2.5rem; padding: 0.5rem 1rem; margin: 0; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: var(--_tab-mcp-small-radius); background: transparent; color: inherit; cursor: pointer; }
|
|
28
|
-
html dialog.tab-mcp-dialog :where(button:hover:not(:disabled)) { color: inherit; background: color-mix(in srgb, currentColor 8%, transparent); }
|
|
29
|
-
html dialog.tab-mcp-dialog :where(button:disabled) { opacity: 0.45; cursor: not-allowed; }
|
|
30
|
-
html button.tab-mcp-primary { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); color: var(--tab-mcp-accent-text, var(--_tab-mcp-bg)); border-color: transparent; font-weight: 600; }
|
|
31
|
-
html button.tab-mcp-primary:where(:hover:not(:disabled)) { background: var(--tab-mcp-accent, var(--_tab-mcp-fg)); opacity: 0.85; }
|
|
32
|
-
html button.tab-mcp-danger { color: var(--_tab-mcp-danger); border-color: color-mix(in srgb, currentColor 45%, transparent); }
|
|
33
|
-
.tab-mcp-copy { min-width: 6em; }
|
|
34
|
-
.tab-mcp-close { font-size: 0.875em; }
|
|
35
|
-
.tab-mcp-status { margin-top: -0.5rem; }
|
|
36
|
-
.tab-mcp-description:where(:empty) { display: none; }
|
|
37
|
-
.tab-mcp-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
|
|
38
|
-
.tab-mcp-address { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
|
|
39
|
-
.tab-mcp-address :where(label) { flex-basis: 100%; font-weight: 600; }
|
|
40
|
-
.tab-mcp-address :where(input) { flex: 1 1 12rem; min-width: 0; min-height: 2.5rem; margin: 0; padding: 0.5rem 0.625rem; font: 0.875em var(--_tab-mcp-mono); text-overflow: ellipsis; color: inherit; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
41
|
-
.tab-mcp-code { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.25rem 1rem; padding: 1rem; background: var(--_tab-mcp-surface); border-radius: var(--_tab-mcp-small-radius); }
|
|
42
|
-
.tab-mcp-code > :where(span) { font-weight: 600; }
|
|
43
|
-
.tab-mcp-code :where(br) { display: none; }
|
|
44
|
-
.tab-mcp-code :where(small) { grid-column: 1 / -1; }
|
|
45
|
-
.tab-mcp-code-value { display: block; font: 700 var(--tab-mcp-code-size, 2em) / 1.2 var(--_tab-mcp-mono); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
|
|
46
|
-
.tab-mcp-help :where(summary) { width: fit-content; cursor: pointer; }
|
|
47
|
-
.tab-mcp-dialog :where(.tab-mcp-help ul, .tab-mcp-apps ul) { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
|
|
48
|
-
.tab-mcp-help :where(ul) { margin-top: 0.75rem; gap: 0.75rem; }
|
|
49
|
-
.tab-mcp-help :where(li) { overflow-wrap: anywhere; }
|
|
50
|
-
.tab-mcp-help :where(strong) { display: block; font-weight: 600; }
|
|
51
|
-
.tab-mcp-command { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; gap: 0.5rem; margin-top: 0.375rem; }
|
|
52
|
-
.tab-mcp-command > :where(pre) { flex: 1 1 16rem; min-width: 0; margin: 0; padding: 0.5rem 0.625rem; font: 0.8125em / 1.5 var(--_tab-mcp-mono); white-space: pre-wrap; word-break: break-all; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
53
|
-
.tab-mcp-command-note { display: block; margin-top: 0.375rem; }
|
|
54
|
-
.tab-mcp-help :where(code) { font: 0.875em var(--_tab-mcp-mono); padding: 0.125em 0.375em; background: var(--_tab-mcp-surface); border-radius: 0.25rem; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
|
|
55
|
-
.tab-mcp-apps :where(li) { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
56
|
-
.tab-mcp-app { min-width: 0; overflow-wrap: anywhere; }
|
|
57
|
-
.tab-mcp-apps-note { margin-top: 0.5rem; }
|
|
58
|
-
.tab-mcp-new-address-question { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid color-mix(in srgb, var(--_tab-mcp-danger) 50%, transparent); border-radius: var(--_tab-mcp-small-radius); }
|
|
59
|
-
.tab-mcp-connect > :where(.tab-mcp-actions) { gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--_tab-mcp-line); }
|
|
60
|
-
.tab-mcp-close-note { flex: 1 1 12rem; }
|
|
61
|
-
.tab-mcp-confirm :where(p bdi) { font-weight: 600; }
|
|
62
|
-
.tab-mcp-arguments { box-sizing: content-box; font: 0.875em / 1.45 var(--_tab-mcp-mono); padding: 0.75rem; background: var(--_tab-mcp-surface); border: 1px solid var(--_tab-mcp-line); border-radius: var(--_tab-mcp-small-radius); }
|
|
63
|
-
.tab-mcp-always-note { font-size: 0.875em; }
|
|
64
|
-
@media (max-width: 30rem) { .tab-mcp-actions > :where(button) { flex: 1 1 auto; } .tab-mcp-connect > :where(.tab-mcp-actions) > :where(button) { flex: 0 0 auto; } }
|
|
65
|
-
@media (prefers-reduced-motion: no-preference) { .tab-mcp-dialog:where([open]) { animation: tab-mcp-in 0.15s ease-out; } }
|
|
66
|
-
@media (forced-colors: active) { html button.tab-mcp-primary { border-color: ButtonText; } }
|
|
67
|
-
@keyframes tab-mcp-in { from { opacity: 0; transform: translateY(0.5rem); } }
|
|
68
|
-
`,ce=new WeakMap;function we(e){try{let n=ce.get(e);if(n===void 0){let t=e.defaultView?.CSSStyleSheet;if(t===void 0||!Array.isArray(e.adoptedStyleSheets))return;n=new t,n.replaceSync(he),ce.set(e,n)}if(!e.adoptedStyleSheets.includes(n))e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]}catch{}}function U(e,n,t,d,s,o,h){let p=f(e,"Copy",()=>{let b=()=>{p.textContent="Copied",p.setAttribute("aria-label",`Copied ${n}`),s(`${n[0]?.toUpperCase()}${n.slice(1)} copied`)},l=()=>{d(),s("Selected: copy it with Ctrl+C or ⌘C")},w=e.defaultView?.navigator?.clipboard;if(w!==void 0)w.writeText(t()).then(b,l);else l()},o,h);p.classList.add("tab-mcp-copy");let v=()=>{p.textContent="Copy",p.setAttribute("aria-label",`Copy ${n}`)};return v(),{button:p,reset:v}}function le(e,n,t){let d=`tab-mcp-${++J}`,s=r(e,"dialog",{className:`tab-mcp-dialog ${n}`});s.setAttribute("aria-labelledby",`${d}-title`),we(e);let o=r(e,"h2",{id:`${d}-title`,text:t});return s.append(o),{dialog:s,heading:o}}var ve=/[\p{Cf}\p{Default_Ignorable_Code_Point}\p{Co}\p{Cn}\u0080-\u009F\u2028\u2029]/gu;function Q(e){return e.replace(ve,(n)=>{let t="";for(let d=0;d<n.length;d++)t+=`\\u${n.charCodeAt(d).toString(16).toUpperCase().padStart(4,"0")}`;return t})}function O(e){let n=Q(e.host||e.id);return e.name!==void 0&&e.name!==""?`${Q(e.name)} (${n})`:n}function D(e,n){let t=r(e,"bdi",{text:n});return t.dir="ltr",t}function ye(e){try{return Q(JSON.stringify(e,null,2))}catch{return}}var xe=750,Ce=500;function _e(e){let n=typeof e==="number"&&Number.isFinite(e)&&e<2147483648?e:xe;return Math.max(Ce,n)}function ke(e,n,t={}){let d=_e(t.allowDelayMs);if(e.signal.aborted)return Promise.resolve("deny");let s=e.tool.title??e.tool.name,{dialog:o,heading:h}=le(n,"tab-mcp-confirm","");h.append("Allow ",D(n,s),"?");let p=O(e.client),v=f(n,"Don't allow",()=>o.close("deny"),"tab-mcp-deny","primary"),b=f(n,"Allow",()=>{if(!b.disabled)o.close("allow")},"tab-mcp-allow"),l=f(n,"Always allow",()=>{if(!l.disabled)o.close("always")},"tab-mcp-always");b.disabled=!0,l.disabled=!0;let w=r(n,"div",{className:"tab-mcp-actions"},v," ",b," ",l),T=r(n,"p",{className:"tab-mcp-always-note"},"Always allow: ",D(n,s)," runs without asking for ",D(n,p)," until you reload this page or disconnect it."),y=ye(e.arguments),m=r(n,"pre",{className:"tab-mcp-arguments",text:y??"The arguments cannot be shown, so this call cannot be allowed."});if(y===void 0)b.hidden=!0,l.hidden=!0,T.hidden=!0;m.dir="ltr",m.style.setProperty("white-space","pre-wrap"),m.style.setProperty("overflow-wrap","anywhere"),m.style.setProperty("max-height","var(--tab-mcp-arguments-height, 12rem)"),m.style.setProperty("overflow","auto"),m.hidden=Object.keys(e.arguments).length===0,o.append(r(n,"p",{},D(n,p)," wants to run ",D(n,s),"."),r(n,"p",{className:"tab-mcp-description",text:e.tool.description}),m,w,T),n.body.append(o);let x=n.defaultView;return new Promise((I)=>{let L=()=>o.close("deny");e.signal.addEventListener("abort",L,{once:!0});let _,c=(u)=>{if(clearTimeout(_),_=void 0,b.disabled=!0,l.disabled=!0,u?.type==="blur"||n.visibilityState==="hidden"||!n.hasFocus())return;_=setTimeout(()=>{b.disabled=!1,l.disabled=!1},d)};n.addEventListener("visibilitychange",c),x?.addEventListener("focus",c),x?.addEventListener("blur",c),o.addEventListener("close",()=>{clearTimeout(_),n.removeEventListener("visibilitychange",c),x?.removeEventListener("focus",c),x?.removeEventListener("blur",c),e.signal.removeEventListener("abort",L);let u=o.returnValue;o.remove(),I(u==="allow"||u==="always"?u:"deny")},{once:!0}),o.showModal(),v.focus(),c()})}function Ne(e){let n=e.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"");return n===""?"tools":n}function Ae(e){try{let n=new URL(e).href;return/^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(n)?n:void 0}catch{return}}var Y="mcp_2026_07_28";function Se(e,n){let t=Ne(e),d=Ae(n);return[["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."],d===void 0?["Claude Code","Add the address with claude mcp add --transport http."]:["Claude Code","Run:",`claude mcp add --transport http ${t} ${d}`],["Codex",...d===void 0?[`Run codex features enable ${Y}, then add the address with codex mcp add --url.`,void 0]:["Run:",`codex features enable ${Y}
|
|
69
|
-
codex mcp add ${t} --url ${d}`],["Start a new chat in Codex after it connects. The first line turns on a feature for all of Codex's MCP servers; ",`codex features disable ${Y}`," turns it off."]]]}function Le(e){return e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`}function Ee(e,n,t,d="tools"){let{dialog:s}=le(t,"tab-mcp-connect","Connect your AI app");s.tabIndex=-1;let o=r(t,"p",{className:"tab-mcp-status",text:"Connecting…"});o.setAttribute("role","status");let h=r(t,"span",{className:"tab-mcp-announce"});h.setAttribute("aria-live","polite");for(let[a,i]of[["position","absolute"],["width","1px"],["height","1px"],["overflow","hidden"],["clip-path","inset(50%)"],["white-space","nowrap"]])h.style.setProperty(a,i);let p=(a)=>{h.textContent=h.textContent===a?`${a} `:a},v=`tab-mcp-${++J}-address`,b=r(t,"label",{text:"Add this address to your AI app:"});b.htmlFor=v;let l=r(t,"input",{id:v,className:"tab-mcp-address-input"});l.readOnly=!0;let{button:w,reset:T}=U(t,"address",()=>l.value,()=>l.select(),p,"tab-mcp-address-copy","primary"),y=f(t,"New address",()=>ge(),"tab-mcp-new-address"),m=r(t,"div",{className:"tab-mcp-address"},b,l," ",w," ",y),x=`tab-mcp-${++J}-new-address`,I=r(t,"p",{id:x}),L=f(t,"Cancel",()=>{c.hidden=!0,y.focus()}),_=f(t,"Disconnect and get new address",()=>ae(),"tab-mcp-new-address-confirm","danger"),c=r(t,"div",{className:"tab-mcp-new-address-question"},I,r(t,"div",{className:"tab-mcp-actions"},L," ",_));c.setAttribute("role","group"),c.setAttribute("aria-labelledby",x),c.hidden=!0;let u=r(t,"strong",{className:"tab-mcp-code-value"});u.style.setProperty("user-select","all"),u.style.setProperty("-webkit-user-select","all");let{button:pe,reset:me}=U(t,"code",()=>u.textContent??"",()=>t.getSelection()?.selectAllChildren(u),p,"tab-mcp-code-copy"),X=r(t,"span",{},"When asked, enter the code ",u);X.setAttribute("aria-live","polite");let M=r(t,"p",{className:"tab-mcp-code"},X," ",pe,r(t,"br"),r(t,"small",{className:"tab-mcp-code-note",text:"A new code appears every 2 minutes and after each use."})),B=r(t,"p",{className:"tab-mcp-sign-in",text:"When your AI app asks, sign in with the account you use on this page. No code is needed."}),Z=r(t,"ul"),P=r(t,"details",{className:"tab-mcp-help"},r(t,"summary",{text:"How do I add it?"}),Z),q=r(t,"ul"),z=r(t,"div",{className:"tab-mcp-apps"},r(t,"h3",{text:"Connected"}),q),ee=r(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."}),N=f(t,"Close",()=>s.close(),"tab-mcp-close"),A=f(t,"Done",()=>s.close(),"tab-mcp-done","primary");A.hidden=!0;let ue=r(t,"div",{className:"tab-mcp-actions"},ee," ",N,A),g=!1,F=new Set,te=()=>{ee.hidden=g||M.hidden},G=(a)=>{if(g=a,!g)F.clear();let i=t.activeElement;if(te(),N.hidden=g,A.hidden=!g,g&&i===N)A.focus();if(!g&&i===A)N.focus()},be=()=>g?A:N;s.append(o,m,c,M,B,P,z,ue,h),m.hidden=!0,M.hidden=!0,B.hidden=!0,P.hidden=!0,z.hidden=!0;let R=!1,ne=()=>{let a=e.grants.map((i)=>O(i.client));if(a.length===0)return!1;return I.textContent=`A new address disconnects ${Le(a)}. To use this page again, add the new address to ${a.length===1?"it":"them"}.`,!0},ge=()=>{if(e.state!=="connected")return;if(!ne()){ae();return}c.hidden=!1,L.focus()},ae=()=>{G(!1),N.focus(),c.hidden=!0,R=!0,o.textContent="Getting a new address…",e.newAddress().then(()=>{R=!1,o.textContent="This is a new address. Add it to your AI app again.",w.focus()},(a)=>{R=!1,o.textContent=`Could not connect: ${a instanceof Error?a.message:String(a)}. Close this and connect again.`,be().focus()})},H=(a)=>{if(a===void 0){m.hidden=!0,c.hidden=!0,P.hidden=!0;return}l.value=a.address,T();let i=a.appName??e.appName;if(!R)o.textContent=i!==void 0?`${i} is ready for your AI app.`:"This page is ready for your AI app.";if(y.disabled=e.state!=="connected",m.hidden=!1,t.activeElement===s)w.focus();P.hidden=!1,Z.replaceChildren(...Se(d,a.address).map(([E,fe,ie,de])=>{let V=r(t,"li",{},r(t,"strong",{text:`${E}:`}),` ${fe}`);if(ie!==void 0){let C=r(t,"pre",{text:ie});C.dir="ltr";let{button:K}=U(t,`${E} command`,()=>C.textContent??"",()=>t.getSelection()?.selectAllChildren(C),p,"tab-mcp-command-copy");V.append(r(t,"div",{className:"tab-mcp-command"},C,K))}if(de!==void 0)V.append(r(t,"small",{className:"tab-mcp-command-note"},...de.map((C,K)=>K%2===1?r(t,"code",{text:C}):C)));return V}))},k=()=>{let a=e.pairingCode,i=e.session?.pairing==="oidc";if(u.textContent!==(a?.code??""))me();u.textContent=a?.code??"",M.hidden=i||a===void 0,B.hidden=!i,te()},W=r(t,"p",{className:"tab-mcp-apps-note"});z.append(W);let j=new Set(e.grants.map((a)=>a.grantId)),re=e.session,S=()=>{if(e.session!==re){re=e.session;for(let i of e.grants)j.add(i.grantId)}for(let i of e.grants){if(j.has(i.grantId))continue;if(j.add(i.grantId),o.textContent=`${O(i.client)} is connected.`,F.add(i.grantId),!g)G(!0)}if(g&&!e.grants.some((i)=>F.has(i.grantId)))G(!1);let a=e.state==="connected";if(q.replaceChildren(...e.grants.map((i)=>{let E=f(t,"Disconnect",()=>{if(!e.revoke(i.grantId))S()},"tab-mcp-disconnect","danger");return E.disabled=!a,r(t,"li",{},r(t,"span",{className:"tab-mcp-app",text:`${O(i.client)} connected `}),E)})),W.textContent=a?"":"To disconnect an app, connect this page again first.",W.hidden=a,z.hidden=e.grants.length===0,!c.hidden&&!ne())c.hidden=!0,y.focus()},oe=(a)=>{if(a.detail.reason!=="new_address")o.textContent="Disconnected. AI apps can use this page again after you connect.";H(void 0),S(),k()},se=()=>{H(e.session),S(),k()};return e.addEventListener("pairingcode",k),e.addEventListener("grantschange",S),e.addEventListener("connected",se),e.addEventListener("disconnected",oe),t.body.append(s),e.startPairing(),S(),k(),H(e.session),n.then((a)=>H(a),(a)=>{o.textContent=`Could not connect: ${a instanceof Error?a.message:String(a)}`}),new Promise((a)=>{if(s.addEventListener("close",()=>{e.stopPairing(),e.removeEventListener("pairingcode",k),e.removeEventListener("grantschange",S),e.removeEventListener("connected",se),e.removeEventListener("disconnected",oe),s.remove(),a()},{once:!0}),s.showModal(),!m.hidden)w.focus();else s.focus()})}export{ke as confirmDialog,Ee as showConnectDialog};
|
|
70
|
-
|
|
71
|
-
//# debugId=A1374C5C3245218E64756E2164756E21
|
|
72
|
-
//# sourceMappingURL=ui-n9c73wge.min.js.map
|