@crewx/sdk 0.9.0-rc.161 → 0.9.0-rc.162
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/dist/agent-interceptor/chain.d.ts +25 -0
- package/dist/agent-interceptor/index.d.ts +6 -0
- package/dist/agent-interceptor/model-runner.d.ts +19 -0
- package/dist/agent-interceptor/program-runner.d.ts +13 -0
- package/dist/agent-interceptor/protocol.d.ts +68 -0
- package/dist/agent-interceptor/run-stop.d.ts +3 -0
- package/dist/agent-interceptor/schema.d.ts +267 -0
- package/dist/agent-interceptor/types.d.ts +88 -0
- package/dist/esm/index.js +305 -297
- package/dist/esm/plugins/index.js +86 -81
- package/dist/esm/publish/index.js +1 -1
- package/dist/esm/repository/index.js +98 -93
- package/dist/esm/skills/index.js +1 -1
- package/dist/events/types.d.ts +12 -0
- package/dist/facade/Crewx.d.ts +9 -0
- package/dist/index.browser.js +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +307 -299
- package/dist/plugins/index.js +83 -78
- package/dist/provider/bridge.d.ts +5 -1
- package/dist/provider/cli/adapter.types.d.ts +9 -0
- package/dist/provider-account/accounts.d.ts +15 -0
- package/dist/provider-account/index.d.ts +5 -0
- package/dist/provider-account/registry.d.ts +30 -0
- package/dist/provider-account/types.d.ts +40 -0
- package/dist/publish/index.js +1 -1
- package/dist/repository/index.js +99 -94
- package/dist/repository/task.repository.d.ts +7 -0
- package/dist/repository/thread.repository.d.ts +1 -0
- package/dist/skills/index.js +1 -1
- package/dist/types/index.d.ts +33 -0
- package/dist/types/task-log.types.d.ts +3 -1
- package/dist/utils/id.d.ts +1 -1
- package/package.json +1 -1
package/dist/skills/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var crypto=require('crypto'),net=require('net'),fs$1=require('fs'),promises=require('fs/promises'),path=require('path'),jsYaml=require('js-yaml');var Cr=Object.defineProperty;var w=(e,n)=>()=>(e&&(n=e(e=0)),n);var kr=(e,n)=>{for(var t in n)Cr(e,t,{get:n[t],enumerable:true});};var g=w(()=>{});var R,bn=w(()=>{g();R=class extends Error{constructor(t,i=t,r){super(i);this.code=t;this.currentRevision=r;}code;currentRevision;name="UiRuntimeError"};});function at(e){return wr.test(e)||xr.test(e)}function se(){throw new R("INPUT_INVALID","JSON value is not projection-safe")}function Fr(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function rt(e,n,t,i,r,o){if(n>i&&se(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(vr.test(e)||Vr.test(e)&&!zr(r,o)||jr.test(e))&&se(),e;if(typeof e=="number")return Number.isFinite(e)||se(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&se();let a=e;t.has(a)&&se(),t.add(a);try{if(Array.isArray(e))return e.map(c=>rt(c,n+1,t,i,r,o));Fr(a)||se();let s={};for(let[c,d]of Object.entries(e))at(c)&&se(),s[c]=rt(d,n+1,t,i,[...r,c],o);return s}finally{t.delete(a);}}function ae(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>Hr)&&se(),(!Array.isArray(t)||t.some(r=>typeof r!="string"))&&se();let i=rt(e,0,new Set,Br+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&se(),i}function Be(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((r,o)=>t[o]===r)}function zr(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>Be(t,i))}function He(e){try{let n=JSON.stringify(e);return n===void 0&&se(),n}catch{se();}}function st(e){return Array.isArray(e)?e.map(st):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,st(e[n])])):e}function Z(e){return He(st(e))}function ct(e){return Buffer.byteLength(e,"utf8")}var wr,xr,vr,jr,Vr,Br,Hr,Ee=w(()=>{g();bn();wr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,xr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,vr=/<\/?[A-Za-z][^>]*>/,jr=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Vr=/^(?:https?|file|ftp|ws|wss):\/\//i;Br=8,Hr=4;});var Pn,dt=w(()=>{g();Pn=["text/plain","application/json"];});var gi=w(()=>{g();dt();});function ze(e){return $r.has(e)||Jr.test(e)||Wr.test(e)}var mi,$r,Jr,Wr,Sn,nn,Ie,pt,lt,ut,ft,yt,Re=w(()=>{g();mi=["__proto__","prototype","constructor","proof","token","secret","password","cookie","authorization","private_key","private-key","stack","exception","plugin_text","url","uri","endpoint","path","filename","filepath","cwd","shell","directory","dir","folder"],$r=new Set(mi),Jr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Wr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;Sn=/^[A-Za-z0-9_]+$/,nn=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,Ie=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,pt=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,lt=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,ut=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,ft=["blue","violet","emerald","amber","rose","sky","slate","indigo"],yt=["inline","panel"];});function At(e){return typeof e=="string"&&Pn.includes(e)}var hi=w(()=>{g();dt();Re();});function Mn(e){if(!It(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Xr(e.in)||Object.hasOwn(e,"out")&&!Kr(e.out))}function Xr(e){return It(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&At(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function Kr(e){return It(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&At(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function It(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var gt=w(()=>{g();gi();hi();new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});});function On(e){return Yr.includes(e)}function Rn(e){return Number.isSafeInteger(e)&&e>=Ln.min&&e<=Ln.max}var Yr,Ln,_i,mt=w(()=>{g();Yr=[5,15,30,60],Ln=Object.freeze({min:15e3,max:6e5,default:3e5}),_i=1;});function ie(e){let t=e.renderer!==void 0||e.surfaces!==void 0||e.stateProjection!==void 0||e.dataPaths!==void 0||e.usage!==void 0||e.detailPanel!==void 0||e.displayModes!==void 0||e.summaryProjection!==void 0||e.legacy!==void 0||Object.values(e.actions).some(r=>r.resultProjection!==void 0)?{id:e.id,version:e.version,...e.renderer===void 0?{}:{renderer:e.renderer},...e.surfaces===void 0?{}:{surfaces:e.surfaces},...e.stateProjection===void 0?{}:{stateProjection:e.stateProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.legacy===void 0?{}:{legacy:e.legacy},...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},actions:e.actions}:e.sourceHash===void 0?{id:e.id,version:e.version,actions:e.actions}:{id:e.id,version:e.version,sourceHash:e.sourceHash,actions:e.actions},i=ae(t);return crypto.createHash("sha256").update(Z(i)).digest("hex")}function _t(e){return `${e.id}\0${e.version}`}function ce(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new R("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!Zr.test(e.sourceHash)))throw new R("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||ie(e)!==e.hash)throw new R("DEFINITION_UNSUPPORTED","UI definition hash is invalid");for(let[n,t]of Object.entries(e.actions)){if(!n||!Array.isArray(t.capabilities)||t.capabilities.some(i=>!es(i)))throw new R("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new R("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new R("DEFINITION_UNSUPPORTED","UI action input declaration is invalid");if(t.dataInputs!==void 0&&(!Array.isArray(t.dataInputs)||new Set(t.dataInputs).size!==t.dataInputs.length||t.dataInputs.some(i=>typeof i!="string"||!i||t.inputKeys!==void 0&&!t.inputKeys.includes(i))))throw new R("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");if(t.resultProjection&&ht(t.resultProjection),t.schedule!==void 0&&(!On(t.schedule.everyMinutes)||!Rn(t.schedule.timeoutMs)))throw new R("DEFINITION_UNSUPPORTED","UI action schedule declaration is invalid");if(t.content!==void 0&&!Mn(t.content))throw new R("DEFINITION_UNSUPPORTED","UI action content declaration is invalid");if(t.env!==void 0&&(!Array.isArray(t.env)||t.env.length===0||new Set(t.env).size!==t.env.length||t.env.some(i=>i!=="CREWX_APP_INSTANCE_ID"&&i!=="CREWX_THREAD_ID")))throw new R("DEFINITION_UNSUPPORTED","UI action environment declaration is invalid")}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new R("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new R("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new R("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new R("DEFINITION_UNSUPPORTED","UI definition detailPanel is invalid");if(e.displayModes&&(!Array.isArray(e.displayModes)||e.displayModes.length===0||new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(n=>n!=="inline"&&n!=="floating"&&n!=="focused")))throw new R("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new R("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new R("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&ht(e.stateProjection),e.summaryProjection){ht(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new R("DEFINITION_UNSUPPORTED","UI summary projection exceeds state projection")}if(e.legacy!==void 0){if(!e.legacy||typeof e.legacy!="object"||Array.isArray(e.legacy)||Object.keys(e.legacy).some(r=>!["readTool","actionTool","hostTools","agentAccess"].includes(r)))throw new R("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[r,o]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(o!==void 0){if(Qr(o,r==="readTool"),n.has(o.name))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(o.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new R("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let r={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[o,a]of Object.entries(t)){if(!Object.hasOwn(r,o)||r[o]!==a||typeof a!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(a)||n.has(a))throw new R("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");n.add(a);}}let i=e.legacy.agentAccess;if(i!==void 0&&(!i||typeof i!="object"||Array.isArray(i)||Object.entries(i).some(([r,o])=>!r||!Object.hasOwn(e.actions,r)||o!=="allowed"&&o!=="denied")))throw new R("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new R("DEFINITION_UNSUPPORTED","UI legacy action tool requires its complete agent access map")}if(e.dataPaths!==void 0){let n=new Set(["__proto__","prototype","constructor"]);if(!Array.isArray(e.dataPaths)||e.dataPaths.length>16||new Set(e.dataPaths).size!==e.dataPaths.length||e.dataPaths.some(t=>typeof t!="string"||!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(t)||t.split(".").some(i=>n.has(i))||!(e.stateProjection?.allow??[]).some(i=>Be(t,i))))throw new R("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Qr(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],r=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(o=>!i.includes(o)&&!(n&&o==="fixedResult"))||i.some(o=>!Object.hasOwn(t,o))||typeof t.name!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t.name)||typeof t.description!="string"||t.description.trim().length===0||t.description.length>8192||typeof t.textFallback!="string"||t.textFallback.trim().length===0||t.textFallback.length>16384||!t.inputSchema||typeof t.inputSchema!="object"||Array.isArray(t.inputSchema)||!Array.isArray(t.visibility)||t.visibility.length===0||t.visibility.some(o=>o!=="model"&&o!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let o=ae(t.inputSchema);if(o.type!==void 0&&o.type!=="object")throw new Error("schema type");if(r){if(!n)throw new Error("fixed result location");let a=t.fixedResult;if(!a||typeof a!="object"||Array.isArray(a))throw new Error("fixed result");let s=a;if(Object.keys(s).sort().join(",")!=="argsPolicy,structuredContent"||s.argsPolicy!=="empty-only"&&s.argsPolicy!=="ignore"||!s.structuredContent||typeof s.structuredContent!="object"||Array.isArray(s.structuredContent))throw new Error("fixed result");let c=ae(s.structuredContent);if(ct(He(c))>4*1024)throw new Error("fixed result size")}}catch{throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function ht(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new R("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function es(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var Zr,Ue=w(()=>{g();Ee();bn();gt();mt();Zr=/^[0-9a-f]{64}$/;});var Ti=w(()=>{g();Ee();});var K,Ce,Tt=w(()=>{g();K="dist/tools.json",Ce="dist/main.mjs";});var tn,Ei=w(()=>{g();tn="window";});function Di(e){if(!Array.isArray(e)||e.length===0)return false;let n=new Set;for(let t of e){if(!ns.some(i=>i===t)||n.has(t))return false;n.add(t);}return true}var ns,Ni=w(()=>{g();ns=["CREWX_APP_INSTANCE_ID","CREWX_THREAD_ID"];});function V(e){throw new Et(e)}function fs(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function ys(e,n){let t=Object.getOwnPropertyDescriptor(e,n);return (!t||!("value"in t))&&V("CSP_ORIGIN_INVALID"),t.value}function Un(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))return [];let t=ys(e,n);Array.isArray(t)||V("CSP_ORIGIN_INVALID"),Reflect.ownKeys(t).some(o=>typeof o!="string"||o!=="length"&&!/^(?:0|[1-9][0-9]*)$/.test(o))&&V("CSP_ORIGIN_INVALID");let r=[];for(let o=0;o<t.length;o+=1)(!Object.prototype.hasOwnProperty.call(t,o)||typeof t[o]!="string")&&V("CSP_ORIGIN_INVALID"),r.push(t[o]);return Object.keys(t).length!==t.length&&V("CSP_ORIGIN_INVALID"),r}function As(e){let n;try{n=JSON.stringify(e);}catch{V("CSP_ORIGIN_INVALID");}return n===void 0&&V("CSP_ORIGIN_INVALID"),new TextEncoder().encode(n).byteLength}function Si(e,n){/\s|\\/u.test(e)&&V("CSP_ORIGIN_INVALID");let t=cs.exec(e);t||V("CSP_ORIGIN_INVALID");let i=t[1].toLowerCase(),r=t[2];(r.includes("@")||r.includes("%")||r.includes("*"))&&V("CSP_ORIGIN_INVALID"),(r.startsWith("[")?ds:ps).test(r)||V("CSP_ORIGIN_INVALID"),i==="wss"&&n!=="connectDomains"&&V("CSP_ORIGIN_INVALID");let a;try{a=new URL(e);}catch{V("CSP_ORIGIN_INVALID");}(a.protocol!==`${i}:`||a.username!==""||a.password!==""||a.search!==""||a.hash!=="")&&V("CSP_ORIGIN_INVALID");let s=a.hostname.toLowerCase();if((!s||s.includes("%"))&&V("CSP_ORIGIN_INVALID"),!s.startsWith("[")){let d=s.endsWith(".")?s.slice(0,-1):s;(d.length===0||d.length>253)&&V("CSP_ORIGIN_INVALID"),d.split(".").some(p=>p.length>63||!ls.test(p))&&V("CSP_ORIGIN_INVALID");}let c=a.origin;return (c==="null"||!c.startsWith(`${i}://`))&&V("CSP_ORIGIN_INVALID"),{origin:c,hostname:s}}function Is(e){let n=e.split(".").map(Number);return ((n[0]*256+n[1])*256+n[2])*256+n[3]}function Mi(e,n,t){let i=4294967295<<32-t>>>0;return (e&i)===(n&i)}function Ri(e){let n=Is(e);return Mi(n,3221225472,24)?n!==3221225481&&n!==3221225482:us.some(([t,i])=>Mi(n,t,i))}function gs(e){let n=e.indexOf("::"),t=(n<0?e:e.slice(0,n)).split(":").filter(Boolean),i=n<0?[]:e.slice(n+2).split(":").filter(Boolean);return (n<0?t:[...t,...Array(8-t.length-i.length).fill("0"),...i]).reduce((o,a)=>o<<16n|BigInt(Number.parseInt(a,16)),0n)}function ms(e){let n=gs(e),t=Number(n>>112n),i=Number(n>>96n&0xffffn);if(n>>32n===0xffffn){let r=Number(n&0xffffffffn);return Ri([r>>>24&255,r>>>16&255,r>>>8&255,r&255].join("."))}return t<8192||t>16383||t===8193&&i<=511||t===8193&&i===3512||t===8194||t===16383&&i<=4095}function hs(e,n){let t=e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e,i=net.isIP(t);if(i===4)return Ri(t);if(i===6)return ms(t);let r=e.toLowerCase().replace(/\.$/,"");return !r||!r.includes(".")||n.has(r)?true:as.some(o=>r===o||r.endsWith(`.${o}`))}function Li(e){return Object.freeze([...new Set(e.map(n=>n.origin))].sort())}function Oi(e){return JSON.stringify({baseUriDomains:[],connectDomains:e.connectDomains,declared:e.declared,frameDomains:e.frameDomains,resourceDomains:[]})}function Ui(e,n={}){if(e===void 0){let A=Oi({declared:false,connectDomains:[],frameDomains:[]});return Object.freeze({declared:false,connectDomains:Object.freeze([]),frameDomains:Object.freeze([]),resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:crypto.createHash("sha256").update(A,"utf8").digest("hex")})}fs(e)||V("CSP_ORIGIN_INVALID");let t=Reflect.ownKeys(e);t.some(A=>typeof A!="string")&&V("CSP_ORIGIN_INVALID"),t.some(A=>!ss.has(A))&&V("CSP_AXIS_UNKNOWN");let i=Un(e,"connectDomains"),r=Un(e,"frameDomains"),o=Un(e,"resourceDomains"),a=Un(e,"baseUriDomains");(o.length>0||a.length>0)&&V("CSP_AXIS_UNSUPPORTED"),(As(e)>is||i.length>Pi||r.length>Pi||i.length+r.length>os||[...i,...r].some(A=>new TextEncoder().encode(A).byteLength>rs))&&V("CSP_LIMIT_EXCEEDED");let c=i.map(A=>Si(A,"connectDomains")),d=r.map(A=>Si(A,"frameDomains")),l=new Set((n.runtimeHostnames??[]).map(A=>A.toLowerCase().replace(/\.$/,"")));[...c,...d].some(A=>hs(A.hostname,l))&&V("CSP_ORIGIN_FORBIDDEN");let p={declared:true,connectDomains:Li(c),frameDomains:Li(d)},u=Oi(p);return Object.freeze({...p,resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:crypto.createHash("sha256").update(u,"utf8").digest("hex")})}var is,Pi,os,rs,ss,as,cs,ds,ps,ls,us,Et,Ci=w(()=>{g();is=4096,Pi=16,os=32,rs=512,ss=new Set(["connectDomains","frameDomains","resourceDomains","baseUriDomains"]),as=["localhost","local","internal","home.arpa","test","example","invalid","onion","lan","corp","home","intranet","private","localdomain"],cs=/^(https|wss):\/\/([^/?#]+)$/i,ds=/^\[[^\]]+\](?::[0-9]+)?$/,ps=/^[^:\[\]]+(?::[0-9]+)?$/,ls=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,us=[[0,8],[1681915904,10],[167772160,8],[2130706432,8],[2851995648,16],[2886729728,12],[3221225984,24],[3227017984,24],[3232235520,16],[3323068416,15],[3325256704,24],[3405803776,24],[3758096384,4],[4026531840,4]],Et=class extends Error{constructor(t){super(t);this.code=t;}code;name="UiPluginCspNormalizationError"};});function rn(e,n){return n===void 0||n===""?e:e===""?n:n.startsWith("[")?`${e}${n}`:`${e}.${n}`}function f(e,n=e,t,i){throw new oe(e,n,t,i)}function H(e,n){try{return n()}catch(t){throw t instanceof oe?t.withPathPrefix(e):t}}function z(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function U(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Ks(e,n){let t={};for(let[i,r]of Object.entries(e))i!==n&&(t[i]=r);return t}function $(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e).find(a=>!i.has(a));r!==void 0&&f("MANIFEST_INVALID","MANIFEST_INVALID",r,"unknown-key");let o=n.find(a=>!U(e,a));o!==void 0&&f("MANIFEST_INVALID","MANIFEST_INVALID",o,"missing-key");}function xn(e,n=false,t=false,i=false){return Ds.test(e)||!i&&bs.test(e)||Ns.test(e)||t&&ki.test(e)||Ps.test(e)&&!(n&&/^\s*data:/i.test(e)&&!ki.test(e))}function wn(e,n=new Set,t=0,i=false,r=false,o=""){if(typeof e=="string"){xn(e,i,r)&&f("UNSAFE_VALUE","UNSAFE_VALUE",o,"unsafe-value");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&f("MANIFEST_INVALID","MANIFEST_INVALID",o),n.add(e);try{if(Array.isArray(e)){e.forEach((a,s)=>wn(a,n,t+1,!1,!1,rn(o,`[${s}]`)));return}z(e)||f("MANIFEST_INVALID","MANIFEST_INVALID",o);for(let[a,s]of Object.entries(e))wn(s,n,t+1,i&&t===0&&(a==="name"||a==="description"),r,rn(o,a));}finally{n.delete(e);}}}function ge(e,n){let t=e[n];return typeof t!="string"&&f("MANIFEST_INVALID"),t}function le(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&f("MANIFEST_INVALID"),i}function Dt(e){return Es.test(e)||f("MANIFEST_INVALID"),e}function Ge(e){return Ts.test(e)||f("TOKEN_INVALID"),e}function Ys(e){return zi.test(e)||f("MANIFEST_INVALID"),e}function qs(e){z(e)||f("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let r=Ys(t);z(i)||f("MANIFEST_INVALID");let o=i.type;if(o==="text"){$(i,["type","maxLength"]),n[r]={type:o,maxLength:le(i,"maxLength",1)};continue}if(o==="text-list"){$(i,["type","max","itemMaxLength"]),n[r]={type:o,max:le(i,"max",0),itemMaxLength:le(i,"itemMaxLength",1)};continue}if(o==="step-list"){$(i,["type","min","max","labelMaxLength","detailMaxLength"]);let a=le(i,"min",0),s=le(i,"max",1);a>s&&f("MANIFEST_INVALID"),n[r]={type:o,min:a,max:s,labelMaxLength:le(i,"labelMaxLength",1),detailMaxLength:le(i,"detailMaxLength",1)};continue}typeof o=="string"&&f("SCHEMA_TYPE_UNSUPPORTED"),f("MANIFEST_INVALID");}return n}function Zs(e,n,t){let i=e[n];(!i||i.type!==t)&&f("MANIFEST_INVALID");}function Cn(e,n,t){let i=ge(e,"field");return zi.test(i)||f("MANIFEST_INVALID"),Zs(n,i,t),i}function Qs(e,n){z(e)||f("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&f("MANIFEST_INVALID"),Xs.includes(t)||f("PRIMITIVE_UNKNOWN"),t){case "card-shell":return $(e,["primitive"]),{primitive:t};case "meta-banner":return $(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:Ge(ge(e,"badgeToken")),noticeToken:Ge(ge(e,"noticeToken"))};case "heading":return $(e,["primitive","field"]),{primitive:t,field:Cn(e,n,"text")};case "labeled-text":return $(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&f("MANIFEST_INVALID"),{primitive:t,titleToken:Ge(ge(e,"titleToken")),field:Cn(e,n,"text"),variant:"callout"};case "step-flow":return $(e,["primitive","titleToken","field"]),{primitive:t,titleToken:Ge(ge(e,"titleToken")),field:Cn(e,n,"step-list")};case "text-list":{$(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:Ge(ge(e,"titleToken")),field:Cn(e,n,"text-list")};return U(e,"emptyToken")&&(i.emptyToken=Ge(ge(e,"emptyToken"))),U(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&f("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return f("MANIFEST_INVALID")}function ea(e,n){return Array.isArray(e)||f("MANIFEST_INVALID"),e.map(t=>Qs(t,n))}function J(e="v2 manifest exceeds a contract limit",n,t){return f("LIMIT_EXCEEDED",e,n,t)}function de(e="initial state is not projection-safe"){return f("INITIAL_STATE_INVALID",e)}function wi(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||$s.test(e)||Js.test(e))&&f("MANIFEST_INVALID",`${n} is invalid`),(xn(e,true,true)||Ss.test(e)||Ms.test(e)||Ls.test(e))&&f("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function Nt(e,n){return (typeof e!="string"||!Ie.test(e))&&f("MANIFEST_INVALID",`${n} is invalid`),e}function na(e){return (typeof e!="string"||!pt.test(e)||e==="*"||e==="all")&&f("MANIFEST_INVALID","action capability is invalid"),e}function Gi(e){return (typeof e!="string"||!Gs.test(e))&&f("MANIFEST_INVALID","resource hash is invalid"),e}function bt(e,n=new Set,t=0,i=""){if(typeof e=="string"){e.length>4096&&J("v2 manifest string is too long",i,"string-too-long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||f("MANIFEST_INVALID","v2 manifest contains a non-finite number",i,"non-finite-number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&f("MANIFEST_INVALID","v2 manifest contains a non-JSON value",i,"non-json-value"),typeof e!="object"&&f("MANIFEST_INVALID","MANIFEST_INVALID",i),t>8&&J("v2 manifest nesting is too deep",i,"too-deep"),n.has(e)&&f("MANIFEST_INVALID","v2 manifest contains a cycle",i,"cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&J("v2 manifest array is too long",i,"array-too-long"),e.forEach((r,o)=>bt(r,n,t+1,rn(i,`[${o}]`)));return}z(e)||f("MANIFEST_INVALID","v2 manifest contains a non-plain object",i,"non-plain-object");for(let[r,o]of Object.entries(e))bt(o,n,t+1,rn(i,r));}finally{n.delete(e);}}}function $i(e){return (typeof e!="string"||e.length>4096||!nn.test(e))&&(typeof e=="string"&&e.length>4096&&J("projection path is too long"),f("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>ze(t))&&f("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function Pt(e){z(e)||f("MANIFEST_INVALID","projection policy must be an object"),$(e,["allow"]),Array.isArray(e.allow)||f("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&J("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let r=$i(i);t.has(r)&&f("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(r),n.push(r);}return {allow:n}}function ta(e,n){if(e===void 0)return;Array.isArray(e)||f("MANIFEST_INVALID","dataPaths must be an array"),e.length>Ws&&J("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let r of e){let o=$i(r);i.has(o)&&f("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(a=>Be(o,a))||f("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(o),t.push(o);}return t}function $e(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&f("MANIFEST_INVALID",`${n} is invalid`),e}function xi(e,n){return (typeof e!="number"||!Number.isFinite(e))&&f("MANIFEST_INVALID",`${n} is invalid`),e}function St(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||xn(e))&&f("UNSAFE_VALUE","schema enum contains an unsafe string"),e;if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||f("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&J("schema enum is too deep"),t.has(e)&&f("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&J("schema enum array is too long"),e.map(r=>St(r,n+1,t));z(e)||f("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[r,o]of Object.entries(e))ze(r)&&f("MANIFEST_INVALID","schema enum contains a reserved key"),i[r]=St(o,n+1,t);return i}finally{t.delete(e);}}function ia(e,n){if(e===void 0)return;Array.isArray(e)||f("MANIFEST_INVALID","schema required must be an array"),e.length>64&&J("schema required list is too long");let t=[],i=new Set;for(let r of e)(typeof r!="string"||!nn.test(r))&&f("MANIFEST_INVALID","schema required contains an invalid key"),r.length>4096&&J("schema required key is too long"),i.has(r)&&f("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,r)&&f("MANIFEST_INVALID","schema required references an undeclared property"),i.add(r),t.push(r);return t}function oa(e,n){let t=n?nn:Sn;return e.length>4096&&J("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>ze(i)))&&f("MANIFEST_INVALID","schema property name is invalid"),e}function Mt(e,n=0,t=false){z(e)||f("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&J("action inputSchema is too deep");let i=e.type;i!=="object"&&i!=="string"&&i!=="number"&&i!=="integer"&&i!=="boolean"&&i!=="array"&&i!=="null"&&(typeof i=="string"&&f("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),f("MANIFEST_INVALID","action inputSchema type is required"));let r=["type","enum"];i==="string"&&r.push("minLength","maxLength"),i==="array"&&r.push("minItems","maxItems","items"),i==="object"&&r.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&r.push("minimum","maximum"),$(e,["type"],r.filter(s=>s!=="type"));let o={type:i};if(U(e,"enum")&&(Array.isArray(e.enum)||f("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&J("schema enum is too long"),o.enum=e.enum.map(s=>St(s))),i==="string"&&(U(e,"minLength")&&(o.minLength=$e(e.minLength,"schema minLength",4096)),U(e,"maxLength")&&(o.maxLength=$e(e.maxLength,"schema maxLength",4096)),o.minLength!==void 0&&o.maxLength!==void 0&&o.minLength>o.maxLength&&f("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(U(e,"minimum")&&(o.minimum=xi(e.minimum,"schema minimum")),U(e,"maximum")&&(o.maximum=xi(e.maximum,"schema maximum")),o.minimum!==void 0&&o.maximum!==void 0&&o.minimum>o.maximum&&f("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(U(e,"minItems")&&(o.minItems=$e(e.minItems,"schema minItems",128)),U(e,"maxItems")&&(o.maxItems=$e(e.maxItems,"schema maxItems",128)),o.minItems!==void 0&&o.maxItems!==void 0&&o.minItems>o.maxItems&&f("MANIFEST_INVALID","schema array length bounds are inverted"),U(e,"items")&&(o.items=Mt(e.items,n+1,false))),i==="object"){let s;if(U(e,"properties")){z(e.properties)||f("MANIFEST_INVALID","schema properties must be an object");let d=Object.entries(e.properties);d.length>64&&J("schema properties are too many"),s={};for(let[l,p]of d){let u=oa(l,t);s[u]=Mt(p,n+1,false);}o.properties=s;}U(e,"minProperties")&&(o.minProperties=$e(e.minProperties,"schema minProperties",64)),U(e,"maxProperties")&&(o.maxProperties=$e(e.maxProperties,"schema maxProperties",64)),o.minProperties!==void 0&&o.maxProperties!==void 0&&o.minProperties>o.maxProperties&&f("MANIFEST_INVALID","schema object property bounds are inverted");let c=ia(e.required,s);c!==void 0&&(o.required=c),U(e,"additionalProperties")&&(e.additionalProperties!==false&&f("MANIFEST_INVALID","schema additionalProperties must be false"),o.additionalProperties=false);}let a=JSON.stringify(o);return (a===void 0||Buffer.byteLength(a,"utf8")>2097152)&&J("action inputSchema subtree is too large"),o}function ra(e){let n=Mt(e,0,true);return (n.type!=="object"||!n.properties)&&f("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function sa(e){if(z(e)||f("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){$(e,js);let n=e.handler;return (typeof n!="string"||!lt.test(n))&&f("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"&&U(e,"entry"))return $(e,Bs),e.entry!==Ce&&f("MANIFEST_INVALID",`skill backend entry must be ${Ce}`),{type:"skill",entry:Ce};if(e.type==="skill"){$(e,Vs,Fs),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&f("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!ut.test(i))&&f("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=U(e,"env")?da(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}f("MANIFEST_INVALID","action backend type is unsupported");}function aa(e){z(e)||f("MANIFEST_INVALID","action must be an object"),$(e,Cs,ks),U(e,"_meta")&&H("_meta",()=>Ji(e._meta));let n=H("actionId",()=>Nt(e.actionId,"actionId"));at(n)&&f("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`,"actionId");let t=H("capability",()=>na(e.capability)),i=e.mutation;typeof i!="boolean"&&f("MANIFEST_INVALID","action mutation must be boolean","mutation");let r=H("inputSchema",()=>ra(e.inputSchema)),o;if(U(e,"dataInputs")){Array.isArray(e.dataInputs)||f("MANIFEST_INVALID","action dataInputs must be an array","dataInputs");let p=r.properties,u=new Set,A=[];for(let I of e.dataInputs)(typeof I!="string"||!U(p,I)||u.has(I))&&f("MANIFEST_INVALID","action dataInputs must be unique declared properties","dataInputs"),u.add(I),A.push(I);o=A;}let a=H("resultProjection",()=>Pt(e.resultProjection)),s=H("backend",()=>sa(e.backend)),c;U(e,"content")&&((s.type!=="skill"||!Mn(e.content))&&f("MANIFEST_INVALID","action content declaration is invalid","content"),c=pa(e.content));let d;if(U(e,"confirmation")){let p=e.confirmation;p!=="none"&&p!=="native"&&f("MANIFEST_INVALID","action confirmation is invalid","confirmation"),d=p;}let l;return U(e,"schedule")&&(l=H("schedule",()=>ca(e.schedule,{backend:s,inputSchema:r,hasContent:c!==void 0,hasDataInputs:o!==void 0,confirmation:d}))),{actionId:n,capability:t,mutation:i,inputSchema:r,resultProjection:a,backend:s,...c===void 0?{}:{content:c},...o===void 0?{}:{dataInputs:o},...d===void 0?{}:{confirmation:d},...l===void 0?{}:{schedule:l}}}function ca(e,n){(n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==Ce)&&f("MANIFEST_INVALID","schedule needs a tool-mode action","schedule"),(n.hasContent||n.hasDataInputs||n.confirmation!==void 0&&n.confirmation!=="none")&&f("MANIFEST_INVALID","a scheduled action takes no content, dataInputs or native confirmation","schedule"),(n.inputSchema.required??[]).length>0&&f("MANIFEST_INVALID","a scheduled action input must accept {}","inputSchema.required"),z(e)||f("MANIFEST_INVALID","schedule must be an object","schedule"),$(e,ws,xs),On(e.everyMinutes)||f("MANIFEST_INVALID","schedule everyMinutes is invalid","schedule.everyMinutes");let t=U(e,"timeoutMs")?e.timeoutMs:Ln.default;return Rn(t)||f("MANIFEST_INVALID","schedule timeoutMs is invalid","schedule.timeoutMs"),{everyMinutes:e.everyMinutes,timeoutMs:t}}function da(e){return Di(e)||f("MANIFEST_INVALID","skill backend env is invalid"),Object.freeze([...e])}function pa(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function la(e){return z(e)||f("INITIAL_STATE_INVALID","initialState must be an object"),$(e,Hs,zs),e.path!=="ui/state.json"&&f("MANIFEST_INVALID","initialState path is not fixed"),U(e,"hash")?{path:"ui/state.json",hash:Gi(e.hash)}:{path:"ui/state.json"}}function ua(e){let n=["wasm","terminal","htmlDocuments"];return (!z(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&f("MANIFEST_INVALID","runtime must contain only known capability flags set to true"),{...e.wasm===true?{wasm:true}:{},...e.terminal===true?{terminal:true}:{},...e.htmlDocuments===true?{htmlDocuments:true}:{}}}function fa(e,n){let t;try{t=Ui(e);}catch(i){let r=i!==null&&typeof i=="object"&&"code"in i&&typeof i.code=="string"?i.code:"CSP_ORIGIN_INVALID";return f("MANIFEST_INVALID",r,void 0,r.toLowerCase().replace(/_/g,"-"))}if(t.frameDomains.length>0&&f("MANIFEST_INVALID","external origins in csp are not enabled in this rollout",void 0,"csp-not-enabled"),t.connectDomains.length!==0)return n?.terminal===true&&f("MANIFEST_INVALID","runtime.terminal cannot be combined with csp.connectDomains","connectDomains","terminal-with-connect-domains"),Object.freeze({connectDomains:t.connectDomains})}function ya(e,n){wn(z(e)&&U(e,"csp")?Ks(e,"csp"):e,new Set,0,true,true),bt(e),z(e)||f("MANIFEST_INVALID"),$(e,Rs,Us),U(e,"_meta")&&H("_meta",()=>Ji(e._meta)),e.manifestVersion!==2&&f("MANIFEST_INVALID");let t;U(e,"runtime")&&(t=H("runtime",()=>ua(e.runtime)));let i;U(e,"csp")&&(i=H("csp",()=>fa(e.csp,t)));let r=H("pluginId",()=>Nt(e.pluginId,"pluginId")),o=H("definitionId",()=>Nt(e.definitionId,"definitionId")),a=H("version",()=>le(e,"version",1)),s=H("name",()=>wi(e.name,"name")),c=H("description",()=>wi(e.description,"description")),d;U(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&f("MANIFEST_INVALID","icon is invalid","icon"),d=e.icon);let l;U(e,"tone")&&((typeof e.tone!="string"||!ft.includes(e.tone))&&f("MANIFEST_INVALID","tone is invalid","tone"),l=e.tone),e.entry!=="ui/index.html"&&f("MANIFEST_INVALID","entry path is not fixed","entry","fixed-value");let p;U(e,"entryHash")&&(p=H("entryHash",()=>Gi(e.entryHash)));let u;U(e,"initialState")&&(u=H("initialState",()=>la(e.initialState)));let A;U(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&f("MANIFEST_INVALID","usage is invalid","usage"),A=e.usage);let I;U(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&f("MANIFEST_INVALID","detailPanel is invalid","detailPanel"),I=e.detailPanel);let h;if(U(e,"displayModes")){((A??tn)!==tn||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&f("MANIFEST_INVALID","displayModes are only valid for window Apps","displayModes");let m=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(E=>typeof E!="string"||!m.has(E)))&&f("MANIFEST_INVALID","displayModes are invalid","displayModes"),h=e.displayModes;}(A??tn)===tn&&I!==void 0&&f("MANIFEST_INVALID","detailPanel is card-only","detailPanel");let N=n.mode??"local";N!=="local"&&N!=="installed"&&N!=="published"&&f("MANIFEST_INVALID","manifest mode is invalid"),N!=="local"&&p===void 0&&f("MANIFEST_INVALID","installed manifests require entryHash","entryHash","required-when-installed"),N!=="local"&&u!==void 0&&u.hash===void 0&&f("MANIFEST_INVALID","installed manifests require initialState.hash","initialState.hash","required-when-installed"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&f("MANIFEST_INVALID","surfaces are invalid","surfaces"),e.surfaces.length>2&&J("surfaces exceed the v2 limit","surfaces","too-many-items");let F=[],v=new Set;for(let m of e.surfaces)(typeof m!="string"||!yt.includes(m))&&f("MANIFEST_INVALID","surface is unsupported","surfaces"),v.has(m)&&f("MANIFEST_INVALID","surfaces contain a duplicate","surfaces","duplicate-item"),v.add(m),F.push(m);z(e.size)||f("MANIFEST_INVALID","size must be an object","size"),H("size",()=>$(e.size,["height"]));let b=H("size",()=>le(e.size,"height",1));b>720&&J("size.height exceeds the v2 limit","size.height","too-large");let C=H("stateProjection",()=>Pt(e.stateProjection)),G=e.summaryProjection===void 0?void 0:H("summaryProjection",()=>Pt(e.summaryProjection));G!==void 0&&G.allow.some(m=>!C.allow.includes(m))&&f("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow","summaryProjection");let D=H("dataPaths",()=>ta(e.dataPaths,C.allow));Array.isArray(e.actions)||f("MANIFEST_INVALID","actions must be an array","actions"),e.actions.length>32&&J("actions exceed the v2 limit","actions","too-many-items");let M=[],S=new Set,y=0;for(let[m,E]of e.actions.entries()){let P=`actions[${m}]`,L=H(P,()=>aa(E));if(S.has(L.actionId)&&f("MANIFEST_INVALID","actions contain a duplicate actionId",`${P}.actionId`,"duplicate-item"),L.schedule!==void 0&&(y+=1,y>_i&&f("MANIFEST_INVALID","an App declares at most one scheduled action",`${P}.schedule`,"duplicate-item")),L.backend.type==="core"&&L.backend.handler==="state.set"){L.mutation||f("MANIFEST_INVALID","state.set actions must be mutations",`${P}.mutation`);for(let O of Object.keys(L.inputSchema.properties))C.allow.includes(O)||f("MANIFEST_INVALID","state.set input paths must be projection-allowed",`${P}.inputSchema.properties`);}S.add(L.actionId),M.push(L);}return {manifestVersion:2,pluginId:r,definitionId:o,version:a,name:s,description:c,...d===void 0?{}:{icon:d},...l===void 0?{}:{tone:l},entry:"ui/index.html",...p===void 0?{}:{entryHash:p},...t===void 0?{}:{runtime:t},...i===void 0?{}:{csp:i},...u===void 0?{}:{initialState:u},...A===void 0?{}:{usage:A},...I===void 0?{}:{detailPanel:I},...h===void 0?{}:{displayModes:h},surfaces:F,size:{height:b},stateProjection:C,...G===void 0?{}:{summaryProjection:G},...D===void 0?{}:{dataPaths:D},actions:M}}function Ji(e){z(e)||f("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>vs)&&J("_meta exceeds the 4 KiB limit",void 0,"meta-too-large");}function Aa(e){let n={},t={};for(let o of e.actions){n[o.actionId]={capabilities:[o.capability],inputKeys:Object.keys(o.inputSchema.properties??{}),...o.dataInputs===void 0?{}:{dataInputs:o.dataInputs},resultProjection:o.resultProjection,...o.confirmation===void 0?{}:{confirmation:o.confirmation},...o.content===void 0?{}:{content:o.content},...o.schedule===void 0?{}:{schedule:o.schedule},...o.backend.type!=="skill"||o.backend.env===void 0?{}:{env:o.backend.env}};let a=o.backend.type==="skill"||o.backend.type==="core"&&o.backend.handler==="state.set";t[o.actionId]={actionId:o.actionId,mutation:o.mutation,backend:o.backend,launchPolicy:a?"allowed":"denied",...a?{}:{denialCode:"EXEC_DENIED"}};}let i={id:e.definitionId,version:e.version,renderer:"sandbox-html",...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},surfaces:e.surfaces,stateProjection:e.stateProjection,...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},actions:n},r={entry:{path:"ui/index.html",...e.entryHash===void 0?{}:{hash:e.entryHash}},...e.initialState===void 0?{}:{initialState:e.initialState}};return {manifest:e,definition:i,handlers:t,resources:r}}function Lt(e,n,t,i,r,o){if(typeof e=="string"){let a=r.length>0&&o.some(s=>Be(r.join("."),s));return (e.length>4096||xn(e,false,false,a))&&de("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||de("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&de("state contains a non-JSON value"),t>8&&de("state is too deep"),n.has(e)&&de("state contains a cycle"),n.add(e);try{let a;if(Array.isArray(e))e.length>128&&de("state array is too long"),a=e.map(c=>Lt(c,n,t+1,2097152,r,o));else {z(e)||de("state contains a non-plain object");let c={};for(let[d,l]of Object.entries(e))(d.length>4096||!Sn.test(d)||ze(d))&&(d.length>4096&&de("state key is too long"),de("state contains a reserved or invalid key")),c[d]=Lt(l,n,t+1,2097152,[...r,d],o);a=c;}let s=JSON.stringify(a);return (s===void 0||Buffer.byteLength(s,"utf8")>i)&&de("state subtree is too large"),a}finally{n.delete(e);}}function Rt(e,n=[]){z(e)||de("initial state must be a JSON object");let t=Lt(e,new Set,0,2097152,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&de(),t}function Ia(e,n={}){wn(e),z(e)||f("MANIFEST_INVALID"),$(e,Os),e.manifestVersion!==1&&f("MANIFEST_INVALID");let t=Dt(ge(e,"pluginId")),i=Dt(ge(e,"definitionId")),r=le(e,"version",1),o=le(e,"primitiveSet",1),a=n.supportedPrimitiveSet??_s;(!Number.isSafeInteger(a)||a<1)&&f("MANIFEST_INVALID"),o>a&&f("PRIMITIVE_SET_UNSUPPORTED"),z(e.activation)||f("MANIFEST_INVALID"),$(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&f("MANIFEST_INVALID");let s=Dt(ge(e.activation,"language")),c=qs(e.schema),d=ea(e.layout,c);return {manifestVersion:1,pluginId:t,definitionId:i,version:r,primitiveSet:o,activation:{kind:"fenced-code",language:s},schema:c,layout:d}}function ga(e,n={}){return z(e)||f("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&f("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?ya(e,n):Ia(e,n)}function sn(e,n={}){try{return ga(e,n)}catch(t){if(t instanceof oe)throw t;return f("MANIFEST_INVALID")}}function an(e,n={}){let t=sn(e,n);return t.manifestVersion===2?Aa(t):t}var _s,Ts,Es,zi,Ds,Ns,bs,Ps,ki,Ss,Ms,Ls,Os,Rs,Us,Cs,ks,ws,xs,vs,js,Vs,Fs,Bs,Hs,zs,Gs,$s,Js,Ws,Xs,oe,Ut=w(()=>{g();Ei();Ee();gt();Ni();Tt();mt();Ci();Re();_s=1,Ts=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Es=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,zi=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Ds=/<\/?[A-Za-z][^>]*>/,Ns=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,bs=/^(?:https?|file|ftp|ws|wss):\/\//i,Ps=/^\s*(?:javascript|data):/i,ki=/data:[^,\s]*,/i,Ss=/(?:https?|file|ftp|ws|wss):\/\//i,Ms=/javascript:/i,Ls=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,Os=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],Rs=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],Us=["_meta","icon","tone","entryHash","runtime","csp","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],Cs=["actionId","capability","mutation","inputSchema","resultProjection","backend"],ks=["confirmation","dataInputs","content","schedule","_meta"],ws=["everyMinutes"],xs=["timeoutMs"],vs=4*1024,js=["type","handler"],Vs=["type","command"],Fs=["env"],Bs=["type","entry"],Hs=["path"],zs=["hash"],Gs=/^[0-9a-f]{64}$/,$s=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,Js=/[\r\n]/,Ws=16,Xs=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],oe=class e extends Error{constructor(t,i=t,r,o){super(i);this.code=t;this.path=r;this.rule=o;}code;path;rule;name="UiPluginValidationError";withPathPrefix(t){return new e(this.code,this.message,rn(t,this.path),this.rule)}};});function Zi(e){return typeof e=="string"&&e.length<=ha&&ma.test(e)}function k(e,n,t,i,r){throw new he(e,{path:n,rule:t,...i===void 0?{}:{message:i},...r===void 0?{}:{file:r}})}function Q(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function W(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function fe(e){let n=`_meta["${Se}"]`;return e===void 0||e===""?n:e.startsWith("[")?`${n}${e}`:`${n}.${e}`}function Da(e){return e.toLowerCase().replace(/_/g,"-")}function Na(e){if(e===void 0||e==="")return "";let n=/^([^.[]+)(.*)$/.exec(e);if(!n)return fe(e);let[,t,i]=n;switch(t){case "pluginId":return `name${i}`;case "name":return `display_name${i}`;case "description":return `description${i}`;case "_meta":return `_meta${i}`;case "version":return fe("definitionVersion");case "definitionId":return fe("definitionId");default:return fe(`${t}${i}`)}}function Qi(e,n,t){return {path:t(e.path),rule:e.rule??Da(e.code),...e.message!==e.code?{message:e.message}:{},file:n}}function eo(e){return JSON.parse(JSON.stringify(e))}function wt(e,n,t=0,i=new Set){if(typeof e=="string"){e.length>4096&&k("LIMIT_EXCEEDED",n,"string-too-long"),(_a.test(e)||Ta.test(e)||Ea.test(e))&&k("UNSAFE_VALUE",n,"unsafe-value");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||k("MANIFEST_INVALID",n,"non-finite-number");return}typeof e!="object"&&k("MANIFEST_INVALID",n,"non-json-value"),t>8&&k("LIMIT_EXCEEDED",n,"too-deep"),i.has(e)&&k("MANIFEST_INVALID",n,"cycle"),i.add(e);try{if(Array.isArray(e)){e.length>128&&k("LIMIT_EXCEEDED",n,"array-too-long"),e.forEach((r,o)=>wt(r,`${n}[${o}]`,t+1,i));return}Q(e)||k("MANIFEST_INVALID",n,"non-plain-object");for(let[r,o]of Object.entries(e))wt(o,n===""?r:`${n}.${r}`,t+1,i);}finally{i.delete(e);}}}function ue(e,n){return (typeof e!="string"||e.length===0)&&k("MANIFEST_INVALID",n,"string"),e}function We(e,n){return Q(e)||k("MANIFEST_INVALID",n,"object"),e}function ba(e,n){Array.isArray(e)||k("MANIFEST_INVALID",n,"array"),e.forEach((t,i)=>ue(t,`${n}[${i}]`));}function Pa(e,n){typeof e!="boolean"&&k("MANIFEST_INVALID",n,"boolean");}function cn(e,n,t,i){for(let r of Object.keys(e))!t.includes(r)&&!i.includes(r)&&k("MANIFEST_INVALID",`${n}.${r}`,"unknown-key");for(let r of t)W(e,r)||k("MANIFEST_INVALID",`${n}.${r}`,"missing-key");}function Sa(e,n){if(e!=="icon")switch(wt(n,e),e){case "long_description":case "homepage":case "documentation":case "support":case "license":ue(n,e);return;case "author":{let t=We(n,e);cn(t,e,["name"],["email","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "repository":{let t=We(n,e);cn(t,e,[],["type","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "icons":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=We(t,r);cn(o,r,["src","size"],["theme"]),ue(o.src,`${r}.src`),ue(o.size,`${r}.size`),W(o,"theme")&&ue(o.theme,`${r}.theme`);});return}case "screenshots":case "keywords":case "privacy_policies":ba(n,e);return;case "tools":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=We(t,r);cn(o,r,["name"],["description"]),ue(o.name,`${r}.name`),W(o,"description")&&ue(o.description,`${r}.description`);});return}case "prompts":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=We(t,r);cn(o,r,["name","text"],["description","arguments"]),ue(o.name,`${r}.name`),ue(o.text,`${r}.text`);});return}case "tools_generated":case "prompts_generated":Pa(n,e);return;case "localization":case "compatibility":case "user_config":We(n,e);return;default:k("MANIFEST_INVALID",e,"unknown-key");}}function vn(e){return typeof e=="string"&&Ie.test(e)?e:void 0}function no(e){return Number.isSafeInteger(e)&&e>=1?e:void 0}function Ma(e){let n=vn(e.name);if(n===void 0)return;let t=e._meta,i=Q(t)?t[Se]:void 0,r=Q(i)?i:{},o=W(r,"definitionId")?vn(r.definitionId):n,a=W(r,"definitionVersion")?no(r.definitionVersion):1;return {pluginId:n,...o===void 0?{}:{definitionId:o},...a===void 0?{}:{definitionVersion:a}}}function La(e){let n=vn(e.pluginId);if(n===void 0)return;let t=vn(e.definitionId),i=no(e.version);return {pluginId:n,...t===void 0?{}:{definitionId:t},...i===void 0?{}:{definitionVersion:i}}}function Vt(e){try{let n=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));if(!Q(n))return !1;let t=n._meta;return Q(t)&&W(t,Se)}catch{return false}}function Oa(e,n){if(e===we)return n.builtinOnly===true;let t=n._meta,i=Q(t)?t[Se]:void 0;return Q(i)&&i.builtinOnly===true}function Ra(e,n){W(e,"server")&&k("MANIFEST_INVALID","server","server-unsupported","phase 1 runs CrewX-owned Apps only");for(let s of Object.keys(e))vt.includes(s)||k("MANIFEST_INVALID",s,"unknown-key");for(let s of jt)W(e,s)||k("MANIFEST_INVALID",s,"missing-key");e.manifest_version!==Ct&&k("MANIFEST_INVALID","manifest_version","unsupported-version",`manifest_version must be "${Ct}"`),Zi(e.version)||k("MANIFEST_INVALID","version","semver","version must be a semver.org version such as 0.1.0");let t=e._meta;Q(t)||k("MANIFEST_INVALID","_meta","object"),W(t,Se)||k("MANIFEST_INVALID",fe(),"missing-key");let i=t[Se];Q(i)||k("MANIFEST_INVALID",fe(),"object");for(let s of Object.keys(i))kt.includes(s)||qi.includes(s)||k("MANIFEST_INVALID",fe(s),"unknown-key");for(let s of kt)s==="actions"&&n!==void 0||W(i,s)||k("MANIFEST_INVALID",fe(s),"missing-key");if(n!==void 0&&W(i,"actions")&&k("MANIFEST_INVALID",fe("actions"),"two-truths",`actions are declared in both ${X} and ${K}; a server.ts App keeps them in the tools file only`),Ua(i.actions),W(i,"definitionVersion")){let s=i.definitionVersion;(!Number.isSafeInteger(s)||s<1)&&k("MANIFEST_INVALID",fe("definitionVersion"),"positive-integer");}let r={};for(let s of Yi)W(e,s)&&(Sa(s,e[s]),r[s]=eo(e[s]));let o={};for(let[s,c]of Object.entries(t))s!==Se&&(o[s]=c);let a={manifestVersion:2,pluginId:e.name,definitionId:W(i,"definitionId")?i.definitionId:e.name,version:W(i,"definitionVersion")?i.definitionVersion:1,name:e.display_name,description:e.description};for(let[s,c]of Object.entries(i))s==="definitionId"||s==="definitionVersion"||(a[s]=c);return n!==void 0&&(a.actions=n.map(s=>({...s,backend:{type:"skill",entry:Ce}}))),Object.keys(o).length>0&&(a._meta=o),{v2Input:a,...Object.keys(o).length>0?{vendorMeta:o}:{},passthrough:r}}function Ua(e){Array.isArray(e)&&e.forEach((n,t)=>{let i=Q(n)?n.backend:void 0;Q(i)&&W(i,"entry")&&k("MANIFEST_INVALID",fe(`actions[${t}].backend.entry`),"entry-not-authorable",`an action in ${X} cannot name an entry; a server.ts App declares its actions in ${K}`);});}function Ca(e,n,t){Q(e)||k("MANIFEST_INVALID","","not-object","manifest.json must be a JSON object",X);let i;try{i=Ra(e,t);}catch(a){throw a instanceof he?new he(a.code,{...a.reason,file:X}):a}let r;try{let a=sn(i.v2Input,{mode:n.mode??"local"});a.manifestVersion!==2&&k("MANIFEST_INVALID","","v2-required"),r=a;}catch(a){throw a instanceof oe?new he(a.code,Qi(a,X,Na)):a}let o=e.tools;if(Array.isArray(o)){let a=new Set(r.actions.map(s=>s.actionId));o.forEach((s,c)=>{let d=s.name;if(!a.has(d))throw new he("MANIFEST_INVALID",{path:`tools[${c}].name`,rule:"tool-not-action",message:"every tools[].name must be an action id",file:X})});}return {file:X,manifest:r,v2Input:i.v2Input,releaseVersion:e.version,...Object.keys(i.passthrough).length>0?{mcpb:i.passthrough}:{}}}function ka(e,n){try{let t=sn(e,{mode:n.mode??"local"});if(t.manifestVersion!==2)throw new he("MANIFEST_INVALID",{path:"manifestVersion",rule:"v2-required",message:"a workspace App requires manifestVersion 2",file:we});return {file:we,manifest:t,v2Input:e}}catch(t){throw t instanceof oe?new he(t.code,Qi(t,we,i=>i??"")):t}}function xt(e){return ie(an(e).definition)}function Xi(e){let{entryHash:n,initialState:t,...i}=e,r={...i};return t!==void 0&&(r.initialState={path:t.path}),eo(r)}function wa(e,n){let t=Xi(e),i=Xi(n);return [...new Set([...Object.keys(t),...Object.keys(i)])].sort().filter(o=>Z(t[o]??null)!==Z(i[o]??null))}function xa(e,n){return e.entryHash!==void 0&&n.entryHash!==void 0&&e.entryHash!==n.entryHash||e.initialState?.hash!==void 0&&n.initialState?.hash!==void 0&&e.initialState.hash!==n.initialState.hash}function va(e,n){let t=wa(e,n),i=xa(e,n),r="";try{let o=xt(e),a=xt(n);i=i||o!==a,r=` (definition hash ${o.slice(0,12)} vs ${a.slice(0,12)})`;}catch{i=true;}t.length===0&&!i||k("MANIFEST_DUAL_MISMATCH","","dual-manifest-mismatch",`${X} and ${we} normalize to different definitions${r}`+(t.length>0?`; differing fields: ${t.join(", ")}`:""));}function me(e,n,t="MANIFEST_INVALID",i){return {code:t,reason:{path:e,rule:n,...i===void 0?{}:{message:i},file:K},files:[]}}function Ki(e){return {...me("","tools-needs-manifest-json","MANIFEST_INVALID",`${K} is read with ${X} only`),files:e}}function ja(e,n){if(e.byteLength>n)return {failure:me("","file-too-large","LIMIT_EXCEEDED")};let t;try{t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));}catch{return {failure:me("","invalid-json")}}if(!Q(t))return {failure:me("","not-object","MANIFEST_INVALID",`${K} must be a JSON object`)};for(let r of Object.keys(t))if(r!=="schemaVersion"&&r!=="actions")return {failure:me(r,"unknown-key")};for(let r of ["schemaVersion","actions"])if(!W(t,r))return {failure:me(r,"missing-key")};if(t.schemaVersion!==1)return {failure:me("schemaVersion","unsupported-version","MANIFEST_INVALID",`schemaVersion must be ${1}`)};let i=t.actions;if(!Array.isArray(i))return {failure:me("actions","array")};for(let[r,o]of i.entries()){if(!Q(o))return {failure:me(`actions[${r}]`,"object")};if(W(o,"backend"))return {failure:me(`actions[${r}].backend`,"tools-backend","MANIFEST_INVALID",`an action in ${K} cannot carry a backend`)}}return {actions:i}}function Va(e,n){let t=n.maxBytes??262144,i=[],r=new TextDecoder("utf-8",{fatal:true});for(let o of pe){let a=e[o];if(a===void 0)continue;if(a.byteLength>t)return {parsed:i,failure:{code:"LIMIT_EXCEEDED",reason:{path:"",rule:"file-too-large",file:o},files:[o]}};let s;try{s=JSON.parse(r.decode(a));}catch{return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"invalid-json",file:o},files:[o]}}}if(!Q(s))return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"not-object",message:`${o} must be a JSON object`,file:o},files:[o]}};i.push({file:o,raw:s});}return {parsed:i}}function Ft(e,n={}){let{parsed:t,failure:i}=Va(e,n),r=pe.filter(A=>e[A]!==void 0);if(i!==void 0)return {ok:false,rejection:i,parseFailure:true,builtinOnly:false};let o=e[K],a=o===void 0?void 0:ja(o,n.maxBytes??262144);if(t.length===0)return {ok:false,rejection:a===void 0?{code:"MANIFEST_INVALID",reason:{path:"",rule:"no-manifest-file",message:"neither manifest.json nor ui-plugin.json is present"},files:[]}:Ki(r),parseFailure:true,builtinOnly:false};let s=t[0],c=s.file===X?Ma(s.raw):La(s.raw),d=t.some(A=>Oa(A.file,A.raw)),l;if(a!==void 0){let A=t.some(I=>I.file===X)?a.failure:Ki(r);if(A!==void 0)return {ok:false,rejection:A,parseFailure:false,...c===void 0?{}:{identity:c},builtinOnly:d};l=a.actions;}let p=[];try{for(let A of t)p.push(A.file===X?Ca(A.raw,n,l):ka(A.raw,n));p.length===2&&va(p[0].manifest,p[1].manifest);}catch(A){if(A instanceof he)return {ok:false,rejection:{code:A.code,reason:A.reason,files:A.code==="MANIFEST_DUAL_MISMATCH"?[...pe]:A.reason.file===void 0||A.reason.file===K?r:[A.reason.file]},parseFailure:false,...c===void 0?{}:{identity:c},builtinOnly:d};throw A}let u=p[0];return {ok:true,...u,identity:c??{pluginId:u.manifest.pluginId},files:r}}var X,we,pe,Ct,Se,vt,jt,Yi,kt,qi,ma,ha,_a,Ta,Ea,he,Bt=w(()=>{g();Ue();Ee();Tt();Re();Ut();X="manifest.json",we="ui-plugin.json",pe=[X,we],Ct="0.3",Se="dev.crewx",vt=Object.freeze(["manifest_version","name","display_name","version","description","long_description","author","repository","homepage","documentation","support","icon","icons","screenshots","localization","server","tools","tools_generated","prompts","prompts_generated","keywords","license","privacy_policies","compatibility","user_config","_meta"]),jt=Object.freeze(["manifest_version","name","display_name","version","description","_meta"]),Yi=Object.freeze(vt.filter(e=>e!=="server"&&!jt.includes(e))),kt=Object.freeze(["entry","surfaces","size","stateProjection","actions"]),qi=Object.freeze(["definitionId","definitionVersion","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","csp"]),ma=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,ha=256,_a=/<\/?[A-Za-z][^>]*>/,Ta=/^\s*javascript:/i,Ea=/data:[^,\s]*,/i;he=class extends Error{constructor(t,i){super(`${t}: ${i.path||"<file>"} (${i.rule})`);this.code=t;this.reason=i;}code;reason};});function co(e){if(e===void 0)return {kind:"none"};if(typeof e!="string")return {kind:"invalid",reason:"bad-path"};if(Ha.test(e))return {kind:"url",declared:e};if(!$a(e))return {kind:"invalid",reason:"bad-path",declared:e};let n=e.lastIndexOf("."),t=n<0?void 0:Fa.get(e.slice(n+1).toLowerCase());return t===void 0?{kind:"invalid",reason:"bad-type",declared:e}:{kind:"file",path:e,contentType:t}}function $a(e){return e.length===0||e.length>512||e.startsWith("/")||e.includes("\\")||e.includes("\0")?false:e.split("/").every(n=>n!==""&&n!=="."&&n!=="..")}async function zt(e,n){let t=co(e);if(t.kind==="none")return {diagnostics:[]};if(t.kind==="url")return {diagnostics:[{code:"ICON_NOT_FILE",severity:"warning",declared:t.declared}]};if(t.kind==="invalid")return {diagnostics:[Ht(t.reason,t.declared)]};let i=await n(t.path);if(typeof i=="string")return {diagnostics:[Ht(i,t.path)]};let r=po(t.contentType,i);if(!r.ok)return {diagnostics:[Ht(r.reason,t.path)]};let o={path:t.path,contentType:t.contentType,byteLength:i.byteLength,bytes:i},a=r.square===false?[{code:"ICON_NOT_SQUARE",severity:"warning",declared:t.path}]:[];return {file:o,diagnostics:a}}function Ht(e,n){return {code:"ICON_INVALID",severity:"error",reason:e,...n===void 0?{}:{declared:n}}}function po(e,n){if(n.byteLength>262144)return {ok:false,reason:"too-large"};if(e==="image/png")return !ro(n,za)||nc(n,12,16)!=="IHDR"||n.byteLength<24?{ok:false,reason:"bytes-mismatch"}:{ok:true,square:oo(so(n,16),so(n,20))};if(e==="image/jpeg"){if(!ro(n,Ga))return {ok:false,reason:"bytes-mismatch"};let t=Qa(n);return {ok:true,square:t===void 0?void 0:oo(t.width,t.height)}}return Ja(n)}function Ja(e){let n;try{n=Ba.decode(e);}catch{return {ok:false,reason:"bytes-mismatch"}}return qa(n)?{ok:false,reason:"unsafe-svg"}:Wa.test(n)?{ok:true,square:Za(n)}:{ok:false,reason:"bytes-mismatch"}}function qa(e){if(Xa.some(n=>n.test(e)))return true;for(let n of e.matchAll(Ka))if(!(n[1]??n[2]??n[3]??"").startsWith("#"))return true;for(let n of e.matchAll(Ya))if(to.lastIndex=n.index??0,!to.test(e))return true;return false}function Za(e){let n=/<svg\b[^>]*>/i.exec(e)?.[0];if(n===void 0)return;let t=lo(n,"viewBox");if(t!==void 0){let o=t.trim().split(/[\s,]+/).map(Number);return o.length===4&&o.every(Number.isFinite)?o[2]===o[3]:void 0}let i=io(n,"width"),r=io(n,"height");return i===void 0||r===void 0?void 0:i===r}function lo(e,n){let t=new RegExp(`\\s${n}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(e);return t?.[1]??t?.[2]}function io(e,n){let t=lo(e,n),i=t===void 0?null:/^\s*(\d+(?:\.\d+)?)(?:px)?\s*$/.exec(t);return i===null?void 0:Number(i[1])}function Qa(e){let n=2;for(;n+4<=e.byteLength;){if(e[n]!==255)return;let t=e[n+1];if(t===255){n+=1;continue}if(t===216||t===1||t>=208&&t<=215){n+=2;continue}if(t===217)return;let i=e[n+2]<<8|e[n+3];if(i<2)return;if(ec(t))return n+9>e.byteLength?void 0:{height:ao(e,n+5),width:ao(e,n+7)};n+=2+i;}}function ec(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}function oo(e,n){if(!(e<=0||n<=0))return e===n}function ro(e,n){return e.byteLength>=n.length&&n.every((t,i)=>e[i]===t)}function nc(e,n,t){return String.fromCharCode(...e.subarray(n,t))}function so(e,n){return (e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0}function ao(e,n){return e[n]<<8|e[n+1]}var Fa,Ba,Ha,za,Ga,Wa,Xa,Ka,Ya,to,Gt=w(()=>{g();Fa=new Map([["svg","image/svg+xml"],["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"]]),Ba=new TextDecoder("utf-8",{fatal:true}),Ha=/^[A-Za-z][A-Za-z0-9+.-]*:/,za=[137,80,78,71,13,10,26,10],Ga=[255,216,255];Wa=/^\s*(?:<\?[\s\S]*?\?>\s*|<!--[\s\S]*?-->\s*)*<svg(?=[\s/>])/,Xa=[/<script/i,/[\s"'/]on[a-z]+\s*=/i,/<foreignobject/i,/<!doctype/i,/<!entity/i,/<(?:iframe|embed|object)\b/i,/@import/i],Ka=/(?:^|[\s"'/])(?:xlink:)?href\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/gi,Ya=/url\(/gi,to=/url\(\s*["']?#/iy;});var fo=w(()=>{g();Ti();Bt();Gt();Ut();Re();});function T(e,n=e){throw new _e(e,n)}var _e,Vn=w(()=>{g();_e=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};});var yo=w(()=>{g();});var Ao=w(()=>{g();Ue();Ee();Vn();yo();});function go(e,n){return Io.add(e),n!==void 0&&tc.set(e,n),e}function Xe(e){return e!==null&&typeof e=="object"&&Io.has(e)}var Io,tc,Fn=w(()=>{g();Io=new WeakSet,tc=new WeakMap;});function ln(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function $t(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e);return n.every(o=>Object.hasOwn(e,o))&&r.every(o=>i.has(o))}function _o(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))_o(n);return Object.freeze(e)}function ee(e){throw new Te("LINEAGE_INVALID",e)}function dc(e){throw new Te("LINEAGE_STALE",e)}function To(e){if(!ln(e)||!$t(e,rc,sc)||!ln(e.actions))return ee("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!ln(n)||!$t(n,ac,cc))return ee("Lineage action definition shape is invalid");return e}function pc(e){if(!ln(e)||!$t(e,ic,oc))return ee("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!mo.test(e.hash))return ee("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!mo.test(e.sourceHash)))return ee("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return ee("Lineage compatibility marker is invalid");let n=To(e.definition);if(n.version!==e.version)return ee("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return ee("Lineage source hash does not match its definition");let t;try{t=ie(n),ce({...n,hash:e.hash});}catch{return ee("Lineage definition is invalid")}return t!==e.hash?ee("Lineage definition hash does not match"):_o({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function ho(e){return e.stateProjection?.allow??[]}function lc(e,n){let t=[],i=new Set(ho(n));ho(e).some(s=>!i.has(s))&&t.push("S1_STATE_PROJECTION");let r=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(s=>!r.has(s))&&t.push("S2_DATA_PATHS");for(let[s,c]of Object.entries(e.actions)){let d=n.actions[s];if(d&&(c.confirmation??"native")==="native"&&(d.confirmation??"native")!=="native"){t.push("S3_ACTION_CONFIRMATION");break}}Object.keys(e.legacy?.agentAccess??{}).some(s=>!Object.hasOwn(n.actions,s))&&t.push("S4_LEGACY_AGENT_ACTIONS");let a=e.summaryProjection?.allow;if(a!==void 0){let s=new Set(n.summaryProjection?.allow??[]);a.some(c=>!s.has(c))&&t.push("S5_SUMMARY_PROJECTION");}return t}function uc(e,n){return Z(e)===Z(n)}function Jt(e,n){if(!Array.isArray(e)||e.length===0)return ee("Definition lineage is missing");if(!ln(n)||typeof n.hash!="string")return ee("Current definition is invalid");let t,i;try{let{hash:s,...c}=n;i=To(c),t={...i,hash:s},ce(t);}catch{return ee("Current definition is invalid")}let r=e.map(pc),o=r[0].definition.id;if(r.some(s=>s.definition.id!==o))return ee("Lineage definition ids do not match");if(r.some((s,c)=>c>0&&s.version<=r[c-1].version))return ee("Lineage generations are not in increasing version order");if(r.some((s,c)=>r.findIndex(d=>d.hash===s.hash)!==c))return ee("Lineage contains a duplicate hash");let a=r[r.length-1];if(a.version!==t.version||a.hash!==t.hash||a.definition.id!==t.id||!uc(a.definition,i))return dc("The last lineage generation does not match the current package");if(t.legacy!==void 0){let s=new Set(Object.keys(t.actions)),c=new Set;for(let l of r)if(l.sourceHash===void 0)for(let p of Object.keys(l.definition.actions))s.has(p)&&c.add(p);let d=Object.keys(t.legacy.agentAccess??{});if(d.length!==c.size||d.some(l=>!c.has(l))){let l="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new Te("LINEAGE_INVALID",`Lineage compatibility failed: ${l}`,[l])}}for(let s=0;s<r.length-1;s+=1){if(r.slice(s,-1).some(l=>l.compat==="break"))continue;let d=lc(r[s].definition,t);if(d.length>0)throw new Te("LINEAGE_INVALID",`Lineage compatibility failed: ${d.join(", ")}`,d)}return Object.freeze({entries:Object.freeze(r),current:t})}var Te,mo,ic,oc,rc,sc,ac,cc,Wt=w(()=>{g();Ue();Ee();Te=class extends Error{constructor(t,i=t,r=[]){super(i);this.code=t;this.violations=r;}code;violations;name="UiDefinitionLineageError"},mo=/^[0-9a-f]{64}$/,ic=["version","hash","definition"],oc=["sourceHash","compat"],rc=["id","version","actions"],sc=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],ac=["capabilities"],cc=["inputKeys","dataInputs","confirmation","resultProjection","content","env"];});var Eo,Do,No,bo,Po=w(()=>{g();Eo="text/html;profile=mcp-app",Do=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],No=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"],bo="text/html";});function un(e){return typeof e=="string"&&fc.includes(e)}function Bn(e,n){return e==="card"&&n?.type==="core"&&un(n.handler)}var fc,Hn=w(()=>{g();fc=Object.freeze(["card.secret-env"]);});function So(e,n=[],t){if(e.content!==void 0||e.confirmation!=="none")return "denied";let i=yc();return i&&Object.hasOwn(i,e.actionId)?i[e.actionId]:e.backend?.type==="core"&&e.backend.handler.startsWith("host.")?"denied":e.backend?.type==="core"&&e.backend.handler==="state.set"?"allowed":e.backend?.type==="core"&&un(e.backend.handler)||e.backend?.type==="skill"?"approval_required":e.backend===void 0&&n.includes(e.actionId)?"allowed":"denied"}function yc(e){return;}var Mo=w(()=>{g();Ue();Fn();Hn();});function Dc(e){return An.has(e)&&(e.initialState===void 0||An.has(e.initialState))}function Co(e,n,t,i){let r=i===void 0?void 0:Object.freeze({hash:i.hash,bytes:Object.freeze(i.bytes)}),o=Object.freeze({mimeType:bo,entryHash:e,html:n,bytes:Object.freeze(t),...r===void 0?{}:{initialState:r}});return r!==void 0&&An.add(r),An.add(o),o}function Nc(e){let n=[];return e?.terminal===true&&n.push({name:"crewx_app_terminal_connect",description:"Open a local-only terminal session for this App.",inputSchema:{type:"object",properties:{workspace:{type:"string"},threadId:{type:"string"},instanceId:{type:"string"}},required:["threadId","instanceId"],additionalProperties:false},textFallback:"A local terminal connection is ready for this App.",visibility:Object.freeze(["app"]),kind:"host",resourceBinding:Le}),e?.htmlDocuments===true&&n.push({name:"crewx_app_html_viewer_open",description:"List workspace HTML documents or open one through a short-lived Host capability.",inputSchema:{type:"object",properties:{workspace:{type:"string"},threadId:{type:"string"},instanceId:{type:"string"},operation:{type:"string",enum:["list","open"]},documentId:{type:"string"}},required:["threadId","instanceId","operation"],additionalProperties:false},textFallback:"Workspace HTML documents are available through this App.",visibility:Object.freeze(["app"]),kind:"host",resourceBinding:Le}),n}function Oe(e,n,t){return (typeof e!="string"||!Ro.test(e))&&T(n,`${t} must be a safe identifier`),e}function fn(e,n,t){let i=e??t;return (typeof i!="string"||i.trim().length===0||i.length>gc)&&T("TOOL_INVALID",`${n} must be a meaningful description`),i}function Kt(e){return (typeof e!="string"||e.length===0||e.length>Ke||!/<html(?:\s|>)/i.test(e)||!/<\/html\s*>/i.test(e))&&T("HTML_INVALID","MCP App HTML must be a non-empty HTML document"),e}function yn(e,n=0){try{let t=ae(e,n);return t.type!==void 0&&t.type!=="object"&&T("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof _e)throw t;T("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function bc(e){return (typeof e!="string"||e.trim().length===0||e.length>mc)&&T("TOOL_INVALID","MCP App tools require a meaningful text fallback"),e}function Pc(e){e===void 0&&T("TOOL_INVALID","MCP App tool visibility is required");let n=[...e];return (n.length===0||n.some(t=>t!=="model"&&t!=="app")||new Set(n).size!==n.length)&&T("TOOL_INVALID","MCP App tool visibility must contain model and/or app once"),n}function wo(e){return (typeof e!="string"||!Uo.test(e))&&T("RESOURCE_URI_INVALID","MCP App resource URI is not a registered ui:// URI"),e}function xo(e){let n=Oe(e.appId,"APP_ID_INVALID","Local App id"),t=fn(e.name,"Local App name",n),i=fn(e.description,"Local App description",`${t} interactive view`),r=Jn(e.definition),o=Kt(e.html),a=zn(e.entryHash,"Local App entry hash"),s=e.entryBytes===void 0?Array.from(new TextEncoder().encode(o)):$n(e.entryBytes,"Local App entry bytes");(Gn(s)!==a||Vo(s)!==o)&&T("HTML_INVALID","Local App entry bytes do not match the HTML hash");let c=Sc(e),d=[];Array.isArray(e.actions)||T("TOOL_INVALID","Local App actions must be an array");for(let b of e.actions){let C=Oe(b.actionId,"TOOL_ID_INVALID","Local App action id");(d.includes(C)||!Object.prototype.hasOwnProperty.call(r.actions,C))&&T("TOOL_INVALID",`Local App action is not declared by the UI definition: ${C}`),d.push(C);}let l=Oe(e.readToolName,"TOOL_ID_INVALID","Local App read tool name"),p=e.actionToolName===void 0?void 0:Oe(e.actionToolName,"TOOL_ID_INVALID","Local App action tool name");d.length===0&&p!==void 0&&T("TOOL_INVALID","A static local App cannot register an action tool"),d.length>0&&p===void 0&&T("TOOL_INVALID","A stateful local App requires an action tool name"),p!==void 0&&p===l&&T("TOOL_ID_CONFLICT",`Local App read and action tools share a name: ${l}`);let u=Nc(e.runtime);u.some(b=>b.name===l||b.name===p)&&T("TOOL_ID_CONFLICT","Local App read or action tool conflicts with a requested Host capability");let A={name:l,description:`${t} current state`,inputSchema:Ec,textFallback:`${t} current state is available through its open instance.`,visibility:Object.freeze(["model","app"]),kind:"read",resourceBinding:Le},I=[Object.freeze(A)];if(I.push(...u.map(b=>Object.freeze(b))),p!==void 0){let b={name:p,description:`${t} actions`,inputSchema:Yt(e.actions),textFallback:`${t} action requests are handled by the open App instance.`,visibility:Object.freeze(["app"]),kind:"action",resourceBinding:Le,actionIds:Object.freeze([...d])};I.push(Object.freeze(b));}let h=[],N=new Set(I.map(b=>b.name));if(p!==void 0)for(let b of e.actions){let C=`${p}__${b.actionId}`;if(C.length>128||!Ro.test(C)){h.push(Object.freeze({toolName:C,actionId:b.actionId,reason:"name_too_long"}));continue}if(N.has(C)){h.push(Object.freeze({toolName:C,actionId:b.actionId,reason:"name_collision"}));continue}let G=So({actionId:b.actionId,confirmation:r.actions[b.actionId]?.confirmation,content:r.actions[b.actionId]?.content,backend:b.backend},e.modelActions),D=Object.freeze([...Uc(G,r.usage,b.backend)]),M={name:C,description:`${C} action`,inputSchema:yn(b.inputSchema),textFallback:`${C} action requests are handled by the open App instance.`,visibility:D,kind:"action",resourceBinding:Le,actionId:b.actionId,actionIds:Object.freeze([b.actionId]),_meta:Object.freeze({ui:Object.freeze({visibility:D})})};I.push(Object.freeze(M)),N.add(C);}let F=Co(a,o,s,c===void 0?void 0:{hash:c.hash,bytes:[...c.bytes]}),v={appId:n,name:t,description:i,...e.icon===void 0?{}:{icon:Fo(e.icon)},...e.tone===void 0?{}:{tone:Bo(e.tone)},builtinOnly:false,definition:r,...e.runtime===void 0?{}:{runtime:Object.freeze({...e.runtime})},resourceBinding:Le,resource:F,tools:Object.freeze(I),toolDiagnostics:Object.freeze(h)};return Y(v)}function vo(e={}){return new Xt(e)}function Yt(e){if(e.length===0)return yn({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,yn(i.inputSchema));return yn(Mc(n,t),ko)}function Sc(e){let n=e.definition.dataPaths??[];if(e.initialStateBytes===void 0){e.initialStateHash!==void 0&&T("STATE_INVALID","Initial state hash has no bytes"),e.initialState!==void 0&&ae(e.initialState,0,n);return}e.initialStateHash===void 0&&T("STATE_INVALID","Initial state bytes require a hash");let t=zn(e.initialStateHash,"Initial state hash"),i=$n(e.initialStateBytes,"Initial state bytes");Gn(i)!==t&&T("STATE_INVALID","Initial state bytes do not match the hash");let r;try{let o=new TextDecoder("utf-8",{fatal:!0}).decode(Uint8Array.from(i));r=ae(JSON.parse(o),0,n);}catch{T("STATE_INVALID","Initial state bytes are not projection-safe JSON");}return e.initialState!==void 0&&Z(r)!==Z(ae(e.initialState,0,n))&&T("STATE_INVALID","Initial state bytes do not match the state value"),{hash:t,bytes:Object.freeze([...i])}}function Mc(e,n){let t=e.map(i=>({type:"object",properties:{actionId:{type:"string",const:i},input:n.get(i)??{type:"object"}},required:["actionId","input"],additionalProperties:false}));return Object.freeze({type:"object",oneOf:Object.freeze(t),properties:Object.freeze({actionId:Object.freeze({type:"string",enum:Object.freeze([...e])}),input:Object.freeze({type:"object"})}),required:Object.freeze(["actionId","input"]),additionalProperties:false})}function Lc(e){let n=In(e),t=Oe(n.appId,"APP_ID_INVALID","MCP App id"),i=Kt(n.html);wo(n.uiUri);let r=n.definition===void 0?void 0:Jn(n.definition),o=e.provenance;o!==void 0&&(!Xe(o)||o.appId!==t||o.definitionId!==r?.id||o.version!==r?.version||o.definitionHash!==r?.hash)&&T("TOOL_INVALID","Product App built-in registration provenance is not verified");let a=Object.freeze(n.tools.map(d=>Y(In(d)))),s=Y({...n,appId:t,html:i,...r===void 0?{}:{definition:r},...o===void 0?{}:{provenance:o},tools:a}),c=Y({uri:s.uiUri,mimeType:Eo,text:i,...s.csp===void 0?{}:{_meta:{ui:{csp:s.csp}}}});return Y({appId:t,name:s.name,description:s.description,...s.icon===void 0?{}:{icon:s.icon},...s.tone===void 0?{}:{tone:s.tone},builtinOnly:s.builtinOnly,uiUri:s.uiUri,...r===void 0?{}:{definition:r},resourceBinding:Object.freeze({kind:"mcp",uri:s.uiUri}),resource:c,tools:a,descriptor:s})}function Oc(e){(e.resourceBinding.kind!=="instance"||e.builtinOnly!==false)&&T("STATE_INVALID","Local App registration binding is invalid"),Object.prototype.hasOwnProperty.call(e,"uiUri")&&T("STATE_INVALID","Local App registration cannot contain uiUri");let n=Oe(e.appId,"APP_ID_INVALID","Local App id"),t=Jn(e.definition),i=e.provenance;i!==void 0&&(!Xe(i)||i.appId!==n||i.definitionId!==t.id||i.version!==t.version||i.definitionHash!==t.hash)&&T("TOOL_INVALID","Product App local registration provenance is not verified");let r=Rc(e.resource),o=e.tools.map(s=>{Oe(s.name,"TOOL_ID_INVALID","Local App tool name"),fn(s.description,"Local App tool description","Local App tool"),bc(s.textFallback);let c=yn(s.inputSchema,s.kind==="action"&&!("actionId"in s)?ko:0);if((s.resourceBinding.kind!=="instance"||Object.prototype.hasOwnProperty.call(s,"resourceUri"))&&T("TOOL_INVALID","Local App tools cannot carry an MCP resource URI"),s.kind==="host")return (!Tc.has(s.name)||s.visibility.length!==1||s.visibility[0]!=="app"||Object.prototype.hasOwnProperty.call(s,"actionId"))&&T("TOOL_INVALID","Local App Host tools must use an allow-listed name and app-only visibility"),Y({...s,inputSchema:c,visibility:Object.freeze(["app"])});if(s.kind==="action"){if("actionId"in s){let l=Oe(s.actionId,"TOOL_ID_INVALID","Local App action id");Object.prototype.hasOwnProperty.call(t.actions,l)||T("TOOL_INVALID","Local App action tool references an undeclared action");let p=Pc(s._meta.ui.visibility);return JSON.stringify(p)!==JSON.stringify(s.visibility)&&T("TOOL_INVALID","Local App action metadata visibility must match the tool visibility"),Y({...s,actionId:l,actionIds:Object.freeze([l]),inputSchema:c,visibility:p,_meta:{ui:{visibility:p}}})}let d=[...s.actionIds];return (d.length===0||d.some(l=>!Object.prototype.hasOwnProperty.call(t.actions,l)))&&T("TOOL_INVALID","Local App action tool references an undeclared action"),Y({...s,inputSchema:c,actionIds:Object.freeze(d)})}return Y({...s,inputSchema:c})}),a=Y({appId:n,name:fn(e.name,"Local App name",e.appId),description:fn(e.description,"Local App description",e.name),...e.icon===void 0?{}:{icon:Fo(e.icon)},...e.tone===void 0?{}:{tone:Bo(e.tone)},builtinOnly:false,definition:t,...e.runtime===void 0?{}:{runtime:Object.freeze({...e.runtime})},...i===void 0?{}:{provenance:i},resourceBinding:Le,resource:r,tools:Object.freeze(o),toolDiagnostics:Object.freeze([...e.toolDiagnostics??[]])});return Lo.has(e)?e:(Lo.add(a),a)}function Rc(e){let n=Kt(e.html),t=zn(e.entryHash,"Local App entry hash");if(Dc(e))return e;let i=$n(e.bytes,"Local App entry bytes");(Gn(i)!==t||Vo(i)!==n)&&T("HTML_INVALID","Local App entry bytes do not match the HTML hash");let r=e.initialState===void 0?void 0:{hash:zn(e.initialState.hash,"Initial state hash"),bytes:$n(e.initialState.bytes,"Initial state bytes")};return r&&Gn(r.bytes)!==r.hash&&T("STATE_INVALID","Initial state bytes do not match the hash"),Co(t,n,i,r)}function Uc(e,n,t){if(Bn(n,t))return ["model"];let i=t?.type==="core"&&un(t.handler);return e==="denied"||i?["app"]:["model","app"]}function Cc(e){return Y({appId:e.appId,name:e.name,description:e.description,...e.icon===void 0?{}:{icon:e.icon},...e.tone===void 0?{}:{tone:e.tone},builtinOnly:false,definition:jo(e.definition),...e.provenance===void 0?{}:{provenance:e.provenance},entryHash:e.resource.entryHash,resourceBinding:Le,tools:e.tools})}function kc(e){return Y({appId:e.appId,name:e.name,description:e.description,...e.icon===void 0?{}:{icon:e.icon},...e.tone===void 0?{}:{tone:e.tone},builtinOnly:e.builtinOnly,uiUri:e.uiUri,...e.definition===void 0?{}:{definition:jo(e.definition)},resourceBinding:Object.freeze({kind:"mcp",uri:e.uiUri}),tools:e.tools})}function Jn(e){try{if(Object.isFrozen(e))return ce(e),Y(e);let n=In(e);return ce(n),Y(n)}catch(n){if(n instanceof _e)throw n;T("STATE_INVALID","UI definition is not a valid immutable definition");}}function jo(e){return Y({id:e.id,version:e.version,hash:e.hash})}function wc(e){return e!==null&&typeof e=="object"&&typeof e.id=="string"&&Number.isSafeInteger(e.version)&&typeof e.hash=="string"}function Oo(e,n,t){return `${e}\0${n}\0${t}`}function zn(e,n){return (typeof e!="string"||!Ic.test(e))&&T("SERIALIZATION_INVALID",`${n} is invalid`),e}function Gn(e){return crypto.createHash("sha256").update(Uint8Array.from(e)).digest("hex")}function $n(e,n){return (!Array.isArray(e)||e.some(t=>!Number.isInteger(t)||t<0||t>255))&&T("SERIALIZATION_INVALID",`${n} is invalid`),[...e]}function Vo(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(Uint8Array.from(e))}catch{T("SERIALIZATION_INVALID","UTF-8 bytes are invalid");}}function Fo(e){return (typeof e!="string"||!hc.test(e))&&T("TOOL_INVALID","MCP App icon is invalid"),e}function Bo(e){return (typeof e!="string"||!_c.has(e))&&T("TOOL_INVALID","MCP App tone is invalid"),e}function In(e,n=new Map){if(e===null||typeof e!="object")return e;let t=e;if(n.has(t)&&T("SERIALIZATION_INVALID","MCP App value contains a cycle"),Array.isArray(e)){let o=[];n.set(t,o);for(let a of e)o.push(In(a,n));return n.delete(t),o}let i;try{i=Object.getPrototypeOf(e);}catch{T("SERIALIZATION_INVALID","MCP App value cannot be cloned");}i!==Object.prototype&&i!==null&&T("SERIALIZATION_INVALID","MCP App value must be plain JSON");let r={};n.set(t,r);for(let[o,a]of Object.entries(e))Object.defineProperty(r,o,{configurable:true,enumerable:true,value:In(a,n),writable:true});return n.delete(t),r}function Y(e,n=new Set){if(e===null||typeof e!="object"||n.has(e)||An.has(e))return e;n.add(e);for(let t of Object.values(e))Y(t,n);return Object.freeze(e),e}var Ro,Uo,Ic,Ke,gc,mc,hc,_c,Tc,Le,Ec,An,Lo,ko,Xt,Wn=w(()=>{g();Ao();Ue();Ee();Fn();Vn();Wt();Po();Mo();Hn();Ro=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Uo=/^ui:\/\/crewx\/([A-Za-z][A-Za-z0-9._-]{0,127})\/([0-9a-f]{12})$/,Ic=/^[0-9a-f]{64}$/,Ke=8*1024*1024,gc=8*1024,mc=16*1024,hc=/^[a-z][a-z0-9-]{0,63}$/,_c=new Set(["blue","violet","emerald","amber","rose","sky","slate","indigo"]),Tc=new Set(Do),new Set(No),Le=Object.freeze({kind:"instance"}),Ec=Object.freeze({type:"object",properties:Object.freeze({}),additionalProperties:false}),An=new WeakSet,Lo=new WeakSet;ko=4;Xt=class{builtinApps;localApps;builtinDescriptors;builtinTools;mcpResources=new Map;localById=new Map;registrationById=new Map;launcherById=new Map;definitionByKey=new Map;handlerByKey=new Map;mcpToolByName=new Map;localToolByName=new Map;constructor(n){let t=n.builtins??n.builtin,i=[],r=[],o=[],a=new Set,s=new Set;for(let p of t?.listMcpApps()??[]){let u=Lc(p);a.has(u.appId)&&T("APP_ID_CONFLICT",`MCP App id is already registered: ${u.appId}`),a.add(u.appId);let A=u.tools;for(let I of A)s.has(I.name)&&T("TOOL_ID_CONFLICT",`MCP App tool name is already registered: ${I.name}`),s.add(I.name),this.mcpToolByName.set(I.name,I),o.push(I);this.mcpResources.set(u.resource.uri,u.resource),i.push(u),r.push(u.descriptor);}let c=(n.localApps??n.locals??[]).map(Oc),d=new Set(c.flatMap(p=>p.tools.filter(u=>!(u.kind==="action"&&"actionId"in u)).map(u=>u.name))),l=[];for(let p of c){let u=p;a.has(u.appId)&&T("APP_ID_CONFLICT",`MCP App id is already registered: ${u.appId}`),a.add(u.appId);let A=[],I=[...u.toolDiagnostics??[]];for(let h of u.tools){if(s.has(h.name)){if(h.kind==="host"&&this.localToolByName.get(h.name)?.kind==="host"){A.push(h);continue}if(h.kind==="action"&&"actionId"in h){I.push(Object.freeze({toolName:h.name,actionId:h.actionId,reason:"name_collision"}));continue}T("TOOL_ID_CONFLICT",`MCP App tool name is already registered: ${h.name}`);}if(h.kind==="action"&&"actionId"in h&&d.has(h.name)){I.push(Object.freeze({toolName:h.name,actionId:h.actionId,reason:"name_collision"}));continue}s.add(h.name),this.localToolByName.set(h.name,h),A.push(h);}(A.length!==u.tools.length||I.length!==(u.toolDiagnostics?.length??0))&&(u=Y({...u,tools:Object.freeze(A),toolDiagnostics:Object.freeze(I)})),l.push(u),this.localById.set(u.appId,u);}for(let p of i)this.registrationById.set(p.appId,p),this.launcherById.set(p.appId,kc(p)),p.definition&&this.addDefinition(p.definition);for(let p of l)this.registrationById.set(p.appId,p),this.launcherById.set(p.appId,Cc(p)),this.addDefinition(p.definition);for(let p of n.definitions??[])this.addDefinition(p);for(let p of n.handlers??[])this.addHandler(p);this.builtinApps=Object.freeze(i),this.localApps=Object.freeze(l),this.builtinDescriptors=Object.freeze(r),this.builtinTools=Object.freeze(o);}getMcpApp(n){return this.builtinApps.find(t=>t.appId===n)?.descriptor??null}listMcpApps(){return this.builtinDescriptors}listMcpAppTools(){return this.builtinTools}resolveMcpAppTool(n){return this.mcpToolByName.get(n)??null}resolveMcpAppResource(n){return typeof n!="string"||!Uo.test(n)?null:this.mcpResources.get(n)??null}requireMcpAppResource(n){wo(n);let t=this.mcpResources.get(n);return t||T("RESOURCE_NOT_FOUND",`MCP App resource is not registered: ${n}`),t}listLocalMcpApps(){return this.localApps}getLocalMcpApp(n){return this.localById.get(n)??null}listLocalMcpAppTools(){return Object.freeze([...this.localToolByName.values()])}resolveLocalMcpAppTool(n){return this.localToolByName.get(n)??null}resolveLocalMcpAppResource(n,t){let i=this.localById.get(n);return !i||t!==void 0&&i.definition.hash!==t?null:i.resource}listRegistrations(){return Object.freeze([...this.builtinApps,...this.localApps])}getRegistration(n){return this.registrationById.get(n)??null}listLaunchers(){return Object.freeze([...this.launcherById.values()].filter(n=>{let t=this.registrationById.get(n.appId),i=t?"descriptor"in t?t.descriptor.provenance:t.provenance:void 0,r=Xe(i)&&i.launcher===false;return t?.definition?.usage!=="card"&&!r}))}listCardApps(){return Object.freeze([...this.launcherById.values()].filter(n=>this.registrationById.get(n.appId)?.definition?.usage==="card"))}getLauncher(n){return this.launcherById.get(n)??null}resolveDefinition(n){if(!wc(n))return null;let t=this.definitionByKey.get(_t(n));if(!t||t.hash!==n.hash)return null;try{return ie(t)===t.hash?t:null}catch{return null}}resolveActionHandler(n,t,i){return typeof n!="string"||typeof i!="string"||!Number.isSafeInteger(t)?null:this.handlerByKey.get(Oo(n,t,i))??null}addDefinition(n){let t=Jn(n),i=_t(t),r=this.definitionByKey.get(i);r&&r.hash!==t.hash&&T("STATE_INVALID",`UI definition generation conflicts: ${i}`),r||this.definitionByKey.set(i,t);}addHandler(n){(!n||typeof n.definitionId!="string"||typeof n.actionId!="string"||!Number.isSafeInteger(n.version)||n.version<1||typeof n.handle!="function")&&T("STATE_INVALID","UI action handler registration is invalid");let t=Oo(n.definitionId,n.version,n.actionId);this.handlerByKey.has(t)&&T("TOOL_INVALID",`Duplicate UI action handler registration: ${t}`),this.handlerByKey.set(t,Object.freeze({...n}));}};});function xc(e){let n=xo({appId:e.appId,name:e.name,description:e.description,...e.icon===void 0?{}:{icon:e.icon},...e.tone===void 0?{}:{tone:e.tone},...e.normalized.manifest.runtime===void 0?{}:{runtime:e.normalized.manifest.runtime},definition:e.definition,html:e.html,entryHash:e.entryHash,entryBytes:e.entryBytes,initialState:e.initialState,...e.initialStateHash===void 0?{}:{initialStateHash:e.initialStateHash},...e.initialStateBytes===void 0?{}:{initialStateBytes:e.initialStateBytes},readToolName:e.toolNames.read,...e.toolNames.action===void 0?{}:{actionToolName:e.toolNames.action},actions:e.normalized.manifest.actions.map(i=>({actionId:i.actionId,inputSchema:i.inputSchema,backend:i.backend}))});return e.provenance===void 0?n:Object.freeze({...n,provenance:e.provenance})}function Ho(e){let n=e.normalized.manifest.actions;if(n.some(i=>i.backend.type==="skill")&&n.some(i=>i.backend.type==="core"))throw new Error("Mixed workspace App execution models");let t=xc(e);vo({localApps:[t],definitions:[e.definition]});}var zo=w(()=>{g();Wn();});function Go(){return Object.freeze({[qt]:{candidates:new Map,assetCatalogs:new Map,preparedCandidates:new Map}})}function vc(e){if(e===null||typeof e!="object"||!(qt in e))throw new TypeError("scanCache must be created by createWorkspaceAppScanCache");return e[qt]}function $o(e,n){let t=vc(e),i=t.rootIdentity;return i!==void 0&&(i.dev!==n.dev||i.ino!==n.ino||i.realPath!==n.realPath)&&(t.candidates.clear(),t.assetCatalogs.clear(),t.preparedCandidates.clear(),t.lastCandidateScanUnchanged=void 0,t.lastCandidateKeys=void 0,t.scanStartedAtNs=void 0,t.lastAssetCatalogsUnchanged=void 0,t.lastSnapshot=void 0,t.lastSnapshotBuildInputs=void 0,t.lastSnapshotCandidates=void 0,t.lastSnapshotCatalogFingerprint=void 0),t.rootIdentity=n,t}var qt,Jo=w(()=>{g();qt=Symbol("crewx.workspace-app-scan-cache.state");});function re(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new _("NOT_FOUND"):n==="ELOOP"?new _("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new _("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new _("READ_DENIED"):new _("READ_DENIED")}function Bc(e){if(typeof e!="string"||e.length===0||!path.isAbsolute(e))throw new _("READ_DENIED")}function Zt(e){if(typeof e!="string"||path.isAbsolute(e)||/[\\\u0000]/.test(e))throw new _("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new _("PATH_ESCAPED");return n}function qn(e,n){let t=path.relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${path.sep}`)&&!path.isAbsolute(t)}function qe(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function ti(e,n){return e.dev===n.dev&&e.ino===n.ino}function ii(e,n){return ti(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function Xn(e){Bc(e);let n,t;try{n=await promises.realpath(e),t=await promises.stat(n,{bigint:!0});}catch(i){throw re(i)}if(!t.isDirectory())throw new _("READ_DENIED");return {realRoot:n,identity:qe(t)}}async function Ko(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,r;try{if(i=path.resolve(e,t[0],t[1]),r=await promises.realpath(i),!(await promises.stat(r,{bigint:!0})).isDirectory())throw new _("READ_DENIED")}catch(o){throw o instanceof _?o:re(o)}if(!qn(n,r))throw new _("PATH_ESCAPED");return r}async function Kn(e,n,t,i){let r,o,a;try{r=await promises.lstat(e,{bigint:!0}),o=await promises.realpath(e),a=await promises.stat(o,{bigint:!0});}catch(s){throw re(s)}if(!qn(n,o)||t!==void 0&&!qn(t,o))throw new _("PATH_ESCAPED");if(!r.isFile()||!a.isFile())throw new _("READ_DENIED");if(!ti(i,r)||!ti(i,a)||i.dev!==a.dev)throw new _("PATH_ESCAPED")}async function Ye(e,n){let t,i;try{t=await promises.realpath(e),i=await promises.stat(t,{bigint:!0});}catch{throw new _("PATH_ESCAPED")}if(t!==n.realRoot||!ii(n.identity,qe(i)))throw new _("PATH_ESCAPED")}function Hc(e){return e.isSymbolicLink()?{name:e.name,kind:"symlink"}:e.isDirectory()?{name:e.name,kind:"directory"}:e.isFile()?{name:e.name,kind:"file"}:{name:e.name,kind:"other"}}var _,ni,Fc,Xo,Ze,Zn,Yo,qo,ri=w(()=>{g();_=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},ni=fs$1.constants.O_NOFOLLOW,Fc=fs$1.constants.O_NONBLOCK,Xo=fs$1.constants.O_RDONLY|(ni??0)|(Fc??0);Ze=class{async getRootIdentity(n){let t=await Xn(n);return await Ye(n,t),{dev:t.identity.dev,ino:t.identity.ino,realPath:t.realRoot}}async listDirectory(n,t){let i=Zt(t),r=await Xn(n),o=path.resolve(n,...i),a,s;try{a=await promises.realpath(o),s=await promises.stat(a,{bigint:!0});}catch(c){let d=re(c);if(d.code==="NOT_FOUND")return [];throw d}if(!qn(r.realRoot,a)||!s.isDirectory())throw new _("PATH_ESCAPED");try{let c=await promises.readdir(a,{withFileTypes:!0,encoding:"utf8"});return await Ye(n,r),c.map(Hc)}catch(c){let d=re(c);if(d.code==="NOT_FOUND")return [];throw d}}async readdir(n,t){return this.listDirectory(n,t)}async readDirectory(n,t){return this.listDirectory(n,t)}async readVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new _("READ_DENIED");if(ni===void 0)throw new _("UNSUPPORTED");let r=Zt(t),o=await Xn(n),a=path.resolve(n,...r),s=path.relative(n,a);if(s===".."||s.startsWith(`..${path.sep}`)||path.isAbsolute(s))throw new _("PATH_ESCAPED");let c;try{c=await promises.open(a,Xo);}catch(d){throw re(d)}try{let d;try{let I=await c.stat({bigint:!0});d=qe(I);}catch(I){throw re(I)}if(d.size>BigInt(i))throw new _("LIMIT_EXCEEDED");if(d.size>BigInt(Number.MAX_SAFE_INTEGER))throw new _("LIMIT_EXCEEDED");await Ye(n,o);let l=await Ko(n,o.realRoot,r);await Kn(a,o.realRoot,l,d);let p=new Uint8Array(new ArrayBuffer(Number(d.size))),u=0;for(;u<p.byteLength;){let I;try{I=(await c.read(p,u,p.byteLength-u,u)).bytesRead;}catch(h){throw re(h)}if(I<=0)throw new _("IDENTITY_CHANGED");u+=I;}let A;try{let I=await c.stat({bigint:!0});A=qe(I);}catch(I){throw re(I)}if(!ii(d,A))throw new _("IDENTITY_CHANGED");return await Kn(a,o.realRoot,l,A),await Ye(n,o),new Uint8Array(p)}finally{await c.close().catch(()=>{});}}async fingerprintVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new _("READ_DENIED");if(ni===void 0)throw new _("UNSUPPORTED");let r=Zt(t),o=await Xn(n),a=path.resolve(n,...r),s=path.relative(n,a);if(s===".."||s.startsWith(`..${path.sep}`)||path.isAbsolute(s))throw new _("PATH_ESCAPED");let c;try{c=await promises.open(a,Xo);}catch(d){throw re(d)}try{let d;try{let u=await c.stat({bigint:!0});d=qe(u);}catch(u){throw re(u)}if(d.size>BigInt(i)||d.size>BigInt(Number.MAX_SAFE_INTEGER))throw new _("LIMIT_EXCEEDED");await Ye(n,o);let l=await Ko(n,o.realRoot,r);await Kn(a,o.realRoot,l,d);let p;try{let u=await c.stat({bigint:!0});p=qe(u);}catch(u){throw re(u)}if(!ii(d,p))throw new _("IDENTITY_CHANGED");return await Kn(a,o.realRoot,l,p),await Ye(n,o),{...p,candidateRealPath:l??o.realRoot}}catch(d){throw d instanceof _?d:re(d)}finally{await c.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},Zn=new Ze,Yo=Zn,qo=Ze;});function _n(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function Qo(e){return typeof e=="string"&&Ie.test(e)?e:void 0}function Kc(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function ve(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let a=t[o]-i[o];if(a!==0)return a}return t.byteLength-i.byteLength}function Yc(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function qc(e){if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("filesystem port returned an invalid byte array")}function Zc(e){return Wc.decode(e)}function Qc(e){return JSON.parse(Zc(e))}function er(e){switch(e){case "ENOENT":return "NOT_FOUND";case "ELOOP":case "EXDEV":return "PATH_ESCAPED";case "EFBIG":case "EOVERFLOW":return "LIMIT_EXCEEDED";case "EACCES":case "EPERM":case "ENOTDIR":return "READ_DENIED";default:return e}}function ed(e){if(e instanceof _)return er(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return er(n)}}function Ne(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function nd(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function td(e){if(typeof e.listDirectory=="function")return e.listDirectory;if(typeof e.readDirectory=="function")return e.readDirectory;if(typeof e.readdir=="function")return e.readdir}async function nr(e,n,t,i){let r=nd(e);if(!r)throw new _("READ_DENIED");return qc(await r.call(e,n,t,i))}async function ci(e,n,t){let i=td(e);if(!i)throw new _("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new _("READ_DENIED");return r.map(Yc).filter(o=>o!==null)}function id(e,n,t,i){return Object.freeze({code:e,...{},source:n,relativePath:t})}function od(e){if(!_n(e))throw new TypeError("productBundle.reservedIds must be an object with appIds and definitionIds arrays");try{let n=Reflect.ownKeys(e);if(n.length!==2||!n.includes("appIds")||!n.includes("definitionIds"))throw new TypeError("productBundle.reservedIds must contain exactly appIds and definitionIds");let t=(i,r)=>{if(!Array.isArray(i))throw new TypeError("productBundle.reservedIds."+r+" must be an array");let o=[];for(let a=0;a<i.length;a+=1){let s=i[a];if(typeof s!="string"||s.length===0)throw new TypeError("productBundle.reservedIds."+r+" must contain non-empty strings");o.push(s);}return Object.freeze([...new Set(o)].sort(ve))};return Object.freeze({appIds:t(e.appIds,"appIds"),definitionIds:t(e.definitionIds,"definitionIds")})}catch(n){throw n instanceof TypeError?n:new TypeError("productBundle.reservedIds must be a valid reservation object")}}function rd(e,n){return e.appIds.length===n.appIds.length&&e.appIds.every((t,i)=>t===n.appIds[i])&&e.definitionIds.length===n.definitionIds.length&&e.definitionIds.every((t,i)=>t===n.definitionIds[i])}function Tn(e){return Object.freeze({appIds:Object.freeze([...new Set(e.map(n=>n.appId))].sort(ve)),definitionIds:Object.freeze([...new Set(e.map(n=>n.definition.id))].sort(ve))})}function Qn(e,n){let t=Object.keys(e).sort(ve),i=[...n].sort(ve);return t.length===i.length&&t.every((r,o)=>r===i[o])}function tr(e){if(typeof e!="string"||e.length===0||e.startsWith("/")||/[\\\u0000]/.test(e))return;let n=e.split("/");if(!n.some(t=>t.length===0||t==="."||t===".."))return n}function sd(e){let n;try{n=Qc(e);}catch{return}if(!_n(n)||!Qn(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>di)return;let t=new Set,i=new Set,r=0,o=[];for(let a of n.packages){if(!_n(a))return;let s=["packageDir","appId","definition","files"],c=Object.hasOwn(a,"lineage"),d=Object.hasOwn(a,"launcher"),l=[...c?["lineage"]:[],...d?["launcher"]:[]];if(!Qn(a,[...s,...l])||d&&a.launcher!==false)return;let p=tr(a.packageDir),u=Qo(a.appId);if(!p||p.length!==2||p[0]!=="apps"||!Kc(p[1])||!u||t.has(a.packageDir)||!_n(a.definition)||!Qn(a.definition,["id","version","hash"]))return;let A=Qo(a.definition.id),I=a.definition.version,h=a.definition.hash;if(!A||!Number.isSafeInteger(I)||I<1||typeof h!="string"||!ai.test(h)||!Array.isArray(a.files)||a.files.length<2||a.files.length>pi)return;let N=new Set,F=[];for(let v of a.files){if(!_n(v)||!Qn(v,["path","sha256"]))return;let b=tr(v.path);if(!b||typeof v.sha256!="string"||!ai.test(v.sha256))return;let C=b.join("/"),G=`${a.packageDir}/${C}`;if(N.has(C)||i.has(G))return;N.add(C),i.add(G),F.push(Object.freeze({path:C,sha256:v.sha256}));}if(!pe.some(v=>N.has(v))||!N.has("ui/index.html")||(r+=F.length,r>Gc))return;t.add(a.packageDir),o.push(Object.freeze({packageDir:a.packageDir,...d?{launcher:false}:{},appId:u,definition:Object.freeze({id:A,version:I,hash:h}),lineage:Array.isArray(a.lineage)?a.lineage:[],files:Object.freeze(F.sort((v,b)=>ve(v.path,b.path)))}));}return Object.freeze({version:1,packages:Object.freeze(o)})}function xe(e){let n=ed(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function ad(e,n,t,i,r){let o=[],a=async(s,c)=>{if(!Ne(i,r))throw new _("LIMIT_EXCEEDED");if(c>2)throw new _("LIMIT_EXCEEDED");let d=await ci(e,n,s);for(let l of d){if(typeof l.name!="string"||l.name.length===0||l.name==="."||l.name===".."||/[\\/\u0000]/.test(l.name))throw new _("PATH_ESCAPED");let p=`${s}/${l.name}`;if(l.kind==="file"){if(o.push(p.slice(t.length+1)),o.length>pi)throw new _("LIMIT_EXCEEDED")}else if(l.kind==="directory")await a(p,c+1);else throw l.kind==="symlink"?new _("PATH_ESCAPED"):new _("READ_DENIED")}};return await a(t,0),o.sort(ve)}function cd(e){return pe.includes(e)?262144:e==="ui/index.html"?Ke:e==="ui/state.json"?2097152:e.startsWith("ui/assets/")?Jc:$c}async function ir(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false,reservedIds:Xc};let r=od(e.reservedIds),o=[],a=(y,m,E)=>id(y,"bundled",m),s=(y=[],m=false,E)=>({...E===void 0?{}:{indexHash:E},packages:y,diagnostics:o,incomplete:m,reservedIds:r});if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!ai.test(e.expectedIndexHash))return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();let c;try{c=await nr(n,e.root,"bundle-index.json",zc);}catch(y){return o.push(a(xe(y),"bundle-index.json")),s()}let d=crypto.createHash("sha256").update(c).digest("hex");if(d!==e.expectedIndexHash)return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();let l=sd(c);if(l===void 0)return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();if(!rd(Tn(l.packages),r))return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s([],false,d);if(!Ne(t,i))return o.push(a("LIMIT_EXCEEDED","bundle-index.json")),s(l.packages.map(y=>({indexEntry:y,failureCode:"LIMIT_EXCEEDED"})),true,d);let p;try{p=await ci(n,e.root,"");}catch(y){return o.push(a(xe(y),"bundle-index.json")),s(l.packages.map(m=>({indexEntry:m,failureCode:xe(y)})),false,d)}if(!Ne(t,i))return o.push(a("LIMIT_EXCEEDED","bundle-index.json")),s(l.packages.map(y=>({indexEntry:y,failureCode:"LIMIT_EXCEEDED"})),true,d);let u=p.find(y=>y.name==="bundle-index.json"&&y.kind==="file"),A=p.find(y=>y.name==="apps"&&y.kind==="directory"),I=y=>l.packages.map(m=>({indexEntry:m,failureCode:y}));if(!u)return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s(I("BUNDLE_INTEGRITY"),false,d);let h=p.filter(y=>y.name!=="bundle-index.json"&&y.name!=="apps");if(h.length>0){let y=h.some(m=>m.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return o.push(a(y,"bundle-index.json")),s(I("BUNDLE_INTEGRITY"),false,d)}if(p.some(y=>y.name==="apps"&&y.kind!=="directory"))return o.push(a("PATH_ESCAPED","apps")),s(I("PATH_ESCAPED"),false,d);let N=[];if(A)try{N=await ci(n,e.root,"apps");}catch(y){return o.push(a(xe(y),"apps")),s(I(xe(y)),false,d)}if(!Ne(t,i)||N.length>di)return o.push(a("LIMIT_EXCEEDED","apps")),s(I("LIMIT_EXCEEDED"),true,d);let F=new Map(l.packages.map(y=>[y.packageDir.slice(5),y])),v=N.filter(y=>!F.has(y.name));for(let y of v)o.push(a(y.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${y.name}`));if(v.length>0){let y=v.some(m=>m.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return s(I(y),false,d)}let b=new Set,C=new Map,G=new Map;for(let y of l.packages){let m=C.get(y.appId)??[];m.push(y),C.set(y.appId,m);let E=`${y.definition.id}\0${String(y.definition.version)}`,P=G.get(E)??[];P.push(y),G.set(E,P);}for(let y of [...C.values(),...G.values()])if(y.length>1)for(let m of y)b.add(m);let D=[],M=c.byteLength,S=false;for(let y of l.packages){if(!Ne(t,i)){S=true,D.push({indexEntry:y,failureCode:"LIMIT_EXCEEDED"});continue}let m;try{let L=y.lineage[y.lineage.length-1];if(!L)throw new Te("LINEAGE_INVALID","Definition lineage is missing");if(L.definition.id!==y.definition.id||L.version!==y.definition.version||L.hash!==y.definition.hash)throw new Te("LINEAGE_STALE","Last lineage generation does not match bundle identity");m=Jt(y.lineage,{...L.definition,hash:L.hash}).entries;}catch(L){let O=L instanceof Te?L.code:"LINEAGE_INVALID";o.push(a(O,y.packageDir)),D.push({indexEntry:y,failureCode:O});continue}let E=N.find(L=>L.name===y.packageDir.slice(5));if(!A||!E){D.push({indexEntry:y,failureCode:"BUNDLE_INTEGRITY"});continue}if(E.kind!=="directory"){D.push({indexEntry:y,failureCode:E.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let P;try{let L=await ad(n,e.root,y.packageDir,t,i);if(!Ne(t,i)){S=!0,D.push({indexEntry:y,failureCode:"LIMIT_EXCEEDED"});continue}let O=y.files.map(B=>B.path);if(L.length!==O.length||L.some((B,Pe)=>B!==O[Pe])){D.push({indexEntry:y,failureCode:"BUNDLE_INTEGRITY"});continue}P=new Map;let q;for(let B of y.files){if(!Ne(t,i)){q="LIMIT_EXCEEDED",S=!0;break}if(M>=si){q="LIMIT_EXCEEDED";break}let Pe;try{Pe=await nr(n,e.root,`${y.packageDir}/${B.path}`,cd(B.path));}catch(ot){q=xe(ot);break}if(!Ne(t,i)){q="LIMIT_EXCEEDED",S=!0;break}if(M+Pe.byteLength>si){M=si,q="LIMIT_EXCEEDED";break}if(M+=Pe.byteLength,crypto.createHash("sha256").update(Pe).digest("hex")!==B.sha256){q="BUNDLE_INTEGRITY";break}P.set(B.path,Pe);}if(q!==void 0){D.push({indexEntry:y,failureCode:q});continue}}catch(L){Ne(t,i)||(S=true),D.push({indexEntry:y,failureCode:xe(L)});continue}D.push({indexEntry:y,lineage:m,files:P,...b.has(y)?{failureCode:"DUPLICATE_ID"}:{}});}return s(D,S,d)}var zc,di,pi,Gc,$c,Jc,si,ai,Wc,Xc,li=w(()=>{g();Wt();Re();Bt();Wn();ri();zc=256*1024,di=64,pi=128,Gc=di*pi,$c=2*1024*1024,Jc=8*1024*1024,si=32*1024*1024,ai=/^[0-9a-f]{64}$/,Wc=new TextDecoder("utf-8",{fatal:true}),Xc=Object.freeze({appIds:Object.freeze([]),definitionIds:Object.freeze([])});});var Pr={};kr(Pr,{AppDiscoveryFsError:()=>_,LOCAL_APP_TOOL_PREFIX:()=>ld,MCP_APP_WORKSPACE_TOOL_PREFIX:()=>ud,NodeAppDiscoveryFs:()=>Ze,NodeAppDiscoveryFsAdapter:()=>qo,WORKSPACE_APP_TOOL_PREFIX:()=>Qe,createWorkspaceAppScanCache:()=>Go,defaultAppDiscoveryFs:()=>Zn,defaultNodeAppDiscoveryFs:()=>Yo,deriveWorkspaceAppToolName:()=>fd,deriveWorkspaceAppToolNames:()=>yi,discoverWorkspaceAppCandidates:()=>Hd,discoverWorkspaceApps:()=>Ai,isWorkspacePackage:()=>pd,productAppBundleReservations:()=>Tn,scanWorkspaceApps:()=>zd});function pd(e,n){let t=n.split("/");return t.length===2&&t[0]===e&&/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t[1])}function yi(e){if(typeof e!="string"||!Ie.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Qe}${e}`.length+7<=128?e:`hash_${crypto.createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Qe}${n}_read`,action:`${Qe}${n}_action`}}function fd(e,n="read"){let t=yi(e);return n==="read"?t.read:t.action}function rr(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function Ad(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function Id(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Dn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let a=t[o]-i[o];if(a!==0)return a}return t.byteLength-i.byteLength}function Ir(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function gd(e){if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("filesystem port returned an invalid byte array")}function gr(e){return yd.decode(e)}function md(e){return JSON.parse(gr(e))}function hd(e){if(e===void 0)return;let n=e.definitionId!==void 0&&e.definitionVersion!==void 0?`${e.definitionId}\0${String(e.definitionVersion)}`:void 0;return {pluginId:e.pluginId,...n===void 0?{}:{definitionKey:n}}}function et(e,n,t,i,r){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t,...r?.reason===void 0?{}:{reason:Object.freeze({...r.reason})},...r?.files===void 0?{}:{files:Object.freeze([...r.files])}};return Object.freeze(o)}function sr(e){switch(e){case "ENOENT":return "NOT_FOUND";case "ELOOP":case "EXDEV":return "PATH_ESCAPED";case "EFBIG":case "EOVERFLOW":return "LIMIT_EXCEEDED";case "EACCES":case "EPERM":case "ENOTDIR":return "READ_DENIED";default:return e}}function ne(e){if(e instanceof _)return sr(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return sr(n)}}function Ve(e,n){return e==="PATH_ESCAPED"||e==="IDENTITY_CHANGED"||e==="TOCTOU"?"PATH_ESCAPED":e==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":n==="manifest"&&e==="NOT_FOUND"?"MANIFEST_MISSING":n==="entry"?"ENTRY_INVALID":n==="initial"?"INITIAL_STATE_INVALID":"MANIFEST_INVALID"}function ar(e){return {reason:e.reason,...e.code==="MANIFEST_DUAL_MISMATCH"?{files:e.files}:{}}}function cr(e){return e==="MANIFEST_DUAL_MISMATCH"?e:mr(e)}function _d(e){return mr(e.code)}function mr(e){switch(e){case "MANIFEST_INVALID":case "PRIMITIVE_UNKNOWN":case "PRIMITIVE_SET_UNSUPPORTED":case "SCHEMA_TYPE_UNSUPPORTED":case "TOKEN_INVALID":case "UNSAFE_VALUE":return "MANIFEST_INVALID";case "LIMIT_EXCEEDED":return "LIMIT_EXCEEDED";case "INITIAL_STATE_INVALID":return "INITIAL_STATE_INVALID";default:return hr("UiPluginValidationError",e)}}function hr(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function _r(e){switch(e){case "APP_ID_INVALID":case "TOOL_ID_INVALID":case "RESOURCE_URI_INVALID":case "TOOL_INVALID":case "SERIALIZATION_INVALID":return "MANIFEST_INVALID";case "APP_ID_CONFLICT":case "TOOL_ID_CONFLICT":return "DUPLICATE_ID";case "RESOURCE_NOT_FOUND":case "HTML_INVALID":return "ENTRY_INVALID";case "STATE_INVALID":case "STATE_PROJECTION_INVALID":case "BUTTON_INVALID":return "INITIAL_STATE_INVALID";default:return hr("McpAppContractError",e)}}function be(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Td(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function Ed(e,n){let t=n.get("package.json");if(t!==void 0)try{let r=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t));if(rr(r)){let o=r.bin,a=typeof o=="string"?o:rr(o)?Object.values(o).find(s=>typeof s=="string"):void 0;for(let s of [a,r.main]){if(typeof s!="string")continue;let c=Dd(s);if(c&&n.has(c))return c}}}catch{}return [`${e.slice(e.lastIndexOf("/")+1)}.js`,"index.js","main.js"].find(r=>n.has(r))}function Dd(e){if(e.startsWith("/")||e.includes("\\")||e.includes("\0"))return;let n=e.split("/").filter(t=>t!==".");if(!(n.length===0||n.some(t=>t.length===0||t==="..")))return n.join("/")}function Nd(){return globalThis.performance?.now()??Date.now()}function je(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))je(n);return Object.freeze(e)}function dr(e){return Object.freeze(Array.from(e))}async function Nn(e,n,t,i){if(n.pinnedFiles!==void 0){let s=n.pinnedFiles.get(t);if(s===void 0)throw new _("NOT_FOUND");if(s.byteLength>i)throw new _("LIMIT_EXCEEDED");return new Uint8Array(s)}let r=`${n.relativePath}/${t}`,o=n.scanContext,a=e.fingerprintVerifiedFile;if(o===void 0||!o.cacheable||typeof a!="function")return fr(e,n.root,r,i);try{let s=o.priorFingerprints.get(r)??await a.call(e,o.workspaceRoot,r,i);o.candidateRealPath=s.candidateRealPath;let c=await fr(e,n.root,r,i),d=await a.call(e,o.workspaceRoot,r,i);return o.candidateRealPath=d.candidateRealPath,Er(s,d)&&d.size===BigInt(c.byteLength)&&!Dr(d,o.scanStartedAtNs)?o.files.set(r,{relativePath:r,byteLimit:i,fingerprint:d}):o.cacheable=!1,c}catch(s){let c=!t.includes("/")&&ne(s)==="NOT_FOUND"&&o.directoryListings.some(l=>l.relativePath===n.relativePath&&!nt(l.key,t)),d=t===K&&ne(s)==="NOT_FOUND"&&Pd(o.directoryListings,n.relativePath);throw !c&&!d&&(o.cacheable=false),s}}async function bd(e,n,t){if(n.pinnedFiles!==void 0)return {iconDiagnostics:[]};let i=await zt(t,async o=>{try{return await Nn(e,n,o,262144)}catch(a){let s=ne(a);return s==="NOT_FOUND"?"missing":s==="LIMIT_EXCEEDED"?"too-large":"bad-path"}}),r=i.file;return {...r===void 0?{}:{iconFile:{path:r.path,sha256:crypto.createHash("sha256").update(r.bytes).digest("hex"),contentType:r.contentType,byteLength:r.byteLength}},iconDiagnostics:i.diagnostics}}function Pd(e,n){let t=e.find(r=>r.relativePath===n);if(t===void 0)return false;if(!nt(t.key,"dist"))return true;let i=e.find(r=>r.relativePath===`${n}/dist`);return i!==void 0&&!nt(i.key,"tools.json")}function Tr(e,n){return JSON.stringify([e.realPath,n.source,n.relativePath])}async function Md(e,n,t,i,r,o,a,s){let c=e.fingerprintVerifiedFile,d=Tr(t,i),l=r.candidates.get(d),p=i.relativePath,u;try{u=await ur(e,n,p);}catch(S){if(ne(S)!=="NOT_FOUND")throw S}let A=u===void 0?void 0:{relativePath:p,key:u};if(A!==void 0&&(i.source==="apps"||i.source==="skills")&&!pe.some(S=>nt(A.key,S)))return be(a,s)?l!==void 0&&l.candidate===void 0&&l.candidateRealPath===void 0&&l.files.length===0&&l.directoryListings.length===1&&l.directoryListings[0]?.relativePath===A.relativePath&&l.directoryListings[0]?.key===A.key&&(i.source==="apps"?l.diagnostic?.code==="MANIFEST_MISSING":l.diagnostic===void 0)&&typeof c=="function"?{memo:l}:typeof c!="function"?{}:{context:{state:r,cacheKey:d,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze([A]),priorFingerprints:new Map,files:new Map,cacheable:true}}:{timeLimitReached:true};let I=async S=>{if(S==="")return A;let y=`${i.relativePath}${S}`;try{let m=await ur(e,n,y);return m===void 0?void 0:{relativePath:y,key:m}}catch(m){if(ne(m)==="NOT_FOUND")return;throw m}},h=await Promise.all(pr.map(I)),N=await Promise.all(Sd.map(I));if(!be(a,s))return {timeLimitReached:true};let F=typeof c=="function"&&h.every(S=>S!==void 0),v=h.filter(S=>S!==void 0),b=[...v,...N.filter(S=>S!==void 0)],C=new Map,G=l!==void 0&&F,D;if(l!==void 0&&typeof c=="function"){let S=await Promise.all(l.files.map(async y=>{if(!be(a,s))return {kind:"time",file:y};try{let m=await c.call(e,n,y.relativePath,y.byteLimit);return {kind:"fingerprint",file:y,current:m}}catch(m){return ne(m)==="NOT_FOUND"?{kind:"missing",file:y}:{kind:"error",file:y,error:m}}}));if(S.some(y=>y.kind==="time"))return {timeLimitReached:true};for(let y of S){if(y.kind==="error")throw y.error;if(y.kind==="missing"){G=false;continue}if(y.kind!=="fingerprint")continue;let{file:m,current:E}=y;C.set(m.relativePath,E),D??=E.candidateRealPath,(E.candidateRealPath!==l.candidateRealPath||!Er(E,m.fingerprint)||Dr(E,o))&&(G=false);}}let M=l!==void 0&&l.directoryListings.length===b.length&&l.directoryListings.every((S,y)=>S.relativePath===b[y]?.relativePath&&S.key===b[y]?.key);return l!==void 0&&F&&M&&G&&D===l.candidateRealPath?{memo:l}:!F||v.length!==pr.length?{}:{context:{state:r,cacheKey:d,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze(b),priorFingerprints:C,files:new Map,...D===void 0?{}:{candidateRealPath:D},cacheable:true}}}function nt(e,n){try{let t=JSON.parse(e);return Array.isArray(t)&&t.some(i=>Array.isArray(i)&&i[0]===n)}catch{return true}}async function ur(e,n,t){let i=Nr(e);if(typeof i!="function")return;let r=await i.call(e,n,t);if(!Array.isArray(r)||r.some(a=>typeof a=="string"))return;let o=r.map(Ir);if(!o.some(a=>a===null))return JSON.stringify(o.slice().sort((a,s)=>Dn(a.name,s.name)||Dn(a.kind,s.kind)).map(a=>[a.name,a.kind]))}function Er(e,n){return e.dev===n.dev&&e.ino===n.ino&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}function Dr(e,n){let t=e.mtimeNs-n;return t>=-lr&&t<=lr}function ui(e){let n=e.scanContext,t=e.source==="skills"&&e.candidate===void 0&&e.diagnostic===void 0&&n?.files.size===0,i=e.source==="apps"&&e.candidate===void 0&&e.diagnostic?.code==="MANIFEST_MISSING"&&n?.files.size===0,r=t||i;if(n===void 0||!n.cacheable||n.candidateRealPath===void 0&&!r||n.files.size===0&&!r)return;let o=Object.freeze({...!r&&n.candidateRealPath!==void 0?{candidateRealPath:n.candidateRealPath}:{},directoryListings:n.directoryListings,files:Object.freeze([...n.files.values()]),...e.candidate===void 0?{}:{candidate:e.candidate},...e.diagnostic===void 0?{}:{diagnostic:e.diagnostic},...e.identity===void 0?{}:{identity:e.identity},...e.provenance===void 0?{}:{provenance:e.provenance}});n.state.candidates.set(n.cacheKey,o);}function Ld(e,n,t){let i=crypto.createHash("sha256"),r=new TextEncoder().encode(Z(e)),o=a=>{let s=new Uint8Array(8);new DataView(s.buffer).setBigUint64(0,BigInt(a)),i.update(s);};return o(r.byteLength),i.update(r),o(n.byteLength),i.update(n),o(t.byteLength),i.update(t),i.digest("hex")}function Od(e,n){let t={...e.definition,sourceHash:n},i;try{i=ie(t);}catch(o){throw o instanceof R&&o.code==="INPUT_INVALID"?new oe("MANIFEST_INVALID","normalized definition is invalid"):o}let r={...t,hash:i};try{ce(r);}catch{throw new oe("MANIFEST_INVALID","normalized definition is invalid")}return r}function Rd(e,n){return e.actions.some(t=>t.backend.type==="core"&&t.backend.handler!=="state.set"&&!Bn(n,t.backend))}function Ud(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function Nr(e){if(typeof e.listDirectory=="function")return e.listDirectory;if(typeof e.readDirectory=="function")return e.readDirectory;if(typeof e.readdir=="function")return e.readdir}async function fr(e,n,t,i){let r=Ud(e);if(!r)throw new _("READ_DENIED");return gd(await r.call(e,n,t,i))}async function Cd(e,n,t){let i=Nr(e);if(!i)throw new _("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new _("READ_DENIED");return r.map(Ir).filter(o=>o!==null)}function kd(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(yr(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(yr(e.builtinCatalog)),n.push({...e.reservedAppIds===void 0?{}:{appIds:e.reservedAppIds},...e.reservedDefinitionIds===void 0?{}:{definitionIds:e.reservedDefinitionIds},...e.reservedToolNames===void 0?{}:{toolNames:e.reservedToolNames}}),n}function yr(e){let n=[],t=[],i=[];for(let r of e.listMcpApps())typeof r.appId=="string"&&n.push(r.appId),r.definition&&typeof r.definition.id=="string"&&t.push(r.definition.id);for(let r of e.listMcpAppTools())typeof r.name=="string"&&i.push(r.name);return {appIds:n,definitionIds:t,toolNames:i}}function ye(e,n){e.diagnostic||(e.diagnostic=et(n,e.source,e.relativePath,e.identity?.pluginId));}function wd(e,n){let t=new Set,i=new Map;for(let o of e){let a=o.identity?.pluginId;if(a===void 0)continue;let s=i.get(a)??[];s.push(o),i.set(a,s);}for(let o of i.values()){if(o.length<2)continue;let a=o.filter(c=>c.provenance!==void 0);if(a.length>0){let c=o.find(d=>n.has(d));if(c){for(let d of a)t.add(d);for(let d of o)d!==c&&d.provenance===void 0&&ye(d,"RESERVED_ID");continue}for(let d of o)d.provenance===void 0&&ye(d,"RESERVED_ID");if(a.length>1)for(let d of a)ye(d,"DUPLICATE_ID");continue}let s=o.filter(c=>c.source==="apps");if(s.length>1){for(let c of s)ye(c,"DUPLICATE_ID");for(let c of o.filter(d=>d.source==="skills"))ye(c,"DUPLICATE_ID");}else for(let c of o.filter(d=>d.source==="skills"))ye(c,"DUPLICATE_ID");}let r=new Map;for(let o of e){if(o.diagnostic?.code==="RESERVED_ID"||t.has(o)||o.provenance===void 0&&!n.has(o)&&i.get(o.identity?.pluginId??"")?.some(c=>c.provenance!==void 0))continue;let a=o.identity?.definitionKey;if(a===void 0)continue;let s=r.get(a)??[];s.push(o),r.set(a,s);}for(let o of r.values())if(o.length>1)for(let a of o)ye(a,"DUPLICATE_ID");return t}function xd(e,n,t){let i=new Set,r=new Set,o=new Set,a=new Set([...t.appIds,...n.productBundleReservationMetadata?.reservedAppIds??[]]),s=new Set([...t.definitionIds,...n.productBundleReservationMetadata?.reservedDefinitionIds??[]]);for(let l of kd(n)){for(let p of l.appIds??[])typeof p=="string"&&i.add(p);for(let p of l.definitionIds??[])typeof p=="string"&&r.add(p);for(let p of l.toolNames??[])typeof p=="string"&&o.add(p);}for(let l of e){let p=l.candidate;if(!p)continue;if(i.has(p.pluginId)||r.has(p.definitionId)){ye(l,"RESERVED_ID");continue}[p.toolNames.read,p.toolNames.action].filter(A=>A!==void 0).some(A=>o.has(A))&&ye(l,"DUPLICATE_ID");}let c=[...e.filter(l=>l.provenance!==void 0&&l.diagnostic===void 0).flatMap(l=>l.candidate?[l.candidate]:[]),...(n.productBundleReservationMetadata?.candidates??[]).filter(l=>n.productBundleReservationMetadata?.indexHash!==void 0&&l.provenance?.indexHash===n.productBundleReservationMetadata.indexHash)],d=new Set;for(let l of e){let p=l.candidate;if(!(!p||l.diagnostic||l.source!=="apps"||l.provenance!==void 0)&&e.filter(u=>u.source==="apps"&&u.identity?.pluginId===p.pluginId).length===1&&c.some(u=>u.pluginId===p.pluginId)&&!(s.has(p.definitionId)&&!c.some(u=>u.pluginId===p.pluginId&&u.definitionId===p.definitionId))&&!c.some(u=>u.pluginId!==p.pluginId&&u.definitionId===p.definitionId)&&!e.some(u=>u.identity?.pluginId!==p.pluginId&&u.identity?.definitionKey===`${p.definitionId}\0${p.version}`&&u.diagnostic?.code!=="RESERVED_ID"))try{Ho(p),d.add(l);}catch(u){ye(l,u instanceof _e?_r(u.code):"EXEC_DENIED");}}for(let l of e){let p=l.candidate;p&&l.provenance===void 0&&!d.has(l)&&(a.has(p.pluginId)||s.has(p.definitionId))&&ye(l,"RESERVED_ID");}return d}function vd(e){return [...e].sort((n,t)=>{let i=or.indexOf(n.source)-or.indexOf(t.source);return i!==0?i:Dn(n.relativePath,t.relativePath)})}function j(e,n,t){e.diagnostic=et(n,e.source,e.relativePath,e.identity?.pluginId,t);}async function Ar(e,n,t){let i=Ft(t,{mode:"local"});if(!i.ok&&i.parseFailure){j(n,cr(i.rejection.code),ar(i.rejection));return}let r=hd(i.identity);if(n.bundleIdentity===void 0)n.identity=r;else if(r?.pluginId!==n.bundleIdentity.appId||r.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){j(n,"BUNDLE_INTEGRITY");return}if(!i.ok&&i.builtinOnly){j(n,"RESERVED_ID");return}if(!i.ok){j(n,cr(i.rejection.code),ar(i.rejection));return}let o=i.manifest,a={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=a),o.actions.length>0)try{Yt(o.actions.map(O=>({actionId:O.actionId,inputSchema:O.inputSchema})));}catch(O){if(O instanceof _e){j(n,_r(O.code));return}throw O}let s;try{s=await Nn(e,n,"ui/index.html",Ke);}catch(O){j(n,Ve(ne(O),"entry"));return}if(s.byteLength>Ke){j(n,"LIMIT_EXCEEDED");return}let c;try{c=gr(s);}catch{j(n,"ENTRY_INVALID");return}if(s.byteLength===0||c.length===0){j(n,"ENTRY_INVALID");return}let d=crypto.createHash("sha256").update(s).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==d){j(n,"ENTRY_INVALID");return}let l={},p,u;if(o.initialState!==void 0){try{p=await Nn(e,n,"ui/state.json",2097152);}catch(O){j(n,Ve(ne(O),"initial"));return}if(p.byteLength>2097152){j(n,"LIMIT_EXCEEDED");return}try{let O=md(p),q=o.dataPaths??[],B=Rt(O,q);l=ae(B,0,q),He(l);}catch{j(n,"INITIAL_STATE_INVALID");return}if(u=crypto.createHash("sha256").update(p).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==u){j(n,"INITIAL_STATE_INVALID");return}}let A={...o,entryHash:d,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:u}}},I=an(A),h=Ld(A,s,p??new Uint8Array),N;try{N=Od(I,h);}catch(O){if(O instanceof oe){j(n,_d(O));return}throw O}let F;if(n.bundleLineage!==void 0){let O=n.bundleLineage[n.bundleLineage.length-1];if(!O){j(n,"LINEAGE_INVALID");return}let{legacy:q,...B}=O.definition,{hash:Pe,...ot}=N;if(Z(B)!==Z(ot)){j(n,"LINEAGE_STALE");return}if(q!==void 0&&(N={...N,legacy:q}),q!==void 0)try{N={...N,hash:ie(N)},ce(N);}catch{j(n,"LINEAGE_INVALID");return}F=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){j(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==N.id||n.bundleIdentity.version!==N.version||n.bundleIdentity.definitionHash!==N.hash)){j(n,"LINEAGE_STALE");return}let v=await bd(e,n,i.mcpb?.icon),b=yi(o.pluginId),C=o.actions.length===0?{read:b.read}:b,G=je(I),D=je(A),M=je(N),S=je({...I.handlers}),y=dr(s),m=p===void 0?void 0:dr(p),E=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:d,bytes:y}),...m===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:u,bytes:m})}}),P={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,...i.releaseVersion===void 0?{}:{releaseVersion:i.releaseVersion},manifestFile:i.file,...i.mcpb===void 0?{}:{mcpb:je(i.mcpb)},relativePath:n.relativePath,manifest:D,normalized:G,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},...v.iconFile===void 0?{}:{iconFile:Object.freeze({...v.iconFile})},...v.iconDiagnostics.length===0?{}:{iconDiagnostics:Object.freeze([...v.iconDiagnostics])},definition:M,handlers:S,resources:E,html:c,entryBytes:y,entryHash:d,initialState:je(l),...m===void 0?{}:{initialStateBytes:m},...u===void 0?{}:{initialStateHash:u},sourceHash:h,toolNames:Object.freeze(C)},L=n.provenance===void 0?{...P,source:n.source}:{...P,provenance:n.provenance,lineage:F??[]};n.candidate=Object.freeze(L),Rd(o,N.usage)&&j(n,"EXEC_DENIED");}async function br(e,n){let t={};for(let i of pe)try{t[i]=await Nn(e,n,i,262144);}catch(r){if(ne(r)==="NOT_FOUND")continue;return {files:t,failure:Ve(ne(r),"manifest")}}if(t[X]!==void 0)try{t[K]=await Nn(e,n,K,262144);}catch(i){if(ne(i)!=="NOT_FOUND")return {files:t,failure:Ve(ne(i),"manifest")}}return {files:t}}function fi(e){return pe.some(n=>e[n]!==void 0)}async function jd(e,n){let{files:t,failure:i}=await br(e,n);if(i!==void 0){j(n,i);return}let r=t[X];return r!==void 0&&!Vt(r)&&(delete t[X],delete t[K]),fi(t)?t:void 0}function Vd(e,n,t,i=dd,r=false,o=new Set){let a=vd(e),s=wd(a,o),c=Object.freeze(a.filter(u=>u.candidate!==void 0&&u.diagnostic===void 0&&!s.has(u)).map(u=>u.candidate)),d=Object.freeze(a.filter(u=>u.diagnostic!==void 0).map(u=>u.diagnostic)),l=r?Object.freeze({...t===void 0?{}:{indexHash:t},candidates:Object.freeze(a.filter(u=>u.source==="bundled"&&u.diagnostic===void 0&&t!==void 0&&u.candidate?.provenance?.indexHash===t).map(u=>u.candidate)),diagnostics:Object.freeze(d.filter(u=>u.source==="bundled").map(u=>Object.freeze({...u}))),reservedAppIds:Object.freeze([...i.appIds]),reservedDefinitionIds:Object.freeze([...i.definitionIds])}):void 0,p={apps:c,diagnostics:d,complete:n===void 0,...n===void 0?{}:{incompleteReason:n},...t===void 0?{}:{productBundleIndexHash:t},...l===void 0?{}:{productBundleSnapshotMetadata:l}};return Object.defineProperty(p,"candidates",{configurable:false,enumerable:false,get:()=>c}),Object.freeze(p)}function Fd(e){if(e===null||typeof e!="object"&&typeof e!="function")return false;let n=e;return typeof n.readVerifiedFile=="function"||typeof n.readFileVerified=="function"||typeof n.listDirectory=="function"||typeof n.readDirectory=="function"||typeof n.readdir=="function"}function Bd(e,n){if(Fd(e))return {fs:e,options:n??{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??Zn,options:t}}async function Ai(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:r}=Bd(n,t),o=r.clock??Nd,a=o(),s=await ir(r.productBundle,i,a,o),c=o(),d=BigInt(Date.now())*1000000n,l=[],p=0,u,A=false,I,h;if(r.scanCache!==void 0&&typeof i.getRootIdentity=="function"&&typeof i.fingerprintVerifiedFile=="function")try{h=await i.getRootIdentity(e),I=$o(r.scanCache,h),I.scanStartedAtNs=d;}catch(D){if(ne(D)!=="NOT_FOUND")throw D}let N=I!==void 0&&r.productBundle===void 0&&s.packages.length===0&&s.diagnostics.length===0,F=new Set,v=true;l.push(...s.diagnostics.map(D=>({source:D.source,root:r.productBundle?.root??e,name:"",relativePath:D.relativePath,diagnostic:D})));let b=s.reservedIds;s.incomplete&&(u="time_limit");for(let D of s.packages){if(!be(c,o)){A=true,u="time_limit";break}let M=D.indexEntry,S=M.packageDir,y=D.files===void 0?void 0:Ed(S,D.files),m=s.indexHash===void 0?void 0:go(Object.freeze({kind:"bundled",launcher:M.launcher!==false,indexHash:s.indexHash,packageDir:S,appId:M.appId,definitionId:M.definition.id,version:M.definition.version,definitionHash:M.definition.hash,files:M.files}),y),E={source:"bundled",root:r.productBundle?.root??e,name:S.slice(5),relativePath:S,...m===void 0?{}:{provenance:m},...D.files===void 0?{}:{pinnedFiles:D.files},...D.lineage===void 0?{}:{bundleLineage:D.lineage},bundleIdentity:{appId:M.appId,definitionId:M.definition.id,version:M.definition.version,definitionHash:M.definition.hash},identity:Td(M)};if(l.push(E),p+=1,D.failureCode!==void 0){j(E,D.failureCode);continue}if(D.files?.has(K)===true){j(E,"EXEC_DENIED",{reason:{path:"",rule:"bundled-tool-mode-unsupported",file:K}});continue}let P={};for(let L of pe){let O=D.files?.get(L);O!==void 0&&(P[L]=O);}if(!fi(P)){j(E,"BUNDLE_INTEGRITY");continue}if(await Ar(i,E,P),!be(c,o)){A=true,u="time_limit";break}}let C=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];e:for(let D of C){let{source:M,directory:S}=D,y;try{y=await Cd(i,e,S);}catch(E){if(ne(E)==="NOT_FOUND")continue;N=false,v=false,l.push({source:M,root:e,name:"",relativePath:M,diagnostic:et(Ve(ne(E),"manifest"),M,M)});continue}let m=y.filter(E=>E.kind==="directory"||E.kind==="symlink").filter(E=>Id(E.name)).map(E=>({source:M,root:e,name:E.name,relativePath:Ad(M,E.name)})).sort((E,P)=>Dn(E.relativePath,P.relativePath));for(let E of m){let P={...E};if(l.push(P),h!==void 0?F.add(Tr(h,P)):N=false,!be(c,o)){A=true,u="time_limit";break e}let L;if(I!==void 0&&h!==void 0){try{let B=await Md(i,e,h,P,I,d,c,o);if(B.timeLimitReached){A=!0,u="time_limit";break e}P.scanContext=B.context,L=B.memo;}catch(B){N=false,j(P,Ve(ne(B),"manifest"));continue}L===void 0&&(N=false);}if(L!==void 0){if(P.candidate=L.candidate,P.diagnostic=L.diagnostic,P.identity=L.identity,M==="skills"&&L.candidate===void 0&&L.diagnostic===void 0)continue;if(p>=64){j(P,"LIMIT_EXCEEDED");continue}if(E.relativePath.split("/").length-1>2){j(P,"LIMIT_EXCEEDED");continue}if(p+=1,!be(c,o)){A=true,u="time_limit";break e}continue}let O;if(M==="skills"&&(O=await jd(i,P),O===void 0)){P.diagnostic===void 0&&ui(P);continue}if(p>=64){j(P,"LIMIT_EXCEEDED");continue}if(E.relativePath.split("/").length-1>2){j(P,"LIMIT_EXCEEDED");continue}if(!be(c,o)){A=true,u="time_limit";break e}if(p+=1,O===void 0){let B=await br(i,P);if(B.failure!==void 0||!fi(B.files)){j(P,B.failure??Ve("NOT_FOUND","manifest")),ui(P);continue}O=B.files;}if(await Ar(i,P,O),ui(P),!be(c,o)){A=true,u="time_limit";break e}}}if(I!==void 0&&h!==void 0){let D=[...F].sort(Dn),M=I.lastCandidateKeys,S=M!==void 0&&M.length===D.length&&M.every((m,E)=>m===D[E]);if(N=N&&S,v&&!A&&u===void 0)for(let m of I.candidates.keys())try{JSON.parse(m)[0]===h.realPath&&!F.has(m)&&I.candidates.delete(m);}catch{I.candidates.delete(m);}let y=[...I.candidates.keys()].filter(m=>{try{return JSON.parse(m)[0]===h.realPath}catch{return false}});N=N&&y.length===F.size&&y.every(m=>F.has(m))&&!A&&u===void 0,I.lastCandidateScanUnchanged=N,v&&!A&&u===void 0&&(I.lastCandidateKeys=Object.freeze(D));}A&&l.push({source:"apps",root:e,name:"",relativePath:"apps",diagnostic:et("DISCOVERY_TIME_LIMIT","apps","apps")});let G=xd(l,r,b);return Vd(l,u,s.indexHash,b,r.productBundle!==void 0,G)}var dd,Qe,ld,ud,or,yd,pr,Sd,lr,Hd,zd,Sr=w(()=>{g();Ue();bn();Ee();fo();Gt();Re();Wn();zo();Hn();Vn();Jo();ri();Fn();li();li();dd=Tn([]);Qe="crewx_local_app_",ld=Qe,ud=Qe;or=["bundled","apps","skills"],yd=new TextDecoder("utf-8",{fatal:true});pr=["","/ui"],Sd=["/dist"],lr=2000000000n;Hd=Ai,zd=Ai;});g();var Mr="SKILL.md",Xd=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function Lr(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Kd(e){return e.isDirectory()||e.isSymbolicLink()}function Ur(e){try{return fs$1.existsSync(e)&&fs$1.statSync(e).isDirectory()}catch{return false}}var Yd=["index.js","main.js"];function rf(e,n){let t=path.join(e,"package.json");if(fs$1.existsSync(t))try{let r=JSON.parse(fs$1.readFileSync(t,"utf8"));if(r.bin){let o=typeof r.bin=="string"?r.bin:Object.values(r.bin).find(a=>typeof a=="string");if(o){let a=path.resolve(e,o);if(fs$1.existsSync(a))return a}}if(typeof r.main=="string"){let o=path.resolve(e,r.main);if(fs$1.existsSync(o))return o}}catch{}let i=path.resolve(e,`${n}.js`);if(fs$1.existsSync(i))return i;for(let r of Yd){let o=path.resolve(e,r);if(fs$1.existsSync(o))return o}}function qd(e){let n;try{n=fs$1.readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(Xd);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=jsYaml.load(t[1]??"");if(!Lr(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let r=Lr(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(r?.version??i.version)=="string"?{version:r?.version??i.version}:{},...typeof i.description=="string"?{description:i.description}:{}},readable:!0,valid:!0,hasFrontmatter:!0}}catch{return {frontmatter:{},readable:true,valid:false,hasFrontmatter:true}}}function Zd(e){return [path.join(e,Mr),path.join(e,"skill",Mr)]}function tt(e,n){if(!Ur(e))return null;for(let t of Zd(e)){if(!fs$1.existsSync(t))continue;let r=qd(t).frontmatter;return {name:r.name??n,...r.version===void 0?{}:{version:r.version},...r.description===void 0?{}:{description:r.description},skillMdPath:t,dir:e}}return null}function Ii(e){try{return fs$1.readdirSync(e,{withFileTypes:!0}).filter(Kd)}catch{return []}}function Qd(e){return e.length===0||/[\\\u0000]/.test(e)?false:e.split("/").every(n=>n.length>0&&n!=="."&&n!=="..")}function Or(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function it(e){let n=[],t=new Set;for(let i of e)if(Ur(i))for(let r of Ii(i)){if(r.name.startsWith("@")){let o=path.join(i,r.name);for(let a of Ii(o))Or(tt(path.join(o,a.name),a.name),t,n);continue}Or(tt(path.join(i,r.name),r.name),t,n);}return n.sort((i,r)=>i.name.localeCompare(r.name))}function ep(e,n){if(!Qd(e))throw new Error(`Skill not found: ${e}`);for(let i of n){let r=tt(path.join(i,e),e);if(r)return r;for(let o of Ii(i)){if(!o.name.startsWith("@"))continue;let a=tt(path.join(i,o.name,e),e);if(a)return a}}let t=it(n).find(i=>i.name===e);if(t)return t;throw new Error(`Skill not found: ${e}`)}async function sf(e){if(!e||e.root===null)return {skills:[],diagnostics:[]};let{discoverWorkspaceApps:n}=await Promise.resolve().then(()=>(Sr(),Pr)),t=await n(e.root,{productBundle:e}),i=[],r=new Set;for(let o of t.apps){let a=o.provenance?.kind==="bundled"?o.provenance.packageDir:void 0;if(!a)continue;let s=path.join(e.root,...a.split("/"));for(let c of it([path.dirname(s)]))path.resolve(c.dir)!==path.resolve(s)||r.has(c.name)||(r.add(c.name),i.push(c));for(let c of [path.join(s,"skill"),path.join(s,"skills")])for(let d of it([c]))r.has(d.name)||(r.add(d.name),i.push(d));}return {skills:i.sort((o,a)=>o.name.localeCompare(a.name)),diagnostics:t.diagnostics.filter(o=>o.source==="bundled")}}var af=it,cf=ep;
|
|
1
|
+
'use strict';var crypto=require('crypto'),net=require('net'),fs$1=require('fs'),promises=require('fs/promises'),path=require('path'),jsYaml=require('js-yaml');var Cr=Object.defineProperty;var w=(e,n)=>()=>(e&&(n=e(e=0)),n);var kr=(e,n)=>{for(var t in n)Cr(e,t,{get:n[t],enumerable:true});};var g=w(()=>{});var R,bn=w(()=>{g();R=class extends Error{constructor(t,i=t,r){super(i);this.code=t;this.currentRevision=r;}code;currentRevision;name="UiRuntimeError"};});function at(e){return wr.test(e)||xr.test(e)}function se(){throw new R("INPUT_INVALID","JSON value is not projection-safe")}function Fr(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function rt(e,n,t,i,r,o){if(n>i&&se(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(vr.test(e)||Vr.test(e)&&!zr(r,o)||jr.test(e))&&se(),e;if(typeof e=="number")return Number.isFinite(e)||se(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&se();let a=e;t.has(a)&&se(),t.add(a);try{if(Array.isArray(e))return e.map(c=>rt(c,n+1,t,i,r,o));Fr(a)||se();let s={};for(let[c,d]of Object.entries(e))at(c)&&se(),s[c]=rt(d,n+1,t,i,[...r,c],o);return s}finally{t.delete(a);}}function ae(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>Hr)&&se(),(!Array.isArray(t)||t.some(r=>typeof r!="string"))&&se();let i=rt(e,0,new Set,Br+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&se(),i}function Be(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((r,o)=>t[o]===r)}function zr(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>Be(t,i))}function He(e){try{let n=JSON.stringify(e);return n===void 0&&se(),n}catch{se();}}function st(e){return Array.isArray(e)?e.map(st):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,st(e[n])])):e}function Z(e){return He(st(e))}function ct(e){return Buffer.byteLength(e,"utf8")}var wr,xr,vr,jr,Vr,Br,Hr,Ee=w(()=>{g();bn();wr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,xr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,vr=/<\/?[A-Za-z][^>]*>/,jr=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Vr=/^(?:https?|file|ftp|ws|wss):\/\//i;Br=8,Hr=4;});var Pn,dt=w(()=>{g();Pn=["text/plain","application/json"];});var gi=w(()=>{g();dt();});function ze(e){return $r.has(e)||Jr.test(e)||Wr.test(e)}var mi,$r,Jr,Wr,Sn,nn,Ie,pt,lt,ut,ft,yt,Re=w(()=>{g();mi=["__proto__","prototype","constructor","proof","token","secret","password","cookie","authorization","private_key","private-key","stack","exception","plugin_text","url","uri","endpoint","path","filename","filepath","cwd","shell","directory","dir","folder"],$r=new Set(mi),Jr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Wr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;Sn=/^[A-Za-z0-9_]+$/,nn=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,Ie=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,pt=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,lt=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,ut=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,ft=["blue","violet","emerald","amber","rose","sky","slate","indigo"],yt=["inline","panel"];});function At(e){return typeof e=="string"&&Pn.includes(e)}var hi=w(()=>{g();dt();Re();});function Mn(e){if(!It(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Xr(e.in)||Object.hasOwn(e,"out")&&!Kr(e.out))}function Xr(e){return It(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&At(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function Kr(e){return It(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&At(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function It(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var gt=w(()=>{g();gi();hi();new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});});function On(e){return Yr.includes(e)}function Rn(e){return Number.isSafeInteger(e)&&e>=Ln.min&&e<=Ln.max}var Yr,Ln,_i,mt=w(()=>{g();Yr=[5,15,30,60],Ln=Object.freeze({min:15e3,max:6e5,default:3e5}),_i=1;});function ie(e){let t=e.renderer!==void 0||e.surfaces!==void 0||e.stateProjection!==void 0||e.dataPaths!==void 0||e.usage!==void 0||e.detailPanel!==void 0||e.displayModes!==void 0||e.summaryProjection!==void 0||e.legacy!==void 0||Object.values(e.actions).some(r=>r.resultProjection!==void 0)?{id:e.id,version:e.version,...e.renderer===void 0?{}:{renderer:e.renderer},...e.surfaces===void 0?{}:{surfaces:e.surfaces},...e.stateProjection===void 0?{}:{stateProjection:e.stateProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.legacy===void 0?{}:{legacy:e.legacy},...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},actions:e.actions}:e.sourceHash===void 0?{id:e.id,version:e.version,actions:e.actions}:{id:e.id,version:e.version,sourceHash:e.sourceHash,actions:e.actions},i=ae(t);return crypto.createHash("sha256").update(Z(i)).digest("hex")}function _t(e){return `${e.id}\0${e.version}`}function ce(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new R("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!Zr.test(e.sourceHash)))throw new R("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||ie(e)!==e.hash)throw new R("DEFINITION_UNSUPPORTED","UI definition hash is invalid");for(let[n,t]of Object.entries(e.actions)){if(!n||!Array.isArray(t.capabilities)||t.capabilities.some(i=>!es(i)))throw new R("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new R("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new R("DEFINITION_UNSUPPORTED","UI action input declaration is invalid");if(t.dataInputs!==void 0&&(!Array.isArray(t.dataInputs)||new Set(t.dataInputs).size!==t.dataInputs.length||t.dataInputs.some(i=>typeof i!="string"||!i||t.inputKeys!==void 0&&!t.inputKeys.includes(i))))throw new R("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");if(t.resultProjection&&ht(t.resultProjection),t.schedule!==void 0&&(!On(t.schedule.everyMinutes)||!Rn(t.schedule.timeoutMs)))throw new R("DEFINITION_UNSUPPORTED","UI action schedule declaration is invalid");if(t.content!==void 0&&!Mn(t.content))throw new R("DEFINITION_UNSUPPORTED","UI action content declaration is invalid");if(t.env!==void 0&&(!Array.isArray(t.env)||t.env.length===0||new Set(t.env).size!==t.env.length||t.env.some(i=>i!=="CREWX_APP_INSTANCE_ID"&&i!=="CREWX_THREAD_ID")))throw new R("DEFINITION_UNSUPPORTED","UI action environment declaration is invalid")}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new R("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new R("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new R("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new R("DEFINITION_UNSUPPORTED","UI definition detailPanel is invalid");if(e.displayModes&&(!Array.isArray(e.displayModes)||e.displayModes.length===0||new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(n=>n!=="inline"&&n!=="floating"&&n!=="focused")))throw new R("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new R("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new R("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&ht(e.stateProjection),e.summaryProjection){ht(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new R("DEFINITION_UNSUPPORTED","UI summary projection exceeds state projection")}if(e.legacy!==void 0){if(!e.legacy||typeof e.legacy!="object"||Array.isArray(e.legacy)||Object.keys(e.legacy).some(r=>!["readTool","actionTool","hostTools","agentAccess"].includes(r)))throw new R("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[r,o]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(o!==void 0){if(Qr(o,r==="readTool"),n.has(o.name))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(o.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new R("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let r={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[o,a]of Object.entries(t)){if(!Object.hasOwn(r,o)||r[o]!==a||typeof a!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(a)||n.has(a))throw new R("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");n.add(a);}}let i=e.legacy.agentAccess;if(i!==void 0&&(!i||typeof i!="object"||Array.isArray(i)||Object.entries(i).some(([r,o])=>!r||!Object.hasOwn(e.actions,r)||o!=="allowed"&&o!=="denied")))throw new R("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new R("DEFINITION_UNSUPPORTED","UI legacy action tool requires its complete agent access map")}if(e.dataPaths!==void 0){let n=new Set(["__proto__","prototype","constructor"]);if(!Array.isArray(e.dataPaths)||e.dataPaths.length>16||new Set(e.dataPaths).size!==e.dataPaths.length||e.dataPaths.some(t=>typeof t!="string"||!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(t)||t.split(".").some(i=>n.has(i))||!(e.stateProjection?.allow??[]).some(i=>Be(t,i))))throw new R("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Qr(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],r=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(o=>!i.includes(o)&&!(n&&o==="fixedResult"))||i.some(o=>!Object.hasOwn(t,o))||typeof t.name!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t.name)||typeof t.description!="string"||t.description.trim().length===0||t.description.length>8192||typeof t.textFallback!="string"||t.textFallback.trim().length===0||t.textFallback.length>16384||!t.inputSchema||typeof t.inputSchema!="object"||Array.isArray(t.inputSchema)||!Array.isArray(t.visibility)||t.visibility.length===0||t.visibility.some(o=>o!=="model"&&o!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let o=ae(t.inputSchema);if(o.type!==void 0&&o.type!=="object")throw new Error("schema type");if(r){if(!n)throw new Error("fixed result location");let a=t.fixedResult;if(!a||typeof a!="object"||Array.isArray(a))throw new Error("fixed result");let s=a;if(Object.keys(s).sort().join(",")!=="argsPolicy,structuredContent"||s.argsPolicy!=="empty-only"&&s.argsPolicy!=="ignore"||!s.structuredContent||typeof s.structuredContent!="object"||Array.isArray(s.structuredContent))throw new Error("fixed result");let c=ae(s.structuredContent);if(ct(He(c))>4*1024)throw new Error("fixed result size")}}catch{throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function ht(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new R("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function es(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var Zr,Ue=w(()=>{g();Ee();bn();gt();mt();Zr=/^[0-9a-f]{64}$/;});var Ti=w(()=>{g();Ee();});var K,Ce,Tt=w(()=>{g();K="dist/tools.json",Ce="dist/main.mjs";});var tn,Ei=w(()=>{g();tn="window";});function Di(e){if(!Array.isArray(e)||e.length===0)return false;let n=new Set;for(let t of e){if(!ns.some(i=>i===t)||n.has(t))return false;n.add(t);}return true}var ns,Ni=w(()=>{g();ns=["CREWX_APP_INSTANCE_ID","CREWX_THREAD_ID"];});function V(e){throw new Et(e)}function fs(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function ys(e,n){let t=Object.getOwnPropertyDescriptor(e,n);return (!t||!("value"in t))&&V("CSP_ORIGIN_INVALID"),t.value}function Un(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))return [];let t=ys(e,n);Array.isArray(t)||V("CSP_ORIGIN_INVALID"),Reflect.ownKeys(t).some(o=>typeof o!="string"||o!=="length"&&!/^(?:0|[1-9][0-9]*)$/.test(o))&&V("CSP_ORIGIN_INVALID");let r=[];for(let o=0;o<t.length;o+=1)(!Object.prototype.hasOwnProperty.call(t,o)||typeof t[o]!="string")&&V("CSP_ORIGIN_INVALID"),r.push(t[o]);return Object.keys(t).length!==t.length&&V("CSP_ORIGIN_INVALID"),r}function As(e){let n;try{n=JSON.stringify(e);}catch{V("CSP_ORIGIN_INVALID");}return n===void 0&&V("CSP_ORIGIN_INVALID"),new TextEncoder().encode(n).byteLength}function Si(e,n){/\s|\\/u.test(e)&&V("CSP_ORIGIN_INVALID");let t=cs.exec(e);t||V("CSP_ORIGIN_INVALID");let i=t[1].toLowerCase(),r=t[2];(r.includes("@")||r.includes("%")||r.includes("*"))&&V("CSP_ORIGIN_INVALID"),(r.startsWith("[")?ds:ps).test(r)||V("CSP_ORIGIN_INVALID"),i==="wss"&&n!=="connectDomains"&&V("CSP_ORIGIN_INVALID");let a;try{a=new URL(e);}catch{V("CSP_ORIGIN_INVALID");}(a.protocol!==`${i}:`||a.username!==""||a.password!==""||a.search!==""||a.hash!=="")&&V("CSP_ORIGIN_INVALID");let s=a.hostname.toLowerCase();if((!s||s.includes("%"))&&V("CSP_ORIGIN_INVALID"),!s.startsWith("[")){let d=s.endsWith(".")?s.slice(0,-1):s;(d.length===0||d.length>253)&&V("CSP_ORIGIN_INVALID"),d.split(".").some(p=>p.length>63||!ls.test(p))&&V("CSP_ORIGIN_INVALID");}let c=a.origin;return (c==="null"||!c.startsWith(`${i}://`))&&V("CSP_ORIGIN_INVALID"),{origin:c,hostname:s}}function Is(e){let n=e.split(".").map(Number);return ((n[0]*256+n[1])*256+n[2])*256+n[3]}function Mi(e,n,t){let i=4294967295<<32-t>>>0;return (e&i)===(n&i)}function Ri(e){let n=Is(e);return Mi(n,3221225472,24)?n!==3221225481&&n!==3221225482:us.some(([t,i])=>Mi(n,t,i))}function gs(e){let n=e.indexOf("::"),t=(n<0?e:e.slice(0,n)).split(":").filter(Boolean),i=n<0?[]:e.slice(n+2).split(":").filter(Boolean);return (n<0?t:[...t,...Array(8-t.length-i.length).fill("0"),...i]).reduce((o,a)=>o<<16n|BigInt(Number.parseInt(a,16)),0n)}function ms(e){let n=gs(e),t=Number(n>>112n),i=Number(n>>96n&0xffffn);if(n>>32n===0xffffn){let r=Number(n&0xffffffffn);return Ri([r>>>24&255,r>>>16&255,r>>>8&255,r&255].join("."))}return t<8192||t>16383||t===8193&&i<=511||t===8193&&i===3512||t===8194||t===16383&&i<=4095}function hs(e,n){let t=e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e,i=net.isIP(t);if(i===4)return Ri(t);if(i===6)return ms(t);let r=e.toLowerCase().replace(/\.$/,"");return !r||!r.includes(".")||n.has(r)?true:as.some(o=>r===o||r.endsWith(`.${o}`))}function Li(e){return Object.freeze([...new Set(e.map(n=>n.origin))].sort())}function Oi(e){return JSON.stringify({baseUriDomains:[],connectDomains:e.connectDomains,declared:e.declared,frameDomains:e.frameDomains,resourceDomains:[]})}function Ui(e,n={}){if(e===void 0){let A=Oi({declared:false,connectDomains:[],frameDomains:[]});return Object.freeze({declared:false,connectDomains:Object.freeze([]),frameDomains:Object.freeze([]),resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:crypto.createHash("sha256").update(A,"utf8").digest("hex")})}fs(e)||V("CSP_ORIGIN_INVALID");let t=Reflect.ownKeys(e);t.some(A=>typeof A!="string")&&V("CSP_ORIGIN_INVALID"),t.some(A=>!ss.has(A))&&V("CSP_AXIS_UNKNOWN");let i=Un(e,"connectDomains"),r=Un(e,"frameDomains"),o=Un(e,"resourceDomains"),a=Un(e,"baseUriDomains");(o.length>0||a.length>0)&&V("CSP_AXIS_UNSUPPORTED"),(As(e)>is||i.length>Pi||r.length>Pi||i.length+r.length>os||[...i,...r].some(A=>new TextEncoder().encode(A).byteLength>rs))&&V("CSP_LIMIT_EXCEEDED");let c=i.map(A=>Si(A,"connectDomains")),d=r.map(A=>Si(A,"frameDomains")),l=new Set((n.runtimeHostnames??[]).map(A=>A.toLowerCase().replace(/\.$/,"")));[...c,...d].some(A=>hs(A.hostname,l))&&V("CSP_ORIGIN_FORBIDDEN");let p={declared:true,connectDomains:Li(c),frameDomains:Li(d)},u=Oi(p);return Object.freeze({...p,resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:crypto.createHash("sha256").update(u,"utf8").digest("hex")})}var is,Pi,os,rs,ss,as,cs,ds,ps,ls,us,Et,Ci=w(()=>{g();is=4096,Pi=16,os=32,rs=512,ss=new Set(["connectDomains","frameDomains","resourceDomains","baseUriDomains"]),as=["localhost","local","internal","home.arpa","test","example","invalid","onion","lan","corp","home","intranet","private","localdomain"],cs=/^(https|wss):\/\/([^/?#]+)$/i,ds=/^\[[^\]]+\](?::[0-9]+)?$/,ps=/^[^:\[\]]+(?::[0-9]+)?$/,ls=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,us=[[0,8],[1681915904,10],[167772160,8],[2130706432,8],[2851995648,16],[2886729728,12],[3221225984,24],[3227017984,24],[3232235520,16],[3323068416,15],[3325256704,24],[3405803776,24],[3758096384,4],[4026531840,4]],Et=class extends Error{constructor(t){super(t);this.code=t;}code;name="UiPluginCspNormalizationError"};});function rn(e,n){return n===void 0||n===""?e:e===""?n:n.startsWith("[")?`${e}${n}`:`${e}.${n}`}function f(e,n=e,t,i){throw new oe(e,n,t,i)}function H(e,n){try{return n()}catch(t){throw t instanceof oe?t.withPathPrefix(e):t}}function z(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function U(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Ks(e,n){let t={};for(let[i,r]of Object.entries(e))i!==n&&(t[i]=r);return t}function $(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e).find(a=>!i.has(a));r!==void 0&&f("MANIFEST_INVALID","MANIFEST_INVALID",r,"unknown-key");let o=n.find(a=>!U(e,a));o!==void 0&&f("MANIFEST_INVALID","MANIFEST_INVALID",o,"missing-key");}function xn(e,n=false,t=false,i=false){return Ds.test(e)||!i&&bs.test(e)||Ns.test(e)||t&&ki.test(e)||Ps.test(e)&&!(n&&/^\s*data:/i.test(e)&&!ki.test(e))}function wn(e,n=new Set,t=0,i=false,r=false,o=""){if(typeof e=="string"){xn(e,i,r)&&f("UNSAFE_VALUE","UNSAFE_VALUE",o,"unsafe-value");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&f("MANIFEST_INVALID","MANIFEST_INVALID",o),n.add(e);try{if(Array.isArray(e)){e.forEach((a,s)=>wn(a,n,t+1,!1,!1,rn(o,`[${s}]`)));return}z(e)||f("MANIFEST_INVALID","MANIFEST_INVALID",o);for(let[a,s]of Object.entries(e))wn(s,n,t+1,i&&t===0&&(a==="name"||a==="description"),r,rn(o,a));}finally{n.delete(e);}}}function ge(e,n){let t=e[n];return typeof t!="string"&&f("MANIFEST_INVALID"),t}function le(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&f("MANIFEST_INVALID"),i}function Dt(e){return Es.test(e)||f("MANIFEST_INVALID"),e}function Ge(e){return Ts.test(e)||f("TOKEN_INVALID"),e}function Ys(e){return zi.test(e)||f("MANIFEST_INVALID"),e}function qs(e){z(e)||f("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let r=Ys(t);z(i)||f("MANIFEST_INVALID");let o=i.type;if(o==="text"){$(i,["type","maxLength"]),n[r]={type:o,maxLength:le(i,"maxLength",1)};continue}if(o==="text-list"){$(i,["type","max","itemMaxLength"]),n[r]={type:o,max:le(i,"max",0),itemMaxLength:le(i,"itemMaxLength",1)};continue}if(o==="step-list"){$(i,["type","min","max","labelMaxLength","detailMaxLength"]);let a=le(i,"min",0),s=le(i,"max",1);a>s&&f("MANIFEST_INVALID"),n[r]={type:o,min:a,max:s,labelMaxLength:le(i,"labelMaxLength",1),detailMaxLength:le(i,"detailMaxLength",1)};continue}typeof o=="string"&&f("SCHEMA_TYPE_UNSUPPORTED"),f("MANIFEST_INVALID");}return n}function Zs(e,n,t){let i=e[n];(!i||i.type!==t)&&f("MANIFEST_INVALID");}function Cn(e,n,t){let i=ge(e,"field");return zi.test(i)||f("MANIFEST_INVALID"),Zs(n,i,t),i}function Qs(e,n){z(e)||f("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&f("MANIFEST_INVALID"),Xs.includes(t)||f("PRIMITIVE_UNKNOWN"),t){case "card-shell":return $(e,["primitive"]),{primitive:t};case "meta-banner":return $(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:Ge(ge(e,"badgeToken")),noticeToken:Ge(ge(e,"noticeToken"))};case "heading":return $(e,["primitive","field"]),{primitive:t,field:Cn(e,n,"text")};case "labeled-text":return $(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&f("MANIFEST_INVALID"),{primitive:t,titleToken:Ge(ge(e,"titleToken")),field:Cn(e,n,"text"),variant:"callout"};case "step-flow":return $(e,["primitive","titleToken","field"]),{primitive:t,titleToken:Ge(ge(e,"titleToken")),field:Cn(e,n,"step-list")};case "text-list":{$(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:Ge(ge(e,"titleToken")),field:Cn(e,n,"text-list")};return U(e,"emptyToken")&&(i.emptyToken=Ge(ge(e,"emptyToken"))),U(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&f("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return f("MANIFEST_INVALID")}function ea(e,n){return Array.isArray(e)||f("MANIFEST_INVALID"),e.map(t=>Qs(t,n))}function J(e="v2 manifest exceeds a contract limit",n,t){return f("LIMIT_EXCEEDED",e,n,t)}function de(e="initial state is not projection-safe"){return f("INITIAL_STATE_INVALID",e)}function wi(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||$s.test(e)||Js.test(e))&&f("MANIFEST_INVALID",`${n} is invalid`),(xn(e,true,true)||Ss.test(e)||Ms.test(e)||Ls.test(e))&&f("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function Nt(e,n){return (typeof e!="string"||!Ie.test(e))&&f("MANIFEST_INVALID",`${n} is invalid`),e}function na(e){return (typeof e!="string"||!pt.test(e)||e==="*"||e==="all")&&f("MANIFEST_INVALID","action capability is invalid"),e}function Gi(e){return (typeof e!="string"||!Gs.test(e))&&f("MANIFEST_INVALID","resource hash is invalid"),e}function bt(e,n=new Set,t=0,i=""){if(typeof e=="string"){e.length>4096&&J("v2 manifest string is too long",i,"string-too-long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||f("MANIFEST_INVALID","v2 manifest contains a non-finite number",i,"non-finite-number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&f("MANIFEST_INVALID","v2 manifest contains a non-JSON value",i,"non-json-value"),typeof e!="object"&&f("MANIFEST_INVALID","MANIFEST_INVALID",i),t>8&&J("v2 manifest nesting is too deep",i,"too-deep"),n.has(e)&&f("MANIFEST_INVALID","v2 manifest contains a cycle",i,"cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&J("v2 manifest array is too long",i,"array-too-long"),e.forEach((r,o)=>bt(r,n,t+1,rn(i,`[${o}]`)));return}z(e)||f("MANIFEST_INVALID","v2 manifest contains a non-plain object",i,"non-plain-object");for(let[r,o]of Object.entries(e))bt(o,n,t+1,rn(i,r));}finally{n.delete(e);}}}function $i(e){return (typeof e!="string"||e.length>4096||!nn.test(e))&&(typeof e=="string"&&e.length>4096&&J("projection path is too long"),f("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>ze(t))&&f("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function Pt(e){z(e)||f("MANIFEST_INVALID","projection policy must be an object"),$(e,["allow"]),Array.isArray(e.allow)||f("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&J("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let r=$i(i);t.has(r)&&f("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(r),n.push(r);}return {allow:n}}function ta(e,n){if(e===void 0)return;Array.isArray(e)||f("MANIFEST_INVALID","dataPaths must be an array"),e.length>Ws&&J("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let r of e){let o=$i(r);i.has(o)&&f("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(a=>Be(o,a))||f("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(o),t.push(o);}return t}function $e(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&f("MANIFEST_INVALID",`${n} is invalid`),e}function xi(e,n){return (typeof e!="number"||!Number.isFinite(e))&&f("MANIFEST_INVALID",`${n} is invalid`),e}function St(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||xn(e))&&f("UNSAFE_VALUE","schema enum contains an unsafe string"),e;if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||f("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&J("schema enum is too deep"),t.has(e)&&f("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&J("schema enum array is too long"),e.map(r=>St(r,n+1,t));z(e)||f("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[r,o]of Object.entries(e))ze(r)&&f("MANIFEST_INVALID","schema enum contains a reserved key"),i[r]=St(o,n+1,t);return i}finally{t.delete(e);}}function ia(e,n){if(e===void 0)return;Array.isArray(e)||f("MANIFEST_INVALID","schema required must be an array"),e.length>64&&J("schema required list is too long");let t=[],i=new Set;for(let r of e)(typeof r!="string"||!nn.test(r))&&f("MANIFEST_INVALID","schema required contains an invalid key"),r.length>4096&&J("schema required key is too long"),i.has(r)&&f("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,r)&&f("MANIFEST_INVALID","schema required references an undeclared property"),i.add(r),t.push(r);return t}function oa(e,n){let t=n?nn:Sn;return e.length>4096&&J("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>ze(i)))&&f("MANIFEST_INVALID","schema property name is invalid"),e}function Mt(e,n=0,t=false){z(e)||f("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&J("action inputSchema is too deep");let i=e.type;i!=="object"&&i!=="string"&&i!=="number"&&i!=="integer"&&i!=="boolean"&&i!=="array"&&i!=="null"&&(typeof i=="string"&&f("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),f("MANIFEST_INVALID","action inputSchema type is required"));let r=["type","enum"];i==="string"&&r.push("minLength","maxLength"),i==="array"&&r.push("minItems","maxItems","items"),i==="object"&&r.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&r.push("minimum","maximum"),$(e,["type"],r.filter(s=>s!=="type"));let o={type:i};if(U(e,"enum")&&(Array.isArray(e.enum)||f("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&J("schema enum is too long"),o.enum=e.enum.map(s=>St(s))),i==="string"&&(U(e,"minLength")&&(o.minLength=$e(e.minLength,"schema minLength",4096)),U(e,"maxLength")&&(o.maxLength=$e(e.maxLength,"schema maxLength",4096)),o.minLength!==void 0&&o.maxLength!==void 0&&o.minLength>o.maxLength&&f("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(U(e,"minimum")&&(o.minimum=xi(e.minimum,"schema minimum")),U(e,"maximum")&&(o.maximum=xi(e.maximum,"schema maximum")),o.minimum!==void 0&&o.maximum!==void 0&&o.minimum>o.maximum&&f("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(U(e,"minItems")&&(o.minItems=$e(e.minItems,"schema minItems",128)),U(e,"maxItems")&&(o.maxItems=$e(e.maxItems,"schema maxItems",128)),o.minItems!==void 0&&o.maxItems!==void 0&&o.minItems>o.maxItems&&f("MANIFEST_INVALID","schema array length bounds are inverted"),U(e,"items")&&(o.items=Mt(e.items,n+1,false))),i==="object"){let s;if(U(e,"properties")){z(e.properties)||f("MANIFEST_INVALID","schema properties must be an object");let d=Object.entries(e.properties);d.length>64&&J("schema properties are too many"),s={};for(let[l,p]of d){let u=oa(l,t);s[u]=Mt(p,n+1,false);}o.properties=s;}U(e,"minProperties")&&(o.minProperties=$e(e.minProperties,"schema minProperties",64)),U(e,"maxProperties")&&(o.maxProperties=$e(e.maxProperties,"schema maxProperties",64)),o.minProperties!==void 0&&o.maxProperties!==void 0&&o.minProperties>o.maxProperties&&f("MANIFEST_INVALID","schema object property bounds are inverted");let c=ia(e.required,s);c!==void 0&&(o.required=c),U(e,"additionalProperties")&&(e.additionalProperties!==false&&f("MANIFEST_INVALID","schema additionalProperties must be false"),o.additionalProperties=false);}let a=JSON.stringify(o);return (a===void 0||Buffer.byteLength(a,"utf8")>2097152)&&J("action inputSchema subtree is too large"),o}function ra(e){let n=Mt(e,0,true);return (n.type!=="object"||!n.properties)&&f("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function sa(e){if(z(e)||f("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){$(e,js);let n=e.handler;return (typeof n!="string"||!lt.test(n))&&f("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"&&U(e,"entry"))return $(e,Bs),e.entry!==Ce&&f("MANIFEST_INVALID",`skill backend entry must be ${Ce}`),{type:"skill",entry:Ce};if(e.type==="skill"){$(e,Vs,Fs),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&f("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!ut.test(i))&&f("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=U(e,"env")?da(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}f("MANIFEST_INVALID","action backend type is unsupported");}function aa(e){z(e)||f("MANIFEST_INVALID","action must be an object"),$(e,Cs,ks),U(e,"_meta")&&H("_meta",()=>Ji(e._meta));let n=H("actionId",()=>Nt(e.actionId,"actionId"));at(n)&&f("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`,"actionId");let t=H("capability",()=>na(e.capability)),i=e.mutation;typeof i!="boolean"&&f("MANIFEST_INVALID","action mutation must be boolean","mutation");let r=H("inputSchema",()=>ra(e.inputSchema)),o;if(U(e,"dataInputs")){Array.isArray(e.dataInputs)||f("MANIFEST_INVALID","action dataInputs must be an array","dataInputs");let p=r.properties,u=new Set,A=[];for(let I of e.dataInputs)(typeof I!="string"||!U(p,I)||u.has(I))&&f("MANIFEST_INVALID","action dataInputs must be unique declared properties","dataInputs"),u.add(I),A.push(I);o=A;}let a=H("resultProjection",()=>Pt(e.resultProjection)),s=H("backend",()=>sa(e.backend)),c;U(e,"content")&&((s.type!=="skill"||!Mn(e.content))&&f("MANIFEST_INVALID","action content declaration is invalid","content"),c=pa(e.content));let d;if(U(e,"confirmation")){let p=e.confirmation;p!=="none"&&p!=="native"&&f("MANIFEST_INVALID","action confirmation is invalid","confirmation"),d=p;}let l;return U(e,"schedule")&&(l=H("schedule",()=>ca(e.schedule,{backend:s,inputSchema:r,hasContent:c!==void 0,hasDataInputs:o!==void 0,confirmation:d}))),{actionId:n,capability:t,mutation:i,inputSchema:r,resultProjection:a,backend:s,...c===void 0?{}:{content:c},...o===void 0?{}:{dataInputs:o},...d===void 0?{}:{confirmation:d},...l===void 0?{}:{schedule:l}}}function ca(e,n){(n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==Ce)&&f("MANIFEST_INVALID","schedule needs a tool-mode action","schedule"),(n.hasContent||n.hasDataInputs||n.confirmation!==void 0&&n.confirmation!=="none")&&f("MANIFEST_INVALID","a scheduled action takes no content, dataInputs or native confirmation","schedule"),(n.inputSchema.required??[]).length>0&&f("MANIFEST_INVALID","a scheduled action input must accept {}","inputSchema.required"),z(e)||f("MANIFEST_INVALID","schedule must be an object","schedule"),$(e,ws,xs),On(e.everyMinutes)||f("MANIFEST_INVALID","schedule everyMinutes is invalid","schedule.everyMinutes");let t=U(e,"timeoutMs")?e.timeoutMs:Ln.default;return Rn(t)||f("MANIFEST_INVALID","schedule timeoutMs is invalid","schedule.timeoutMs"),{everyMinutes:e.everyMinutes,timeoutMs:t}}function da(e){return Di(e)||f("MANIFEST_INVALID","skill backend env is invalid"),Object.freeze([...e])}function pa(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function la(e){return z(e)||f("INITIAL_STATE_INVALID","initialState must be an object"),$(e,Hs,zs),e.path!=="ui/state.json"&&f("MANIFEST_INVALID","initialState path is not fixed"),U(e,"hash")?{path:"ui/state.json",hash:Gi(e.hash)}:{path:"ui/state.json"}}function ua(e){let n=["wasm","terminal","htmlDocuments"];return (!z(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&f("MANIFEST_INVALID","runtime must contain only known capability flags set to true"),{...e.wasm===true?{wasm:true}:{},...e.terminal===true?{terminal:true}:{},...e.htmlDocuments===true?{htmlDocuments:true}:{}}}function fa(e,n){let t;try{t=Ui(e);}catch(i){let r=i!==null&&typeof i=="object"&&"code"in i&&typeof i.code=="string"?i.code:"CSP_ORIGIN_INVALID";return f("MANIFEST_INVALID",r,void 0,r.toLowerCase().replace(/_/g,"-"))}if(t.frameDomains.length>0&&f("MANIFEST_INVALID","external origins in csp are not enabled in this rollout",void 0,"csp-not-enabled"),t.connectDomains.length!==0)return n?.terminal===true&&f("MANIFEST_INVALID","runtime.terminal cannot be combined with csp.connectDomains","connectDomains","terminal-with-connect-domains"),Object.freeze({connectDomains:t.connectDomains})}function ya(e,n){wn(z(e)&&U(e,"csp")?Ks(e,"csp"):e,new Set,0,true,true),bt(e),z(e)||f("MANIFEST_INVALID"),$(e,Rs,Us),U(e,"_meta")&&H("_meta",()=>Ji(e._meta)),e.manifestVersion!==2&&f("MANIFEST_INVALID");let t;U(e,"runtime")&&(t=H("runtime",()=>ua(e.runtime)));let i;U(e,"csp")&&(i=H("csp",()=>fa(e.csp,t)));let r=H("pluginId",()=>Nt(e.pluginId,"pluginId")),o=H("definitionId",()=>Nt(e.definitionId,"definitionId")),a=H("version",()=>le(e,"version",1)),s=H("name",()=>wi(e.name,"name")),c=H("description",()=>wi(e.description,"description")),d;U(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&f("MANIFEST_INVALID","icon is invalid","icon"),d=e.icon);let l;U(e,"tone")&&((typeof e.tone!="string"||!ft.includes(e.tone))&&f("MANIFEST_INVALID","tone is invalid","tone"),l=e.tone),e.entry!=="ui/index.html"&&f("MANIFEST_INVALID","entry path is not fixed","entry","fixed-value");let p;U(e,"entryHash")&&(p=H("entryHash",()=>Gi(e.entryHash)));let u;U(e,"initialState")&&(u=H("initialState",()=>la(e.initialState)));let A;U(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&f("MANIFEST_INVALID","usage is invalid","usage"),A=e.usage);let I;U(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&f("MANIFEST_INVALID","detailPanel is invalid","detailPanel"),I=e.detailPanel);let h;if(U(e,"displayModes")){((A??tn)!==tn||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&f("MANIFEST_INVALID","displayModes are only valid for window Apps","displayModes");let m=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(E=>typeof E!="string"||!m.has(E)))&&f("MANIFEST_INVALID","displayModes are invalid","displayModes"),h=e.displayModes;}(A??tn)===tn&&I!==void 0&&f("MANIFEST_INVALID","detailPanel is card-only","detailPanel");let N=n.mode??"local";N!=="local"&&N!=="installed"&&N!=="published"&&f("MANIFEST_INVALID","manifest mode is invalid"),N!=="local"&&p===void 0&&f("MANIFEST_INVALID","installed manifests require entryHash","entryHash","required-when-installed"),N!=="local"&&u!==void 0&&u.hash===void 0&&f("MANIFEST_INVALID","installed manifests require initialState.hash","initialState.hash","required-when-installed"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&f("MANIFEST_INVALID","surfaces are invalid","surfaces"),e.surfaces.length>2&&J("surfaces exceed the v2 limit","surfaces","too-many-items");let F=[],v=new Set;for(let m of e.surfaces)(typeof m!="string"||!yt.includes(m))&&f("MANIFEST_INVALID","surface is unsupported","surfaces"),v.has(m)&&f("MANIFEST_INVALID","surfaces contain a duplicate","surfaces","duplicate-item"),v.add(m),F.push(m);z(e.size)||f("MANIFEST_INVALID","size must be an object","size"),H("size",()=>$(e.size,["height"]));let b=H("size",()=>le(e.size,"height",1));b>720&&J("size.height exceeds the v2 limit","size.height","too-large");let C=H("stateProjection",()=>Pt(e.stateProjection)),G=e.summaryProjection===void 0?void 0:H("summaryProjection",()=>Pt(e.summaryProjection));G!==void 0&&G.allow.some(m=>!C.allow.includes(m))&&f("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow","summaryProjection");let D=H("dataPaths",()=>ta(e.dataPaths,C.allow));Array.isArray(e.actions)||f("MANIFEST_INVALID","actions must be an array","actions"),e.actions.length>32&&J("actions exceed the v2 limit","actions","too-many-items");let M=[],S=new Set,y=0;for(let[m,E]of e.actions.entries()){let P=`actions[${m}]`,L=H(P,()=>aa(E));if(S.has(L.actionId)&&f("MANIFEST_INVALID","actions contain a duplicate actionId",`${P}.actionId`,"duplicate-item"),L.schedule!==void 0&&(y+=1,y>_i&&f("MANIFEST_INVALID","an App declares at most one scheduled action",`${P}.schedule`,"duplicate-item")),L.backend.type==="core"&&L.backend.handler==="state.set"){L.mutation||f("MANIFEST_INVALID","state.set actions must be mutations",`${P}.mutation`);for(let O of Object.keys(L.inputSchema.properties))C.allow.includes(O)||f("MANIFEST_INVALID","state.set input paths must be projection-allowed",`${P}.inputSchema.properties`);}S.add(L.actionId),M.push(L);}return {manifestVersion:2,pluginId:r,definitionId:o,version:a,name:s,description:c,...d===void 0?{}:{icon:d},...l===void 0?{}:{tone:l},entry:"ui/index.html",...p===void 0?{}:{entryHash:p},...t===void 0?{}:{runtime:t},...i===void 0?{}:{csp:i},...u===void 0?{}:{initialState:u},...A===void 0?{}:{usage:A},...I===void 0?{}:{detailPanel:I},...h===void 0?{}:{displayModes:h},surfaces:F,size:{height:b},stateProjection:C,...G===void 0?{}:{summaryProjection:G},...D===void 0?{}:{dataPaths:D},actions:M}}function Ji(e){z(e)||f("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>vs)&&J("_meta exceeds the 4 KiB limit",void 0,"meta-too-large");}function Aa(e){let n={},t={};for(let o of e.actions){n[o.actionId]={capabilities:[o.capability],inputKeys:Object.keys(o.inputSchema.properties??{}),...o.dataInputs===void 0?{}:{dataInputs:o.dataInputs},resultProjection:o.resultProjection,...o.confirmation===void 0?{}:{confirmation:o.confirmation},...o.content===void 0?{}:{content:o.content},...o.schedule===void 0?{}:{schedule:o.schedule},...o.backend.type!=="skill"||o.backend.env===void 0?{}:{env:o.backend.env}};let a=o.backend.type==="skill"||o.backend.type==="core"&&o.backend.handler==="state.set";t[o.actionId]={actionId:o.actionId,mutation:o.mutation,backend:o.backend,launchPolicy:a?"allowed":"denied",...a?{}:{denialCode:"EXEC_DENIED"}};}let i={id:e.definitionId,version:e.version,renderer:"sandbox-html",...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},surfaces:e.surfaces,stateProjection:e.stateProjection,...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},actions:n},r={entry:{path:"ui/index.html",...e.entryHash===void 0?{}:{hash:e.entryHash}},...e.initialState===void 0?{}:{initialState:e.initialState}};return {manifest:e,definition:i,handlers:t,resources:r}}function Lt(e,n,t,i,r,o){if(typeof e=="string"){let a=r.length>0&&o.some(s=>Be(r.join("."),s));return (e.length>4096||xn(e,false,false,a))&&de("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||de("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&de("state contains a non-JSON value"),t>8&&de("state is too deep"),n.has(e)&&de("state contains a cycle"),n.add(e);try{let a;if(Array.isArray(e))e.length>128&&de("state array is too long"),a=e.map(c=>Lt(c,n,t+1,2097152,r,o));else {z(e)||de("state contains a non-plain object");let c={};for(let[d,l]of Object.entries(e))(d.length>4096||!Sn.test(d)||ze(d))&&(d.length>4096&&de("state key is too long"),de("state contains a reserved or invalid key")),c[d]=Lt(l,n,t+1,2097152,[...r,d],o);a=c;}let s=JSON.stringify(a);return (s===void 0||Buffer.byteLength(s,"utf8")>i)&&de("state subtree is too large"),a}finally{n.delete(e);}}function Rt(e,n=[]){z(e)||de("initial state must be a JSON object");let t=Lt(e,new Set,0,2097152,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&de(),t}function Ia(e,n={}){wn(e),z(e)||f("MANIFEST_INVALID"),$(e,Os),e.manifestVersion!==1&&f("MANIFEST_INVALID");let t=Dt(ge(e,"pluginId")),i=Dt(ge(e,"definitionId")),r=le(e,"version",1),o=le(e,"primitiveSet",1),a=n.supportedPrimitiveSet??_s;(!Number.isSafeInteger(a)||a<1)&&f("MANIFEST_INVALID"),o>a&&f("PRIMITIVE_SET_UNSUPPORTED"),z(e.activation)||f("MANIFEST_INVALID"),$(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&f("MANIFEST_INVALID");let s=Dt(ge(e.activation,"language")),c=qs(e.schema),d=ea(e.layout,c);return {manifestVersion:1,pluginId:t,definitionId:i,version:r,primitiveSet:o,activation:{kind:"fenced-code",language:s},schema:c,layout:d}}function ga(e,n={}){return z(e)||f("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&f("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?ya(e,n):Ia(e,n)}function sn(e,n={}){try{return ga(e,n)}catch(t){if(t instanceof oe)throw t;return f("MANIFEST_INVALID")}}function an(e,n={}){let t=sn(e,n);return t.manifestVersion===2?Aa(t):t}var _s,Ts,Es,zi,Ds,Ns,bs,Ps,ki,Ss,Ms,Ls,Os,Rs,Us,Cs,ks,ws,xs,vs,js,Vs,Fs,Bs,Hs,zs,Gs,$s,Js,Ws,Xs,oe,Ut=w(()=>{g();Ei();Ee();gt();Ni();Tt();mt();Ci();Re();_s=1,Ts=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Es=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,zi=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Ds=/<\/?[A-Za-z][^>]*>/,Ns=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,bs=/^(?:https?|file|ftp|ws|wss):\/\//i,Ps=/^\s*(?:javascript|data):/i,ki=/data:[^,\s]*,/i,Ss=/(?:https?|file|ftp|ws|wss):\/\//i,Ms=/javascript:/i,Ls=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,Os=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],Rs=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],Us=["_meta","icon","tone","entryHash","runtime","csp","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],Cs=["actionId","capability","mutation","inputSchema","resultProjection","backend"],ks=["confirmation","dataInputs","content","schedule","_meta"],ws=["everyMinutes"],xs=["timeoutMs"],vs=4*1024,js=["type","handler"],Vs=["type","command"],Fs=["env"],Bs=["type","entry"],Hs=["path"],zs=["hash"],Gs=/^[0-9a-f]{64}$/,$s=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,Js=/[\r\n]/,Ws=16,Xs=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],oe=class e extends Error{constructor(t,i=t,r,o){super(i);this.code=t;this.path=r;this.rule=o;}code;path;rule;name="UiPluginValidationError";withPathPrefix(t){return new e(this.code,this.message,rn(t,this.path),this.rule)}};});function Zi(e){return typeof e=="string"&&e.length<=ha&&ma.test(e)}function k(e,n,t,i,r){throw new he(e,{path:n,rule:t,...i===void 0?{}:{message:i},...r===void 0?{}:{file:r}})}function Q(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function W(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function fe(e){let n=`_meta["${Se}"]`;return e===void 0||e===""?n:e.startsWith("[")?`${n}${e}`:`${n}.${e}`}function Da(e){return e.toLowerCase().replace(/_/g,"-")}function Na(e){if(e===void 0||e==="")return "";let n=/^([^.[]+)(.*)$/.exec(e);if(!n)return fe(e);let[,t,i]=n;switch(t){case "pluginId":return `name${i}`;case "name":return `display_name${i}`;case "description":return `description${i}`;case "_meta":return `_meta${i}`;case "version":return fe("definitionVersion");case "definitionId":return fe("definitionId");default:return fe(`${t}${i}`)}}function Qi(e,n,t){return {path:t(e.path),rule:e.rule??Da(e.code),...e.message!==e.code?{message:e.message}:{},file:n}}function eo(e){return JSON.parse(JSON.stringify(e))}function wt(e,n,t=0,i=new Set){if(typeof e=="string"){e.length>4096&&k("LIMIT_EXCEEDED",n,"string-too-long"),(_a.test(e)||Ta.test(e)||Ea.test(e))&&k("UNSAFE_VALUE",n,"unsafe-value");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||k("MANIFEST_INVALID",n,"non-finite-number");return}typeof e!="object"&&k("MANIFEST_INVALID",n,"non-json-value"),t>8&&k("LIMIT_EXCEEDED",n,"too-deep"),i.has(e)&&k("MANIFEST_INVALID",n,"cycle"),i.add(e);try{if(Array.isArray(e)){e.length>128&&k("LIMIT_EXCEEDED",n,"array-too-long"),e.forEach((r,o)=>wt(r,`${n}[${o}]`,t+1,i));return}Q(e)||k("MANIFEST_INVALID",n,"non-plain-object");for(let[r,o]of Object.entries(e))wt(o,n===""?r:`${n}.${r}`,t+1,i);}finally{i.delete(e);}}}function ue(e,n){return (typeof e!="string"||e.length===0)&&k("MANIFEST_INVALID",n,"string"),e}function We(e,n){return Q(e)||k("MANIFEST_INVALID",n,"object"),e}function ba(e,n){Array.isArray(e)||k("MANIFEST_INVALID",n,"array"),e.forEach((t,i)=>ue(t,`${n}[${i}]`));}function Pa(e,n){typeof e!="boolean"&&k("MANIFEST_INVALID",n,"boolean");}function cn(e,n,t,i){for(let r of Object.keys(e))!t.includes(r)&&!i.includes(r)&&k("MANIFEST_INVALID",`${n}.${r}`,"unknown-key");for(let r of t)W(e,r)||k("MANIFEST_INVALID",`${n}.${r}`,"missing-key");}function Sa(e,n){if(e!=="icon")switch(wt(n,e),e){case "long_description":case "homepage":case "documentation":case "support":case "license":ue(n,e);return;case "author":{let t=We(n,e);cn(t,e,["name"],["email","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "repository":{let t=We(n,e);cn(t,e,[],["type","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "icons":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=We(t,r);cn(o,r,["src","size"],["theme"]),ue(o.src,`${r}.src`),ue(o.size,`${r}.size`),W(o,"theme")&&ue(o.theme,`${r}.theme`);});return}case "screenshots":case "keywords":case "privacy_policies":ba(n,e);return;case "tools":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=We(t,r);cn(o,r,["name"],["description"]),ue(o.name,`${r}.name`),W(o,"description")&&ue(o.description,`${r}.description`);});return}case "prompts":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=We(t,r);cn(o,r,["name","text"],["description","arguments"]),ue(o.name,`${r}.name`),ue(o.text,`${r}.text`);});return}case "tools_generated":case "prompts_generated":Pa(n,e);return;case "localization":case "compatibility":case "user_config":We(n,e);return;default:k("MANIFEST_INVALID",e,"unknown-key");}}function vn(e){return typeof e=="string"&&Ie.test(e)?e:void 0}function no(e){return Number.isSafeInteger(e)&&e>=1?e:void 0}function Ma(e){let n=vn(e.name);if(n===void 0)return;let t=e._meta,i=Q(t)?t[Se]:void 0,r=Q(i)?i:{},o=W(r,"definitionId")?vn(r.definitionId):n,a=W(r,"definitionVersion")?no(r.definitionVersion):1;return {pluginId:n,...o===void 0?{}:{definitionId:o},...a===void 0?{}:{definitionVersion:a}}}function La(e){let n=vn(e.pluginId);if(n===void 0)return;let t=vn(e.definitionId),i=no(e.version);return {pluginId:n,...t===void 0?{}:{definitionId:t},...i===void 0?{}:{definitionVersion:i}}}function Vt(e){try{let n=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));if(!Q(n))return !1;let t=n._meta;return Q(t)&&W(t,Se)}catch{return false}}function Oa(e,n){if(e===we)return n.builtinOnly===true;let t=n._meta,i=Q(t)?t[Se]:void 0;return Q(i)&&i.builtinOnly===true}function Ra(e,n){W(e,"server")&&k("MANIFEST_INVALID","server","server-unsupported","phase 1 runs CrewX-owned Apps only");for(let s of Object.keys(e))vt.includes(s)||k("MANIFEST_INVALID",s,"unknown-key");for(let s of jt)W(e,s)||k("MANIFEST_INVALID",s,"missing-key");e.manifest_version!==Ct&&k("MANIFEST_INVALID","manifest_version","unsupported-version",`manifest_version must be "${Ct}"`),Zi(e.version)||k("MANIFEST_INVALID","version","semver","version must be a semver.org version such as 0.1.0");let t=e._meta;Q(t)||k("MANIFEST_INVALID","_meta","object"),W(t,Se)||k("MANIFEST_INVALID",fe(),"missing-key");let i=t[Se];Q(i)||k("MANIFEST_INVALID",fe(),"object");for(let s of Object.keys(i))kt.includes(s)||qi.includes(s)||k("MANIFEST_INVALID",fe(s),"unknown-key");for(let s of kt)s==="actions"&&n!==void 0||W(i,s)||k("MANIFEST_INVALID",fe(s),"missing-key");if(n!==void 0&&W(i,"actions")&&k("MANIFEST_INVALID",fe("actions"),"two-truths",`actions are declared in both ${X} and ${K}; a server.ts App keeps them in the tools file only`),Ua(i.actions),W(i,"definitionVersion")){let s=i.definitionVersion;(!Number.isSafeInteger(s)||s<1)&&k("MANIFEST_INVALID",fe("definitionVersion"),"positive-integer");}let r={};for(let s of Yi)W(e,s)&&(Sa(s,e[s]),r[s]=eo(e[s]));let o={};for(let[s,c]of Object.entries(t))s!==Se&&(o[s]=c);let a={manifestVersion:2,pluginId:e.name,definitionId:W(i,"definitionId")?i.definitionId:e.name,version:W(i,"definitionVersion")?i.definitionVersion:1,name:e.display_name,description:e.description};for(let[s,c]of Object.entries(i))s==="definitionId"||s==="definitionVersion"||(a[s]=c);return n!==void 0&&(a.actions=n.map(s=>({...s,backend:{type:"skill",entry:Ce}}))),Object.keys(o).length>0&&(a._meta=o),{v2Input:a,...Object.keys(o).length>0?{vendorMeta:o}:{},passthrough:r}}function Ua(e){Array.isArray(e)&&e.forEach((n,t)=>{let i=Q(n)?n.backend:void 0;Q(i)&&W(i,"entry")&&k("MANIFEST_INVALID",fe(`actions[${t}].backend.entry`),"entry-not-authorable",`an action in ${X} cannot name an entry; a server.ts App declares its actions in ${K}`);});}function Ca(e,n,t){Q(e)||k("MANIFEST_INVALID","","not-object","manifest.json must be a JSON object",X);let i;try{i=Ra(e,t);}catch(a){throw a instanceof he?new he(a.code,{...a.reason,file:X}):a}let r;try{let a=sn(i.v2Input,{mode:n.mode??"local"});a.manifestVersion!==2&&k("MANIFEST_INVALID","","v2-required"),r=a;}catch(a){throw a instanceof oe?new he(a.code,Qi(a,X,Na)):a}let o=e.tools;if(Array.isArray(o)){let a=new Set(r.actions.map(s=>s.actionId));o.forEach((s,c)=>{let d=s.name;if(!a.has(d))throw new he("MANIFEST_INVALID",{path:`tools[${c}].name`,rule:"tool-not-action",message:"every tools[].name must be an action id",file:X})});}return {file:X,manifest:r,v2Input:i.v2Input,releaseVersion:e.version,...Object.keys(i.passthrough).length>0?{mcpb:i.passthrough}:{}}}function ka(e,n){try{let t=sn(e,{mode:n.mode??"local"});if(t.manifestVersion!==2)throw new he("MANIFEST_INVALID",{path:"manifestVersion",rule:"v2-required",message:"a workspace App requires manifestVersion 2",file:we});return {file:we,manifest:t,v2Input:e}}catch(t){throw t instanceof oe?new he(t.code,Qi(t,we,i=>i??"")):t}}function xt(e){return ie(an(e).definition)}function Xi(e){let{entryHash:n,initialState:t,...i}=e,r={...i};return t!==void 0&&(r.initialState={path:t.path}),eo(r)}function wa(e,n){let t=Xi(e),i=Xi(n);return [...new Set([...Object.keys(t),...Object.keys(i)])].sort().filter(o=>Z(t[o]??null)!==Z(i[o]??null))}function xa(e,n){return e.entryHash!==void 0&&n.entryHash!==void 0&&e.entryHash!==n.entryHash||e.initialState?.hash!==void 0&&n.initialState?.hash!==void 0&&e.initialState.hash!==n.initialState.hash}function va(e,n){let t=wa(e,n),i=xa(e,n),r="";try{let o=xt(e),a=xt(n);i=i||o!==a,r=` (definition hash ${o.slice(0,12)} vs ${a.slice(0,12)})`;}catch{i=true;}t.length===0&&!i||k("MANIFEST_DUAL_MISMATCH","","dual-manifest-mismatch",`${X} and ${we} normalize to different definitions${r}`+(t.length>0?`; differing fields: ${t.join(", ")}`:""));}function me(e,n,t="MANIFEST_INVALID",i){return {code:t,reason:{path:e,rule:n,...i===void 0?{}:{message:i},file:K},files:[]}}function Ki(e){return {...me("","tools-needs-manifest-json","MANIFEST_INVALID",`${K} is read with ${X} only`),files:e}}function ja(e,n){if(e.byteLength>n)return {failure:me("","file-too-large","LIMIT_EXCEEDED")};let t;try{t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));}catch{return {failure:me("","invalid-json")}}if(!Q(t))return {failure:me("","not-object","MANIFEST_INVALID",`${K} must be a JSON object`)};for(let r of Object.keys(t))if(r!=="schemaVersion"&&r!=="actions")return {failure:me(r,"unknown-key")};for(let r of ["schemaVersion","actions"])if(!W(t,r))return {failure:me(r,"missing-key")};if(t.schemaVersion!==1)return {failure:me("schemaVersion","unsupported-version","MANIFEST_INVALID",`schemaVersion must be ${1}`)};let i=t.actions;if(!Array.isArray(i))return {failure:me("actions","array")};for(let[r,o]of i.entries()){if(!Q(o))return {failure:me(`actions[${r}]`,"object")};if(W(o,"backend"))return {failure:me(`actions[${r}].backend`,"tools-backend","MANIFEST_INVALID",`an action in ${K} cannot carry a backend`)}}return {actions:i}}function Va(e,n){let t=n.maxBytes??262144,i=[],r=new TextDecoder("utf-8",{fatal:true});for(let o of pe){let a=e[o];if(a===void 0)continue;if(a.byteLength>t)return {parsed:i,failure:{code:"LIMIT_EXCEEDED",reason:{path:"",rule:"file-too-large",file:o},files:[o]}};let s;try{s=JSON.parse(r.decode(a));}catch{return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"invalid-json",file:o},files:[o]}}}if(!Q(s))return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"not-object",message:`${o} must be a JSON object`,file:o},files:[o]}};i.push({file:o,raw:s});}return {parsed:i}}function Ft(e,n={}){let{parsed:t,failure:i}=Va(e,n),r=pe.filter(A=>e[A]!==void 0);if(i!==void 0)return {ok:false,rejection:i,parseFailure:true,builtinOnly:false};let o=e[K],a=o===void 0?void 0:ja(o,n.maxBytes??262144);if(t.length===0)return {ok:false,rejection:a===void 0?{code:"MANIFEST_INVALID",reason:{path:"",rule:"no-manifest-file",message:"neither manifest.json nor ui-plugin.json is present"},files:[]}:Ki(r),parseFailure:true,builtinOnly:false};let s=t[0],c=s.file===X?Ma(s.raw):La(s.raw),d=t.some(A=>Oa(A.file,A.raw)),l;if(a!==void 0){let A=t.some(I=>I.file===X)?a.failure:Ki(r);if(A!==void 0)return {ok:false,rejection:A,parseFailure:false,...c===void 0?{}:{identity:c},builtinOnly:d};l=a.actions;}let p=[];try{for(let A of t)p.push(A.file===X?Ca(A.raw,n,l):ka(A.raw,n));p.length===2&&va(p[0].manifest,p[1].manifest);}catch(A){if(A instanceof he)return {ok:false,rejection:{code:A.code,reason:A.reason,files:A.code==="MANIFEST_DUAL_MISMATCH"?[...pe]:A.reason.file===void 0||A.reason.file===K?r:[A.reason.file]},parseFailure:false,...c===void 0?{}:{identity:c},builtinOnly:d};throw A}let u=p[0];return {ok:true,...u,identity:c??{pluginId:u.manifest.pluginId},files:r}}var X,we,pe,Ct,Se,vt,jt,Yi,kt,qi,ma,ha,_a,Ta,Ea,he,Bt=w(()=>{g();Ue();Ee();Tt();Re();Ut();X="manifest.json",we="ui-plugin.json",pe=[X,we],Ct="0.3",Se="dev.crewx",vt=Object.freeze(["manifest_version","name","display_name","version","description","long_description","author","repository","homepage","documentation","support","icon","icons","screenshots","localization","server","tools","tools_generated","prompts","prompts_generated","keywords","license","privacy_policies","compatibility","user_config","_meta"]),jt=Object.freeze(["manifest_version","name","display_name","version","description","_meta"]),Yi=Object.freeze(vt.filter(e=>e!=="server"&&!jt.includes(e))),kt=Object.freeze(["entry","surfaces","size","stateProjection","actions"]),qi=Object.freeze(["definitionId","definitionVersion","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","csp"]),ma=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,ha=256,_a=/<\/?[A-Za-z][^>]*>/,Ta=/^\s*javascript:/i,Ea=/data:[^,\s]*,/i;he=class extends Error{constructor(t,i){super(`${t}: ${i.path||"<file>"} (${i.rule})`);this.code=t;this.reason=i;}code;reason};});function co(e){if(e===void 0)return {kind:"none"};if(typeof e!="string")return {kind:"invalid",reason:"bad-path"};if(Ha.test(e))return {kind:"url",declared:e};if(!$a(e))return {kind:"invalid",reason:"bad-path",declared:e};let n=e.lastIndexOf("."),t=n<0?void 0:Fa.get(e.slice(n+1).toLowerCase());return t===void 0?{kind:"invalid",reason:"bad-type",declared:e}:{kind:"file",path:e,contentType:t}}function $a(e){return e.length===0||e.length>512||e.startsWith("/")||e.includes("\\")||e.includes("\0")?false:e.split("/").every(n=>n!==""&&n!=="."&&n!=="..")}async function zt(e,n){let t=co(e);if(t.kind==="none")return {diagnostics:[]};if(t.kind==="url")return {diagnostics:[{code:"ICON_NOT_FILE",severity:"warning",declared:t.declared}]};if(t.kind==="invalid")return {diagnostics:[Ht(t.reason,t.declared)]};let i=await n(t.path);if(typeof i=="string")return {diagnostics:[Ht(i,t.path)]};let r=po(t.contentType,i);if(!r.ok)return {diagnostics:[Ht(r.reason,t.path)]};let o={path:t.path,contentType:t.contentType,byteLength:i.byteLength,bytes:i},a=r.square===false?[{code:"ICON_NOT_SQUARE",severity:"warning",declared:t.path}]:[];return {file:o,diagnostics:a}}function Ht(e,n){return {code:"ICON_INVALID",severity:"error",reason:e,...n===void 0?{}:{declared:n}}}function po(e,n){if(n.byteLength>262144)return {ok:false,reason:"too-large"};if(e==="image/png")return !ro(n,za)||nc(n,12,16)!=="IHDR"||n.byteLength<24?{ok:false,reason:"bytes-mismatch"}:{ok:true,square:oo(so(n,16),so(n,20))};if(e==="image/jpeg"){if(!ro(n,Ga))return {ok:false,reason:"bytes-mismatch"};let t=Qa(n);return {ok:true,square:t===void 0?void 0:oo(t.width,t.height)}}return Ja(n)}function Ja(e){let n;try{n=Ba.decode(e);}catch{return {ok:false,reason:"bytes-mismatch"}}return qa(n)?{ok:false,reason:"unsafe-svg"}:Wa.test(n)?{ok:true,square:Za(n)}:{ok:false,reason:"bytes-mismatch"}}function qa(e){if(Xa.some(n=>n.test(e)))return true;for(let n of e.matchAll(Ka))if(!(n[1]??n[2]??n[3]??"").startsWith("#"))return true;for(let n of e.matchAll(Ya))if(to.lastIndex=n.index??0,!to.test(e))return true;return false}function Za(e){let n=/<svg\b[^>]*>/i.exec(e)?.[0];if(n===void 0)return;let t=lo(n,"viewBox");if(t!==void 0){let o=t.trim().split(/[\s,]+/).map(Number);return o.length===4&&o.every(Number.isFinite)?o[2]===o[3]:void 0}let i=io(n,"width"),r=io(n,"height");return i===void 0||r===void 0?void 0:i===r}function lo(e,n){let t=new RegExp(`\\s${n}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(e);return t?.[1]??t?.[2]}function io(e,n){let t=lo(e,n),i=t===void 0?null:/^\s*(\d+(?:\.\d+)?)(?:px)?\s*$/.exec(t);return i===null?void 0:Number(i[1])}function Qa(e){let n=2;for(;n+4<=e.byteLength;){if(e[n]!==255)return;let t=e[n+1];if(t===255){n+=1;continue}if(t===216||t===1||t>=208&&t<=215){n+=2;continue}if(t===217)return;let i=e[n+2]<<8|e[n+3];if(i<2)return;if(ec(t))return n+9>e.byteLength?void 0:{height:ao(e,n+5),width:ao(e,n+7)};n+=2+i;}}function ec(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}function oo(e,n){if(!(e<=0||n<=0))return e===n}function ro(e,n){return e.byteLength>=n.length&&n.every((t,i)=>e[i]===t)}function nc(e,n,t){return String.fromCharCode(...e.subarray(n,t))}function so(e,n){return (e[n]<<24|e[n+1]<<16|e[n+2]<<8|e[n+3])>>>0}function ao(e,n){return e[n]<<8|e[n+1]}var Fa,Ba,Ha,za,Ga,Wa,Xa,Ka,Ya,to,Gt=w(()=>{g();Fa=new Map([["svg","image/svg+xml"],["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"]]),Ba=new TextDecoder("utf-8",{fatal:true}),Ha=/^[A-Za-z][A-Za-z0-9+.-]*:/,za=[137,80,78,71,13,10,26,10],Ga=[255,216,255];Wa=/^\s*(?:<\?[\s\S]*?\?>\s*|<!--[\s\S]*?-->\s*)*<svg(?=[\s/>])/,Xa=[/<script/i,/[\s"'/]on[a-z]+\s*=/i,/<foreignobject/i,/<!doctype/i,/<!entity/i,/<(?:iframe|embed|object)\b/i,/@import/i],Ka=/(?:^|[\s"'/])(?:xlink:)?href\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/gi,Ya=/url\(/gi,to=/url\(\s*["']?#/iy;});var fo=w(()=>{g();Ti();Bt();Gt();Ut();Re();});function T(e,n=e){throw new _e(e,n)}var _e,Vn=w(()=>{g();_e=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};});var yo=w(()=>{g();});var Ao=w(()=>{g();Ue();Ee();Vn();yo();});function go(e,n){return Io.add(e),n!==void 0&&tc.set(e,n),e}function Xe(e){return e!==null&&typeof e=="object"&&Io.has(e)}var Io,tc,Fn=w(()=>{g();Io=new WeakSet,tc=new WeakMap;});function ln(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function $t(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e);return n.every(o=>Object.hasOwn(e,o))&&r.every(o=>i.has(o))}function _o(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))_o(n);return Object.freeze(e)}function ee(e){throw new Te("LINEAGE_INVALID",e)}function dc(e){throw new Te("LINEAGE_STALE",e)}function To(e){if(!ln(e)||!$t(e,rc,sc)||!ln(e.actions))return ee("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!ln(n)||!$t(n,ac,cc))return ee("Lineage action definition shape is invalid");return e}function pc(e){if(!ln(e)||!$t(e,ic,oc))return ee("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!mo.test(e.hash))return ee("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!mo.test(e.sourceHash)))return ee("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return ee("Lineage compatibility marker is invalid");let n=To(e.definition);if(n.version!==e.version)return ee("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return ee("Lineage source hash does not match its definition");let t;try{t=ie(n),ce({...n,hash:e.hash});}catch{return ee("Lineage definition is invalid")}return t!==e.hash?ee("Lineage definition hash does not match"):_o({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function ho(e){return e.stateProjection?.allow??[]}function lc(e,n){let t=[],i=new Set(ho(n));ho(e).some(s=>!i.has(s))&&t.push("S1_STATE_PROJECTION");let r=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(s=>!r.has(s))&&t.push("S2_DATA_PATHS");for(let[s,c]of Object.entries(e.actions)){let d=n.actions[s];if(d&&(c.confirmation??"native")==="native"&&(d.confirmation??"native")!=="native"){t.push("S3_ACTION_CONFIRMATION");break}}Object.keys(e.legacy?.agentAccess??{}).some(s=>!Object.hasOwn(n.actions,s))&&t.push("S4_LEGACY_AGENT_ACTIONS");let a=e.summaryProjection?.allow;if(a!==void 0){let s=new Set(n.summaryProjection?.allow??[]);a.some(c=>!s.has(c))&&t.push("S5_SUMMARY_PROJECTION");}return t}function uc(e,n){return Z(e)===Z(n)}function Jt(e,n){if(!Array.isArray(e)||e.length===0)return ee("Definition lineage is missing");if(!ln(n)||typeof n.hash!="string")return ee("Current definition is invalid");let t,i;try{let{hash:s,...c}=n;i=To(c),t={...i,hash:s},ce(t);}catch{return ee("Current definition is invalid")}let r=e.map(pc),o=r[0].definition.id;if(r.some(s=>s.definition.id!==o))return ee("Lineage definition ids do not match");if(r.some((s,c)=>c>0&&s.version<=r[c-1].version))return ee("Lineage generations are not in increasing version order");if(r.some((s,c)=>r.findIndex(d=>d.hash===s.hash)!==c))return ee("Lineage contains a duplicate hash");let a=r[r.length-1];if(a.version!==t.version||a.hash!==t.hash||a.definition.id!==t.id||!uc(a.definition,i))return dc("The last lineage generation does not match the current package");if(t.legacy!==void 0){let s=new Set(Object.keys(t.actions)),c=new Set;for(let l of r)if(l.sourceHash===void 0)for(let p of Object.keys(l.definition.actions))s.has(p)&&c.add(p);let d=Object.keys(t.legacy.agentAccess??{});if(d.length!==c.size||d.some(l=>!c.has(l))){let l="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new Te("LINEAGE_INVALID",`Lineage compatibility failed: ${l}`,[l])}}for(let s=0;s<r.length-1;s+=1){if(r.slice(s,-1).some(l=>l.compat==="break"))continue;let d=lc(r[s].definition,t);if(d.length>0)throw new Te("LINEAGE_INVALID",`Lineage compatibility failed: ${d.join(", ")}`,d)}return Object.freeze({entries:Object.freeze(r),current:t})}var Te,mo,ic,oc,rc,sc,ac,cc,Wt=w(()=>{g();Ue();Ee();Te=class extends Error{constructor(t,i=t,r=[]){super(i);this.code=t;this.violations=r;}code;violations;name="UiDefinitionLineageError"},mo=/^[0-9a-f]{64}$/,ic=["version","hash","definition"],oc=["sourceHash","compat"],rc=["id","version","actions"],sc=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],ac=["capabilities"],cc=["inputKeys","dataInputs","confirmation","resultProjection","content","env","schedule"];});var Eo,Do,No,bo,Po=w(()=>{g();Eo="text/html;profile=mcp-app",Do=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],No=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"],bo="text/html";});function un(e){return typeof e=="string"&&fc.includes(e)}function Bn(e,n){return e==="card"&&n?.type==="core"&&un(n.handler)}var fc,Hn=w(()=>{g();fc=Object.freeze(["card.secret-env"]);});function So(e,n=[],t){if(e.content!==void 0||e.confirmation!=="none")return "denied";let i=yc();return i&&Object.hasOwn(i,e.actionId)?i[e.actionId]:e.backend?.type==="core"&&e.backend.handler.startsWith("host.")?"denied":e.backend?.type==="core"&&e.backend.handler==="state.set"?"allowed":e.backend?.type==="core"&&un(e.backend.handler)||e.backend?.type==="skill"?"approval_required":e.backend===void 0&&n.includes(e.actionId)?"allowed":"denied"}function yc(e){return;}var Mo=w(()=>{g();Ue();Fn();Hn();});function Dc(e){return An.has(e)&&(e.initialState===void 0||An.has(e.initialState))}function Co(e,n,t,i){let r=i===void 0?void 0:Object.freeze({hash:i.hash,bytes:Object.freeze(i.bytes)}),o=Object.freeze({mimeType:bo,entryHash:e,html:n,bytes:Object.freeze(t),...r===void 0?{}:{initialState:r}});return r!==void 0&&An.add(r),An.add(o),o}function Nc(e){let n=[];return e?.terminal===true&&n.push({name:"crewx_app_terminal_connect",description:"Open a local-only terminal session for this App.",inputSchema:{type:"object",properties:{workspace:{type:"string"},threadId:{type:"string"},instanceId:{type:"string"}},required:["threadId","instanceId"],additionalProperties:false},textFallback:"A local terminal connection is ready for this App.",visibility:Object.freeze(["app"]),kind:"host",resourceBinding:Le}),e?.htmlDocuments===true&&n.push({name:"crewx_app_html_viewer_open",description:"List workspace HTML documents or open one through a short-lived Host capability.",inputSchema:{type:"object",properties:{workspace:{type:"string"},threadId:{type:"string"},instanceId:{type:"string"},operation:{type:"string",enum:["list","open"]},documentId:{type:"string"}},required:["threadId","instanceId","operation"],additionalProperties:false},textFallback:"Workspace HTML documents are available through this App.",visibility:Object.freeze(["app"]),kind:"host",resourceBinding:Le}),n}function Oe(e,n,t){return (typeof e!="string"||!Ro.test(e))&&T(n,`${t} must be a safe identifier`),e}function fn(e,n,t){let i=e??t;return (typeof i!="string"||i.trim().length===0||i.length>gc)&&T("TOOL_INVALID",`${n} must be a meaningful description`),i}function Kt(e){return (typeof e!="string"||e.length===0||e.length>Ke||!/<html(?:\s|>)/i.test(e)||!/<\/html\s*>/i.test(e))&&T("HTML_INVALID","MCP App HTML must be a non-empty HTML document"),e}function yn(e,n=0){try{let t=ae(e,n);return t.type!==void 0&&t.type!=="object"&&T("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof _e)throw t;T("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function bc(e){return (typeof e!="string"||e.trim().length===0||e.length>mc)&&T("TOOL_INVALID","MCP App tools require a meaningful text fallback"),e}function Pc(e){e===void 0&&T("TOOL_INVALID","MCP App tool visibility is required");let n=[...e];return (n.length===0||n.some(t=>t!=="model"&&t!=="app")||new Set(n).size!==n.length)&&T("TOOL_INVALID","MCP App tool visibility must contain model and/or app once"),n}function wo(e){return (typeof e!="string"||!Uo.test(e))&&T("RESOURCE_URI_INVALID","MCP App resource URI is not a registered ui:// URI"),e}function xo(e){let n=Oe(e.appId,"APP_ID_INVALID","Local App id"),t=fn(e.name,"Local App name",n),i=fn(e.description,"Local App description",`${t} interactive view`),r=Jn(e.definition),o=Kt(e.html),a=zn(e.entryHash,"Local App entry hash"),s=e.entryBytes===void 0?Array.from(new TextEncoder().encode(o)):$n(e.entryBytes,"Local App entry bytes");(Gn(s)!==a||Vo(s)!==o)&&T("HTML_INVALID","Local App entry bytes do not match the HTML hash");let c=Sc(e),d=[];Array.isArray(e.actions)||T("TOOL_INVALID","Local App actions must be an array");for(let b of e.actions){let C=Oe(b.actionId,"TOOL_ID_INVALID","Local App action id");(d.includes(C)||!Object.prototype.hasOwnProperty.call(r.actions,C))&&T("TOOL_INVALID",`Local App action is not declared by the UI definition: ${C}`),d.push(C);}let l=Oe(e.readToolName,"TOOL_ID_INVALID","Local App read tool name"),p=e.actionToolName===void 0?void 0:Oe(e.actionToolName,"TOOL_ID_INVALID","Local App action tool name");d.length===0&&p!==void 0&&T("TOOL_INVALID","A static local App cannot register an action tool"),d.length>0&&p===void 0&&T("TOOL_INVALID","A stateful local App requires an action tool name"),p!==void 0&&p===l&&T("TOOL_ID_CONFLICT",`Local App read and action tools share a name: ${l}`);let u=Nc(e.runtime);u.some(b=>b.name===l||b.name===p)&&T("TOOL_ID_CONFLICT","Local App read or action tool conflicts with a requested Host capability");let A={name:l,description:`${t} current state`,inputSchema:Ec,textFallback:`${t} current state is available through its open instance.`,visibility:Object.freeze(["model","app"]),kind:"read",resourceBinding:Le},I=[Object.freeze(A)];if(I.push(...u.map(b=>Object.freeze(b))),p!==void 0){let b={name:p,description:`${t} actions`,inputSchema:Yt(e.actions),textFallback:`${t} action requests are handled by the open App instance.`,visibility:Object.freeze(["app"]),kind:"action",resourceBinding:Le,actionIds:Object.freeze([...d])};I.push(Object.freeze(b));}let h=[],N=new Set(I.map(b=>b.name));if(p!==void 0)for(let b of e.actions){let C=`${p}__${b.actionId}`;if(C.length>128||!Ro.test(C)){h.push(Object.freeze({toolName:C,actionId:b.actionId,reason:"name_too_long"}));continue}if(N.has(C)){h.push(Object.freeze({toolName:C,actionId:b.actionId,reason:"name_collision"}));continue}let G=So({actionId:b.actionId,confirmation:r.actions[b.actionId]?.confirmation,content:r.actions[b.actionId]?.content,backend:b.backend},e.modelActions),D=Object.freeze([...Uc(G,r.usage,b.backend)]),M={name:C,description:`${C} action`,inputSchema:yn(b.inputSchema),textFallback:`${C} action requests are handled by the open App instance.`,visibility:D,kind:"action",resourceBinding:Le,actionId:b.actionId,actionIds:Object.freeze([b.actionId]),_meta:Object.freeze({ui:Object.freeze({visibility:D})})};I.push(Object.freeze(M)),N.add(C);}let F=Co(a,o,s,c===void 0?void 0:{hash:c.hash,bytes:[...c.bytes]}),v={appId:n,name:t,description:i,...e.icon===void 0?{}:{icon:Fo(e.icon)},...e.tone===void 0?{}:{tone:Bo(e.tone)},builtinOnly:false,definition:r,...e.runtime===void 0?{}:{runtime:Object.freeze({...e.runtime})},resourceBinding:Le,resource:F,tools:Object.freeze(I),toolDiagnostics:Object.freeze(h)};return Y(v)}function vo(e={}){return new Xt(e)}function Yt(e){if(e.length===0)return yn({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,yn(i.inputSchema));return yn(Mc(n,t),ko)}function Sc(e){let n=e.definition.dataPaths??[];if(e.initialStateBytes===void 0){e.initialStateHash!==void 0&&T("STATE_INVALID","Initial state hash has no bytes"),e.initialState!==void 0&&ae(e.initialState,0,n);return}e.initialStateHash===void 0&&T("STATE_INVALID","Initial state bytes require a hash");let t=zn(e.initialStateHash,"Initial state hash"),i=$n(e.initialStateBytes,"Initial state bytes");Gn(i)!==t&&T("STATE_INVALID","Initial state bytes do not match the hash");let r;try{let o=new TextDecoder("utf-8",{fatal:!0}).decode(Uint8Array.from(i));r=ae(JSON.parse(o),0,n);}catch{T("STATE_INVALID","Initial state bytes are not projection-safe JSON");}return e.initialState!==void 0&&Z(r)!==Z(ae(e.initialState,0,n))&&T("STATE_INVALID","Initial state bytes do not match the state value"),{hash:t,bytes:Object.freeze([...i])}}function Mc(e,n){let t=e.map(i=>({type:"object",properties:{actionId:{type:"string",const:i},input:n.get(i)??{type:"object"}},required:["actionId","input"],additionalProperties:false}));return Object.freeze({type:"object",oneOf:Object.freeze(t),properties:Object.freeze({actionId:Object.freeze({type:"string",enum:Object.freeze([...e])}),input:Object.freeze({type:"object"})}),required:Object.freeze(["actionId","input"]),additionalProperties:false})}function Lc(e){let n=In(e),t=Oe(n.appId,"APP_ID_INVALID","MCP App id"),i=Kt(n.html);wo(n.uiUri);let r=n.definition===void 0?void 0:Jn(n.definition),o=e.provenance;o!==void 0&&(!Xe(o)||o.appId!==t||o.definitionId!==r?.id||o.version!==r?.version||o.definitionHash!==r?.hash)&&T("TOOL_INVALID","Product App built-in registration provenance is not verified");let a=Object.freeze(n.tools.map(d=>Y(In(d)))),s=Y({...n,appId:t,html:i,...r===void 0?{}:{definition:r},...o===void 0?{}:{provenance:o},tools:a}),c=Y({uri:s.uiUri,mimeType:Eo,text:i,...s.csp===void 0?{}:{_meta:{ui:{csp:s.csp}}}});return Y({appId:t,name:s.name,description:s.description,...s.icon===void 0?{}:{icon:s.icon},...s.tone===void 0?{}:{tone:s.tone},builtinOnly:s.builtinOnly,uiUri:s.uiUri,...r===void 0?{}:{definition:r},resourceBinding:Object.freeze({kind:"mcp",uri:s.uiUri}),resource:c,tools:a,descriptor:s})}function Oc(e){(e.resourceBinding.kind!=="instance"||e.builtinOnly!==false)&&T("STATE_INVALID","Local App registration binding is invalid"),Object.prototype.hasOwnProperty.call(e,"uiUri")&&T("STATE_INVALID","Local App registration cannot contain uiUri");let n=Oe(e.appId,"APP_ID_INVALID","Local App id"),t=Jn(e.definition),i=e.provenance;i!==void 0&&(!Xe(i)||i.appId!==n||i.definitionId!==t.id||i.version!==t.version||i.definitionHash!==t.hash)&&T("TOOL_INVALID","Product App local registration provenance is not verified");let r=Rc(e.resource),o=e.tools.map(s=>{Oe(s.name,"TOOL_ID_INVALID","Local App tool name"),fn(s.description,"Local App tool description","Local App tool"),bc(s.textFallback);let c=yn(s.inputSchema,s.kind==="action"&&!("actionId"in s)?ko:0);if((s.resourceBinding.kind!=="instance"||Object.prototype.hasOwnProperty.call(s,"resourceUri"))&&T("TOOL_INVALID","Local App tools cannot carry an MCP resource URI"),s.kind==="host")return (!Tc.has(s.name)||s.visibility.length!==1||s.visibility[0]!=="app"||Object.prototype.hasOwnProperty.call(s,"actionId"))&&T("TOOL_INVALID","Local App Host tools must use an allow-listed name and app-only visibility"),Y({...s,inputSchema:c,visibility:Object.freeze(["app"])});if(s.kind==="action"){if("actionId"in s){let l=Oe(s.actionId,"TOOL_ID_INVALID","Local App action id");Object.prototype.hasOwnProperty.call(t.actions,l)||T("TOOL_INVALID","Local App action tool references an undeclared action");let p=Pc(s._meta.ui.visibility);return JSON.stringify(p)!==JSON.stringify(s.visibility)&&T("TOOL_INVALID","Local App action metadata visibility must match the tool visibility"),Y({...s,actionId:l,actionIds:Object.freeze([l]),inputSchema:c,visibility:p,_meta:{ui:{visibility:p}}})}let d=[...s.actionIds];return (d.length===0||d.some(l=>!Object.prototype.hasOwnProperty.call(t.actions,l)))&&T("TOOL_INVALID","Local App action tool references an undeclared action"),Y({...s,inputSchema:c,actionIds:Object.freeze(d)})}return Y({...s,inputSchema:c})}),a=Y({appId:n,name:fn(e.name,"Local App name",e.appId),description:fn(e.description,"Local App description",e.name),...e.icon===void 0?{}:{icon:Fo(e.icon)},...e.tone===void 0?{}:{tone:Bo(e.tone)},builtinOnly:false,definition:t,...e.runtime===void 0?{}:{runtime:Object.freeze({...e.runtime})},...i===void 0?{}:{provenance:i},resourceBinding:Le,resource:r,tools:Object.freeze(o),toolDiagnostics:Object.freeze([...e.toolDiagnostics??[]])});return Lo.has(e)?e:(Lo.add(a),a)}function Rc(e){let n=Kt(e.html),t=zn(e.entryHash,"Local App entry hash");if(Dc(e))return e;let i=$n(e.bytes,"Local App entry bytes");(Gn(i)!==t||Vo(i)!==n)&&T("HTML_INVALID","Local App entry bytes do not match the HTML hash");let r=e.initialState===void 0?void 0:{hash:zn(e.initialState.hash,"Initial state hash"),bytes:$n(e.initialState.bytes,"Initial state bytes")};return r&&Gn(r.bytes)!==r.hash&&T("STATE_INVALID","Initial state bytes do not match the hash"),Co(t,n,i,r)}function Uc(e,n,t){if(Bn(n,t))return ["model"];let i=t?.type==="core"&&un(t.handler);return e==="denied"||i?["app"]:["model","app"]}function Cc(e){return Y({appId:e.appId,name:e.name,description:e.description,...e.icon===void 0?{}:{icon:e.icon},...e.tone===void 0?{}:{tone:e.tone},builtinOnly:false,definition:jo(e.definition),...e.provenance===void 0?{}:{provenance:e.provenance},entryHash:e.resource.entryHash,resourceBinding:Le,tools:e.tools})}function kc(e){return Y({appId:e.appId,name:e.name,description:e.description,...e.icon===void 0?{}:{icon:e.icon},...e.tone===void 0?{}:{tone:e.tone},builtinOnly:e.builtinOnly,uiUri:e.uiUri,...e.definition===void 0?{}:{definition:jo(e.definition)},resourceBinding:Object.freeze({kind:"mcp",uri:e.uiUri}),tools:e.tools})}function Jn(e){try{if(Object.isFrozen(e))return ce(e),Y(e);let n=In(e);return ce(n),Y(n)}catch(n){if(n instanceof _e)throw n;T("STATE_INVALID","UI definition is not a valid immutable definition");}}function jo(e){return Y({id:e.id,version:e.version,hash:e.hash})}function wc(e){return e!==null&&typeof e=="object"&&typeof e.id=="string"&&Number.isSafeInteger(e.version)&&typeof e.hash=="string"}function Oo(e,n,t){return `${e}\0${n}\0${t}`}function zn(e,n){return (typeof e!="string"||!Ic.test(e))&&T("SERIALIZATION_INVALID",`${n} is invalid`),e}function Gn(e){return crypto.createHash("sha256").update(Uint8Array.from(e)).digest("hex")}function $n(e,n){return (!Array.isArray(e)||e.some(t=>!Number.isInteger(t)||t<0||t>255))&&T("SERIALIZATION_INVALID",`${n} is invalid`),[...e]}function Vo(e){try{return new TextDecoder("utf-8",{fatal:!0}).decode(Uint8Array.from(e))}catch{T("SERIALIZATION_INVALID","UTF-8 bytes are invalid");}}function Fo(e){return (typeof e!="string"||!hc.test(e))&&T("TOOL_INVALID","MCP App icon is invalid"),e}function Bo(e){return (typeof e!="string"||!_c.has(e))&&T("TOOL_INVALID","MCP App tone is invalid"),e}function In(e,n=new Map){if(e===null||typeof e!="object")return e;let t=e;if(n.has(t)&&T("SERIALIZATION_INVALID","MCP App value contains a cycle"),Array.isArray(e)){let o=[];n.set(t,o);for(let a of e)o.push(In(a,n));return n.delete(t),o}let i;try{i=Object.getPrototypeOf(e);}catch{T("SERIALIZATION_INVALID","MCP App value cannot be cloned");}i!==Object.prototype&&i!==null&&T("SERIALIZATION_INVALID","MCP App value must be plain JSON");let r={};n.set(t,r);for(let[o,a]of Object.entries(e))Object.defineProperty(r,o,{configurable:true,enumerable:true,value:In(a,n),writable:true});return n.delete(t),r}function Y(e,n=new Set){if(e===null||typeof e!="object"||n.has(e)||An.has(e))return e;n.add(e);for(let t of Object.values(e))Y(t,n);return Object.freeze(e),e}var Ro,Uo,Ic,Ke,gc,mc,hc,_c,Tc,Le,Ec,An,Lo,ko,Xt,Wn=w(()=>{g();Ao();Ue();Ee();Fn();Vn();Wt();Po();Mo();Hn();Ro=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Uo=/^ui:\/\/crewx\/([A-Za-z][A-Za-z0-9._-]{0,127})\/([0-9a-f]{12})$/,Ic=/^[0-9a-f]{64}$/,Ke=8*1024*1024,gc=8*1024,mc=16*1024,hc=/^[a-z][a-z0-9-]{0,63}$/,_c=new Set(["blue","violet","emerald","amber","rose","sky","slate","indigo"]),Tc=new Set(Do),new Set(No),Le=Object.freeze({kind:"instance"}),Ec=Object.freeze({type:"object",properties:Object.freeze({}),additionalProperties:false}),An=new WeakSet,Lo=new WeakSet;ko=4;Xt=class{builtinApps;localApps;builtinDescriptors;builtinTools;mcpResources=new Map;localById=new Map;registrationById=new Map;launcherById=new Map;definitionByKey=new Map;handlerByKey=new Map;mcpToolByName=new Map;localToolByName=new Map;constructor(n){let t=n.builtins??n.builtin,i=[],r=[],o=[],a=new Set,s=new Set;for(let p of t?.listMcpApps()??[]){let u=Lc(p);a.has(u.appId)&&T("APP_ID_CONFLICT",`MCP App id is already registered: ${u.appId}`),a.add(u.appId);let A=u.tools;for(let I of A)s.has(I.name)&&T("TOOL_ID_CONFLICT",`MCP App tool name is already registered: ${I.name}`),s.add(I.name),this.mcpToolByName.set(I.name,I),o.push(I);this.mcpResources.set(u.resource.uri,u.resource),i.push(u),r.push(u.descriptor);}let c=(n.localApps??n.locals??[]).map(Oc),d=new Set(c.flatMap(p=>p.tools.filter(u=>!(u.kind==="action"&&"actionId"in u)).map(u=>u.name))),l=[];for(let p of c){let u=p;a.has(u.appId)&&T("APP_ID_CONFLICT",`MCP App id is already registered: ${u.appId}`),a.add(u.appId);let A=[],I=[...u.toolDiagnostics??[]];for(let h of u.tools){if(s.has(h.name)){if(h.kind==="host"&&this.localToolByName.get(h.name)?.kind==="host"){A.push(h);continue}if(h.kind==="action"&&"actionId"in h){I.push(Object.freeze({toolName:h.name,actionId:h.actionId,reason:"name_collision"}));continue}T("TOOL_ID_CONFLICT",`MCP App tool name is already registered: ${h.name}`);}if(h.kind==="action"&&"actionId"in h&&d.has(h.name)){I.push(Object.freeze({toolName:h.name,actionId:h.actionId,reason:"name_collision"}));continue}s.add(h.name),this.localToolByName.set(h.name,h),A.push(h);}(A.length!==u.tools.length||I.length!==(u.toolDiagnostics?.length??0))&&(u=Y({...u,tools:Object.freeze(A),toolDiagnostics:Object.freeze(I)})),l.push(u),this.localById.set(u.appId,u);}for(let p of i)this.registrationById.set(p.appId,p),this.launcherById.set(p.appId,kc(p)),p.definition&&this.addDefinition(p.definition);for(let p of l)this.registrationById.set(p.appId,p),this.launcherById.set(p.appId,Cc(p)),this.addDefinition(p.definition);for(let p of n.definitions??[])this.addDefinition(p);for(let p of n.handlers??[])this.addHandler(p);this.builtinApps=Object.freeze(i),this.localApps=Object.freeze(l),this.builtinDescriptors=Object.freeze(r),this.builtinTools=Object.freeze(o);}getMcpApp(n){return this.builtinApps.find(t=>t.appId===n)?.descriptor??null}listMcpApps(){return this.builtinDescriptors}listMcpAppTools(){return this.builtinTools}resolveMcpAppTool(n){return this.mcpToolByName.get(n)??null}resolveMcpAppResource(n){return typeof n!="string"||!Uo.test(n)?null:this.mcpResources.get(n)??null}requireMcpAppResource(n){wo(n);let t=this.mcpResources.get(n);return t||T("RESOURCE_NOT_FOUND",`MCP App resource is not registered: ${n}`),t}listLocalMcpApps(){return this.localApps}getLocalMcpApp(n){return this.localById.get(n)??null}listLocalMcpAppTools(){return Object.freeze([...this.localToolByName.values()])}resolveLocalMcpAppTool(n){return this.localToolByName.get(n)??null}resolveLocalMcpAppResource(n,t){let i=this.localById.get(n);return !i||t!==void 0&&i.definition.hash!==t?null:i.resource}listRegistrations(){return Object.freeze([...this.builtinApps,...this.localApps])}getRegistration(n){return this.registrationById.get(n)??null}listLaunchers(){return Object.freeze([...this.launcherById.values()].filter(n=>{let t=this.registrationById.get(n.appId),i=t?"descriptor"in t?t.descriptor.provenance:t.provenance:void 0,r=Xe(i)&&i.launcher===false;return t?.definition?.usage!=="card"&&!r}))}listCardApps(){return Object.freeze([...this.launcherById.values()].filter(n=>this.registrationById.get(n.appId)?.definition?.usage==="card"))}getLauncher(n){return this.launcherById.get(n)??null}resolveDefinition(n){if(!wc(n))return null;let t=this.definitionByKey.get(_t(n));if(!t||t.hash!==n.hash)return null;try{return ie(t)===t.hash?t:null}catch{return null}}resolveActionHandler(n,t,i){return typeof n!="string"||typeof i!="string"||!Number.isSafeInteger(t)?null:this.handlerByKey.get(Oo(n,t,i))??null}addDefinition(n){let t=Jn(n),i=_t(t),r=this.definitionByKey.get(i);r&&r.hash!==t.hash&&T("STATE_INVALID",`UI definition generation conflicts: ${i}`),r||this.definitionByKey.set(i,t);}addHandler(n){(!n||typeof n.definitionId!="string"||typeof n.actionId!="string"||!Number.isSafeInteger(n.version)||n.version<1||typeof n.handle!="function")&&T("STATE_INVALID","UI action handler registration is invalid");let t=Oo(n.definitionId,n.version,n.actionId);this.handlerByKey.has(t)&&T("TOOL_INVALID",`Duplicate UI action handler registration: ${t}`),this.handlerByKey.set(t,Object.freeze({...n}));}};});function xc(e){let n=xo({appId:e.appId,name:e.name,description:e.description,...e.icon===void 0?{}:{icon:e.icon},...e.tone===void 0?{}:{tone:e.tone},...e.normalized.manifest.runtime===void 0?{}:{runtime:e.normalized.manifest.runtime},definition:e.definition,html:e.html,entryHash:e.entryHash,entryBytes:e.entryBytes,initialState:e.initialState,...e.initialStateHash===void 0?{}:{initialStateHash:e.initialStateHash},...e.initialStateBytes===void 0?{}:{initialStateBytes:e.initialStateBytes},readToolName:e.toolNames.read,...e.toolNames.action===void 0?{}:{actionToolName:e.toolNames.action},actions:e.normalized.manifest.actions.map(i=>({actionId:i.actionId,inputSchema:i.inputSchema,backend:i.backend}))});return e.provenance===void 0?n:Object.freeze({...n,provenance:e.provenance})}function Ho(e){let n=e.normalized.manifest.actions;if(n.some(i=>i.backend.type==="skill")&&n.some(i=>i.backend.type==="core"))throw new Error("Mixed workspace App execution models");let t=xc(e);vo({localApps:[t],definitions:[e.definition]});}var zo=w(()=>{g();Wn();});function Go(){return Object.freeze({[qt]:{candidates:new Map,assetCatalogs:new Map,preparedCandidates:new Map}})}function vc(e){if(e===null||typeof e!="object"||!(qt in e))throw new TypeError("scanCache must be created by createWorkspaceAppScanCache");return e[qt]}function $o(e,n){let t=vc(e),i=t.rootIdentity;return i!==void 0&&(i.dev!==n.dev||i.ino!==n.ino||i.realPath!==n.realPath)&&(t.candidates.clear(),t.assetCatalogs.clear(),t.preparedCandidates.clear(),t.lastCandidateScanUnchanged=void 0,t.lastCandidateKeys=void 0,t.scanStartedAtNs=void 0,t.lastAssetCatalogsUnchanged=void 0,t.lastSnapshot=void 0,t.lastSnapshotBuildInputs=void 0,t.lastSnapshotCandidates=void 0,t.lastSnapshotCatalogFingerprint=void 0),t.rootIdentity=n,t}var qt,Jo=w(()=>{g();qt=Symbol("crewx.workspace-app-scan-cache.state");});function re(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new _("NOT_FOUND"):n==="ELOOP"?new _("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new _("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new _("READ_DENIED"):new _("READ_DENIED")}function Bc(e){if(typeof e!="string"||e.length===0||!path.isAbsolute(e))throw new _("READ_DENIED")}function Zt(e){if(typeof e!="string"||path.isAbsolute(e)||/[\\\u0000]/.test(e))throw new _("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new _("PATH_ESCAPED");return n}function qn(e,n){let t=path.relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${path.sep}`)&&!path.isAbsolute(t)}function qe(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function ti(e,n){return e.dev===n.dev&&e.ino===n.ino}function ii(e,n){return ti(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function Xn(e){Bc(e);let n,t;try{n=await promises.realpath(e),t=await promises.stat(n,{bigint:!0});}catch(i){throw re(i)}if(!t.isDirectory())throw new _("READ_DENIED");return {realRoot:n,identity:qe(t)}}async function Ko(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,r;try{if(i=path.resolve(e,t[0],t[1]),r=await promises.realpath(i),!(await promises.stat(r,{bigint:!0})).isDirectory())throw new _("READ_DENIED")}catch(o){throw o instanceof _?o:re(o)}if(!qn(n,r))throw new _("PATH_ESCAPED");return r}async function Kn(e,n,t,i){let r,o,a;try{r=await promises.lstat(e,{bigint:!0}),o=await promises.realpath(e),a=await promises.stat(o,{bigint:!0});}catch(s){throw re(s)}if(!qn(n,o)||t!==void 0&&!qn(t,o))throw new _("PATH_ESCAPED");if(!r.isFile()||!a.isFile())throw new _("READ_DENIED");if(!ti(i,r)||!ti(i,a)||i.dev!==a.dev)throw new _("PATH_ESCAPED")}async function Ye(e,n){let t,i;try{t=await promises.realpath(e),i=await promises.stat(t,{bigint:!0});}catch{throw new _("PATH_ESCAPED")}if(t!==n.realRoot||!ii(n.identity,qe(i)))throw new _("PATH_ESCAPED")}function Hc(e){return e.isSymbolicLink()?{name:e.name,kind:"symlink"}:e.isDirectory()?{name:e.name,kind:"directory"}:e.isFile()?{name:e.name,kind:"file"}:{name:e.name,kind:"other"}}var _,ni,Fc,Xo,Ze,Zn,Yo,qo,ri=w(()=>{g();_=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},ni=fs$1.constants.O_NOFOLLOW,Fc=fs$1.constants.O_NONBLOCK,Xo=fs$1.constants.O_RDONLY|(ni??0)|(Fc??0);Ze=class{async getRootIdentity(n){let t=await Xn(n);return await Ye(n,t),{dev:t.identity.dev,ino:t.identity.ino,realPath:t.realRoot}}async listDirectory(n,t){let i=Zt(t),r=await Xn(n),o=path.resolve(n,...i),a,s;try{a=await promises.realpath(o),s=await promises.stat(a,{bigint:!0});}catch(c){let d=re(c);if(d.code==="NOT_FOUND")return [];throw d}if(!qn(r.realRoot,a)||!s.isDirectory())throw new _("PATH_ESCAPED");try{let c=await promises.readdir(a,{withFileTypes:!0,encoding:"utf8"});return await Ye(n,r),c.map(Hc)}catch(c){let d=re(c);if(d.code==="NOT_FOUND")return [];throw d}}async readdir(n,t){return this.listDirectory(n,t)}async readDirectory(n,t){return this.listDirectory(n,t)}async readVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new _("READ_DENIED");if(ni===void 0)throw new _("UNSUPPORTED");let r=Zt(t),o=await Xn(n),a=path.resolve(n,...r),s=path.relative(n,a);if(s===".."||s.startsWith(`..${path.sep}`)||path.isAbsolute(s))throw new _("PATH_ESCAPED");let c;try{c=await promises.open(a,Xo);}catch(d){throw re(d)}try{let d;try{let I=await c.stat({bigint:!0});d=qe(I);}catch(I){throw re(I)}if(d.size>BigInt(i))throw new _("LIMIT_EXCEEDED");if(d.size>BigInt(Number.MAX_SAFE_INTEGER))throw new _("LIMIT_EXCEEDED");await Ye(n,o);let l=await Ko(n,o.realRoot,r);await Kn(a,o.realRoot,l,d);let p=new Uint8Array(new ArrayBuffer(Number(d.size))),u=0;for(;u<p.byteLength;){let I;try{I=(await c.read(p,u,p.byteLength-u,u)).bytesRead;}catch(h){throw re(h)}if(I<=0)throw new _("IDENTITY_CHANGED");u+=I;}let A;try{let I=await c.stat({bigint:!0});A=qe(I);}catch(I){throw re(I)}if(!ii(d,A))throw new _("IDENTITY_CHANGED");return await Kn(a,o.realRoot,l,A),await Ye(n,o),new Uint8Array(p)}finally{await c.close().catch(()=>{});}}async fingerprintVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new _("READ_DENIED");if(ni===void 0)throw new _("UNSUPPORTED");let r=Zt(t),o=await Xn(n),a=path.resolve(n,...r),s=path.relative(n,a);if(s===".."||s.startsWith(`..${path.sep}`)||path.isAbsolute(s))throw new _("PATH_ESCAPED");let c;try{c=await promises.open(a,Xo);}catch(d){throw re(d)}try{let d;try{let u=await c.stat({bigint:!0});d=qe(u);}catch(u){throw re(u)}if(d.size>BigInt(i)||d.size>BigInt(Number.MAX_SAFE_INTEGER))throw new _("LIMIT_EXCEEDED");await Ye(n,o);let l=await Ko(n,o.realRoot,r);await Kn(a,o.realRoot,l,d);let p;try{let u=await c.stat({bigint:!0});p=qe(u);}catch(u){throw re(u)}if(!ii(d,p))throw new _("IDENTITY_CHANGED");return await Kn(a,o.realRoot,l,p),await Ye(n,o),{...p,candidateRealPath:l??o.realRoot}}catch(d){throw d instanceof _?d:re(d)}finally{await c.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},Zn=new Ze,Yo=Zn,qo=Ze;});function _n(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function Qo(e){return typeof e=="string"&&Ie.test(e)?e:void 0}function Kc(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function ve(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let a=t[o]-i[o];if(a!==0)return a}return t.byteLength-i.byteLength}function Yc(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function qc(e){if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("filesystem port returned an invalid byte array")}function Zc(e){return Wc.decode(e)}function Qc(e){return JSON.parse(Zc(e))}function er(e){switch(e){case "ENOENT":return "NOT_FOUND";case "ELOOP":case "EXDEV":return "PATH_ESCAPED";case "EFBIG":case "EOVERFLOW":return "LIMIT_EXCEEDED";case "EACCES":case "EPERM":case "ENOTDIR":return "READ_DENIED";default:return e}}function ed(e){if(e instanceof _)return er(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return er(n)}}function Ne(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function nd(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function td(e){if(typeof e.listDirectory=="function")return e.listDirectory;if(typeof e.readDirectory=="function")return e.readDirectory;if(typeof e.readdir=="function")return e.readdir}async function nr(e,n,t,i){let r=nd(e);if(!r)throw new _("READ_DENIED");return qc(await r.call(e,n,t,i))}async function ci(e,n,t){let i=td(e);if(!i)throw new _("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new _("READ_DENIED");return r.map(Yc).filter(o=>o!==null)}function id(e,n,t,i){return Object.freeze({code:e,...{},source:n,relativePath:t})}function od(e){if(!_n(e))throw new TypeError("productBundle.reservedIds must be an object with appIds and definitionIds arrays");try{let n=Reflect.ownKeys(e);if(n.length!==2||!n.includes("appIds")||!n.includes("definitionIds"))throw new TypeError("productBundle.reservedIds must contain exactly appIds and definitionIds");let t=(i,r)=>{if(!Array.isArray(i))throw new TypeError("productBundle.reservedIds."+r+" must be an array");let o=[];for(let a=0;a<i.length;a+=1){let s=i[a];if(typeof s!="string"||s.length===0)throw new TypeError("productBundle.reservedIds."+r+" must contain non-empty strings");o.push(s);}return Object.freeze([...new Set(o)].sort(ve))};return Object.freeze({appIds:t(e.appIds,"appIds"),definitionIds:t(e.definitionIds,"definitionIds")})}catch(n){throw n instanceof TypeError?n:new TypeError("productBundle.reservedIds must be a valid reservation object")}}function rd(e,n){return e.appIds.length===n.appIds.length&&e.appIds.every((t,i)=>t===n.appIds[i])&&e.definitionIds.length===n.definitionIds.length&&e.definitionIds.every((t,i)=>t===n.definitionIds[i])}function Tn(e){return Object.freeze({appIds:Object.freeze([...new Set(e.map(n=>n.appId))].sort(ve)),definitionIds:Object.freeze([...new Set(e.map(n=>n.definition.id))].sort(ve))})}function Qn(e,n){let t=Object.keys(e).sort(ve),i=[...n].sort(ve);return t.length===i.length&&t.every((r,o)=>r===i[o])}function tr(e){if(typeof e!="string"||e.length===0||e.startsWith("/")||/[\\\u0000]/.test(e))return;let n=e.split("/");if(!n.some(t=>t.length===0||t==="."||t===".."))return n}function sd(e){let n;try{n=Qc(e);}catch{return}if(!_n(n)||!Qn(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>di)return;let t=new Set,i=new Set,r=0,o=[];for(let a of n.packages){if(!_n(a))return;let s=["packageDir","appId","definition","files"],c=Object.hasOwn(a,"lineage"),d=Object.hasOwn(a,"launcher"),l=[...c?["lineage"]:[],...d?["launcher"]:[]];if(!Qn(a,[...s,...l])||d&&a.launcher!==false)return;let p=tr(a.packageDir),u=Qo(a.appId);if(!p||p.length!==2||p[0]!=="apps"||!Kc(p[1])||!u||t.has(a.packageDir)||!_n(a.definition)||!Qn(a.definition,["id","version","hash"]))return;let A=Qo(a.definition.id),I=a.definition.version,h=a.definition.hash;if(!A||!Number.isSafeInteger(I)||I<1||typeof h!="string"||!ai.test(h)||!Array.isArray(a.files)||a.files.length<2||a.files.length>pi)return;let N=new Set,F=[];for(let v of a.files){if(!_n(v)||!Qn(v,["path","sha256"]))return;let b=tr(v.path);if(!b||typeof v.sha256!="string"||!ai.test(v.sha256))return;let C=b.join("/"),G=`${a.packageDir}/${C}`;if(N.has(C)||i.has(G))return;N.add(C),i.add(G),F.push(Object.freeze({path:C,sha256:v.sha256}));}if(!pe.some(v=>N.has(v))||!N.has("ui/index.html")||(r+=F.length,r>Gc))return;t.add(a.packageDir),o.push(Object.freeze({packageDir:a.packageDir,...d?{launcher:false}:{},appId:u,definition:Object.freeze({id:A,version:I,hash:h}),lineage:Array.isArray(a.lineage)?a.lineage:[],files:Object.freeze(F.sort((v,b)=>ve(v.path,b.path)))}));}return Object.freeze({version:1,packages:Object.freeze(o)})}function xe(e){let n=ed(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function ad(e,n,t,i,r){let o=[],a=async(s,c)=>{if(!Ne(i,r))throw new _("LIMIT_EXCEEDED");if(c>2)throw new _("LIMIT_EXCEEDED");let d=await ci(e,n,s);for(let l of d){if(typeof l.name!="string"||l.name.length===0||l.name==="."||l.name===".."||/[\\/\u0000]/.test(l.name))throw new _("PATH_ESCAPED");let p=`${s}/${l.name}`;if(l.kind==="file"){if(o.push(p.slice(t.length+1)),o.length>pi)throw new _("LIMIT_EXCEEDED")}else if(l.kind==="directory")await a(p,c+1);else throw l.kind==="symlink"?new _("PATH_ESCAPED"):new _("READ_DENIED")}};return await a(t,0),o.sort(ve)}function cd(e){return pe.includes(e)?262144:e==="ui/index.html"?Ke:e==="ui/state.json"?2097152:e.startsWith("ui/assets/")?Jc:$c}async function ir(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false,reservedIds:Xc};let r=od(e.reservedIds),o=[],a=(y,m,E)=>id(y,"bundled",m),s=(y=[],m=false,E)=>({...E===void 0?{}:{indexHash:E},packages:y,diagnostics:o,incomplete:m,reservedIds:r});if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!ai.test(e.expectedIndexHash))return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();let c;try{c=await nr(n,e.root,"bundle-index.json",zc);}catch(y){return o.push(a(xe(y),"bundle-index.json")),s()}let d=crypto.createHash("sha256").update(c).digest("hex");if(d!==e.expectedIndexHash)return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();let l=sd(c);if(l===void 0)return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();if(!rd(Tn(l.packages),r))return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s([],false,d);if(!Ne(t,i))return o.push(a("LIMIT_EXCEEDED","bundle-index.json")),s(l.packages.map(y=>({indexEntry:y,failureCode:"LIMIT_EXCEEDED"})),true,d);let p;try{p=await ci(n,e.root,"");}catch(y){return o.push(a(xe(y),"bundle-index.json")),s(l.packages.map(m=>({indexEntry:m,failureCode:xe(y)})),false,d)}if(!Ne(t,i))return o.push(a("LIMIT_EXCEEDED","bundle-index.json")),s(l.packages.map(y=>({indexEntry:y,failureCode:"LIMIT_EXCEEDED"})),true,d);let u=p.find(y=>y.name==="bundle-index.json"&&y.kind==="file"),A=p.find(y=>y.name==="apps"&&y.kind==="directory"),I=y=>l.packages.map(m=>({indexEntry:m,failureCode:y}));if(!u)return o.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s(I("BUNDLE_INTEGRITY"),false,d);let h=p.filter(y=>y.name!=="bundle-index.json"&&y.name!=="apps");if(h.length>0){let y=h.some(m=>m.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return o.push(a(y,"bundle-index.json")),s(I("BUNDLE_INTEGRITY"),false,d)}if(p.some(y=>y.name==="apps"&&y.kind!=="directory"))return o.push(a("PATH_ESCAPED","apps")),s(I("PATH_ESCAPED"),false,d);let N=[];if(A)try{N=await ci(n,e.root,"apps");}catch(y){return o.push(a(xe(y),"apps")),s(I(xe(y)),false,d)}if(!Ne(t,i)||N.length>di)return o.push(a("LIMIT_EXCEEDED","apps")),s(I("LIMIT_EXCEEDED"),true,d);let F=new Map(l.packages.map(y=>[y.packageDir.slice(5),y])),v=N.filter(y=>!F.has(y.name));for(let y of v)o.push(a(y.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${y.name}`));if(v.length>0){let y=v.some(m=>m.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return s(I(y),false,d)}let b=new Set,C=new Map,G=new Map;for(let y of l.packages){let m=C.get(y.appId)??[];m.push(y),C.set(y.appId,m);let E=`${y.definition.id}\0${String(y.definition.version)}`,P=G.get(E)??[];P.push(y),G.set(E,P);}for(let y of [...C.values(),...G.values()])if(y.length>1)for(let m of y)b.add(m);let D=[],M=c.byteLength,S=false;for(let y of l.packages){if(!Ne(t,i)){S=true,D.push({indexEntry:y,failureCode:"LIMIT_EXCEEDED"});continue}let m;try{let L=y.lineage[y.lineage.length-1];if(!L)throw new Te("LINEAGE_INVALID","Definition lineage is missing");if(L.definition.id!==y.definition.id||L.version!==y.definition.version||L.hash!==y.definition.hash)throw new Te("LINEAGE_STALE","Last lineage generation does not match bundle identity");m=Jt(y.lineage,{...L.definition,hash:L.hash}).entries;}catch(L){let O=L instanceof Te?L.code:"LINEAGE_INVALID";o.push(a(O,y.packageDir)),D.push({indexEntry:y,failureCode:O});continue}let E=N.find(L=>L.name===y.packageDir.slice(5));if(!A||!E){D.push({indexEntry:y,failureCode:"BUNDLE_INTEGRITY"});continue}if(E.kind!=="directory"){D.push({indexEntry:y,failureCode:E.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let P;try{let L=await ad(n,e.root,y.packageDir,t,i);if(!Ne(t,i)){S=!0,D.push({indexEntry:y,failureCode:"LIMIT_EXCEEDED"});continue}let O=y.files.map(B=>B.path);if(L.length!==O.length||L.some((B,Pe)=>B!==O[Pe])){D.push({indexEntry:y,failureCode:"BUNDLE_INTEGRITY"});continue}P=new Map;let q;for(let B of y.files){if(!Ne(t,i)){q="LIMIT_EXCEEDED",S=!0;break}if(M>=si){q="LIMIT_EXCEEDED";break}let Pe;try{Pe=await nr(n,e.root,`${y.packageDir}/${B.path}`,cd(B.path));}catch(ot){q=xe(ot);break}if(!Ne(t,i)){q="LIMIT_EXCEEDED",S=!0;break}if(M+Pe.byteLength>si){M=si,q="LIMIT_EXCEEDED";break}if(M+=Pe.byteLength,crypto.createHash("sha256").update(Pe).digest("hex")!==B.sha256){q="BUNDLE_INTEGRITY";break}P.set(B.path,Pe);}if(q!==void 0){D.push({indexEntry:y,failureCode:q});continue}}catch(L){Ne(t,i)||(S=true),D.push({indexEntry:y,failureCode:xe(L)});continue}D.push({indexEntry:y,lineage:m,files:P,...b.has(y)?{failureCode:"DUPLICATE_ID"}:{}});}return s(D,S,d)}var zc,di,pi,Gc,$c,Jc,si,ai,Wc,Xc,li=w(()=>{g();Wt();Re();Bt();Wn();ri();zc=256*1024,di=64,pi=128,Gc=di*pi,$c=2*1024*1024,Jc=8*1024*1024,si=32*1024*1024,ai=/^[0-9a-f]{64}$/,Wc=new TextDecoder("utf-8",{fatal:true}),Xc=Object.freeze({appIds:Object.freeze([]),definitionIds:Object.freeze([])});});var Pr={};kr(Pr,{AppDiscoveryFsError:()=>_,LOCAL_APP_TOOL_PREFIX:()=>ld,MCP_APP_WORKSPACE_TOOL_PREFIX:()=>ud,NodeAppDiscoveryFs:()=>Ze,NodeAppDiscoveryFsAdapter:()=>qo,WORKSPACE_APP_TOOL_PREFIX:()=>Qe,createWorkspaceAppScanCache:()=>Go,defaultAppDiscoveryFs:()=>Zn,defaultNodeAppDiscoveryFs:()=>Yo,deriveWorkspaceAppToolName:()=>fd,deriveWorkspaceAppToolNames:()=>yi,discoverWorkspaceAppCandidates:()=>Hd,discoverWorkspaceApps:()=>Ai,isWorkspacePackage:()=>pd,productAppBundleReservations:()=>Tn,scanWorkspaceApps:()=>zd});function pd(e,n){let t=n.split("/");return t.length===2&&t[0]===e&&/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t[1])}function yi(e){if(typeof e!="string"||!Ie.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Qe}${e}`.length+7<=128?e:`hash_${crypto.createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Qe}${n}_read`,action:`${Qe}${n}_action`}}function fd(e,n="read"){let t=yi(e);return n==="read"?t.read:t.action}function rr(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function Ad(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function Id(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Dn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let a=t[o]-i[o];if(a!==0)return a}return t.byteLength-i.byteLength}function Ir(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function gd(e){if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("filesystem port returned an invalid byte array")}function gr(e){return yd.decode(e)}function md(e){return JSON.parse(gr(e))}function hd(e){if(e===void 0)return;let n=e.definitionId!==void 0&&e.definitionVersion!==void 0?`${e.definitionId}\0${String(e.definitionVersion)}`:void 0;return {pluginId:e.pluginId,...n===void 0?{}:{definitionKey:n}}}function et(e,n,t,i,r){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t,...r?.reason===void 0?{}:{reason:Object.freeze({...r.reason})},...r?.files===void 0?{}:{files:Object.freeze([...r.files])}};return Object.freeze(o)}function sr(e){switch(e){case "ENOENT":return "NOT_FOUND";case "ELOOP":case "EXDEV":return "PATH_ESCAPED";case "EFBIG":case "EOVERFLOW":return "LIMIT_EXCEEDED";case "EACCES":case "EPERM":case "ENOTDIR":return "READ_DENIED";default:return e}}function ne(e){if(e instanceof _)return sr(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return sr(n)}}function Ve(e,n){return e==="PATH_ESCAPED"||e==="IDENTITY_CHANGED"||e==="TOCTOU"?"PATH_ESCAPED":e==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":n==="manifest"&&e==="NOT_FOUND"?"MANIFEST_MISSING":n==="entry"?"ENTRY_INVALID":n==="initial"?"INITIAL_STATE_INVALID":"MANIFEST_INVALID"}function ar(e){return {reason:e.reason,...e.code==="MANIFEST_DUAL_MISMATCH"?{files:e.files}:{}}}function cr(e){return e==="MANIFEST_DUAL_MISMATCH"?e:mr(e)}function _d(e){return mr(e.code)}function mr(e){switch(e){case "MANIFEST_INVALID":case "PRIMITIVE_UNKNOWN":case "PRIMITIVE_SET_UNSUPPORTED":case "SCHEMA_TYPE_UNSUPPORTED":case "TOKEN_INVALID":case "UNSAFE_VALUE":return "MANIFEST_INVALID";case "LIMIT_EXCEEDED":return "LIMIT_EXCEEDED";case "INITIAL_STATE_INVALID":return "INITIAL_STATE_INVALID";default:return hr("UiPluginValidationError",e)}}function hr(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function _r(e){switch(e){case "APP_ID_INVALID":case "TOOL_ID_INVALID":case "RESOURCE_URI_INVALID":case "TOOL_INVALID":case "SERIALIZATION_INVALID":return "MANIFEST_INVALID";case "APP_ID_CONFLICT":case "TOOL_ID_CONFLICT":return "DUPLICATE_ID";case "RESOURCE_NOT_FOUND":case "HTML_INVALID":return "ENTRY_INVALID";case "STATE_INVALID":case "STATE_PROJECTION_INVALID":case "BUTTON_INVALID":return "INITIAL_STATE_INVALID";default:return hr("McpAppContractError",e)}}function be(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Td(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function Ed(e,n){let t=n.get("package.json");if(t!==void 0)try{let r=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t));if(rr(r)){let o=r.bin,a=typeof o=="string"?o:rr(o)?Object.values(o).find(s=>typeof s=="string"):void 0;for(let s of [a,r.main]){if(typeof s!="string")continue;let c=Dd(s);if(c&&n.has(c))return c}}}catch{}return [`${e.slice(e.lastIndexOf("/")+1)}.js`,"index.js","main.js"].find(r=>n.has(r))}function Dd(e){if(e.startsWith("/")||e.includes("\\")||e.includes("\0"))return;let n=e.split("/").filter(t=>t!==".");if(!(n.length===0||n.some(t=>t.length===0||t==="..")))return n.join("/")}function Nd(){return globalThis.performance?.now()??Date.now()}function je(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))je(n);return Object.freeze(e)}function dr(e){return Object.freeze(Array.from(e))}async function Nn(e,n,t,i){if(n.pinnedFiles!==void 0){let s=n.pinnedFiles.get(t);if(s===void 0)throw new _("NOT_FOUND");if(s.byteLength>i)throw new _("LIMIT_EXCEEDED");return new Uint8Array(s)}let r=`${n.relativePath}/${t}`,o=n.scanContext,a=e.fingerprintVerifiedFile;if(o===void 0||!o.cacheable||typeof a!="function")return fr(e,n.root,r,i);try{let s=o.priorFingerprints.get(r)??await a.call(e,o.workspaceRoot,r,i);o.candidateRealPath=s.candidateRealPath;let c=await fr(e,n.root,r,i),d=await a.call(e,o.workspaceRoot,r,i);return o.candidateRealPath=d.candidateRealPath,Er(s,d)&&d.size===BigInt(c.byteLength)&&!Dr(d,o.scanStartedAtNs)?o.files.set(r,{relativePath:r,byteLimit:i,fingerprint:d}):o.cacheable=!1,c}catch(s){let c=!t.includes("/")&&ne(s)==="NOT_FOUND"&&o.directoryListings.some(l=>l.relativePath===n.relativePath&&!nt(l.key,t)),d=t===K&&ne(s)==="NOT_FOUND"&&Pd(o.directoryListings,n.relativePath);throw !c&&!d&&(o.cacheable=false),s}}async function bd(e,n,t){if(n.pinnedFiles!==void 0)return {iconDiagnostics:[]};let i=await zt(t,async o=>{try{return await Nn(e,n,o,262144)}catch(a){let s=ne(a);return s==="NOT_FOUND"?"missing":s==="LIMIT_EXCEEDED"?"too-large":"bad-path"}}),r=i.file;return {...r===void 0?{}:{iconFile:{path:r.path,sha256:crypto.createHash("sha256").update(r.bytes).digest("hex"),contentType:r.contentType,byteLength:r.byteLength}},iconDiagnostics:i.diagnostics}}function Pd(e,n){let t=e.find(r=>r.relativePath===n);if(t===void 0)return false;if(!nt(t.key,"dist"))return true;let i=e.find(r=>r.relativePath===`${n}/dist`);return i!==void 0&&!nt(i.key,"tools.json")}function Tr(e,n){return JSON.stringify([e.realPath,n.source,n.relativePath])}async function Md(e,n,t,i,r,o,a,s){let c=e.fingerprintVerifiedFile,d=Tr(t,i),l=r.candidates.get(d),p=i.relativePath,u;try{u=await ur(e,n,p);}catch(S){if(ne(S)!=="NOT_FOUND")throw S}let A=u===void 0?void 0:{relativePath:p,key:u};if(A!==void 0&&(i.source==="apps"||i.source==="skills")&&!pe.some(S=>nt(A.key,S)))return be(a,s)?l!==void 0&&l.candidate===void 0&&l.candidateRealPath===void 0&&l.files.length===0&&l.directoryListings.length===1&&l.directoryListings[0]?.relativePath===A.relativePath&&l.directoryListings[0]?.key===A.key&&(i.source==="apps"?l.diagnostic?.code==="MANIFEST_MISSING":l.diagnostic===void 0)&&typeof c=="function"?{memo:l}:typeof c!="function"?{}:{context:{state:r,cacheKey:d,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze([A]),priorFingerprints:new Map,files:new Map,cacheable:true}}:{timeLimitReached:true};let I=async S=>{if(S==="")return A;let y=`${i.relativePath}${S}`;try{let m=await ur(e,n,y);return m===void 0?void 0:{relativePath:y,key:m}}catch(m){if(ne(m)==="NOT_FOUND")return;throw m}},h=await Promise.all(pr.map(I)),N=await Promise.all(Sd.map(I));if(!be(a,s))return {timeLimitReached:true};let F=typeof c=="function"&&h.every(S=>S!==void 0),v=h.filter(S=>S!==void 0),b=[...v,...N.filter(S=>S!==void 0)],C=new Map,G=l!==void 0&&F,D;if(l!==void 0&&typeof c=="function"){let S=await Promise.all(l.files.map(async y=>{if(!be(a,s))return {kind:"time",file:y};try{let m=await c.call(e,n,y.relativePath,y.byteLimit);return {kind:"fingerprint",file:y,current:m}}catch(m){return ne(m)==="NOT_FOUND"?{kind:"missing",file:y}:{kind:"error",file:y,error:m}}}));if(S.some(y=>y.kind==="time"))return {timeLimitReached:true};for(let y of S){if(y.kind==="error")throw y.error;if(y.kind==="missing"){G=false;continue}if(y.kind!=="fingerprint")continue;let{file:m,current:E}=y;C.set(m.relativePath,E),D??=E.candidateRealPath,(E.candidateRealPath!==l.candidateRealPath||!Er(E,m.fingerprint)||Dr(E,o))&&(G=false);}}let M=l!==void 0&&l.directoryListings.length===b.length&&l.directoryListings.every((S,y)=>S.relativePath===b[y]?.relativePath&&S.key===b[y]?.key);return l!==void 0&&F&&M&&G&&D===l.candidateRealPath?{memo:l}:!F||v.length!==pr.length?{}:{context:{state:r,cacheKey:d,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze(b),priorFingerprints:C,files:new Map,...D===void 0?{}:{candidateRealPath:D},cacheable:true}}}function nt(e,n){try{let t=JSON.parse(e);return Array.isArray(t)&&t.some(i=>Array.isArray(i)&&i[0]===n)}catch{return true}}async function ur(e,n,t){let i=Nr(e);if(typeof i!="function")return;let r=await i.call(e,n,t);if(!Array.isArray(r)||r.some(a=>typeof a=="string"))return;let o=r.map(Ir);if(!o.some(a=>a===null))return JSON.stringify(o.slice().sort((a,s)=>Dn(a.name,s.name)||Dn(a.kind,s.kind)).map(a=>[a.name,a.kind]))}function Er(e,n){return e.dev===n.dev&&e.ino===n.ino&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}function Dr(e,n){let t=e.mtimeNs-n;return t>=-lr&&t<=lr}function ui(e){let n=e.scanContext,t=e.source==="skills"&&e.candidate===void 0&&e.diagnostic===void 0&&n?.files.size===0,i=e.source==="apps"&&e.candidate===void 0&&e.diagnostic?.code==="MANIFEST_MISSING"&&n?.files.size===0,r=t||i;if(n===void 0||!n.cacheable||n.candidateRealPath===void 0&&!r||n.files.size===0&&!r)return;let o=Object.freeze({...!r&&n.candidateRealPath!==void 0?{candidateRealPath:n.candidateRealPath}:{},directoryListings:n.directoryListings,files:Object.freeze([...n.files.values()]),...e.candidate===void 0?{}:{candidate:e.candidate},...e.diagnostic===void 0?{}:{diagnostic:e.diagnostic},...e.identity===void 0?{}:{identity:e.identity},...e.provenance===void 0?{}:{provenance:e.provenance}});n.state.candidates.set(n.cacheKey,o);}function Ld(e,n,t){let i=crypto.createHash("sha256"),r=new TextEncoder().encode(Z(e)),o=a=>{let s=new Uint8Array(8);new DataView(s.buffer).setBigUint64(0,BigInt(a)),i.update(s);};return o(r.byteLength),i.update(r),o(n.byteLength),i.update(n),o(t.byteLength),i.update(t),i.digest("hex")}function Od(e,n){let t={...e.definition,sourceHash:n},i;try{i=ie(t);}catch(o){throw o instanceof R&&o.code==="INPUT_INVALID"?new oe("MANIFEST_INVALID","normalized definition is invalid"):o}let r={...t,hash:i};try{ce(r);}catch{throw new oe("MANIFEST_INVALID","normalized definition is invalid")}return r}function Rd(e,n){return e.actions.some(t=>t.backend.type==="core"&&t.backend.handler!=="state.set"&&!Bn(n,t.backend))}function Ud(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function Nr(e){if(typeof e.listDirectory=="function")return e.listDirectory;if(typeof e.readDirectory=="function")return e.readDirectory;if(typeof e.readdir=="function")return e.readdir}async function fr(e,n,t,i){let r=Ud(e);if(!r)throw new _("READ_DENIED");return gd(await r.call(e,n,t,i))}async function Cd(e,n,t){let i=Nr(e);if(!i)throw new _("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new _("READ_DENIED");return r.map(Ir).filter(o=>o!==null)}function kd(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(yr(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(yr(e.builtinCatalog)),n.push({...e.reservedAppIds===void 0?{}:{appIds:e.reservedAppIds},...e.reservedDefinitionIds===void 0?{}:{definitionIds:e.reservedDefinitionIds},...e.reservedToolNames===void 0?{}:{toolNames:e.reservedToolNames}}),n}function yr(e){let n=[],t=[],i=[];for(let r of e.listMcpApps())typeof r.appId=="string"&&n.push(r.appId),r.definition&&typeof r.definition.id=="string"&&t.push(r.definition.id);for(let r of e.listMcpAppTools())typeof r.name=="string"&&i.push(r.name);return {appIds:n,definitionIds:t,toolNames:i}}function ye(e,n){e.diagnostic||(e.diagnostic=et(n,e.source,e.relativePath,e.identity?.pluginId));}function wd(e,n){let t=new Set,i=new Map;for(let o of e){let a=o.identity?.pluginId;if(a===void 0)continue;let s=i.get(a)??[];s.push(o),i.set(a,s);}for(let o of i.values()){if(o.length<2)continue;let a=o.filter(c=>c.provenance!==void 0);if(a.length>0){let c=o.find(d=>n.has(d));if(c){for(let d of a)t.add(d);for(let d of o)d!==c&&d.provenance===void 0&&ye(d,"RESERVED_ID");continue}for(let d of o)d.provenance===void 0&&ye(d,"RESERVED_ID");if(a.length>1)for(let d of a)ye(d,"DUPLICATE_ID");continue}let s=o.filter(c=>c.source==="apps");if(s.length>1){for(let c of s)ye(c,"DUPLICATE_ID");for(let c of o.filter(d=>d.source==="skills"))ye(c,"DUPLICATE_ID");}else for(let c of o.filter(d=>d.source==="skills"))ye(c,"DUPLICATE_ID");}let r=new Map;for(let o of e){if(o.diagnostic?.code==="RESERVED_ID"||t.has(o)||o.provenance===void 0&&!n.has(o)&&i.get(o.identity?.pluginId??"")?.some(c=>c.provenance!==void 0))continue;let a=o.identity?.definitionKey;if(a===void 0)continue;let s=r.get(a)??[];s.push(o),r.set(a,s);}for(let o of r.values())if(o.length>1)for(let a of o)ye(a,"DUPLICATE_ID");return t}function xd(e,n,t){let i=new Set,r=new Set,o=new Set,a=new Set([...t.appIds,...n.productBundleReservationMetadata?.reservedAppIds??[]]),s=new Set([...t.definitionIds,...n.productBundleReservationMetadata?.reservedDefinitionIds??[]]);for(let l of kd(n)){for(let p of l.appIds??[])typeof p=="string"&&i.add(p);for(let p of l.definitionIds??[])typeof p=="string"&&r.add(p);for(let p of l.toolNames??[])typeof p=="string"&&o.add(p);}for(let l of e){let p=l.candidate;if(!p)continue;if(i.has(p.pluginId)||r.has(p.definitionId)){ye(l,"RESERVED_ID");continue}[p.toolNames.read,p.toolNames.action].filter(A=>A!==void 0).some(A=>o.has(A))&&ye(l,"DUPLICATE_ID");}let c=[...e.filter(l=>l.provenance!==void 0&&l.diagnostic===void 0).flatMap(l=>l.candidate?[l.candidate]:[]),...(n.productBundleReservationMetadata?.candidates??[]).filter(l=>n.productBundleReservationMetadata?.indexHash!==void 0&&l.provenance?.indexHash===n.productBundleReservationMetadata.indexHash)],d=new Set;for(let l of e){let p=l.candidate;if(!(!p||l.diagnostic||l.source!=="apps"||l.provenance!==void 0)&&e.filter(u=>u.source==="apps"&&u.identity?.pluginId===p.pluginId).length===1&&c.some(u=>u.pluginId===p.pluginId)&&!(s.has(p.definitionId)&&!c.some(u=>u.pluginId===p.pluginId&&u.definitionId===p.definitionId))&&!c.some(u=>u.pluginId!==p.pluginId&&u.definitionId===p.definitionId)&&!e.some(u=>u.identity?.pluginId!==p.pluginId&&u.identity?.definitionKey===`${p.definitionId}\0${p.version}`&&u.diagnostic?.code!=="RESERVED_ID"))try{Ho(p),d.add(l);}catch(u){ye(l,u instanceof _e?_r(u.code):"EXEC_DENIED");}}for(let l of e){let p=l.candidate;p&&l.provenance===void 0&&!d.has(l)&&(a.has(p.pluginId)||s.has(p.definitionId))&&ye(l,"RESERVED_ID");}return d}function vd(e){return [...e].sort((n,t)=>{let i=or.indexOf(n.source)-or.indexOf(t.source);return i!==0?i:Dn(n.relativePath,t.relativePath)})}function j(e,n,t){e.diagnostic=et(n,e.source,e.relativePath,e.identity?.pluginId,t);}async function Ar(e,n,t){let i=Ft(t,{mode:"local"});if(!i.ok&&i.parseFailure){j(n,cr(i.rejection.code),ar(i.rejection));return}let r=hd(i.identity);if(n.bundleIdentity===void 0)n.identity=r;else if(r?.pluginId!==n.bundleIdentity.appId||r.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){j(n,"BUNDLE_INTEGRITY");return}if(!i.ok&&i.builtinOnly){j(n,"RESERVED_ID");return}if(!i.ok){j(n,cr(i.rejection.code),ar(i.rejection));return}let o=i.manifest,a={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=a),o.actions.length>0)try{Yt(o.actions.map(O=>({actionId:O.actionId,inputSchema:O.inputSchema})));}catch(O){if(O instanceof _e){j(n,_r(O.code));return}throw O}let s;try{s=await Nn(e,n,"ui/index.html",Ke);}catch(O){j(n,Ve(ne(O),"entry"));return}if(s.byteLength>Ke){j(n,"LIMIT_EXCEEDED");return}let c;try{c=gr(s);}catch{j(n,"ENTRY_INVALID");return}if(s.byteLength===0||c.length===0){j(n,"ENTRY_INVALID");return}let d=crypto.createHash("sha256").update(s).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==d){j(n,"ENTRY_INVALID");return}let l={},p,u;if(o.initialState!==void 0){try{p=await Nn(e,n,"ui/state.json",2097152);}catch(O){j(n,Ve(ne(O),"initial"));return}if(p.byteLength>2097152){j(n,"LIMIT_EXCEEDED");return}try{let O=md(p),q=o.dataPaths??[],B=Rt(O,q);l=ae(B,0,q),He(l);}catch{j(n,"INITIAL_STATE_INVALID");return}if(u=crypto.createHash("sha256").update(p).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==u){j(n,"INITIAL_STATE_INVALID");return}}let A={...o,entryHash:d,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:u}}},I=an(A),h=Ld(A,s,p??new Uint8Array),N;try{N=Od(I,h);}catch(O){if(O instanceof oe){j(n,_d(O));return}throw O}let F;if(n.bundleLineage!==void 0){let O=n.bundleLineage[n.bundleLineage.length-1];if(!O){j(n,"LINEAGE_INVALID");return}let{legacy:q,...B}=O.definition,{hash:Pe,...ot}=N;if(Z(B)!==Z(ot)){j(n,"LINEAGE_STALE");return}if(q!==void 0&&(N={...N,legacy:q}),q!==void 0)try{N={...N,hash:ie(N)},ce(N);}catch{j(n,"LINEAGE_INVALID");return}F=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){j(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==N.id||n.bundleIdentity.version!==N.version||n.bundleIdentity.definitionHash!==N.hash)){j(n,"LINEAGE_STALE");return}let v=await bd(e,n,i.mcpb?.icon),b=yi(o.pluginId),C=o.actions.length===0?{read:b.read}:b,G=je(I),D=je(A),M=je(N),S=je({...I.handlers}),y=dr(s),m=p===void 0?void 0:dr(p),E=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:d,bytes:y}),...m===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:u,bytes:m})}}),P={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,...i.releaseVersion===void 0?{}:{releaseVersion:i.releaseVersion},manifestFile:i.file,...i.mcpb===void 0?{}:{mcpb:je(i.mcpb)},relativePath:n.relativePath,manifest:D,normalized:G,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},...v.iconFile===void 0?{}:{iconFile:Object.freeze({...v.iconFile})},...v.iconDiagnostics.length===0?{}:{iconDiagnostics:Object.freeze([...v.iconDiagnostics])},definition:M,handlers:S,resources:E,html:c,entryBytes:y,entryHash:d,initialState:je(l),...m===void 0?{}:{initialStateBytes:m},...u===void 0?{}:{initialStateHash:u},sourceHash:h,toolNames:Object.freeze(C)},L=n.provenance===void 0?{...P,source:n.source}:{...P,provenance:n.provenance,lineage:F??[]};n.candidate=Object.freeze(L),Rd(o,N.usage)&&j(n,"EXEC_DENIED");}async function br(e,n){let t={};for(let i of pe)try{t[i]=await Nn(e,n,i,262144);}catch(r){if(ne(r)==="NOT_FOUND")continue;return {files:t,failure:Ve(ne(r),"manifest")}}if(t[X]!==void 0)try{t[K]=await Nn(e,n,K,262144);}catch(i){if(ne(i)!=="NOT_FOUND")return {files:t,failure:Ve(ne(i),"manifest")}}return {files:t}}function fi(e){return pe.some(n=>e[n]!==void 0)}async function jd(e,n){let{files:t,failure:i}=await br(e,n);if(i!==void 0){j(n,i);return}let r=t[X];return r!==void 0&&!Vt(r)&&(delete t[X],delete t[K]),fi(t)?t:void 0}function Vd(e,n,t,i=dd,r=false,o=new Set){let a=vd(e),s=wd(a,o),c=Object.freeze(a.filter(u=>u.candidate!==void 0&&u.diagnostic===void 0&&!s.has(u)).map(u=>u.candidate)),d=Object.freeze(a.filter(u=>u.diagnostic!==void 0).map(u=>u.diagnostic)),l=r?Object.freeze({...t===void 0?{}:{indexHash:t},candidates:Object.freeze(a.filter(u=>u.source==="bundled"&&u.diagnostic===void 0&&t!==void 0&&u.candidate?.provenance?.indexHash===t).map(u=>u.candidate)),diagnostics:Object.freeze(d.filter(u=>u.source==="bundled").map(u=>Object.freeze({...u}))),reservedAppIds:Object.freeze([...i.appIds]),reservedDefinitionIds:Object.freeze([...i.definitionIds])}):void 0,p={apps:c,diagnostics:d,complete:n===void 0,...n===void 0?{}:{incompleteReason:n},...t===void 0?{}:{productBundleIndexHash:t},...l===void 0?{}:{productBundleSnapshotMetadata:l}};return Object.defineProperty(p,"candidates",{configurable:false,enumerable:false,get:()=>c}),Object.freeze(p)}function Fd(e){if(e===null||typeof e!="object"&&typeof e!="function")return false;let n=e;return typeof n.readVerifiedFile=="function"||typeof n.readFileVerified=="function"||typeof n.listDirectory=="function"||typeof n.readDirectory=="function"||typeof n.readdir=="function"}function Bd(e,n){if(Fd(e))return {fs:e,options:n??{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??Zn,options:t}}async function Ai(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:r}=Bd(n,t),o=r.clock??Nd,a=o(),s=await ir(r.productBundle,i,a,o),c=o(),d=BigInt(Date.now())*1000000n,l=[],p=0,u,A=false,I,h;if(r.scanCache!==void 0&&typeof i.getRootIdentity=="function"&&typeof i.fingerprintVerifiedFile=="function")try{h=await i.getRootIdentity(e),I=$o(r.scanCache,h),I.scanStartedAtNs=d;}catch(D){if(ne(D)!=="NOT_FOUND")throw D}let N=I!==void 0&&r.productBundle===void 0&&s.packages.length===0&&s.diagnostics.length===0,F=new Set,v=true;l.push(...s.diagnostics.map(D=>({source:D.source,root:r.productBundle?.root??e,name:"",relativePath:D.relativePath,diagnostic:D})));let b=s.reservedIds;s.incomplete&&(u="time_limit");for(let D of s.packages){if(!be(c,o)){A=true,u="time_limit";break}let M=D.indexEntry,S=M.packageDir,y=D.files===void 0?void 0:Ed(S,D.files),m=s.indexHash===void 0?void 0:go(Object.freeze({kind:"bundled",launcher:M.launcher!==false,indexHash:s.indexHash,packageDir:S,appId:M.appId,definitionId:M.definition.id,version:M.definition.version,definitionHash:M.definition.hash,files:M.files}),y),E={source:"bundled",root:r.productBundle?.root??e,name:S.slice(5),relativePath:S,...m===void 0?{}:{provenance:m},...D.files===void 0?{}:{pinnedFiles:D.files},...D.lineage===void 0?{}:{bundleLineage:D.lineage},bundleIdentity:{appId:M.appId,definitionId:M.definition.id,version:M.definition.version,definitionHash:M.definition.hash},identity:Td(M)};if(l.push(E),p+=1,D.failureCode!==void 0){j(E,D.failureCode);continue}if(D.files?.has(K)===true){j(E,"EXEC_DENIED",{reason:{path:"",rule:"bundled-tool-mode-unsupported",file:K}});continue}let P={};for(let L of pe){let O=D.files?.get(L);O!==void 0&&(P[L]=O);}if(!fi(P)){j(E,"BUNDLE_INTEGRITY");continue}if(await Ar(i,E,P),!be(c,o)){A=true,u="time_limit";break}}let C=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];e:for(let D of C){let{source:M,directory:S}=D,y;try{y=await Cd(i,e,S);}catch(E){if(ne(E)==="NOT_FOUND")continue;N=false,v=false,l.push({source:M,root:e,name:"",relativePath:M,diagnostic:et(Ve(ne(E),"manifest"),M,M)});continue}let m=y.filter(E=>E.kind==="directory"||E.kind==="symlink").filter(E=>Id(E.name)).map(E=>({source:M,root:e,name:E.name,relativePath:Ad(M,E.name)})).sort((E,P)=>Dn(E.relativePath,P.relativePath));for(let E of m){let P={...E};if(l.push(P),h!==void 0?F.add(Tr(h,P)):N=false,!be(c,o)){A=true,u="time_limit";break e}let L;if(I!==void 0&&h!==void 0){try{let B=await Md(i,e,h,P,I,d,c,o);if(B.timeLimitReached){A=!0,u="time_limit";break e}P.scanContext=B.context,L=B.memo;}catch(B){N=false,j(P,Ve(ne(B),"manifest"));continue}L===void 0&&(N=false);}if(L!==void 0){if(P.candidate=L.candidate,P.diagnostic=L.diagnostic,P.identity=L.identity,M==="skills"&&L.candidate===void 0&&L.diagnostic===void 0)continue;if(p>=64){j(P,"LIMIT_EXCEEDED");continue}if(E.relativePath.split("/").length-1>2){j(P,"LIMIT_EXCEEDED");continue}if(p+=1,!be(c,o)){A=true,u="time_limit";break e}continue}let O;if(M==="skills"&&(O=await jd(i,P),O===void 0)){P.diagnostic===void 0&&ui(P);continue}if(p>=64){j(P,"LIMIT_EXCEEDED");continue}if(E.relativePath.split("/").length-1>2){j(P,"LIMIT_EXCEEDED");continue}if(!be(c,o)){A=true,u="time_limit";break e}if(p+=1,O===void 0){let B=await br(i,P);if(B.failure!==void 0||!fi(B.files)){j(P,B.failure??Ve("NOT_FOUND","manifest")),ui(P);continue}O=B.files;}if(await Ar(i,P,O),ui(P),!be(c,o)){A=true,u="time_limit";break e}}}if(I!==void 0&&h!==void 0){let D=[...F].sort(Dn),M=I.lastCandidateKeys,S=M!==void 0&&M.length===D.length&&M.every((m,E)=>m===D[E]);if(N=N&&S,v&&!A&&u===void 0)for(let m of I.candidates.keys())try{JSON.parse(m)[0]===h.realPath&&!F.has(m)&&I.candidates.delete(m);}catch{I.candidates.delete(m);}let y=[...I.candidates.keys()].filter(m=>{try{return JSON.parse(m)[0]===h.realPath}catch{return false}});N=N&&y.length===F.size&&y.every(m=>F.has(m))&&!A&&u===void 0,I.lastCandidateScanUnchanged=N,v&&!A&&u===void 0&&(I.lastCandidateKeys=Object.freeze(D));}A&&l.push({source:"apps",root:e,name:"",relativePath:"apps",diagnostic:et("DISCOVERY_TIME_LIMIT","apps","apps")});let G=xd(l,r,b);return Vd(l,u,s.indexHash,b,r.productBundle!==void 0,G)}var dd,Qe,ld,ud,or,yd,pr,Sd,lr,Hd,zd,Sr=w(()=>{g();Ue();bn();Ee();fo();Gt();Re();Wn();zo();Hn();Vn();Jo();ri();Fn();li();li();dd=Tn([]);Qe="crewx_local_app_",ld=Qe,ud=Qe;or=["bundled","apps","skills"],yd=new TextDecoder("utf-8",{fatal:true});pr=["","/ui"],Sd=["/dist"],lr=2000000000n;Hd=Ai,zd=Ai;});g();var Mr="SKILL.md",Xd=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function Lr(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Kd(e){return e.isDirectory()||e.isSymbolicLink()}function Ur(e){try{return fs$1.existsSync(e)&&fs$1.statSync(e).isDirectory()}catch{return false}}var Yd=["index.js","main.js"];function rf(e,n){let t=path.join(e,"package.json");if(fs$1.existsSync(t))try{let r=JSON.parse(fs$1.readFileSync(t,"utf8"));if(r.bin){let o=typeof r.bin=="string"?r.bin:Object.values(r.bin).find(a=>typeof a=="string");if(o){let a=path.resolve(e,o);if(fs$1.existsSync(a))return a}}if(typeof r.main=="string"){let o=path.resolve(e,r.main);if(fs$1.existsSync(o))return o}}catch{}let i=path.resolve(e,`${n}.js`);if(fs$1.existsSync(i))return i;for(let r of Yd){let o=path.resolve(e,r);if(fs$1.existsSync(o))return o}}function qd(e){let n;try{n=fs$1.readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(Xd);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=jsYaml.load(t[1]??"");if(!Lr(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let r=Lr(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(r?.version??i.version)=="string"?{version:r?.version??i.version}:{},...typeof i.description=="string"?{description:i.description}:{}},readable:!0,valid:!0,hasFrontmatter:!0}}catch{return {frontmatter:{},readable:true,valid:false,hasFrontmatter:true}}}function Zd(e){return [path.join(e,Mr),path.join(e,"skill",Mr)]}function tt(e,n){if(!Ur(e))return null;for(let t of Zd(e)){if(!fs$1.existsSync(t))continue;let r=qd(t).frontmatter;return {name:r.name??n,...r.version===void 0?{}:{version:r.version},...r.description===void 0?{}:{description:r.description},skillMdPath:t,dir:e}}return null}function Ii(e){try{return fs$1.readdirSync(e,{withFileTypes:!0}).filter(Kd)}catch{return []}}function Qd(e){return e.length===0||/[\\\u0000]/.test(e)?false:e.split("/").every(n=>n.length>0&&n!=="."&&n!=="..")}function Or(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function it(e){let n=[],t=new Set;for(let i of e)if(Ur(i))for(let r of Ii(i)){if(r.name.startsWith("@")){let o=path.join(i,r.name);for(let a of Ii(o))Or(tt(path.join(o,a.name),a.name),t,n);continue}Or(tt(path.join(i,r.name),r.name),t,n);}return n.sort((i,r)=>i.name.localeCompare(r.name))}function ep(e,n){if(!Qd(e))throw new Error(`Skill not found: ${e}`);for(let i of n){let r=tt(path.join(i,e),e);if(r)return r;for(let o of Ii(i)){if(!o.name.startsWith("@"))continue;let a=tt(path.join(i,o.name,e),e);if(a)return a}}let t=it(n).find(i=>i.name===e);if(t)return t;throw new Error(`Skill not found: ${e}`)}async function sf(e){if(!e||e.root===null)return {skills:[],diagnostics:[]};let{discoverWorkspaceApps:n}=await Promise.resolve().then(()=>(Sr(),Pr)),t=await n(e.root,{productBundle:e}),i=[],r=new Set;for(let o of t.apps){let a=o.provenance?.kind==="bundled"?o.provenance.packageDir:void 0;if(!a)continue;let s=path.join(e.root,...a.split("/"));for(let c of it([path.dirname(s)]))path.resolve(c.dir)!==path.resolve(s)||r.has(c.name)||(r.add(c.name),i.push(c));for(let c of [path.join(s,"skill"),path.join(s,"skills")])for(let d of it([c]))r.has(d.name)||(r.add(d.name),i.push(d));}return {skills:i.sort((o,a)=>o.name.localeCompare(a.name)),diagnostics:t.diagnostics.filter(o=>o.source==="bundled")}}var af=it,cf=ep;
|
|
2
2
|
exports.discover=it;exports.discoverBundledProductSkills=sf;exports.discoverSkills=af;exports.findEntrypoint=rf;exports.readSkillFrontmatter=qd;exports.resolve=ep;exports.resolveSkill=cf;
|