dsh-edge 0.20.0-alpha.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,7 +152,7 @@ Known schemas:
152
152
  - `)}`,new Error(Ve)}let gt=`${c}/$ref`,nt=Ds(e,Le,n,r,i,s,o,gt,l);if(nt.valid||Se.push({instanceLocation:o,keyword:"$ref",keywordLocation:gt,error:"A subschema had errors."},...nt.errors),n==="4"||n==="7")return{valid:Se.length===0,errors:Se}}if(Array.isArray(g)){let ze=g.length,Le=!1;for(let gt=0;gt<ze;gt++)if(d===g[gt]||g[gt]==="integer"&&d==="number"&&e%1===0&&e===e){Le=!0;break}Le||Se.push({instanceLocation:o,keyword:"type",keywordLocation:`${c}/type`,error:`Instance type "${d}" is invalid. Expected "${g.join('", "')}".`})}else g==="integer"?(d!=="number"||e%1||e!==e)&&Se.push({instanceLocation:o,keyword:"type",keywordLocation:`${c}/type`,error:`Instance type "${d}" is invalid. Expected "${g}".`}):g!==void 0&&d!==g&&Se.push({instanceLocation:o,keyword:"type",keywordLocation:`${c}/type`,error:`Instance type "${d}" is invalid. Expected "${g}".`});if(y!==void 0&&(d==="object"||d==="array"?Nb(e,y)||Se.push({instanceLocation:o,keyword:"const",keywordLocation:`${c}/const`,error:`Instance does not match ${JSON.stringify(y)}.`}):e!==y&&Se.push({instanceLocation:o,keyword:"const",keywordLocation:`${c}/const`,error:`Instance does not match ${JSON.stringify(y)}.`})),v!==void 0&&(d==="object"||d==="array"?v.some(ze=>Nb(e,ze))||Se.push({instanceLocation:o,keyword:"enum",keywordLocation:`${c}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`}):v.some(ze=>e===ze)||Se.push({instanceLocation:o,keyword:"enum",keywordLocation:`${c}/enum`,error:`Instance does not match any of ${JSON.stringify(v)}.`})),b!==void 0){let ze=`${c}/not`;Ds(e,b,n,r,i,s,o,ze).valid&&Se.push({instanceLocation:o,keyword:"not",keywordLocation:ze,error:'Instance matched "not" schema.'})}let at=[];if(S!==void 0){let ze=`${c}/anyOf`,Le=Se.length,gt=!1;for(let nt=0;nt<S.length;nt++){let Ve=S[nt],ht=Object.create(l),Re=Ds(e,Ve,n,r,i,h===!0?s:null,o,`${ze}/${nt}`,ht);Se.push(...Re.errors),gt=gt||Re.valid,Re.valid&&at.push(ht)}gt?Se.length=Le:Se.splice(Le,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:ze,error:"Instance does not match any subschemas."})}if(k!==void 0){let ze=`${c}/allOf`,Le=Se.length,gt=!0;for(let nt=0;nt<k.length;nt++){let Ve=k[nt],ht=Object.create(l),Re=Ds(e,Ve,n,r,i,h===!0?s:null,o,`${ze}/${nt}`,ht);Se.push(...Re.errors),gt=gt&&Re.valid,Re.valid&&at.push(ht)}gt?Se.length=Le:Se.splice(Le,0,{instanceLocation:o,keyword:"allOf",keywordLocation:ze,error:"Instance does not match every subschema."})}if(E!==void 0){let ze=`${c}/oneOf`,Le=Se.length,gt=E.filter((nt,Ve)=>{let ht=Object.create(l),Re=Ds(e,nt,n,r,i,h===!0?s:null,o,`${ze}/${Ve}`,ht);return Se.push(...Re.errors),Re.valid&&at.push(ht),Re.valid}).length;gt===1?Se.length=Le:Se.splice(Le,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:ze,error:`Instance does not match exactly one subschema (${gt} matches).`})}if((d==="object"||d==="array")&&Object.assign(l,...at),_!==void 0){let ze=`${c}/if`;if(Ds(e,_,n,r,i,s,o,ze,l).valid){if(I!==void 0){let gt=Ds(e,I,n,r,i,s,o,`${c}/then`,l);gt.valid||Se.push({instanceLocation:o,keyword:"if",keywordLocation:ze,error:'Instance does not match "then" schema.'},...gt.errors)}}else if(L!==void 0){let gt=Ds(e,L,n,r,i,s,o,`${c}/else`,l);gt.valid||Se.push({instanceLocation:o,keyword:"if",keywordLocation:ze,error:'Instance does not match "else" schema.'},...gt.errors)}}if(d==="object"){if(w!==void 0)for(let nt of w)nt in e||Se.push({instanceLocation:o,keyword:"required",keywordLocation:`${c}/required`,error:`Instance does not have required property "${nt}".`});let ze=Object.keys(e);if(A!==void 0&&ze.length<A&&Se.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${c}/minProperties`,error:`Instance does not have at least ${A} properties.`}),z!==void 0&&ze.length>z&&Se.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${c}/maxProperties`,error:`Instance does not have at least ${z} properties.`}),C!==void 0){let nt=`${c}/propertyNames`;for(let Ve in e){let ht=`${o}/${su(Ve)}`,Re=Ds(Ve,C,n,r,i,s,ht,nt);Re.valid||Se.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:nt,error:`Property name "${Ve}" does not match schema.`},...Re.errors)}}if(R!==void 0){let nt=`${c}/dependantRequired`;for(let Ve in R)if(Ve in e){let ht=R[Ve];for(let Re of ht)Re in e||Se.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:nt,error:`Instance has "${Ve}" but does not have "${Re}".`})}}if($!==void 0)for(let nt in $){let Ve=`${c}/dependentSchemas`;if(nt in e){let ht=Ds(e,$[nt],n,r,i,s,o,`${Ve}/${su(nt)}`,l);ht.valid||Se.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:Ve,error:`Instance has "${nt}" but does not match dependant schema.`},...ht.errors)}}if(N!==void 0){let nt=`${c}/dependencies`;for(let Ve in N)if(Ve in e){let ht=N[Ve];if(Array.isArray(ht))for(let Re of ht)Re in e||Se.push({instanceLocation:o,keyword:"dependencies",keywordLocation:nt,error:`Instance has "${Ve}" but does not have "${Re}".`});else{let Re=Ds(e,ht,n,r,i,s,o,`${nt}/${su(Ve)}`);Re.valid||Se.push({instanceLocation:o,keyword:"dependencies",keywordLocation:nt,error:`Instance has "${Ve}" but does not match dependant schema.`},...Re.errors)}}}let Le=Object.create(null),gt=!1;if(j!==void 0){let nt=`${c}/properties`;for(let Ve in j){if(!(Ve in e))continue;let ht=`${o}/${su(Ve)}`,Re=Ds(e[Ve],j[Ve],n,r,i,s,ht,`${nt}/${su(Ve)}`);if(Re.valid)l[Ve]=Le[Ve]=!0;else if(gt=i,Se.push({instanceLocation:o,keyword:"properties",keywordLocation:nt,error:`Property "${Ve}" does not match schema.`},...Re.errors),gt)break}}if(!gt&&O!==void 0){let nt=`${c}/patternProperties`;for(let Ve in O){let ht=new RegExp(Ve,"u"),Re=O[Ve];for(let St in e){if(!ht.test(St))continue;let Bt=`${o}/${su(St)}`,dt=Ds(e[St],Re,n,r,i,s,Bt,`${nt}/${su(Ve)}`);dt.valid?l[St]=Le[St]=!0:(gt=i,Se.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:nt,error:`Property "${St}" matches pattern "${Ve}" but does not match associated schema.`},...dt.errors))}}}if(!gt&&V!==void 0){let nt=`${c}/additionalProperties`;for(let Ve in e){if(Le[Ve])continue;let ht=`${o}/${su(Ve)}`,Re=Ds(e[Ve],V,n,r,i,s,ht,nt);Re.valid?l[Ve]=!0:(gt=i,Se.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:nt,error:`Property "${Ve}" does not match additional properties schema.`},...Re.errors))}}else if(!gt&&Q!==void 0){let nt=`${c}/unevaluatedProperties`;for(let Ve in e)if(!l[Ve]){let ht=`${o}/${su(Ve)}`,Re=Ds(e[Ve],Q,n,r,i,s,ht,nt);Re.valid?l[Ve]=!0:Se.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:nt,error:`Property "${Ve}" does not match unevaluated properties schema.`},...Re.errors)}}}else if(d==="array"){le!==void 0&&e.length>le&&Se.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${c}/maxItems`,error:`Array has too many items (${e.length} > ${le}).`}),ve!==void 0&&e.length<ve&&Se.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${c}/minItems`,error:`Array has too few items (${e.length} < ${ve}).`});let ze=e.length,Le=0,gt=!1;if(P!==void 0){let nt=`${c}/prefixItems`,Ve=Math.min(P.length,ze);for(;Le<Ve;Le++){let ht=Ds(e[Le],P[Le],n,r,i,s,`${o}/${Le}`,`${nt}/${Le}`);if(l[Le]=!0,!ht.valid&&(gt=i,Se.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:nt,error:"Items did not match schema."},...ht.errors),gt))break}}if(G!==void 0){let nt=`${c}/items`;if(Array.isArray(G)){let Ve=Math.min(G.length,ze);for(;Le<Ve;Le++){let ht=Ds(e[Le],G[Le],n,r,i,s,`${o}/${Le}`,`${nt}/${Le}`);if(l[Le]=!0,!ht.valid&&(gt=i,Se.push({instanceLocation:o,keyword:"items",keywordLocation:nt,error:"Items did not match schema."},...ht.errors),gt))break}}else for(;Le<ze;Le++){let Ve=Ds(e[Le],G,n,r,i,s,`${o}/${Le}`,nt);if(l[Le]=!0,!Ve.valid&&(gt=i,Se.push({instanceLocation:o,keyword:"items",keywordLocation:nt,error:"Items did not match schema."},...Ve.errors),gt))break}if(!gt&&Y!==void 0){let Ve=`${c}/additionalItems`;for(;Le<ze;Le++){let ht=Ds(e[Le],Y,n,r,i,s,`${o}/${Le}`,Ve);l[Le]=!0,ht.valid||(gt=i,Se.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:Ve,error:"Items did not match additional items schema."},...ht.errors))}}}if(B!==void 0)if(ze===0&&ne===void 0)Se.push({instanceLocation:o,keyword:"contains",keywordLocation:`${c}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(ne!==void 0&&ze<ne)Se.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${c}/minContains`,error:`Array has less items (${ze}) than minContains (${ne}).`});else{let nt=`${c}/contains`,Ve=Se.length,ht=0;for(let Re=0;Re<ze;Re++){let St=Ds(e[Re],B,n,r,i,s,`${o}/${Re}`,nt);St.valid?(l[Re]=!0,ht++):Se.push(...St.errors)}ht>=(ne||0)&&(Se.length=Ve),ne===void 0&&ye===void 0&&ht===0?Se.splice(Ve,0,{instanceLocation:o,keyword:"contains",keywordLocation:nt,error:"Array does not contain item matching schema."}):ne!==void 0&&ht<ne?Se.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${c}/minContains`,error:`Array must contain at least ${ne} items matching schema. Only ${ht} items were found.`}):ye!==void 0&&ht>ye&&Se.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${c}/maxContains`,error:`Array may contain at most ${ye} items matching schema. ${ht} items were found.`})}if(!gt&&X!==void 0){let nt=`${c}/unevaluatedItems`;for(Le;Le<ze;Le++){if(l[Le])continue;let Ve=Ds(e[Le],X,n,r,i,s,`${o}/${Le}`,nt);l[Le]=!0,Ve.valid||Se.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:nt,error:"Items did not match unevaluated items schema."},...Ve.errors)}}if(ke)for(let nt=0;nt<ze;nt++){let Ve=e[nt],ht=typeof Ve=="object"&&Ve!==null;for(let Re=0;Re<ze;Re++){if(nt===Re)continue;let St=e[Re];(Ve===St||ht&&(typeof St=="object"&&St!==null)&&Nb(Ve,St))&&(Se.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${c}/uniqueItems`,error:`Duplicate items at indexes ${nt} and ${Re}.`}),nt=Number.MAX_SAFE_INTEGER,Re=Number.MAX_SAFE_INTEGER)}}}else if(d==="number"){if(n==="4"?(Ee!==void 0&&(de===!0&&e<=Ee||e<Ee)&&Se.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${c}/minimum`,error:`${e} is less than ${de?"or equal to ":""} ${Ee}.`}),ue!==void 0&&(rt===!0&&e>=ue||e>ue)&&Se.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${c}/maximum`,error:`${e} is greater than ${rt?"or equal to ":""} ${ue}.`})):(Ee!==void 0&&e<Ee&&Se.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${c}/minimum`,error:`${e} is less than ${Ee}.`}),ue!==void 0&&e>ue&&Se.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${c}/maximum`,error:`${e} is greater than ${ue}.`}),de!==void 0&&e<=de&&Se.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${c}/exclusiveMinimum`,error:`${e} is less than ${de}.`}),rt!==void 0&&e>=rt&&Se.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${c}/exclusiveMaximum`,error:`${e} is greater than or equal to ${rt}.`})),We!==void 0){let ze=e%We;Math.abs(0-ze)>=11920929e-14&&Math.abs(We-ze)>=11920929e-14&&Se.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${c}/multipleOf`,error:`${e} is not a multiple of ${We}.`})}}else if(d==="string"){let ze=tt===void 0&&Ae===void 0?0:gSe(e);tt!==void 0&&ze<tt&&Se.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${c}/minLength`,error:`String is too short (${ze} < ${tt}).`}),Ae!==void 0&&ze>Ae&&Se.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${c}/maxLength`,error:`String is too long (${ze} > ${Ae}).`}),xe!==void 0&&!new RegExp(xe,"u").test(e)&&Se.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${c}/pattern`,error:"String does not match pattern."}),D!==void 0&&pK[D]&&!pK[D](e)&&Se.push({instanceLocation:o,keyword:"format",keywordLocation:`${c}/format`,error:`String does not match format "${D}".`})}return{valid:Se.length===0,errors:Se}}var mK=ce(()=>{dK();gN();fK();mN();hK();a(Ds,"validate")});var yN,ySe=ce(()=>{gN();mK();yN=class{static{a(this,"Validator")}schema;draft;shortCircuit;lookup;constructor(t,n="2019-09",r=!0){this.schema=t,this.draft=n,this.shortCircuit=r,this.lookup=Uh(t)}validate(t){return Ds(t,this.schema,this.draft,this.lookup,this.shortCircuit)}addSchema(t,n){n&&(t={...t,$id:n}),Uh(t,this.lookup)}}});var vSe=ce(()=>{dK();gN();fK();mN();mSe();hK();mK();ySe()});var vN,wSe=ce(()=>{vSe();vN=class{static{a(this,"CfWorkerJsonSchemaValidator")}constructor(t){this.shortcircuit=t?.shortcircuit??!0,this.draft=t?.draft??"2020-12"}getValidator(t){let n=new yN(t,this.draft,this.shortcircuit);return r=>{let i=n.validate(r);return i.valid?{valid:!0,data:r,errorMessage:void 0}:{valid:!1,data:void 0,errorMessage:i.errors.map(s=>`${s.instanceLocation}: ${s.error}`).join("; ")}}}}});var So,wN=ce(()=>{"use strict";So={probeTimeoutMs:3e4,callTimeoutMs:6e4,maxToolsPerServer:128,maxCatalogPages:10,maxCatalogBytes:131072,maxDescriptionLength:512,maxErrorMessageChars:300,maxPublicNameLength:64,maxInstructionsLength:1024,metaToolThreshold:20}});import{createHash as x0t}from"node:crypto";function k0t(e){let t=e.replace(/[.*+?^${}()|[\]\\]/gu,n=>n==="*"?"\0":`\\${n}`);return new RegExp(`^${t.replaceAll("\0",".*")}$`)}function bSe(e,t,n){let r=t??"read_only";return r==="allow_all"?"allow":r==="approve_all"?"ask":n===!0?"allow":n===!1?"ask":S0t.some(i=>k0t(i).test(e))?"allow":"ask"}function yf(e){return e.replace(/Bearer\s+[^\s"']+/giu,"Bearer ***").replace(/(https?:\/\/[^\s"'?]+)\?[^\s"']*/giu,"$1?***").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/gu,"").slice(0,So.maxErrorMessageChars)}function xSe(e,t){let n=`mcp__${e}__${t}`,r=n.replace(/[^A-Za-z0-9_-]/gu,"_");if(r===n&&r.length<=So.maxPublicNameLength)return r;let i=E0t(e,t),s=So.maxPublicNameLength-i.length-1;return`${r.slice(0,s)}_${i}`}function E0t(e,t){return x0t("sha256").update(`${e}\0${t}`).digest("hex").slice(0,12)}function SSe(e){if(!(e==null||typeof e!="object"))try{let t=JSON.parse(JSON.stringify(e));return x0(t),t}catch{return}}function I0t(e){return _0t.has(e)}function kSe(e){return e.type!=="image"||e.data===void 0||e.mimeType===void 0||!I0t(e.mimeType)||!T0t.test(e.data)?void 0:{data:Uint8Array.from(atob(e.data),n=>n.charCodeAt(0)),mediaType:e.mimeType}}function ESe(e){return e.some(t=>t.type==="image"&&t.data!==void 0)}function z2(e){if(e.isError)return[{type:"text",text:e.content.filter(i=>i.type==="text"&&typeof i.text=="string").map(i=>i.text).join(`
153
153
  `)||"MCP tool returned an error."}];let t=[],n=[];for(let r of e.content)if(r.type==="text"&&typeof r.text=="string")n.push(r.text);else if(r.type==="resource_link"&&r.uri!==void 0)n.push(`Resource: ${r.name??"unnamed"} (${r.uri})`);else if(r.type==="image"&&r.data!==void 0)n.push(`![image](data:${r.mimeType??"image/png"};base64,${r.data})`);else if(r.type==="image")n.push(`[image: ${r.mimeType??"unknown type"}]`);else if(r.type==="audio")n.push("[audio result unsupported on Cloudflare Workers]");else if(r.type==="resource"&&r.resource?.text!==void 0){let i=r.resource.uri??"embedded resource";n.push(`--- ${i} ---
154
154
  ${r.resource.text}`)}else r.type==="resource"?n.push("[embedded resource: binary content not displayed]"):n.push(`[unsupported MCP content type: ${r.type}]`);return n.length>0&&t.push({type:"text",text:n.join(`
155
- `)}),t.length>0?t:[{type:"text",text:"(empty MCP result)"}]}var S0t,_0t,T0t,bN=ce(()=>{"use strict";Go();wN();S0t=["get_*","list_*","read_*","search_*","find_*","fetch_*","describe_*"];a(k0t,"globToRegExp");a(bSe,"evaluateMcpToolPolicy");a(yf,"scrubMcpErrorMessage");a(xSe,"publicToolName");a(E0t,"hashSuffix");a(SSe,"supportedOutputSchema");_0t=new Set(["image/png","image/jpeg"]),T0t=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;a(I0t,"isImageMediaType");a(kSe,"decodeImageBlock");a(ESe,"containsImage");a(z2,"mapMcpResultToContentBlocks")});var gK,_Se=ce(()=>{gK={name:"dsh-edge",version:"0.20.0-alpha.1",description:"Your DeepSeek Harness, anywhere \u2014 deploy a persistent personal coding agent to Cloudflare Workers in one command",author:"pawaca",license:"MIT",type:"module",bin:{"dsh-edge":"scripts/cli.mjs"},files:["dist","worker","scripts/*.d.mts","scripts/*.mjs","wrangler.jsonc","README.md","README.zh.md","LICENSE","THIRD_PARTY_NOTICES.md"],repository:{type:"git",url:"git+https://github.com/pawaca/dsh-edge.git",directory:"apps/dsh-edge"},homepage:"https://github.com/pawaca/dsh-edge#readme",bugs:{url:"https://github.com/pawaca/dsh-edge/issues"},keywords:["deepseek","deepseek-harness","ai-agents","byok","cloudflare-workers","durable-objects","self-hosted"],engines:{node:">=22.14.0"},publishConfig:{access:"public"},dshEdge:{upstreamVersion:"0.2.0-rc.2"},scripts:{"bundle:direct":"pnpm run web:build && pnpm --dir standalone run build:worker:direct && node standalone/scripts/promote.mjs direct","bundle:isolated":"pnpm run web:build && pnpm --dir standalone run build:worker:isolated && node standalone/scripts/promote.mjs isolated","bundle:workers":"pnpm --dir standalone run build && pnpm --dir standalone run verify && node standalone/scripts/promote.mjs all",dev:"pnpm run bundle:direct && node scripts/dev.mjs direct","dev:isolated":"pnpm run bundle:isolated && node scripts/dev.mjs isolated","dev:container":"pnpm run bundle:isolated && node scripts/dev.mjs container","dsh-edge":"node scripts/cli.mjs","example:install":"node examples/install-keyless.mjs","install:cloudflare":"pnpm run bundle:workers && node scripts/cli.mjs install","legal:write":"node scripts/legal-files.mjs write","pack:verify":"node scripts/verify-packed.mjs",prepack:"node scripts/legal-files.mjs verify && pnpm run bundle:workers","web:build":"pnpm --dir standalone run build:web && node standalone/scripts/promote.mjs web",test:"vitest run --root ../.. --project edge-runtime","test:integration":"pnpm run bundle:workers && node tests/run-session-integration.mjs","test:container":"pnpm run bundle:isolated && node tests/container.integration.mjs","test:snapshot":"vitest run --root ../.. --config apps/dsh-edge/vitest.snapshot.config.ts",typecheck:"tsc --noEmit"},dependencies:{"@clack/prompts":"1.7.0","compare-versions":"6.1.1",execa:"^10.0.1","jsonc-parser":"^3.3.1",wrangler:"4.129.0"},devDependencies:{"@cfworker/json-schema":"^4.1.1","@cloudflare/computer":"0.3.1","@cloudflare/workers-types":"5.20260904.1","@deepseek-ai/cordis":"4.0.4","@deepseek-ai/cosmokit":"1.8.5","@deepseek-ai/dsh-agent":"0.2.0-rc.2","@deepseek-ai/dsh-agent-loop":"0.2.0-rc.2","@deepseek-ai/dsh-anonymous-user-id":"0.2.0-rc.2","@deepseek-ai/dsh-api-gateway":"0.2.0-rc.2","@deepseek-ai/dsh-api-job-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-remotes":"0.2.0-rc.2","@deepseek-ai/dsh-api-session-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-settings-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-workspace-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-workspace-files":"0.2.0-rc.2","@deepseek-ai/dsh-attachment":"0.2.0-rc.2","@deepseek-ai/dsh-brand":"0.2.0-rc.2","@deepseek-ai/dsh-client-locale":"0.2.0-rc.2","@deepseek-ai/dsh-client-store":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-chat":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-conversation":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-settings":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-settings-general":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-theme":"0.2.0-rc.2","@deepseek-ai/dsh-commands":"0.2.0-rc.2","@deepseek-ai/dsh-compaction":"0.2.0-rc.2","@deepseek-ai/dsh-compaction-basic":"0.2.0-rc.2","@deepseek-ai/dsh-compaction-tool-result-pruner":"0.2.0-rc.2","@deepseek-ai/dsh-credentials":"0.2.0-rc.2","@deepseek-ai/dsh-file-reference":"0.2.0-rc.2","@deepseek-ai/dsh-fs":"0.2.0-rc.2","@deepseek-ai/dsh-fs-observation-policy":"0.2.0-rc.2","@deepseek-ai/dsh-goal":"0.2.0-rc.2","@deepseek-ai/dsh-goal-round-driver":"0.2.0-rc.2","@deepseek-ai/dsh-host-directory-picker":"0.2.0-rc.2","@deepseek-ai/dsh-host-plugin-inventory":"0.2.0-rc.2","@deepseek-ai/dsh-invariants":"0.2.0-rc.2","@deepseek-ai/dsh-jobs":"0.2.0-rc.2","@deepseek-ai/dsh-jobs-local":"0.2.0-rc.2","@deepseek-ai/dsh-launch-environment":"0.2.0-rc.2","@deepseek-ai/dsh-llm":"0.2.0-rc.2","@deepseek-ai/dsh-llm-deepseek":"0.2.0-rc.2","@deepseek-ai/dsh-llm-deepseek-api-key":"0.2.0-rc.2","@deepseek-ai/dsh-llm-retry":"0.2.0-rc.2","@deepseek-ai/dsh-message-feedback":"0.2.0-rc.2","@deepseek-ai/dsh-output-retention":"0.2.0-rc.2","@deepseek-ai/dsh-plan-mode":"0.2.0-rc.2","@deepseek-ai/dsh-ptc-runtime":"0.2.0-rc.2","@deepseek-ai/dsh-repeat-tool-reminder":"0.2.0-rc.2","@deepseek-ai/dsh-sandbox":"0.2.0-rc.2","@deepseek-ai/dsh-schedule":"0.2.0-rc.2","@deepseek-ai/dsh-scope":"0.2.0-rc.2","@deepseek-ai/dsh-session":"0.2.0-rc.2","@deepseek-ai/dsh-session-checkpoint-policy":"0.2.0-rc.2","@deepseek-ai/dsh-session-format":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-catalog":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v0-to-v1":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v1-to-v2":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v2-to-v3":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v3-to-v4":"0.2.0-rc.2","@deepseek-ai/dsh-session-persistence":"0.2.0-rc.2","@deepseek-ai/dsh-session-projection":"0.2.0-rc.2","@deepseek-ai/dsh-session-projection-cache":"0.2.0-rc.2","@deepseek-ai/dsh-session-query":"0.2.0-rc.2","@deepseek-ai/dsh-session-reference":"0.2.0-rc.2","@deepseek-ai/dsh-session-title":"0.2.0-rc.2","@deepseek-ai/dsh-session-title-first-prompt-llm":"0.2.0-rc.2","@deepseek-ai/dsh-session-title-llm":"0.2.0-rc.2","@deepseek-ai/dsh-settings":"0.2.0-rc.2","@deepseek-ai/dsh-skill":"0.2.0-rc.2","@deepseek-ai/dsh-spill":"0.2.0-rc.2","@deepseek-ai/dsh-spill-policy":"0.2.0-rc.2","@deepseek-ai/dsh-storage":"0.2.0-rc.2","@deepseek-ai/dsh-storage-domain":"0.2.0-rc.2","@deepseek-ai/dsh-subagent":"0.2.0-rc.2","@deepseek-ai/dsh-subagent-in-process-driver":"0.2.0-rc.2","@deepseek-ai/dsh-subagent-spawn-in-process":"0.2.0-rc.2","@deepseek-ai/dsh-system-prompt":"0.2.0-rc.2","@deepseek-ai/dsh-timeout":"0.2.0-rc.2","@deepseek-ai/dsh-token-meter":"0.2.0-rc.2","@deepseek-ai/dsh-tool-ask-user":"0.2.0-rc.2","@deepseek-ai/dsh-tool-call-timeout-policy":"0.2.0-rc.2","@deepseek-ai/dsh-tool-fs":"0.2.0-rc.2","@deepseek-ai/dsh-tool-goal":"0.2.0-rc.2","@deepseek-ai/dsh-tool-jobs":"0.2.0-rc.2","@deepseek-ai/dsh-tool-skill":"0.2.0-rc.2","@deepseek-ai/dsh-tool-subagent":"0.2.0-rc.2","@deepseek-ai/dsh-tool-web":"0.2.0-rc.2","@deepseek-ai/dsh-tool-workflow":"0.2.0-rc.2","@deepseek-ai/dsh-tools":"0.2.0-rc.2","@deepseek-ai/dsh-typert-protocol":"0.2.0-rc.2","@deepseek-ai/dsh-typert-registry":"0.2.0-rc.2","@deepseek-ai/dsh-user-approval":"0.2.0-rc.2","@deepseek-ai/dsh-user-questions":"0.2.0-rc.2","@deepseek-ai/dsh-util-values":"0.2.0-rc.2","@deepseek-ai/dsh-web":"0.2.0-rc.2","@deepseek-ai/dsh-web-fetch-http":"0.2.0-rc.2","@deepseek-ai/dsh-web-search-deepseek":"0.2.0-rc.2","@deepseek-ai/dsh-workflow":"0.2.0-rc.2","@deepseek-ai/dsh-workspace":"0.2.0-rc.2","@deepseek-ai/schemastery":"3.18.4","@mixmark-io/domino":"2.2.0","@modelcontextprotocol/sdk":"1.30.0",acorn:"8.18.0","fast-png":"8.0.0","jpeg-js":"0.4.4","just-bash":"3.4.2",playwright:"^1.49.0",sucrase:"3.35.1",typescript:"^6.0.3",vitest:"^4.1.8",ws:"^8.21.0"}}});var o1,TSe,ISe,B2=ce(()=>{"use strict";_Se();o1=gK.version,TSe=gK.dshEdge.upstreamVersion,ISe=`npx dsh-edge@${o1.includes("-")?"next":"latest"} upgrade`});function O0t(e){let t=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/iu.exec(e);if(t!==null)return t[1];let n=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/iu.exec(e);if(n!==null){let r=parseInt(n[1],16),i=parseInt(n[2],16);return`${String(r>>8)}.${String(r&255)}.${String(i>>8)}.${String(i&255)}`}}function N0t(e){return/^\d+\.\d+\.\d+\.\d+$/u.test(e)||e.includes(":")}function zh(e){let t=new URL(e);if(t.protocol!=="http:"&&t.protocol!=="https:")throw new Error("MCP server URL must use http: or https: protocol.");let n=t.hostname.toLowerCase(),r=n.endsWith(".")?n.slice(0,-1):n,i=r.startsWith("[")&&r.endsWith("]")?r.slice(1,-1):r;if(!(i==="localhost"||i==="127.0.0.1"||i==="::1")){for(let s of C0t)if(i.endsWith(s))throw new Error(`MCP server hostname "${i}" is blocked.`);if(N0t(i)){let s=O0t(i),o=s??i;for(let c of R0t)if(c.test(o))throw new Error(`MCP server address "${i}" is a private IP and is blocked.`);if(s===void 0){for(let c of $0t)if(c.test(i))throw new Error(`MCP server address "${i}" is a private IP and is blocked.`)}}}}function P0t(e){return e?.type==="bearer"&&e.token!==void 0?{Authorization:`Bearer ${e.token}`}:{}}async function ASe(e,t,n){zh(e);let r=new hN(new URL(e),{requestInit:{headers:P0t(t),signal:n},fetch:a1}),i=new pN({name:"dsh-edge",version:o1},{capabilities:{},jsonSchemaValidator:D0t});return await i.connect(r),{client:i,close:a(async()=>{await i.close().catch(()=>{})},"close")}}async function CSe(e,t,n){let r=AbortSignal.timeout(So.probeTimeoutMs),i;try{i=await ASe(t,n,r)}catch(c){throw new Error(yf(c instanceof Error?c.message:String(c)))}let{client:s,close:o}=i;try{let c=[],l=new Set,u=new Set,d;for(let h=0;h<So.maxCatalogPages;h++){let g=await s.listTools(d===void 0?void 0:{cursor:d},{signal:r});for(let y of g.tools){if(c.length>=So.maxToolsPerServer)break;let v=xSe(e,y.name);if(l.has(v))throw new Error(`Server listed tool "${y.name}" more than once`);l.add(v);let w=y.annotations?.readOnlyHint,b=SSe(y.outputSchema);c.push({name:y.name,publicName:v,description:y.description??"",inputSchema:y.inputSchema??{type:"object"},...b!==void 0?{outputSchema:b}:{},...w!==void 0?{annotations:{readOnlyHint:w}}:{}})}if(c.length>=So.maxToolsPerServer||(d=g.nextCursor??void 0,d===void 0))break;if(u.has(d))throw new Error("Server repeated a tools/list continuation cursor");u.add(d)}let p=s.getServerVersion?.(),f=s.getInstructions?.();return{tools:c,serverInfo:p?{name:p.name,version:p.version}:void 0,instructions:typeof f=="string"&&f.length>0?f.slice(0,So.maxInstructionsLength):void 0}}finally{await o()}}async function xN(e,t,n,r,i,s){let o=s??So.callTimeoutMs,c=i?AbortSignal.any([i,AbortSignal.timeout(o)]):AbortSignal.timeout(o),l;try{l=await ASe(e,r,c)}catch(u){throw new Error(yf(u instanceof Error?u.message:String(u)))}try{let u=await l.client.callTool({name:t,arguments:n},void 0,{signal:c});return{content:u.content??[],structuredContent:u.structuredContent,isError:u.isError===!0}}catch(u){throw new Error(yf(u instanceof Error?u.message:String(u)))}finally{await l.close()}}var C0t,R0t,$0t,D0t,a1,W2=ce(()=>{"use strict";Oxe();dSe();wSe();bN();wN();B2();C0t=[".internal",".local",".localhost"],R0t=[/^127\./u,/^10\./u,/^172\.(1[6-9]|2\d|3[01])\./u,/^192\.168\./u,/^0\./u,/^169\.254\./u],$0t=[/^::1$/u,/^fc/iu,/^fd/iu,/^fe[89ab][0-9a-f]:/iu];a(O0t,"extractMappedIPv4");a(N0t,"isIpAddress");a(zh,"assertSafeUrl");a(P0t,"buildHeaders");D0t=new vN,a1=a(async(e,t)=>{let n=await globalThis.fetch(e,{...t,redirect:"manual"});if(n.status>=300&&n.status<400)throw new Error(`MCP server returned HTTP ${String(n.status)} redirect; redirects are blocked for security.`);return n},"noRedirectFetch");a(ASe,"connectClient");a(CSe,"probe");a(xN,"callTool")});import{Buffer as M0t}from"node:buffer";function q0t(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&F0t.has(e.code)}function $Se(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&j0t.has(e.code)}function OSe(e,t,n){let r=M0t.from(e,"base64");if(e.length===0&&t==="reject"||r.toString("base64")!==e)throw new ir(n==="INVALID_IMAGE_BASE64"?"Image upload is not canonical base64.":"File upload is not canonical base64.",n);return new Uint8Array(r)}function U0t(e){return OSe(e,"reject","INVALID_IMAGE_BASE64")}function z0t(e){return{data:U0t(e.data),mediaType:e.mediaType,...e.name===void 0?{}:{name:e.name}}}async function H2(e,t){return e.saveImages(t.map(z0t))}async function B0t(e,t){return e.saveFile({data:OSe(t.data,"accept","INVALID_FILE_BASE64"),...t.name===void 0?{}:{name:t.name}})}function NSe(e,t,n){let r=Math.min(1,Math.sqrt(n/(e*t)));if(r===1)return{width:e,height:t};if(e>=t){let o=Math.max(1,Math.floor(e*r)),c=Math.max(1,Math.round(o*t/e));for(;o*c>n&&o>1;)o-=1,c=Math.max(1,Math.round(o*t/e));return{width:o,height:c}}let i=Math.max(1,Math.floor(t*r)),s=Math.max(1,Math.round(i*e/t));for(;s*i>n&&i>1;)i-=1,s=Math.max(1,Math.round(i*e/t));return{width:s,height:i}}function yK(e,t,n){return n>=Math.max(e,t)?{width:e,height:t}:e>=t?{width:n,height:Math.max(1,Math.round(n*t/e))}:{width:Math.max(1,Math.round(n*e/t)),height:n}}var RSe,L0t,j0t,F0t,ir,vK,Bh=ce(()=>{Hn();RSe=["TOO_MANY_IMAGES","IMAGES_TOO_LARGE","UNSUPPORTED_IMAGE_TYPE","INVALID_IMAGE_BASE64","INVALID_IMAGE","IMAGE_TYPE_MISMATCH","IMAGE_TOO_LARGE","IMAGE_TOO_MANY_PIXELS","IMAGE_DIMENSION_TOO_LARGE"],L0t=[...RSe,"INVALID_FILE_BASE64","INVALID_ATTACHMENT_REF","ATTACHMENT_CORRUPT","ATTACHMENT_WRITE_FAILED","ATTACHMENT_NOT_FOUND","ATTACHMENT_READ_FAILED","ATTACHMENT_PROJECTION_UNSUPPORTED","ATTACHMENT_FILES_UNSUPPORTED"],j0t=new Set(RSe),F0t=new Set(L0t),ir=class extends Error{static{a(this,"AttachmentError")}code;constructor(e,t,n){super(e,n),this.name="AttachmentError",this.code=t}};a(q0t,"isAttachmentError");a($Se,"isImageAdmissionError");a(OSe,"decodeCanonicalBase64");a(U0t,"decodeBase64");a(z0t,"saveInput");a(H2,"admitEncodedImages");a(B0t,"admitEncodedFile");a(NSe,"requestImageDimensions");a(yK,"longEdgeDimensions");vK=class extends xt{static{a(this,"AttachmentStore")}constructor(e){super(e,"attachments")}validateImageBatch(e){let{maxImagesPerMessage:t,maxMessageImageBytes:n,mediaTypes:r}=this.imageLimits;if(e.length>t)throw new ir("Image batch exceeds the configured image-count limit.","TOO_MANY_IMAGES");if(e.reduce((i,s)=>i+s.data.byteLength,0)>n)throw new ir("Image batch exceeds the configured aggregate image-byte limit.","IMAGES_TOO_LARGE");for(let i of e)if(!r.includes(i.mediaType))throw new ir(`Image type ${i.mediaType} is not accepted by this deployment.`,"UNSUPPORTED_IMAGE_TYPE")}async saveImages(e){this.validateImageBatch(e);for(let n of e)await this.validateImage(n);let t=[];for(let n of e)t.push(await this.saveImage(n));return t}async admitPromptContent(e){if(e.every(r=>r.type!=="image"))return e.map(r=>r.type==="text"?{type:"text",text:r.text}:{type:"file",attachment:r.attachment});let t=await H2(this,e.filter(r=>r.type==="image")),n=0;return e.map(r=>r.type==="text"?{type:"text",text:r.text}:r.type==="file"?{type:"file",attachment:r.attachment}:{type:"image",attachment:t[n++]})}admitEncodedFile(e){return B0t(this,e)}isAttachmentError(e){return q0t(e)}imageHostPath(e){}saveFile(e){return Promise.reject(new ir("The mounted attachment provider cannot store verbatim files.","ATTACHMENT_FILES_UNSUPPORTED"))}saveFileStream(e){return Promise.reject(new ir("The mounted attachment provider cannot stream verbatim files.","ATTACHMENT_FILES_UNSUPPORTED"))}async*readFileStream(e,t){t?.throwIfAborted(),await Promise.reject(new ir("The mounted attachment provider cannot read verbatim files.","ATTACHMENT_FILES_UNSUPPORTED"))}fileHostPath(e){}readImageRequest(e,t,n){return n?.throwIfAborted(),Promise.reject(new ir("The mounted attachment provider cannot derive model-request images.","ATTACHMENT_PROJECTION_UNSUPPORTED"))}}});var kN={};In(kN,{buildAuthorizationUrl:()=>X0t,discoverEndpoints:()=>J0t,exchangeCode:()=>Q0t,isTokenExpired:()=>t1t,refreshToken:()=>e1t,registerClient:()=>Y0t});function LSe(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(2,"0")).join("").slice(0,e)}async function Z0t(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return btoa(String.fromCharCode(...new Uint8Array(n))).replace(/\+/gu,"-").replace(/\//gu,"_").replace(/=/gu,"")}async function J0t(e){let t=AbortSignal.timeout(SN),n=new URL(e),r=n.pathname==="/"?"/.well-known/oauth-protected-resource":`/.well-known/oauth-protected-resource${n.pathname}`,i=new URL(r,n.origin);zh(i.href);let s=await a1(i.href,{signal:t});if(!s.ok)throw new Error(`PRM discovery failed: HTTP ${s.status}`);let c=(await s.json()).authorization_servers?.[0];if(typeof c!="string")throw new Error("No authorization server in PRM");let l=new URL(c),u=l.pathname==="/"?"/.well-known/oauth-authorization-server":`/.well-known/oauth-authorization-server${l.pathname}`,d=new URL(u,l.origin);zh(d.href);let p=await a1(d.href,{signal:t});if(!p.ok)throw new Error(`AS metadata failed: HTTP ${p.status}`);let f=await p.json();if(typeof f.authorization_endpoint!="string"||typeof f.token_endpoint!="string")throw new Error("Missing required endpoints in AS metadata");return{authorization:f.authorization_endpoint,token:f.token_endpoint,registration:f.registration_endpoint}}async function Y0t(e,t,n){let r=AbortSignal.timeout(SN);zh(e);let i=await a1(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({client_name:n,redirect_uris:[t],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none"}),signal:r});if(!i.ok)throw new Error(`DCR failed: HTTP ${i.status}`);let s=await i.json();if(typeof s.client_id!="string")throw new Error("DCR response missing client_id");return{clientId:s.client_id,clientSecret:s.client_secret}}async function X0t(e,t,n,r,i){let s=LSe(32),o=LSe(64),c=await Z0t(o),l=new URL(e.authorization);for(let[u,d]of Object.entries({response_type:"code",client_id:t.clientId,redirect_uri:n,state:s,code_challenge:c,code_challenge_method:"S256",resource:i}))l.searchParams.set(u,d);return{authorizationUrl:l.href,pendingFlow:{state:s,codeVerifier:o,redirectUri:n,serverName:r,serverUrl:i,stagedClient:t,createdAt:Date.now()}}}async function Q0t(e,t,n,r,i,s){let o=AbortSignal.timeout(SN),c=new URLSearchParams({grant_type:"authorization_code",code:n,redirect_uri:i,client_id:t.clientId,code_verifier:r});s!==void 0&&c.set("resource",s),t.clientSecret!==void 0&&c.set("client_secret",t.clientSecret),zh(e);let l=await a1(e,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:c.toString(),signal:o});if(!l.ok)throw new Error(`Token exchange failed: HTTP ${l.status}`);return jSe(await l.json())}async function e1t(e,t,n,r){let i=AbortSignal.timeout(SN),s=new URLSearchParams({grant_type:"refresh_token",refresh_token:n,client_id:t.clientId});r!==void 0&&s.set("resource",r),t.clientSecret!==void 0&&s.set("client_secret",t.clientSecret),zh(e);let o=await a1(e,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:s.toString(),signal:i});if(!o.ok)throw new Error(`Token refresh failed: HTTP ${o.status}`);return jSe(await o.json())}function jSe(e){let t=e;if(typeof t.access_token!="string")throw new Error("Missing access_token");let n=typeof t.expires_in=="number"?t.expires_in:void 0;return{accessToken:t.access_token,refreshToken:typeof t.refresh_token=="string"?t.refresh_token:void 0,expiresAt:n!==void 0?Date.now()+n*1e3:void 0,tokenType:typeof t.token_type=="string"?t.token_type:"Bearer",scope:typeof t.scope=="string"?t.scope:void 0}}function t1t(e){return e.expiresAt===void 0?!1:Date.now()>e.expiresAt-12e4}var SN,EN=ce(()=>{"use strict";W2();SN=1e4;a(LSe,"randomString");a(Z0t,"sha256Base64Url");a(J0t,"discoverEndpoints");a(Y0t,"registerClient");a(X0t,"buildAuthorizationUrl");a(Q0t,"exchangeCode");a(e1t,"refreshToken");a(jSe,"parseTokenResponse");a(t1t,"isTokenExpired")});var Un,VSe,V2=ce(()=>{Hn();kr();Un=class extends Jr{static{a(this,"FsError")}code;constructor(e,t,n){super(e,t,n),this.code=t}},VSe=class extends xt{static{a(this,"FileSystem")}constructor(e){super(e,"fs")}watch(e,t,n){return n.throwIfAborted(),Promise.reject(new Un("Filesystem watching is not supported by this provider.","FS_IO_ERROR"))}get sandboxMode(){}processPathFromHostPath(e){}}});function LK(e){return DN.test(e)}function MN(e){return e.invocation.modelInvocable}function Db(e){return e.invocation.userInvocable}function jK(e){let t=Fvt(e);return[`<skill_content name="${qvt(e.name)}">`,"<skill_resources>",...t,"</skill_resources>","","<skill_instructions>",e.content,"</skill_instructions>","</skill_content>"].join(`
155
+ `)}),t.length>0?t:[{type:"text",text:"(empty MCP result)"}]}var S0t,_0t,T0t,bN=ce(()=>{"use strict";Go();wN();S0t=["get_*","list_*","read_*","search_*","find_*","fetch_*","describe_*"];a(k0t,"globToRegExp");a(bSe,"evaluateMcpToolPolicy");a(yf,"scrubMcpErrorMessage");a(xSe,"publicToolName");a(E0t,"hashSuffix");a(SSe,"supportedOutputSchema");_0t=new Set(["image/png","image/jpeg"]),T0t=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;a(I0t,"isImageMediaType");a(kSe,"decodeImageBlock");a(ESe,"containsImage");a(z2,"mapMcpResultToContentBlocks")});var gK,_Se=ce(()=>{gK={name:"dsh-edge",version:"0.20.0",description:"Your DeepSeek Harness, anywhere \u2014 deploy a persistent personal coding agent to Cloudflare Workers in one command",author:"pawaca",license:"MIT",type:"module",bin:{"dsh-edge":"scripts/cli.mjs"},files:["dist","worker","scripts/*.d.mts","scripts/*.mjs","wrangler.jsonc","README.md","README.zh.md","LICENSE","THIRD_PARTY_NOTICES.md"],repository:{type:"git",url:"git+https://github.com/pawaca/dsh-edge.git",directory:"apps/dsh-edge"},homepage:"https://github.com/pawaca/dsh-edge#readme",bugs:{url:"https://github.com/pawaca/dsh-edge/issues"},keywords:["deepseek","deepseek-harness","ai-agents","byok","cloudflare-workers","durable-objects","self-hosted"],engines:{node:">=22.14.0"},publishConfig:{access:"public"},dshEdge:{upstreamVersion:"0.2.0-rc.2"},scripts:{"bundle:direct":"pnpm run web:build && pnpm --dir standalone run build:worker:direct && node standalone/scripts/promote.mjs direct","bundle:isolated":"pnpm run web:build && pnpm --dir standalone run build:worker:isolated && node standalone/scripts/promote.mjs isolated","bundle:workers":"pnpm --dir standalone run build && pnpm --dir standalone run verify && node standalone/scripts/promote.mjs all",dev:"pnpm run bundle:direct && node scripts/dev.mjs direct","dev:isolated":"pnpm run bundle:isolated && node scripts/dev.mjs isolated","dev:container":"pnpm run bundle:isolated && node scripts/dev.mjs container","dsh-edge":"node scripts/cli.mjs","example:install":"node examples/install-keyless.mjs","install:cloudflare":"pnpm run bundle:workers && node scripts/cli.mjs install","legal:write":"node scripts/legal-files.mjs write","pack:verify":"node scripts/verify-packed.mjs",prepack:"node scripts/legal-files.mjs verify && pnpm run bundle:workers","web:build":"pnpm --dir standalone run build:web && node standalone/scripts/promote.mjs web",test:"vitest run --root ../.. --project edge-runtime","test:integration":"pnpm run bundle:workers && node tests/run-session-integration.mjs","test:container":"pnpm run bundle:isolated && node tests/container.integration.mjs","test:snapshot":"vitest run --root ../.. --config apps/dsh-edge/vitest.snapshot.config.ts",typecheck:"tsc --noEmit"},dependencies:{"@clack/prompts":"1.7.0","compare-versions":"6.1.1",execa:"^10.0.1","jsonc-parser":"^3.3.1",wrangler:"4.129.0"},devDependencies:{"@cfworker/json-schema":"^4.1.1","@cloudflare/computer":"0.3.1","@cloudflare/workers-types":"5.20260904.1","@deepseek-ai/cordis":"4.0.4","@deepseek-ai/cosmokit":"1.8.5","@deepseek-ai/dsh-agent":"0.2.0-rc.2","@deepseek-ai/dsh-agent-loop":"0.2.0-rc.2","@deepseek-ai/dsh-anonymous-user-id":"0.2.0-rc.2","@deepseek-ai/dsh-api-gateway":"0.2.0-rc.2","@deepseek-ai/dsh-api-job-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-remotes":"0.2.0-rc.2","@deepseek-ai/dsh-api-session-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-settings-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-workspace-controller":"0.2.0-rc.2","@deepseek-ai/dsh-api-workspace-files":"0.2.0-rc.2","@deepseek-ai/dsh-attachment":"0.2.0-rc.2","@deepseek-ai/dsh-brand":"0.2.0-rc.2","@deepseek-ai/dsh-client-locale":"0.2.0-rc.2","@deepseek-ai/dsh-client-store":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-chat":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-conversation":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-settings":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-settings-general":"0.2.0-rc.2","@deepseek-ai/dsh-client-ui-theme":"0.2.0-rc.2","@deepseek-ai/dsh-commands":"0.2.0-rc.2","@deepseek-ai/dsh-compaction":"0.2.0-rc.2","@deepseek-ai/dsh-compaction-basic":"0.2.0-rc.2","@deepseek-ai/dsh-compaction-tool-result-pruner":"0.2.0-rc.2","@deepseek-ai/dsh-credentials":"0.2.0-rc.2","@deepseek-ai/dsh-file-reference":"0.2.0-rc.2","@deepseek-ai/dsh-fs":"0.2.0-rc.2","@deepseek-ai/dsh-fs-observation-policy":"0.2.0-rc.2","@deepseek-ai/dsh-goal":"0.2.0-rc.2","@deepseek-ai/dsh-goal-round-driver":"0.2.0-rc.2","@deepseek-ai/dsh-host-directory-picker":"0.2.0-rc.2","@deepseek-ai/dsh-host-plugin-inventory":"0.2.0-rc.2","@deepseek-ai/dsh-invariants":"0.2.0-rc.2","@deepseek-ai/dsh-jobs":"0.2.0-rc.2","@deepseek-ai/dsh-jobs-local":"0.2.0-rc.2","@deepseek-ai/dsh-launch-environment":"0.2.0-rc.2","@deepseek-ai/dsh-llm":"0.2.0-rc.2","@deepseek-ai/dsh-llm-deepseek":"0.2.0-rc.2","@deepseek-ai/dsh-llm-deepseek-api-key":"0.2.0-rc.2","@deepseek-ai/dsh-llm-retry":"0.2.0-rc.2","@deepseek-ai/dsh-message-feedback":"0.2.0-rc.2","@deepseek-ai/dsh-output-retention":"0.2.0-rc.2","@deepseek-ai/dsh-plan-mode":"0.2.0-rc.2","@deepseek-ai/dsh-ptc-runtime":"0.2.0-rc.2","@deepseek-ai/dsh-repeat-tool-reminder":"0.2.0-rc.2","@deepseek-ai/dsh-sandbox":"0.2.0-rc.2","@deepseek-ai/dsh-schedule":"0.2.0-rc.2","@deepseek-ai/dsh-scope":"0.2.0-rc.2","@deepseek-ai/dsh-session":"0.2.0-rc.2","@deepseek-ai/dsh-session-checkpoint-policy":"0.2.0-rc.2","@deepseek-ai/dsh-session-format":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-catalog":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v0-to-v1":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v1-to-v2":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v2-to-v3":"0.2.0-rc.2","@deepseek-ai/dsh-session-format-v3-to-v4":"0.2.0-rc.2","@deepseek-ai/dsh-session-persistence":"0.2.0-rc.2","@deepseek-ai/dsh-session-projection":"0.2.0-rc.2","@deepseek-ai/dsh-session-projection-cache":"0.2.0-rc.2","@deepseek-ai/dsh-session-query":"0.2.0-rc.2","@deepseek-ai/dsh-session-reference":"0.2.0-rc.2","@deepseek-ai/dsh-session-title":"0.2.0-rc.2","@deepseek-ai/dsh-session-title-first-prompt-llm":"0.2.0-rc.2","@deepseek-ai/dsh-session-title-llm":"0.2.0-rc.2","@deepseek-ai/dsh-settings":"0.2.0-rc.2","@deepseek-ai/dsh-skill":"0.2.0-rc.2","@deepseek-ai/dsh-spill":"0.2.0-rc.2","@deepseek-ai/dsh-spill-policy":"0.2.0-rc.2","@deepseek-ai/dsh-storage":"0.2.0-rc.2","@deepseek-ai/dsh-storage-domain":"0.2.0-rc.2","@deepseek-ai/dsh-subagent":"0.2.0-rc.2","@deepseek-ai/dsh-subagent-in-process-driver":"0.2.0-rc.2","@deepseek-ai/dsh-subagent-spawn-in-process":"0.2.0-rc.2","@deepseek-ai/dsh-system-prompt":"0.2.0-rc.2","@deepseek-ai/dsh-timeout":"0.2.0-rc.2","@deepseek-ai/dsh-token-meter":"0.2.0-rc.2","@deepseek-ai/dsh-tool-ask-user":"0.2.0-rc.2","@deepseek-ai/dsh-tool-call-timeout-policy":"0.2.0-rc.2","@deepseek-ai/dsh-tool-fs":"0.2.0-rc.2","@deepseek-ai/dsh-tool-goal":"0.2.0-rc.2","@deepseek-ai/dsh-tool-jobs":"0.2.0-rc.2","@deepseek-ai/dsh-tool-skill":"0.2.0-rc.2","@deepseek-ai/dsh-tool-subagent":"0.2.0-rc.2","@deepseek-ai/dsh-tool-web":"0.2.0-rc.2","@deepseek-ai/dsh-tool-workflow":"0.2.0-rc.2","@deepseek-ai/dsh-tools":"0.2.0-rc.2","@deepseek-ai/dsh-typert-protocol":"0.2.0-rc.2","@deepseek-ai/dsh-typert-registry":"0.2.0-rc.2","@deepseek-ai/dsh-user-approval":"0.2.0-rc.2","@deepseek-ai/dsh-user-questions":"0.2.0-rc.2","@deepseek-ai/dsh-util-values":"0.2.0-rc.2","@deepseek-ai/dsh-web":"0.2.0-rc.2","@deepseek-ai/dsh-web-fetch-http":"0.2.0-rc.2","@deepseek-ai/dsh-web-search-deepseek":"0.2.0-rc.2","@deepseek-ai/dsh-workflow":"0.2.0-rc.2","@deepseek-ai/dsh-workspace":"0.2.0-rc.2","@deepseek-ai/schemastery":"3.18.4","@mixmark-io/domino":"2.2.0","@modelcontextprotocol/sdk":"1.30.0",acorn:"8.18.0","fast-png":"8.0.0","jpeg-js":"0.4.4","just-bash":"3.4.2",playwright:"^1.49.0",sucrase:"3.35.1",typescript:"^6.0.3",vitest:"^4.1.8",ws:"^8.21.0"}}});var o1,TSe,ISe,B2=ce(()=>{"use strict";_Se();o1=gK.version,TSe=gK.dshEdge.upstreamVersion,ISe=`npx dsh-edge@${o1.includes("-")?"next":"latest"} upgrade`});function O0t(e){let t=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/iu.exec(e);if(t!==null)return t[1];let n=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/iu.exec(e);if(n!==null){let r=parseInt(n[1],16),i=parseInt(n[2],16);return`${String(r>>8)}.${String(r&255)}.${String(i>>8)}.${String(i&255)}`}}function N0t(e){return/^\d+\.\d+\.\d+\.\d+$/u.test(e)||e.includes(":")}function zh(e){let t=new URL(e);if(t.protocol!=="http:"&&t.protocol!=="https:")throw new Error("MCP server URL must use http: or https: protocol.");let n=t.hostname.toLowerCase(),r=n.endsWith(".")?n.slice(0,-1):n,i=r.startsWith("[")&&r.endsWith("]")?r.slice(1,-1):r;if(!(i==="localhost"||i==="127.0.0.1"||i==="::1")){for(let s of C0t)if(i.endsWith(s))throw new Error(`MCP server hostname "${i}" is blocked.`);if(N0t(i)){let s=O0t(i),o=s??i;for(let c of R0t)if(c.test(o))throw new Error(`MCP server address "${i}" is a private IP and is blocked.`);if(s===void 0){for(let c of $0t)if(c.test(i))throw new Error(`MCP server address "${i}" is a private IP and is blocked.`)}}}}function P0t(e){return e?.type==="bearer"&&e.token!==void 0?{Authorization:`Bearer ${e.token}`}:{}}async function ASe(e,t,n){zh(e);let r=new hN(new URL(e),{requestInit:{headers:P0t(t),signal:n},fetch:a1}),i=new pN({name:"dsh-edge",version:o1},{capabilities:{},jsonSchemaValidator:D0t});return await i.connect(r),{client:i,close:a(async()=>{await i.close().catch(()=>{})},"close")}}async function CSe(e,t,n){let r=AbortSignal.timeout(So.probeTimeoutMs),i;try{i=await ASe(t,n,r)}catch(c){throw new Error(yf(c instanceof Error?c.message:String(c)))}let{client:s,close:o}=i;try{let c=[],l=new Set,u=new Set,d;for(let h=0;h<So.maxCatalogPages;h++){let g=await s.listTools(d===void 0?void 0:{cursor:d},{signal:r});for(let y of g.tools){if(c.length>=So.maxToolsPerServer)break;let v=xSe(e,y.name);if(l.has(v))throw new Error(`Server listed tool "${y.name}" more than once`);l.add(v);let w=y.annotations?.readOnlyHint,b=SSe(y.outputSchema);c.push({name:y.name,publicName:v,description:y.description??"",inputSchema:y.inputSchema??{type:"object"},...b!==void 0?{outputSchema:b}:{},...w!==void 0?{annotations:{readOnlyHint:w}}:{}})}if(c.length>=So.maxToolsPerServer||(d=g.nextCursor??void 0,d===void 0))break;if(u.has(d))throw new Error("Server repeated a tools/list continuation cursor");u.add(d)}let p=s.getServerVersion?.(),f=s.getInstructions?.();return{tools:c,serverInfo:p?{name:p.name,version:p.version}:void 0,instructions:typeof f=="string"&&f.length>0?f.slice(0,So.maxInstructionsLength):void 0}}finally{await o()}}async function xN(e,t,n,r,i,s){let o=s??So.callTimeoutMs,c=i?AbortSignal.any([i,AbortSignal.timeout(o)]):AbortSignal.timeout(o),l;try{l=await ASe(e,r,c)}catch(u){throw new Error(yf(u instanceof Error?u.message:String(u)))}try{let u=await l.client.callTool({name:t,arguments:n},void 0,{signal:c});return{content:u.content??[],structuredContent:u.structuredContent,isError:u.isError===!0}}catch(u){throw new Error(yf(u instanceof Error?u.message:String(u)))}finally{await l.close()}}var C0t,R0t,$0t,D0t,a1,W2=ce(()=>{"use strict";Oxe();dSe();wSe();bN();wN();B2();C0t=[".internal",".local",".localhost"],R0t=[/^127\./u,/^10\./u,/^172\.(1[6-9]|2\d|3[01])\./u,/^192\.168\./u,/^0\./u,/^169\.254\./u],$0t=[/^::1$/u,/^fc/iu,/^fd/iu,/^fe[89ab][0-9a-f]:/iu];a(O0t,"extractMappedIPv4");a(N0t,"isIpAddress");a(zh,"assertSafeUrl");a(P0t,"buildHeaders");D0t=new vN,a1=a(async(e,t)=>{let n=await globalThis.fetch(e,{...t,redirect:"manual"});if(n.status>=300&&n.status<400)throw new Error(`MCP server returned HTTP ${String(n.status)} redirect; redirects are blocked for security.`);return n},"noRedirectFetch");a(ASe,"connectClient");a(CSe,"probe");a(xN,"callTool")});import{Buffer as M0t}from"node:buffer";function q0t(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&F0t.has(e.code)}function $Se(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&j0t.has(e.code)}function OSe(e,t,n){let r=M0t.from(e,"base64");if(e.length===0&&t==="reject"||r.toString("base64")!==e)throw new ir(n==="INVALID_IMAGE_BASE64"?"Image upload is not canonical base64.":"File upload is not canonical base64.",n);return new Uint8Array(r)}function U0t(e){return OSe(e,"reject","INVALID_IMAGE_BASE64")}function z0t(e){return{data:U0t(e.data),mediaType:e.mediaType,...e.name===void 0?{}:{name:e.name}}}async function H2(e,t){return e.saveImages(t.map(z0t))}async function B0t(e,t){return e.saveFile({data:OSe(t.data,"accept","INVALID_FILE_BASE64"),...t.name===void 0?{}:{name:t.name}})}function NSe(e,t,n){let r=Math.min(1,Math.sqrt(n/(e*t)));if(r===1)return{width:e,height:t};if(e>=t){let o=Math.max(1,Math.floor(e*r)),c=Math.max(1,Math.round(o*t/e));for(;o*c>n&&o>1;)o-=1,c=Math.max(1,Math.round(o*t/e));return{width:o,height:c}}let i=Math.max(1,Math.floor(t*r)),s=Math.max(1,Math.round(i*e/t));for(;s*i>n&&i>1;)i-=1,s=Math.max(1,Math.round(i*e/t));return{width:s,height:i}}function yK(e,t,n){return n>=Math.max(e,t)?{width:e,height:t}:e>=t?{width:n,height:Math.max(1,Math.round(n*t/e))}:{width:Math.max(1,Math.round(n*e/t)),height:n}}var RSe,L0t,j0t,F0t,ir,vK,Bh=ce(()=>{Hn();RSe=["TOO_MANY_IMAGES","IMAGES_TOO_LARGE","UNSUPPORTED_IMAGE_TYPE","INVALID_IMAGE_BASE64","INVALID_IMAGE","IMAGE_TYPE_MISMATCH","IMAGE_TOO_LARGE","IMAGE_TOO_MANY_PIXELS","IMAGE_DIMENSION_TOO_LARGE"],L0t=[...RSe,"INVALID_FILE_BASE64","INVALID_ATTACHMENT_REF","ATTACHMENT_CORRUPT","ATTACHMENT_WRITE_FAILED","ATTACHMENT_NOT_FOUND","ATTACHMENT_READ_FAILED","ATTACHMENT_PROJECTION_UNSUPPORTED","ATTACHMENT_FILES_UNSUPPORTED"],j0t=new Set(RSe),F0t=new Set(L0t),ir=class extends Error{static{a(this,"AttachmentError")}code;constructor(e,t,n){super(e,n),this.name="AttachmentError",this.code=t}};a(q0t,"isAttachmentError");a($Se,"isImageAdmissionError");a(OSe,"decodeCanonicalBase64");a(U0t,"decodeBase64");a(z0t,"saveInput");a(H2,"admitEncodedImages");a(B0t,"admitEncodedFile");a(NSe,"requestImageDimensions");a(yK,"longEdgeDimensions");vK=class extends xt{static{a(this,"AttachmentStore")}constructor(e){super(e,"attachments")}validateImageBatch(e){let{maxImagesPerMessage:t,maxMessageImageBytes:n,mediaTypes:r}=this.imageLimits;if(e.length>t)throw new ir("Image batch exceeds the configured image-count limit.","TOO_MANY_IMAGES");if(e.reduce((i,s)=>i+s.data.byteLength,0)>n)throw new ir("Image batch exceeds the configured aggregate image-byte limit.","IMAGES_TOO_LARGE");for(let i of e)if(!r.includes(i.mediaType))throw new ir(`Image type ${i.mediaType} is not accepted by this deployment.`,"UNSUPPORTED_IMAGE_TYPE")}async saveImages(e){this.validateImageBatch(e);for(let n of e)await this.validateImage(n);let t=[];for(let n of e)t.push(await this.saveImage(n));return t}async admitPromptContent(e){if(e.every(r=>r.type!=="image"))return e.map(r=>r.type==="text"?{type:"text",text:r.text}:{type:"file",attachment:r.attachment});let t=await H2(this,e.filter(r=>r.type==="image")),n=0;return e.map(r=>r.type==="text"?{type:"text",text:r.text}:r.type==="file"?{type:"file",attachment:r.attachment}:{type:"image",attachment:t[n++]})}admitEncodedFile(e){return B0t(this,e)}isAttachmentError(e){return q0t(e)}imageHostPath(e){}saveFile(e){return Promise.reject(new ir("The mounted attachment provider cannot store verbatim files.","ATTACHMENT_FILES_UNSUPPORTED"))}saveFileStream(e){return Promise.reject(new ir("The mounted attachment provider cannot stream verbatim files.","ATTACHMENT_FILES_UNSUPPORTED"))}async*readFileStream(e,t){t?.throwIfAborted(),await Promise.reject(new ir("The mounted attachment provider cannot read verbatim files.","ATTACHMENT_FILES_UNSUPPORTED"))}fileHostPath(e){}readImageRequest(e,t,n){return n?.throwIfAborted(),Promise.reject(new ir("The mounted attachment provider cannot derive model-request images.","ATTACHMENT_PROJECTION_UNSUPPORTED"))}}});var kN={};In(kN,{buildAuthorizationUrl:()=>X0t,discoverEndpoints:()=>J0t,exchangeCode:()=>Q0t,isTokenExpired:()=>t1t,refreshToken:()=>e1t,registerClient:()=>Y0t});function LSe(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(2,"0")).join("").slice(0,e)}async function Z0t(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return btoa(String.fromCharCode(...new Uint8Array(n))).replace(/\+/gu,"-").replace(/\//gu,"_").replace(/=/gu,"")}async function J0t(e){let t=AbortSignal.timeout(SN),n=new URL(e),r=n.pathname==="/"?"/.well-known/oauth-protected-resource":`/.well-known/oauth-protected-resource${n.pathname}`,i=new URL(r,n.origin);zh(i.href);let s=await a1(i.href,{signal:t});if(!s.ok)throw new Error(`PRM discovery failed: HTTP ${s.status}`);let c=(await s.json()).authorization_servers?.[0];if(typeof c!="string")throw new Error("No authorization server in PRM");let l=new URL(c),u=l.pathname==="/"?"/.well-known/oauth-authorization-server":`/.well-known/oauth-authorization-server${l.pathname}`,d=new URL(u,l.origin);zh(d.href);let p=await a1(d.href,{signal:t});if(!p.ok)throw new Error(`AS metadata failed: HTTP ${p.status}`);let f=await p.json();if(typeof f.authorization_endpoint!="string"||typeof f.token_endpoint!="string")throw new Error("Missing required endpoints in AS metadata");return{authorization:f.authorization_endpoint,token:f.token_endpoint,registration:f.registration_endpoint}}async function Y0t(e,t,n){let r=AbortSignal.timeout(SN);zh(e);let i=await a1(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({client_name:n,redirect_uris:[t],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none"}),signal:r});if(!i.ok)throw new Error(`DCR failed: HTTP ${i.status}`);let s=await i.json();if(typeof s.client_id!="string")throw new Error("DCR response missing client_id");return{clientId:s.client_id,clientSecret:s.client_secret}}async function X0t(e,t,n,r,i){let s=LSe(32),o=LSe(64),c=await Z0t(o),l=new URL(e.authorization);for(let[u,d]of Object.entries({response_type:"code",client_id:t.clientId,redirect_uri:n,state:s,code_challenge:c,code_challenge_method:"S256",resource:i}))l.searchParams.set(u,d);return{authorizationUrl:l.href,pendingFlow:{state:s,codeVerifier:o,redirectUri:n,serverName:r,serverUrl:i,stagedClient:t,createdAt:Date.now()}}}async function Q0t(e,t,n,r,i,s){let o=AbortSignal.timeout(SN),c=new URLSearchParams({grant_type:"authorization_code",code:n,redirect_uri:i,client_id:t.clientId,code_verifier:r});s!==void 0&&c.set("resource",s),t.clientSecret!==void 0&&c.set("client_secret",t.clientSecret),zh(e);let l=await a1(e,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:c.toString(),signal:o});if(!l.ok)throw new Error(`Token exchange failed: HTTP ${l.status}`);return jSe(await l.json())}async function e1t(e,t,n,r){let i=AbortSignal.timeout(SN),s=new URLSearchParams({grant_type:"refresh_token",refresh_token:n,client_id:t.clientId});r!==void 0&&s.set("resource",r),t.clientSecret!==void 0&&s.set("client_secret",t.clientSecret),zh(e);let o=await a1(e,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:s.toString(),signal:i});if(!o.ok)throw new Error(`Token refresh failed: HTTP ${o.status}`);return jSe(await o.json())}function jSe(e){let t=e;if(typeof t.access_token!="string")throw new Error("Missing access_token");let n=typeof t.expires_in=="number"?t.expires_in:void 0;return{accessToken:t.access_token,refreshToken:typeof t.refresh_token=="string"?t.refresh_token:void 0,expiresAt:n!==void 0?Date.now()+n*1e3:void 0,tokenType:typeof t.token_type=="string"?t.token_type:"Bearer",scope:typeof t.scope=="string"?t.scope:void 0}}function t1t(e){return e.expiresAt===void 0?!1:Date.now()>e.expiresAt-12e4}var SN,EN=ce(()=>{"use strict";W2();SN=1e4;a(LSe,"randomString");a(Z0t,"sha256Base64Url");a(J0t,"discoverEndpoints");a(Y0t,"registerClient");a(X0t,"buildAuthorizationUrl");a(Q0t,"exchangeCode");a(e1t,"refreshToken");a(jSe,"parseTokenResponse");a(t1t,"isTokenExpired")});var Un,VSe,V2=ce(()=>{Hn();kr();Un=class extends Jr{static{a(this,"FsError")}code;constructor(e,t,n){super(e,t,n),this.code=t}},VSe=class extends xt{static{a(this,"FileSystem")}constructor(e){super(e,"fs")}watch(e,t,n){return n.throwIfAborted(),Promise.reject(new Un("Filesystem watching is not supported by this provider.","FS_IO_ERROR"))}get sandboxMode(){}processPathFromHostPath(e){}}});function LK(e){return DN.test(e)}function MN(e){return e.invocation.modelInvocable}function Db(e){return e.invocation.userInvocable}function jK(e){let t=Fvt(e);return[`<skill_content name="${qvt(e.name)}">`,"<skill_resources>",...t,"</skill_resources>","","<skill_instructions>",e.content,"</skill_instructions>","</skill_content>"].join(`
156
156
  `)}function Fvt(e){let t=e.resourceBase;if(t===void 0)return[`Resources for this skill are managed by provider "${Pb(e.provider)}".`,"Load referenced resources only as needed."];switch(t.kind){case"directory":return[`Base directory for this skill: ${Pb(t.path)}`,"Resolve relative paths mentioned by this skill against the base directory before using them. Load referenced resources only as needed."];case"url":return[`Base URL for this skill: ${Pb(t.url)}`,"Resolve relative URLs mentioned by this skill against the base URL before using them. Load referenced resources only as needed."];case"opaque":return[`Resources for this skill: ${Pb(t.description)}`,"Load referenced resources only as needed."];default:return Ei(t,"SkillResourceBase.kind")}}function qvt(e){return e.replaceAll("&","&amp;").replaceAll('"',"&quot;").replaceAll("<","&lt;")}function Pb(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}function zvt(e,t){if(Array.isArray(e))return{candidates:e,complete:!0};if(e===null||typeof e!="object")throw fke(t);let n=e;if(!Array.isArray(n.candidates)||typeof n.complete!="boolean")throw fke(t);return n}function fke(e){return new TypeError(`skill provider "${e}" list() must return an array or { candidates, complete } observation`)}function Wvt(e){return{name:e.name,description:e.description,...e.whenToUse!==void 0?{whenToUse:e.whenToUse}:{},invocation:e.invocation,source:e.source,provider:e.provider,...e.resourceBase!==void 0?{resourceBase:e.resourceBase}:{},rank:jvt,locator:e,...e.path!==void 0?{path:e.path}:{},...e.metadata!==void 0?{metadata:e.metadata}:{}}}function Hvt(e,t){if(typeof e.name!="string")throw new TypeError(`skill provider "${t}" returned a non-string skill name`);if(!DN.test(e.name))throw new Error(`skill provider "${t}" returned invalid skill name "${e.name}"`);if(typeof e.description!="string")throw new TypeError(`skill provider "${t}" returned skill "${e.name}" with a non-string description`);if(e.description.length===0)throw new Error(`skill provider "${t}" returned skill "${e.name}" without a description`);if(FK(e.invocation,`skill provider "${t}" returned skill "${e.name}"`),e.whenToUse!==void 0&&typeof e.whenToUse!="string")throw new TypeError(`skill provider "${t}" returned skill "${e.name}" with a non-string whenToUse`);if(typeof e.source!="string")throw new TypeError(`skill provider "${t}" returned skill "${e.name}" with a non-string source`);if(typeof e.rank!="number"||!Number.isFinite(e.rank))throw new Error(`skill provider "${t}" returned skill "${e.name}" with an invalid rank`);if(typeof e.provider!="string")throw new TypeError(`skill provider "${t}" returned skill "${e.name}" with a non-string provider`);if(e.provider!==t)throw new Error(`skill provider "${t}" returned skill "${e.name}" for provider "${e.provider}"`);if(e.path!==void 0&&typeof e.path!="string")throw new TypeError(`skill provider "${t}" returned skill "${e.name}" with a non-string path`)}function Vvt(e){if(!DN.test(e.name))throw new Error(`invalid skill name "${e.name}"`);if(e.description.length===0)throw new Error(`skill "${e.name}" requires a description`);FK(e.invocation,`runtime skill "${e.name}"`)}function Gvt(e){let t=e.name,n=e.description,r=e.whenToUse,i=e.invocation,s=e.source,o=e.provider,c=e.content,l=e.path;if(typeof t!="string")throw new TypeError("loaded skill name must be a string");if(!DN.test(t))throw new Error(`loaded skill has invalid name "${t}"`);if(typeof n!="string")throw new TypeError(`loaded skill "${t}" description must be a string`);if(n.length===0)throw new Error(`loaded skill "${t}" requires a description`);if(FK(i,`loaded skill "${t}"`),r!==void 0&&typeof r!="string")throw new TypeError(`loaded skill "${t}" whenToUse must be a string`);if(typeof s!="string")throw new TypeError(`loaded skill "${t}" source must be a string`);if(typeof o!="string")throw new TypeError(`loaded skill "${t}" provider must be a string`);if(typeof c!="string")throw new TypeError(`loaded skill "${t}" content must be a string`);if(l!==void 0&&typeof l!="string")throw new TypeError(`loaded skill "${t}" path must be a string`)}function Kvt(e){let{name:t,description:n,whenToUse:r,invocation:i,source:s,provider:o,resourceBase:c}=e;return{name:t,...e.path===void 0?{}:{path:e.path},description:n,...r!==void 0?{whenToUse:r}:{},invocation:i,source:s,provider:o,...c!==void 0?{resourceBase:c}:{}}}function FK(e,t){if(e===void 0)return;if(typeof e!="object"||e===null||Array.isArray(e))throw new TypeError(`${t} with a non-object invocation policy`);let n=e;if(typeof n.modelInvocable!="boolean")throw new TypeError(`${t} with a non-boolean invocation.modelInvocable`);if(typeof n.userInvocable!="boolean")throw new TypeError(`${t} with a non-boolean invocation.userInvocable`)}function Zvt(e,t){return yke(e.name,t.name)}function yke(e,t){return e<t?-1:e>t?1:0}function Jvt(e,t){return e.candidate.rank-t.candidate.rank||e.providerOrder-t.providerOrder||e.localOrder-t.localOrder}function Yvt(e,t,n=1){if(!Number.isInteger(t)||t<n)throw new Error(`skill: ${e} must be an integer greater than or equal to ${n}`)}function hke(e,t){return t===void 0?e:(J2(t),new Promise((n,r)=>{let i=a(()=>{t.removeEventListener("abort",s)},"cleanup"),s=a(()=>{i(),r(PN(t.reason))},"onAbort");t.addEventListener("abort",s,{once:!0}),e.then(o=>{i(),n(o)},o=>{i(),r(PN(o))})}))}function J2(e){if(e?.aborted===!0)throw PN(e.reason)}function PN(e){try{if(e instanceof Error)return e}catch{}return new Error(NN(e))}function NN(e){try{return String(e)}catch{return"[unrenderable thrown value]"}}var DN,pke,Lvt,ON,jvt,mke,Uvt,gke,Bvt,Mb=ce(()=>{Hn();ls();jc();xn();DN=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,pke=128,Lvt=2,ON="runtime",jvt=250,mke=600;a(LK,"isSkillName");a(MN,"isModelInvocable");a(Db,"isUserInvocable");a(jK,"renderSkillContent");a(Fvt,"renderResourceHint");a(qvt,"escapeAttr");a(Pb,"escapeText");Uvt=class{static{a(this,"SkillLayer")}providers;runtime=new Map;constructor(e){this.providers=new Xp(t=>new Error(e===void 0?`a skill provider named "${t}" is already registered`:`a skill provider named "${t}" is already registered in this scope`))}isEmpty(){return this.providers.isEmpty()&&this.runtime.size===0}},gke=class extends xt{static{a(this,"SkillRegistry")}static Config=U.object({collectCacheMaxEntries:U.number().default(pke)});collectCacheMaxEntries;layers=new Qp(e=>new Uvt(e),()=>{this.invalidateCache()});collectCache=new Map;revision=0;nextProviderOrder=0;scopeIds=new WeakMap;nextScopeId=1;constructor(e,t={}){super(e,"skills"),this.collectCacheMaxEntries=t.collectCacheMaxEntries??pke,Yvt("collectCacheMaxEntries",this.collectCacheMaxEntries)}registerProvider(e){let t=new AbortController,n,r,i={signal:t.signal,invalidate:a(()=>{let s=n;s!==void 0&&s.layer.providers.get(s.name)?.provider===r&&this.invalidateCache()},"invalidate")};try{r=e(i);let s=r.name;if(s===ON)throw new Error(`"${ON}" is reserved for runtime skill registrations`);let o=this.nextProviderOrder;return this.nextProviderOrder+=1,this.layers.effect(this.ctx,c=>{let l=c.providers.insert(s,{provider:r,order:o});return n={layer:c,name:s},()=>{n=void 0,l(),t.abort(new Error(`skill provider "${s}" disposed`))}},{label:"skills.registerProvider()"})}catch(s){throw t.abort(s),s}}register(e){Vvt(e);let t=Lc(this.ctx),n=t===void 0?this.layers.global:this.layers.peek(t);if(n!==void 0&&n.runtime.has(e.name))return this.ctx.logger.warn(`runtime skill "${e.name}" ignored because it is already registered`),()=>{};let r={...e,invocation:e.invocation??{modelInvocable:!0,userInvocable:!0},provider:e.provider??ON};return this.layers.effect(this.ctx,i=>(i.runtime.set(r.name,r),()=>{i.runtime.delete(r.name)}),{label:"skills.register()"})}async list(e={}){return(await this.snapshot(e)).skills}async snapshot(e={}){let t=await this.collect(e);return{skills:[...t.entries.values()].map(n=>Kvt(n.candidate)).sort(Zvt),complete:t.cacheable}}async get(e,t={}){if(!LK(e))return;let n=await this.collect(t);J2(t.signal);let r=n.entries.get(e);if(r===void 0)return;let i=await hke(r.provider.get(r.candidate,t),t.signal);if(i!==void 0){if(Gvt(i),i.name!==r.candidate.name){this.invalidateEntry(r);return}return i}}async collect(e){J2(e.signal);let t=1;for(;;){let n=this.revision,r=this.collectCacheKey(e.cwd,vE(e.scope),n),i=this.collectCache.get(r);if(i!==void 0)return{entries:i,cacheable:!0};let s=await this.collectFresh(e);if(J2(e.signal),n!==this.revision){if(t<Lvt){t+=1;continue}return{entries:s.entries,cacheable:!1}}if(s.cacheable&&(this.collectCache.set(r,s.entries),this.collectCache.size>this.collectCacheMaxEntries)){let o=this.collectCache.keys().next();this.collectCache.delete(o.value)}return s}}async collectFresh(e){let t=[this.layers.global,...this.layers.chainLayers(e.scope)],n=new Map,r=!0;for(let i of t){let s=await this.collectLayer(i,e);s.cacheable||(r=!1);for(let o of s.entries)n.set(o.candidate.name,o)}return{entries:n,cacheable:r}}async collectLayer(e,t){let n=await this.listLayerCandidates(e,t);n.entries.sort(Jvt);let r=new Set,i=[];for(let s of n.entries){let o=s.candidate;if(r.has(o.name)){this.ctx.logger.warn(`skill "${o.name}" from ${o.source} ignored because a higher-priority skill already exists`);continue}r.add(o.name),i.push(s)}return{entries:i,cacheable:n.cacheable}}async listLayerCandidates(e,t){J2(t.signal);let n=[],r=!0,i=0;for(let s of[...e.runtime.values()].sort((o,c)=>yke(o.name,c.name)))n.push({candidate:Wvt(s),provider:Bvt,providerOrder:-1,localOrder:i,layer:e}),i+=1;for(let{provider:s,order:o}of[...e.providers.values()]){let c=0,l;try{l=await hke(s.list(t),t.signal)}catch(d){if(t.signal?.aborted===!0)throw PN(t.signal.reason);r=!1,this.ctx.logger.warn(`skill provider "${s.name}" skipped: ${NN(d)}`)}if(l===void 0)continue;let u=zvt(l,s.name);u.complete||(r=!1);for(let d of u.candidates)Hvt(d,s.name),n.push({candidate:d,provider:s,providerOrder:o,localOrder:c,layer:e}),c+=1}return{entries:n,cacheable:r}}invalidateCache(){this.revision+=1,this.collectCache.clear(),this.notifyChange()}invalidateEntry(e){e.layer.providers.get(e.provider.name)?.provider===e.provider&&this.invalidateCache()}scopeId(e){let t=this.scopeIds.get(e);return t===void 0&&(t=this.nextScopeId,this.nextScopeId+=1,this.scopeIds.set(e,t)),t}collectCacheKey(e,t,n){return JSON.stringify({cwd:e,scopes:t.map(r=>this.scopeId(r)),revision:n})}notifyChange(){for(let e of this.ctx.events.dispatch("emit",["skills/change"]))try{let t=e();Promise.resolve(t).catch(n=>{this.ctx.logger.warn(`skills/change listener rejected: ${NN(n)}`)})}catch(t){this.ctx.logger.warn(`skills/change listener threw: ${NN(t)}`)}}};a(zvt,"normalizeProviderObservation");a(fke,"invalidProviderObservation");Bvt={name:ON,list(){return Promise.resolve([])},get(e){return Promise.resolve(e.locator)}};a(Wvt,"runtimeCandidate");a(Hvt,"validateCandidate");a(Vvt,"validateRuntimeSkill");a(Gvt,"validateDefinition");a(Kvt,"toSummary");a(FK,"validateInvocation");a(Zvt,"compareSkillSummary");a(yke,"compareCodePoints");a(Jvt,"compareIndexedCandidates");a(Yvt,"assertPositiveInteger");a(hke,"waitWithAbort");a(J2,"throwIfAborted");a(PN,"toError");a(NN,"errorMessage")});var td,jb=ce(()=>{td=class{static{a(this,"Deque")}buffer=new Array(16);head=0;count=0;get size(){return this.count}pushBack(e){this.ensureCapacity();let t=this.head+this.count;this.buffer[t<this.buffer.length?t:t-this.buffer.length]=e,this.count+=1}pushFront(e){this.ensureCapacity(),this.head=this.head===0?this.buffer.length-1:this.head-1,this.buffer[this.head]=e,this.count+=1}popFront(){if(this.count===0)return;let e=this.buffer[this.head];return this.buffer[this.head]=void 0,this.head+=1,this.head===this.buffer.length&&(this.head=0),this.count-=1,this.compact(),e}clear(){this.buffer=new Array(16),this.head=0,this.count=0}ensureCapacity(){this.count<this.buffer.length||this.resize(this.buffer.length*2)}compact(){if(this.count===0){this.head=0;return}this.buffer.length>16&&this.count<=this.buffer.length/4&&this.resize(Math.max(16,this.buffer.length/2))}resize(e){let t=new Array(e),n=this.head;for(let r=0;r<this.count;r+=1)t[r]=this.buffer[n],n+=1,n===this.buffer.length&&(n=0);this.buffer=t,this.head=0}}});var Hh,lEe,eZ=ce(()=>{Hn();Hh=class extends Error{static{a(this,"DirectoryPickerError")}code;path;constructor(e,t,n){super(n),this.code=e,this.path=t,this.name="DirectoryPickerError"}},lEe=class extends xt{static{a(this,"DirectoryPicker")}constructor(e){super(e,"directoryPicker")}}});var r2e=we((LLn,FP)=>{var n2e=n2e||function(e){return Buffer.from(e).toString("base64")};function CEt(e){var t=this,n=Math.round,r=Math.floor,i=new Array(64),s=new Array(64),o=new Array(64),c=new Array(64),l,u,d,p,f=new Array(65535),h=new Array(65535),g=new Array(64),y=new Array(64),v=[],w=0,b=7,S=new Array(64),k=new Array(64),E=new Array(64),_=new Array(256),I=new Array(2048),L,D=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],j=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],O=[0,1,2,3,4,5,6,7,8,9,10,11],V=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],Q=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],A=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],z=[0,1,2,3,4,5,6,7,8,9,10,11],C=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],R=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function $(oe){for(var Me=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],Se=0;Se<64;Se++){var at=r((Me[Se]*oe+50)/100);at<1?at=1:at>255&&(at=255),i[D[Se]]=at}for(var ze=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],Le=0;Le<64;Le++){var gt=r((ze[Le]*oe+50)/100);gt<1?gt=1:gt>255&&(gt=255),s[D[Le]]=gt}for(var nt=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],Ve=0,ht=0;ht<8;ht++)for(var Re=0;Re<8;Re++)o[Ve]=1/(i[D[Ve]]*nt[ht]*nt[Re]*8),c[Ve]=1/(s[D[Ve]]*nt[ht]*nt[Re]*8),Ve++}a($,"initQuantTables");function N(oe,Me){for(var Se=0,at=0,ze=new Array,Le=1;Le<=16;Le++){for(var gt=1;gt<=oe[Le];gt++)ze[Me[at]]=[],ze[Me[at]][0]=Se,ze[Me[at]][1]=Le,at++,Se++;Se*=2}return ze}a(N,"computeHuffmanTbl");function P(){l=N(j,O),u=N(A,z),d=N(V,Q),p=N(C,R)}a(P,"initHuffmanTbl");function G(){for(var oe=1,Me=2,Se=1;Se<=15;Se++){for(var at=oe;at<Me;at++)h[32767+at]=Se,f[32767+at]=[],f[32767+at][1]=Se,f[32767+at][0]=at;for(var ze=-(Me-1);ze<=-oe;ze++)h[32767+ze]=Se,f[32767+ze]=[],f[32767+ze][1]=Se,f[32767+ze][0]=Me-1+ze;oe<<=1,Me<<=1}}a(G,"initCategoryNumber");function Y(){for(var oe=0;oe<256;oe++)I[oe]=19595*oe,I[oe+256>>0]=38470*oe,I[oe+512>>0]=7471*oe+32768,I[oe+768>>0]=-11059*oe,I[oe+1024>>0]=-21709*oe,I[oe+1280>>0]=32768*oe+8421375,I[oe+1536>>0]=-27439*oe,I[oe+1792>>0]=-5329*oe}a(Y,"initRGBYUVTable");function X(oe){for(var Me=oe[0],Se=oe[1]-1;Se>=0;)Me&1<<Se&&(w|=1<<b),Se--,b--,b<0&&(w==255?(B(255),B(0)):B(w),b=7,w=0)}a(X,"writeBits");function B(oe){v.push(oe)}a(B,"writeByte");function ne(oe){B(oe>>8&255),B(oe&255)}a(ne,"writeWord");function ye(oe,Me){var Se,at,ze,Le,gt,nt,Ve,ht,Re=0,St,Bt=8,dt=64;for(St=0;St<Bt;++St){Se=oe[Re],at=oe[Re+1],ze=oe[Re+2],Le=oe[Re+3],gt=oe[Re+4],nt=oe[Re+5],Ve=oe[Re+6],ht=oe[Re+7];var fn=Se+ht,zt=Se-ht,Lt=at+Ve,ae=at-Ve,Ne=ze+nt,He=ze-nt,st=Le+gt,At=Le-gt,Ze=fn+st,rn=fn-st,Qt=Lt+Ne,hn=Lt-Ne;oe[Re]=Ze+Qt,oe[Re+4]=Ze-Qt;var Pt=(hn+rn)*.707106781;oe[Re+2]=rn+Pt,oe[Re+6]=rn-Pt,Ze=At+He,Qt=He+ae,hn=ae+zt;var Rr=(Ze-hn)*.382683433,Pr=.5411961*Ze+Rr,os=1.306562965*hn+Rr,ki=Qt*.707106781,or=zt+ki,as=zt-ki;oe[Re+5]=as+Pr,oe[Re+3]=as-Pr,oe[Re+1]=or+os,oe[Re+7]=or-os,Re+=8}for(Re=0,St=0;St<Bt;++St){Se=oe[Re],at=oe[Re+8],ze=oe[Re+16],Le=oe[Re+24],gt=oe[Re+32],nt=oe[Re+40],Ve=oe[Re+48],ht=oe[Re+56];var Os=Se+ht,Qs=Se-ht,ho=at+Ve,jt=at-Ve,Nn=ze+nt,mo=ze-nt,ya=Le+gt,No=Le-gt,Po=Os+ya,zo=Os-ya,va=ho+Nn,Va=ho-Nn;oe[Re]=Po+va,oe[Re+32]=Po-va;var Wl=(Va+zo)*.707106781;oe[Re+16]=zo+Wl,oe[Re+48]=zo-Wl,Po=No+mo,va=mo+jt,Va=jt+Qs;var Xc=(Po-Va)*.382683433,Ad=.5411961*Po+Xc,Cd=1.306562965*Va+Xc,Rd=va*.707106781,$d=Qs+Rd,nh=Qs-Rd;oe[Re+40]=nh+Ad,oe[Re+24]=nh-Ad,oe[Re+8]=$d+Cd,oe[Re+56]=$d-Cd,Re++}var Pp;for(St=0;St<dt;++St)Pp=oe[St]*Me[St],g[St]=Pp>0?Pp+.5|0:Pp-.5|0;return g}a(ye,"fDCTQuant");function ve(){ne(65504),ne(16),B(74),B(70),B(73),B(70),B(0),B(1),B(1),B(0),ne(1),ne(1),B(0),B(0)}a(ve,"writeAPP0");function le(oe){if(oe){ne(65505),oe[0]===69&&oe[1]===120&&oe[2]===105&&oe[3]===102?ne(oe.length+2):(ne(oe.length+5+2),B(69),B(120),B(105),B(102),B(0));for(var Me=0;Me<oe.length;Me++)B(oe[Me])}}a(le,"writeAPP1");function ke(oe,Me){ne(65472),ne(17),B(8),ne(Me),ne(oe),B(3),B(1),B(17),B(0),B(2),B(17),B(1),B(3),B(17),B(1)}a(ke,"writeSOF0");function Ee(){ne(65499),ne(132),B(0);for(var oe=0;oe<64;oe++)B(i[oe]);B(1);for(var Me=0;Me<64;Me++)B(s[Me])}a(Ee,"writeDQT");function ue(){ne(65476),ne(418),B(0);for(var oe=0;oe<16;oe++)B(j[oe+1]);for(var Me=0;Me<=11;Me++)B(O[Me]);B(16);for(var Se=0;Se<16;Se++)B(V[Se+1]);for(var at=0;at<=161;at++)B(Q[at]);B(1);for(var ze=0;ze<16;ze++)B(A[ze+1]);for(var Le=0;Le<=11;Le++)B(z[Le]);B(17);for(var gt=0;gt<16;gt++)B(C[gt+1]);for(var nt=0;nt<=161;nt++)B(R[nt])}a(ue,"writeDHT");function de(oe){typeof oe>"u"||oe.constructor!==Array||oe.forEach(Me=>{if(typeof Me=="string"){ne(65534);var Se=Me.length;ne(Se+2);var at;for(at=0;at<Se;at++)B(Me.charCodeAt(at))}})}a(de,"writeCOM");function rt(){ne(65498),ne(12),B(3),B(1),B(0),B(2),B(17),B(3),B(17),B(0),B(63),B(0)}a(rt,"writeSOS");function We(oe,Me,Se,at,ze){for(var Le=ze[0],gt=ze[240],nt,Ve=16,ht=63,Re=64,St=ye(oe,Me),Bt=0;Bt<Re;++Bt)y[D[Bt]]=St[Bt];var dt=y[0]-Se;Se=y[0],dt==0?X(at[0]):(nt=32767+dt,X(at[h[nt]]),X(f[nt]));for(var fn=63;fn>0&&y[fn]==0;fn--);if(fn==0)return X(Le),Se;for(var zt=1,Lt;zt<=fn;){for(var ae=zt;y[zt]==0&&zt<=fn;++zt);var Ne=zt-ae;if(Ne>=Ve){Lt=Ne>>4;for(var He=1;He<=Lt;++He)X(gt);Ne=Ne&15}nt=32767+y[zt],X(ze[(Ne<<4)+h[nt]]),X(f[nt]),zt++}return fn!=ht&&X(Le),Se}a(We,"processDU");function tt(){for(var oe=String.fromCharCode,Me=0;Me<256;Me++)_[Me]=oe(Me)}a(tt,"initCharLookupTable"),this.encode=function(oe,Me){var Se=new Date().getTime();Me&&Ae(Me),v=new Array,w=0,b=7,ne(65496),ve(),de(oe.comments),le(oe.exifBuffer),Ee(),ke(oe.width,oe.height),ue(),rt();var at=0,ze=0,Le=0;w=0,b=7,this.encode.displayName="_encode_";for(var gt=oe.data,nt=oe.width,Ve=oe.height,ht=nt*4,Re=nt*3,St,Bt=0,dt,fn,zt,Lt,ae,Ne,He,st;Bt<Ve;){for(St=0;St<ht;){for(Lt=ht*Bt+St,ae=Lt,Ne=-1,He=0,st=0;st<64;st++)He=st>>3,Ne=(st&7)*4,ae=Lt+He*ht+Ne,Bt+He>=Ve&&(ae-=ht*(Bt+1+He-Ve)),St+Ne>=ht&&(ae-=St+Ne-ht+4),dt=gt[ae++],fn=gt[ae++],zt=gt[ae++],S[st]=(I[dt]+I[fn+256>>0]+I[zt+512>>0]>>16)-128,k[st]=(I[dt+768>>0]+I[fn+1024>>0]+I[zt+1280>>0]>>16)-128,E[st]=(I[dt+1280>>0]+I[fn+1536>>0]+I[zt+1792>>0]>>16)-128;at=We(S,o,at,l,d),ze=We(k,c,ze,u,p),Le=We(E,c,Le,u,p),St+=32}Bt+=8}if(b>=0){var At=[];At[1]=b+1,At[0]=(1<<b+1)-1,X(At)}if(ne(65497),typeof FP>"u")return new Uint8Array(v);return Buffer.from(v);var Ze,rn};function Ae(oe){if(oe<=0&&(oe=1),oe>100&&(oe=100),L!=oe){var Me=0;oe<50?Me=Math.floor(5e3/oe):Me=Math.floor(200-oe*2),$(Me),L=oe}}a(Ae,"setQuality");function xe(){var oe=new Date().getTime();e||(e=50),tt(),P(),G(),Y(),Ae(e);var Me=new Date().getTime()-oe}a(xe,"init"),xe()}a(CEt,"JPEGEncoder");typeof FP<"u"?FP.exports=t2e:typeof window<"u"&&(window["jpeg-js"]=window["jpeg-js"]||{},window["jpeg-js"].encode=t2e);function t2e(e,t){typeof t>"u"&&(t=50);var n=new CEt(t),r=n.encode(e,t);return{data:r,width:e.width,height:e.height}}a(t2e,"encode")});var s2e=we((FLn,uJ)=>{var lJ=a((function(){"use strict";var t=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),n=4017,r=799,i=3406,s=2276,o=1567,c=3784,l=5793,u=2896;function d(){}a(d,"constructor");function p(b,S){for(var k=0,E=[],_,I,L=16;L>0&&!b[L-1];)L--;E.push({children:[],index:0});var D=E[0],j;for(_=0;_<L;_++){for(I=0;I<b[_];I++){for(D=E.pop(),D.children[D.index]=S[k];D.index>0;){if(E.length===0)throw new Error("Could not recreate Huffman Table");D=E.pop()}for(D.index++,E.push(D);E.length<=_;)E.push(j={children:[],index:0}),D.children[D.index]=j.children,D=j;k++}_+1<L&&(E.push(j={children:[],index:0}),D.children[D.index]=j.children,D=j)}return E[0].children}a(p,"buildHuffmanTable");function f(b,S,k,E,_,I,L,D,j,O){var V=k.precision,Q=k.samplesPerLine,A=k.scanLines,z=k.mcusPerLine,C=k.progressive,R=k.maxH,$=k.maxV,N=S,P=0,G=0;function Y(){if(G>0)return G--,P>>G&1;if(P=b[S++],P==255){var Re=b[S++];if(Re)throw new Error("unexpected marker: "+(P<<8|Re).toString(16))}return G=7,P>>>7}a(Y,"readBit");function X(Re){for(var St=Re,Bt;(Bt=Y())!==null;){if(St=St[Bt],typeof St=="number")return St;if(typeof St!="object")throw new Error("invalid huffman sequence")}return null}a(X,"decodeHuffman");function B(Re){for(var St=0;Re>0;){var Bt=Y();if(Bt===null)return;St=St<<1|Bt,Re--}return St}a(B,"receive");function ne(Re){var St=B(Re);return St>=1<<Re-1?St:St+(-1<<Re)+1}a(ne,"receiveAndExtend");function ye(Re,St){var Bt=X(Re.huffmanTableDC),dt=Bt===0?0:ne(Bt);St[0]=Re.pred+=dt;for(var fn=1;fn<64;){var zt=X(Re.huffmanTableAC),Lt=zt&15,ae=zt>>4;if(Lt===0){if(ae<15)break;fn+=16;continue}fn+=ae;var Ne=t[fn];St[Ne]=ne(Lt),fn++}}a(ye,"decodeBaseline");function ve(Re,St){var Bt=X(Re.huffmanTableDC),dt=Bt===0?0:ne(Bt)<<j;St[0]=Re.pred+=dt}a(ve,"decodeDCFirst");function le(Re,St){St[0]|=Y()<<j}a(le,"decodeDCSuccessive");var ke=0;function Ee(Re,St){if(ke>0){ke--;return}for(var Bt=I,dt=L;Bt<=dt;){var fn=X(Re.huffmanTableAC),zt=fn&15,Lt=fn>>4;if(zt===0){if(Lt<15){ke=B(Lt)+(1<<Lt)-1;break}Bt+=16;continue}Bt+=Lt;var ae=t[Bt];St[ae]=ne(zt)*(1<<j),Bt++}}a(Ee,"decodeACFirst");var ue=0,de;function rt(Re,St){for(var Bt=I,dt=L,fn=0;Bt<=dt;){var zt=t[Bt],Lt=St[zt]<0?-1:1;switch(ue){case 0:var ae=X(Re.huffmanTableAC),Ne=ae&15,fn=ae>>4;if(Ne===0)fn<15?(ke=B(fn)+(1<<fn),ue=4):(fn=16,ue=1);else{if(Ne!==1)throw new Error("invalid ACn encoding");de=ne(Ne),ue=fn?2:3}continue;case 1:case 2:St[zt]?St[zt]+=(Y()<<j)*Lt:(fn--,fn===0&&(ue=ue==2?3:0));break;case 3:St[zt]?St[zt]+=(Y()<<j)*Lt:(St[zt]=de<<j,ue=0);break;case 4:St[zt]&&(St[zt]+=(Y()<<j)*Lt);break}Bt++}ue===4&&(ke--,ke===0&&(ue=0))}a(rt,"decodeACSuccessive");function We(Re,St,Bt,dt,fn){var zt=Bt/z|0,Lt=Bt%z,ae=zt*Re.v+dt,Ne=Lt*Re.h+fn;Re.blocks[ae]===void 0&&O.tolerantDecoding||St(Re,Re.blocks[ae][Ne])}a(We,"decodeMcu");function tt(Re,St,Bt){var dt=Bt/Re.blocksPerLine|0,fn=Bt%Re.blocksPerLine;Re.blocks[dt]===void 0&&O.tolerantDecoding||St(Re,Re.blocks[dt][fn])}a(tt,"decodeBlock");var Ae=E.length,xe,oe,Me,Se,at,ze;C?I===0?ze=D===0?ve:le:ze=D===0?Ee:rt:ze=ye;var Le=0,gt,nt;Ae==1?nt=E[0].blocksPerLine*E[0].blocksPerColumn:nt=z*k.mcusPerColumn,_||(_=nt);for(var Ve,ht;Le<nt;){for(oe=0;oe<Ae;oe++)E[oe].pred=0;if(ke=0,Ae==1)for(xe=E[0],at=0;at<_;at++)tt(xe,ze,Le),Le++;else for(at=0;at<_;at++){for(oe=0;oe<Ae;oe++)for(xe=E[oe],Ve=xe.h,ht=xe.v,Me=0;Me<ht;Me++)for(Se=0;Se<Ve;Se++)We(xe,ze,Le,Me,Se);if(Le++,Le===nt)break}if(Le===nt)do{if(b[S]===255&&b[S+1]!==0)break;S+=1}while(S<b.length-2);if(G=0,gt=b[S]<<8|b[S+1],gt<65280)throw new Error("marker was not found");if(gt>=65488&&gt<=65495)S+=2;else break}return S-N}a(f,"decodeScan");function h(b,S){var k=[],E=S.blocksPerLine,_=S.blocksPerColumn,I=E<<3,L=new Int32Array(64),D=new Uint8Array(64);function j(N,P,G){var Y=S.quantizationTable,X,B,ne,ye,ve,le,ke,Ee,ue,de=G,rt;for(rt=0;rt<64;rt++)de[rt]=N[rt]*Y[rt];for(rt=0;rt<8;++rt){var We=8*rt;if(de[1+We]==0&&de[2+We]==0&&de[3+We]==0&&de[4+We]==0&&de[5+We]==0&&de[6+We]==0&&de[7+We]==0){ue=l*de[0+We]+512>>10,de[0+We]=ue,de[1+We]=ue,de[2+We]=ue,de[3+We]=ue,de[4+We]=ue,de[5+We]=ue,de[6+We]=ue,de[7+We]=ue;continue}X=l*de[0+We]+128>>8,B=l*de[4+We]+128>>8,ne=de[2+We],ye=de[6+We],ve=u*(de[1+We]-de[7+We])+128>>8,Ee=u*(de[1+We]+de[7+We])+128>>8,le=de[3+We]<<4,ke=de[5+We]<<4,ue=X-B+1>>1,X=X+B+1>>1,B=ue,ue=ne*c+ye*o+128>>8,ne=ne*o-ye*c+128>>8,ye=ue,ue=ve-ke+1>>1,ve=ve+ke+1>>1,ke=ue,ue=Ee+le+1>>1,le=Ee-le+1>>1,Ee=ue,ue=X-ye+1>>1,X=X+ye+1>>1,ye=ue,ue=B-ne+1>>1,B=B+ne+1>>1,ne=ue,ue=ve*s+Ee*i+2048>>12,ve=ve*i-Ee*s+2048>>12,Ee=ue,ue=le*r+ke*n+2048>>12,le=le*n-ke*r+2048>>12,ke=ue,de[0+We]=X+Ee,de[7+We]=X-Ee,de[1+We]=B+ke,de[6+We]=B-ke,de[2+We]=ne+le,de[5+We]=ne-le,de[3+We]=ye+ve,de[4+We]=ye-ve}for(rt=0;rt<8;++rt){var tt=rt;if(de[8+tt]==0&&de[16+tt]==0&&de[24+tt]==0&&de[32+tt]==0&&de[40+tt]==0&&de[48+tt]==0&&de[56+tt]==0){ue=l*G[rt+0]+8192>>14,de[0+tt]=ue,de[8+tt]=ue,de[16+tt]=ue,de[24+tt]=ue,de[32+tt]=ue,de[40+tt]=ue,de[48+tt]=ue,de[56+tt]=ue;continue}X=l*de[0+tt]+2048>>12,B=l*de[32+tt]+2048>>12,ne=de[16+tt],ye=de[48+tt],ve=u*(de[8+tt]-de[56+tt])+2048>>12,Ee=u*(de[8+tt]+de[56+tt])+2048>>12,le=de[24+tt],ke=de[40+tt],ue=X-B+1>>1,X=X+B+1>>1,B=ue,ue=ne*c+ye*o+2048>>12,ne=ne*o-ye*c+2048>>12,ye=ue,ue=ve-ke+1>>1,ve=ve+ke+1>>1,ke=ue,ue=Ee+le+1>>1,le=Ee-le+1>>1,Ee=ue,ue=X-ye+1>>1,X=X+ye+1>>1,ye=ue,ue=B-ne+1>>1,B=B+ne+1>>1,ne=ue,ue=ve*s+Ee*i+2048>>12,ve=ve*i-Ee*s+2048>>12,Ee=ue,ue=le*r+ke*n+2048>>12,le=le*n-ke*r+2048>>12,ke=ue,de[0+tt]=X+Ee,de[56+tt]=X-Ee,de[8+tt]=B+ke,de[48+tt]=B-ke,de[16+tt]=ne+le,de[40+tt]=ne-le,de[24+tt]=ye+ve,de[32+tt]=ye-ve}for(rt=0;rt<64;++rt){var Ae=128+(de[rt]+8>>4);P[rt]=Ae<0?0:Ae>255?255:Ae}}a(j,"quantizeAndInverse"),w(I*_*8);for(var O,V,Q=0;Q<_;Q++){var A=Q<<3;for(O=0;O<8;O++)k.push(new Uint8Array(I));for(var z=0;z<E;z++){j(S.blocks[Q][z],D,L);var C=0,R=z<<3;for(V=0;V<8;V++){var $=k[A+V];for(O=0;O<8;O++)$[R+O]=D[C++]}}}return k}a(h,"buildComponentData");function g(b){return b<0?0:b>255?255:b}a(g,"clampTo8bit"),d.prototype={load:a(function(S){var k=new XMLHttpRequest;k.open("GET",S,!0),k.responseType="arraybuffer",k.onload=(function(){var E=new Uint8Array(k.response||k.mozResponseArrayBuffer);this.parse(E),this.onload&&this.onload()}).bind(this),k.send(null)},"load"),parse:a(function(S){var k=this.opts.maxResolutionInMP*1e3*1e3,E=0,_=S.length;function I(){var ae=S[E]<<8|S[E+1];return E+=2,ae}a(I,"readUint16");function L(){var ae=I(),Ne=S.subarray(E,E+ae-2);return E+=Ne.length,Ne}a(L,"readDataBlock");function D(ae){var Ne=1,He=1,st,At;for(At in ae.components)ae.components.hasOwnProperty(At)&&(st=ae.components[At],Ne<st.h&&(Ne=st.h),He<st.v&&(He=st.v));var Ze=Math.ceil(ae.samplesPerLine/8/Ne),rn=Math.ceil(ae.scanLines/8/He);for(At in ae.components)if(ae.components.hasOwnProperty(At)){st=ae.components[At];var Qt=Math.ceil(Math.ceil(ae.samplesPerLine/8)*st.h/Ne),hn=Math.ceil(Math.ceil(ae.scanLines/8)*st.v/He),Pt=Ze*st.h,Rr=rn*st.v,Pr=Rr*Pt,os=[];w(Pr*256);for(var ki=0;ki<Rr;ki++){for(var or=[],as=0;as<Pt;as++)or.push(new Int32Array(64));os.push(or)}st.blocksPerLine=Qt,st.blocksPerColumn=hn,st.blocks=os}ae.maxH=Ne,ae.maxV=He,ae.mcusPerLine=Ze,ae.mcusPerColumn=rn}a(D,"prepareComponents");var j=null,O=null,V=null,Q,A,z=[],C=[],R=[],$=[],N=I(),P=-1;if(this.comments=[],N!=65496)throw new Error("SOI not found");for(N=I();N!=65497;){var G,Y,X;switch(N){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var B=L();if(N===65534){var ne=String.fromCharCode.apply(null,B);this.comments.push(ne)}N===65504&&B[0]===74&&B[1]===70&&B[2]===73&&B[3]===70&&B[4]===0&&(j={version:{major:B[5],minor:B[6]},densityUnits:B[7],xDensity:B[8]<<8|B[9],yDensity:B[10]<<8|B[11],thumbWidth:B[12],thumbHeight:B[13],thumbData:B.subarray(14,14+3*B[12]*B[13])}),N===65505&&B[0]===69&&B[1]===120&&B[2]===105&&B[3]===102&&B[4]===0&&(this.exifBuffer=B.subarray(5,B.length)),N===65518&&B[0]===65&&B[1]===100&&B[2]===111&&B[3]===98&&B[4]===101&&B[5]===0&&(O={version:B[6],flags0:B[7]<<8|B[8],flags1:B[9]<<8|B[10],transformCode:B[11]});break;case 65499:for(var ye=I(),ve=ye+E-2;E<ve;){var le=S[E++];w(256);var ke=new Int32Array(64);if(le>>4===0)for(Y=0;Y<64;Y++){var Ee=t[Y];ke[Ee]=S[E++]}else if(le>>4===1)for(Y=0;Y<64;Y++){var Ee=t[Y];ke[Ee]=I()}else throw new Error("DQT: invalid table spec");z[le&15]=ke}break;case 65472:case 65473:case 65474:I(),Q={},Q.extended=N===65473,Q.progressive=N===65474,Q.precision=S[E++],Q.scanLines=I(),Q.samplesPerLine=I(),Q.components={},Q.componentsOrder=[];var ue=Q.scanLines*Q.samplesPerLine;if(ue>k){var de=Math.ceil((ue-k)/1e6);throw new Error(`maxResolutionInMP limit exceeded by ${de}MP`)}var rt=S[E++],We,tt=0,Ae=0;for(G=0;G<rt;G++){We=S[E];var xe=S[E+1]>>4,oe=S[E+1]&15,Me=S[E+2];if(xe<=0||oe<=0)throw new Error("Invalid sampling factor, expected values above 0");Q.componentsOrder.push(We),Q.components[We]={h:xe,v:oe,quantizationIdx:Me},E+=3}D(Q),C.push(Q);break;case 65476:var Se=I();for(G=2;G<Se;){var at=S[E++],ze=new Uint8Array(16),Le=0;for(Y=0;Y<16;Y++,E++)Le+=ze[Y]=S[E];w(16+Le);var gt=new Uint8Array(Le);for(Y=0;Y<Le;Y++,E++)gt[Y]=S[E];G+=17+Le,(at>>4===0?$:R)[at&15]=p(ze,gt)}break;case 65501:I(),A=I();break;case 65500:I(),I();break;case 65498:var nt=I(),Ve=S[E++],ht=[],Re;for(G=0;G<Ve;G++){Re=Q.components[S[E++]];var St=S[E++];Re.huffmanTableDC=$[St>>4],Re.huffmanTableAC=R[St&15],ht.push(Re)}var Bt=S[E++],dt=S[E++],fn=S[E++],zt=f(S,E,Q,ht,A,Bt,dt,fn>>4,fn&15,this.opts);E+=zt;break;case 65535:S[E]!==255&&E--;break;default:if(S[E-3]==255&&S[E-2]>=192&&S[E-2]<=254){E-=3;break}else if(N===224||N==225){if(P!==-1)throw new Error(`first unknown JPEG marker at offset ${P.toString(16)}, second unknown JPEG marker ${N.toString(16)} at offset ${(E-1).toString(16)}`);P=E-1;let ae=I();if(S[E+ae-2]===255){E+=ae-2;break}}throw new Error("unknown JPEG marker "+N.toString(16))}N=I()}if(C.length!=1)throw new Error("only single frame JPEGs supported");for(var G=0;G<C.length;G++){var Lt=C[G].components;for(var Y in Lt)Lt[Y].quantizationTable=z[Lt[Y].quantizationIdx],delete Lt[Y].quantizationIdx}this.width=Q.samplesPerLine,this.height=Q.scanLines,this.jfif=j,this.adobe=O,this.components=[];for(var G=0;G<Q.componentsOrder.length;G++){var Re=Q.components[Q.componentsOrder[G]];this.components.push({lines:h(Q,Re),scaleX:Re.h/Q.maxH,scaleY:Re.v/Q.maxV})}},"parse"),getData:a(function(S,k){var E=this.width/S,_=this.height/k,I,L,D,j,O,V,Q,A,z,C,R=0,$,N,P,G,Y,X,B,ne,ye,ve,le,ke=S*k*this.components.length;w(ke);var Ee=new Uint8Array(ke);switch(this.components.length){case 1:for(I=this.components[0],C=0;C<k;C++)for(O=I.lines[0|C*I.scaleY*_],z=0;z<S;z++)$=O[0|z*I.scaleX*E],Ee[R++]=$;break;case 2:for(I=this.components[0],L=this.components[1],C=0;C<k;C++)for(O=I.lines[0|C*I.scaleY*_],V=L.lines[0|C*L.scaleY*_],z=0;z<S;z++)$=O[0|z*I.scaleX*E],Ee[R++]=$,$=V[0|z*L.scaleX*E],Ee[R++]=$;break;case 3:for(le=!0,this.adobe&&this.adobe.transformCode?le=!0:typeof this.opts.colorTransform<"u"&&(le=!!this.opts.colorTransform),I=this.components[0],L=this.components[1],D=this.components[2],C=0;C<k;C++)for(O=I.lines[0|C*I.scaleY*_],V=L.lines[0|C*L.scaleY*_],Q=D.lines[0|C*D.scaleY*_],z=0;z<S;z++)le?($=O[0|z*I.scaleX*E],N=V[0|z*L.scaleX*E],P=Q[0|z*D.scaleX*E],ne=g($+1.402*(P-128)),ye=g($-.3441363*(N-128)-.71413636*(P-128)),ve=g($+1.772*(N-128))):(ne=O[0|z*I.scaleX*E],ye=V[0|z*L.scaleX*E],ve=Q[0|z*D.scaleX*E]),Ee[R++]=ne,Ee[R++]=ye,Ee[R++]=ve;break;case 4:if(!this.adobe)throw new Error("Unsupported color mode (4 components)");for(le=!1,this.adobe&&this.adobe.transformCode?le=!0:typeof this.opts.colorTransform<"u"&&(le=!!this.opts.colorTransform),I=this.components[0],L=this.components[1],D=this.components[2],j=this.components[3],C=0;C<k;C++)for(O=I.lines[0|C*I.scaleY*_],V=L.lines[0|C*L.scaleY*_],Q=D.lines[0|C*D.scaleY*_],A=j.lines[0|C*j.scaleY*_],z=0;z<S;z++)le?($=O[0|z*I.scaleX*E],N=V[0|z*L.scaleX*E],P=Q[0|z*D.scaleX*E],G=A[0|z*j.scaleX*E],Y=255-g($+1.402*(P-128)),X=255-g($-.3441363*(N-128)-.71413636*(P-128)),B=255-g($+1.772*(N-128))):(Y=O[0|z*I.scaleX*E],X=V[0|z*L.scaleX*E],B=Q[0|z*D.scaleX*E],G=A[0|z*j.scaleX*E]),Ee[R++]=255-Y,Ee[R++]=255-X,Ee[R++]=255-B,Ee[R++]=255-G;break;default:throw new Error("Unsupported color mode")}return Ee},"getData"),copyToImageData:a(function(S,k){var E=S.width,_=S.height,I=S.data,L=this.getData(E,_),D=0,j=0,O,V,Q,A,z,C,R,$,N;switch(this.components.length){case 1:for(V=0;V<_;V++)for(O=0;O<E;O++)Q=L[D++],I[j++]=Q,I[j++]=Q,I[j++]=Q,k&&(I[j++]=255);break;case 3:for(V=0;V<_;V++)for(O=0;O<E;O++)R=L[D++],$=L[D++],N=L[D++],I[j++]=R,I[j++]=$,I[j++]=N,k&&(I[j++]=255);break;case 4:for(V=0;V<_;V++)for(O=0;O<E;O++)z=L[D++],C=L[D++],Q=L[D++],A=L[D++],R=255-g(z*(1-A/255)+A),$=255-g(C*(1-A/255)+A),N=255-g(Q*(1-A/255)+A),I[j++]=R,I[j++]=$,I[j++]=N,k&&(I[j++]=255);break;default:throw new Error("Unsupported color mode")}},"copyToImageData")};var y=0,v=0;function w(b=0){var S=y+b;if(S>v){var k=Math.ceil((S-v)/1024/1024);throw new Error(`maxMemoryUsageInMB limit exceeded by at least ${k}MB`)}y=S}return a(w,"requestMemoryAllocation"),d.resetMaxMemoryUsage=function(b){y=0,v=b},d.getBytesAllocated=function(){return y},d.requestMemoryAllocation=w,d}),"jpegImage")();typeof uJ<"u"?uJ.exports=i2e:typeof window<"u"&&(window["jpeg-js"]=window["jpeg-js"]||{},window["jpeg-js"].decode=i2e);function i2e(e,t={}){var n={colorTransform:void 0,useTArray:!1,formatAsRGBA:!0,tolerantDecoding:!0,maxResolutionInMP:100,maxMemoryUsageInMB:512},r={...n,...t},i=new Uint8Array(e),s=new lJ;s.opts=r,lJ.resetMaxMemoryUsage(r.maxMemoryUsageInMB*1024*1024),s.parse(i);var o=r.formatAsRGBA?4:3,c=s.width*s.height*o;try{lJ.requestMemoryAllocation(c);var l={width:s.width,height:s.height,exifBuffer:s.exifBuffer,data:r.useTArray?new Uint8Array(c):Buffer.alloc(c)};s.comments.length>0&&(l.comments=s.comments)}catch(u){throw u instanceof RangeError?new Error("Could not allocate enough memory for the image. Required: "+c):u instanceof ReferenceError&&u.message==="Buffer is not defined"?new Error("Buffer is not globally defined in this environment. Consider setting useTArray to true"):u}return s.copyToImageData(l,r.formatAsRGBA),l}a(i2e,"decode")});var a2e=we((ULn,o2e)=>{var REt=r2e(),$Et=s2e();o2e.exports={encode:REt,decode:$Et}});function P2e(e,t){let n=0,r=0,s=a(o=>{let c;for(let[l,u]of o.entries()){let d=u;if(u.type==="image"){if(n===t[r]){if(u.offloaded===!0)throw new Error(`image/offload: image index ${n} is already offloaded`);d={...u,offloaded:!0},r+=1}n+=1}d!==u&&(c??=o.slice(0,l)),c?.push(d)}return c??o},"visit")(e.content);if(r!==t.length)throw new Error(`image/offload: image index ${t[r]} does not exist`);return pn({...e,content:s})}var D2e=ce(()=>{ls();a(P2e,"offloadMessageImages")});function M2e(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function L2e(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0&&!Object.is(e,-0)}var KP,EJ=ce(()=>{D2e();a(M2e,"isRecord");a(L2e,"isIndex");KP={type:"image/offload",project(e,t){let n=e.data;if(!M2e(n)||Object.keys(n).length!==1||!Array.isArray(n.targets)||n.targets.length===0)throw new Error("image/offload: data must contain a nonempty targets array");let r=new Map,i=new Set(t.nodes);for(let s of n.targets){if(!M2e(s)||Object.keys(s).length!==2||!L2e(s.seq)||!Array.isArray(s.imageIndexes)||s.imageIndexes.length===0)throw new Error("image/offload: each target must contain a seq and nonempty imageIndexes");let o=s.seq;if(r.has(o))throw new Error(`image/offload: duplicate target seq ${o}`);if(!i.has(o))throw new Error(`image/offload: target seq ${o} is not a current surface node`);let c=t.events[o-t.baseSeq];if(c?.type!=="user/message"&&c?.type!=="tool/result")throw new Error(`image/offload: target seq ${o} must be user/message or tool/result`);let l=-1;for(let d of s.imageIndexes){if(!L2e(d)||d<=l)throw new Error("image/offload: imageIndexes must be strictly increasing non-negative safe integers");l=d}let u=t.messages.get(o)??(c.type==="user/message"?c.data:c.data.message);r.set(o,P2e(u,s.imageIndexes))}return r}}});var l4,nIe=ce(()=>{EJ();l4=[KP]});async function lIe(e,t,n){let r=n===void 0?void 0:{signal:n},i=await e.open(t,"read",r),s;try{s=await i.read(0,void 0,r)}catch(c){try{await i.close()}catch{}throw c}await i.close();let{events:o}=s;return{eventState:s.eventState,header:i.header,inheritedEventCount:i.inheritedEventCount,events:[...o,...DR(o)]}}function oY(e,t){if(e.id!==t.id||e.createdAt!==t.createdAt||e.cwd!==t.cwd||e.parentSession!==t.parentSession||e.isSeeded!==t.isSeeded||(e.delegationDepth??0)!==(t.delegationDepth??0))throw new Ir(`session source headers conflict for session "${e.id}"`,"SESSION_QUERY_SOURCE_CONFLICT")}function u4(e,t,n,r){try{r?.throwIfAborted();let i=n(t);return r?.throwIfAborted(),{sessionId:e,status:"fulfilled",value:i}}catch(i){return r?.aborted&&r.throwIfAborted(),{sessionId:e,status:"rejected",reason:i}}}function aY(e){return{header:e.header,events:e.snapshotEvents()}}function d4(e,t){return e.map(n=>t.get(n))}async function cY(e,t){try{return(await e.list(t===void 0?void 0:{signal:t})).map(n=>n.header)}catch(n){throw t?.aborted&&t.throwIfAborted(),new Ir(`session persistence listing failed: ${dY(n)}`,"SESSION_QUERY_PERSISTENCE_FAILED",{cause:n})}}async function rIe(e,t,n){try{return await lIe(e,t,n)}catch(r){throw n?.aborted&&n.throwIfAborted(),r instanceof Error&&r.name==="SessionPersistenceCorruptionError"?new Ir(`stored session "${t}" is corrupt: ${dY(r)}`,"SESSION_QUERY_CORRUPT_SESSION",{cause:r}):new Ir(`failed to read stored session "${t}": ${dY(r)}`,"SESSION_QUERY_PERSISTENCE_FAILED",{cause:r})}}function iIe(e){return{header:structuredClone(e.header),inheritedEventCount:e.inheritedEventCount,events:e.snapshotEvents().map(t=>structuredClone(t))}}function lIt(e,t){return t.header.createdAt-e.header.createdAt||e.header.id.localeCompare(t.header.id)}function p4(e){return new Ir(`session "${e}" not found`,"SESSION_QUERY_SESSION_NOT_FOUND")}function dY(e){return e instanceof Error?e.message:"unknown error"}function DT(e){if(e?.aborted===!0)throw new Ir("session observation was aborted","SESSION_QUERY_ABORTED",{cause:e.reason})}function sIe(e,t){return oIe(t,"SessionPersistenceNotFoundError")?pY(e,t):oIe(t,"SessionPersistenceCorruptionError")?new Ir(`stored session "${e}" is corrupt: ${t.message}`,"SESSION_QUERY_CORRUPT_SESSION",{cause:t}):new Ir(`failed to observe session "${e}": ${f4(t)}`,"SESSION_QUERY_PERSISTENCE_FAILED",{cause:t})}function pY(e,t){return new Ir(`session "${e}" not found`,"SESSION_QUERY_SESSION_NOT_FOUND",t===void 0?void 0:{cause:t})}function f4(e){return e instanceof Error?e.message:"unknown error"}function oIe(e,t){return e instanceof Error&&e.name===t}function dIt(e){switch(e.type){case"user/message":return lY(e.data.content);case"assistant/message":return lY(e.data.message.content);case"tool/call":return MT([e.data.name,e.data.arguments]);case"tool/result":return MT([lY(e.data.message.content),e.data.error?.name??"",e.data.error?.code??""]);case"todo/write":return MT(e.data.todos.flatMap(t=>[t.status,t.content]));case"turn/end":return pIt(e.data.reason);case"turn/start":case"step/start":case"step/end":case"assistant/attempt":case"request/header":return"";default:return""}}function pIt(e){switch(e.kind){case"error":return MT(["error",e.error.message]);case"aborted":return"aborted";case"max-tokens":case"interrupted":return e.kind;case"completed":return"";default:return""}}function lY(e){return MT(e.flatMap(fIt))}function fIt(e){switch(e.type){case"text":return[e.text];case"reasoning":return[];case"tool-call":return[e.name,e.arguments];default:return[]}}function MT(e){return e.map(t=>t.trim()).filter(Boolean).join(`
157
157
  `)}function hY(e,t){let n=hIt(t),r=[];for(let i of t){let s=dIt(i);s.length!==0&&r.push({sessionId:e,seq:i.seq,type:i.type,time:i.time,surface:n.get(i.seq)??"log-only",text:s})}return r}function hIt(e){let t;try{t=p5(e,l4)}catch(r){throw new Ir(`invalid session surface: ${r instanceof Error?r.message:"unknown error"}`,"SESSION_QUERY_INVALID_SURFACE",{cause:r})}let n=new Map;for(let r of t.nodes)n.set(r,"current");for(let r of t.replacements)for(let i of r.shadowedSeqs)n.set(i,"shadowed");return n}function mY(e,t=[]){let n=t.map(gIt);return e.filter(r=>n.every(i=>i(r)))}function y4(e,t=[]){let n=t.map(yIt);return e.filter(r=>n.every(i=>i(r)))}function gY(e){return uIe(e),e.map(t=>{switch(t.kind){case"id":return{kind:t.kind,values:m4(t.kind,t.values)};case"cwd":return{kind:t.kind,values:aIe(t.kind,t.values)};case"created-at":return dIe(t.kind,t);case"parent":return{kind:t.kind,values:aIe(t.kind,t.values)};case"availability":{let n=m4(t.kind,t.values);return b4(t.kind,n,["live","persisted"]),{kind:t.kind,values:n}}default:return w4(t)}})}function v4(e){return uIe(e),e.map(t=>{switch(t.kind){case"seq":case"time":return dIe(t.kind,t);case"type":return{kind:t.kind,values:m4(t.kind,t.values)};case"surface":{let n=m4(t.kind,t.values);return b4(t.kind,n,["current","shadowed","log-only"]),{kind:t.kind,values:n}}case"text":if(typeof t.text!="string")throw dx("text filter text must be a string");return{kind:t.kind,text:t.text};default:return w4(t)}})}function mIt(e){let t=e.trim();if(t.length===0)throw new Ir("session text filter must contain non-whitespace text","SESSION_QUERY_INVALID_FILTER");let n=t.split(/\s+/u).map(r=>r.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")).join("\\s+");return new RegExp(n,"iu")}function gIt(e){switch(e.kind){case"id":return t=>e.values.includes(t.header.id);case"cwd":return t=>e.values.includes(t.header.cwd??null);case"created-at":{let t=g4(e.kind,e);return n=>fY(n.header.createdAt,t)}case"parent":return t=>e.values.includes(t.header.parentSession??null);case"availability":return b4(e.kind,e.values,["live","persisted"]),t=>e.values.some(n=>n==="live"?t.live:t.persisted);default:return w4(e)}}function yIt(e){switch(e.kind){case"seq":{let t=g4(e.kind,e);return n=>fY(n.seq,t)}case"time":{let t=g4(e.kind,e);return n=>fY(n.time,t)}case"type":return t=>e.values.includes(t.type);case"surface":return b4(e.kind,e.values,["current","shadowed","log-only"]),t=>e.values.includes(t.surface);case"text":{let t=mIt(e.text);return n=>t.test(n.text)}default:return w4(e)}}function m4(e,t){if(!pIe(t)||t.some(n=>typeof n!="string"))throw dx(`${e} filter values must be an array of strings`);return[...t]}function uIe(e){if(!Array.isArray(e))throw dx("filters must be an array")}function aIe(e,t){if(!pIe(t)||t.some(n=>n!==null&&typeof n!="string"))throw dx(`${e} filter values must be an array of strings or null`);return[...t]}function dIe(e,t){let n={kind:e,...t.from===void 0?{}:{from:t.from},...t.to===void 0?{}:{to:t.to}};return g4(e,n),n}function w4(e){let t=e.kind;throw dx(`unknown filter kind ${typeof t=="string"?`"${t}"`:"(missing)"}`)}function b4(e,t,n){for(let r of t)if(!n.includes(r))throw new Ir(`session ${e} filter contains unknown value "${r}"`,"SESSION_QUERY_INVALID_FILTER")}function g4(e,t){if(t.from!==void 0&&!Number.isFinite(t.from))throw uY(e,"from must be finite");if(t.to!==void 0&&!Number.isFinite(t.to))throw uY(e,"to must be finite");if(t.from!==void 0&&t.to!==void 0&&t.from>t.to)throw uY(e,"from must be less than or equal to to");return t}function fY(e,t){return(t.from===void 0||e>=t.from)&&(t.to===void 0||e<=t.to)}function uY(e,t){return dx(`${e} filter ${t}`)}function dx(e){return new Ir(`session ${e}`,"SESSION_QUERY_INVALID_FILTER")}function pIe(e){return Array.isArray(e)}function vIt(e,t){return yY(e,t).records}function wIt(e,t){return yY(e,t).currentSeqs.map(n=>{let r=t[n];if(r===void 0||r.seq!==n||!ig(r))throw new Ir(`invalid session surface: current node ${n} is not a surface event`,"SESSION_QUERY_INVALID_SURFACE");return xE(r)})}function bIt(e,t,n){let r=t[n];if(r===void 0||r.seq!==n)throw new Ir(`session "${e}" has no event at seq ${n}`,"SESSION_QUERY_EVENT_NOT_FOUND");let i=yY(e,t),s=[],o=i.replacedBy.get(n);for(;o!==void 0;)s.push(o),o=i.replacedBy.get(o);let c=[];for(let d of t)d.seq<=n||cIe(d).includes(n)&&c.push(d.seq);let l=i.records[n],u=i.replacedBy.get(n);return{target:l,...u===void 0?{}:{replacedBy:u},replacementChain:s,replacedEventSeqs:i.replacedEventSeqs.get(n)??[],sourceEventSeqs:[...cIe(r)],derivedEventSeqs:c}}function xIt(e,t){let n=new Map(e.map(p=>[p.header.id,p])),r=n.get(t);if(r===void 0)throw new Ir(`session "${t}" not found`,"SESSION_QUERY_SESSION_NOT_FOUND");let i=[],s=new Set([t]),o,c=r.header.parentSession;for(;c!==void 0;){if(s.has(c))throw new Ir(`session lineage contains a cycle at "${c}"`,"SESSION_QUERY_INVALID_LINEAGE");s.add(c);let p=n.get(c);if(p===void 0){o=c;break}i.push(p),c=p.header.parentSession}let l=new Map;for(let p of e){let f=p.header.parentSession;if(f===void 0)continue;let h=l.get(f)??[];h.push(p),l.set(f,h)}for(let p of l.values())p.sort((f,h)=>f.header.createdAt-h.header.createdAt||f.header.id.localeCompare(h.header.id));let u=SIt(l,t),d={target:h4(r),ancestors:i.map(h4),descendants:u};return o!==void 0?{...d,complete:!1,unresolvedParentId:o}:{...d,complete:!0,root:h4(i.at(-1)??r)}}function yY(e,t){let n;try{n=p5(t,l4)}catch(o){throw new Ir(`invalid session surface: ${o instanceof Error?o.message:"unknown error"}`,"SESSION_QUERY_INVALID_SURFACE",{cause:o})}let r=new Set(n.nodes),i=new Map,s=new Map;for(let o of n.replacements){let c=o.shadowedSeqs;s.set(o.seq,c);for(let l of c)i.set(l,o.seq)}return{records:t.map(o=>({sessionId:e,seq:o.seq,type:o.type,time:o.time,surface:r.has(o.seq)?"current":i.has(o.seq)?"shadowed":"log-only"})),replacedBy:i,replacedEventSeqs:s,currentSeqs:[...n.nodes]}}function cIe(e){return e.sourceEventSeqs??[]}function SIt(e,t){let n=[],r=[{sessionId:t,descendants:n}];for(;r.length>0;){let i=r.pop(),s=[];for(let o of e.get(i.sessionId)??[]){let c={session:h4(o),descendants:[]};s.push(c),i.descendants.push(c)}for(let o=s.length-1;o>=0;o-=1){let c=s[o];r.push({sessionId:c.session.header.id,descendants:c.descendants})}}return n}function h4(e){return{...e,header:structuredClone(e.header)}}var Ir,cIt,uIt,fIe,vY=ce(()=>{nIe();Hn();Ps();Eg();kr();Ir=class extends Jr{static{a(this,"SessionQueryError")}constructor(e,t,n){super(e,t,n)}};a(lIe,"readColdSessionLog");a(oY,"assertSessionHeadersCompatible");cIt=class{static{a(this,"SessionCorpus")}_ctx;_persistedReadConcurrency;_persistence;_optionalPersistenceFiber;constructor(e,t){this._ctx=e,this._persistedReadConcurrency=t,this._optionalPersistenceFiber=e.inject(["sessionPersistence"],n=>{let r=n.sessionPersistence;this._persistence=r,n.effect(()=>()=>{this._persistence===r&&(this._persistence=void 0)},"sessionQuery.persistenceBinding")}),e.effect(()=>()=>this._optionalPersistenceFiber.dispose(),"sessionQuery.optionalPersistence")}async listSessions(e){e?.throwIfAborted();let t=this._persistence,n=t===void 0?[]:await cY(t,e);e?.throwIfAborted();let r=new Map;for(let i of n)r.set(i.id,{header:structuredClone(i),live:!1,persisted:!0});for(let i of this._ctx.sessions.list()){let s=r.get(i.id);s!==void 0&&oY(i.header,s.header),r.set(i.id,{header:structuredClone(i.header),live:!0,persisted:s!==void 0})}return[...r.values()].sort(lIt)}async load(e,t){t?.throwIfAborted();let n=this._ctx.sessions.get(e);if(n!==void 0){let l=iIe(n);return t?.throwIfAborted(),l}let r=this._persistence;if(r===void 0)throw p4(e);let i=(await cY(r,t)).find(l=>l.id===e);if(t?.throwIfAborted(),i===void 0)throw p4(e);let s=await rIe(r,e,t);t?.throwIfAborted();let o=this._ctx.sessions.get(e);if(o!==void 0){let l=iIe(o);return t?.throwIfAborted(),l}oY(s.header,i);let c={header:structuredClone(s.header),inheritedEventCount:s.inheritedEventCount,events:s.events.map(l=>structuredClone(l))};return t?.throwIfAborted(),c}async projectMany(e,t,n){let r=[...new Set(e)];n?.throwIfAborted();let i=new Map,s=[];for(let g of r){let y=this._ctx.sessions.get(g);y===void 0?s.push(g):i.set(g,u4(g,aY(y),t,n))}if(s.length===0)return d4(r,i);let o=this._persistence;if(o===void 0){for(let g of s)i.set(g,{sessionId:g,status:"rejected",reason:p4(g)});return d4(r,i)}let c;try{c=await cY(o,n),n?.throwIfAborted()}catch(g){n?.aborted&&n.throwIfAborted();for(let y of s)i.set(y,{sessionId:y,status:"rejected",reason:g});return d4(r,i)}let l=new Map(c.map(g=>[g.id,g])),u=a(async g=>{let y=l.get(g);if(y===void 0){let v=this._ctx.sessions.get(g);i.set(g,v===void 0?{sessionId:g,status:"rejected",reason:p4(g)}:u4(g,aY(v),t,n));return}try{n?.throwIfAborted();let v=await rIe(o,g,n);n?.throwIfAborted();let w=this._ctx.sessions.get(g);if(w!==void 0){i.set(g,u4(g,aY(w),t,n));return}oY(v.header,y),i.set(g,u4(g,{header:v.header,events:v.events},t,n))}catch(v){n?.aborted&&n.throwIfAborted(),i.set(g,{sessionId:g,status:"rejected",reason:v})}},"resolvePersisted"),d=0,p=a(async()=>{for(;;){n?.throwIfAborted();let g=d;if(g>=s.length)return;d+=1,await u(s[g])}},"worker"),f=Math.min(this._persistedReadConcurrency,s.length),h=await Promise.allSettled(Array.from({length:f},()=>p()));n?.aborted&&n.throwIfAborted();for(let g of h)if(g.status==="rejected")throw g.reason;return n?.throwIfAborted(),d4(r,i)}};a(u4,"projectSource");a(aY,"sourceLive");a(d4,"orderedResults");a(cY,"listPersisted");a(rIe,"inspectPersisted");a(iIe,"snapshotLive");a(lIt,"compareSessions");a(p4,"notFound$1");a(dY,"errorMessage$1");uIt=class{static{a(this,"SessionObservationReader")}ctx;cacheCapacity;cache=new Map;constructor(e,t=5){this.ctx=e,this.cacheCapacity=t}async read(e,t={}){let{signal:n,projectionMode:r="all"}=t;for(;;){DT(n);let i=this.ctx.sessions.get(e);if(i!==void 0)return this.live(i,r);let s=this.ctx.get("sessionPersistence");if(s===void 0)throw pY(e);let o=await this.statSource(s,e,n),c=this.ctx.sessions.get(e);if(c!==void 0)return this.live(c,r);let l=this.cachedEntry(s.identity,e,o.revision);if(l===void 0){let d=await this.loadSource(s,e,n);DT(n);let p=this.ctx.sessions.get(e);if(p!==void 0)return this.live(p,r);let f=d.events,h;try{h=this.ctx.sessions.prepare(e,{seed:f,meta:structuredClone(d.header),inheritedEventCount:d.inheritedEventCount,eventState:d.eventState})}catch(g){if(this.ctx.sessions.get(e)!==void 0)continue;throw new Ir(`stored session "${e}" is corrupt: ${f4(g)}`,"SESSION_QUERY_CORRUPT_SESSION",{cause:g})}l={persistenceIdentity:s.identity,revision:o.revision,session:h,events:Object.freeze(f),refs:0},this.store(e,l)}let u;try{u=r==="none"?void 0:this.preparedProjections(l)}catch(d){throw new Ir(`failed to project session "${e}": ${f4(d)}`,"SESSION_QUERY_CORRUPT_SESSION",{cause:d})}return this.preparedLease(e,l,u)}}async statSource(e,t,n){let r;try{r=await e.stat(t,n===void 0?void 0:{signal:n})}catch(i){throw DT(n),sIe(t,i)}if(DT(n),r===void 0)throw pY(t);if(r.header.id!==t)throw new Ir(`session persistence returned "${r.header.id}" for "${t}"`,"SESSION_QUERY_SOURCE_CONFLICT");return r}async loadSource(e,t,n){try{return await lIe(e,t,n)}catch(r){throw DT(n),sIe(t,r)}}cachedEntry(e,t,n){let r=this.cache.get(t);if(!(r===void 0||r.persistenceIdentity!==e||r.revision!==n))return this.cache.delete(t),this.cache.set(t,r),r}store(e,t){this.cache.delete(e),this.cache.set(e,t),this.evictPastCapacity(t)}evictPastCapacity(e){if(!(this.cache.size<=this.cacheCapacity)){for(let[t,n]of this.cache)if(!(n===e||n.refs>0)&&(this.cache.delete(t),this.cache.size<=this.cacheCapacity))return}}preparedLease(e,t,n){t.refs+=1;let r=a(()=>{let i=!1;return{source:"prepared",header:t.session.header,inheritedEventCount:t.session.inheritedEventCount,events:t.events,cursor:t.events.at(-1)?.seq??-1,revision:t.revision,...n===void 0?{}:{projections:n},retain:a(()=>{if(i)throw new Error(`session observation "${e}" is disposed`);return t.refs+=1,r()},"retain"),[Symbol.dispose]:()=>{i||(i=!0,t.refs-=1,t.refs===0&&this.evictPastCapacity())}}},"lease");return r()}live(e,t){let n=e.seq,r,i;try{i=t==="none"?void 0:this.ctx.get("sessionProjections")?.snapshot(e)}catch(o){throw new Ir(`failed to project session "${e.id}": ${f4(o)}`,"SESSION_QUERY_CORRUPT_SESSION",{cause:o})}let s=a(()=>{let o=!1;return{source:"live",header:e.header,inheritedEventCount:e.inheritedEventCount,get events(){return r??=e.snapshotEvents(Sn(0),n),r},cursor:n===0?-1:sn(n-1),...i===void 0?{}:{projections:i},retain:a(()=>{if(o)throw new Error(`session observation "${e.id}" is disposed`);return s()},"retain"),[Symbol.dispose]:()=>{o=!0}}},"lease");return s()}preparedProjections(e){let t=this.ctx.get("sessionProjections");if(t===void 0)return;let n=this.ctx.get("sessionProjectionCache");return n===void 0?t.hydrate(e.session,{},e.events,Sn(0)):n.hydratePrepared(e.session,e.events)}};a(DT,"throwIfObservationAborted");a(sIe,"mapPersistenceFailure");a(pY,"notFound");a(f4,"errorMessage");a(oIe,"hasErrorName");a(dIt,"extractSessionEventText");a(pIt,"turnEndText");a(lY,"contentText");a(fIt,"blockText");a(MT,"joinText");a(hY,"buildSessionEventSearchDocuments");a(hIt,"classifySurface");a(mY,"filterSessionResults");a(y4,"filterSessionEventDocuments");a(gY,"materializeSessionResultFilters");a(v4,"materializeSessionEventResultFilters");a(mIt,"compileSessionTextFilter");a(gIt,"sessionPredicate");a(yIt,"eventPredicate");a(m4,"copyStrings");a(uIe,"assertArray");a(aIe,"copyNullableStrings");a(dIe,"copyRange");a(w4,"unknownFilter");a(b4,"assertAllowedValues");a(g4,"validateRange");a(fY,"matchesRange");a(uY,"invalidRange");a(dx,"invalidFilter");a(pIe,"isRuntimeArray");a(vIt,"eventRecords");a(wIt,"currentSurfaceEvents");a(bIt,"traceEvent");a(xIt,"traceSession");a(yY,"analyzeEventLog");a(cIe,"eventSources");a(SIt,"buildDescendants");a(h4,"cloneRecord");fIe=class extends xt{static{a(this,"SessionQueryEngine")}static inject=["sessions"];_readWindowMax;_corpus;_observations;constructor(e,t={}){if(super(e,"sessionQuery"),this._readWindowMax=t.readWindowMax??50,!Number.isInteger(this._readWindowMax)||this._readWindowMax<0)throw new Ir("session-query: readWindowMax must be a non-negative integer","SESSION_QUERY_INVALID_CONFIG");let n=t.persistedReadConcurrency??4;if(!Number.isSafeInteger(n)||n<1)throw new Ir("session-query: persistedReadConcurrency must be a positive safe integer","SESSION_QUERY_INVALID_CONFIG");let r=t.preparedSessionCacheSize??5;if(!Number.isSafeInteger(r)||r<1)throw new Ir("session-query: preparedSessionCacheSize must be a positive safe integer","SESSION_QUERY_INVALID_CONFIG");this._corpus=new cIt(e,n),this._observations=new uIt(e,r)}observeSession(e,t={}){return this._observations.read(e,t)}listSessions(e){return this._corpus.listSessions(e)}async readSession(e){let t=await this._corpus.load(e);return y0.create(e,t.events,t.header,t.inheritedEventCount,l4),{session:structuredClone(t.header),inheritedEventCount:t.inheritedEventCount,events:t.events.map(xE)}}async filterSessions(e,t){let n=gY(e);return this._filterSessions(n,t)}async readTitle(e,t){return(await this.readTitleSnapshot(e,t)).title}async readTitleSnapshot(e,t){let n=(await this.readTitleSnapshots([e],t))[0];if(n.status==="rejected")throw n.reason;return n.value}async readTitleSnapshots(e,t){return this._corpus.projectMany(e,n=>{let r=kg(n.events);return{session:structuredClone(n.header),...r===void 0?{}:{title:r}}},t)}async listEvents(e){return vIt(e,(await this._corpus.load(e)).events)}async filterEvents(e,t){let n=v4(t);return this._filterEvents(e,n)}async _filterSessions(e,t){return mY(await this._corpus.listSessions(t),e)}async _filterEvents(e,t){return y4(hY(e,(await this._corpus.load(e)).events),t)}async readSurface(e){let t=await this._corpus.load(e);return{session:structuredClone(t.header),inheritedEventCount:t.inheritedEventCount,capturedThroughSeq:t.events.at(-1)?.seq??null,events:wIt(e,t.events)}}async traceSession(e,t){let n=await this._corpus.listSessions(t);return t?.throwIfAborted(),xIt(n,e)}async traceEvent(e,t){let n=await this._corpus.load(e.sessionId,t);return t?.throwIfAborted(),{session:n.header,...bIt(e.sessionId,n.events,e.seq)}}async readEvent(e,t){let n=this._readWindow("before",e.before),r=this._readWindow("after",e.after),i=e.sessionId,s=e.seq;return this._readEvent(i,s,n,r,t)}async _readEvent(e,t,n,r,i){let s=await this._corpus.load(e,i);i?.throwIfAborted();let o=s.events[t];if(o===void 0||o.seq!==t)throw new Ir(`session "${e}" has no event at seq ${t}`,"SESSION_QUERY_EVENT_NOT_FOUND");let c=sn(Math.max(0,t-n)),l=sn(Math.min(s.events.length-1,t+r)),u=xE(o),d=s.events.slice(c,l+1).map(p=>p===o?u:xE(p));return{session:structuredClone(s.header),inheritedEventCount:s.inheritedEventCount,target:u,events:d,startSeq:c,endSeq:l}}_readWindow(e,t){if(t===void 0)return 0;if(!Number.isInteger(t)||t<0||t>this._readWindowMax)throw new Ir(`${e} must be an integer between 0 and ${this._readWindowMax}`,"SESSION_QUERY_INVALID_WINDOW");return t}}});var px=we((AFn,_Ie)=>{"use strict";_Ie.exports=_1;_1.CAPTURING_PHASE=1;_1.AT_TARGET=2;_1.BUBBLING_PHASE=3;function _1(e,t){if(this.type="",this.target=null,this.currentTarget=null,this.eventPhase=_1.AT_TARGET,this.bubbles=!1,this.cancelable=!1,this.isTrusted=!1,this.defaultPrevented=!1,this.timeStamp=Date.now(),this._propagationStopped=!1,this._immediatePropagationStopped=!1,this._initialized=!0,this._dispatching=!1,e&&(this.type=e),t)for(var n in t)this[n]=t[n]}a(_1,"Event");_1.prototype=Object.create(Object.prototype,{constructor:{value:_1},stopPropagation:{value:a(function(){this._propagationStopped=!0},"stopPropagation")},stopImmediatePropagation:{value:a(function(){this._propagationStopped=!0,this._immediatePropagationStopped=!0},"stopImmediatePropagation")},preventDefault:{value:a(function(){this.cancelable&&(this.defaultPrevented=!0)},"preventDefault")},initEvent:{value:a(function(t,n,r){this._initialized=!0,!this._dispatching&&(this._propagationStopped=!1,this._immediatePropagationStopped=!1,this.defaultPrevented=!1,this.isTrusted=!1,this.target=null,this.type=t,this.bubbles=n,this.cancelable=r)},"initEvent")}})});var _Y=we((RFn,IIe)=>{"use strict";var TIe=px();IIe.exports=EY;function EY(){TIe.call(this),this.view=null,this.detail=0}a(EY,"UIEvent");EY.prototype=Object.create(TIe.prototype,{constructor:{value:EY},initUIEvent:{value:a(function(e,t,n,r,i){this.initEvent(e,t,n),this.view=r,this.detail=i},"value")}})});var IY=we((OFn,CIe)=>{"use strict";var AIe=_Y();CIe.exports=TY;function TY(){AIe.call(this),this.screenX=this.screenY=this.clientX=this.clientY=0,this.ctrlKey=this.altKey=this.shiftKey=this.metaKey=!1,this.button=0,this.buttons=1,this.relatedTarget=null}a(TY,"MouseEvent");TY.prototype=Object.create(AIe.prototype,{constructor:{value:TY},initMouseEvent:{value:a(function(e,t,n,r,i,s,o,c,l,u,d,p,f,h,g){switch(this.initEvent(e,t,n,r,i),this.screenX=s,this.screenY=o,this.clientX=c,this.clientY=l,this.ctrlKey=u,this.altKey=d,this.shiftKey=p,this.metaKey=f,this.button=h,h){case 0:this.buttons=1;break;case 1:this.buttons=4;break;case 2:this.buttons=2;break;default:this.buttons=0;break}this.relatedTarget=g},"value")},getModifierState:{value:a(function(e){switch(e){case"Alt":return this.altKey;case"Control":return this.ctrlKey;case"Shift":return this.shiftKey;case"Meta":return this.metaKey;default:return!1}},"value")}})});var T4=we((PFn,$Ie)=>{"use strict";$Ie.exports=_4;var FIt=1,qIt=3,UIt=4,zIt=5,BIt=7,WIt=8,HIt=9,VIt=11,GIt=12,KIt=13,ZIt=14,JIt=15,YIt=17,XIt=18,QIt=19,eAt=20,tAt=21,nAt=22,rAt=23,iAt=24,sAt=25,oAt=[null,"INDEX_SIZE_ERR",null,"HIERARCHY_REQUEST_ERR","WRONG_DOCUMENT_ERR","INVALID_CHARACTER_ERR",null,"NO_MODIFICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INUSE_ATTRIBUTE_ERR","INVALID_STATE_ERR","SYNTAX_ERR","INVALID_MODIFICATION_ERR","NAMESPACE_ERR","INVALID_ACCESS_ERR",null,"TYPE_MISMATCH_ERR","SECURITY_ERR","NETWORK_ERR","ABORT_ERR","URL_MISMATCH_ERR","QUOTA_EXCEEDED_ERR","TIMEOUT_ERR","INVALID_NODE_TYPE_ERR","DATA_CLONE_ERR"],aAt=[null,"INDEX_SIZE_ERR (1): the index is not in the allowed range",null,"HIERARCHY_REQUEST_ERR (3): the operation would yield an incorrect nodes model","WRONG_DOCUMENT_ERR (4): the object is in the wrong Document, a call to importNode is required","INVALID_CHARACTER_ERR (5): the string contains invalid characters",null,"NO_MODIFICATION_ALLOWED_ERR (7): the object can not be modified","NOT_FOUND_ERR (8): the object can not be found here","NOT_SUPPORTED_ERR (9): this operation is not supported","INUSE_ATTRIBUTE_ERR (10): setAttributeNode called on owned Attribute","INVALID_STATE_ERR (11): the object is in an invalid state","SYNTAX_ERR (12): the string did not match the expected pattern","INVALID_MODIFICATION_ERR (13): the object can not be modified in this way","NAMESPACE_ERR (14): the operation is not allowed by Namespaces in XML","INVALID_ACCESS_ERR (15): the object does not support the operation or argument",null,"TYPE_MISMATCH_ERR (17): the type of the object does not match the expected type","SECURITY_ERR (18): the operation is insecure","NETWORK_ERR (19): a network error occurred","ABORT_ERR (20): the user aborted an operation","URL_MISMATCH_ERR (21): the given URL does not match another URL","QUOTA_EXCEEDED_ERR (22): the quota has been exceeded","TIMEOUT_ERR (23): a timeout occurred","INVALID_NODE_TYPE_ERR (24): the supplied node is invalid or has an invalid ancestor for this operation","DATA_CLONE_ERR (25): the object can not be cloned."],RIe={INDEX_SIZE_ERR:FIt,DOMSTRING_SIZE_ERR:2,HIERARCHY_REQUEST_ERR:qIt,WRONG_DOCUMENT_ERR:UIt,INVALID_CHARACTER_ERR:zIt,NO_DATA_ALLOWED_ERR:6,NO_MODIFICATION_ALLOWED_ERR:BIt,NOT_FOUND_ERR:WIt,NOT_SUPPORTED_ERR:HIt,INUSE_ATTRIBUTE_ERR:10,INVALID_STATE_ERR:VIt,SYNTAX_ERR:GIt,INVALID_MODIFICATION_ERR:KIt,NAMESPACE_ERR:ZIt,INVALID_ACCESS_ERR:JIt,VALIDATION_ERR:16,TYPE_MISMATCH_ERR:YIt,SECURITY_ERR:XIt,NETWORK_ERR:QIt,ABORT_ERR:eAt,URL_MISMATCH_ERR:tAt,QUOTA_EXCEEDED_ERR:nAt,TIMEOUT_ERR:rAt,INVALID_NODE_TYPE_ERR:iAt,DATA_CLONE_ERR:sAt};function _4(e){Error.call(this),Error.captureStackTrace(this,this.constructor),this.code=e,this.message=aAt[e],this.name=oAt[e]}a(_4,"DOMException");_4.prototype.__proto__=Error.prototype;for(E4 in RIe)AY={value:RIe[E4]},Object.defineProperty(_4,E4,AY),Object.defineProperty(_4.prototype,E4,AY);var AY,E4});var I4=we(OIe=>{OIe.isApiWritable=!globalThis.__domino_frozen__});var so=we(Ri=>{"use strict";var io=T4(),ko=io,cAt=I4().isApiWritable;Ri.NAMESPACE={HTML:"http://www.w3.org/1999/xhtml",XML:"http://www.w3.org/XML/1998/namespace",XMLNS:"http://www.w3.org/2000/xmlns/",MATHML:"http://www.w3.org/1998/Math/MathML",SVG:"http://www.w3.org/2000/svg",XLINK:"http://www.w3.org/1999/xlink"};Ri.IndexSizeError=function(){throw new io(ko.INDEX_SIZE_ERR)};Ri.HierarchyRequestError=function(){throw new io(ko.HIERARCHY_REQUEST_ERR)};Ri.WrongDocumentError=function(){throw new io(ko.WRONG_DOCUMENT_ERR)};Ri.InvalidCharacterError=function(){throw new io(ko.INVALID_CHARACTER_ERR)};Ri.NoModificationAllowedError=function(){throw new io(ko.NO_MODIFICATION_ALLOWED_ERR)};Ri.NotFoundError=function(){throw new io(ko.NOT_FOUND_ERR)};Ri.NotSupportedError=function(){throw new io(ko.NOT_SUPPORTED_ERR)};Ri.InvalidStateError=function(){throw new io(ko.INVALID_STATE_ERR)};Ri.SyntaxError=function(){throw new io(ko.SYNTAX_ERR)};Ri.InvalidModificationError=function(){throw new io(ko.INVALID_MODIFICATION_ERR)};Ri.NamespaceError=function(){throw new io(ko.NAMESPACE_ERR)};Ri.InvalidAccessError=function(){throw new io(ko.INVALID_ACCESS_ERR)};Ri.TypeMismatchError=function(){throw new io(ko.TYPE_MISMATCH_ERR)};Ri.SecurityError=function(){throw new io(ko.SECURITY_ERR)};Ri.NetworkError=function(){throw new io(ko.NETWORK_ERR)};Ri.AbortError=function(){throw new io(ko.ABORT_ERR)};Ri.UrlMismatchError=function(){throw new io(ko.URL_MISMATCH_ERR)};Ri.QuotaExceededError=function(){throw new io(ko.QUOTA_EXCEEDED_ERR)};Ri.TimeoutError=function(){throw new io(ko.TIMEOUT_ERR)};Ri.InvalidNodeTypeError=function(){throw new io(ko.INVALID_NODE_TYPE_ERR)};Ri.DataCloneError=function(){throw new io(ko.DATA_CLONE_ERR)};Ri.nyi=function(){throw new Error("NotYetImplemented")};Ri.shouldOverride=function(){throw new Error("Abstract function; should be overriding in subclass.")};Ri.assert=function(e,t){if(!e)throw new Error("Assertion failed: "+(t||"")+`
158
158
  `+new Error().stack)};Ri.expose=function(e,t){for(var n in e)Object.defineProperty(t.prototype,n,{value:e[n],writable:cAt})};Ri.merge=function(e,t){for(var n in t)e[n]=t[n]};Ri.documentOrder=function(e,t){return 3-(e.compareDocumentPosition(t)&6)};Ri.toASCIILowerCase=function(e){return e.replace(/[A-Z]+/g,function(t){return t.toLowerCase()})};Ri.toASCIIUpperCase=function(e){return e.replace(/[a-z]+/g,function(t){return t.toUpperCase()})}});var CY=we((jFn,PIe)=>{"use strict";var T1=px(),lAt=IY(),uAt=so();PIe.exports=NIe;function NIe(){}a(NIe,"EventTarget");NIe.prototype={addEventListener:a(function(t,n,r){if(n){r===void 0&&(r=!1),this._listeners||(this._listeners=Object.create(null)),this._listeners[t]||(this._listeners[t]=[]);for(var i=this._listeners[t],s=0,o=i.length;s<o;s++){var c=i[s];if(c.listener===n&&c.capture===r)return}var l={listener:n,capture:r};typeof n=="function"&&(l.f=n),i.push(l)}},"addEventListener"),removeEventListener:a(function(t,n,r){if(r===void 0&&(r=!1),this._listeners){var i=this._listeners[t];if(i)for(var s=0,o=i.length;s<o;s++){var c=i[s];if(c.listener===n&&c.capture===r){i.length===1?this._listeners[t]=void 0:i.splice(s,1);return}}}},"removeEventListener"),dispatchEvent:a(function(t){return this._dispatchEvent(t,!1)},"dispatchEvent"),_dispatchEvent:a(function(t,n){typeof n!="boolean"&&(n=!1);function r(u,d){var p=d.type,f=d.eventPhase;if(d.currentTarget=u,f!==T1.CAPTURING_PHASE&&u._handlers&&u._handlers[p]){var h=u._handlers[p],g;if(typeof h=="function")g=h.call(d.currentTarget,d);else{var y=h.handleEvent;if(typeof y!="function")throw new TypeError("handleEvent property of event handler object isnot a function.");g=y.call(h,d)}d.type==="mouseover"?g===!0&&d.preventDefault():g===!1&&d.preventDefault()}var v=u._listeners&&u._listeners[p];if(v){v=v.slice();for(var w=0,b=v.length;w<b;w++){if(d._immediatePropagationStopped)return;var S=v[w];if(!(f===T1.CAPTURING_PHASE&&!S.capture||f===T1.BUBBLING_PHASE&&S.capture))if(S.f)S.f.call(d.currentTarget,d);else{var k=S.listener.handleEvent;if(typeof k!="function")throw new TypeError("handleEvent property of event listener object is not a function.");k.call(S.listener,d)}}}}a(r,"invoke"),(!t._initialized||t._dispatching)&&uAt.InvalidStateError(),t.isTrusted=n,t._dispatching=!0,t.target=this;for(var i=[],s=this.parentNode;s;s=s.parentNode)i.push(s);t.eventPhase=T1.CAPTURING_PHASE;for(var o=i.length-1;o>=0&&(r(i[o],t),!t._propagationStopped);o--);if(t._propagationStopped||(t.eventPhase=T1.AT_TARGET,r(this,t)),t.bubbles&&!t._propagationStopped){t.eventPhase=T1.BUBBLING_PHASE;for(var c=0,l=i.length;c<l&&(r(i[c],t),!t._propagationStopped);c++);}if(t._dispatching=!1,t.eventPhase=T1.AT_TARGET,t.currentTarget=null,n&&!t.defaultPrevented&&t instanceof lAt)switch(t.type){case"mousedown":this._armed={x:t.clientX,y:t.clientY,t:t.timeStamp};break;case"mouseout":case"mouseover":this._armed=null;break;case"mouseup":this._isClick(t)&&this._doClick(t),this._armed=null;break}return!t.defaultPrevented},"_dispatchEvent"),_isClick:a(function(e){return this._armed!==null&&e.type==="mouseup"&&e.isTrusted&&e.button===0&&e.timeStamp-this._armed.t<1e3&&Math.abs(e.clientX-this._armed.x)<10&&Math.abs(e.clientY-this._armed.Y)<10},"_isClick"),_doClick:a(function(e){if(!this._click_in_progress){this._click_in_progress=!0;for(var t=this;t&&!t._post_click_activation_steps;)t=t.parentNode;t&&t._pre_click_activation_steps&&t._pre_click_activation_steps();var n=this.ownerDocument.createEvent("MouseEvent");n.initMouseEvent("click",!0,!0,this.ownerDocument.defaultView,1,e.screenX,e.screenY,e.clientX,e.clientY,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,e.button,null);var r=this._dispatchEvent(n,!0);t&&(r?t._post_click_activation_steps&&t._post_click_activation_steps(n):t._cancelled_activation_steps&&t._cancelled_activation_steps())}},"_doClick"),_setEventHandler:a(function(t,n){this._handlers||(this._handlers=Object.create(null)),this._handlers[t]=n},"_setEventHandler"),_getEventHandler:a(function(t){return this._handlers&&this._handlers[t]||null},"_getEventHandler")}});var RY=we((qFn,DIe)=>{"use strict";var Qh=so(),rd=DIe.exports={valid:a(function(e){return Qh.assert(e,"list falsy"),Qh.assert(e._previousSibling,"previous falsy"),Qh.assert(e._nextSibling,"next falsy"),!0},"valid"),insertBefore:a(function(e,t){Qh.assert(rd.valid(e)&&rd.valid(t));var n=e,r=e._previousSibling,i=t,s=t._previousSibling;n._previousSibling=s,r._nextSibling=i,s._nextSibling=n,i._previousSibling=r,Qh.assert(rd.valid(e)&&rd.valid(t))},"insertBefore"),replace:a(function(e,t){Qh.assert(rd.valid(e)&&(t===null||rd.valid(t))),t!==null&&rd.insertBefore(t,e),rd.remove(e),Qh.assert(rd.valid(e)&&(t===null||rd.valid(t)))},"replace"),remove:a(function(e){Qh.assert(rd.valid(e));var t=e._previousSibling;if(t!==e){var n=e._nextSibling;t._nextSibling=n,n._previousSibling=t,e._previousSibling=e._nextSibling=e,Qh.assert(rd.valid(e))}},"remove")}});var $Y=we((zFn,BIe)=>{"use strict";BIe.exports={serializeOne:yAt,\u0275escapeMatchingClosingTag:qIe,\u0275escapeClosingCommentTag:UIe,\u0275escapeProcessingInstructionContent:zIe};var FIe=so(),I1=FIe.NAMESPACE,MIe={STYLE:!0,SCRIPT:!0,XMP:!0,IFRAME:!0,NOEMBED:!0,NOFRAMES:!0,PLAINTEXT:!0},dAt={area:!0,base:!0,basefont:!0,bgsound:!0,br:!0,col:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},pAt={},LIe=/[&<>\u00A0]/g,jIe=/[&"<>\u00A0]/g;function fAt(e){return LIe.test(e)?e.replace(LIe,t=>{switch(t){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case"\xA0":return"&nbsp;"}}):e}a(fAt,"escape");function hAt(e){return jIe.test(e)?e.replace(jIe,t=>{switch(t){case"<":return"&lt;";case">":return"&gt;";case"&":return"&amp;";case'"':return"&quot;";case"\xA0":return"&nbsp;"}}):e}a(hAt,"escapeAttr");function mAt(e){var t=e.namespaceURI;return t?t===I1.XML?"xml:"+e.localName:t===I1.XLINK?"xlink:"+e.localName:t===I1.XMLNS?e.localName==="xmlns"?"xmlns":"xmlns:"+e.localName:e.name:e.localName}a(mAt,"attrname");function qIe(e,t){let n="</"+t;if(!e.toLowerCase().includes(n))return e;let r=[...e],i=e.matchAll(new RegExp(n,"ig"));for(let s of i)r[s.index]="&lt;";return r.join("")}a(qIe,"escapeMatchingClosingTag");var gAt=/--!?>/;function UIe(e){return gAt.test(e)?e.replace(/(--\!?)>/g,"$1&gt;"):e}a(UIe,"escapeClosingCommentTag");function zIe(e){return e.includes(">")?e.replaceAll(">","&gt;"):e}a(zIe,"escapeProcessingInstructionContent");function yAt(e,t){var n="";switch(e.nodeType){case 1:var r=e.namespaceURI,i=r===I1.HTML,s=i||r===I1.SVG||r===I1.MATHML?e.localName:e.tagName;n+="<"+s;for(var o=0,c=e._numattrs;o<c;o++){var l=e._attr(o);n+=" "+mAt(l),l.value!==void 0&&(n+='="'+hAt(l.value)+'"')}if(n+=">",!(i&&dAt[s])){var u=e.serialize();MIe[s.toUpperCase()]&&(u=qIe(u,s)),i&&pAt[s]&&u.charAt(0)===`
@@ -5793,7 +5793,7 @@ The web search request used endpoint ${JSON.stringify(e)}. Search endpoint confi
5793
5793
  .error { padding: .75rem; border-radius: .5rem; background: #461d2b; color: #ffd6df; }
5794
5794
  .hint { margin: 1.5rem 0 0; font-size: .875rem; }
5795
5795
  code { padding: .1rem .3rem; border-radius: .3rem; background: #0c1222; color: #edf2ff; }
5796
- `}a(vMe,"pageStyles");B2();var Hne="enabled",Vne=Object.freeze({id:"direct",capabilities:Object.freeze(["bash"]),plan:"free",shell:"just-bash-direct",probe:a(e=>e.LOADER===void 0?"available":"needs-binding","probe")}),KI=Object.freeze({id:"dynamic-worker",capabilities:Object.freeze(["bash","coding"]),plan:"paid",shell:"just-bash-isolated",probe:a(e=>e.LOADER===void 0?"needs-binding":"available","probe")}),Gne=Object.freeze({id:"container",capabilities:Object.freeze(["container"]),plan:"paid",shell:"linux-container",probe:a(e=>e.DSH_EDGE_CONTAINER_RUNTIME===Hne?"available":"needs-binding","probe")}),xVt=Object.freeze([Gne,KI,Vne]);function Kne(e,t=xVt){return t.filter(n=>n.probe(e)==="available")}a(Kne,"availableEdgeRuntimeProviders");function Zne(e){let t=a(r=>e.find(i=>i.capabilities.includes(r)),"first"),n=t("bash");if(n===void 0)throw new Error("No available runtime provider serves the bash layer.");return{bash:n.id,container:t("container")?.id??null}}a(Zne,"resolveEdgeRuntimeSelection");function nM(e){let t=Kne(e),{bash:n,container:r}=Zne(t);return t.find(i=>i.id===(r??n)).shell}a(nM,"resolveEdgeRuntimeShell");function SVt(){return"dsh-edge@0.20.0-alpha.1/direct"}a(SVt,"resolveEdgeDeploymentId");function ZI(e){return{baseURL:EZ(e.DEEPSEEK_BASE_URL),maxTokens:IZ(e.DEEPSEEK_MAX_OUTPUT_TOKENS),model:p1(e.DEEPSEEK_MODEL),reasoningEffort:_Z(e.DEEPSEEK_REASONING_EFFORT),searchBaseURL:p3(e.DEEPSEEK_SEARCH_BASE_URL),streamIdleTimeoutMs:TZ(e.DEEPSEEK_STREAM_IDLE_TIMEOUT_MS),commandTimeoutPolicy:Sy(e.DSH_EDGE_DEFAULT_COMMAND_TIMEOUT_MS,e.DSH_EDGE_MAX_COMMAND_TIMEOUT_MS)}}a(ZI,"resolveEdgeDeploymentConfig");function kVt(e){return typeof e.DEEPSEEK_API_KEY=="string"&&e.DEEPSEEK_API_KEY.trim().length>0}a(kVt,"edgeDeploymentApiKeyConfigured");function EVt(e){let t=EZ(e),n=new URL(t);return n.search.length===0&&n.hash.length===0?t:(n.search="",n.hash="",n.href)}a(EVt,"projectedEdgeBaseURL");function Jne(e,t){return{shell:nM(e),storage:"durable-object-sqlite-vfs",attachmentStorage:t??(e.DSH_EDGE_ATTACHMENTS===void 0?"temporary-do":"private-r2"),deploymentId:SVt(),apiKeyConfigured:kVt(e),baseURL:EVt(e.DEEPSEEK_BASE_URL),maxTokens:IZ(e.DEEPSEEK_MAX_OUTPUT_TOKENS),model:p1(e.DEEPSEEK_MODEL),reasoningEffort:_Z(e.DEEPSEEK_REASONING_EFFORT),searchBaseURL:p3(e.DEEPSEEK_SEARCH_BASE_URL),streamIdleTimeoutMs:TZ(e.DEEPSEEK_STREAM_IDLE_TIMEOUT_MS),commandTimeoutPolicy:Sy(e.DSH_EDGE_DEFAULT_COMMAND_TIMEOUT_MS,e.DSH_EDGE_MAX_COMMAND_TIMEOUT_MS)}}a(Jne,"resolveEdgeDeploymentProfile");function rM(e){ZI(e);let t=Jne(e);return{ok:!0,service:"dsh-edge",storage:t.storage,attachmentStorage:t.attachmentStorage,shell:t.shell,agent:"upstream-react-loop-agent",access:"single-owner-cookie",deploymentId:t.deploymentId,...e.CF_VERSION_METADATA===void 0?{}:{workerVersionId:e.CF_VERSION_METADATA.id},version:o1,upstreamVersion:TSe,status:"ready"}}a(rM,"resolveEdgeDeploymentHealth");import{AsyncLocalStorage as qun}from"node:async_hooks";import{RpcTarget as _Vt}from"cloudflare:workers";function TVt(e){let{intervalMs:t,ping:n,onFailure:r}=e,i=!1,s=setInterval(()=>{i||n().catch(o=>{i||(i=!0,clearInterval(s),r(o instanceof Error?o:new Error(String(o))))})},t);return()=>{i||(i=!0,clearInterval(s))}}a(TVt,"startHeartbeat");async function IVt(e,t){let n=AbortSignal.timeout(t.timeoutMs),r=await e.fetchPort(t.port,`http://container${t.path}`,{method:"HEAD",signal:n});if(r.body?.cancel(),!r.ok)throw new Error(`computerd health returned ${r.status}`)}a(IVt,"probeComputerdHealth");var AVt="computer.internal",CVt="/health",Yne="/api",RVt=8080,$Vt=3e4,OVt=2e4,NVt=1,PVt=2e3,DVt=250,MVt=2e3;function LVt(e,t){if(t===void 0||e===null)return!1;let n=e.indexOf(" ");if(n===-1||e.slice(0,n).toLowerCase()!=="bearer")return!1;let r=e.slice(n+1).trim();if(r.length!==t.length)return!1;let i=0;for(let s=0;s<t.length;s+=1)i|=r.charCodeAt(s)^t.charCodeAt(s);return i===0}a(LVt,"bearerMatches");var sM=class{static{a(this,"CloudflareContainerBackend")}type="cloudflare-container";id;#e;#t;#r;#n;#i;#s;#a;#c;constructor(e){this.id=e.id??"container-shell",this.#t=e.egress??{mode:"none"},this.#r=this.#t.mode==="http-gateway"?crypto.randomUUID():void 0,this.#e={container:e.container,workspace:e.workspace,containerEnv:e.containerEnv,egressHost:e.egressHost??AVt,containerPort:e.containerPort??RVt,connectTimeoutMs:e.connectTimeoutMs??$Vt,heartbeatIntervalMs:e.heartbeatIntervalMs??OVt,restartAttempts:e.restartAttempts??NVt,healthProbeTimeoutMs:e.healthProbeTimeoutMs??PVt,healthRetryInitialDelayMs:e.healthRetryInitialDelayMs??DVt,healthRetryMaxDelayMs:e.healthRetryMaxDelayMs??MVt}}async connect(){if(this.#c)return this.#c;let e=Date.now()+this.#e.connectTimeoutMs,t=await(await this.#e.container()).getWorkspaceContainer(),n=await t.exitInfo().catch(()=>null),r={PORT:String(this.#e.containerPort),MOUNT_POINT:"/workspace",...this.#e.containerEnv},i,s;try{({runtimeId:i,clientSecret:s}=await t.start({env:r,enableInternet:this.#t.mode==="direct"}))}catch(p){throw new wc(this.#d("start",{attempt:1,maxAttempts:this.#e.restartAttempts+1,restarts:0,lastError:p,priorExit:n}),{cause:p})}try{await t.interceptOutboundHttp(this.#e.egressHost,this.#e.workspace),this.#t.mode==="http-gateway"&&this.#r!==void 0&&await t.interceptAllOutboundHttp(this.#e.workspace,this.#r)}catch(p){throw new wc(this.#d("egress",{attempt:1,maxAttempts:this.#e.restartAttempts+1,restarts:0,lastError:p,priorExit:n}),{cause:p})}this.#n=s,this.#u(),i=await this.#p(t,r,e,n,i),await this.#f(t,e),await this.#v(t,e,s);let o=await this.#h(e),c=N8(o),l,u=new Promise(p=>{let f=!1,h=a(()=>{f||(f=!0,l?.(),p(),this.#c=void 0)},"onClose");o.addEventListener("close",h,{once:!0}),o.addEventListener("error",h,{once:!0}),c.onRpcBroken(h)});this.#e.heartbeatIntervalMs>0&&(l=TVt({intervalMs:this.#e.heartbeatIntervalMs,ping:a(()=>c.sync.watermarks(),"ping"),onFailure:a(()=>{try{o.close()}catch{}},"onFailure")}));let d={rpc:c,runtimeId:i,closed:u,close:a(async()=>{l?.();try{c[Symbol.dispose]?.()}catch{}try{o.close()}catch{}this.#c=void 0},"close")};return this.#c=d,d}async handleFetch(e){if(this.#t.mode==="http-gateway"&&this.#r!==void 0&&e.headers.get("x-workspace-egress-token")===this.#r){let i=new Headers(e.headers),s=i.get(KS),o;try{o=new URL(s??"")}catch{return new Response("invalid egress URL",{status:400})}if(o.protocol!=="http:"&&o.protocol!=="https:")return new Response("invalid egress URL",{status:400});i.delete(uC),i.delete(KS);let c=new Request(e,{headers:i});return this.#t.gateway.fetch(new Request(o,c))}if(new URL(e.url).pathname!==Yne)return new Response("not found",{status:404});if(e.headers.get("upgrade")!=="websocket")return new Response(`${Yne} requires a websocket upgrade`,{status:400});if(!LVt(e.headers.get("authorization"),this.#n))return new Response("unauthorized",{status:401,headers:{"www-authenticate":"Bearer"}});let t=new WebSocketPair,[n,r]=[t[0],t[1]];if(r.accept(),this.#s)this.#s(r);else return r.close(1011,"no pending connect"),new Response("no pending connect",{status:409});return new Response(null,{status:101,webSocket:n})}#u(){this.#i=new Promise((e,t)=>{this.#s=e,this.#a=t}),this.#i.catch(()=>{})}#o(){this.#i=void 0,this.#s=void 0,this.#a=void 0}async#p(e,t,n,r,i){let s=this.#e.restartAttempts+1,o=Math.max(0,n-Date.now()),c=Math.max(250,Math.floor(o/s)),l=0,u=0,d,p=i;for(;l<s;){l++;let f=Math.min(n,Date.now()+c);if(await this.#m(e,f).then(()=>!0,h=>(d=h,!1)))return p;if(l<s)try{({runtimeId:p}=await e.restart({env:t,enableInternet:this.#t.mode==="direct"})),u++}catch(h){throw this.#a?.(h),this.#o(),new wc(this.#d("restart",{attempt:l,maxAttempts:s,restarts:u,lastError:h}),{cause:h})}}throw this.#a?.(new Error("computerd never became healthy")),this.#o(),new wc(this.#d("health",{attempt:l,maxAttempts:s,restarts:u,lastError:d,priorExit:r}),d instanceof Error?{cause:d}:void 0)}async#m(e,t){let n=this.#e.healthRetryInitialDelayMs,r;for(;Date.now()<t;)try{await IVt(e,{port:this.#e.containerPort,path:"/health",timeoutMs:Math.min(this.#e.healthProbeTimeoutMs,Math.max(50,t-Date.now()))});return}catch(i){r=i;let s=t-Date.now();if(s<=0)break;await jVt(Math.min(n,s)),n=Math.min(n*2,this.#e.healthRetryMaxDelayMs)}throw r??new Error("computerd health probe timed out")}#d(e,t){let n=t.priorExit?` priorExit=${JSON.stringify(t.priorExit.reason)}`:"";return`CloudflareContainerBackend(${this.id}): connect failed at stage=${e} port=${this.#e.containerPort} attempt=${t.attempt}/${t.maxAttempts} restarts=${t.restarts} timeoutMs=${this.#e.connectTimeoutMs}${n} lastError=${wMe(t.lastError)}`}async#f(e,t){let n;try{let r=await e.fetchPort(this.#e.containerPort,"http://container/api",{signal:AbortSignal.timeout(Math.min(this.#e.healthProbeTimeoutMs,Math.max(50,t-Date.now())))});n=r.status,await r.text().catch(()=>"")}catch{return}if(n!==401)throw this.#a?.(new Error("container is not enforcing RPC_CLIENT_SECRET")),this.#o(),new wc(`CloudflareContainerBackend(${this.id}) [stage=auth]: container served an unauthenticated request to /api with ${n}, so this workspace would run without authorization. A container or image predating RPC_CLIENT_SECRET has to be recycled.`)}async#v(e,t,n){let r=Math.max(0,t-Date.now()),i;try{i=await e.fetchPort(this.#e.containerPort,"http://container/connect",{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${n}`},body:JSON.stringify({base:`http://${this.#e.egressHost}`,health:CVt,api:Yne,healthTimeoutMs:r})})}catch(s){throw this.#a?.(s),this.#o(),new wc(`CloudflareContainerBackend(${this.id}) [stage=connect]: POST /connect failed: ${wMe(s)}`,{cause:s})}if(!i.ok){let s=await i.text().catch(()=>""),o=new Error(`/connect ${i.status}`);throw this.#a?.(o),this.#o(),new wc(`CloudflareContainerBackend(${this.id}) [stage=connect]: POST /connect returned ${i.status}: ${s}`,{cause:o})}}async#h(e){let t=this.#i;if(!t)throw new Error("CloudflareContainerBackend: upgrade promise missing");let n=Math.max(0,e-Date.now()),r;try{return await Promise.race([t,new Promise((i,s)=>{r=setTimeout(()=>s(new wc(`CloudflareContainerBackend(${this.id}) [stage=ws]: /api upgrade did not arrive within ${this.#e.connectTimeoutMs}ms`)),n)})])}finally{r&&clearTimeout(r),this.#o()}}};function jVt(e){return new Promise(t=>setTimeout(t,e))}a(jVt,"sleep");function wMe(e){return e instanceof Error?e.message:String(e)}a(wMe,"describeError");var bMe="computer:container-client-secret",FVt=16;function qVt(){let e=crypto.getRandomValues(new Uint8Array(FVt));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}a(qVt,"generate");var UVt=class{static{a(this,"ContainerClientSecret")}storage;constructor(e){this.storage=e}async ensure(){let e=await this.storage.get(bMe);if(typeof e=="string"&&e.length>0)return e;let t=qVt();return await this.storage.put(bMe,t),t}},xMe="computer:container-launch-record";async function SMe(e){return{enableInternet:e.enableInternet,envDigest:await BVt(e.env)}}a(SMe,"launchRecordFor");function zVt(e,t){return e.enableInternet===t.enableInternet&&e.envDigest===t.envDigest}a(zVt,"sameLaunch");async function BVt(e){let t=Object.keys(e).sort().map(r=>`${r.length}:${r}=${e[r]?.length??0}:${e[r]??""}`).join(";"),n=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return Array.from(new Uint8Array(n),r=>r.toString(16).padStart(2,"0")).join("")}a(BVt,"digestEnv");var WVt=class{static{a(this,"CurrentContainerLaunchRecord")}storage;constructor(e){this.storage=e}async get(){return await this.storage.get(xMe)??null}async set(e){await this.storage.put(xMe,e)}},kMe=new WeakMap;function ere(e){let t=kMe.get(e);return t===void 0&&(t={exit:null,currentGeneration:0,expectedExitGeneration:null,currentMonitorSettled:null},kMe.set(e,t)),t}a(ere,"getContainerLifecycle");function iM(e){return ere(e).exit}a(iM,"containerExitInfo");function EMe(e){return e===void 0?"exited normally":e instanceof Error?e.message:String(e)}a(EMe,"formatExitReason");function _Me(e,t,n){let r=ere(e);r.currentGeneration+=1;let i=r.currentGeneration;r.exit=null,r.currentMonitorSettled=t.monitor().then(()=>TMe(r,i,void 0,n),s=>TMe(r,i,s,n))}a(_Me,"installContainerMonitor");async function Xne(e,t){let n=ere(e);n.expectedExitGeneration=n.currentGeneration;let r=n.currentMonitorSettled;await t.destroy(),r&&await r}a(Xne,"destroyContainerExpectingExit");async function TMe(e,t,n,r){if(t!==e.currentGeneration)return;let i=e.expectedExitGeneration===t;i&&(e.expectedExitGeneration=null);let s=EMe(n),o=Date.now();e.exit={reason:s,exitedAt:o},i?console.info({message:"workspace.container.exited",reason:s,exitedAt:o,expected:!0}):console.warn({message:"workspace.container.exited",reason:s,exitedAt:o,expected:!1});try{await r?.()}catch(c){console.error({message:"workspace.container.exit_cleanup_failed",reason:EMe(c),exitedAt:Date.now()})}}a(TMe,"recordExit");var Qne="computer:container-runtime-identity",HVt=class{static{a(this,"CurrentContainerRuntimeIdentity")}storage;constructor(e){this.storage=e}async get(){return await this.storage.get(Qne)??null}async markStarted(){let e={id:crypto.randomUUID()};return await this.storage.put(Qne,e),e}async clear(e){(await this.get())?.id===e.id&&await this.storage.delete(Qne)}},VVt=class extends _Vt{static{a(this,"WorkspaceContainerAPI")}#e;#t;#r;#n;#i;constructor(e){if(super(),!e.container)throw new Error("WorkspaceContainerAPI: DO is not container-enabled (check wrangler.jsonc)");this.#e=e.container,this.#t=e,this.#r=new HVt(e.storage),this.#n=new UVt(e.storage),this.#i=new WVt(e.storage)}async start(e){let t=iM(this.#t),n=await this.#n.ensure(),r=await SMe(e);if(t!==null){try{await Xne(this.#t,this.#e)}catch{}return this.#s(e,n,r,"launched")}if(!this.#e.running)return this.#s(e,n,r,"launched");let i=await this.#i.get();if(i===null||!zVt(i,r)){console.warn({message:i===null?"container was started outside WorkspaceContainerAPI; relaunching so the requested environment applies":"running container was launched with a different spec; relaunching",component:"workspace-container",requested:r,actual:i});try{await Xne(this.#t,this.#e)}catch{}return this.#s(e,n,r,"relaunched")}let s=await this.#r.get()??await this.#r.markStarted();return _Me(this.#t,this.#e,()=>this.#r.clear(s)),{runtimeId:s.id,clientSecret:n,outcome:"adopted"}}async restart(e){try{await Xne(this.#t,this.#e)}catch{}let t=await this.#n.ensure();return this.#s(e,t,await SMe(e),"launched")}async setInactivityTimeout(e){await this.#e.setInactivityTimeout(e)}async#s(e,t,n,r){let i=await this.#r.markStarted();try{this.#e.start({enableInternet:e.enableInternet,env:{...e.env,RPC_CLIENT_SECRET:t}})}catch(s){throw await this.#r.clear(i),s}return await this.#i.set(n),_Me(this.#t,this.#e,()=>this.#r.clear(i)),{runtimeId:i.id,clientSecret:t,outcome:r}}async status(){return{running:this.#e.running,exit:iM(this.#t)}}async exitInfo(){return iM(this.#t)}async interceptAllOutboundHttp(e,t){let n=this.#t.exports.WorkspaceProxy({props:{...e,egressToken:t}});await Promise.all([this.#e.interceptAllOutboundHttp(n),this.#e.interceptOutboundHttps("*",n)])}async interceptOutboundHttp(e,t){let n=this.#t.exports;await this.#e.interceptOutboundHttp(e,n.WorkspaceProxy({props:t}))}fetchPort(e,t,n){let r=iM(this.#t);if(r!==null)throw new wc(`container exited: ${r.reason}`);return this.#e.getTcpPort(e).fetch(t,n)}port(e){return this.#e.getTcpPort(e)}};function IMe(e){class t extends e{static{a(this,"WithWorkspaceContainer")}getWorkspaceContainer(){return new VVt(this.ctx)}}return t}a(IMe,"withWorkspaceContainer");var GVt={session:"sessions",skill:"skills",agentPreset:"agentPresets",subagent:"subagents",goal:"goals",event:"events",download:"downloads"};function CMe(e,t){let n=t.indexOf("."),r=t.indexOf("/"),i=n>=0?n:r;if(i<0)return;let s=t.slice(0,i),o=t.slice(i+1),c=GVt[s]??s,l=e[c];if(l===void 0)return;let u=l[o];return typeof u=="function"?u:void 0}a(CMe,"resolve");function KVt(e,t){return Response.json({type:"server-response",rpcId:e,result:{ok:!1,error:t}})}a(KVt,"errorResponse");async function tre(e,t,n,r,i){let s=CMe(e,t);if(s!==void 0)return await s({rpcId:n,payload:r},i)}a(tre,"callEdgeApi");async function RMe(e,t){let r=new URL(t.url).pathname;if(t.method!=="POST"||!r.startsWith("/api/"))return new Response("not found",{status:404});if(r==="/api/respond")return Response.json({accepted:!1,reason:"not-pending"});let i=r.slice(5);if(CMe(e,i)===void 0)return new Response("not found",{status:404});let s;try{s=await t.json()}catch{return new Response("body is not JSON",{status:400})}let o=typeof s.rpcId=="string"?s.rpcId:"invalid-request",c=s.payload??{};try{let l=await tre(e,i,o,c,t.signal);return l===void 0?new Response("not found",{status:404}):Response.json({type:"server-response",rpcId:l.rpcId,result:l.result})}catch(l){return KVt(o,{code:"internal",message:String(l),details:{}})}}a(RMe,"dispatchEdgeApi");kr();Ps();Eg();import{DurableObject as Uun}from"cloudflare:workers";var oM=class{constructor(t,n=Date.now,r=2){this.sleepAfterMs=t;this.now=n;this.maxConcurrent=r}sleepAfterMs;now;maxConcurrent;static{a(this,"ContainerActivity")}inFlight=0;lastActivity;stopping;waiters=[];async admit(t){let n=this.now();for(;this.stopping!==void 0||this.inFlight>=this.maxConcurrent;){if(t?.throwIfAborted(),this.stopping!==void 0){await ZVt(this.stopping,t);continue}await new Promise((r,i)=>{let s=a(()=>{t?.removeEventListener("abort",o),r()},"wake"),o=a(()=>{let c=this.waiters.indexOf(s);c!==-1&&this.waiters.splice(c,1),i(t.reason)},"abort");this.waiters.push(s),t?.addEventListener("abort",o,{once:!0})})}return t?.aborted===!0&&(this.waiters.shift()?.(),t.throwIfAborted()),{release:this.begin(),queuedMs:this.now()-n}}begin(){this.inFlight+=1,this.lastActivity=this.now();let t=!1;return()=>{t||(t=!0,this.inFlight-=1,this.lastActivity=this.now(),this.waiters.shift()?.())}}async stopIfIdle(t){return this.idle()?await this.stop(t):"busy"}async stopNow(t){return this.inFlight===0?await this.stop(t):"busy"}snapshot(){return{runningCommands:this.inFlight,lastActivityAt:this.lastActivity??null}}async stop(t){if(this.stopping!==void 0)return"busy";let n="stopped",r=t().catch(i=>{n="failed",this.lastActivity=this.now(),console.error("dsh-edge container stop failed.",i)});this.stopping=r;try{await r}finally{this.stopping=void 0}return n}deadline(){return this.inFlight>0?this.now()+this.sleepAfterMs():this.lastActivity===void 0?this.now():this.lastActivity+this.sleepAfterMs()}idle(){return this.inFlight===0&&(this.lastActivity===void 0||this.now()>=this.lastActivity+this.sleepAfterMs())}};function ZVt(e,t){return t===void 0?e:new Promise((n,r)=>{let i=a(()=>r(t.reason),"abort");t.addEventListener("abort",i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener("abort",i))})}a(ZVt,"untilAborted");import{WorkerEntrypoint as LQn}from"cloudflare:workers";var Iv=tl($Me());var nre=a((e,t,n)=>{let r=e instanceof RegExp?OMe(e,n):e,i=t instanceof RegExp?OMe(t,n):t,s=r!==null&&i!=null&&JVt(r,i,n);return s&&{start:s[0],end:s[1],pre:n.slice(0,s[0]),body:n.slice(s[0]+r.length,s[1]),post:n.slice(s[1]+i.length)}},"balanced"),OMe=a((e,t)=>{let n=t.match(e);return n?n[0]:null},"maybeMatch"),JVt=a((e,t,n)=>{let r,i,s,o,c,l=n.indexOf(e),u=n.indexOf(t,l+1),d=l;if(l>=0&&u>0){if(e===t)return[l,u];for(r=[],s=n.length;d>=0&&!c;){if(d===l)r.push(d),l=n.indexOf(e,d+1);else if(r.length===1){let p=r.pop();p!==void 0&&(c=[p,u])}else i=r.pop(),i!==void 0&&i<s&&(s=i,o=u),u=n.indexOf(t,d+1);d=l<u&&l>=0?l:u}r.length&&o!==void 0&&(c=[s,o])}return c},"range");var NMe="\0SLASH"+Math.random()+"\0",PMe="\0OPEN"+Math.random()+"\0",sre="\0CLOSE"+Math.random()+"\0",DMe="\0COMMA"+Math.random()+"\0",MMe="\0PERIOD"+Math.random()+"\0",YVt=new RegExp(NMe,"g"),XVt=new RegExp(PMe,"g"),QVt=new RegExp(sre,"g"),eGt=new RegExp(DMe,"g"),tGt=new RegExp(MMe,"g"),nGt=/\\\\/g,rGt=/\\{/g,iGt=/\\}/g,sGt=/\\,/g,oGt=/\\\./g,aGt=1e5,cGt=4e6;function rre(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}a(rre,"numeric");function lGt(e){return e.replace(nGt,NMe).replace(rGt,PMe).replace(iGt,sre).replace(sGt,DMe).replace(oGt,MMe)}a(lGt,"escapeBraces");function uGt(e){return e.replace(YVt,"\\").replace(XVt,"{").replace(QVt,"}").replace(eGt,",").replace(tGt,".")}a(uGt,"unescapeBraces");function LMe(e){if(!e)return[""];let t=[],n=nre("{","}",e);if(!n)return e.split(",");let{pre:r,body:i,post:s}=n,o=r.split(",");o[o.length-1]+="{"+i+"}";let c=LMe(s);return s.length&&(o[o.length-1]+=c.shift(),o.push.apply(o,c)),t.push.apply(t,o),t}a(LMe,"parseCommaParts");function jMe(e,t={}){if(!e)return[];let{max:n=aGt,maxLength:r=cGt}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),ire(lGt(e),n,r,!0).map(uGt)}a(jMe,"expand");function dGt(e){return"{"+e+"}"}a(dGt,"embrace");function pGt(e){return/^-?0\d/.test(e)}a(pGt,"isPadded");function fGt(e,t){return e<=t}a(fGt,"lte");function hGt(e,t){return e>=t}a(hGt,"gte");function JI(e,t,n,r,i,s){let o=[],c=0;for(let l=0;l<e.length;l++)for(let u=0;u<n.length;u++){if(o.length>=r)return o;let d=e[l]+t+n[u];if(!(s&&!d)){if(c+d.length>i)return o;o.push(d),c+=d.length}}return o}a(JI,"combine");function mGt(e,t,n,r){let i=e.split(/\.\./),s=[];if(i[0]===void 0||i[1]===void 0)return s;let o=rre(i[0]),c=rre(i[1]),l=Math.max(i[0].length,i[1].length),u=i.length===3&&i[2]!==void 0?Math.max(Math.abs(rre(i[2])),1):1,d=fGt;c<o&&(u*=-1,d=hGt);let f=i.some(pGt),h=0;for(let g=o;d(g,c)&&s.length<n;g+=u){let y;if(t)y=String.fromCharCode(g),y==="\\"&&(y="");else if(y=String(g),f){let v=l-y.length;if(v>0){let w=new Array(v+1).join("0");g<0?y="-"+w+y.slice(1):y=w+y}}if(h+y.length>r)break;s.push(y),h+=y.length}return s}a(mGt,"expandSequence");function ire(e,t,n,r){let i=[""],s=!1,o=!0;for(;;){let c=nre("{","}",e);if(!c)return JI(i,e,[""],t,n,s);let l=c.pre;if(/\$$/.test(l)){if(i=JI(i,l+"{"+c.body+"}",[""],t,n,s&&!c.post.length),o=!1,!c.post.length)break;e=c.post;continue}let u=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(c.body),d=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(c.body),p=u||d,f=c.body.indexOf(",")>=0;if(!p&&!f){if(c.post.match(/,(?!,).*\}/)){e=c.pre+"{"+c.body+sre+c.post,r=!0;continue}return JI(i,l+"{"+c.body+"}"+c.post,[""],t,n,s)}o&&(s=r&&!p,o=!1);let h;if(p)h=mGt(c.body,d,t,n);else{let g=LMe(c.body);if(g.length===1&&g[0]!==void 0&&(g=ire(g[0],t,n,!1).map(dGt),g.length===1)){if(i=JI(i,l+g[0],[""],t,n,s&&!c.post.length),!c.post.length)break;e=c.post;continue}let y=s&&!c.post.length&&!l;for(let w=0;y&&w<i.length;w++)i[w]&&(y=!1);h=[];let v=0;e:for(let w=0;w<g.length;w++){let b=ire(g[w],t,n,!1);for(let S=0;S<b.length;S++){let k=b[S];if(!(y&&!k)){if(h.length>=t||v+k.length>n)break e;h.push(k),v+=k.length}}}}if(i=JI(i,l,h,t,n,s&&!c.post.length),!c.post.length)break;e=c.post}return i}a(ire,"expand_");var YI=a(e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")},"assertValidPattern");var gGt={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},XI=a(e=>e.replace(/[[\]\\-]/g,"\\$&"),"braceEscape"),yGt=a(e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"regexpEscape"),FMe=a(e=>e.join(""),"rangesToString"),qMe=a((e,t)=>{let n=t;if(e.charAt(n)!=="[")throw new Error("not in a brace expression");let r=[],i=[],s=n+1,o=!1,c=!1,l=!1,u=!1,d=n,p="";e:for(;s<e.length;){let y=e.charAt(s);if((y==="!"||y==="^")&&s===n+1){u=!0,s++;continue}if(y==="]"&&o&&!l){d=s+1;break}if(o=!0,y==="\\"&&!l){l=!0,s++;continue}if(y==="["&&!l){for(let[v,[w,b,S]]of Object.entries(gGt))if(e.startsWith(v,s)){if(p)return["$.",!1,e.length-n,!0];s+=v.length,S?i.push(w):r.push(w),c=c||b;continue e}}if(l=!1,p){y>p?r.push(XI(p)+"-"+XI(y)):y===p&&r.push(XI(y)),p="",s++;continue}if(e.startsWith("-]",s+1)){r.push(XI(y+"-")),s+=2;continue}if(e.startsWith("-",s+1)){p=y,s+=2;continue}r.push(XI(y)),s++}if(d<s)return["",!1,0,!1];if(!r.length&&!i.length)return["$.",!1,e.length-n,!0];if(i.length===0&&r.length===1&&/^\\?.$/.test(r[0])&&!u){let y=r[0].length===2?r[0].slice(-1):r[0];return[yGt(y),!1,d-n,!1]}let f="["+(u?"^":"")+FMe(r)+"]",h="["+(u?"":"^")+FMe(i)+"]";return[r.length&&i.length?"("+f+"|"+h+")":r.length?f:h,c,d-n,!0]},"parseClass");var _y=a((e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?t?e.replace(/\[([^/\\])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\])\]/g,"$1$2").replace(/\\([^/])/g,"$1"):t?e.replace(/\[([^/\\{}])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,"$1$2").replace(/\\([^/{}])/g,"$1"),"unescape");var Nl,vGt=new Set(["!","?","+","*","@"]),ore=a(e=>vGt.has(e),"isExtglobType"),UMe=a(e=>ore(e.type),"isExtglobAST"),wGt=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),bGt=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),xGt=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),zMe=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),SGt="(?!(?:^|/)\\.\\.?(?:$|/))",cM="(?!\\.)",kGt=new Set(["[","."]),EGt=new Set(["..","."]),_Gt=new Set("().*{}+?[]^$\\!"),TGt=a(e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"regExpEscape"),are="[^/]",BMe=are+"*?",WMe=are+"+?",IGt=0,J1=class{static{a(this,"AST")}type;#e;#t;#r=!1;#n=[];#i;#s;#a;#c=!1;#u;#o;#p=!1;id=++IGt;get depth(){return(this.#i?.depth??-1)+1}[Symbol.for("nodejs.util.inspect.custom")](){return{"@@type":"AST",id:this.id,type:this.type,root:this.#e.id,parent:this.#i?.id,depth:this.depth,partsLength:this.#n.length,parts:this.#n}}constructor(t,n,r={}){this.type=t,t&&(this.#t=!0),this.#i=n,this.#e=this.#i?this.#i.#e:this,this.#u=this.#e===this?r:this.#e.#u,this.#a=this.#e===this?[]:this.#e.#a,t==="!"&&!this.#e.#c&&this.#a.push(this),this.#s=this.#i?this.#i.#n.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let t of this.#n)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#o!==void 0?this.#o:this.type?this.#o=this.type+"("+this.#n.map(t=>String(t)).join("|")+")":this.#o=this.#n.map(t=>String(t)).join("")}#m(){if(this!==this.#e)throw new Error("should only call on root");if(this.#c)return this;this.toString(),this.#c=!0;let t;for(;t=this.#a.pop();){if(t.type!=="!")continue;let n=t,r=n.#i;for(;r;){for(let i=n.#s+1;!r.type&&i<r.#n.length;i++)for(let s of t.#n){if(typeof s=="string")throw new Error("string part in extglob AST??");s.copyIn(r.#n[i])}n=r,r=n.#i}}return this}push(...t){for(let n of t)if(n!==""){if(typeof n!="string"&&!(n instanceof Nl&&n.#i===this))throw new Error("invalid part: "+n);this.#n.push(n)}}toJSON(){let t=this.type===null?this.#n.slice().map(n=>typeof n=="string"?n:n.toJSON()):[this.type,...this.#n.map(n=>n.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#c&&this.#i?.type==="!")&&t.push({}),t}isStart(){if(this.#e===this)return!0;if(!this.#i?.isStart())return!1;if(this.#s===0)return!0;let t=this.#i;for(let n=0;n<this.#s;n++){let r=t.#n[n];if(!(r instanceof Nl&&r.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#i?.type==="!")return!0;if(!this.#i?.isEnd())return!1;if(!this.type)return this.#i?.isEnd();let t=this.#i?this.#i.#n.length:0;return this.#s===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let n=new Nl(this.type,t);for(let r of this.#n)n.copyIn(r);return n}static#d(t,n,r,i,s){let o=i.maxExtglobRecursion??2,c=!1,l=!1,u=-1,d=!1;if(n.type===null){let y=r,v="";for(;y<t.length;){let w=t.charAt(y++);if(c||w==="\\"){c=!c,v+=w;continue}if(l){y===u+1?(w==="^"||w==="!")&&(d=!0):w==="]"&&!(y===u+2&&d)&&(l=!1),v+=w;continue}else if(w==="["){l=!0,u=y,d=!1,v+=w;continue}if(!i.noext&&ore(w)&&t.charAt(y)==="("&&s<=o){n.push(v),v="";let S=new Nl(w,n);y=Nl.#d(t,S,y,i,s+1),n.push(S);continue}v+=w}return n.push(v),y}let p=r+1,f=new Nl(null,n),h=[],g="";for(;p<t.length;){let y=t.charAt(p++);if(c||y==="\\"){c=!c,g+=y;continue}if(l){p===u+1?(y==="^"||y==="!")&&(d=!0):y==="]"&&!(p===u+2&&d)&&(l=!1),g+=y;continue}else if(y==="["){l=!0,u=p,d=!1,g+=y;continue}if(!i.noext&&ore(y)&&t.charAt(p)==="("&&(s<=o||n&&n.#h(y))){let w=n&&n.#h(y)?0:1;f.push(g),g="";let b=new Nl(y,f);f.push(b),p=Nl.#d(t,b,p,i,s+w);continue}if(y==="|"){f.push(g),g="",h.push(f),f=new Nl(null,n);continue}if(y===")")return g===""&&n.#n.length===0&&(n.#p=!0),f.push(g),g="",n.push(...h,f),p;g+=y}return n.type=null,n.#t=void 0,n.#n=[t.substring(r-1)],p}#f(t){return this.#v(t,bGt)}#v(t,n=wGt){if(!t||typeof t!="object"||t.type!==null||t.#n.length!==1||this.type===null)return!1;let r=t.#n[0];return!r||typeof r!="object"||r.type===null?!1:this.#h(r.type,n)}#h(t,n=xGt){return!!n.get(this.type)?.includes(t)}#O(t,n){let r=t.#n[0],i=new Nl(null,r,this.options);i.#n.push(""),r.push(i),this.#w(t,n)}#w(t,n){let r=t.#n[0];this.#n.splice(n,1,...r.#n);for(let i of r.#n)typeof i=="object"&&(i.#i=this);this.#o=void 0}#E(t){return!!zMe.get(this.type)?.has(t)}#_(t){if(!t||typeof t!="object"||t.type!==null||t.#n.length!==1||this.type===null||this.#n.length!==1)return!1;let n=t.#n[0];return!n||typeof n!="object"||n.type===null?!1:this.#E(n.type)}#T(t){let n=zMe.get(this.type),r=t.#n[0],i=n?.get(r.type);if(!i)return!1;this.#n=r.#n;for(let s of this.#n)typeof s=="object"&&(s.#i=this);this.type=i,this.#o=void 0,this.#p=!1}static fromGlob(t,n={}){let r=new Nl(null,void 0,n);return Nl.#d(t,r,0,n,0),r}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let t=this.toString(),[n,r,i,s]=this.toRegExpSource();if(!(i||this.#t||this.#u.nocase&&!this.#u.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return r;let c=(this.#u.nocase?"i":"")+(s?"u":"");return Object.assign(new RegExp(`^${n}$`,c),{_src:n,_glob:t})}get options(){return this.#u}toRegExpSource(t){let n=t??!!this.#u.dot;if(this.#e===this&&(this.#l(),this.#m()),!UMe(this)){let l=this.isStart()&&this.isEnd()&&!this.#n.some(h=>typeof h!="string"),u=this.#n.map(h=>{let[g,y,v,w]=typeof h=="string"?Nl.#b(h,this.#t,l):h.toRegExpSource(t);return this.#t=this.#t||v,this.#r=this.#r||w,g}).join(""),d="";if(this.isStart()&&typeof this.#n[0]=="string"&&!(this.#n.length===1&&EGt.has(this.#n[0]))){let g=kGt,y=n&&g.has(u.charAt(0))||u.startsWith("\\.")&&g.has(u.charAt(2))||u.startsWith("\\.\\.")&&g.has(u.charAt(4)),v=!n&&!t&&g.has(u.charAt(0));d=y?SGt:v?cM:""}let p="";return this.isEnd()&&this.#e.#c&&this.#i?.type==="!"&&(p="(?:$|\\/)"),[d+u+p,_y(u),this.#t=!!this.#t,this.#r]}let r=this.type==="*"||this.type==="+",i=this.type==="!"?"(?:(?!(?:":"(?:",s=this.#g(n);if(this.isStart()&&this.isEnd()&&!s&&this.type!=="!"){let l=this.toString(),u=this;return u.#n=[l],u.type=null,u.#t=void 0,[l,_y(this.toString()),!1,!1]}let o=!r||t||n||!cM?"":this.#g(!0);o===s&&(o=""),o&&(s=`(?:${s})(?:${o})*?`);let c="";if(this.type==="!"&&this.#p)c=(this.isStart()&&!n?cM:"")+WMe;else{let l=this.type==="!"?"))"+(this.isStart()&&!n&&!t?cM:"")+BMe+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;c=i+s+l}return[c,_y(s),this.#t=!!this.#t,this.#r]}#l(){if(UMe(this)){let t=0,n=!1;do{n=!0;for(let r=0;r<this.#n.length;r++){let i=this.#n[r];typeof i=="object"&&(i.#l(),this.#v(i)?(n=!1,this.#w(i,r)):this.#f(i)?(n=!1,this.#O(i,r)):this.#_(i)&&(n=!1,this.#T(i)))}}while(!n&&++t<10)}else for(let t of this.#n)typeof t=="object"&&t.#l();this.#o=void 0}#g(t){return this.#n.map(n=>{if(typeof n=="string")throw new Error("string type in extglob ast??");let[r,i,s,o]=n.toRegExpSource(t);return this.#r=this.#r||o,r}).filter(n=>!(this.isStart()&&this.isEnd())||!!n).join("|")}static#b(t,n,r=!1){let i=!1,s="",o=!1,c=!1;for(let l=0;l<t.length;l++){let u=t.charAt(l);if(i){i=!1,s+=(_Gt.has(u)?"\\":"")+u;continue}if(u==="*"){if(c)continue;c=!0,s+=r&&/^[*]+$/.test(t)?WMe:BMe,n=!0;continue}else c=!1;if(u==="\\"){l===t.length-1?s+="\\\\":i=!0;continue}if(u==="["){let[d,p,f,h]=qMe(t,l);if(f){s+=d,o=o||p,l+=f-1,n=n||h;continue}}if(u==="?"){s+=are,n=!0;continue}s+=TGt(u)}return[s,_y(t),!!n,o]}};Nl=J1;var cre=a((e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&"),"escape");var fa=a((e,t,n={})=>(YI(t),!n.nocomment&&t.charAt(0)==="#"?!1:new Jx(t,n).match(e)),"minimatch"),AGt=/^\*+([^+@!?*[(]*)$/,CGt=a(e=>t=>!t.startsWith(".")&&t.endsWith(e),"starDotExtTest"),RGt=a(e=>t=>t.endsWith(e),"starDotExtTestDot"),$Gt=a(e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),"starDotExtTestNocase"),OGt=a(e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),"starDotExtTestNocaseDot"),NGt=/^\*+\.\*+$/,PGt=a(e=>!e.startsWith(".")&&e.includes("."),"starDotStarTest"),DGt=a(e=>e!=="."&&e!==".."&&e.includes("."),"starDotStarTestDot"),MGt=/^\.\*+$/,LGt=a(e=>e!=="."&&e!==".."&&e.startsWith("."),"dotStarTest"),jGt=/^\*+$/,FGt=a(e=>e.length!==0&&!e.startsWith("."),"starTest"),qGt=a(e=>e.length!==0&&e!=="."&&e!=="..","starTestDot"),UGt=/^\?+([^+@!?*[(]*)?$/,zGt=a(([e,t=""])=>{let n=GMe([e]);return t?(t=t.toLowerCase(),r=>n(r)&&r.toLowerCase().endsWith(t)):n},"qmarksTestNocase"),BGt=a(([e,t=""])=>{let n=KMe([e]);return t?(t=t.toLowerCase(),r=>n(r)&&r.toLowerCase().endsWith(t)):n},"qmarksTestNocaseDot"),WGt=a(([e,t=""])=>{let n=KMe([e]);return t?r=>n(r)&&r.endsWith(t):n},"qmarksTestDot"),HGt=a(([e,t=""])=>{let n=GMe([e]);return t?r=>n(r)&&r.endsWith(t):n},"qmarksTest"),GMe=a(([e])=>{let t=e.length;return n=>n.length===t&&!n.startsWith(".")},"qmarksTestNoExt"),KMe=a(([e])=>{let t=e.length;return n=>n.length===t&&n!=="."&&n!==".."},"qmarksTestNoExtDot"),ZMe=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",HMe={win32:{sep:"\\"},posix:{sep:"/"}},VGt=ZMe==="win32"?HMe.win32.sep:HMe.posix.sep;fa.sep=VGt;var hc=Symbol("globstar **");fa.GLOBSTAR=hc;var GGt="[^/]",KGt=GGt+"*?",ZGt="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",JGt="(?:(?!(?:\\/|^)\\.).)*?",YGt=a((e,t={})=>n=>fa(n,e,t),"filter");fa.filter=YGt;var dd=a((e,t={})=>Object.assign({},e,t),"ext"),XGt=a(e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return fa;let t=fa;return Object.assign(a((r,i,s={})=>t(r,i,dd(e,s)),"m"),{Minimatch:class extends t.Minimatch{static{a(this,"Minimatch")}constructor(i,s={}){super(i,dd(e,s))}static defaults(i){return t.defaults(dd(e,i)).Minimatch}},AST:class extends t.AST{static{a(this,"AST")}constructor(i,s,o={}){super(i,s,dd(e,o))}static fromGlob(i,s={}){return t.AST.fromGlob(i,dd(e,s))}},unescape:a((r,i={})=>t.unescape(r,dd(e,i)),"unescape"),escape:a((r,i={})=>t.escape(r,dd(e,i)),"escape"),filter:a((r,i={})=>t.filter(r,dd(e,i)),"filter"),defaults:a(r=>t.defaults(dd(e,r)),"defaults"),makeRe:a((r,i={})=>t.makeRe(r,dd(e,i)),"makeRe"),braceExpand:a((r,i={})=>t.braceExpand(r,dd(e,i)),"braceExpand"),match:a((r,i,s={})=>t.match(r,i,dd(e,s)),"match"),sep:t.sep,GLOBSTAR:hc})},"defaults");fa.defaults=XGt;var JMe=a((e,t={})=>(YI(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:jMe(e,{max:t.braceExpandMax})),"braceExpand");fa.braceExpand=JMe;var QGt=a((e,t={})=>new Jx(e,t).makeRe(),"makeRe");fa.makeRe=QGt;var eKt=a((e,t,n={})=>{let r=new Jx(t,n);return e=e.filter(i=>r.match(i)),r.options.nonull&&!e.length&&e.push(t),e},"match");fa.match=eKt;var VMe=/[?*]|[+@!]\(.*?\)|\[|\]/,tKt=a(e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"regExpEscape"),Jx=class{static{a(this,"Minimatch")}options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,n={}){YI(t),n=n||{},this.options=n,this.maxGlobstarRecursion=n.maxGlobstarRecursion??200,this.pattern=t,this.platform=n.platform||ZMe,this.isWindows=this.platform==="win32";let r="allowWindowsEscape";this.windowsPathsNoEscape=!!n.windowsPathsNoEscape||n[r]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!n.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!n.nonegate,this.comment=!1,this.empty=!1,this.partial=!!n.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=n.windowsNoMagicRoot!==void 0?n.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let n of t)if(typeof n!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,n=this.options;if(!n.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],n.debug&&(this.debug=(...s)=>console.error(...s)),this.debug(this.pattern,this.globSet);let r=this.globSet.map(s=>this.slashSplit(s));this.globParts=this.preprocess(r),this.debug(this.pattern,this.globParts);let i=this.globParts.map((s,o,c)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=s[0]===""&&s[1]===""&&(s[2]==="?"||!VMe.test(s[2]))&&!VMe.test(s[3]),u=/^[a-z]:/i.test(s[0]);if(l)return[...s.slice(0,4),...s.slice(4).map(d=>this.parse(d))];if(u)return[s[0],...s.slice(1).map(d=>this.parse(d))]}return s.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(s=>s.indexOf(!1)===-1),this.isWindows)for(let s=0;s<this.set.length;s++){let o=this.set[s];o[0]===""&&o[1]===""&&this.globParts[s][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let r of t)for(let i=0;i<r.length;i++)r[i]==="**"&&(r[i]="*");let{optimizationLevel:n=1}=this.options;return n>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):n>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(n=>{let r=-1;for(;(r=n.indexOf("**",r+1))!==-1;){let i=r;for(;n[i+1]==="**";)i++;i!==r&&n.splice(r,i-r)}return n})}levelOneOptimize(t){return t.map(n=>(n=n.reduce((r,i)=>{let s=r[r.length-1];return i==="**"&&s==="**"?r:i===".."&&s&&s!==".."&&s!=="."&&s!=="**"?(r.pop(),r):(r.push(i),r)},[]),n.length===0?[""]:n))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let n=!1;do{if(n=!1,!this.preserveMultipleSlashes){for(let i=1;i<t.length-1;i++){let s=t[i];i===1&&s===""&&t[0]===""||(s==="."||s==="")&&(n=!0,t.splice(i,1),i--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(n=!0,t.pop())}let r=0;for(;(r=t.indexOf("..",r+1))!==-1;){let i=t[r-1];i&&i!=="."&&i!==".."&&i!=="**"&&!(this.isWindows&&/^[a-z]:$/i.test(i))&&(n=!0,t.splice(r-1,2),r-=2)}}while(n);return t.length===0?[""]:t}firstPhasePreProcess(t){let n=!1;do{n=!1;for(let r of t){let i=-1;for(;(i=r.indexOf("**",i+1))!==-1;){let o=i;for(;r[o+1]==="**";)o++;o>i&&r.splice(i+1,o-i);let c=r[i+1],l=r[i+2],u=r[i+3];if(c!==".."||!l||l==="."||l===".."||!u||u==="."||u==="..")continue;n=!0,r.splice(i,1);let d=r.slice(0);d[i]="**",t.push(d),i--}if(!this.preserveMultipleSlashes){for(let o=1;o<r.length-1;o++){let c=r[o];o===1&&c===""&&r[0]===""||(c==="."||c==="")&&(n=!0,r.splice(o,1),o--)}r[0]==="."&&r.length===2&&(r[1]==="."||r[1]==="")&&(n=!0,r.pop())}let s=0;for(;(s=r.indexOf("..",s+1))!==-1;){let o=r[s-1];if(o&&o!=="."&&o!==".."&&o!=="**"){n=!0;let l=s===1&&r[s+1]==="**"?["."]:[];r.splice(s-1,2,...l),r.length===0&&r.push(""),s-=2}}}}while(n);return t}secondPhasePreProcess(t){for(let n=0;n<t.length-1;n++)for(let r=n+1;r<t.length;r++){let i=this.partsMatch(t[n],t[r],!this.preserveMultipleSlashes);if(i){t[n]=[],t[r]=i;break}}return t.filter(n=>n.length)}partsMatch(t,n,r=!1){let i=0,s=0,o=[],c="";for(;i<t.length&&s<n.length;)if(t[i]===n[s])o.push(c==="b"?n[s]:t[i]),i++,s++;else if(r&&t[i]==="**"&&n[s]===t[i+1])o.push(t[i]),i++;else if(r&&n[s]==="**"&&t[i]===n[s+1])o.push(n[s]),s++;else if(t[i]==="*"&&n[s]&&(this.options.dot||!n[s].startsWith("."))&&n[s]!=="**"){if(c==="b")return!1;c="a",o.push(t[i]),i++,s++}else if(n[s]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(c==="a")return!1;c="b",o.push(n[s]),i++,s++}else return!1;return t.length===n.length&&o}parseNegate(){if(this.nonegate)return;let t=this.pattern,n=!1,r=0;for(let i=0;i<t.length&&t.charAt(i)==="!";i++)n=!n,r++;r&&(this.pattern=t.slice(r)),this.negate=n}matchOne(t,n,r=!1){let i=0,s=0;if(this.isWindows){let c=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),l=!c&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),u=typeof n[0]=="string"&&/^[a-z]:$/i.test(n[0]),d=!u&&n[0]===""&&n[1]===""&&n[2]==="?"&&typeof n[3]=="string"&&/^[a-z]:$/i.test(n[3]),p=l?3:c?0:void 0,f=d?3:u?0:void 0;if(typeof p=="number"&&typeof f=="number"){let[h,g]=[t[p],n[f]];h.toLowerCase()===g.toLowerCase()&&(n[f]=h,s=f,i=p)}}let{optimizationLevel:o=1}=this.options;return o>=2&&(t=this.levelTwoFileOptimize(t)),n.includes(hc)?this.#e(t,n,r,i,s):this.#r(t,n,r,i,s)}#e(t,n,r,i,s){let o=n.indexOf(hc,s),c=n.lastIndexOf(hc),[l,u,d]=r?[n.slice(s,o),n.slice(o+1),[]]:[n.slice(s,o),n.slice(o+1,c),n.slice(c+1)];if(l.length){let b=t.slice(i,i+l.length);if(!this.#r(b,l,r,0,0))return!1;i+=l.length,s+=l.length}let p=0;if(d.length){if(d.length+i>t.length)return!1;let b=t.length-d.length;if(this.#r(t,d,r,b,0))p=d.length;else{if(t[t.length-1]!==""||i+d.length===t.length||(b--,!this.#r(t,d,r,b,0)))return!1;p=d.length+1}}if(!u.length){let b=!!p;for(let S=i;S<t.length-p;S++){let k=String(t[S]);if(b=!0,k==="."||k===".."||!this.options.dot&&k.startsWith("."))return!1}return r||b}let f=[[[],0]],h=f[0],g=0,y=[0];for(let b of u)b===hc?(y.push(g),h=[[],0],f.push(h)):(h[0].push(b),g++);let v=f.length-1,w=t.length-p;for(let b of f)b[1]=w-(y[v--]+b[0].length);return!!this.#t(t,f,i,0,r,0,!!p)}#t(t,n,r,i,s,o,c){let l=n[i];if(!l){for(let p=r;p<t.length;p++){c=!0;let f=t[p];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1}return c}let[u,d]=l;for(;r<=d;){if(this.#r(t.slice(0,r+u.length),u,s,r,0)&&o<this.maxGlobstarRecursion){let h=this.#t(t,n,r+u.length,i+1,s,o+1,c);if(h!==!1)return h}let f=t[r];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1;r++}return s||null}#r(t,n,r,i,s){let o,c,l,u;for(o=i,c=s,u=t.length,l=n.length;o<u&&c<l;o++,c++){this.debug("matchOne loop");let d=n[c],p=t[o];if(this.debug(n,d,p),d===!1||d===hc)return!1;let f;if(typeof d=="string"?(f=p===d,this.debug("string match",d,p,f)):(f=d.test(p),this.debug("pattern match",d,p,f)),!f)return!1}if(o===u&&c===l)return!0;if(o===u)return r;if(c===l)return o===u-1&&t[o]==="";throw new Error("wtf?")}braceExpand(){return JMe(this.pattern,this.options)}parse(t){YI(t);let n=this.options;if(t==="**")return hc;if(t==="")return"";let r,i=null;(r=t.match(jGt))?i=n.dot?qGt:FGt:(r=t.match(AGt))?i=(n.nocase?n.dot?OGt:$Gt:n.dot?RGt:CGt)(r[1]):(r=t.match(UGt))?i=(n.nocase?n.dot?BGt:zGt:n.dot?WGt:HGt)(r):(r=t.match(NGt))?i=n.dot?DGt:PGt:(r=t.match(MGt))&&(i=LGt);let s=J1.fromGlob(t,this.options).toMMPattern();return i&&typeof s=="object"&&Reflect.defineProperty(s,"test",{value:i}),s}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let n=this.options,r=n.noglobstar?KGt:n.dot?ZGt:JGt,i=new Set(n.nocase?["i"]:[]),s=t.map(l=>{let u=l.map(p=>{if(p instanceof RegExp)for(let f of p.flags.split(""))i.add(f);return typeof p=="string"?tKt(p):p===hc?hc:p._src});u.forEach((p,f)=>{let h=u[f+1],g=u[f-1];p!==hc||g===hc||(g===void 0?h!==void 0&&h!==hc?u[f+1]="(?:\\/|"+r+"\\/)?"+h:u[f]=r:h===void 0?u[f-1]=g+"(?:\\/|\\/"+r+")?":h!==hc&&(u[f-1]=g+"(?:\\/|\\/"+r+"\\/)"+h,u[f+1]=hc))});let d=u.filter(p=>p!==hc);if(this.partial&&d.length>=1){let p=[];for(let f=1;f<=d.length;f++)p.push(d.slice(0,f).join("/"));return"(?:"+p.join("|")+")"}return d.join("/")}).join("|"),[o,c]=t.length>1?["(?:",")"]:["",""];s="^"+o+s+c+"$",this.partial&&(s="^(?:\\/|"+o+s.slice(1,-1)+c+")$"),this.negate&&(s="^(?!"+s+").+$");try{this.regexp=new RegExp(s,[...i].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,n=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&n)return!0;let r=this.options;this.isWindows&&(t=t.split("\\").join("/"));let i=this.slashSplit(t);this.debug(this.pattern,"split",i);let s=this.set;this.debug(this.pattern,"set",s);let o=i[i.length-1];if(!o)for(let c=i.length-2;!o&&c>=0;c--)o=i[c];for(let c of s){let l=i;if(r.matchBase&&c.length===1&&(l=[o]),this.matchOne(l,c,n))return r.flipNegate?!0:!this.negate}return r.flipNegate?!1:this.negate}static defaults(t){return fa.defaults(t).Minimatch}};fa.AST=J1;fa.Minimatch=Jx;fa.escape=cre;fa.unescape=_y;import{gunzipSync as oJt}from"node:zlib";var QI=class{static{a(this,"Diff")}diff(t,n,r={}){let i;typeof r=="function"?(i=r,r={}):"callback"in r&&(i=r.callback);let s=this.castInput(t,r),o=this.castInput(n,r),c=this.removeEmpty(this.tokenize(s,r)),l=this.removeEmpty(this.tokenize(o,r));return this.diffWithOptionsObj(c,l,r,i)}diffWithOptionsObj(t,n,r,i){var s;let o=a(b=>{if(b=this.postProcess(b,r),i){setTimeout(function(){i(b)},0);return}else return b},"done"),c=n.length,l=t.length,u=1,d=c+l;r.maxEditLength!=null&&(d=Math.min(d,r.maxEditLength));let p=(s=r.timeout)!==null&&s!==void 0?s:1/0,f=Date.now()+p,h=[{oldPos:-1,lastComponent:void 0}],g=this.extractCommon(h[0],n,t,0,r);if(h[0].oldPos+1>=l&&g+1>=c)return o(this.buildValues(h[0].lastComponent,n,t));let y=-1/0,v=1/0,w=a(()=>{for(let b=Math.max(y,-u);b<=Math.min(v,u);b+=2){let S,k=h[b-1],E=h[b+1];k&&(h[b-1]=void 0);let _=!1;if(E){let L=E.oldPos-b;_=E&&0<=L&&L<c}let I=k&&k.oldPos+1<l;if(!_&&!I){h[b]=void 0;continue}if(!I||_&&k.oldPos<E.oldPos?S=this.addToPath(E,!0,!1,0,r):S=this.addToPath(k,!1,!0,1,r),g=this.extractCommon(S,n,t,b,r),S.oldPos+1>=l&&g+1>=c)return o(this.buildValues(S.lastComponent,n,t))||!0;h[b]=S,S.oldPos+1>=l&&(v=Math.min(v,b-1)),g+1>=c&&(y=Math.max(y,b+1))}u++},"execEditLength");if(i)a(function b(){setTimeout(function(){if(u>d||Date.now()>f)return i(void 0);w()||b()},0)},"exec")();else for(;u<=d&&Date.now()<=f;){let b=w();if(b)return b}}addToPath(t,n,r,i,s){let o=t.lastComponent;return o&&!s.oneChangePerToken&&o.added===n&&o.removed===r?{oldPos:t.oldPos+i,lastComponent:{count:o.count+1,added:n,removed:r,previousComponent:o.previousComponent}}:{oldPos:t.oldPos+i,lastComponent:{count:1,added:n,removed:r,previousComponent:o}}}extractCommon(t,n,r,i,s){let o=n.length,c=r.length,l=t.oldPos,u=l-i,d=0;for(;u+1<o&&l+1<c&&this.equals(r[l+1],n[u+1],s);)u++,l++,d++,s.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return d&&!s.oneChangePerToken&&(t.lastComponent={count:d,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=l,u}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){let n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){let i=[],s;for(;t;)i.push(t),s=t.previousComponent,delete t.previousComponent,t=s;i.reverse();let o=i.length,c=0,l=0,u=0;for(;c<o;c++){let d=i[c];if(d.removed)d.value=this.join(r.slice(u,u+d.count)),u+=d.count;else{if(!d.added&&this.useLongestToken){let p=n.slice(l,l+d.count);p=p.map(function(f,h){let g=r[u+h];return g.length>f.length?g:f}),d.value=this.join(p)}else d.value=this.join(n.slice(l,l+d.count));l+=d.count,d.added||(u+=d.count)}}return i}};var lre=class extends QI{static{a(this,"LineDiff")}constructor(){super(...arguments),this.tokenize=rKt}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
5796
+ `}a(vMe,"pageStyles");B2();var Hne="enabled",Vne=Object.freeze({id:"direct",capabilities:Object.freeze(["bash"]),plan:"free",shell:"just-bash-direct",probe:a(e=>e.LOADER===void 0?"available":"needs-binding","probe")}),KI=Object.freeze({id:"dynamic-worker",capabilities:Object.freeze(["bash","coding"]),plan:"paid",shell:"just-bash-isolated",probe:a(e=>e.LOADER===void 0?"needs-binding":"available","probe")}),Gne=Object.freeze({id:"container",capabilities:Object.freeze(["container"]),plan:"paid",shell:"linux-container",probe:a(e=>e.DSH_EDGE_CONTAINER_RUNTIME===Hne?"available":"needs-binding","probe")}),xVt=Object.freeze([Gne,KI,Vne]);function Kne(e,t=xVt){return t.filter(n=>n.probe(e)==="available")}a(Kne,"availableEdgeRuntimeProviders");function Zne(e){let t=a(r=>e.find(i=>i.capabilities.includes(r)),"first"),n=t("bash");if(n===void 0)throw new Error("No available runtime provider serves the bash layer.");return{bash:n.id,container:t("container")?.id??null}}a(Zne,"resolveEdgeRuntimeSelection");function nM(e){let t=Kne(e),{bash:n,container:r}=Zne(t);return t.find(i=>i.id===(r??n)).shell}a(nM,"resolveEdgeRuntimeShell");function SVt(){return"dsh-edge@0.20.0/direct"}a(SVt,"resolveEdgeDeploymentId");function ZI(e){return{baseURL:EZ(e.DEEPSEEK_BASE_URL),maxTokens:IZ(e.DEEPSEEK_MAX_OUTPUT_TOKENS),model:p1(e.DEEPSEEK_MODEL),reasoningEffort:_Z(e.DEEPSEEK_REASONING_EFFORT),searchBaseURL:p3(e.DEEPSEEK_SEARCH_BASE_URL),streamIdleTimeoutMs:TZ(e.DEEPSEEK_STREAM_IDLE_TIMEOUT_MS),commandTimeoutPolicy:Sy(e.DSH_EDGE_DEFAULT_COMMAND_TIMEOUT_MS,e.DSH_EDGE_MAX_COMMAND_TIMEOUT_MS)}}a(ZI,"resolveEdgeDeploymentConfig");function kVt(e){return typeof e.DEEPSEEK_API_KEY=="string"&&e.DEEPSEEK_API_KEY.trim().length>0}a(kVt,"edgeDeploymentApiKeyConfigured");function EVt(e){let t=EZ(e),n=new URL(t);return n.search.length===0&&n.hash.length===0?t:(n.search="",n.hash="",n.href)}a(EVt,"projectedEdgeBaseURL");function Jne(e,t){return{shell:nM(e),storage:"durable-object-sqlite-vfs",attachmentStorage:t??(e.DSH_EDGE_ATTACHMENTS===void 0?"temporary-do":"private-r2"),deploymentId:SVt(),apiKeyConfigured:kVt(e),baseURL:EVt(e.DEEPSEEK_BASE_URL),maxTokens:IZ(e.DEEPSEEK_MAX_OUTPUT_TOKENS),model:p1(e.DEEPSEEK_MODEL),reasoningEffort:_Z(e.DEEPSEEK_REASONING_EFFORT),searchBaseURL:p3(e.DEEPSEEK_SEARCH_BASE_URL),streamIdleTimeoutMs:TZ(e.DEEPSEEK_STREAM_IDLE_TIMEOUT_MS),commandTimeoutPolicy:Sy(e.DSH_EDGE_DEFAULT_COMMAND_TIMEOUT_MS,e.DSH_EDGE_MAX_COMMAND_TIMEOUT_MS)}}a(Jne,"resolveEdgeDeploymentProfile");function rM(e){ZI(e);let t=Jne(e);return{ok:!0,service:"dsh-edge",storage:t.storage,attachmentStorage:t.attachmentStorage,shell:t.shell,agent:"upstream-react-loop-agent",access:"single-owner-cookie",deploymentId:t.deploymentId,...e.CF_VERSION_METADATA===void 0?{}:{workerVersionId:e.CF_VERSION_METADATA.id},version:o1,upstreamVersion:TSe,status:"ready"}}a(rM,"resolveEdgeDeploymentHealth");import{AsyncLocalStorage as qun}from"node:async_hooks";import{RpcTarget as _Vt}from"cloudflare:workers";function TVt(e){let{intervalMs:t,ping:n,onFailure:r}=e,i=!1,s=setInterval(()=>{i||n().catch(o=>{i||(i=!0,clearInterval(s),r(o instanceof Error?o:new Error(String(o))))})},t);return()=>{i||(i=!0,clearInterval(s))}}a(TVt,"startHeartbeat");async function IVt(e,t){let n=AbortSignal.timeout(t.timeoutMs),r=await e.fetchPort(t.port,`http://container${t.path}`,{method:"HEAD",signal:n});if(r.body?.cancel(),!r.ok)throw new Error(`computerd health returned ${r.status}`)}a(IVt,"probeComputerdHealth");var AVt="computer.internal",CVt="/health",Yne="/api",RVt=8080,$Vt=3e4,OVt=2e4,NVt=1,PVt=2e3,DVt=250,MVt=2e3;function LVt(e,t){if(t===void 0||e===null)return!1;let n=e.indexOf(" ");if(n===-1||e.slice(0,n).toLowerCase()!=="bearer")return!1;let r=e.slice(n+1).trim();if(r.length!==t.length)return!1;let i=0;for(let s=0;s<t.length;s+=1)i|=r.charCodeAt(s)^t.charCodeAt(s);return i===0}a(LVt,"bearerMatches");var sM=class{static{a(this,"CloudflareContainerBackend")}type="cloudflare-container";id;#e;#t;#r;#n;#i;#s;#a;#c;constructor(e){this.id=e.id??"container-shell",this.#t=e.egress??{mode:"none"},this.#r=this.#t.mode==="http-gateway"?crypto.randomUUID():void 0,this.#e={container:e.container,workspace:e.workspace,containerEnv:e.containerEnv,egressHost:e.egressHost??AVt,containerPort:e.containerPort??RVt,connectTimeoutMs:e.connectTimeoutMs??$Vt,heartbeatIntervalMs:e.heartbeatIntervalMs??OVt,restartAttempts:e.restartAttempts??NVt,healthProbeTimeoutMs:e.healthProbeTimeoutMs??PVt,healthRetryInitialDelayMs:e.healthRetryInitialDelayMs??DVt,healthRetryMaxDelayMs:e.healthRetryMaxDelayMs??MVt}}async connect(){if(this.#c)return this.#c;let e=Date.now()+this.#e.connectTimeoutMs,t=await(await this.#e.container()).getWorkspaceContainer(),n=await t.exitInfo().catch(()=>null),r={PORT:String(this.#e.containerPort),MOUNT_POINT:"/workspace",...this.#e.containerEnv},i,s;try{({runtimeId:i,clientSecret:s}=await t.start({env:r,enableInternet:this.#t.mode==="direct"}))}catch(p){throw new wc(this.#d("start",{attempt:1,maxAttempts:this.#e.restartAttempts+1,restarts:0,lastError:p,priorExit:n}),{cause:p})}try{await t.interceptOutboundHttp(this.#e.egressHost,this.#e.workspace),this.#t.mode==="http-gateway"&&this.#r!==void 0&&await t.interceptAllOutboundHttp(this.#e.workspace,this.#r)}catch(p){throw new wc(this.#d("egress",{attempt:1,maxAttempts:this.#e.restartAttempts+1,restarts:0,lastError:p,priorExit:n}),{cause:p})}this.#n=s,this.#u(),i=await this.#p(t,r,e,n,i),await this.#f(t,e),await this.#v(t,e,s);let o=await this.#h(e),c=N8(o),l,u=new Promise(p=>{let f=!1,h=a(()=>{f||(f=!0,l?.(),p(),this.#c=void 0)},"onClose");o.addEventListener("close",h,{once:!0}),o.addEventListener("error",h,{once:!0}),c.onRpcBroken(h)});this.#e.heartbeatIntervalMs>0&&(l=TVt({intervalMs:this.#e.heartbeatIntervalMs,ping:a(()=>c.sync.watermarks(),"ping"),onFailure:a(()=>{try{o.close()}catch{}},"onFailure")}));let d={rpc:c,runtimeId:i,closed:u,close:a(async()=>{l?.();try{c[Symbol.dispose]?.()}catch{}try{o.close()}catch{}this.#c=void 0},"close")};return this.#c=d,d}async handleFetch(e){if(this.#t.mode==="http-gateway"&&this.#r!==void 0&&e.headers.get("x-workspace-egress-token")===this.#r){let i=new Headers(e.headers),s=i.get(KS),o;try{o=new URL(s??"")}catch{return new Response("invalid egress URL",{status:400})}if(o.protocol!=="http:"&&o.protocol!=="https:")return new Response("invalid egress URL",{status:400});i.delete(uC),i.delete(KS);let c=new Request(e,{headers:i});return this.#t.gateway.fetch(new Request(o,c))}if(new URL(e.url).pathname!==Yne)return new Response("not found",{status:404});if(e.headers.get("upgrade")!=="websocket")return new Response(`${Yne} requires a websocket upgrade`,{status:400});if(!LVt(e.headers.get("authorization"),this.#n))return new Response("unauthorized",{status:401,headers:{"www-authenticate":"Bearer"}});let t=new WebSocketPair,[n,r]=[t[0],t[1]];if(r.accept(),this.#s)this.#s(r);else return r.close(1011,"no pending connect"),new Response("no pending connect",{status:409});return new Response(null,{status:101,webSocket:n})}#u(){this.#i=new Promise((e,t)=>{this.#s=e,this.#a=t}),this.#i.catch(()=>{})}#o(){this.#i=void 0,this.#s=void 0,this.#a=void 0}async#p(e,t,n,r,i){let s=this.#e.restartAttempts+1,o=Math.max(0,n-Date.now()),c=Math.max(250,Math.floor(o/s)),l=0,u=0,d,p=i;for(;l<s;){l++;let f=Math.min(n,Date.now()+c);if(await this.#m(e,f).then(()=>!0,h=>(d=h,!1)))return p;if(l<s)try{({runtimeId:p}=await e.restart({env:t,enableInternet:this.#t.mode==="direct"})),u++}catch(h){throw this.#a?.(h),this.#o(),new wc(this.#d("restart",{attempt:l,maxAttempts:s,restarts:u,lastError:h}),{cause:h})}}throw this.#a?.(new Error("computerd never became healthy")),this.#o(),new wc(this.#d("health",{attempt:l,maxAttempts:s,restarts:u,lastError:d,priorExit:r}),d instanceof Error?{cause:d}:void 0)}async#m(e,t){let n=this.#e.healthRetryInitialDelayMs,r;for(;Date.now()<t;)try{await IVt(e,{port:this.#e.containerPort,path:"/health",timeoutMs:Math.min(this.#e.healthProbeTimeoutMs,Math.max(50,t-Date.now()))});return}catch(i){r=i;let s=t-Date.now();if(s<=0)break;await jVt(Math.min(n,s)),n=Math.min(n*2,this.#e.healthRetryMaxDelayMs)}throw r??new Error("computerd health probe timed out")}#d(e,t){let n=t.priorExit?` priorExit=${JSON.stringify(t.priorExit.reason)}`:"";return`CloudflareContainerBackend(${this.id}): connect failed at stage=${e} port=${this.#e.containerPort} attempt=${t.attempt}/${t.maxAttempts} restarts=${t.restarts} timeoutMs=${this.#e.connectTimeoutMs}${n} lastError=${wMe(t.lastError)}`}async#f(e,t){let n;try{let r=await e.fetchPort(this.#e.containerPort,"http://container/api",{signal:AbortSignal.timeout(Math.min(this.#e.healthProbeTimeoutMs,Math.max(50,t-Date.now())))});n=r.status,await r.text().catch(()=>"")}catch{return}if(n!==401)throw this.#a?.(new Error("container is not enforcing RPC_CLIENT_SECRET")),this.#o(),new wc(`CloudflareContainerBackend(${this.id}) [stage=auth]: container served an unauthenticated request to /api with ${n}, so this workspace would run without authorization. A container or image predating RPC_CLIENT_SECRET has to be recycled.`)}async#v(e,t,n){let r=Math.max(0,t-Date.now()),i;try{i=await e.fetchPort(this.#e.containerPort,"http://container/connect",{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${n}`},body:JSON.stringify({base:`http://${this.#e.egressHost}`,health:CVt,api:Yne,healthTimeoutMs:r})})}catch(s){throw this.#a?.(s),this.#o(),new wc(`CloudflareContainerBackend(${this.id}) [stage=connect]: POST /connect failed: ${wMe(s)}`,{cause:s})}if(!i.ok){let s=await i.text().catch(()=>""),o=new Error(`/connect ${i.status}`);throw this.#a?.(o),this.#o(),new wc(`CloudflareContainerBackend(${this.id}) [stage=connect]: POST /connect returned ${i.status}: ${s}`,{cause:o})}}async#h(e){let t=this.#i;if(!t)throw new Error("CloudflareContainerBackend: upgrade promise missing");let n=Math.max(0,e-Date.now()),r;try{return await Promise.race([t,new Promise((i,s)=>{r=setTimeout(()=>s(new wc(`CloudflareContainerBackend(${this.id}) [stage=ws]: /api upgrade did not arrive within ${this.#e.connectTimeoutMs}ms`)),n)})])}finally{r&&clearTimeout(r),this.#o()}}};function jVt(e){return new Promise(t=>setTimeout(t,e))}a(jVt,"sleep");function wMe(e){return e instanceof Error?e.message:String(e)}a(wMe,"describeError");var bMe="computer:container-client-secret",FVt=16;function qVt(){let e=crypto.getRandomValues(new Uint8Array(FVt));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}a(qVt,"generate");var UVt=class{static{a(this,"ContainerClientSecret")}storage;constructor(e){this.storage=e}async ensure(){let e=await this.storage.get(bMe);if(typeof e=="string"&&e.length>0)return e;let t=qVt();return await this.storage.put(bMe,t),t}},xMe="computer:container-launch-record";async function SMe(e){return{enableInternet:e.enableInternet,envDigest:await BVt(e.env)}}a(SMe,"launchRecordFor");function zVt(e,t){return e.enableInternet===t.enableInternet&&e.envDigest===t.envDigest}a(zVt,"sameLaunch");async function BVt(e){let t=Object.keys(e).sort().map(r=>`${r.length}:${r}=${e[r]?.length??0}:${e[r]??""}`).join(";"),n=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return Array.from(new Uint8Array(n),r=>r.toString(16).padStart(2,"0")).join("")}a(BVt,"digestEnv");var WVt=class{static{a(this,"CurrentContainerLaunchRecord")}storage;constructor(e){this.storage=e}async get(){return await this.storage.get(xMe)??null}async set(e){await this.storage.put(xMe,e)}},kMe=new WeakMap;function ere(e){let t=kMe.get(e);return t===void 0&&(t={exit:null,currentGeneration:0,expectedExitGeneration:null,currentMonitorSettled:null},kMe.set(e,t)),t}a(ere,"getContainerLifecycle");function iM(e){return ere(e).exit}a(iM,"containerExitInfo");function EMe(e){return e===void 0?"exited normally":e instanceof Error?e.message:String(e)}a(EMe,"formatExitReason");function _Me(e,t,n){let r=ere(e);r.currentGeneration+=1;let i=r.currentGeneration;r.exit=null,r.currentMonitorSettled=t.monitor().then(()=>TMe(r,i,void 0,n),s=>TMe(r,i,s,n))}a(_Me,"installContainerMonitor");async function Xne(e,t){let n=ere(e);n.expectedExitGeneration=n.currentGeneration;let r=n.currentMonitorSettled;await t.destroy(),r&&await r}a(Xne,"destroyContainerExpectingExit");async function TMe(e,t,n,r){if(t!==e.currentGeneration)return;let i=e.expectedExitGeneration===t;i&&(e.expectedExitGeneration=null);let s=EMe(n),o=Date.now();e.exit={reason:s,exitedAt:o},i?console.info({message:"workspace.container.exited",reason:s,exitedAt:o,expected:!0}):console.warn({message:"workspace.container.exited",reason:s,exitedAt:o,expected:!1});try{await r?.()}catch(c){console.error({message:"workspace.container.exit_cleanup_failed",reason:EMe(c),exitedAt:Date.now()})}}a(TMe,"recordExit");var Qne="computer:container-runtime-identity",HVt=class{static{a(this,"CurrentContainerRuntimeIdentity")}storage;constructor(e){this.storage=e}async get(){return await this.storage.get(Qne)??null}async markStarted(){let e={id:crypto.randomUUID()};return await this.storage.put(Qne,e),e}async clear(e){(await this.get())?.id===e.id&&await this.storage.delete(Qne)}},VVt=class extends _Vt{static{a(this,"WorkspaceContainerAPI")}#e;#t;#r;#n;#i;constructor(e){if(super(),!e.container)throw new Error("WorkspaceContainerAPI: DO is not container-enabled (check wrangler.jsonc)");this.#e=e.container,this.#t=e,this.#r=new HVt(e.storage),this.#n=new UVt(e.storage),this.#i=new WVt(e.storage)}async start(e){let t=iM(this.#t),n=await this.#n.ensure(),r=await SMe(e);if(t!==null){try{await Xne(this.#t,this.#e)}catch{}return this.#s(e,n,r,"launched")}if(!this.#e.running)return this.#s(e,n,r,"launched");let i=await this.#i.get();if(i===null||!zVt(i,r)){console.warn({message:i===null?"container was started outside WorkspaceContainerAPI; relaunching so the requested environment applies":"running container was launched with a different spec; relaunching",component:"workspace-container",requested:r,actual:i});try{await Xne(this.#t,this.#e)}catch{}return this.#s(e,n,r,"relaunched")}let s=await this.#r.get()??await this.#r.markStarted();return _Me(this.#t,this.#e,()=>this.#r.clear(s)),{runtimeId:s.id,clientSecret:n,outcome:"adopted"}}async restart(e){try{await Xne(this.#t,this.#e)}catch{}let t=await this.#n.ensure();return this.#s(e,t,await SMe(e),"launched")}async setInactivityTimeout(e){await this.#e.setInactivityTimeout(e)}async#s(e,t,n,r){let i=await this.#r.markStarted();try{this.#e.start({enableInternet:e.enableInternet,env:{...e.env,RPC_CLIENT_SECRET:t}})}catch(s){throw await this.#r.clear(i),s}return await this.#i.set(n),_Me(this.#t,this.#e,()=>this.#r.clear(i)),{runtimeId:i.id,clientSecret:t,outcome:r}}async status(){return{running:this.#e.running,exit:iM(this.#t)}}async exitInfo(){return iM(this.#t)}async interceptAllOutboundHttp(e,t){let n=this.#t.exports.WorkspaceProxy({props:{...e,egressToken:t}});await Promise.all([this.#e.interceptAllOutboundHttp(n),this.#e.interceptOutboundHttps("*",n)])}async interceptOutboundHttp(e,t){let n=this.#t.exports;await this.#e.interceptOutboundHttp(e,n.WorkspaceProxy({props:t}))}fetchPort(e,t,n){let r=iM(this.#t);if(r!==null)throw new wc(`container exited: ${r.reason}`);return this.#e.getTcpPort(e).fetch(t,n)}port(e){return this.#e.getTcpPort(e)}};function IMe(e){class t extends e{static{a(this,"WithWorkspaceContainer")}getWorkspaceContainer(){return new VVt(this.ctx)}}return t}a(IMe,"withWorkspaceContainer");var GVt={session:"sessions",skill:"skills",agentPreset:"agentPresets",subagent:"subagents",goal:"goals",event:"events",download:"downloads"};function CMe(e,t){let n=t.indexOf("."),r=t.indexOf("/"),i=n>=0?n:r;if(i<0)return;let s=t.slice(0,i),o=t.slice(i+1),c=GVt[s]??s,l=e[c];if(l===void 0)return;let u=l[o];return typeof u=="function"?u:void 0}a(CMe,"resolve");function KVt(e,t){return Response.json({type:"server-response",rpcId:e,result:{ok:!1,error:t}})}a(KVt,"errorResponse");async function tre(e,t,n,r,i){let s=CMe(e,t);if(s!==void 0)return await s({rpcId:n,payload:r},i)}a(tre,"callEdgeApi");async function RMe(e,t){let r=new URL(t.url).pathname;if(t.method!=="POST"||!r.startsWith("/api/"))return new Response("not found",{status:404});if(r==="/api/respond")return Response.json({accepted:!1,reason:"not-pending"});let i=r.slice(5);if(CMe(e,i)===void 0)return new Response("not found",{status:404});let s;try{s=await t.json()}catch{return new Response("body is not JSON",{status:400})}let o=typeof s.rpcId=="string"?s.rpcId:"invalid-request",c=s.payload??{};try{let l=await tre(e,i,o,c,t.signal);return l===void 0?new Response("not found",{status:404}):Response.json({type:"server-response",rpcId:l.rpcId,result:l.result})}catch(l){return KVt(o,{code:"internal",message:String(l),details:{}})}}a(RMe,"dispatchEdgeApi");kr();Ps();Eg();import{DurableObject as Uun}from"cloudflare:workers";var oM=class{constructor(t,n=Date.now,r=2){this.sleepAfterMs=t;this.now=n;this.maxConcurrent=r}sleepAfterMs;now;maxConcurrent;static{a(this,"ContainerActivity")}inFlight=0;lastActivity;stopping;waiters=[];async admit(t){let n=this.now();for(;this.stopping!==void 0||this.inFlight>=this.maxConcurrent;){if(t?.throwIfAborted(),this.stopping!==void 0){await ZVt(this.stopping,t);continue}await new Promise((r,i)=>{let s=a(()=>{t?.removeEventListener("abort",o),r()},"wake"),o=a(()=>{let c=this.waiters.indexOf(s);c!==-1&&this.waiters.splice(c,1),i(t.reason)},"abort");this.waiters.push(s),t?.addEventListener("abort",o,{once:!0})})}return t?.aborted===!0&&(this.waiters.shift()?.(),t.throwIfAborted()),{release:this.begin(),queuedMs:this.now()-n}}begin(){this.inFlight+=1,this.lastActivity=this.now();let t=!1;return()=>{t||(t=!0,this.inFlight-=1,this.lastActivity=this.now(),this.waiters.shift()?.())}}async stopIfIdle(t){return this.idle()?await this.stop(t):"busy"}async stopNow(t){return this.inFlight===0?await this.stop(t):"busy"}snapshot(){return{runningCommands:this.inFlight,lastActivityAt:this.lastActivity??null}}async stop(t){if(this.stopping!==void 0)return"busy";let n="stopped",r=t().catch(i=>{n="failed",this.lastActivity=this.now(),console.error("dsh-edge container stop failed.",i)});this.stopping=r;try{await r}finally{this.stopping=void 0}return n}deadline(){return this.inFlight>0?this.now()+this.sleepAfterMs():this.lastActivity===void 0?this.now():this.lastActivity+this.sleepAfterMs()}idle(){return this.inFlight===0&&(this.lastActivity===void 0||this.now()>=this.lastActivity+this.sleepAfterMs())}};function ZVt(e,t){return t===void 0?e:new Promise((n,r)=>{let i=a(()=>r(t.reason),"abort");t.addEventListener("abort",i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener("abort",i))})}a(ZVt,"untilAborted");import{WorkerEntrypoint as LQn}from"cloudflare:workers";var Iv=tl($Me());var nre=a((e,t,n)=>{let r=e instanceof RegExp?OMe(e,n):e,i=t instanceof RegExp?OMe(t,n):t,s=r!==null&&i!=null&&JVt(r,i,n);return s&&{start:s[0],end:s[1],pre:n.slice(0,s[0]),body:n.slice(s[0]+r.length,s[1]),post:n.slice(s[1]+i.length)}},"balanced"),OMe=a((e,t)=>{let n=t.match(e);return n?n[0]:null},"maybeMatch"),JVt=a((e,t,n)=>{let r,i,s,o,c,l=n.indexOf(e),u=n.indexOf(t,l+1),d=l;if(l>=0&&u>0){if(e===t)return[l,u];for(r=[],s=n.length;d>=0&&!c;){if(d===l)r.push(d),l=n.indexOf(e,d+1);else if(r.length===1){let p=r.pop();p!==void 0&&(c=[p,u])}else i=r.pop(),i!==void 0&&i<s&&(s=i,o=u),u=n.indexOf(t,d+1);d=l<u&&l>=0?l:u}r.length&&o!==void 0&&(c=[s,o])}return c},"range");var NMe="\0SLASH"+Math.random()+"\0",PMe="\0OPEN"+Math.random()+"\0",sre="\0CLOSE"+Math.random()+"\0",DMe="\0COMMA"+Math.random()+"\0",MMe="\0PERIOD"+Math.random()+"\0",YVt=new RegExp(NMe,"g"),XVt=new RegExp(PMe,"g"),QVt=new RegExp(sre,"g"),eGt=new RegExp(DMe,"g"),tGt=new RegExp(MMe,"g"),nGt=/\\\\/g,rGt=/\\{/g,iGt=/\\}/g,sGt=/\\,/g,oGt=/\\\./g,aGt=1e5,cGt=4e6;function rre(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}a(rre,"numeric");function lGt(e){return e.replace(nGt,NMe).replace(rGt,PMe).replace(iGt,sre).replace(sGt,DMe).replace(oGt,MMe)}a(lGt,"escapeBraces");function uGt(e){return e.replace(YVt,"\\").replace(XVt,"{").replace(QVt,"}").replace(eGt,",").replace(tGt,".")}a(uGt,"unescapeBraces");function LMe(e){if(!e)return[""];let t=[],n=nre("{","}",e);if(!n)return e.split(",");let{pre:r,body:i,post:s}=n,o=r.split(",");o[o.length-1]+="{"+i+"}";let c=LMe(s);return s.length&&(o[o.length-1]+=c.shift(),o.push.apply(o,c)),t.push.apply(t,o),t}a(LMe,"parseCommaParts");function jMe(e,t={}){if(!e)return[];let{max:n=aGt,maxLength:r=cGt}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),ire(lGt(e),n,r,!0).map(uGt)}a(jMe,"expand");function dGt(e){return"{"+e+"}"}a(dGt,"embrace");function pGt(e){return/^-?0\d/.test(e)}a(pGt,"isPadded");function fGt(e,t){return e<=t}a(fGt,"lte");function hGt(e,t){return e>=t}a(hGt,"gte");function JI(e,t,n,r,i,s){let o=[],c=0;for(let l=0;l<e.length;l++)for(let u=0;u<n.length;u++){if(o.length>=r)return o;let d=e[l]+t+n[u];if(!(s&&!d)){if(c+d.length>i)return o;o.push(d),c+=d.length}}return o}a(JI,"combine");function mGt(e,t,n,r){let i=e.split(/\.\./),s=[];if(i[0]===void 0||i[1]===void 0)return s;let o=rre(i[0]),c=rre(i[1]),l=Math.max(i[0].length,i[1].length),u=i.length===3&&i[2]!==void 0?Math.max(Math.abs(rre(i[2])),1):1,d=fGt;c<o&&(u*=-1,d=hGt);let f=i.some(pGt),h=0;for(let g=o;d(g,c)&&s.length<n;g+=u){let y;if(t)y=String.fromCharCode(g),y==="\\"&&(y="");else if(y=String(g),f){let v=l-y.length;if(v>0){let w=new Array(v+1).join("0");g<0?y="-"+w+y.slice(1):y=w+y}}if(h+y.length>r)break;s.push(y),h+=y.length}return s}a(mGt,"expandSequence");function ire(e,t,n,r){let i=[""],s=!1,o=!0;for(;;){let c=nre("{","}",e);if(!c)return JI(i,e,[""],t,n,s);let l=c.pre;if(/\$$/.test(l)){if(i=JI(i,l+"{"+c.body+"}",[""],t,n,s&&!c.post.length),o=!1,!c.post.length)break;e=c.post;continue}let u=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(c.body),d=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(c.body),p=u||d,f=c.body.indexOf(",")>=0;if(!p&&!f){if(c.post.match(/,(?!,).*\}/)){e=c.pre+"{"+c.body+sre+c.post,r=!0;continue}return JI(i,l+"{"+c.body+"}"+c.post,[""],t,n,s)}o&&(s=r&&!p,o=!1);let h;if(p)h=mGt(c.body,d,t,n);else{let g=LMe(c.body);if(g.length===1&&g[0]!==void 0&&(g=ire(g[0],t,n,!1).map(dGt),g.length===1)){if(i=JI(i,l+g[0],[""],t,n,s&&!c.post.length),!c.post.length)break;e=c.post;continue}let y=s&&!c.post.length&&!l;for(let w=0;y&&w<i.length;w++)i[w]&&(y=!1);h=[];let v=0;e:for(let w=0;w<g.length;w++){let b=ire(g[w],t,n,!1);for(let S=0;S<b.length;S++){let k=b[S];if(!(y&&!k)){if(h.length>=t||v+k.length>n)break e;h.push(k),v+=k.length}}}}if(i=JI(i,l,h,t,n,s&&!c.post.length),!c.post.length)break;e=c.post}return i}a(ire,"expand_");var YI=a(e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")},"assertValidPattern");var gGt={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},XI=a(e=>e.replace(/[[\]\\-]/g,"\\$&"),"braceEscape"),yGt=a(e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"regexpEscape"),FMe=a(e=>e.join(""),"rangesToString"),qMe=a((e,t)=>{let n=t;if(e.charAt(n)!=="[")throw new Error("not in a brace expression");let r=[],i=[],s=n+1,o=!1,c=!1,l=!1,u=!1,d=n,p="";e:for(;s<e.length;){let y=e.charAt(s);if((y==="!"||y==="^")&&s===n+1){u=!0,s++;continue}if(y==="]"&&o&&!l){d=s+1;break}if(o=!0,y==="\\"&&!l){l=!0,s++;continue}if(y==="["&&!l){for(let[v,[w,b,S]]of Object.entries(gGt))if(e.startsWith(v,s)){if(p)return["$.",!1,e.length-n,!0];s+=v.length,S?i.push(w):r.push(w),c=c||b;continue e}}if(l=!1,p){y>p?r.push(XI(p)+"-"+XI(y)):y===p&&r.push(XI(y)),p="",s++;continue}if(e.startsWith("-]",s+1)){r.push(XI(y+"-")),s+=2;continue}if(e.startsWith("-",s+1)){p=y,s+=2;continue}r.push(XI(y)),s++}if(d<s)return["",!1,0,!1];if(!r.length&&!i.length)return["$.",!1,e.length-n,!0];if(i.length===0&&r.length===1&&/^\\?.$/.test(r[0])&&!u){let y=r[0].length===2?r[0].slice(-1):r[0];return[yGt(y),!1,d-n,!1]}let f="["+(u?"^":"")+FMe(r)+"]",h="["+(u?"":"^")+FMe(i)+"]";return[r.length&&i.length?"("+f+"|"+h+")":r.length?f:h,c,d-n,!0]},"parseClass");var _y=a((e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?t?e.replace(/\[([^/\\])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\])\]/g,"$1$2").replace(/\\([^/])/g,"$1"):t?e.replace(/\[([^/\\{}])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,"$1$2").replace(/\\([^/{}])/g,"$1"),"unescape");var Nl,vGt=new Set(["!","?","+","*","@"]),ore=a(e=>vGt.has(e),"isExtglobType"),UMe=a(e=>ore(e.type),"isExtglobAST"),wGt=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),bGt=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),xGt=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),zMe=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),SGt="(?!(?:^|/)\\.\\.?(?:$|/))",cM="(?!\\.)",kGt=new Set(["[","."]),EGt=new Set(["..","."]),_Gt=new Set("().*{}+?[]^$\\!"),TGt=a(e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"regExpEscape"),are="[^/]",BMe=are+"*?",WMe=are+"+?",IGt=0,J1=class{static{a(this,"AST")}type;#e;#t;#r=!1;#n=[];#i;#s;#a;#c=!1;#u;#o;#p=!1;id=++IGt;get depth(){return(this.#i?.depth??-1)+1}[Symbol.for("nodejs.util.inspect.custom")](){return{"@@type":"AST",id:this.id,type:this.type,root:this.#e.id,parent:this.#i?.id,depth:this.depth,partsLength:this.#n.length,parts:this.#n}}constructor(t,n,r={}){this.type=t,t&&(this.#t=!0),this.#i=n,this.#e=this.#i?this.#i.#e:this,this.#u=this.#e===this?r:this.#e.#u,this.#a=this.#e===this?[]:this.#e.#a,t==="!"&&!this.#e.#c&&this.#a.push(this),this.#s=this.#i?this.#i.#n.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let t of this.#n)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#o!==void 0?this.#o:this.type?this.#o=this.type+"("+this.#n.map(t=>String(t)).join("|")+")":this.#o=this.#n.map(t=>String(t)).join("")}#m(){if(this!==this.#e)throw new Error("should only call on root");if(this.#c)return this;this.toString(),this.#c=!0;let t;for(;t=this.#a.pop();){if(t.type!=="!")continue;let n=t,r=n.#i;for(;r;){for(let i=n.#s+1;!r.type&&i<r.#n.length;i++)for(let s of t.#n){if(typeof s=="string")throw new Error("string part in extglob AST??");s.copyIn(r.#n[i])}n=r,r=n.#i}}return this}push(...t){for(let n of t)if(n!==""){if(typeof n!="string"&&!(n instanceof Nl&&n.#i===this))throw new Error("invalid part: "+n);this.#n.push(n)}}toJSON(){let t=this.type===null?this.#n.slice().map(n=>typeof n=="string"?n:n.toJSON()):[this.type,...this.#n.map(n=>n.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#c&&this.#i?.type==="!")&&t.push({}),t}isStart(){if(this.#e===this)return!0;if(!this.#i?.isStart())return!1;if(this.#s===0)return!0;let t=this.#i;for(let n=0;n<this.#s;n++){let r=t.#n[n];if(!(r instanceof Nl&&r.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#i?.type==="!")return!0;if(!this.#i?.isEnd())return!1;if(!this.type)return this.#i?.isEnd();let t=this.#i?this.#i.#n.length:0;return this.#s===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let n=new Nl(this.type,t);for(let r of this.#n)n.copyIn(r);return n}static#d(t,n,r,i,s){let o=i.maxExtglobRecursion??2,c=!1,l=!1,u=-1,d=!1;if(n.type===null){let y=r,v="";for(;y<t.length;){let w=t.charAt(y++);if(c||w==="\\"){c=!c,v+=w;continue}if(l){y===u+1?(w==="^"||w==="!")&&(d=!0):w==="]"&&!(y===u+2&&d)&&(l=!1),v+=w;continue}else if(w==="["){l=!0,u=y,d=!1,v+=w;continue}if(!i.noext&&ore(w)&&t.charAt(y)==="("&&s<=o){n.push(v),v="";let S=new Nl(w,n);y=Nl.#d(t,S,y,i,s+1),n.push(S);continue}v+=w}return n.push(v),y}let p=r+1,f=new Nl(null,n),h=[],g="";for(;p<t.length;){let y=t.charAt(p++);if(c||y==="\\"){c=!c,g+=y;continue}if(l){p===u+1?(y==="^"||y==="!")&&(d=!0):y==="]"&&!(p===u+2&&d)&&(l=!1),g+=y;continue}else if(y==="["){l=!0,u=p,d=!1,g+=y;continue}if(!i.noext&&ore(y)&&t.charAt(p)==="("&&(s<=o||n&&n.#h(y))){let w=n&&n.#h(y)?0:1;f.push(g),g="";let b=new Nl(y,f);f.push(b),p=Nl.#d(t,b,p,i,s+w);continue}if(y==="|"){f.push(g),g="",h.push(f),f=new Nl(null,n);continue}if(y===")")return g===""&&n.#n.length===0&&(n.#p=!0),f.push(g),g="",n.push(...h,f),p;g+=y}return n.type=null,n.#t=void 0,n.#n=[t.substring(r-1)],p}#f(t){return this.#v(t,bGt)}#v(t,n=wGt){if(!t||typeof t!="object"||t.type!==null||t.#n.length!==1||this.type===null)return!1;let r=t.#n[0];return!r||typeof r!="object"||r.type===null?!1:this.#h(r.type,n)}#h(t,n=xGt){return!!n.get(this.type)?.includes(t)}#O(t,n){let r=t.#n[0],i=new Nl(null,r,this.options);i.#n.push(""),r.push(i),this.#w(t,n)}#w(t,n){let r=t.#n[0];this.#n.splice(n,1,...r.#n);for(let i of r.#n)typeof i=="object"&&(i.#i=this);this.#o=void 0}#E(t){return!!zMe.get(this.type)?.has(t)}#_(t){if(!t||typeof t!="object"||t.type!==null||t.#n.length!==1||this.type===null||this.#n.length!==1)return!1;let n=t.#n[0];return!n||typeof n!="object"||n.type===null?!1:this.#E(n.type)}#T(t){let n=zMe.get(this.type),r=t.#n[0],i=n?.get(r.type);if(!i)return!1;this.#n=r.#n;for(let s of this.#n)typeof s=="object"&&(s.#i=this);this.type=i,this.#o=void 0,this.#p=!1}static fromGlob(t,n={}){let r=new Nl(null,void 0,n);return Nl.#d(t,r,0,n,0),r}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let t=this.toString(),[n,r,i,s]=this.toRegExpSource();if(!(i||this.#t||this.#u.nocase&&!this.#u.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return r;let c=(this.#u.nocase?"i":"")+(s?"u":"");return Object.assign(new RegExp(`^${n}$`,c),{_src:n,_glob:t})}get options(){return this.#u}toRegExpSource(t){let n=t??!!this.#u.dot;if(this.#e===this&&(this.#l(),this.#m()),!UMe(this)){let l=this.isStart()&&this.isEnd()&&!this.#n.some(h=>typeof h!="string"),u=this.#n.map(h=>{let[g,y,v,w]=typeof h=="string"?Nl.#b(h,this.#t,l):h.toRegExpSource(t);return this.#t=this.#t||v,this.#r=this.#r||w,g}).join(""),d="";if(this.isStart()&&typeof this.#n[0]=="string"&&!(this.#n.length===1&&EGt.has(this.#n[0]))){let g=kGt,y=n&&g.has(u.charAt(0))||u.startsWith("\\.")&&g.has(u.charAt(2))||u.startsWith("\\.\\.")&&g.has(u.charAt(4)),v=!n&&!t&&g.has(u.charAt(0));d=y?SGt:v?cM:""}let p="";return this.isEnd()&&this.#e.#c&&this.#i?.type==="!"&&(p="(?:$|\\/)"),[d+u+p,_y(u),this.#t=!!this.#t,this.#r]}let r=this.type==="*"||this.type==="+",i=this.type==="!"?"(?:(?!(?:":"(?:",s=this.#g(n);if(this.isStart()&&this.isEnd()&&!s&&this.type!=="!"){let l=this.toString(),u=this;return u.#n=[l],u.type=null,u.#t=void 0,[l,_y(this.toString()),!1,!1]}let o=!r||t||n||!cM?"":this.#g(!0);o===s&&(o=""),o&&(s=`(?:${s})(?:${o})*?`);let c="";if(this.type==="!"&&this.#p)c=(this.isStart()&&!n?cM:"")+WMe;else{let l=this.type==="!"?"))"+(this.isStart()&&!n&&!t?cM:"")+BMe+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;c=i+s+l}return[c,_y(s),this.#t=!!this.#t,this.#r]}#l(){if(UMe(this)){let t=0,n=!1;do{n=!0;for(let r=0;r<this.#n.length;r++){let i=this.#n[r];typeof i=="object"&&(i.#l(),this.#v(i)?(n=!1,this.#w(i,r)):this.#f(i)?(n=!1,this.#O(i,r)):this.#_(i)&&(n=!1,this.#T(i)))}}while(!n&&++t<10)}else for(let t of this.#n)typeof t=="object"&&t.#l();this.#o=void 0}#g(t){return this.#n.map(n=>{if(typeof n=="string")throw new Error("string type in extglob ast??");let[r,i,s,o]=n.toRegExpSource(t);return this.#r=this.#r||o,r}).filter(n=>!(this.isStart()&&this.isEnd())||!!n).join("|")}static#b(t,n,r=!1){let i=!1,s="",o=!1,c=!1;for(let l=0;l<t.length;l++){let u=t.charAt(l);if(i){i=!1,s+=(_Gt.has(u)?"\\":"")+u;continue}if(u==="*"){if(c)continue;c=!0,s+=r&&/^[*]+$/.test(t)?WMe:BMe,n=!0;continue}else c=!1;if(u==="\\"){l===t.length-1?s+="\\\\":i=!0;continue}if(u==="["){let[d,p,f,h]=qMe(t,l);if(f){s+=d,o=o||p,l+=f-1,n=n||h;continue}}if(u==="?"){s+=are,n=!0;continue}s+=TGt(u)}return[s,_y(t),!!n,o]}};Nl=J1;var cre=a((e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&"),"escape");var fa=a((e,t,n={})=>(YI(t),!n.nocomment&&t.charAt(0)==="#"?!1:new Jx(t,n).match(e)),"minimatch"),AGt=/^\*+([^+@!?*[(]*)$/,CGt=a(e=>t=>!t.startsWith(".")&&t.endsWith(e),"starDotExtTest"),RGt=a(e=>t=>t.endsWith(e),"starDotExtTestDot"),$Gt=a(e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),"starDotExtTestNocase"),OGt=a(e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),"starDotExtTestNocaseDot"),NGt=/^\*+\.\*+$/,PGt=a(e=>!e.startsWith(".")&&e.includes("."),"starDotStarTest"),DGt=a(e=>e!=="."&&e!==".."&&e.includes("."),"starDotStarTestDot"),MGt=/^\.\*+$/,LGt=a(e=>e!=="."&&e!==".."&&e.startsWith("."),"dotStarTest"),jGt=/^\*+$/,FGt=a(e=>e.length!==0&&!e.startsWith("."),"starTest"),qGt=a(e=>e.length!==0&&e!=="."&&e!=="..","starTestDot"),UGt=/^\?+([^+@!?*[(]*)?$/,zGt=a(([e,t=""])=>{let n=GMe([e]);return t?(t=t.toLowerCase(),r=>n(r)&&r.toLowerCase().endsWith(t)):n},"qmarksTestNocase"),BGt=a(([e,t=""])=>{let n=KMe([e]);return t?(t=t.toLowerCase(),r=>n(r)&&r.toLowerCase().endsWith(t)):n},"qmarksTestNocaseDot"),WGt=a(([e,t=""])=>{let n=KMe([e]);return t?r=>n(r)&&r.endsWith(t):n},"qmarksTestDot"),HGt=a(([e,t=""])=>{let n=GMe([e]);return t?r=>n(r)&&r.endsWith(t):n},"qmarksTest"),GMe=a(([e])=>{let t=e.length;return n=>n.length===t&&!n.startsWith(".")},"qmarksTestNoExt"),KMe=a(([e])=>{let t=e.length;return n=>n.length===t&&n!=="."&&n!==".."},"qmarksTestNoExtDot"),ZMe=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",HMe={win32:{sep:"\\"},posix:{sep:"/"}},VGt=ZMe==="win32"?HMe.win32.sep:HMe.posix.sep;fa.sep=VGt;var hc=Symbol("globstar **");fa.GLOBSTAR=hc;var GGt="[^/]",KGt=GGt+"*?",ZGt="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",JGt="(?:(?!(?:\\/|^)\\.).)*?",YGt=a((e,t={})=>n=>fa(n,e,t),"filter");fa.filter=YGt;var dd=a((e,t={})=>Object.assign({},e,t),"ext"),XGt=a(e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return fa;let t=fa;return Object.assign(a((r,i,s={})=>t(r,i,dd(e,s)),"m"),{Minimatch:class extends t.Minimatch{static{a(this,"Minimatch")}constructor(i,s={}){super(i,dd(e,s))}static defaults(i){return t.defaults(dd(e,i)).Minimatch}},AST:class extends t.AST{static{a(this,"AST")}constructor(i,s,o={}){super(i,s,dd(e,o))}static fromGlob(i,s={}){return t.AST.fromGlob(i,dd(e,s))}},unescape:a((r,i={})=>t.unescape(r,dd(e,i)),"unescape"),escape:a((r,i={})=>t.escape(r,dd(e,i)),"escape"),filter:a((r,i={})=>t.filter(r,dd(e,i)),"filter"),defaults:a(r=>t.defaults(dd(e,r)),"defaults"),makeRe:a((r,i={})=>t.makeRe(r,dd(e,i)),"makeRe"),braceExpand:a((r,i={})=>t.braceExpand(r,dd(e,i)),"braceExpand"),match:a((r,i,s={})=>t.match(r,i,dd(e,s)),"match"),sep:t.sep,GLOBSTAR:hc})},"defaults");fa.defaults=XGt;var JMe=a((e,t={})=>(YI(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:jMe(e,{max:t.braceExpandMax})),"braceExpand");fa.braceExpand=JMe;var QGt=a((e,t={})=>new Jx(e,t).makeRe(),"makeRe");fa.makeRe=QGt;var eKt=a((e,t,n={})=>{let r=new Jx(t,n);return e=e.filter(i=>r.match(i)),r.options.nonull&&!e.length&&e.push(t),e},"match");fa.match=eKt;var VMe=/[?*]|[+@!]\(.*?\)|\[|\]/,tKt=a(e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),"regExpEscape"),Jx=class{static{a(this,"Minimatch")}options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,n={}){YI(t),n=n||{},this.options=n,this.maxGlobstarRecursion=n.maxGlobstarRecursion??200,this.pattern=t,this.platform=n.platform||ZMe,this.isWindows=this.platform==="win32";let r="allowWindowsEscape";this.windowsPathsNoEscape=!!n.windowsPathsNoEscape||n[r]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!n.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!n.nonegate,this.comment=!1,this.empty=!1,this.partial=!!n.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=n.windowsNoMagicRoot!==void 0?n.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let n of t)if(typeof n!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,n=this.options;if(!n.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],n.debug&&(this.debug=(...s)=>console.error(...s)),this.debug(this.pattern,this.globSet);let r=this.globSet.map(s=>this.slashSplit(s));this.globParts=this.preprocess(r),this.debug(this.pattern,this.globParts);let i=this.globParts.map((s,o,c)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=s[0]===""&&s[1]===""&&(s[2]==="?"||!VMe.test(s[2]))&&!VMe.test(s[3]),u=/^[a-z]:/i.test(s[0]);if(l)return[...s.slice(0,4),...s.slice(4).map(d=>this.parse(d))];if(u)return[s[0],...s.slice(1).map(d=>this.parse(d))]}return s.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(s=>s.indexOf(!1)===-1),this.isWindows)for(let s=0;s<this.set.length;s++){let o=this.set[s];o[0]===""&&o[1]===""&&this.globParts[s][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let r of t)for(let i=0;i<r.length;i++)r[i]==="**"&&(r[i]="*");let{optimizationLevel:n=1}=this.options;return n>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):n>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(n=>{let r=-1;for(;(r=n.indexOf("**",r+1))!==-1;){let i=r;for(;n[i+1]==="**";)i++;i!==r&&n.splice(r,i-r)}return n})}levelOneOptimize(t){return t.map(n=>(n=n.reduce((r,i)=>{let s=r[r.length-1];return i==="**"&&s==="**"?r:i===".."&&s&&s!==".."&&s!=="."&&s!=="**"?(r.pop(),r):(r.push(i),r)},[]),n.length===0?[""]:n))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let n=!1;do{if(n=!1,!this.preserveMultipleSlashes){for(let i=1;i<t.length-1;i++){let s=t[i];i===1&&s===""&&t[0]===""||(s==="."||s==="")&&(n=!0,t.splice(i,1),i--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(n=!0,t.pop())}let r=0;for(;(r=t.indexOf("..",r+1))!==-1;){let i=t[r-1];i&&i!=="."&&i!==".."&&i!=="**"&&!(this.isWindows&&/^[a-z]:$/i.test(i))&&(n=!0,t.splice(r-1,2),r-=2)}}while(n);return t.length===0?[""]:t}firstPhasePreProcess(t){let n=!1;do{n=!1;for(let r of t){let i=-1;for(;(i=r.indexOf("**",i+1))!==-1;){let o=i;for(;r[o+1]==="**";)o++;o>i&&r.splice(i+1,o-i);let c=r[i+1],l=r[i+2],u=r[i+3];if(c!==".."||!l||l==="."||l===".."||!u||u==="."||u==="..")continue;n=!0,r.splice(i,1);let d=r.slice(0);d[i]="**",t.push(d),i--}if(!this.preserveMultipleSlashes){for(let o=1;o<r.length-1;o++){let c=r[o];o===1&&c===""&&r[0]===""||(c==="."||c==="")&&(n=!0,r.splice(o,1),o--)}r[0]==="."&&r.length===2&&(r[1]==="."||r[1]==="")&&(n=!0,r.pop())}let s=0;for(;(s=r.indexOf("..",s+1))!==-1;){let o=r[s-1];if(o&&o!=="."&&o!==".."&&o!=="**"){n=!0;let l=s===1&&r[s+1]==="**"?["."]:[];r.splice(s-1,2,...l),r.length===0&&r.push(""),s-=2}}}}while(n);return t}secondPhasePreProcess(t){for(let n=0;n<t.length-1;n++)for(let r=n+1;r<t.length;r++){let i=this.partsMatch(t[n],t[r],!this.preserveMultipleSlashes);if(i){t[n]=[],t[r]=i;break}}return t.filter(n=>n.length)}partsMatch(t,n,r=!1){let i=0,s=0,o=[],c="";for(;i<t.length&&s<n.length;)if(t[i]===n[s])o.push(c==="b"?n[s]:t[i]),i++,s++;else if(r&&t[i]==="**"&&n[s]===t[i+1])o.push(t[i]),i++;else if(r&&n[s]==="**"&&t[i]===n[s+1])o.push(n[s]),s++;else if(t[i]==="*"&&n[s]&&(this.options.dot||!n[s].startsWith("."))&&n[s]!=="**"){if(c==="b")return!1;c="a",o.push(t[i]),i++,s++}else if(n[s]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(c==="a")return!1;c="b",o.push(n[s]),i++,s++}else return!1;return t.length===n.length&&o}parseNegate(){if(this.nonegate)return;let t=this.pattern,n=!1,r=0;for(let i=0;i<t.length&&t.charAt(i)==="!";i++)n=!n,r++;r&&(this.pattern=t.slice(r)),this.negate=n}matchOne(t,n,r=!1){let i=0,s=0;if(this.isWindows){let c=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),l=!c&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),u=typeof n[0]=="string"&&/^[a-z]:$/i.test(n[0]),d=!u&&n[0]===""&&n[1]===""&&n[2]==="?"&&typeof n[3]=="string"&&/^[a-z]:$/i.test(n[3]),p=l?3:c?0:void 0,f=d?3:u?0:void 0;if(typeof p=="number"&&typeof f=="number"){let[h,g]=[t[p],n[f]];h.toLowerCase()===g.toLowerCase()&&(n[f]=h,s=f,i=p)}}let{optimizationLevel:o=1}=this.options;return o>=2&&(t=this.levelTwoFileOptimize(t)),n.includes(hc)?this.#e(t,n,r,i,s):this.#r(t,n,r,i,s)}#e(t,n,r,i,s){let o=n.indexOf(hc,s),c=n.lastIndexOf(hc),[l,u,d]=r?[n.slice(s,o),n.slice(o+1),[]]:[n.slice(s,o),n.slice(o+1,c),n.slice(c+1)];if(l.length){let b=t.slice(i,i+l.length);if(!this.#r(b,l,r,0,0))return!1;i+=l.length,s+=l.length}let p=0;if(d.length){if(d.length+i>t.length)return!1;let b=t.length-d.length;if(this.#r(t,d,r,b,0))p=d.length;else{if(t[t.length-1]!==""||i+d.length===t.length||(b--,!this.#r(t,d,r,b,0)))return!1;p=d.length+1}}if(!u.length){let b=!!p;for(let S=i;S<t.length-p;S++){let k=String(t[S]);if(b=!0,k==="."||k===".."||!this.options.dot&&k.startsWith("."))return!1}return r||b}let f=[[[],0]],h=f[0],g=0,y=[0];for(let b of u)b===hc?(y.push(g),h=[[],0],f.push(h)):(h[0].push(b),g++);let v=f.length-1,w=t.length-p;for(let b of f)b[1]=w-(y[v--]+b[0].length);return!!this.#t(t,f,i,0,r,0,!!p)}#t(t,n,r,i,s,o,c){let l=n[i];if(!l){for(let p=r;p<t.length;p++){c=!0;let f=t[p];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1}return c}let[u,d]=l;for(;r<=d;){if(this.#r(t.slice(0,r+u.length),u,s,r,0)&&o<this.maxGlobstarRecursion){let h=this.#t(t,n,r+u.length,i+1,s,o+1,c);if(h!==!1)return h}let f=t[r];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1;r++}return s||null}#r(t,n,r,i,s){let o,c,l,u;for(o=i,c=s,u=t.length,l=n.length;o<u&&c<l;o++,c++){this.debug("matchOne loop");let d=n[c],p=t[o];if(this.debug(n,d,p),d===!1||d===hc)return!1;let f;if(typeof d=="string"?(f=p===d,this.debug("string match",d,p,f)):(f=d.test(p),this.debug("pattern match",d,p,f)),!f)return!1}if(o===u&&c===l)return!0;if(o===u)return r;if(c===l)return o===u-1&&t[o]==="";throw new Error("wtf?")}braceExpand(){return JMe(this.pattern,this.options)}parse(t){YI(t);let n=this.options;if(t==="**")return hc;if(t==="")return"";let r,i=null;(r=t.match(jGt))?i=n.dot?qGt:FGt:(r=t.match(AGt))?i=(n.nocase?n.dot?OGt:$Gt:n.dot?RGt:CGt)(r[1]):(r=t.match(UGt))?i=(n.nocase?n.dot?BGt:zGt:n.dot?WGt:HGt)(r):(r=t.match(NGt))?i=n.dot?DGt:PGt:(r=t.match(MGt))&&(i=LGt);let s=J1.fromGlob(t,this.options).toMMPattern();return i&&typeof s=="object"&&Reflect.defineProperty(s,"test",{value:i}),s}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let n=this.options,r=n.noglobstar?KGt:n.dot?ZGt:JGt,i=new Set(n.nocase?["i"]:[]),s=t.map(l=>{let u=l.map(p=>{if(p instanceof RegExp)for(let f of p.flags.split(""))i.add(f);return typeof p=="string"?tKt(p):p===hc?hc:p._src});u.forEach((p,f)=>{let h=u[f+1],g=u[f-1];p!==hc||g===hc||(g===void 0?h!==void 0&&h!==hc?u[f+1]="(?:\\/|"+r+"\\/)?"+h:u[f]=r:h===void 0?u[f-1]=g+"(?:\\/|\\/"+r+")?":h!==hc&&(u[f-1]=g+"(?:\\/|\\/"+r+"\\/)"+h,u[f+1]=hc))});let d=u.filter(p=>p!==hc);if(this.partial&&d.length>=1){let p=[];for(let f=1;f<=d.length;f++)p.push(d.slice(0,f).join("/"));return"(?:"+p.join("|")+")"}return d.join("/")}).join("|"),[o,c]=t.length>1?["(?:",")"]:["",""];s="^"+o+s+c+"$",this.partial&&(s="^(?:\\/|"+o+s.slice(1,-1)+c+")$"),this.negate&&(s="^(?!"+s+").+$");try{this.regexp=new RegExp(s,[...i].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,n=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&n)return!0;let r=this.options;this.isWindows&&(t=t.split("\\").join("/"));let i=this.slashSplit(t);this.debug(this.pattern,"split",i);let s=this.set;this.debug(this.pattern,"set",s);let o=i[i.length-1];if(!o)for(let c=i.length-2;!o&&c>=0;c--)o=i[c];for(let c of s){let l=i;if(r.matchBase&&c.length===1&&(l=[o]),this.matchOne(l,c,n))return r.flipNegate?!0:!this.negate}return r.flipNegate?!1:this.negate}static defaults(t){return fa.defaults(t).Minimatch}};fa.AST=J1;fa.Minimatch=Jx;fa.escape=cre;fa.unescape=_y;import{gunzipSync as oJt}from"node:zlib";var QI=class{static{a(this,"Diff")}diff(t,n,r={}){let i;typeof r=="function"?(i=r,r={}):"callback"in r&&(i=r.callback);let s=this.castInput(t,r),o=this.castInput(n,r),c=this.removeEmpty(this.tokenize(s,r)),l=this.removeEmpty(this.tokenize(o,r));return this.diffWithOptionsObj(c,l,r,i)}diffWithOptionsObj(t,n,r,i){var s;let o=a(b=>{if(b=this.postProcess(b,r),i){setTimeout(function(){i(b)},0);return}else return b},"done"),c=n.length,l=t.length,u=1,d=c+l;r.maxEditLength!=null&&(d=Math.min(d,r.maxEditLength));let p=(s=r.timeout)!==null&&s!==void 0?s:1/0,f=Date.now()+p,h=[{oldPos:-1,lastComponent:void 0}],g=this.extractCommon(h[0],n,t,0,r);if(h[0].oldPos+1>=l&&g+1>=c)return o(this.buildValues(h[0].lastComponent,n,t));let y=-1/0,v=1/0,w=a(()=>{for(let b=Math.max(y,-u);b<=Math.min(v,u);b+=2){let S,k=h[b-1],E=h[b+1];k&&(h[b-1]=void 0);let _=!1;if(E){let L=E.oldPos-b;_=E&&0<=L&&L<c}let I=k&&k.oldPos+1<l;if(!_&&!I){h[b]=void 0;continue}if(!I||_&&k.oldPos<E.oldPos?S=this.addToPath(E,!0,!1,0,r):S=this.addToPath(k,!1,!0,1,r),g=this.extractCommon(S,n,t,b,r),S.oldPos+1>=l&&g+1>=c)return o(this.buildValues(S.lastComponent,n,t))||!0;h[b]=S,S.oldPos+1>=l&&(v=Math.min(v,b-1)),g+1>=c&&(y=Math.max(y,b+1))}u++},"execEditLength");if(i)a(function b(){setTimeout(function(){if(u>d||Date.now()>f)return i(void 0);w()||b()},0)},"exec")();else for(;u<=d&&Date.now()<=f;){let b=w();if(b)return b}}addToPath(t,n,r,i,s){let o=t.lastComponent;return o&&!s.oneChangePerToken&&o.added===n&&o.removed===r?{oldPos:t.oldPos+i,lastComponent:{count:o.count+1,added:n,removed:r,previousComponent:o.previousComponent}}:{oldPos:t.oldPos+i,lastComponent:{count:1,added:n,removed:r,previousComponent:o}}}extractCommon(t,n,r,i,s){let o=n.length,c=r.length,l=t.oldPos,u=l-i,d=0;for(;u+1<o&&l+1<c&&this.equals(r[l+1],n[u+1],s);)u++,l++,d++,s.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return d&&!s.oneChangePerToken&&(t.lastComponent={count:d,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=l,u}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){let n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){let i=[],s;for(;t;)i.push(t),s=t.previousComponent,delete t.previousComponent,t=s;i.reverse();let o=i.length,c=0,l=0,u=0;for(;c<o;c++){let d=i[c];if(d.removed)d.value=this.join(r.slice(u,u+d.count)),u+=d.count;else{if(!d.added&&this.useLongestToken){let p=n.slice(l,l+d.count);p=p.map(function(f,h){let g=r[u+h];return g.length>f.length?g:f}),d.value=this.join(p)}else d.value=this.join(n.slice(l,l+d.count));l+=d.count,d.added||(u+=d.count)}}return i}};var lre=class extends QI{static{a(this,"LineDiff")}constructor(){super(...arguments),this.tokenize=rKt}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
5797
5797
  `))&&(t=t.trim()),(!r.newlineIsToken||!n.includes(`
5798
5798
  `))&&(n=n.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(t.endsWith(`
5799
5799
  `)&&(t=t.slice(0,-1)),n.endsWith(`