@abacus-ai/cli 2.4.6-canary.2 → 2.4.6-canary.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -47,7 +47,7 @@ import{createRequire as e}from"node:module";import*as t from"node:util";import n
|
|
|
47
47
|
|
|
48
48
|
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=gf,s=!ef.jitless,c=s&&_f.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Vm([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Hm(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!wf(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Df(e,r,tf())))}),t)}const Um=G(`$ZodUnion`,(e,t)=>{rm.init(e,t),uf(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),uf(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),uf(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),uf(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>sf(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>Hm(t,i,e,a)):Hm(s,i,e,a)}});function Wm(e,t,n,r){let i=e.filter(e=>e.issues.length===0);return i.length===1?(t.value=i[0].value,t):(i.length===0?t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Df(e,r,tf())))}):t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:[],inclusive:!1}),t)}const Ree=G(`$ZodXor`,(e,t)=>{Um.init(e,t),t.inclusive=!1;let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);t instanceof Promise?(s.push(t),o=!0):s.push(t)}return o?Promise.all(s).then(t=>Wm(t,i,e,a)):Wm(s,i,e,a)}}),zee=G(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,Um.init(e,t);let n=e._zod.parse;uf(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=af(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!gf(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),i)}}),Bee=G(`$ZodIntersection`,(e,t)=>{rm.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Km(e,t,n)):Km(e,i,a)}});function Gm(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(vf(e)&&vf(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Gm(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Gm(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Km(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),wf(e))return e;let o=Gm(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const qm=G(`$ZodTuple`,(e,t)=>{rm.init(e,t);let n=t.items;e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({input:a,inst:e,expected:`tuple`,code:`invalid_type`}),r;r.value=[];let o=[],s=[...n].reverse().findIndex(e=>e._zod.optin!==`optional`),c=s===-1?0:n.length-s;if(!t.rest){let t=a.length>n.length,i=a.length<c-1;if(t||i)return r.issues.push({...t?{code:`too_big`,maximum:n.length,inclusive:!0}:{code:`too_small`,minimum:n.length},input:a,inst:e,origin:`array`}),r}let l=-1;for(let e of n){if(l++,l>=a.length&&l>=c)continue;let t=e._zod.run({value:a[l],issues:[]},i);t instanceof Promise?o.push(t.then(e=>Jm(e,r,l))):Jm(t,r,l)}if(t.rest){let e=a.slice(n.length);for(let n of e){l++;let e=t.rest._zod.run({value:n,issues:[]},i);e instanceof Promise?o.push(e.then(e=>Jm(e,r,l))):Jm(e,r,l)}}return o.length?Promise.all(o).then(()=>r):r}});function Jm(e,t,n){e.issues.length&&t.issues.push(...Tf(n,e.issues)),t.value[n]=e.value}const Vee=G(`$ZodRecord`,(e,t)=>{rm.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!vf(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){s.add(typeof e==`number`?e.toString():e);let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...Tf(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...Tf(e,o.issues)),n.value[e]=o.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&wp.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Df(e,r,tf())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Tf(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Tf(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Hee=G(`$ZodMap`,(e,t)=>{rm.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!(i instanceof Map))return n.issues.push({expected:`map`,code:`invalid_type`,input:i,inst:e}),n;let a=[];n.value=new Map;for(let[o,s]of i){let c=t.keyType._zod.run({value:o,issues:[]},r),l=t.valueType._zod.run({value:s,issues:[]},r);c instanceof Promise||l instanceof Promise?a.push(Promise.all([c,l]).then(([t,a])=>{Ym(t,a,n,o,i,e,r)})):Ym(c,l,n,o,i,e,r)}return a.length?Promise.all(a).then(()=>n):n}});function Ym(e,t,n,r,i,a,o){e.issues.length&&(bf.has(typeof r)?n.issues.push(...Tf(r,e.issues)):n.issues.push({code:`invalid_key`,origin:`map`,input:i,inst:a,issues:e.issues.map(e=>Df(e,o,tf()))})),t.issues.length&&(bf.has(typeof r)?n.issues.push(...Tf(r,t.issues)):n.issues.push({origin:`map`,code:`invalid_element`,input:i,inst:a,key:r,issues:t.issues.map(e=>Df(e,o,tf()))})),n.value.set(e.value,t.value)}const Uee=G(`$ZodSet`,(e,t)=>{rm.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!(i instanceof Set))return n.issues.push({input:i,inst:e,expected:`set`,code:`invalid_type`}),n;let a=[];n.value=new Set;for(let e of i){let i=t.valueType._zod.run({value:e,issues:[]},r);i instanceof Promise?a.push(i.then(e=>Xm(e,n))):Xm(i,n)}return a.length?Promise.all(a).then(()=>n):n}});function Xm(e,t){e.issues.length&&t.issues.push(...e.issues),t.value.add(e.value)}const Wee=G(`$ZodEnum`,(e,t)=>{rm.init(e,t);let n=nf(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>bf.has(typeof e)).map(e=>typeof e==`string`?xf(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Gee=G(`$ZodLiteral`,(e,t)=>{if(rm.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?xf(e):e?xf(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Kee=G(`$ZodFile`,(e,t)=>{rm.init(e,t),e._zod.parse=(t,n)=>{let r=t.value;return r instanceof File||t.issues.push({expected:`file`,code:`invalid_type`,input:r,inst:e}),t}}),qee=G(`$ZodTransform`,(e,t)=>{rm.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new $d(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new Qd;return n.value=i,n}});function Zm(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Qm=G(`$ZodOptional`,(e,t)=>{rm.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,uf(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),uf(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${sf(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>Zm(t,e.value)):Zm(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Jee=G(`$ZodExactOptional`,(e,t)=>{Qm.init(e,t),uf(e._zod,`values`,()=>t.innerType._zod.values),uf(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Yee=G(`$ZodNullable`,(e,t)=>{rm.init(e,t),uf(e._zod,`optin`,()=>t.innerType._zod.optin),uf(e._zod,`optout`,()=>t.innerType._zod.optout),uf(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${sf(e.source)}|null)$`):void 0}),uf(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Xee=G(`$ZodDefault`,(e,t)=>{rm.init(e,t),e._zod.optin=`optional`,uf(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>$m(e,t)):$m(r,t)}});function $m(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Zee=G(`$ZodPrefault`,(e,t)=>{rm.init(e,t),e._zod.optin=`optional`,uf(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Qee=G(`$ZodNonOptional`,(e,t)=>{rm.init(e,t),uf(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>eh(t,e)):eh(i,e)}});function eh(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const $ee=G(`$ZodSuccess`,(e,t)=>{rm.init(e,t),e._zod.parse=(e,n)=>{if(n.direction===`backward`)throw new $d(`ZodSuccess`);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>(e.value=t.issues.length===0,e)):(e.value=r.issues.length===0,e)}}),ete=G(`$ZodCatch`,(e,t)=>{rm.init(e,t),uf(e._zod,`optin`,()=>t.innerType._zod.optin),uf(e._zod,`optout`,()=>t.innerType._zod.optout),uf(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Df(e,n,tf()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Df(e,n,tf()))},input:e.value}),e.issues=[]),e)}}),tte=G(`$ZodNaN`,(e,t)=>{rm.init(e,t),e._zod.parse=(t,n)=>((typeof t.value!=`number`||!Number.isNaN(t.value))&&t.issues.push({input:t.value,inst:e,expected:`nan`,code:`invalid_type`}),t)}),nte=G(`$ZodPipe`,(e,t)=>{rm.init(e,t),uf(e._zod,`values`,()=>t.in._zod.values),uf(e._zod,`optin`,()=>t.in._zod.optin),uf(e._zod,`optout`,()=>t.out._zod.optout),uf(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>th(e,t.in,n)):th(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>th(e,t.out,n)):th(r,t.out,n)}});function th(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const rte=G(`$ZodCodec`,(e,t)=>{rm.init(e,t),uf(e._zod,`values`,()=>t.in._zod.values),uf(e._zod,`optin`,()=>t.in._zod.optin),uf(e._zod,`optout`,()=>t.out._zod.optout),uf(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if((n.direction||`forward`)===`forward`){let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>nh(e,t,n)):nh(r,t,n)}else{let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>nh(e,t,n)):nh(r,t,n)}}});function nh(e,t,n){if(e.issues.length)return e.aborted=!0,e;if((n.direction||`forward`)===`forward`){let r=t.transform(e.value,e);return r instanceof Promise?r.then(r=>rh(e,r,t.out,n)):rh(e,r,t.out,n)}else{let r=t.reverseTransform(e.value,e);return r instanceof Promise?r.then(r=>rh(e,r,t.in,n)):rh(e,r,t.in,n)}}function rh(e,t,n,r){return e.issues.length?(e.aborted=!0,e):n._zod.run({value:t,issues:e.issues},r)}const ite=G(`$ZodReadonly`,(e,t)=>{rm.init(e,t),uf(e._zod,`propValues`,()=>t.innerType._zod.propValues),uf(e._zod,`values`,()=>t.innerType._zod.values),uf(e._zod,`optin`,()=>t.innerType?._zod?.optin),uf(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(ih):ih(r)}});function ih(e){return e.value=Object.freeze(e.value),e}const ate=G(`$ZodTemplateLiteral`,(e,t)=>{rm.init(e,t);let n=[];for(let e of t.parts)if(typeof e==`object`&&e){if(!e._zod.pattern)throw Error(`Invalid template literal part, no pattern found: ${[...e._zod.traits].shift()}`);let t=e._zod.pattern instanceof RegExp?e._zod.pattern.source:e._zod.pattern;if(!t)throw Error(`Invalid template literal part: ${e._zod.traits}`);let r=t.startsWith(`^`)?1:0,i=t.endsWith(`$`)?t.length-1:t.length;n.push(t.slice(r,i))}else if(e===null||mee.has(typeof e))n.push(xf(`${e}`));else throw Error(`Invalid template literal part: ${e}`);e._zod.pattern=RegExp(`^${n.join(``)}$`),e._zod.parse=(n,r)=>typeof n.value==`string`?(e._zod.pattern.lastIndex=0,e._zod.pattern.test(n.value)||n.issues.push({input:n.value,inst:e,code:`invalid_format`,format:t.format??`template_literal`,pattern:e._zod.pattern.source}),n):(n.issues.push({input:n.value,inst:e,expected:`string`,code:`invalid_type`}),n)}),ote=G(`$ZodFunction`,(e,t)=>(rm.init(e,t),e._def=t,e._zod.def=t,e.implement=t=>{if(typeof t!=`function`)throw Error(`implement() must be called with a function`);return function(...n){let r=e._def.input?If(e._def.input,n):n,i=Reflect.apply(t,this,r);return e._def.output?If(e._def.output,i):i}},e.implementAsync=t=>{if(typeof t!=`function`)throw Error(`implementAsync() must be called with a function`);return async function(...n){let r=e._def.input?await Rf(e._def.input,n):n,i=await Reflect.apply(t,this,r);return e._def.output?await Rf(e._def.output,i):i}},e._zod.parse=(t,n)=>typeof t.value==`function`?(e._def.output&&e._def.output._zod.def.type===`promise`?t.value=e.implementAsync(t.value):t.value=e.implement(t.value),t):(t.issues.push({code:`invalid_type`,expected:`function`,input:t.value,inst:e}),t),e.input=(...t)=>{let n=e.constructor;return Array.isArray(t[0])?new n({type:`function`,input:new qm({type:`tuple`,items:t[0],rest:t[1]}),output:e._def.output}):new n({type:`function`,input:t[0],output:e._def.output})},e.output=t=>{let n=e.constructor;return new n({type:`function`,input:e._def.input,output:t})},e)),ste=G(`$ZodPromise`,(e,t)=>{rm.init(e,t),e._zod.parse=(e,n)=>Promise.resolve(e.value).then(e=>t.innerType._zod.run({value:e,issues:[]},n))}),cte=G(`$ZodLazy`,(e,t)=>{rm.init(e,t),uf(e._zod,`innerType`,()=>t.getter()),uf(e._zod,`pattern`,()=>e._zod.innerType?._zod?.pattern),uf(e._zod,`propValues`,()=>e._zod.innerType?._zod?.propValues),uf(e._zod,`optin`,()=>e._zod.innerType?._zod?.optin??void 0),uf(e._zod,`optout`,()=>e._zod.innerType?._zod?.optout??void 0),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),lte=G(`$ZodCustom`,(e,t)=>{Mp.init(e,t),rm.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>ah(t,n,r,e));ah(i,n,r,e)}});function ah(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Af(e))}}var oh,ute=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function dte(){return new ute}(oh=globalThis).__zod_globalRegistry??(oh.__zod_globalRegistry=dte());const sh=globalThis.__zod_globalRegistry;function fte(e,t){return new e({type:`string`,...Cf(t)})}function pte(e,t){return new e({type:`string`,coerce:!0,...Cf(t)})}function mte(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...Cf(t)})}function ch(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...Cf(t)})}function hte(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...Cf(t)})}function gte(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...Cf(t)})}function _te(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...Cf(t)})}function vte(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...Cf(t)})}function lh(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...Cf(t)})}function yte(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...Cf(t)})}function bte(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...Cf(t)})}function xte(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...Cf(t)})}function uh(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...Cf(t)})}function dh(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...Cf(t)})}function fh(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...Cf(t)})}function ph(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...Cf(t)})}function mh(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...Cf(t)})}function hh(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...Cf(t)})}function gh(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...Cf(t)})}function _h(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...Cf(t)})}function vh(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...Cf(t)})}function yh(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...Cf(t)})}function bh(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...Cf(t)})}function xh(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...Cf(t)})}function Sh(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...Cf(t)})}function Ch(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...Cf(t)})}function wh(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...Cf(t)})}function Th(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...Cf(t)})}function Eh(e,t){return new e({type:`number`,checks:[],...Cf(t)})}function Dh(e,t){return new e({type:`number`,coerce:!0,checks:[],...Cf(t)})}function Oh(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...Cf(t)})}function kh(e,t){return new e({type:`boolean`,...Cf(t)})}function Ah(e,t){return new e({type:`null`,...Cf(t)})}function jh(e){return new e({type:`any`})}function Mh(e){return new e({type:`unknown`})}function Nh(e,t){return new e({type:`never`,...Cf(t)})}function Ph(e,t){return new Pp({check:`less_than`,...Cf(t),value:e,inclusive:!1})}function Fh(e,t){return new Pp({check:`less_than`,...Cf(t),value:e,inclusive:!0})}function Ih(e,t){return new Fp({check:`greater_than`,...Cf(t),value:e,inclusive:!1})}function Lh(e,t){return new Fp({check:`greater_than`,...Cf(t),value:e,inclusive:!0})}function Rh(e,t){return new Ip({check:`multiple_of`,...Cf(t),value:e})}function zh(e,t){return new zp({check:`max_size`,...Cf(t),maximum:e})}function Bh(e,t){return new Bp({check:`min_size`,...Cf(t),minimum:e})}function Vh(e,t){return new Vp({check:`size_equals`,...Cf(t),size:e})}function Hh(e,t){return new Hp({check:`max_length`,...Cf(t),maximum:e})}function Uh(e,t){return new Up({check:`min_length`,...Cf(t),minimum:e})}function Wh(e,t){return new Wp({check:`length_equals`,...Cf(t),length:e})}function Gh(e,t){return new Kp({check:`string_format`,format:`regex`,...Cf(t),pattern:e})}function Kh(e){return new qp({check:`string_format`,format:`lowercase`,...Cf(e)})}function qh(e){return new Jp({check:`string_format`,format:`uppercase`,...Cf(e)})}function Jh(e,t){return new Yp({check:`string_format`,format:`includes`,...Cf(t),includes:e})}function Yh(e,t){return new Xp({check:`string_format`,format:`starts_with`,...Cf(t),prefix:e})}function Xh(e,t){return new Zp({check:`string_format`,format:`ends_with`,...Cf(t),suffix:e})}function Zh(e,t){return new $p({check:`mime_type`,mime:e,...Cf(t)})}function Qh(e){return new em({check:`overwrite`,tx:e})}function $h(e){return Qh(t=>t.normalize(e))}function eg(){return Qh(e=>e.trim())}function tg(){return Qh(e=>e.toLowerCase())}function ng(){return Qh(e=>e.toUpperCase())}function rg(){return Qh(e=>mf(e))}function ig(e,t,n){return new e({type:`array`,element:t,...Cf(n)})}function ag(e,t,n){let r=Cf(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}function og(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...Cf(n)})}function sg(e){let t=cg(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(Af(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(Af(r))}},e(n.value,n)));return t}function cg(e,t){let n=new Mp({check:`custom`,...Cf(t)});return n._zod.check=e,n}function lg(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??sh,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function ug(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,ug(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&pg(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function dg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
49
49
|
|
|
50
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function fg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:hg(t,`input`,e.processors),output:hg(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function pg(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return pg(r.element,n);if(r.type===`set`)return pg(r.valueType,n);if(r.type===`lazy`)return pg(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return pg(r.innerType,n);if(r.type===`intersection`)return pg(r.left,n)||pg(r.right,n);if(r.type===`record`||r.type===`map`)return pg(r.keyType,n)||pg(r.valueType,n);if(r.type===`pipe`)return pg(r.in,n)||pg(r.out,n);if(r.type===`object`){for(let e in r.shape)if(pg(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(pg(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(pg(e,n))return!0;return!!(r.rest&&pg(r.rest,n))}return!1}const mg=(e,t={})=>n=>{let r=lg({...n,processors:t});return ug(e,r),dg(r,e),fg(r,e)},hg=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=lg({...i??{},target:a,io:t,processors:n});return ug(e,o),dg(o,e),fg(o,e)},gg={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},_g=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=gg[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},vg=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},yg=(e,t,n,r)=>{n.type=`boolean`},bg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`BigInt cannot be represented in JSON Schema`)},xg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Symbols cannot be represented in JSON Schema`)},Sg=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},Cg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Undefined cannot be represented in JSON Schema`)},wg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Void cannot be represented in JSON Schema`)},Tg=(e,t,n,r)=>{n.not={}},Eg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Date cannot be represented in JSON Schema`)},Dg=(e,t,n,r)=>{let i=e._zod.def,a=nf(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Og=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},kg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`NaN cannot be represented in JSON Schema`)},Ag=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},jg=(e,t,n,r)=>{let i=n,a={type:`string`,format:`binary`,contentEncoding:`binary`},{minimum:o,maximum:s,mime:c}=e._zod.bag;o!==void 0&&(a.minLength=o),s!==void 0&&(a.maxLength=s),c?c.length===1?(a.contentMediaType=c[0],Object.assign(i,a)):(Object.assign(i,a),i.anyOf=c.map(e=>({contentMediaType:e}))):Object.assign(i,a)},Mg=(e,t,n,r)=>{n.type=`boolean`},Ng=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Pg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Function types cannot be represented in JSON Schema`)},Fg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Ig=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Map cannot be represented in JSON Schema`)},Lg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Set cannot be represented in JSON Schema`)},Rg=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=ug(a.element,t,{...r,path:[...r.path,`items`]})},zg=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=ug(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=ug(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Bg=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>ug(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Vg=(e,t,n,r)=>{let i=e._zod.def,a=ug(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=ug(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Hg=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>ug(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?ug(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null;t.target===`draft-2020-12`?(i.prefixItems=c,l&&(i.items=l)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),i.minItems=c.length,l||(i.maxItems=c.length)):(i.items=c,l&&(i.additionalItems=l));let{minimum:u,maximum:d}=e._zod.bag;typeof u==`number`&&(i.minItems=u),typeof d==`number`&&(i.maxItems=d)},Ug=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=ug(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=ug(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=ug(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Wg=(e,t,n,r)=>{let i=e._zod.def,a=ug(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Gg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Kg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},qg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Jg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Yg=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;ug(a,t,r);let o=t.seen.get(e);o.ref=a},Xg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Zg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Qg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},$g=(e,t,n,r)=>{let i=e._zod.innerType;ug(i,t,r);let a=t.seen.get(e);a.ref=i},e_=G(`ZodISODateTime`,(e,t)=>{_m.init(e,t),T_.init(e,t)});function t_(e){return Sh(e_,e)}const n_=G(`ZodISODate`,(e,t)=>{vm.init(e,t),T_.init(e,t)});function r_(e){return Ch(n_,e)}const i_=G(`ZodISOTime`,(e,t)=>{ym.init(e,t),T_.init(e,t)});function a_(e){return wh(i_,e)}const o_=G(`ZodISODuration`,(e,t)=>{bm.init(e,t),T_.init(e,t)});function s_(e){return Th(o_,e)}const c_=(e,t)=>{Mf.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Pf(e,t)},flatten:{value:t=>Tee(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,rf,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,rf,2)}},isEmpty:{get(){return e.issues.length===0}}})};G(`ZodError`,c_);const l_=G(`ZodError`,c_,{Parent:Error}),u_=Ff(l_),d_=Lf(l_),f_=zf(l_),p_=Vf(l_),m_=Uf(l_),h_=Wf(l_),g_=Gf(l_),__=Kf(l_),v_=qf(l_),y_=Jf(l_),b_=Yf(l_),x_=Xf(l_),S_=G(`ZodType`,(e,t)=>(rm.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:hg(e,`input`),output:hg(e,`output`)}}),e.toJSONSchema=mg(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(ff(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Sf(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>u_(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>f_(e,t,n),e.parseAsync=async(t,n)=>d_(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>p_(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>m_(e,t,n),e.decode=(t,n)=>h_(e,t,n),e.encodeAsync=async(t,n)=>g_(e,t,n),e.decodeAsync=async(t,n)=>__(e,t,n),e.safeEncode=(t,n)=>v_(e,t,n),e.safeDecode=(t,n)=>y_(e,t,n),e.safeEncodeAsync=async(t,n)=>b_(e,t,n),e.safeDecodeAsync=async(t,n)=>x_(e,t,n),e.refine=(t,n)=>e.check(qv(t,n)),e.superRefine=t=>e.check(Jv(t)),e.overwrite=t=>e.check(Qh(t)),e.optional=()=>Ov(e),e.exactOptional=()=>Av(e),e.nullable=()=>Mv(e),e.nullish=()=>Ov(Mv(e)),e.nonoptional=t=>Rv(e,t),e.array=()=>cv(e),e.or=t=>fv([e,t]),e.and=t=>gv(e,t),e.transform=t=>Hv(e,Ev(t)),e.default=t=>Pv(e,t),e.prefault=t=>Iv(e,t),e.catch=t=>Bv(e,t),e.pipe=t=>Hv(e,t),e.readonly=()=>Wv(e),e.describe=t=>{let n=e.clone();return sh.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return sh.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return sh.get(e);let n=e.clone();return sh.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),C_=G(`_ZodString`,(e,t)=>{im.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_g(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Gh(...t)),e.includes=(...t)=>e.check(Jh(...t)),e.startsWith=(...t)=>e.check(Yh(...t)),e.endsWith=(...t)=>e.check(Xh(...t)),e.min=(...t)=>e.check(Uh(...t)),e.max=(...t)=>e.check(Hh(...t)),e.length=(...t)=>e.check(Wh(...t)),e.nonempty=(...t)=>e.check(Uh(1,...t)),e.lowercase=t=>e.check(Kh(t)),e.uppercase=t=>e.check(qh(t)),e.trim=()=>e.check(eg()),e.normalize=(...t)=>e.check($h(...t)),e.toLowerCase=()=>e.check(tg()),e.toUpperCase=()=>e.check(ng()),e.slugify=()=>e.check(rg())}),w_=G(`ZodString`,(e,t)=>{im.init(e,t),C_.init(e,t),e.email=t=>e.check(mte(E_,t)),e.url=t=>e.check(lh(k_,t)),e.jwt=t=>e.check(xh(G_,t)),e.emoji=t=>e.check(yte(j_,t)),e.guid=t=>e.check(ch(D_,t)),e.uuid=t=>e.check(hte(O_,t)),e.uuidv4=t=>e.check(gte(O_,t)),e.uuidv6=t=>e.check(_te(O_,t)),e.uuidv7=t=>e.check(vte(O_,t)),e.nanoid=t=>e.check(bte(M_,t)),e.guid=t=>e.check(ch(D_,t)),e.cuid=t=>e.check(xte(N_,t)),e.cuid2=t=>e.check(uh(P_,t)),e.ulid=t=>e.check(dh(F_,t)),e.base64=t=>e.check(vh(H_,t)),e.base64url=t=>e.check(yh(U_,t)),e.xid=t=>e.check(fh(I_,t)),e.ksuid=t=>e.check(ph(L_,t)),e.ipv4=t=>e.check(mh(R_,t)),e.ipv6=t=>e.check(hh(z_,t)),e.cidrv4=t=>e.check(gh(B_,t)),e.cidrv6=t=>e.check(_h(V_,t)),e.e164=t=>e.check(bh(W_,t)),e.datetime=t=>e.check(t_(t)),e.date=t=>e.check(r_(t)),e.time=t=>e.check(a_(t)),e.duration=t=>e.check(s_(t))});function K(e){return fte(w_,e)}const T_=G(`ZodStringFormat`,(e,t)=>{am.init(e,t),C_.init(e,t)}),E_=G(`ZodEmail`,(e,t)=>{cm.init(e,t),T_.init(e,t)}),D_=G(`ZodGUID`,(e,t)=>{om.init(e,t),T_.init(e,t)}),O_=G(`ZodUUID`,(e,t)=>{sm.init(e,t),T_.init(e,t)}),k_=G(`ZodURL`,(e,t)=>{lm.init(e,t),T_.init(e,t)});function A_(e){return lh(k_,e)}const j_=G(`ZodEmoji`,(e,t)=>{um.init(e,t),T_.init(e,t)}),M_=G(`ZodNanoID`,(e,t)=>{dm.init(e,t),T_.init(e,t)}),N_=G(`ZodCUID`,(e,t)=>{fm.init(e,t),T_.init(e,t)}),P_=G(`ZodCUID2`,(e,t)=>{pm.init(e,t),T_.init(e,t)}),F_=G(`ZodULID`,(e,t)=>{mm.init(e,t),T_.init(e,t)}),I_=G(`ZodXID`,(e,t)=>{hm.init(e,t),T_.init(e,t)}),L_=G(`ZodKSUID`,(e,t)=>{gm.init(e,t),T_.init(e,t)}),R_=G(`ZodIPv4`,(e,t)=>{xm.init(e,t),T_.init(e,t)});G(`ZodMAC`,(e,t)=>{Cm.init(e,t),T_.init(e,t)});const z_=G(`ZodIPv6`,(e,t)=>{Sm.init(e,t),T_.init(e,t)}),B_=G(`ZodCIDRv4`,(e,t)=>{wm.init(e,t),T_.init(e,t)}),V_=G(`ZodCIDRv6`,(e,t)=>{Tm.init(e,t),T_.init(e,t)}),H_=G(`ZodBase64`,(e,t)=>{Dm.init(e,t),T_.init(e,t)}),U_=G(`ZodBase64URL`,(e,t)=>{km.init(e,t),T_.init(e,t)}),W_=G(`ZodE164`,(e,t)=>{Am.init(e,t),T_.init(e,t)}),G_=G(`ZodJWT`,(e,t)=>{Mm.init(e,t),T_.init(e,t)});G(`ZodCustomStringFormat`,(e,t)=>{Nm.init(e,t),T_.init(e,t)});const K_=G(`ZodNumber`,(e,t)=>{Pm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vg(e,t,n,r),e.gt=(t,n)=>e.check(Ih(t,n)),e.gte=(t,n)=>e.check(Lh(t,n)),e.min=(t,n)=>e.check(Lh(t,n)),e.lt=(t,n)=>e.check(Ph(t,n)),e.lte=(t,n)=>e.check(Fh(t,n)),e.max=(t,n)=>e.check(Fh(t,n)),e.int=t=>e.check(Y_(t)),e.safe=t=>e.check(Y_(t)),e.positive=t=>e.check(Ih(0,t)),e.nonnegative=t=>e.check(Lh(0,t)),e.negative=t=>e.check(Ph(0,t)),e.nonpositive=t=>e.check(Fh(0,t)),e.multipleOf=(t,n)=>e.check(Rh(t,n)),e.step=(t,n)=>e.check(Rh(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function q_(e){return Eh(K_,e)}const J_=G(`ZodNumberFormat`,(e,t)=>{Fm.init(e,t),K_.init(e,t)});function Y_(e){return Oh(J_,e)}const X_=G(`ZodBoolean`,(e,t)=>{Im.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yg(e,t,n,r)});function Z_(e){return kh(X_,e)}const Q_=G(`ZodBigInt`,(e,t)=>{Lm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bg(e,t,n,r),e.gte=(t,n)=>e.check(Lh(t,n)),e.min=(t,n)=>e.check(Lh(t,n)),e.gt=(t,n)=>e.check(Ih(t,n)),e.gte=(t,n)=>e.check(Lh(t,n)),e.min=(t,n)=>e.check(Lh(t,n)),e.lt=(t,n)=>e.check(Ph(t,n)),e.lte=(t,n)=>e.check(Fh(t,n)),e.max=(t,n)=>e.check(Fh(t,n)),e.positive=t=>e.check(Ih(BigInt(0),t)),e.negative=t=>e.check(Ph(BigInt(0),t)),e.nonpositive=t=>e.check(Fh(BigInt(0),t)),e.nonnegative=t=>e.check(Lh(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Rh(t,n));let n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});G(`ZodBigIntFormat`,(e,t)=>{Eee.init(e,t),Q_.init(e,t)}),G(`ZodSymbol`,(e,t)=>{Dee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xg(e,t,n,r)}),G(`ZodUndefined`,(e,t)=>{Oee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cg(e,t,n,r)});const $_=G(`ZodNull`,(e,t)=>{kee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sg(e,t,n,r)});function ev(e){return Ah($_,e)}const tv=G(`ZodAny`,(e,t)=>{Aee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function nv(){return jh(tv)}const rv=G(`ZodUnknown`,(e,t)=>{jee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function iv(){return Mh(rv)}const av=G(`ZodNever`,(e,t)=>{Mee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Tg(e,t,n,r)});function ov(e){return Nh(av,e)}G(`ZodVoid`,(e,t)=>{Nee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wg(e,t,n,r)}),G(`ZodDate`,(e,t)=>{Pee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eg(e,t,n,r),e.min=(t,n)=>e.check(Lh(t,n)),e.max=(t,n)=>e.check(Fh(t,n));let n=e._zod.bag;e.minDate=n.minimum?new Date(n.minimum):null,e.maxDate=n.maximum?new Date(n.maximum):null});const sv=G(`ZodArray`,(e,t)=>{Fee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Rg(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Uh(t,n)),e.nonempty=t=>e.check(Uh(1,t)),e.max=(t,n)=>e.check(Hh(t,n)),e.length=(t,n)=>e.check(Wh(t,n)),e.unwrap=()=>e.element});function cv(e,t){return ig(sv,e,t)}const lv=G(`ZodObject`,(e,t)=>{Lee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zg(e,t,n,r),uf(e,`shape`,()=>t.shape),e.keyof=()=>Sv(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:iv()}),e.loose=()=>e.clone({...e._zod.def,catchall:iv()}),e.strict=()=>e.clone({...e._zod.def,catchall:ov()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>bee(e,t),e.safeExtend=t=>xee(e,t),e.merge=t=>See(e,t),e.pick=t=>vee(e,t),e.omit=t=>yee(e,t),e.partial=(...t)=>Cee(Dv,e,t[0]),e.required=(...t)=>wee(Lv,e,t[0])});function q(e,t){return new lv({type:`object`,shape:e??{},...Cf(t)})}function uv(e,t){return new lv({type:`object`,shape:e,catchall:iv(),...Cf(t)})}const dv=G(`ZodUnion`,(e,t)=>{Um.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bg(e,t,n,r),e.options=t.options});function fv(e,t){return new dv({type:`union`,options:e,...Cf(t)})}G(`ZodXor`,(e,t)=>{dv.init(e,t),Ree.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bg(e,t,n,r),e.options=t.options});const pv=G(`ZodDiscriminatedUnion`,(e,t)=>{dv.init(e,t),zee.init(e,t)});function mv(e,t,n){return new pv({type:`union`,options:t,discriminator:e,...Cf(n)})}const hv=G(`ZodIntersection`,(e,t)=>{Bee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vg(e,t,n,r)});function gv(e,t){return new hv({type:`intersection`,left:e,right:t})}const _v=G(`ZodTuple`,(e,t)=>{qm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hg(e,t,n,r),e.rest=t=>e.clone({...e._zod.def,rest:t})});function vv(e,t,n){let r=t instanceof rm;return new _v({type:`tuple`,items:e,rest:r?t:null,...Cf(r?n:t)})}const yv=G(`ZodRecord`,(e,t)=>{Vee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ug(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function bv(e,t,n){return new yv({type:`record`,keyType:e,valueType:t,...Cf(n)})}G(`ZodMap`,(e,t)=>{Hee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ig(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType,e.min=(...t)=>e.check(Bh(...t)),e.nonempty=t=>e.check(Bh(1,t)),e.max=(...t)=>e.check(zh(...t)),e.size=(...t)=>e.check(Vh(...t))}),G(`ZodSet`,(e,t)=>{Uee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lg(e,t,n,r),e.min=(...t)=>e.check(Bh(...t)),e.nonempty=t=>e.check(Bh(1,t)),e.max=(...t)=>e.check(zh(...t)),e.size=(...t)=>e.check(Vh(...t))});const xv=G(`ZodEnum`,(e,t)=>{Wee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Dg(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new xv({...t,checks:[],...Cf(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new xv({...t,checks:[],...Cf(r),entries:i})}});function Sv(e,t){return new xv({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...Cf(t)})}const Cv=G(`ZodLiteral`,(e,t)=>{Gee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Og(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function wv(e,t){return new Cv({type:`literal`,values:Array.isArray(e)?e:[e],...Cf(t)})}G(`ZodFile`,(e,t)=>{Kee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jg(e,t,n,r),e.min=(t,n)=>e.check(Bh(t,n)),e.max=(t,n)=>e.check(zh(t,n)),e.mime=(t,n)=>e.check(Zh(Array.isArray(t)?t:[t],n))});const Tv=G(`ZodTransform`,(e,t)=>{qee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fg(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new $d(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Af(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Af(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Ev(e){return new Tv({type:`transform`,transform:e})}const Dv=G(`ZodOptional`,(e,t)=>{Qm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ov(e){return new Dv({type:`optional`,innerType:e})}const kv=G(`ZodExactOptional`,(e,t)=>{Jee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Av(e){return new kv({type:`optional`,innerType:e})}const jv=G(`ZodNullable`,(e,t)=>{Yee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mv(e){return new jv({type:`nullable`,innerType:e})}const Nv=G(`ZodDefault`,(e,t)=>{Xee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Pv(e,t){return new Nv({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():yf(t)}})}const Fv=G(`ZodPrefault`,(e,t)=>{Zee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Iv(e,t){return new Fv({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():yf(t)}})}const Lv=G(`ZodNonOptional`,(e,t)=>{Qee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Rv(e,t){return new Lv({type:`nonoptional`,innerType:e,...Cf(t)})}G(`ZodSuccess`,(e,t)=>{$ee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const zv=G(`ZodCatch`,(e,t)=>{ete.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Bv(e,t){return new zv({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}G(`ZodNaN`,(e,t)=>{tte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>kg(e,t,n,r)});const Vv=G(`ZodPipe`,(e,t)=>{nte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yg(e,t,n,r),e.in=t.in,e.out=t.out});function Hv(e,t){return new Vv({type:`pipe`,in:e,out:t})}G(`ZodCodec`,(e,t)=>{Vv.init(e,t),rte.init(e,t)});const Uv=G(`ZodReadonly`,(e,t)=>{ite.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Wv(e){return new Uv({type:`readonly`,innerType:e})}G(`ZodTemplateLiteral`,(e,t)=>{ate.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ag(e,t,n,r)}),G(`ZodLazy`,(e,t)=>{cte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$g(e,t,n,r),e.unwrap=()=>e._zod.def.getter()}),G(`ZodPromise`,(e,t)=>{ste.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),G(`ZodFunction`,(e,t)=>{ote.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Pg(e,t,n,r)});const Gv=G(`ZodCustom`,(e,t)=>{lte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ng(e,t,n,r)});function Kv(e,t){return ag(Gv,e??(()=>!0),t)}function qv(e,t={}){return og(Gv,e,t)}function Jv(e){return sg(e)}function Yv(e,t){return Hv(Ev(e),t)}const Xv={invalid_type:`invalid_type`,too_big:`too_big`,too_small:`too_small`,invalid_format:`invalid_format`,not_multiple_of:`not_multiple_of`,unrecognized_keys:`unrecognized_keys`,invalid_union:`invalid_union`,invalid_key:`invalid_key`,invalid_element:`invalid_element`,invalid_value:`invalid_value`,custom:`custom`};var Zv;(function(e){})(Zv||={});function Qv(e){return pte(w_,e)}function $v(e){return Dh(K_,e)}const ey={USER_MESSAGE:`user_message`,REJECTED:`rejected`,INTERRUPTED:`interrupted`},ty={REJECTED:`rejected`};function ny(e){if(e===`Tool was rejected by user`)return{rejected:!0};try{let t=JSON.parse(e);if(t.reason===ey.USER_MESSAGE)return{rejected:!0,userNote:t.message};if(t.reason===ey.REJECTED||t.reason===ey.INTERRUPTED)return{rejected:!0};if(t.status===ty.REJECTED)return{rejected:!0,userNote:t.userNote}}catch{}return{rejected:!1}}const ry=`sibling_tool_failed`,iy=JSON.stringify({type:ry,message:`Not executed: a tool call in a preceding parallel batch failed`});function ay(e){try{return JSON.parse(e)?.type===ry}catch{return!1}}var oy=class{concurrency(e,t){return!1}includeInApiDefinitions=!0;isEnabled(e){return!0}async prepare(e,t){return null}needsPermission(e,t,n){return!this.isReadonly}format(e,t){return typeof e==`string`?e:JSON.stringify(e)}formatForLLM(e,t){return this.format(e,t)}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:this.name,data:{},summary:t.userNote?`Rejected \u00b7 "${t.userNote}"`:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e),n=`success`;return t.status===`error`?n=`error`:t.status===`skipped`&&(n=`skipped`),{phase:n,toolType:t.type??this.name,data:t,summary:t.message??t.summary??`Completed`,...t.errorMessage!==void 0&&{errorMessage:t.errorMessage}}}catch{}return e.startsWith(`Error:`)?{phase:`error`,toolType:this.name,data:{},summary:e,errorMessage:e}:{phase:`success`,toolType:this.name,data:{},summary:`Completed`}}validateParams(e){return this.parameters.parse(e)}getToolDefinition(){let e=this.getParameterNames();return{name:this.name,description:this.description,arguments:e}}getParameterNames(){return Object.keys(this.parameters.shape)}};const sy=Symbol.for(`server-executed`);var cy=class extends oy{isReadonly=!0;async execute(e,t,n){return sy}format(e,t){return JSON.stringify({type:this.name,status:`server-executed`})}};it([`codellm`,`agent`,`tools`,`subagent`]);var ly=class e extends cy{name=`subagent`;displayName=`Subagent`;description=`Switch to a different subagent for a task`;static parametersSchema=q({agent:K().describe(`The name of the subagent to switch to`),task:K().describe(`The task description for the subagent`)});parameters=e.parametersSchema;needsPermission(){return!1}format(e,t){return JSON.stringify({type:`subagent`,status:`success`,agent:t.agent,task:t.task})}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`subagent`,data:{},summary:t.userNote?`Rejected \u00b7 "${t.userNote}"`:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e);return{phase:`success`,toolType:`subagent`,data:t,summary:`Delegated to ${t.agent??`explore`} agent`}}catch{}return{phase:`success`,toolType:`subagent`,data:{},summary:`Delegated`}}};it([`codellm`,`agent`,`tools`,`todo-write`]);var uy=class e extends cy{name=`todo_write`;displayName=`TodoWrite`;description=`Create and manage a structured task list`;static parametersSchema=q({todos:Yv(e=>{if(e==null)return[];if(typeof e==`string`)try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}return Array.isArray(e)?e:[]},cv(q({content:K().describe(`The task content`),status:Sv([`pending`,`in_progress`,`completed`,`cancelled`]).describe(`The status of the task`),id:K().optional().describe(`Optional task ID`)}))).describe(`Array of todo items`)});parameters=e.parametersSchema;needsPermission(){return!1}format(e,t){return`Updated`}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`todo_write`,data:{},summary:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e);if(t.todos){let e=t.todos;return{phase:`success`,toolType:`todo_write`,data:t,summary:`${e.filter(e=>e.status===`pending`).length} pending, ${e.filter(e=>e.status===`in_progress`).length} in progress, ${e.filter(e=>e.status===`completed`).length} completed`}}}catch{}return{phase:`success`,toolType:`todo_write`,data:{},summary:`Updated`}}};function dy(e){if(typeof e!=`string`)return e;let t=e.trim();return t?Number(t):NaN}function fy(e){if(typeof e!=`string`)return e;let t=e.trim().toLowerCase();return[`true`,`1`,`yes`,`y`].includes(t)?!0:[`false`,`0`,`no`,`n`].includes(t)?!1:e}const py=Yv(dy,q_()),my=Yv(dy,q_().optional()),hy=Yv(fy,Z_()),gy=Yv(fy,Z_().optional()),_y=it([`codellm`,`agent`,`tools`,`ask-user`]);var vy=class e extends oy{isReadonly=!0;name=`ask_user_question`;displayName=`AskUserQuestion`;description=`Ask the user questions during execution to gather preferences, clarify instructions, or get decisions on implementation choices`;static parametersSchema=q({questions:cv(q({question:K().describe(`The question to ask the user`),header:K().describe(`A header/title for the question`),options:cv(q({label:K().describe(`The option label`),description:K().describe(`A description of the option`)})).describe(`Array of options for the user to select from`),multiSelect:hy.describe(`Whether the user can select multiple options`)})).describe(`Array of questions to ask the user`),answers:bv(K(),K()).optional().describe(`User-provided answers to the questions`)});parameters=e.parametersSchema;needsPermission(){return!0}async execute(e){return _y.debug`Asking user ${e.questions.length} question(s)`,{answers:e.answers||{}}}format(e,t){return JSON.stringify({type:`ask_user_question`,status:`success`,answers:e.answers})}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`ask_user_question`,data:{},summary:`Cancelled`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e),n=t.answers,r=n?Object.keys(n).length:0;return{phase:`success`,toolType:`ask_user_question`,data:t,summary:`Answered ${r} question${r===1?``:`s`}`}}catch{}return{phase:`success`,toolType:`ask_user_question`,data:{},summary:`Answered`}}};const yy=it([`codellm`,`agent`,`tools`,`plan-mode`]);var by=class e extends oy{name=`enter_plan_mode`;displayName=`EnterPlanMode`;description=`Enter plan mode to create a plan before implementing changes`;static parametersSchema=q({});parameters=e.parametersSchema;isReadonly=!0;needsPermission(e,t,n){return!1}async execute(e,t){return yy.info`Entering plan mode`,{success:!0}}format(e,t){return`Entered plan mode`}parse(e){let t=ny(e);return t.rejected?{phase:`rejected`,toolType:`enter_plan_mode`,data:{},summary:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}}:{phase:`success`,toolType:`enter_plan_mode`,data:{},summary:`Entered plan mode`}}};const xy=it([`codellm`,`agent`,`tools`,`plan-mode`]);var Sy=class e extends oy{name=`exit_plan_mode`;displayName=`ExitPlanMode`;description=`Exit plan mode and return to normal agent operation`;static parametersSchema=q({planFilePath:K().describe(`Path to the plan file`)});parameters=e.parametersSchema;isReadonly=!0;async prepare(e,t){if(!e.planFilePath)return{error:`Plan not found`,skipPermission:!0};try{let n=await t.workspace.readRawFile(e.planFilePath);return n?{planContent:n}:{error:`Plan not found`,skipPermission:!0}}catch{return{error:`Plan not found`,skipPermission:!0}}}needsPermission(e,t,n){return!n?.skipPermission}async execute(e,t,n){if(n?.error)throw Error(n.error);return xy.info`Exiting plan mode with plan: ${e.planFilePath}`,{planFilePath:e.planFilePath}}format(e,t){return JSON.stringify({type:`exit_plan_mode`,status:`success`,...e.planFilePath&&{planFilePath:e.planFilePath}})}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`exit_plan_mode`,data:{},summary:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{return{phase:`success`,toolType:`exit_plan_mode`,data:JSON.parse(e),summary:`Plan approved`}}catch{}return e.includes(`implement the plan`),{phase:`success`,toolType:`exit_plan_mode`,data:{},summary:`Plan approved`}}},Cy;(function(e){e.GeneralPurpose=`GENERAL_PURPOSE`,e.Explore=`EXPLORE`,e.Plan=`PLAN`})(Cy||={});const wy={[Cy.GeneralPurpose]:{name:Cy.GeneralPurpose,displayName:`Agent`,description:`General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks`,allowedTools:[`*`],defaultModel:`CLAUDE_V4_5_SONNET`},[Cy.Explore]:{name:Cy.Explore,displayName:`Explore`,description:`Fast agent specialized for exploring codebases. Use for finding files by patterns, searching code for keywords, or answering questions about the codebase.`,allowedTools:[`read`,`glob`,`grep`,`bash`,`web_fetch`,`web_search`],defaultModel:`CLAUDE_V4_5_HAIKU`},[Cy.Plan]:{name:Cy.Plan,displayName:`Plan`,description:`Fast agent for creating implementation plans. Explores codebase to understand architecture before planning.`,allowedTools:[`read`,`glob`,`grep`,`bash`,`web_fetch`,`web_search`],defaultModel:`CLAUDE_V4_5_HAIKU`}},Ty=new Set(Object.values(Cy));function Ey(e){return Ty.has(e)}function Dy(e){if(Ey(e))return e}function Oy(e){return wy[e]}function ky(){return Object.values(Cy)}function Ay(e){let t=Dy(e);return t?Oy(t).displayName:e}function jy(e,t){let n=Dy(e);if(!n)return!1;let r=Oy(n);return r.allowedTools.includes(`*`)?!0:r.allowedTools.includes(t)}const My=/[ \t()[\]{};|*?$`'"#&<>!~]/;function Ny(e){return e.replace(RegExp(`\\\\([${My.source.slice(1,-1)}])`,`g`),`$1`)}const Py=N.homedir();function Fy(e){return e===`~`?Py:e.startsWith(`~/`)?E.join(Py,e.slice(2)):e}function Iy(e,t){return E.isAbsolute(e)?(E.relative(t,e)||e).split(E.sep).join(`/`):e.startsWith(`./`)||e.startsWith(`.\\`)?e.slice(2):e}function Ly(e){let t=E.resolve(e);try{return v(t)}catch{try{let e=E.dirname(t),n=E.basename(t);return E.join(v(e),n)}catch{return t}}}function Ry(e){return!!e&&!e.startsWith(`..`)&&!E.isAbsolute(e)}function zy(e,t){let n=E.resolve(e),r=E.resolve(t);if(n===r||Ry(E.relative(r,n)))return!0;let i=Ly(n),a=Ly(r);return i===a?!0:Ry(E.relative(a,i))}function By(e,t){let n=E.resolve(e),r=E.resolve(t),i=E.relative(r,n);if(Ry(i))return{success:!0,relativePath:i};let a=Ly(n),o=Ly(r);return i=E.relative(o,a),Ry(i)?{success:!0,relativePath:i}:{success:!1,reason:`outside_workspace`}}async function Vy(e){return new Promise(t=>setTimeout(t,e))}const Hy=it([`codellm`,`agent`,`loop`]);function Uy(e){if(!e)return null;if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e;if(t.text)return t.text;if(t.segment)return Uy(t.segment)}return null}function Wy(e){return Math.min((e+1)*2e3,1e4)}function Gy(e){return 2**(e+1)*1e3}function*Ky(e,t,n){if(e.error){let t=e.error,r=typeof t==`string`?t:JSON.stringify(t);r.includes(`Credit limit`)||r.includes(`no_usage_points`)||r.includes(`compute_point_budgeting`)||r.includes(`limit_exceeded`)||r.includes(`exhausted`)||r.includes(`purchase more credits`)?yield{__error:new qd({...n.pendingCreditLimitSegment??void 0,message:r})}:Ml(r)?yield{__error:new kl}:yield{__error:new Kd(r)};return}if(e.type===`no_usage_points`||e.type===`compute_point_budgeting`||e.type===`limit_exceeded`){n.pendingCreditLimitSegment=e;return}if(e.type===`code_llm_credits`){yield{type:`credits`,creditsUsed:e.creditsUsed};return}if(e.type===`collapsible_component`&&e.isThoughts===!0){let t=e.title||`Thinking`,n=Uy(e.segment)??``;n&&(yield{type:`thinking_delta`,content:n,title:t}),e.isSpinny===!1&&(yield{type:`thinking_complete`});return}if(e.type===`code_llm_notification`){let t=e.message||Uy(e.segment)||`Notification`;yield{...e,type:`notification`,message:t,severity:e.severity??`info`};return}if(e.type===`code_llm_agent_tool_call_start`){yield{type:`tool_call_start`,toolCallId:e.toolCallId,toolName:e.toolName};return}if(e.type===`code_llm_agent_tool_call_delta`){yield{type:`tool_call_delta`,toolCallId:e.toolCallId,argumentsDelta:e.argumentsDelta};return}if(e.type===`code_llm_agent_tool_call_stop`){yield{type:`tool_call_stop`,toolCallId:e.toolCallId,toolName:e.toolName,arguments:e.arguments};let n=e.toolUseRequest;if(n){let e=n;if(e.name===`edit`){let t=e.input;(`startLineOneIndexed`in t||`endLineOneIndexed`in t)&&(e={...e,input:{...t,startLine:t.startLineOneIndexed??t.startLine,endLine:t.endLineOneIndexed??t.endLine}})}t.push(e),yield{type:`tool_requested`,tool:e}}return}if(e.toolUseRequest){let n=(Array.isArray(e.toolUseRequest)?e.toolUseRequest:[e.toolUseRequest]).map(e=>{if(e.name===`edit`){let t=e.input;if(`startLineOneIndexed`in t||`endLineOneIndexed`in t)return{...e,input:{...t,startLine:t.startLineOneIndexed??t.startLine,endLine:t.endLineOneIndexed??t.endLine}}}return e}),r=new Set(t.map(e=>e.id)),i=n.filter(e=>!r.has(e.id));t.push(...i);for(let e of i)yield{type:`tool_requested`,tool:e};return}if(e.segment){let t=Uy(e.segment);t&&(yield{type:`text_delta`,content:t})}}async function*qy(e,t){let n=t?.generateRequestId?.()??crypto.randomUUID(),r=!1;Hy.debug(`Starting agent loop (conversationId={conversationId}, model={model})`,{conversationId:e.conversationId,model:e.model});for(let t=0;t<8;t++){Sl(`turn started`,`agent`);let i=n,a=!1;if(t>0){Hy.debug(`Retry attempt {attempt}: checking for pending request ID`,{attempt:t});try{let t=await e.apiClient.getPendingRequestIdForConversation(e.conversationId);t?.success&&t.result?.requestId&&(i=t.result.requestId,a=!0)}catch{}}let o=[],s={pendingCreditLimitSegment:null},c=!1;try{let t=e.apiClient.streamAgentMessage({deploymentConversationId:e.conversationId,message:e.message,supportedTools:e.supportedTools,supportedSubAgents:e.supportedSubAgents,mcpTools:e.isPrintMode?[]:e.mcpTools??[],workspacePath:e.workspacePath,...e.swapFolder&&{swapFolder:e.swapFolder},llmName:e.model,requestId:i,docInfos:e.uploadedDocs?Array.from(e.uploadedDocs):[],toolUseResult:e.toolResult,supportsV2:!0,supportsThoughtStreaming:e.supportsThoughtStreaming??!0,supportsParallelToolUse:!0,isPrintMode:e.isPrintMode??!1,...e.subagent&&{subagent:e.subagent},agentMode:e.agentMode,currentFile:e.currentFile,selectionStartLine:e.selectionStartLine,selectionEndLine:e.selectionEndLine,gitBranch:e.gitBranch,gitMain:e.gitMain,gitStatus:e.gitStatus,gitCommits:e.gitCommits,diagnosticIssues:e.diagnosticIssues,availableSkills:e.availableSkills,activeSkills:e.activeSkills,client:e.client,setFolder:e.setFolder,reconnect:a,signal:e.signal});for await(let n of t){if(e.signal?.aborted)break;for(let e of Ky(n,o,s)){if(`__error`in e)throw e.__error;yield e}c=!0}if(e.signal?.aborted){e.apiClient.stopResponseSSE(i).catch(()=>{}),yield{type:`turn_complete_with_tools`,toolCalls:o};return}r&&=(yield{type:`network_status`,online:!0},!1),yield{type:`turn_complete_with_tools`,toolCalls:o},Hy.debug(`Agent loop completed with {count} tool calls`,{count:o.length});return}catch(n){let i=n instanceof Error?n:Error(String(n));if(i instanceof kl){if(c&&t<4&&!e.signal?.aborted){let e=Gy(t);Hy.warn(`Auth error mid-stream (attempt={attempt}, delay={delayMs}ms) — retrying (server may have re-validated against a stale replica)`,{attempt:t+1,delayMs:e}),bl(`Mid-stream auth error, retrying`,`warning`,{context:`agent-loop`,attempt:t+1}),yield{type:`retry`,attempt:t+1,maxAttempts:5,delayMs:e,isNetworkError:!1},await Vy(e);continue}throw Hy.warn(`Auth expired, aborting loop`),i}if(i instanceof qd)throw Hy.warn(`Credit limit reached, aborting loop`),bl(`Credit limit reached`,`warning`,{context:`agent-loop`}),i;let a=Nl(i),o=a?8:5;if(t<o-1&&!e.signal?.aborted){let e=a?Wy(t):Gy(t);Hy.warn(`Retrying after error (attempt={attempt}, network={isNetErr}, delay={delayMs}ms): {error}`,{attempt:t+1,isNetErr:a,delayMs:e,error:i.message}),a&&!r&&(r=!0,yield{type:`network_status`,online:!1}),yield{type:`retry`,attempt:t+1,maxAttempts:o,delayMs:e,isNetworkError:a},await Vy(e);continue}throw Hy.error(`All retry attempts exhausted: {error}`,{error:i.message}),yl(i,{context:`agent-loop-retry-exhausted`}),Nl(i)?i instanceof Al?i:new Al(i.message,i):i}}}const Jy=it([`codellm`,`agent`,`runner`]);var Yy=class{queue=[];resolvers=[];closed=!1;push(e){this.closed||(this.resolvers.length>0?this.resolvers.shift()(e):this.queue.push(e))}async next(){return this.queue.length>0?this.queue.shift():this.closed?null:new Promise(e=>{this.resolvers.push(e)})}close(){this.closed=!0;for(let e of this.resolvers)e(null);this.resolvers=[]}drain(){let e=[...this.queue];return this.queue=[],e}};function Xy(e){return e.toUpperCase().includes(`CLAUDE`)}async function*Zy(e,t,n){let r=e.maxTurns??2**53-1,i=t,a,o=0,s=0,c=[],l=e.agentMode;Jy.info(`Starting agent conversation (model={model}, maxTurns={maxTurns})`,{model:e.model,maxTurns:r});try{for(;o<r;){if(n?.aborted)return Jy.info(`Conversation aborted after {numTurns} turns`,{numTurns:o}),{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!1,error:Error(`Execution cancelled`)};o++;let t={...e,swapFolder:a===void 0?e.swapFolder:void 0,setFolder:a===void 0?e.setFolder:void 0,agentMode:l,message:i,...a!==void 0&&{toolResult:a},...n!==void 0&&{signal:n}},r=[],u=new Map,d=new Map,f=new Map,p=[],m=new Yy,h=new AbortController,g=()=>h.abort(`interrupted`);n&&(n.aborted?h.abort(`interrupted`):n.addEventListener(`abort`,g,{once:!0}));let _=async(t,n,r)=>(await e.executeTools([t],n,r))[0],v=e.getConcurrency??(()=>!1),y=e=>{let t=_(e,h.signal,e=>m.push(e)).then(t=>{d.set(e.id,t);for(let[t,n]of f)if(n===e.id){f.delete(t);break}return t}).catch(e=>{throw h.abort(`sibling_tool_failed`),e});u.set(e.id,t)},b=e=>{let t=v(e);typeof t==`string`&&f.has(t)?p.push(e):(typeof t==`string`&&f.set(t,e.id),y(e))},x=!1;for await(let e of qy(t)){for(let e of m.drain())e.type===`mode_changed`&&(l=e.mode),yield e;if(e.type===`turn_complete_with_tools`){r=e.toolCalls,x=!0;continue}if(e.type===`text_delta`&&c.push(e.content),e.type===`tool_requested`){yield e,b(e.tool);continue}yield e}for(let e of m.drain())e.type===`mode_changed`&&(l=e.mode),yield e;if(x||Jy.warn(`Agent loop exited without turn_complete_with_tools (collected {count} tool calls)`,{count:r.length}),r.length===0){Jy.debug(`Turn {numTurns} complete with no tool calls`,{numTurns:o}),n?.removeEventListener(`abort`,g),yield{type:`turn_complete`};break}for(let e of p){let t=v(e);if(typeof t==`string`&&f.has(t)){let e=f.get(t),n=u.get(e);if(n)try{await n}catch{}}h.signal.aborted||b(e)}let S=r.filter(e=>!u.has(e.id));if(S.length>0)if(u.size===0){let t,n=e.executeTools(r,h.signal,e=>m.push(e)).then(e=>{t=e;for(let t=0;t<e.length;t++){let n=r[t];n&&d.set(n.id,e[t])}return m.close(),e}),i=new Set;for(;t===void 0;){let e=await Promise.race([m.next(),n.then(()=>null)]);if(e!==null)e.type===`mode_changed`&&(l=e.mode),e.type===`tool_execution_complete`&&i.add(e.tool.id),yield e;else if(t!==void 0)break}t||=await n;for(let e of m.drain())e.type===`mode_changed`&&(l=e.mode),e.type===`tool_execution_complete`&&i.add(e.tool.id),yield e;for(let e=0;e<t.length;e++){let n=r[e],a=t[e];n&&a&&!i.has(n.id)&&(yield{type:`tool_execution_complete`,tool:n,result:a})}}else for(let e of S)h.signal.aborted||y(e);if(u.size>0){let e=Promise.allSettled(u.values()).then(()=>{m.close()}),t=new Set,n=await m.next();for(;n!==null;)n.type===`mode_changed`&&(l=n.mode),n.type===`tool_execution_complete`&&t.add(n.tool.id),yield n,n=await m.next();await e;for(let e of r){let n=d.get(e.id);n&&!t.has(e.id)&&(yield{type:`tool_execution_complete`,tool:e,result:n})}}s+=r.length;let C=r.map(e=>d.get(e.id)??{id:e.id,content:`Error: tool execution did not complete`});n?.removeEventListener(`abort`,g);for(let t of e.drainEvents?.()??[])t.type===`mode_changed`&&(l=t.mode),yield t;let w=new Set([`task`]),T=(e,t)=>!(!e.rejected||w.has(r[t]?.name??``)),E=C.some((e,t)=>{if(!T(e,t))return!1;try{return JSON.parse(e.content).reason===ey.REJECTED}catch{return!1}}),D=C.some((e,t)=>{if(!T(e,t))return!1;try{return JSON.parse(e.content).reason===ey.INTERRUPTED}catch{return!1}}),O=C.some(e=>{if(!e.rejected)return!1;try{return JSON.parse(e.content).reason===ey.USER_MESSAGE}catch{return!1}});if((E||D)&&!O){yield{type:`turn_complete`};break}let k=C.map(({parsedResult:e,...t})=>t);a=k.length===1?k[0]:k;let A=r.some(e=>e.name===`exit_plan_mode`)&&C.some(e=>{if(e.rejected)return!1;try{return JSON.parse(e.content).type===`exit_plan_mode`}catch{return!1}}),j=`I want you to start implementing the plan now as you have outlined in your plan.`,M=e.getQueuedMessage?.();if(M)if(Xy(e.model))i=A?`${j} ${M}`:M,e.clearQueuedMessage?.(),e.isQueuedMessageHidden?.()||(yield{type:`user_message_dequeued`,content:M});else{yield{type:`turn_complete`};break}else i=A?j:``;yield{type:`turn_complete`}}if(o>=r){Jy.warn(`Maximum turns ({maxTurns}) exceeded`,{maxTurns:r});let e=Error(`Maximum turns (${r}) exceeded`);return yield{type:`error`,error:e},{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!1,error:e}}return Jy.info(`Conversation completed (turns={numTurns}, toolCalls={toolCallsExecuted})`,{numTurns:o,toolCallsExecuted:s}),{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!0}}catch(e){let t=e instanceof Error?e:Error(String(e));return yl(t,{context:`agent-runner`}),Jy.error(`Conversation failed after {numTurns} turns: {error}`,{numTurns:o,toolCallsExecuted:s,error:t}),yield{type:`error`,error:t},{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!1,error:t}}}const Qy=it([`codellm`,`agent`,`subagent`]);function $y(e,t){let n=Oy(t);return!n||n.allowedTools.includes(`*`)?e:e.filter(e=>jy(t,e.name))}function eb(e,t,n,r,i){let a=n.get(e.name)?.displayName??e.name;if(!n.isBuiltinRequest(e))return{type:`generic`,tool:e,displayName:a,toolName:a,inputSummary:JSON.stringify(e.input??{}).slice(0,200)};switch(e.name){case`read`:{let n=t._prepareResult;if(n?.resolvedPath){let t=Ly(n.resolvedPath);return{type:`read_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t)}}return{type:`generic`,tool:e,displayName:a,toolName:a,inputSummary:JSON.stringify(e.input??{}).slice(0,200)}}case`edit`:{let n=t._prepareResult;if(n?.outsideWorkspace){let t=Ly(n.resolvedPath??e.input.filePath??``);return{type:`edit_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t)}}return{type:`edit_file`,tool:e,displayName:a,filePath:e.input.filePath??``,originalContent:n?.currentContent??``,newContent:n?.newContent??``}}case`write`:{let n=t._prepareResult;if(n?.outsideWorkspace){let t=Ly(n.resolvedPath??e.input.filePath??``);return{type:`write_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t),isNewFile:!n?.fileExists}}return{type:`write_file`,tool:e,displayName:a,filePath:e.input.filePath??``,originalContent:n?.currentContent??``,content:e.input.content??``,isNewFile:!n?.fileExists}}case`bash`:return{type:`run_terminal`,tool:e,displayName:a,command:e.input.command??``,cwd:r,background:!!(e.input.runInBackground??!1),unmatchedPatterns:i?.getUnmatchedBashSegments(e.input.command??``)??[]};case`notebook_edit`:{let n=t._prepareResult;if(n?.outsideWorkspace){let t=Ly(n.resolvedPath??e.input.notebookPath??``);return{type:`notebook_edit_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t)}}let r=n?.notebook,i=e.input.cellId,o=``;if(i&&r?.cells){let e=r.cells.find(e=>e.id===i||e.metadata?.id===i);e&&(o=Array.isArray(e.source)?e.source.join(``):String(e.source??``))}return{type:`notebook_edit`,tool:e,displayName:a,notebookPath:e.input.notebookPath??``,cellId:i,editMode:e.input.editMode??`replace`,cellType:e.input.cellType,originalContent:o,newContent:e.input.newSource??``}}case`ask_user_question`:return{type:`ask_user_question`,tool:e,displayName:a,questions:Array.isArray(e.input.questions)?e.input.questions:[]};case`exit_plan_mode`:{let n=t._prepareResult;return{type:`exit_plan_mode`,tool:e,displayName:a,planFilePath:e.input.planFilePath??``,planContent:n?.planContent??``}}default:return{type:`generic`,tool:e,displayName:a,toolName:a,inputSummary:JSON.stringify(e.input??{}).slice(0,200)}}}async function tb(e){let{prompt:t,subagentType:n,model:r,resume:i,parentContext:a,onProgress:o,signal:s}=e;Qy.info(`Starting subagent (type={subagentType}, model={model})`,{subagentType:n,model:r??`default`});let c=Oy(n);if(!c)return Qy.error(`Unknown subagent type: {subagentType}`,{subagentType:n}),{success:!1,output:``,toolsExecuted:[],toolCalls:[],numTurns:0,error:`Unknown subagent type: ${n}`};let l=Lw(),u=$y(l.getApiToolDefinitions(),n),d=r??c.defaultModel??`CLAUDE_V4_5_SONNET`,f;if(i&&c.supportsResume)f=i;else try{let e=await a.apiClient.createCodellmDeploymentConversation(`CODE_LLM_NON_INTERACTIVE`,a.clientType);if(!e?.result?.deploymentConversationId)return{success:!1,output:``,toolsExecuted:[],toolCalls:[],numTurns:0,error:`Failed to create subagent conversation: no conversation ID returned`};f=e.result.deploymentConversationId}catch(e){return{success:!1,output:``,toolsExecuted:[],toolCalls:[],numTurns:0,error:`Failed to create subagent conversation: ${e instanceof Error?e.message:String(e)}`}}let p=[],m=[],h=[],g=a.permissionProvider&&a.rulesEngine&&a.getAgentMode,_=()=>a.getAgentMode?.()??Wd.Yolo,v=c?.name,y={apiClient:a.apiClient,conversationId:f,model:d,workspacePath:a.workspacePath,supportedTools:u,mcpTools:[],uploadedDocs:a.uploadedDocs,isPrintMode:!g,...v&&{subagent:v},supportsThoughtStreaming:!0,agentMode:_(),executeTools:async(e,t,n)=>{let r=[];for(let i of e){if(t?.aborted||s?.aborted)break;m.push(i.name);let e={name:i.name,input:i.input??{}};o?.({type:`tool_requested`,content:`${i.name}`,toolName:i.name,toolInput:e.input,toolId:i.id}),n?.({type:`tool_execution_start`,tool:i});let c=_(),u={...a,toolCallId:i.id,conversationId:f,agentMode:c,status:`executing`};try{let d=l.createToolInstance(i.name,i.input??{},u);await d.prepare();let f=c===Wd.Yolo&&i.name!==`ask_user_question`;if(g&&!f&&d.needsPermission()){let c=l.get(i.name)?.displayName??i.name,f=Xw(i),p=a.rulesEngine.evaluate(c,f);if(p===`deny`){r.push({id:i.id,content:JSON.stringify({reason:ey.REJECTED}),rejected:!0}),e.result=`denied by rule`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(p!==`allow`){let c=eb(i,d,l,a.workspacePath,a.rulesEngine);if(a.permissionProvider.needsPermission(c)){n?.({type:`status_changed`,status:Gd.WaitingForToolPermission}),a.emitEvent?.({type:`status_changed`,status:Gd.WaitingForToolPermission});let l;try{let e=a.permissionProvider.requestPermission(c),n=t||s;if(n){let t,r=new Promise((e,r)=>{n.aborted?r(Error(`interrupted`)):(t=()=>r(Error(`interrupted`)),n.addEventListener(`abort`,t,{once:!0}))});try{l=await Promise.race([e,r])}finally{t&&n.removeEventListener(`abort`,t)}}else l=await e}catch{r.push({id:i.id,content:JSON.stringify({reason:ey.INTERRUPTED}),rejected:!0}),e.result=`interrupted`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(n?.({type:`status_changed`,status:Gd.ExecutingTool}),a.emitEvent?.({type:`status_changed`,status:Gd.ExecutingTool}),l===`reject`){r.push({id:i.id,content:JSON.stringify({reason:ey.REJECTED}),rejected:!0}),e.result=`rejected`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(typeof l==`object`&&l.type===`reject_with_message`){r.push({id:i.id,content:JSON.stringify({reason:ey.USER_MESSAGE,message:l.message}),rejected:!0}),e.result=`rejected`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(l===`allowAlways`||l===`allowYolo`||l===`accept`){if(l===`allowAlways`&&(c.type===`read_outside_directory`||c.type===`write_outside_directory`||c.type===`edit_outside_directory`||c.type===`notebook_edit_outside_directory`)&&`deducedDirectory`in c){let e=a.allowEditingPaths??[],t=c.deducedDirectory;e.includes(t)||e.push(t)}else if(i.name===`exit_plan_mode`){let e=l===`allowYolo`?Wd.Yolo:l===`allowAlways`?Wd.AcceptEdits:Wd.Normal;a.setAgentMode?.(e),u.agentMode=e,n?.({type:`mode_changed`,mode:e})}else if(l===`allowAlways`){let e=Xd(c.type);a.setAgentMode?.(e),u.agentMode=e,n?.({type:`mode_changed`,mode:e})}}if(typeof l==`object`&&l.type===`accept_with_message`){r.push({id:i.id,content:JSON.stringify({reason:ey.USER_MESSAGE,message:l.message}),rejected:!0}),e.result=`accepted with message`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(typeof l==`object`&&l.type===`question_answers`&&d.mergeParams({answers:l.answers}),typeof l==`object`&&l.type===`allow_always_with_rule`&&a.rulesEngine.addAllowRule(l.rule),typeof l==`object`&&l.type===`allow_always_with_rules`)for(let e of l.rules)a.rulesEngine.addAllowRule(e)}}}i.name===`enter_plan_mode`&&(a.setAgentMode?.(Wd.PlanMode),u.agentMode=Wd.PlanMode,n?.({type:`mode_changed`,mode:Wd.PlanMode})),i.name===`exit_plan_mode`&&f&&(a.setAgentMode?.(Wd.Normal),u.agentMode=Wd.Normal,n?.({type:`mode_changed`,mode:Wd.Normal})),await d.execute();let p=d.formatResultForLLM(),m=d.formatResult(),_=typeof p==`string`?p:JSON.stringify(p),v=l.parse(i.name,m);r.push({id:i.id,content:_,parsedResult:v}),e.result=_}catch(t){let n=t instanceof Error?t.message:String(t);r.push({id:i.id,content:`Error: ${n}`}),e.result=`Error: ${n}`}h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id})}for(let t of e)r.some(e=>e.id===t.id)||r.push({id:t.id,content:JSON.stringify({reason:ey.INTERRUPTED}),rejected:!0});return r}};try{o?.({type:`status`,content:`Starting ${n} agent...`});let e=Zy(y,t,s),r=await e.next();for(;!r.done;){let t=r.value;switch(t.type){case`text_delta`:p.push(t.content),o?.({type:`text`,content:t.content});break;case`thinking_delta`:o?.({type:`thinking`,content:t.content});break;case`tool_requested`:case`turn_complete`:break;case`tool_execution_complete`:p.length=0;break;case`error`:return{success:!1,output:p.join(``),toolsExecuted:m,toolCalls:h,numTurns:0,error:t.error?.message??`Unknown error`};case`credits`:a.emitEvent?.(t);break;case`mode_changed`:a.emitEvent?.(t);break;case`status_changed`:case`notification`:break}r=await e.next()}let i=r.value;return Qy.info(`Subagent completed (type={subagentType}, turns={numTurns}, tools={toolCount})`,{subagentType:n,numTurns:i.numTurns,toolCount:m.length}),{success:i.success,output:p.join(``),toolsExecuted:m,toolCalls:h,numTurns:i.numTurns,...i.error&&{error:i.error.message}}}catch(e){let t=e instanceof Error?e.message:String(e);return yl(e instanceof Error?e:Error(t),{context:`subagent-runner`}),Qy.error(`Subagent failed (type={subagentType}): {error}`,{subagentType:n,error:t}),{success:!1,output:p.join(``),toolsExecuted:m,toolCalls:h,numTurns:0,error:t}}}const nb=it([`codellm`,`agent`,`tools`,`task`]);var rb=class e extends oy{name=`task`;displayName=`Task`;description=`Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
50
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function fg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:hg(t,`input`,e.processors),output:hg(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function pg(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return pg(r.element,n);if(r.type===`set`)return pg(r.valueType,n);if(r.type===`lazy`)return pg(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return pg(r.innerType,n);if(r.type===`intersection`)return pg(r.left,n)||pg(r.right,n);if(r.type===`record`||r.type===`map`)return pg(r.keyType,n)||pg(r.valueType,n);if(r.type===`pipe`)return pg(r.in,n)||pg(r.out,n);if(r.type===`object`){for(let e in r.shape)if(pg(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(pg(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(pg(e,n))return!0;return!!(r.rest&&pg(r.rest,n))}return!1}const mg=(e,t={})=>n=>{let r=lg({...n,processors:t});return ug(e,r),dg(r,e),fg(r,e)},hg=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=lg({...i??{},target:a,io:t,processors:n});return ug(e,o),dg(o,e),fg(o,e)},gg={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},_g=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=gg[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},vg=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},yg=(e,t,n,r)=>{n.type=`boolean`},bg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`BigInt cannot be represented in JSON Schema`)},xg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Symbols cannot be represented in JSON Schema`)},Sg=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},Cg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Undefined cannot be represented in JSON Schema`)},wg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Void cannot be represented in JSON Schema`)},Tg=(e,t,n,r)=>{n.not={}},Eg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Date cannot be represented in JSON Schema`)},Dg=(e,t,n,r)=>{let i=e._zod.def,a=nf(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Og=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},kg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`NaN cannot be represented in JSON Schema`)},Ag=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},jg=(e,t,n,r)=>{let i=n,a={type:`string`,format:`binary`,contentEncoding:`binary`},{minimum:o,maximum:s,mime:c}=e._zod.bag;o!==void 0&&(a.minLength=o),s!==void 0&&(a.maxLength=s),c?c.length===1?(a.contentMediaType=c[0],Object.assign(i,a)):(Object.assign(i,a),i.anyOf=c.map(e=>({contentMediaType:e}))):Object.assign(i,a)},Mg=(e,t,n,r)=>{n.type=`boolean`},Ng=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Pg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Function types cannot be represented in JSON Schema`)},Fg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Ig=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Map cannot be represented in JSON Schema`)},Lg=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Set cannot be represented in JSON Schema`)},Rg=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=ug(a.element,t,{...r,path:[...r.path,`items`]})},zg=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=ug(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=ug(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Bg=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>ug(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Vg=(e,t,n,r)=>{let i=e._zod.def,a=ug(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=ug(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Hg=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>ug(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?ug(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null;t.target===`draft-2020-12`?(i.prefixItems=c,l&&(i.items=l)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),i.minItems=c.length,l||(i.maxItems=c.length)):(i.items=c,l&&(i.additionalItems=l));let{minimum:u,maximum:d}=e._zod.bag;typeof u==`number`&&(i.minItems=u),typeof d==`number`&&(i.maxItems=d)},Ug=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=ug(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=ug(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=ug(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Wg=(e,t,n,r)=>{let i=e._zod.def,a=ug(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Gg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Kg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},qg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Jg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Yg=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;ug(a,t,r);let o=t.seen.get(e);o.ref=a},Xg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Zg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Qg=(e,t,n,r)=>{let i=e._zod.def;ug(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},$g=(e,t,n,r)=>{let i=e._zod.innerType;ug(i,t,r);let a=t.seen.get(e);a.ref=i},e_=G(`ZodISODateTime`,(e,t)=>{_m.init(e,t),T_.init(e,t)});function t_(e){return Sh(e_,e)}const n_=G(`ZodISODate`,(e,t)=>{vm.init(e,t),T_.init(e,t)});function r_(e){return Ch(n_,e)}const i_=G(`ZodISOTime`,(e,t)=>{ym.init(e,t),T_.init(e,t)});function a_(e){return wh(i_,e)}const o_=G(`ZodISODuration`,(e,t)=>{bm.init(e,t),T_.init(e,t)});function s_(e){return Th(o_,e)}const c_=(e,t)=>{Mf.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Pf(e,t)},flatten:{value:t=>Tee(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,rf,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,rf,2)}},isEmpty:{get(){return e.issues.length===0}}})};G(`ZodError`,c_);const l_=G(`ZodError`,c_,{Parent:Error}),u_=Ff(l_),d_=Lf(l_),f_=zf(l_),p_=Vf(l_),m_=Uf(l_),h_=Wf(l_),g_=Gf(l_),__=Kf(l_),v_=qf(l_),y_=Jf(l_),b_=Yf(l_),x_=Xf(l_),S_=G(`ZodType`,(e,t)=>(rm.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:hg(e,`input`),output:hg(e,`output`)}}),e.toJSONSchema=mg(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(ff(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Sf(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>u_(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>f_(e,t,n),e.parseAsync=async(t,n)=>d_(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>p_(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>m_(e,t,n),e.decode=(t,n)=>h_(e,t,n),e.encodeAsync=async(t,n)=>g_(e,t,n),e.decodeAsync=async(t,n)=>__(e,t,n),e.safeEncode=(t,n)=>v_(e,t,n),e.safeDecode=(t,n)=>y_(e,t,n),e.safeEncodeAsync=async(t,n)=>b_(e,t,n),e.safeDecodeAsync=async(t,n)=>x_(e,t,n),e.refine=(t,n)=>e.check(qv(t,n)),e.superRefine=t=>e.check(Jv(t)),e.overwrite=t=>e.check(Qh(t)),e.optional=()=>Ov(e),e.exactOptional=()=>Av(e),e.nullable=()=>Mv(e),e.nullish=()=>Ov(Mv(e)),e.nonoptional=t=>Rv(e,t),e.array=()=>cv(e),e.or=t=>fv([e,t]),e.and=t=>gv(e,t),e.transform=t=>Hv(e,Ev(t)),e.default=t=>Pv(e,t),e.prefault=t=>Iv(e,t),e.catch=t=>Bv(e,t),e.pipe=t=>Hv(e,t),e.readonly=()=>Wv(e),e.describe=t=>{let n=e.clone();return sh.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return sh.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return sh.get(e);let n=e.clone();return sh.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),C_=G(`_ZodString`,(e,t)=>{im.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_g(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Gh(...t)),e.includes=(...t)=>e.check(Jh(...t)),e.startsWith=(...t)=>e.check(Yh(...t)),e.endsWith=(...t)=>e.check(Xh(...t)),e.min=(...t)=>e.check(Uh(...t)),e.max=(...t)=>e.check(Hh(...t)),e.length=(...t)=>e.check(Wh(...t)),e.nonempty=(...t)=>e.check(Uh(1,...t)),e.lowercase=t=>e.check(Kh(t)),e.uppercase=t=>e.check(qh(t)),e.trim=()=>e.check(eg()),e.normalize=(...t)=>e.check($h(...t)),e.toLowerCase=()=>e.check(tg()),e.toUpperCase=()=>e.check(ng()),e.slugify=()=>e.check(rg())}),w_=G(`ZodString`,(e,t)=>{im.init(e,t),C_.init(e,t),e.email=t=>e.check(mte(E_,t)),e.url=t=>e.check(lh(k_,t)),e.jwt=t=>e.check(xh(G_,t)),e.emoji=t=>e.check(yte(j_,t)),e.guid=t=>e.check(ch(D_,t)),e.uuid=t=>e.check(hte(O_,t)),e.uuidv4=t=>e.check(gte(O_,t)),e.uuidv6=t=>e.check(_te(O_,t)),e.uuidv7=t=>e.check(vte(O_,t)),e.nanoid=t=>e.check(bte(M_,t)),e.guid=t=>e.check(ch(D_,t)),e.cuid=t=>e.check(xte(N_,t)),e.cuid2=t=>e.check(uh(P_,t)),e.ulid=t=>e.check(dh(F_,t)),e.base64=t=>e.check(vh(H_,t)),e.base64url=t=>e.check(yh(U_,t)),e.xid=t=>e.check(fh(I_,t)),e.ksuid=t=>e.check(ph(L_,t)),e.ipv4=t=>e.check(mh(R_,t)),e.ipv6=t=>e.check(hh(z_,t)),e.cidrv4=t=>e.check(gh(B_,t)),e.cidrv6=t=>e.check(_h(V_,t)),e.e164=t=>e.check(bh(W_,t)),e.datetime=t=>e.check(t_(t)),e.date=t=>e.check(r_(t)),e.time=t=>e.check(a_(t)),e.duration=t=>e.check(s_(t))});function K(e){return fte(w_,e)}const T_=G(`ZodStringFormat`,(e,t)=>{am.init(e,t),C_.init(e,t)}),E_=G(`ZodEmail`,(e,t)=>{cm.init(e,t),T_.init(e,t)}),D_=G(`ZodGUID`,(e,t)=>{om.init(e,t),T_.init(e,t)}),O_=G(`ZodUUID`,(e,t)=>{sm.init(e,t),T_.init(e,t)}),k_=G(`ZodURL`,(e,t)=>{lm.init(e,t),T_.init(e,t)});function A_(e){return lh(k_,e)}const j_=G(`ZodEmoji`,(e,t)=>{um.init(e,t),T_.init(e,t)}),M_=G(`ZodNanoID`,(e,t)=>{dm.init(e,t),T_.init(e,t)}),N_=G(`ZodCUID`,(e,t)=>{fm.init(e,t),T_.init(e,t)}),P_=G(`ZodCUID2`,(e,t)=>{pm.init(e,t),T_.init(e,t)}),F_=G(`ZodULID`,(e,t)=>{mm.init(e,t),T_.init(e,t)}),I_=G(`ZodXID`,(e,t)=>{hm.init(e,t),T_.init(e,t)}),L_=G(`ZodKSUID`,(e,t)=>{gm.init(e,t),T_.init(e,t)}),R_=G(`ZodIPv4`,(e,t)=>{xm.init(e,t),T_.init(e,t)});G(`ZodMAC`,(e,t)=>{Cm.init(e,t),T_.init(e,t)});const z_=G(`ZodIPv6`,(e,t)=>{Sm.init(e,t),T_.init(e,t)}),B_=G(`ZodCIDRv4`,(e,t)=>{wm.init(e,t),T_.init(e,t)}),V_=G(`ZodCIDRv6`,(e,t)=>{Tm.init(e,t),T_.init(e,t)}),H_=G(`ZodBase64`,(e,t)=>{Dm.init(e,t),T_.init(e,t)}),U_=G(`ZodBase64URL`,(e,t)=>{km.init(e,t),T_.init(e,t)}),W_=G(`ZodE164`,(e,t)=>{Am.init(e,t),T_.init(e,t)}),G_=G(`ZodJWT`,(e,t)=>{Mm.init(e,t),T_.init(e,t)});G(`ZodCustomStringFormat`,(e,t)=>{Nm.init(e,t),T_.init(e,t)});const K_=G(`ZodNumber`,(e,t)=>{Pm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vg(e,t,n,r),e.gt=(t,n)=>e.check(Ih(t,n)),e.gte=(t,n)=>e.check(Lh(t,n)),e.min=(t,n)=>e.check(Lh(t,n)),e.lt=(t,n)=>e.check(Ph(t,n)),e.lte=(t,n)=>e.check(Fh(t,n)),e.max=(t,n)=>e.check(Fh(t,n)),e.int=t=>e.check(Y_(t)),e.safe=t=>e.check(Y_(t)),e.positive=t=>e.check(Ih(0,t)),e.nonnegative=t=>e.check(Lh(0,t)),e.negative=t=>e.check(Ph(0,t)),e.nonpositive=t=>e.check(Fh(0,t)),e.multipleOf=(t,n)=>e.check(Rh(t,n)),e.step=(t,n)=>e.check(Rh(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function q_(e){return Eh(K_,e)}const J_=G(`ZodNumberFormat`,(e,t)=>{Fm.init(e,t),K_.init(e,t)});function Y_(e){return Oh(J_,e)}const X_=G(`ZodBoolean`,(e,t)=>{Im.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yg(e,t,n,r)});function Z_(e){return kh(X_,e)}const Q_=G(`ZodBigInt`,(e,t)=>{Lm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bg(e,t,n,r),e.gte=(t,n)=>e.check(Lh(t,n)),e.min=(t,n)=>e.check(Lh(t,n)),e.gt=(t,n)=>e.check(Ih(t,n)),e.gte=(t,n)=>e.check(Lh(t,n)),e.min=(t,n)=>e.check(Lh(t,n)),e.lt=(t,n)=>e.check(Ph(t,n)),e.lte=(t,n)=>e.check(Fh(t,n)),e.max=(t,n)=>e.check(Fh(t,n)),e.positive=t=>e.check(Ih(BigInt(0),t)),e.negative=t=>e.check(Ph(BigInt(0),t)),e.nonpositive=t=>e.check(Fh(BigInt(0),t)),e.nonnegative=t=>e.check(Lh(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Rh(t,n));let n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});G(`ZodBigIntFormat`,(e,t)=>{Eee.init(e,t),Q_.init(e,t)}),G(`ZodSymbol`,(e,t)=>{Dee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xg(e,t,n,r)}),G(`ZodUndefined`,(e,t)=>{Oee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cg(e,t,n,r)});const $_=G(`ZodNull`,(e,t)=>{kee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sg(e,t,n,r)});function ev(e){return Ah($_,e)}const tv=G(`ZodAny`,(e,t)=>{Aee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function nv(){return jh(tv)}const rv=G(`ZodUnknown`,(e,t)=>{jee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function iv(){return Mh(rv)}const av=G(`ZodNever`,(e,t)=>{Mee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Tg(e,t,n,r)});function ov(e){return Nh(av,e)}G(`ZodVoid`,(e,t)=>{Nee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wg(e,t,n,r)}),G(`ZodDate`,(e,t)=>{Pee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eg(e,t,n,r),e.min=(t,n)=>e.check(Lh(t,n)),e.max=(t,n)=>e.check(Fh(t,n));let n=e._zod.bag;e.minDate=n.minimum?new Date(n.minimum):null,e.maxDate=n.maximum?new Date(n.maximum):null});const sv=G(`ZodArray`,(e,t)=>{Fee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Rg(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Uh(t,n)),e.nonempty=t=>e.check(Uh(1,t)),e.max=(t,n)=>e.check(Hh(t,n)),e.length=(t,n)=>e.check(Wh(t,n)),e.unwrap=()=>e.element});function cv(e,t){return ig(sv,e,t)}const lv=G(`ZodObject`,(e,t)=>{Lee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zg(e,t,n,r),uf(e,`shape`,()=>t.shape),e.keyof=()=>Sv(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:iv()}),e.loose=()=>e.clone({...e._zod.def,catchall:iv()}),e.strict=()=>e.clone({...e._zod.def,catchall:ov()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>bee(e,t),e.safeExtend=t=>xee(e,t),e.merge=t=>See(e,t),e.pick=t=>vee(e,t),e.omit=t=>yee(e,t),e.partial=(...t)=>Cee(Dv,e,t[0]),e.required=(...t)=>wee(Lv,e,t[0])});function q(e,t){return new lv({type:`object`,shape:e??{},...Cf(t)})}function uv(e,t){return new lv({type:`object`,shape:e,catchall:iv(),...Cf(t)})}const dv=G(`ZodUnion`,(e,t)=>{Um.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bg(e,t,n,r),e.options=t.options});function fv(e,t){return new dv({type:`union`,options:e,...Cf(t)})}G(`ZodXor`,(e,t)=>{dv.init(e,t),Ree.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bg(e,t,n,r),e.options=t.options});const pv=G(`ZodDiscriminatedUnion`,(e,t)=>{dv.init(e,t),zee.init(e,t)});function mv(e,t,n){return new pv({type:`union`,options:t,discriminator:e,...Cf(n)})}const hv=G(`ZodIntersection`,(e,t)=>{Bee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vg(e,t,n,r)});function gv(e,t){return new hv({type:`intersection`,left:e,right:t})}const _v=G(`ZodTuple`,(e,t)=>{qm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hg(e,t,n,r),e.rest=t=>e.clone({...e._zod.def,rest:t})});function vv(e,t,n){let r=t instanceof rm;return new _v({type:`tuple`,items:e,rest:r?t:null,...Cf(r?n:t)})}const yv=G(`ZodRecord`,(e,t)=>{Vee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ug(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function bv(e,t,n){return new yv({type:`record`,keyType:e,valueType:t,...Cf(n)})}G(`ZodMap`,(e,t)=>{Hee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ig(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType,e.min=(...t)=>e.check(Bh(...t)),e.nonempty=t=>e.check(Bh(1,t)),e.max=(...t)=>e.check(zh(...t)),e.size=(...t)=>e.check(Vh(...t))}),G(`ZodSet`,(e,t)=>{Uee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lg(e,t,n,r),e.min=(...t)=>e.check(Bh(...t)),e.nonempty=t=>e.check(Bh(1,t)),e.max=(...t)=>e.check(zh(...t)),e.size=(...t)=>e.check(Vh(...t))});const xv=G(`ZodEnum`,(e,t)=>{Wee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Dg(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new xv({...t,checks:[],...Cf(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new xv({...t,checks:[],...Cf(r),entries:i})}});function Sv(e,t){return new xv({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...Cf(t)})}const Cv=G(`ZodLiteral`,(e,t)=>{Gee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Og(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function wv(e,t){return new Cv({type:`literal`,values:Array.isArray(e)?e:[e],...Cf(t)})}G(`ZodFile`,(e,t)=>{Kee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jg(e,t,n,r),e.min=(t,n)=>e.check(Bh(t,n)),e.max=(t,n)=>e.check(zh(t,n)),e.mime=(t,n)=>e.check(Zh(Array.isArray(t)?t:[t],n))});const Tv=G(`ZodTransform`,(e,t)=>{qee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fg(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new $d(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Af(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Af(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Ev(e){return new Tv({type:`transform`,transform:e})}const Dv=G(`ZodOptional`,(e,t)=>{Qm.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ov(e){return new Dv({type:`optional`,innerType:e})}const kv=G(`ZodExactOptional`,(e,t)=>{Jee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Av(e){return new kv({type:`optional`,innerType:e})}const jv=G(`ZodNullable`,(e,t)=>{Yee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mv(e){return new jv({type:`nullable`,innerType:e})}const Nv=G(`ZodDefault`,(e,t)=>{Xee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Pv(e,t){return new Nv({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():yf(t)}})}const Fv=G(`ZodPrefault`,(e,t)=>{Zee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Iv(e,t){return new Fv({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():yf(t)}})}const Lv=G(`ZodNonOptional`,(e,t)=>{Qee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Rv(e,t){return new Lv({type:`nonoptional`,innerType:e,...Cf(t)})}G(`ZodSuccess`,(e,t)=>{$ee.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const zv=G(`ZodCatch`,(e,t)=>{ete.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Bv(e,t){return new zv({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}G(`ZodNaN`,(e,t)=>{tte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>kg(e,t,n,r)});const Vv=G(`ZodPipe`,(e,t)=>{nte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yg(e,t,n,r),e.in=t.in,e.out=t.out});function Hv(e,t){return new Vv({type:`pipe`,in:e,out:t})}G(`ZodCodec`,(e,t)=>{Vv.init(e,t),rte.init(e,t)});const Uv=G(`ZodReadonly`,(e,t)=>{ite.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Wv(e){return new Uv({type:`readonly`,innerType:e})}G(`ZodTemplateLiteral`,(e,t)=>{ate.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ag(e,t,n,r)}),G(`ZodLazy`,(e,t)=>{cte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$g(e,t,n,r),e.unwrap=()=>e._zod.def.getter()}),G(`ZodPromise`,(e,t)=>{ste.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zg(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),G(`ZodFunction`,(e,t)=>{ote.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Pg(e,t,n,r)});const Gv=G(`ZodCustom`,(e,t)=>{lte.init(e,t),S_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ng(e,t,n,r)});function Kv(e,t){return ag(Gv,e??(()=>!0),t)}function qv(e,t={}){return og(Gv,e,t)}function Jv(e){return sg(e)}function Yv(e,t){return Hv(Ev(e),t)}const Xv={invalid_type:`invalid_type`,too_big:`too_big`,too_small:`too_small`,invalid_format:`invalid_format`,not_multiple_of:`not_multiple_of`,unrecognized_keys:`unrecognized_keys`,invalid_union:`invalid_union`,invalid_key:`invalid_key`,invalid_element:`invalid_element`,invalid_value:`invalid_value`,custom:`custom`};var Zv;(function(e){})(Zv||={});function Qv(e){return pte(w_,e)}function $v(e){return Dh(K_,e)}const ey={USER_MESSAGE:`user_message`,REJECTED:`rejected`,INTERRUPTED:`interrupted`},ty={REJECTED:`rejected`};function ny(e){if(e===`Tool was rejected by user`)return{rejected:!0};try{let t=JSON.parse(e);if(t.reason===ey.USER_MESSAGE)return{rejected:!0,userNote:t.message};if(t.reason===ey.REJECTED||t.reason===ey.INTERRUPTED)return{rejected:!0};if(t.status===ty.REJECTED)return{rejected:!0,userNote:t.userNote}}catch{}return{rejected:!1}}const ry=`sibling_tool_failed`,iy=JSON.stringify({type:ry,message:`Not executed: a tool call in a preceding parallel batch failed`});function ay(e){try{return JSON.parse(e)?.type===ry}catch{return!1}}var oy=class{concurrency(e,t){return!1}includeInApiDefinitions=!0;isEnabled(e){return!0}async prepare(e,t){return null}needsPermission(e,t,n){return!this.isReadonly}format(e,t){return typeof e==`string`?e:JSON.stringify(e)}formatForLLM(e,t){return this.format(e,t)}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:this.name,data:{},summary:t.userNote?`Rejected \u00b7 "${t.userNote}"`:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e),n=`success`;return t.status===`error`?n=`error`:t.status===`skipped`&&(n=`skipped`),{phase:n,toolType:t.type??this.name,data:t,summary:t.message??t.summary??`Completed`,...t.errorMessage!==void 0&&{errorMessage:t.errorMessage}}}catch{}return e.startsWith(`Error:`)?{phase:`error`,toolType:this.name,data:{},summary:e,errorMessage:e}:{phase:`success`,toolType:this.name,data:{},summary:`Completed`}}validateParams(e){return this.parameters.parse(e)}getToolDefinition(){let e=this.getParameterNames();return{name:this.name,description:this.description,arguments:e}}getParameterNames(){return Object.keys(this.parameters.shape)}};const sy=Symbol.for(`server-executed`);var cy=class extends oy{isReadonly=!0;async execute(e,t,n){return sy}format(e,t){return JSON.stringify({type:this.name,status:`server-executed`})}};it([`codellm`,`agent`,`tools`,`subagent`]);var ly=class e extends cy{name=`subagent`;displayName=`Subagent`;description=`Switch to a different subagent for a task`;static parametersSchema=q({agent:K().describe(`The name of the subagent to switch to`),task:K().describe(`The task description for the subagent`)});parameters=e.parametersSchema;needsPermission(){return!1}format(e,t){return JSON.stringify({type:`subagent`,status:`success`,agent:t.agent,task:t.task})}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`subagent`,data:{},summary:t.userNote?`Rejected \u00b7 "${t.userNote}"`:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e);return{phase:`success`,toolType:`subagent`,data:t,summary:`Delegated to ${t.agent??`explore`} agent`}}catch{}return{phase:`success`,toolType:`subagent`,data:{},summary:`Delegated`}}};it([`codellm`,`agent`,`tools`,`todo-write`]);var uy=class e extends cy{name=`todo_write`;displayName=`TodoWrite`;description=`Create and manage a structured task list`;static parametersSchema=q({todos:Yv(e=>{if(e==null)return[];if(typeof e==`string`)try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}return Array.isArray(e)?e:[]},cv(q({content:K().describe(`The task content`),status:Sv([`pending`,`in_progress`,`completed`,`cancelled`]).describe(`The status of the task`),id:K().optional().describe(`Optional task ID`)}))).describe(`Array of todo items`)});parameters=e.parametersSchema;needsPermission(){return!1}format(e,t){return`Updated`}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`todo_write`,data:{},summary:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e);if(t.todos){let e=t.todos;return{phase:`success`,toolType:`todo_write`,data:t,summary:`${e.filter(e=>e.status===`pending`).length} pending, ${e.filter(e=>e.status===`in_progress`).length} in progress, ${e.filter(e=>e.status===`completed`).length} completed`}}}catch{}return{phase:`success`,toolType:`todo_write`,data:{},summary:`Updated`}}};function dy(e){if(typeof e!=`string`)return e;let t=e.trim();return t?Number(t):NaN}function fy(e){if(typeof e!=`string`)return e;let t=e.trim().toLowerCase();return[`true`,`1`,`yes`,`y`].includes(t)?!0:[`false`,`0`,`no`,`n`].includes(t)?!1:e}const py=Yv(dy,q_()),my=Yv(dy,q_().optional()),hy=Yv(fy,Z_()),gy=Yv(fy,Z_().optional()),_y=it([`codellm`,`agent`,`tools`,`ask-user`]);var vy=class e extends oy{isReadonly=!0;name=`ask_user_question`;displayName=`AskUserQuestion`;description=`Ask the user questions during execution to gather preferences, clarify instructions, or get decisions on implementation choices`;static parametersSchema=q({questions:cv(q({question:K().describe(`The question to ask the user`),header:K().describe(`A header/title for the question`),options:cv(q({label:K().describe(`The option label`),description:K().describe(`A description of the option`)})).describe(`Array of options for the user to select from`),multiSelect:hy.describe(`Whether the user can select multiple options`)})).describe(`Array of questions to ask the user`),answers:bv(K(),K()).optional().describe(`User-provided answers to the questions`)});parameters=e.parametersSchema;needsPermission(){return!0}async execute(e){return _y.debug`Asking user ${e.questions.length} question(s)`,{answers:e.answers||{}}}format(e,t){return JSON.stringify({type:`ask_user_question`,status:`success`,answers:e.answers})}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`ask_user_question`,data:{},summary:`Cancelled`,...t.userNote!==void 0&&{userNote:t.userNote}};try{let t=JSON.parse(e),n=t.answers,r=n?Object.keys(n).length:0;return{phase:`success`,toolType:`ask_user_question`,data:t,summary:`Answered ${r} question${r===1?``:`s`}`}}catch{}return{phase:`success`,toolType:`ask_user_question`,data:{},summary:`Answered`}}};const yy=it([`codellm`,`agent`,`tools`,`plan-mode`]);var by=class e extends oy{name=`enter_plan_mode`;displayName=`EnterPlanMode`;description=`Enter plan mode to create a plan before implementing changes`;static parametersSchema=q({});parameters=e.parametersSchema;isReadonly=!0;needsPermission(e,t,n){return!1}async execute(e,t){return yy.info`Entering plan mode`,{success:!0}}format(e,t){return`Entered plan mode`}parse(e){let t=ny(e);return t.rejected?{phase:`rejected`,toolType:`enter_plan_mode`,data:{},summary:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}}:{phase:`success`,toolType:`enter_plan_mode`,data:{},summary:`Entered plan mode`}}};const xy=it([`codellm`,`agent`,`tools`,`plan-mode`]);var Sy=class e extends oy{name=`exit_plan_mode`;displayName=`ExitPlanMode`;description=`Exit plan mode and return to normal agent operation`;static parametersSchema=q({planFilePath:K().describe(`Path to the plan file`)});parameters=e.parametersSchema;isReadonly=!0;async prepare(e,t){if(!e.planFilePath)return{error:`Plan not found`,skipPermission:!0};try{let n=await t.workspace.readRawFile(e.planFilePath);return n?{planContent:n}:{error:`Plan not found`,skipPermission:!0}}catch{return{error:`Plan not found`,skipPermission:!0}}}needsPermission(e,t,n){return!n?.skipPermission}async execute(e,t,n){if(n?.error)throw Error(n.error);return xy.info`Exiting plan mode with plan: ${e.planFilePath}`,{planFilePath:e.planFilePath}}format(e,t){return JSON.stringify({type:`exit_plan_mode`,status:`success`,...e.planFilePath&&{planFilePath:e.planFilePath}})}parse(e){let t=ny(e);if(t.rejected)return{phase:`rejected`,toolType:`exit_plan_mode`,data:{},summary:`Rejected`,...t.userNote!==void 0&&{userNote:t.userNote}};try{return{phase:`success`,toolType:`exit_plan_mode`,data:JSON.parse(e),summary:`Plan approved`}}catch{}return e.includes(`implement the plan`),{phase:`success`,toolType:`exit_plan_mode`,data:{},summary:`Plan approved`}}},Cy;(function(e){e.GeneralPurpose=`GENERAL_PURPOSE`,e.Explore=`EXPLORE`,e.Plan=`PLAN`})(Cy||={});const wy={[Cy.GeneralPurpose]:{name:Cy.GeneralPurpose,displayName:`Agent`,description:`General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks`,allowedTools:[`*`],defaultModel:`CLAUDE_V4_5_SONNET`},[Cy.Explore]:{name:Cy.Explore,displayName:`Explore`,description:`Fast agent specialized for exploring codebases. Use for finding files by patterns, searching code for keywords, or answering questions about the codebase.`,allowedTools:[`read`,`glob`,`grep`,`bash`,`web_fetch`,`web_search`],defaultModel:`CLAUDE_V4_5_HAIKU`},[Cy.Plan]:{name:Cy.Plan,displayName:`Plan`,description:`Fast agent for creating implementation plans. Explores codebase to understand architecture before planning.`,allowedTools:[`read`,`glob`,`grep`,`bash`,`web_fetch`,`web_search`],defaultModel:`CLAUDE_V4_5_HAIKU`}},Ty=new Set(Object.values(Cy));function Ey(e){return Ty.has(e)}function Dy(e){if(Ey(e))return e}function Oy(e){return wy[e]}function ky(){return Object.values(Cy)}function Ay(e){let t=Dy(e);return t?Oy(t).displayName:e}function jy(e,t){let n=Dy(e);if(!n)return!1;let r=Oy(n);return r.allowedTools.includes(`*`)?!0:r.allowedTools.includes(t)}const My=/[ \t()[\]{};|*?$`'"#&<>!~]/;function Ny(e){return e.replace(RegExp(`\\\\([${My.source.slice(1,-1)}])`,`g`),`$1`)}const Py=N.homedir();function Fy(e){return e===`~`?Py:e.startsWith(`~/`)?E.join(Py,e.slice(2)):e}function Iy(e,t){return E.isAbsolute(e)?(E.relative(t,e)||e).split(E.sep).join(`/`):e.startsWith(`./`)||e.startsWith(`.\\`)?e.slice(2):e}function Ly(e){let t=E.resolve(e);try{return v(t)}catch{try{let e=E.dirname(t),n=E.basename(t);return E.join(v(e),n)}catch{return t}}}function Ry(e){return!!e&&!e.startsWith(`..`)&&!E.isAbsolute(e)}function zy(e,t){let n=E.resolve(e),r=E.resolve(t);if(n===r||Ry(E.relative(r,n)))return!0;let i=Ly(n),a=Ly(r);return i===a?!0:Ry(E.relative(a,i))}function By(e,t){let n=E.resolve(e),r=E.resolve(t),i=E.relative(r,n);if(Ry(i))return{success:!0,relativePath:i};let a=Ly(n),o=Ly(r);return i=E.relative(o,a),Ry(i)?{success:!0,relativePath:i}:{success:!1,reason:`outside_workspace`}}async function Vy(e){return new Promise(t=>setTimeout(t,e))}const Hy=it([`codellm`,`agent`,`loop`]);function Uy(e){if(!e)return null;if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e;if(t.text)return t.text;if(t.segment)return Uy(t.segment)}return null}function Wy(e){return Math.min((e+1)*2e3,1e4)}function Gy(e){return 2**(e+1)*1e3}function*Ky(e,t,n){if(e.error){let t=e.error,r=typeof t==`string`?t:JSON.stringify(t);r.includes(`Credit limit`)||r.includes(`no_usage_points`)||r.includes(`compute_point_budgeting`)||r.includes(`limit_exceeded`)||r.includes(`exhausted`)||r.includes(`purchase more credits`)?yield{__error:new qd({...n.pendingCreditLimitSegment??void 0,message:r})}:Ml(r)?yield{__error:new kl}:yield{__error:new Kd(r)};return}if(e.type===`no_usage_points`||e.type===`compute_point_budgeting`||e.type===`limit_exceeded`){n.pendingCreditLimitSegment=e;return}if(e.type===`code_llm_credits`){yield{type:`credits`,creditsUsed:e.creditsUsed};return}if(e.type===`collapsible_component`&&e.isThoughts===!0){let t=e.title||`Thinking`,n=Uy(e.segment)??``;n&&(yield{type:`thinking_delta`,content:n,title:t}),e.isSpinny===!1&&(yield{type:`thinking_complete`});return}if(e.type===`code_llm_notification`){let t=e.message||Uy(e.segment)||`Notification`;yield{...e,type:`notification`,message:t,severity:e.severity??`info`};return}if(e.type===`code_llm_agent_tool_call_start`){yield{type:`tool_call_start`,toolCallId:e.toolCallId,toolName:e.toolName};return}if(e.type===`code_llm_agent_tool_call_delta`){yield{type:`tool_call_delta`,toolCallId:e.toolCallId,argumentsDelta:e.argumentsDelta};return}if(e.type===`code_llm_agent_tool_call_stop`){yield{type:`tool_call_stop`,toolCallId:e.toolCallId,toolName:e.toolName,arguments:e.arguments};let n=e.toolUseRequest;if(n){let e=n;if(e.name===`edit`){let t=e.input;(`startLineOneIndexed`in t||`endLineOneIndexed`in t)&&(e={...e,input:{...t,startLine:t.startLineOneIndexed??t.startLine,endLine:t.endLineOneIndexed??t.endLine}})}t.push(e),yield{type:`tool_requested`,tool:e}}return}if(e.toolUseRequest){let n=(Array.isArray(e.toolUseRequest)?e.toolUseRequest:[e.toolUseRequest]).map(e=>{if(e.name===`edit`){let t=e.input;if(`startLineOneIndexed`in t||`endLineOneIndexed`in t)return{...e,input:{...t,startLine:t.startLineOneIndexed??t.startLine,endLine:t.endLineOneIndexed??t.endLine}}}return e}),r=new Set(t.map(e=>e.id)),i=n.filter(e=>!r.has(e.id));t.push(...i);for(let e of i)yield{type:`tool_requested`,tool:e};return}if(e.segment){let t=Uy(e.segment);t&&(yield{type:`text_delta`,content:t})}}async function*qy(e,t){let n=t?.generateRequestId?.()??crypto.randomUUID(),r=!1;Hy.debug(`Starting agent loop (conversationId={conversationId}, model={model})`,{conversationId:e.conversationId,model:e.model});for(let t=0;t<8;t++){Sl(`turn started`,`agent`);let i=n,a=!1;if(t>0){Hy.debug(`Retry attempt {attempt}: checking for pending request ID`,{attempt:t});try{let t=await e.apiClient.getPendingRequestIdForConversation(e.conversationId);t?.success&&t.result?.requestId&&(i=t.result.requestId,a=!0)}catch{}}let o=[],s={pendingCreditLimitSegment:null},c=!1;try{let t=e.apiClient.streamAgentMessage({deploymentConversationId:e.conversationId,message:e.message,supportedTools:e.supportedTools,supportedSubAgents:e.supportedSubAgents,mcpTools:e.isPrintMode?[]:e.mcpTools??[],workspacePath:e.workspacePath,...e.swapFolder&&{swapFolder:e.swapFolder},llmName:e.model,requestId:i,docInfos:e.uploadedDocs?Array.from(e.uploadedDocs):[],toolUseResult:e.toolResult,supportsV2:!0,supportsThoughtStreaming:e.supportsThoughtStreaming??!0,supportsParallelToolUse:!0,isPrintMode:e.isPrintMode??!1,...e.subagent&&{subagent:e.subagent},agentMode:e.agentMode,currentFile:e.currentFile,selectionStartLine:e.selectionStartLine,selectionEndLine:e.selectionEndLine,gitBranch:e.gitBranch,gitMain:e.gitMain,gitStatus:e.gitStatus,gitCommits:e.gitCommits,diagnosticIssues:e.diagnosticIssues,availableSkills:e.availableSkills,activeSkills:e.activeSkills,client:e.client,setFolder:e.setFolder,reconnect:a,signal:e.signal});for await(let n of t){if(e.signal?.aborted)break;for(let e of Ky(n,o,s)){if(`__error`in e)throw e.__error;yield e}c=!0}if(e.signal?.aborted){e.apiClient.stopResponseSSE(i).catch(()=>{}),yield{type:`turn_complete_with_tools`,toolCalls:o};return}r&&=(yield{type:`network_status`,online:!0},!1),yield{type:`turn_complete_with_tools`,toolCalls:o},Hy.debug(`Agent loop completed with {count} tool calls`,{count:o.length});return}catch(n){let i=n instanceof Error?n:Error(String(n));if(i instanceof kl){if(c&&t<4&&!e.signal?.aborted){let e=Gy(t);Hy.warn(`Auth error mid-stream (attempt={attempt}, delay={delayMs}ms) — retrying (server may have re-validated against a stale replica)`,{attempt:t+1,delayMs:e}),bl(`Mid-stream auth error, retrying`,`warning`,{context:`agent-loop`,attempt:t+1}),yield{type:`retry`,attempt:t+1,maxAttempts:5,delayMs:e,isNetworkError:!1},await Vy(e);continue}throw Hy.warn(`Auth expired, aborting loop`),i}if(i instanceof qd)throw Hy.warn(`Credit limit reached, aborting loop`),bl(`Credit limit reached`,`warning`,{context:`agent-loop`}),i;let a=Nl(i),o=a?8:5;if(t<o-1&&!e.signal?.aborted){let e=a?Wy(t):Gy(t);Hy.warn(`Retrying after error (attempt={attempt}, network={isNetErr}, delay={delayMs}ms): {error}`,{attempt:t+1,isNetErr:a,delayMs:e,error:i.message}),a&&!r&&(r=!0,yield{type:`network_status`,online:!1}),yield{type:`retry`,attempt:t+1,maxAttempts:o,delayMs:e,isNetworkError:a},await Vy(e);continue}throw Hy.error(`All retry attempts exhausted: {error}`,{error:i.message}),yl(i,{context:`agent-loop-retry-exhausted`}),Nl(i)?i instanceof Al?i:new Al(i.message,i):i}}}const Jy=it([`codellm`,`agent`,`runner`]);var Yy=class{queue=[];resolvers=[];closed=!1;push(e){this.closed||(this.resolvers.length>0?this.resolvers.shift()(e):this.queue.push(e))}async next(){return this.queue.length>0?this.queue.shift():this.closed?null:new Promise(e=>{this.resolvers.push(e)})}close(){this.closed=!0;for(let e of this.resolvers)e(null);this.resolvers=[]}drain(){let e=[...this.queue];return this.queue=[],e}};function Xy(e){return e.toUpperCase().includes(`CLAUDE`)}async function*Zy(e,t,n){let r=e.maxTurns??2**53-1,i=t,a,o=0,s=0,c=[],l=e.agentMode;Jy.info(`Starting agent conversation (model={model}, maxTurns={maxTurns})`,{model:e.model,maxTurns:r});try{for(;o<r;){if(n?.aborted)return Jy.info(`Conversation aborted after {numTurns} turns`,{numTurns:o}),{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!1,error:Error(`Execution cancelled`)};o++;let t={...e,swapFolder:a===void 0?e.swapFolder:void 0,setFolder:a===void 0?e.setFolder:void 0,agentMode:l,message:i,...a!==void 0&&{toolResult:a},...n!==void 0&&{signal:n}},r=[],u=new Map,d=new Map,f=new Map,p=[],m=new Yy,h=new AbortController,g=()=>h.abort(`interrupted`);n&&(n.aborted?h.abort(`interrupted`):n.addEventListener(`abort`,g,{once:!0}));let _=async(t,n,r)=>(await e.executeTools([t],n,r))[0],v=e.getConcurrency??(()=>!1),y=e=>{let t=_(e,h.signal,e=>m.push(e)).then(t=>{d.set(e.id,t);for(let[t,n]of f)if(n===e.id){f.delete(t);break}return t}).catch(e=>{throw h.abort(`sibling_tool_failed`),e});u.set(e.id,t)},b=e=>{let t=v(e);typeof t==`string`&&f.has(t)?p.push(e):(typeof t==`string`&&f.set(t,e.id),y(e))},x=!1;for await(let e of qy(t)){for(let e of m.drain())e.type===`mode_changed`&&(l=e.mode),yield e;if(e.type===`turn_complete_with_tools`){r=e.toolCalls,x=!0;continue}if(e.type===`text_delta`&&c.push(e.content),e.type===`tool_requested`){yield e,b(e.tool);continue}yield e}for(let e of m.drain())e.type===`mode_changed`&&(l=e.mode),yield e;if(x||Jy.warn(`Agent loop exited without turn_complete_with_tools (collected {count} tool calls)`,{count:r.length}),r.length===0){Jy.debug(`Turn {numTurns} complete with no tool calls`,{numTurns:o}),n?.removeEventListener(`abort`,g),yield{type:`turn_complete`};break}for(let e of p){let t=v(e);if(typeof t==`string`&&f.has(t)){let e=f.get(t),n=u.get(e);if(n)try{await n}catch{}}h.signal.aborted||b(e)}let S=r.filter(e=>!u.has(e.id));if(S.length>0)if(u.size===0){let t,n=e.executeTools(r,h.signal,e=>m.push(e)).then(e=>{t=e;for(let t=0;t<e.length;t++){let n=r[t];n&&d.set(n.id,e[t])}return m.close(),e}),i=new Set;for(;t===void 0;){let e=await Promise.race([m.next(),n.then(()=>null)]);if(e!==null)e.type===`mode_changed`&&(l=e.mode),e.type===`tool_execution_complete`&&i.add(e.tool.id),yield e;else if(t!==void 0)break}t||=await n;for(let e of m.drain())e.type===`mode_changed`&&(l=e.mode),e.type===`tool_execution_complete`&&i.add(e.tool.id),yield e;for(let e=0;e<t.length;e++){let n=r[e],a=t[e];n&&a&&!i.has(n.id)&&(yield{type:`tool_execution_complete`,tool:n,result:a})}}else for(let e of S)h.signal.aborted||y(e);if(u.size>0){let e=Promise.allSettled(u.values()).then(()=>{m.close()}),t=new Set,n=await m.next();for(;n!==null;)n.type===`mode_changed`&&(l=n.mode),n.type===`tool_execution_complete`&&t.add(n.tool.id),yield n,n=await m.next();await e;for(let e of r){let n=d.get(e.id);n&&!t.has(e.id)&&(yield{type:`tool_execution_complete`,tool:e,result:n})}}s+=r.length;let C=r.map(e=>d.get(e.id)??{id:e.id,content:`Error: tool execution did not complete`});n?.removeEventListener(`abort`,g);for(let t of e.drainEvents?.()??[])t.type===`mode_changed`&&(l=t.mode),yield t;let w=new Set([`task`]),T=(e,t)=>!(!e.rejected||w.has(r[t]?.name??``)),E=C.some((e,t)=>{if(!T(e,t))return!1;try{return JSON.parse(e.content).reason===ey.REJECTED}catch{return!1}}),D=C.some((e,t)=>{if(!T(e,t))return!1;try{return JSON.parse(e.content).reason===ey.INTERRUPTED}catch{return!1}}),O=C.some(e=>{if(!e.rejected)return!1;try{return JSON.parse(e.content).reason===ey.USER_MESSAGE}catch{return!1}});if((E||D)&&!O){yield{type:`turn_complete`};break}let k=C.map(({parsedResult:e,...t})=>t);a=k.length===1?k[0]:k;let A=r.some(e=>e.name===`exit_plan_mode`)&&C.some(e=>{if(e.rejected)return!1;try{return JSON.parse(e.content).type===`exit_plan_mode`}catch{return!1}}),j=`I want you to start implementing the plan now as you have outlined in your plan.`,M=e.getQueuedMessage?.();M&&Xy(e.model)?(i=A?`${j} ${M}`:M,e.clearQueuedMessage?.(),e.isQueuedMessageHidden?.()||(yield{type:`user_message_dequeued`,content:M})):i=A?j:``,yield{type:`turn_complete`}}if(o>=r){Jy.warn(`Maximum turns ({maxTurns}) exceeded`,{maxTurns:r});let e=Error(`Maximum turns (${r}) exceeded`);return yield{type:`error`,error:e},{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!1,error:e}}return Jy.info(`Conversation completed (turns={numTurns}, toolCalls={toolCallsExecuted})`,{numTurns:o,toolCallsExecuted:s}),{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!0}}catch(e){let t=e instanceof Error?e:Error(String(e));return yl(t,{context:`agent-runner`}),Jy.error(`Conversation failed after {numTurns} turns: {error}`,{numTurns:o,toolCallsExecuted:s,error:t}),yield{type:`error`,error:t},{content:c.join(``),numTurns:o,toolCallsExecuted:s,success:!1,error:t}}}const Qy=it([`codellm`,`agent`,`subagent`]);function $y(e,t){let n=Oy(t);return!n||n.allowedTools.includes(`*`)?e:e.filter(e=>jy(t,e.name))}function eb(e,t,n,r,i){let a=n.get(e.name)?.displayName??e.name;if(!n.isBuiltinRequest(e))return{type:`generic`,tool:e,displayName:a,toolName:a,inputSummary:JSON.stringify(e.input??{}).slice(0,200)};switch(e.name){case`read`:{let n=t._prepareResult;if(n?.resolvedPath){let t=Ly(n.resolvedPath);return{type:`read_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t)}}return{type:`generic`,tool:e,displayName:a,toolName:a,inputSummary:JSON.stringify(e.input??{}).slice(0,200)}}case`edit`:{let n=t._prepareResult;if(n?.outsideWorkspace){let t=Ly(n.resolvedPath??e.input.filePath??``);return{type:`edit_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t)}}return{type:`edit_file`,tool:e,displayName:a,filePath:e.input.filePath??``,originalContent:n?.currentContent??``,newContent:n?.newContent??``}}case`write`:{let n=t._prepareResult;if(n?.outsideWorkspace){let t=Ly(n.resolvedPath??e.input.filePath??``);return{type:`write_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t),isNewFile:!n?.fileExists}}return{type:`write_file`,tool:e,displayName:a,filePath:e.input.filePath??``,originalContent:n?.currentContent??``,content:e.input.content??``,isNewFile:!n?.fileExists}}case`bash`:return{type:`run_terminal`,tool:e,displayName:a,command:e.input.command??``,cwd:r,background:!!(e.input.runInBackground??!1),unmatchedPatterns:i?.getUnmatchedBashSegments(e.input.command??``)??[]};case`notebook_edit`:{let n=t._prepareResult;if(n?.outsideWorkspace){let t=Ly(n.resolvedPath??e.input.notebookPath??``);return{type:`notebook_edit_outside_directory`,tool:e,displayName:a,filePath:t,resolvedPath:t,deducedDirectory:E.dirname(t)}}let r=n?.notebook,i=e.input.cellId,o=``;if(i&&r?.cells){let e=r.cells.find(e=>e.id===i||e.metadata?.id===i);e&&(o=Array.isArray(e.source)?e.source.join(``):String(e.source??``))}return{type:`notebook_edit`,tool:e,displayName:a,notebookPath:e.input.notebookPath??``,cellId:i,editMode:e.input.editMode??`replace`,cellType:e.input.cellType,originalContent:o,newContent:e.input.newSource??``}}case`ask_user_question`:return{type:`ask_user_question`,tool:e,displayName:a,questions:Array.isArray(e.input.questions)?e.input.questions:[]};case`exit_plan_mode`:{let n=t._prepareResult;return{type:`exit_plan_mode`,tool:e,displayName:a,planFilePath:e.input.planFilePath??``,planContent:n?.planContent??``}}default:return{type:`generic`,tool:e,displayName:a,toolName:a,inputSummary:JSON.stringify(e.input??{}).slice(0,200)}}}async function tb(e){let{prompt:t,subagentType:n,model:r,resume:i,parentContext:a,onProgress:o,signal:s}=e;Qy.info(`Starting subagent (type={subagentType}, model={model})`,{subagentType:n,model:r??`default`});let c=Oy(n);if(!c)return Qy.error(`Unknown subagent type: {subagentType}`,{subagentType:n}),{success:!1,output:``,toolsExecuted:[],toolCalls:[],numTurns:0,error:`Unknown subagent type: ${n}`};let l=Lw(),u=$y(l.getApiToolDefinitions(),n),d=r??c.defaultModel??`CLAUDE_V4_5_SONNET`,f;if(i&&c.supportsResume)f=i;else try{let e=await a.apiClient.createCodellmDeploymentConversation(`CODE_LLM_NON_INTERACTIVE`,a.clientType);if(!e?.result?.deploymentConversationId)return{success:!1,output:``,toolsExecuted:[],toolCalls:[],numTurns:0,error:`Failed to create subagent conversation: no conversation ID returned`};f=e.result.deploymentConversationId}catch(e){return{success:!1,output:``,toolsExecuted:[],toolCalls:[],numTurns:0,error:`Failed to create subagent conversation: ${e instanceof Error?e.message:String(e)}`}}let p=[],m=[],h=[],g=a.permissionProvider&&a.rulesEngine&&a.getAgentMode,_=()=>a.getAgentMode?.()??Wd.Yolo,v=c?.name,y={apiClient:a.apiClient,conversationId:f,model:d,workspacePath:a.workspacePath,supportedTools:u,mcpTools:[],uploadedDocs:a.uploadedDocs,isPrintMode:!g,...v&&{subagent:v},supportsThoughtStreaming:!0,agentMode:_(),executeTools:async(e,t,n)=>{let r=[];for(let i of e){if(t?.aborted||s?.aborted)break;m.push(i.name);let e={name:i.name,input:i.input??{}};o?.({type:`tool_requested`,content:`${i.name}`,toolName:i.name,toolInput:e.input,toolId:i.id}),n?.({type:`tool_execution_start`,tool:i});let c=_(),u={...a,toolCallId:i.id,conversationId:f,agentMode:c,status:`executing`};try{let d=l.createToolInstance(i.name,i.input??{},u);await d.prepare();let f=c===Wd.Yolo&&i.name!==`ask_user_question`;if(g&&!f&&d.needsPermission()){let c=l.get(i.name)?.displayName??i.name,f=Xw(i),p=a.rulesEngine.evaluate(c,f);if(p===`deny`){r.push({id:i.id,content:JSON.stringify({reason:ey.REJECTED}),rejected:!0}),e.result=`denied by rule`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(p!==`allow`){let c=eb(i,d,l,a.workspacePath,a.rulesEngine);if(a.permissionProvider.needsPermission(c)){n?.({type:`status_changed`,status:Gd.WaitingForToolPermission}),a.emitEvent?.({type:`status_changed`,status:Gd.WaitingForToolPermission});let l;try{let e=a.permissionProvider.requestPermission(c),n=t||s;if(n){let t,r=new Promise((e,r)=>{n.aborted?r(Error(`interrupted`)):(t=()=>r(Error(`interrupted`)),n.addEventListener(`abort`,t,{once:!0}))});try{l=await Promise.race([e,r])}finally{t&&n.removeEventListener(`abort`,t)}}else l=await e}catch{r.push({id:i.id,content:JSON.stringify({reason:ey.INTERRUPTED}),rejected:!0}),e.result=`interrupted`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(n?.({type:`status_changed`,status:Gd.ExecutingTool}),a.emitEvent?.({type:`status_changed`,status:Gd.ExecutingTool}),l===`reject`){r.push({id:i.id,content:JSON.stringify({reason:ey.REJECTED}),rejected:!0}),e.result=`rejected`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(typeof l==`object`&&l.type===`reject_with_message`){r.push({id:i.id,content:JSON.stringify({reason:ey.USER_MESSAGE,message:l.message}),rejected:!0}),e.result=`rejected`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(l===`allowAlways`||l===`allowYolo`||l===`accept`){if(l===`allowAlways`&&(c.type===`read_outside_directory`||c.type===`write_outside_directory`||c.type===`edit_outside_directory`||c.type===`notebook_edit_outside_directory`)&&`deducedDirectory`in c){let e=a.allowEditingPaths??[],t=c.deducedDirectory;e.includes(t)||e.push(t)}else if(i.name===`exit_plan_mode`){let e=l===`allowYolo`?Wd.Yolo:l===`allowAlways`?Wd.AcceptEdits:Wd.Normal;a.setAgentMode?.(e),u.agentMode=e,n?.({type:`mode_changed`,mode:e})}else if(l===`allowAlways`){let e=Xd(c.type);a.setAgentMode?.(e),u.agentMode=e,n?.({type:`mode_changed`,mode:e})}}if(typeof l==`object`&&l.type===`accept_with_message`){r.push({id:i.id,content:JSON.stringify({reason:ey.USER_MESSAGE,message:l.message}),rejected:!0}),e.result=`accepted with message`,h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id});continue}if(typeof l==`object`&&l.type===`question_answers`&&d.mergeParams({answers:l.answers}),typeof l==`object`&&l.type===`allow_always_with_rule`&&a.rulesEngine.addAllowRule(l.rule),typeof l==`object`&&l.type===`allow_always_with_rules`)for(let e of l.rules)a.rulesEngine.addAllowRule(e)}}}i.name===`enter_plan_mode`&&(a.setAgentMode?.(Wd.PlanMode),u.agentMode=Wd.PlanMode,n?.({type:`mode_changed`,mode:Wd.PlanMode})),i.name===`exit_plan_mode`&&f&&(a.setAgentMode?.(Wd.Normal),u.agentMode=Wd.Normal,n?.({type:`mode_changed`,mode:Wd.Normal})),await d.execute();let p=d.formatResultForLLM(),m=d.formatResult(),_=typeof p==`string`?p:JSON.stringify(p),v=l.parse(i.name,m);r.push({id:i.id,content:_,parsedResult:v}),e.result=_}catch(t){let n=t instanceof Error?t.message:String(t);r.push({id:i.id,content:`Error: ${n}`}),e.result=`Error: ${n}`}h.push(e),o?.({type:`tool_complete`,content:`${i.name}`,toolName:i.name,toolId:i.id})}for(let t of e)r.some(e=>e.id===t.id)||r.push({id:t.id,content:JSON.stringify({reason:ey.INTERRUPTED}),rejected:!0});return r}};try{o?.({type:`status`,content:`Starting ${n} agent...`});let e=Zy(y,t,s),r=await e.next();for(;!r.done;){let t=r.value;switch(t.type){case`text_delta`:p.push(t.content),o?.({type:`text`,content:t.content});break;case`thinking_delta`:o?.({type:`thinking`,content:t.content});break;case`tool_requested`:case`turn_complete`:break;case`tool_execution_complete`:p.length=0;break;case`error`:return{success:!1,output:p.join(``),toolsExecuted:m,toolCalls:h,numTurns:0,error:t.error?.message??`Unknown error`};case`credits`:a.emitEvent?.(t);break;case`mode_changed`:a.emitEvent?.(t);break;case`status_changed`:case`notification`:break}r=await e.next()}let i=r.value;return Qy.info(`Subagent completed (type={subagentType}, turns={numTurns}, tools={toolCount})`,{subagentType:n,numTurns:i.numTurns,toolCount:m.length}),{success:i.success,output:p.join(``),toolsExecuted:m,toolCalls:h,numTurns:i.numTurns,...i.error&&{error:i.error.message}}}catch(e){let t=e instanceof Error?e.message:String(e);return yl(e instanceof Error?e:Error(t),{context:`subagent-runner`}),Qy.error(`Subagent failed (type={subagentType}): {error}`,{subagentType:n,error:t}),{success:!1,output:p.join(``),toolsExecuted:m,toolCalls:h,numTurns:0,error:t}}}const nb=it([`codellm`,`agent`,`tools`,`task`]);var rb=class e extends oy{name=`task`;displayName=`Task`;description=`Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
51
51
|
|
|
52
52
|
The Task tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
|
|
53
53
|
|
|
@@ -73324,7 +73324,7 @@ No matching component was found for:
|
|
|
73324
73324
|
`).map(e=>mz(e,i)).join(`
|
|
73325
73325
|
`):t===`truncate-start`&&(r=r.split(`
|
|
73326
73326
|
`).map(e=>pz(e,i)).join(`
|
|
73327
|
-
`))}}r=dB(e,r),e.renderCache={lines:[r],width:n,height:0,left:l,top:u},t.write(l,u,r,d)}else e.renderCache=void 0;e.renderDirty=!1;return}let f=!1;if(e.nodeName===`jar-view`){e.style.backgroundColor&&fB(l,u,e,t),e.style.borderStyle&&aB(l,u,e,t);let n=e.style.overflowX===`hidden`||e.style.overflow===`hidden`,r=e.style.overflowY===`hidden`||e.style.overflow===`hidden`;if(n||r){let i=n?l+lB(e.style,`Left`):void 0,a=n?l+c.getComputedWidth()-lB(e.style,`Right`):void 0,o=r?u+lB(e.style,`Top`):void 0,s=r?u+c.getComputedHeight()-lB(e.style,`Bottom`):void 0;t.clip({x1:i,x2:a,y1:o,y2:s}),f=!0}}if(e.nodeName===`jar-root`||e.nodeName===`jar-view`){let n=f?u+lB(e.style,`Top`):o,r=f?u+c.getComputedHeight()-lB(e.style,`Bottom`):s;for(let i of e.childNodes)pB(i,t,{offsetX:l,offsetY:u,transformers:d,clipY1:n,clipY2:r});f&&t.unclip()}e.renderDirty=!1};var mB=class{rootNode;lastWidth=0;cachedLines=null;output=new vz(0,0);constructor(e){this.rootNode=e}notifyCommit(){this.cachedLines=null}render(e){let t=e!==this.lastWidth;if(t&&(this.clearAllRenderCaches(this.rootNode),this.lastWidth=e),this.cachedLines&&!this.rootNode.renderDirty&&!t)return this.cachedLines;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,1);let n=Math.ceil(this.rootNode.yogaNode.getComputedHeight());if(n<=0)return this.cachedLines=[],this.cachedLines;this.output.reset(e,n),pB(this.rootNode,this.output,{});let r=this.output.get(),i=!1;for(let t of r)if(mI(t)>e){i=!0;break}return this.cachedLines=i?r.map(t=>mI(t)>e?SI(t,e):t):r,this.cachedLines}invalidate(){this.cachedLines=null,this.clearAllRenderCaches(this.rootNode)}clearAllRenderCaches(e){e.renderDirty=!0,e.renderCache=void 0;for(let t of e.childNodes)t.nodeName!==`#text`&&this.clearAllRenderCaches(t)}},hB;(function(e){e[e.BlinkingBlock=0]=`BlinkingBlock`,e[e.BlinkingBlockDefault=1]=`BlinkingBlockDefault`,e[e.SteadyBlock=2]=`SteadyBlock`,e[e.BlinkingUnderline=3]=`BlinkingUnderline`,e[e.SteadyUnderline=4]=`SteadyUnderline`,e[e.BlinkingBar=5]=`BlinkingBar`,e[e.SteadyBar=6]=`SteadyBar`})(hB||={});const gB=`\x1B[?25h`,_B=`\x1B[?25l`;function vB(e,t){let n=``;return t!==``&&(n=typeof Buffer<`u`?Buffer.from(t).toString(`base64`):btoa(t)),`\x1B]52;`+String.fromCharCode(e)+`;`+n+`\x07`}function yB(e){return vB(99,e)}function bB(e){let t=e??Gz(),n=t.TERM_PROGRAM.toLowerCase(),r=t.TERM.toLowerCase(),i=(t.LC_TERMINAL??``).toLowerCase();if(n===`iterm.app`)return`iterm2`;if(n===`wezterm`)return`wezterm`;if(n===`ghostty`)return`ghostty`;if(n===`vscode`)return`vscode`;if(n===`tmux`)return`tmux`;if(t.WT_SESSION)return`windows-terminal`;if(r.includes(`kitty`))return`kitty`;if(r.includes(`alacritty`))return`alacritty`;if(r.includes(`foot`))return`foot`;if(r.includes(`contour`))return`contour`;if(r.includes(`rio`))return`rio`;if(r.includes(`ghostty`))return`ghostty`;if(r.includes(`wezterm`))return`wezterm`;if(r.startsWith(`tmux`))return`tmux`;if(r.startsWith(`screen`))return`screen`;if(r===`xterm`||r.startsWith(`xterm-`))return`xterm`;if(r===`linux`)return`linux`;if(!n&&i){if(i===`iterm2`)return`iterm2`;if(i===`wezterm`)return`wezterm`}return`unknown`}function xB(e){return(e??Gz()).isTTY}function SB(e){let t=bB(e);return t===`windows-terminal`||t===`iterm2`||t===`wezterm`||t===`ghostty`}function CB(e){let t=bB(e);return t===`iterm2`||t===`kitty`||t===`wezterm`||t===`ghostty`||t===`alacritty`||t===`foot`||t===`xterm`||t===`tmux`||t===`windows-terminal`||t===`rio`||t===`contour`}function wB(e){let t=bB(e);return t===`iterm2`||t===`kitty`||t===`wezterm`||t===`ghostty`||t===`alacritty`||t===`foot`||t===`contour`||t===`rio`||t===`vscode`||t===`windows-terminal`}function TB(e,...t){return`\x1B]8;`+(t.length>0?t.join(`:`):``)+`;`+e+`\x07`}function EB(...e){return TB(``,...e)}function DB(e){return e.replace(/[\x07\x1b\x9c]/g,``)}function OB(e){return`\x1B]9;`+DB(e)+`\x07`}function kB(e,...t){return`\x1B]99;`+t.map(DB).join(`:`)+`;`+DB(e)+`\x07`}function AB(e){return`\x1B]777;notify;;`+DB(e)+`\x07`}const jB=`\x1B]9;4;0\x07`;function MB(e){return`\x1B]9;4;1;`+Math.min(Math.max(0,e),100)+`\x07`}function NB(e){return`\x1B]9;4;2;`+Math.min(Math.max(0,e),100)+`\x07`}function PB(e){return`\x1B]9;4;4;`+Math.min(Math.max(0,e),100)+`\x07`}var FB=class{env;profile;terminalType;_isDark;_writer;_progressHideTimer=null;constructor(e){this.env=e?.env??Gz(),this.profile=qz(this.env),Zz(this.profile),this.terminalType=bB(this.env),this._isDark=e?.isDark??Dz(),this._writer=e?.writer??null,e?.isDark!==void 0&&Oz(e.isDark)}get isDark(){return this._isDark}setDark(e){this._isDark=e,Oz(e)}resolveAdaptiveColor(e){if(typeof e==`string`)return Uz.parse(e);let t=this._isDark?e.dark:e.light;return Uz.parse(t)}colorize(e,t,n){if(!t)return e;let r=this.resolveAdaptiveColor(t);if(!r)return e;let i=Qz(r,this.profile);return i?`\x1B[`+(n===`foreground`?i.fgSequence():i.bgSequence())+`m`+e+`\x1B[0m`:e}styledText(){return nB(this.profile)}write(e){this._writer?this._writer(e):typeof process<`u`&&process.stdout?.isTTY&&process.stdout.write(e)}notify(e){if(!xB(this.env))return;let t=this.terminalType,{title:n,body:r}=e,i=n?`${n}:\n${r}`:r;t===`kitty`&&(n?this.write(kB(r,`d=0:p=title`,n)):this.write(kB(r))),this.write(AB(i)),this.write(OB(i))}showProgress(e){if(!SB(this.env))return;this.clearProgressTimer();let t=e.state??`normal`,n=Math.min(Math.max(0,e.percentage??0),100);switch(t){case`indeterminate`:this.write(`\x1B]9;4;3\x07`);break;case`error`:this.write(NB(n));break;case`warning`:this.write(PB(n));break;default:this.write(MB(n));break}(t===`error`||n>=100)&&this.scheduleProgressHide()}hideProgress(){this.clearProgressTimer(),SB(this.env)&&this.write(jB)}async trackProgress(e){this.showProgress({state:`indeterminate`});try{let t=await e;return this.showProgress({percentage:100}),this.scheduleProgressHide(),t}catch(e){throw this.showProgress({percentage:100,state:`error`}),this.scheduleProgressHide(),e}}copyToClipboard(e){CB(this.env)&&this.write(yB(e))}clearClipboard(){CB(this.env)&&this.write(`\x1B]52;c;\x07`)}hyperlink(e,t){return wB(this.env)?TB(e)+t+EB():t}clearProgressTimer(){this._progressHideTimer&&=(clearTimeout(this._progressHideTimer),null)}scheduleProgressHide(){this.clearProgressTimer(),this._progressHideTimer=setTimeout(()=>{this.write(jB),this._progressHideTimer=null},500)}},IB=class{tui;terminal;terminalOutput;rootNode;bridge;container;exitCallbacks=[];exitPromise;resolveExit;exitOnCtrlC;ownsTui;suspendable;onSuspended;cleanupSuspend;originalWarningListeners;warningInterceptor;constructor(e={}){this.exitOnCtrlC=e.exitOnCtrlC??!0,this.suspendable=e.suspendable??!1,this.onSuspended=e.onSuspended,e.tui?(this.tui=e.tui,this.terminal=e.tui.terminal,this.ownsTui=!1):e.terminal?(this.terminal=e.terminal,this.tui=new oL(this.terminal),this.ownsTui=!0):(this.terminal=new gL,this.tui=new oL(this.terminal),this.ownsTui=!0),this.terminalOutput=new FB({writer:e=>this.terminal.write(e)}),this.rootNode=WR(`jar-root`),this.rootNode.yogaNode.setFlexDirection(0),this.rootNode.yogaNode.setFlexGrow(1),this.rootNode.onRender=()=>{this.bridge.notifyCommit(),this.tui.requestRender(),performance.clearMeasures()},this.bridge=new mB(this.rootNode),this.tui.addChild(this.bridge),this.container=az.createContainer(this.rootNode,0,null,!1,null,`jar`,()=>{},()=>{},()=>{},()=>{}),this.exitPromise=new Promise(e=>{this.resolveExit=e}),this.exitOnCtrlC&&this.tui.addInputListener(e=>{if(!BI(e)&&qI(e,`ctrl+c`))return this.exit(),{consume:!0}})}render(e){az.updateContainerSync(e,this.container,null),az.flushSyncWork()}start(){this.ownsTui&&this.tui.start(),this.setupWarningInterceptor(),this.suspendable&&(this.cleanupSuspend=this.setupSuspendHandler())}exit(e){for(let t of this.exitCallbacks)t(e);this.unmount()}onExit(e){this.exitCallbacks.push(e)}unmount(){if(this.warningInterceptor&&=(U.removeListener(`warning`,this.warningInterceptor),void 0),this.originalWarningListeners){let e=U.listeners(`warning`);for(let t of this.originalWarningListeners)e.includes(t)||U.on(`warning`,t);this.originalWarningListeners=void 0}this.cleanupSuspend?.(),this.ownsTui&&this.disableInputProtocols(),az.updateContainerSync(null,this.container,null),az.flushSyncWork(),this.tui.removeChild(this.bridge),this.ownsTui&&this.tui.stop(),this.rootNode.yogaNode?.unsetMeasureFunc(),this.rootNode.yogaNode?.free(),this.rootNode.yogaNode=void 0,this.resolveExit()}cleanupTerminal(){this.ownsTui&&(this.cleanupSuspend?.(),this.disableInputProtocols(),this.tui.stop(),U.stdout.write(gB))}disableInputProtocols(){this.terminal.write(vL),this.terminal.write(`\x1B[?2004l`),this.terminal.kittyProtocolActive&&this.terminal.write(`\x1B[<u`)}setupWarningInterceptor(){this.originalWarningListeners||(this.originalWarningListeners=U.rawListeners(`warning`),U.removeAllListeners(`warning`),this.warningInterceptor=()=>{},U.on(`warning`,this.warningInterceptor))}setupSuspendHandler(){if(U.platform===`win32`||!this.ownsTui)return()=>{};let e=!1,t=()=>{e=this.terminal.kittyProtocolActive,U.stdout.isTTY&&(this.disableInputProtocols(),U.stdout.write(gB)),U.stdin.isTTY&&U.stdin.isRaw&&U.stdin.setRawMode(!1),this.onSuspended?.(),U.removeListener(`SIGTSTP`,t),U.kill(U.pid,`SIGTSTP`)},n=()=>{U.stdin.isTTY&&U.stdin.setRawMode(!0),U.stdout.isTTY&&(U.stdout.write(_B),this.terminal.write(`\x1B[?2004h`),this.terminal.write(_L),e&&this.terminal.write(`\x1B[>7u`)),U.on(`SIGTSTP`,t),this.tui.requestRender(!0)};return U.on(`SIGTSTP`,t),U.on(`SIGCONT`,n),()=>{U.removeListener(`SIGTSTP`,t),U.removeListener(`SIGCONT`,n)}}waitUntilExit(){return this.exitPromise}getRootNode(){return this.rootNode}};function LB(e,t){let n=new IB(t),r=Y.createElement(dz,{tui:n.tui,terminal:n.terminal,terminalOutput:n.terminalOutput,exit:e=>n.exit(e),children:e});return n.render(r),n.start(),{rerender(e){let t=Y.createElement(dz,{tui:n.tui,terminal:n.terminal,terminalOutput:n.terminalOutput,exit:e=>n.exit(e),children:e});n.render(t)},unmount(){n.unmount()},waitUntilExit(){return n.waitUntilExit()},cleanupTerminal(){n.cleanupTerminal()}}}function X({children:e,...t}){return(0,J.jsx)(`jar-view`,{style:{flexWrap:`nowrap`,flexDirection:`row`,flexGrow:0,flexShrink:1,...t,overflowX:t.overflowX??t.overflow??`visible`,overflowY:t.overflowY??t.overflow??`visible`},children:e})}function Z({color:e,backgroundColor:t,dimColor:n=!1,bold:r=!1,italic:i=!1,underline:a=!1,strikethrough:o=!1,inverse:s=!1,wrap:c=`wrap`,transform:l,children:u}){if(u==null)return null;let d=(0,Y.useCallback)(c=>(n&&(c=nB().dim().render(c)),e&&(c=eB(c,e,`foreground`)),t&&(c=eB(c,t,`background`)),r&&(c=nB().bold().render(c)),i&&(c=nB().italic().render(c)),a&&(c=nB().underline().render(c)),o&&(c=nB().strikethrough().render(c)),s&&(c=nB().reverse().render(c)),l&&(c=l(c)),c),[e,t,n,r,i,a,o,s,l]);return(0,J.jsx)(`jar-text`,{style:{flexGrow:0,flexShrink:0,flexDirection:`row`,textWrap:c},internal_transform:d,children:u})}const RB=/\x1b\[[\d:]*;(\d+)/;function zB(e){let t=RB.exec(e);return t?(parseInt(t[1],10)-1&8)!=0:!1}const BB={upArrow:!1,downArrow:!1,leftArrow:!1,rightArrow:!1,pageDown:!1,pageUp:!1,home:!1,end:!1,return:!1,escape:!1,ctrl:!1,shift:!1,tab:!1,backspace:!1,delete:!1,meta:!1,super:!1,paste:!1,raw:``},VB=(e,t={})=>{let{addInputListener:n}=(0,Y.use)(cz),r=(0,Y.useRef)(e);r.current=e,(0,Y.useEffect)(()=>{if(t.isActive!==!1)return n(e=>{if(BI(e))return;if(e.startsWith(`\x1B[200~`)){let t=e.indexOf(`\x1B[201~`),n=t===-1?e.slice(6):e.slice(6,t);BB.upArrow=!1,BB.downArrow=!1,BB.leftArrow=!1,BB.rightArrow=!1,BB.pageDown=!1,BB.pageUp=!1,BB.home=!1,BB.end=!1,BB.return=!1,BB.escape=!1,BB.ctrl=!1,BB.shift=!1,BB.tab=!1,BB.backspace=!1,BB.delete=!1,BB.meta=!1,BB.super=!1,BB.paste=!0,BB.raw=e,r.current(n,{...BB});return}let t=JI(e),n=t?t.split(`+`):[],i=n[n.length-1]??``,a=n.includes(`ctrl`),o=n.includes(`shift`),s=n.includes(`alt`);BB.upArrow=i===`up`,BB.downArrow=i===`down`,BB.leftArrow=i===`left`,BB.rightArrow=i===`right`,BB.pageDown=i===`pagedown`,BB.pageUp=i===`pageup`,BB.home=i===`home`,BB.end=i===`end`,BB.return=i===`return`||i===`enter`,BB.escape=i===`escape`,BB.ctrl=a,BB.shift=o,BB.tab=i===`tab`,BB.backspace=i===`backspace`,BB.delete=i===`delete`,BB.meta=s,BB.super=zB(e),BB.paste=!1,BB.raw=e;let c=BB,l=``;if(a&&i)l=i;else if(!c.upArrow&&!c.downArrow&&!c.leftArrow&&!c.rightArrow&&!c.pageDown&&!c.pageUp&&!c.home&&!c.end&&!c.return&&!c.escape&&!c.tab&&!c.backspace&&!c.delete){let t=ZI(e);t===void 0?e.length===1?l=e:i.length===1&&(l=i):l=t}r.current(l,{...c})})},[t.isActive,n])},HB=({isActive:e=!0,autoFocus:t=!1,id:n}={})=>{let{activeId:r,add:i,remove:a,activate:o,deactivate:s,focus:c}=(0,Y.use)(oz),l=(0,Y.useMemo)(()=>n??Math.random().toString().slice(2,7),[n]);return(0,Y.useEffect)(()=>(i(l,{autoFocus:t}),()=>{a(l)}),[l,t]),(0,Y.useEffect)(()=>{e?o(l):s(l)},[e,l]),{isFocused:!!l&&r===l,focus:c}};function UB(){return(0,Y.use)(sz)}const WB=()=>{let e=(0,Y.use)(uz);if(!e)throw Error(`useTerminal must be used within a jar render context`);return e.output},GB=RegExp(`[\\x1b\\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]|\\x1b\\][\\s\\S]*?(?:\\x07|\\x1b\\\\)`,`g`);function KB(){return new RegExp(GB.source,`g`)}function qB(e){return e.replace(GB,``)}function JB(e){return e.replace(/[\x07\x1b\x9c]/g,``)}function YB(e){return`\x1B]2;`+JB(e)+`\x07`}var XB=W(((e,t)=>{t.exports={name:`@codellm/cli`,version:`2.4.6-canary.2`,private:!0,bin:{abacusai:`dist/index.mjs`},files:[`dist`,`LICENSE.txt`],type:`module`,scripts:{"prepare-publish":`bun ./scripts/prepare-publish.ts`,build:`tsdown`,"check-types":`tsgo -b --noEmit`,test:`FORCE_COLOR=1 vitest run`,"test:watch":`FORCE_COLOR=1 vitest`,"test:ui":`FORCE_COLOR=1 vitest --ui`,"test:coverage":`FORCE_COLOR=1 vitest run --coverage`},dependencies:{"@clack/prompts":`^0.11.0`,"@codellm/agent":`workspace:*`,"@codellm/api":`workspace:*`,"@codellm/auth":`workspace:*`,"@codellm/comms":`workspace:*`,"@codellm/jar":`workspace:*`,"@codellm/logging":`workspace:*`,"@codellm/product":`workspace:*`,"@logtape/logtape":`^2.0.5`,"@orpc/client":`catalog:`,"@orpc/contract":`catalog:`,"@orpc/server":`catalog:`,"@sentry/node-core":`10.46.0`,"@slack/web-api":`^7.0.0`,"@tanstack/react-query":`^5.90.19`,"@vscode/ripgrep":`1.17.0`,"ansi-styles":`^6.2.3`,"beautiful-mermaid":`^1.1.3`,"cli-boxes":`^4.0.1`,"cli-highlight":`^2.1.11`,conf:`^15.0.2`,diff:`^8.0.3`,fzf:`^0.5.2`,"gradient-string":`^3.0.0`,immer:`^11.1.4`,"isomorphic-git":`^1.36.1`,marked:`^17.0.4`,"patchright-core":`^1.58.2`,react:`^19.2.3`,"react-compiler-runtime":`^1.0.0`,remend:`^1.2.2`,semver:`^7.7.4`,"shell-history":`^2.0.1`,"string-width":`^8.1.0`,"strip-ansi":`^7.2.0`,trash:`^9.0.0`,zod:`catalog:`},devDependencies:{"@codellm/configs":`workspace:*`,"@playwright/mcp":`^0.0.68`,"@types/diff":`^8.0.0`,"@types/node":`catalog:`,"@types/react":`^19.2.9`,"@types/semver":`^7.7.1`,"@typescript/native-preview":`catalog:`,"@vitejs/plugin-react":`^5.1.2`,"@vitest/coverage-v8":`^4.0.18`,"@vitest/ui":`^4.0.18`,"@xterm/addon-serialize":`^0.14.0`,"@xterm/headless":`^6.0.0`,"babel-plugin-react-compiler":`^1.0.0`,"cli-testing-library":`^3.0.1`,jsdom:`^27.4.0`,"node-pty":`^1.1.0`,"react-devtools-core":`^6.1.5`,"svg-term-cli":`^2.1.1`,tsdown:`^0.21.0`,vite:`catalog:`,vitest:`^4.0.18`},engines:{node:`>=18`}}})),ZB=Ge(XB(),1);let QB=null;function $B(e){let t=(0,_F.prerelease)(e);return t&&t.length>0&&typeof t[0]==`string`?t[0]:`latest`}function eV(){let e=process.env.npm_command;if(e===`exec`||e===`dlx`)return!0;let t=process.argv[1]??``;return!!/_npx[/\\]|[/\\]dlx[/\\]|\.cache[/\\]/.test(t)}function tV(){if(process.versions.bun===void 0)return!1;let e=process.argv[1]??process.argv[0]??``;return/[/\\]\.abacusai[/\\]bin[/\\]/.test(e)}function nV(){let e=`${cn.internalEnvPrefix}DEV`,t=process.env[e];if(t===`1`||t===`true`)return!0;let n=process.argv[1]??``;try{n=v(n)}catch{}if(/[/\\]\.abacusai[/\\]bin[/\\]/.test(n))return!1;let r=/[/\\]node_modules[/\\]/.test(n)||/[/\\]\.npm[/\\]/.test(n)||/[/\\]\.bun[/\\]/.test(n),i=!!process.env.npm_config_user_agent;return!r&&!i}function rV(){return`${process.platform===`win32`?`win32`:process.platform===`darwin`?`darwin`:`linux`}-${process.arch===`arm64`?`arm64`:`x64`}`}function iV(){let e=process.env.npm_config_user_agent;if(e){let t=e.split(`/`)[0];if(t===`yarn`||t===`pnpm`||t===`bun`||t===`npm`)return t}if(process.versions.bun!==void 0)return`bun`;let t=process.argv[1]??``;return/[/\\]\.?yarn[/\\]/.test(t)?`yarn`:/[/\\]\.?pnpm[/\\]/.test(t)?`pnpm`:/[/\\]\.bun[/\\]/.test(t)?`bun`:`npm`}async function aV(e){let t=Date.now();if(QB&&t-QB.timestamp<6e4)return QB.tags;let n=await fetch(`https://registry.npmjs.org/${e}`,{signal:AbortSignal.timeout(1e4),headers:{accept:`application/json`}});if(!n.ok)throw Error(`Registry returned ${n.status}`);let r=(await n.json())[`dist-tags`]??{};return QB={tags:r,timestamp:t},r}async function oV(e,t,n,r){let i=t??$B(e),a=(r??`https://apps.abacus.ai`).replace(/\/$/,``),o=new URL(`${a}/api/v0/_getCodellmCliVersion`);o.searchParams.set(`channel`,i),n&&o.searchParams.set(`platform`,n),o.searchParams.set(`cli_version`,e);let s=await fetch(o.toString(),{signal:AbortSignal.timeout(1e4)});if(s.status===204)return null;if(!s.ok)throw Error(`API returned ${s.status}`);let c=await s.json();return{currentVersion:e,latestVersion:c.result.version,tag:c.result.channel,packageManager:iV(),isEphemeral:eV(),downloadUrl:c.result.url}}async function sV(e){let t=$B(e),n=iV(),r=eV(),i=(await aV(ln.publishName))[t];return!i&&t!==`latest`||!i||i===e?null:{currentVersion:e,latestVersion:i,tag:t,packageManager:n,isEphemeral:r}}async function cV(e,t,n){if(tV())try{return await oV(e,t,rV(),n)}catch{return null}return await sV(e)}function lV(){return`${cn.binName} upgrade`}function uV(e){let t=`${ln.publishName}@${e.tag}`;switch(e.packageManager){case`yarn`:return`yarn global add ${t}`;case`pnpm`:return`pnpm add -g ${t}`;case`bun`:return`bun add -g ${t}`;default:return`npm install -g ${t}`}}function dV(e){try{return se(uV(e),{stdio:`pipe`}),!0}catch{return!1}}function fV(e){try{return{ok:!0,output:se(uV(e),{stdio:`pipe`,encoding:`utf-8`}).trim()}}catch(e){return{ok:!1,output:e instanceof Error&&`stderr`in e?String(e.stderr).trim():e instanceof Error?e.message:`Unknown error`}}}async function pV(e){if(!e.downloadUrl)return{ok:!1,output:`No download URL`};let t=T.join(M.tmpdir(),`abacusai-update-${Date.now()}`),n=T.join(M.homedir(),`.${cn.configDirName}`,`bin`),r=process.platform===`win32`,i=r?`${cn.binName}.exe`:cn.binName;try{await ye.mkdir(t,{recursive:!0});let a=T.join(t,r?`update.zip`:`update.tar.gz`),o=await fetch(e.downloadUrl);if(!o.ok)throw Error(`Download failed: ${o.status}`);let s=Buffer.from(await o.arrayBuffer());await ye.writeFile(a,s),se(r?`powershell -Command "Expand-Archive -Path '${a}' -DestinationPath '${t}' -Force"`:`tar -xzf "${a}" -C "${t}"`,{stdio:`pipe`});let c=T.join(t,i),l=T.join(n,i);return await ye.copyFile(c,l),r||await ye.chmod(l,493),{ok:!0,output:`Updated to ${e.latestVersion}`}}catch(e){return{ok:!1,output:e instanceof Error?e.message:`Unknown error`}}finally{await ye.rm(t,{recursive:!0,force:!0}).catch(()=>{})}}function mV(e,t){let n=e=>{let n=e.toLowerCase();if(n===t)return 1e3;if(n.startsWith(t))return 900;let r=0,i=-1;for(let e of t){let t=n.indexOf(e,i+1);if(t===-1)return 0;r+=100-(t-i),i=t}return r+=Math.max(0,50-n.length),r},r=null,i=0;for(let t of e){let e=Math.max(n(t.name??``),n(t.llmName));e>i&&(i=e,r=t.llmName)}return i>=100?r:null}async function hV(e,t){let n=(await e.listLLMModels())?.result??[];return n.length||(process.stderr.write(`Error: No models available.
|
|
73327
|
+
`))}}r=dB(e,r),e.renderCache={lines:[r],width:n,height:0,left:l,top:u},t.write(l,u,r,d)}else e.renderCache=void 0;e.renderDirty=!1;return}let f=!1;if(e.nodeName===`jar-view`){e.style.backgroundColor&&fB(l,u,e,t),e.style.borderStyle&&aB(l,u,e,t);let n=e.style.overflowX===`hidden`||e.style.overflow===`hidden`,r=e.style.overflowY===`hidden`||e.style.overflow===`hidden`;if(n||r){let i=n?l+lB(e.style,`Left`):void 0,a=n?l+c.getComputedWidth()-lB(e.style,`Right`):void 0,o=r?u+lB(e.style,`Top`):void 0,s=r?u+c.getComputedHeight()-lB(e.style,`Bottom`):void 0;t.clip({x1:i,x2:a,y1:o,y2:s}),f=!0}}if(e.nodeName===`jar-root`||e.nodeName===`jar-view`){let n=f?u+lB(e.style,`Top`):o,r=f?u+c.getComputedHeight()-lB(e.style,`Bottom`):s;for(let i of e.childNodes)pB(i,t,{offsetX:l,offsetY:u,transformers:d,clipY1:n,clipY2:r});f&&t.unclip()}e.renderDirty=!1};var mB=class{rootNode;lastWidth=0;cachedLines=null;output=new vz(0,0);constructor(e){this.rootNode=e}notifyCommit(){this.cachedLines=null}render(e){let t=e!==this.lastWidth;if(t&&(this.clearAllRenderCaches(this.rootNode),this.lastWidth=e),this.cachedLines&&!this.rootNode.renderDirty&&!t)return this.cachedLines;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,1);let n=Math.ceil(this.rootNode.yogaNode.getComputedHeight());if(n<=0)return this.cachedLines=[],this.cachedLines;this.output.reset(e,n),pB(this.rootNode,this.output,{});let r=this.output.get(),i=!1;for(let t of r)if(mI(t)>e){i=!0;break}return this.cachedLines=i?r.map(t=>mI(t)>e?SI(t,e):t):r,this.cachedLines}invalidate(){this.cachedLines=null,this.clearAllRenderCaches(this.rootNode)}clearAllRenderCaches(e){e.renderDirty=!0,e.renderCache=void 0;for(let t of e.childNodes)t.nodeName!==`#text`&&this.clearAllRenderCaches(t)}},hB;(function(e){e[e.BlinkingBlock=0]=`BlinkingBlock`,e[e.BlinkingBlockDefault=1]=`BlinkingBlockDefault`,e[e.SteadyBlock=2]=`SteadyBlock`,e[e.BlinkingUnderline=3]=`BlinkingUnderline`,e[e.SteadyUnderline=4]=`SteadyUnderline`,e[e.BlinkingBar=5]=`BlinkingBar`,e[e.SteadyBar=6]=`SteadyBar`})(hB||={});const gB=`\x1B[?25h`,_B=`\x1B[?25l`;function vB(e,t){let n=``;return t!==``&&(n=typeof Buffer<`u`?Buffer.from(t).toString(`base64`):btoa(t)),`\x1B]52;`+String.fromCharCode(e)+`;`+n+`\x07`}function yB(e){return vB(99,e)}function bB(e){let t=e??Gz(),n=t.TERM_PROGRAM.toLowerCase(),r=t.TERM.toLowerCase(),i=(t.LC_TERMINAL??``).toLowerCase();if(n===`iterm.app`)return`iterm2`;if(n===`wezterm`)return`wezterm`;if(n===`ghostty`)return`ghostty`;if(n===`vscode`)return`vscode`;if(n===`tmux`)return`tmux`;if(t.WT_SESSION)return`windows-terminal`;if(r.includes(`kitty`))return`kitty`;if(r.includes(`alacritty`))return`alacritty`;if(r.includes(`foot`))return`foot`;if(r.includes(`contour`))return`contour`;if(r.includes(`rio`))return`rio`;if(r.includes(`ghostty`))return`ghostty`;if(r.includes(`wezterm`))return`wezterm`;if(r.startsWith(`tmux`))return`tmux`;if(r.startsWith(`screen`))return`screen`;if(r===`xterm`||r.startsWith(`xterm-`))return`xterm`;if(r===`linux`)return`linux`;if(!n&&i){if(i===`iterm2`)return`iterm2`;if(i===`wezterm`)return`wezterm`}return`unknown`}function xB(e){return(e??Gz()).isTTY}function SB(e){let t=bB(e);return t===`windows-terminal`||t===`iterm2`||t===`wezterm`||t===`ghostty`}function CB(e){let t=bB(e);return t===`iterm2`||t===`kitty`||t===`wezterm`||t===`ghostty`||t===`alacritty`||t===`foot`||t===`xterm`||t===`tmux`||t===`windows-terminal`||t===`rio`||t===`contour`}function wB(e){let t=bB(e);return t===`iterm2`||t===`kitty`||t===`wezterm`||t===`ghostty`||t===`alacritty`||t===`foot`||t===`contour`||t===`rio`||t===`vscode`||t===`windows-terminal`}function TB(e,...t){return`\x1B]8;`+(t.length>0?t.join(`:`):``)+`;`+e+`\x07`}function EB(...e){return TB(``,...e)}function DB(e){return e.replace(/[\x07\x1b\x9c]/g,``)}function OB(e){return`\x1B]9;`+DB(e)+`\x07`}function kB(e,...t){return`\x1B]99;`+t.map(DB).join(`:`)+`;`+DB(e)+`\x07`}function AB(e){return`\x1B]777;notify;;`+DB(e)+`\x07`}const jB=`\x1B]9;4;0\x07`;function MB(e){return`\x1B]9;4;1;`+Math.min(Math.max(0,e),100)+`\x07`}function NB(e){return`\x1B]9;4;2;`+Math.min(Math.max(0,e),100)+`\x07`}function PB(e){return`\x1B]9;4;4;`+Math.min(Math.max(0,e),100)+`\x07`}var FB=class{env;profile;terminalType;_isDark;_writer;_progressHideTimer=null;constructor(e){this.env=e?.env??Gz(),this.profile=qz(this.env),Zz(this.profile),this.terminalType=bB(this.env),this._isDark=e?.isDark??Dz(),this._writer=e?.writer??null,e?.isDark!==void 0&&Oz(e.isDark)}get isDark(){return this._isDark}setDark(e){this._isDark=e,Oz(e)}resolveAdaptiveColor(e){if(typeof e==`string`)return Uz.parse(e);let t=this._isDark?e.dark:e.light;return Uz.parse(t)}colorize(e,t,n){if(!t)return e;let r=this.resolveAdaptiveColor(t);if(!r)return e;let i=Qz(r,this.profile);return i?`\x1B[`+(n===`foreground`?i.fgSequence():i.bgSequence())+`m`+e+`\x1B[0m`:e}styledText(){return nB(this.profile)}write(e){this._writer?this._writer(e):typeof process<`u`&&process.stdout?.isTTY&&process.stdout.write(e)}notify(e){if(!xB(this.env))return;let t=this.terminalType,{title:n,body:r}=e,i=n?`${n}:\n${r}`:r;t===`kitty`&&(n?this.write(kB(r,`d=0:p=title`,n)):this.write(kB(r))),this.write(AB(i)),this.write(OB(i))}showProgress(e){if(!SB(this.env))return;this.clearProgressTimer();let t=e.state??`normal`,n=Math.min(Math.max(0,e.percentage??0),100);switch(t){case`indeterminate`:this.write(`\x1B]9;4;3\x07`);break;case`error`:this.write(NB(n));break;case`warning`:this.write(PB(n));break;default:this.write(MB(n));break}(t===`error`||n>=100)&&this.scheduleProgressHide()}hideProgress(){this.clearProgressTimer(),SB(this.env)&&this.write(jB)}async trackProgress(e){this.showProgress({state:`indeterminate`});try{let t=await e;return this.showProgress({percentage:100}),this.scheduleProgressHide(),t}catch(e){throw this.showProgress({percentage:100,state:`error`}),this.scheduleProgressHide(),e}}copyToClipboard(e){CB(this.env)&&this.write(yB(e))}clearClipboard(){CB(this.env)&&this.write(`\x1B]52;c;\x07`)}hyperlink(e,t){return wB(this.env)?TB(e)+t+EB():t}clearProgressTimer(){this._progressHideTimer&&=(clearTimeout(this._progressHideTimer),null)}scheduleProgressHide(){this.clearProgressTimer(),this._progressHideTimer=setTimeout(()=>{this.write(jB),this._progressHideTimer=null},500)}},IB=class{tui;terminal;terminalOutput;rootNode;bridge;container;exitCallbacks=[];exitPromise;resolveExit;exitOnCtrlC;ownsTui;suspendable;onSuspended;cleanupSuspend;originalWarningListeners;warningInterceptor;constructor(e={}){this.exitOnCtrlC=e.exitOnCtrlC??!0,this.suspendable=e.suspendable??!1,this.onSuspended=e.onSuspended,e.tui?(this.tui=e.tui,this.terminal=e.tui.terminal,this.ownsTui=!1):e.terminal?(this.terminal=e.terminal,this.tui=new oL(this.terminal),this.ownsTui=!0):(this.terminal=new gL,this.tui=new oL(this.terminal),this.ownsTui=!0),this.terminalOutput=new FB({writer:e=>this.terminal.write(e)}),this.rootNode=WR(`jar-root`),this.rootNode.yogaNode.setFlexDirection(0),this.rootNode.yogaNode.setFlexGrow(1),this.rootNode.onRender=()=>{this.bridge.notifyCommit(),this.tui.requestRender(),performance.clearMeasures()},this.bridge=new mB(this.rootNode),this.tui.addChild(this.bridge),this.container=az.createContainer(this.rootNode,0,null,!1,null,`jar`,()=>{},()=>{},()=>{},()=>{}),this.exitPromise=new Promise(e=>{this.resolveExit=e}),this.exitOnCtrlC&&this.tui.addInputListener(e=>{if(!BI(e)&&qI(e,`ctrl+c`))return this.exit(),{consume:!0}})}render(e){az.updateContainerSync(e,this.container,null),az.flushSyncWork()}start(){this.ownsTui&&this.tui.start(),this.setupWarningInterceptor(),this.suspendable&&(this.cleanupSuspend=this.setupSuspendHandler())}exit(e){for(let t of this.exitCallbacks)t(e);this.unmount()}onExit(e){this.exitCallbacks.push(e)}unmount(){if(this.warningInterceptor&&=(U.removeListener(`warning`,this.warningInterceptor),void 0),this.originalWarningListeners){let e=U.listeners(`warning`);for(let t of this.originalWarningListeners)e.includes(t)||U.on(`warning`,t);this.originalWarningListeners=void 0}this.cleanupSuspend?.(),this.ownsTui&&this.disableInputProtocols(),az.updateContainerSync(null,this.container,null),az.flushSyncWork(),this.tui.removeChild(this.bridge),this.ownsTui&&this.tui.stop(),this.rootNode.yogaNode?.unsetMeasureFunc(),this.rootNode.yogaNode?.free(),this.rootNode.yogaNode=void 0,this.resolveExit()}cleanupTerminal(){this.ownsTui&&(this.cleanupSuspend?.(),this.disableInputProtocols(),this.tui.stop(),U.stdout.write(gB))}disableInputProtocols(){this.terminal.write(vL),this.terminal.write(`\x1B[?2004l`),this.terminal.kittyProtocolActive&&this.terminal.write(`\x1B[<u`)}setupWarningInterceptor(){this.originalWarningListeners||(this.originalWarningListeners=U.rawListeners(`warning`),U.removeAllListeners(`warning`),this.warningInterceptor=()=>{},U.on(`warning`,this.warningInterceptor))}setupSuspendHandler(){if(U.platform===`win32`||!this.ownsTui)return()=>{};let e=!1,t=()=>{e=this.terminal.kittyProtocolActive,U.stdout.isTTY&&(this.disableInputProtocols(),U.stdout.write(gB)),U.stdin.isTTY&&U.stdin.isRaw&&U.stdin.setRawMode(!1),this.onSuspended?.(),U.removeListener(`SIGTSTP`,t),U.kill(U.pid,`SIGTSTP`)},n=()=>{U.stdin.isTTY&&U.stdin.setRawMode(!0),U.stdout.isTTY&&(U.stdout.write(_B),this.terminal.write(`\x1B[?2004h`),this.terminal.write(_L),e&&this.terminal.write(`\x1B[>7u`)),U.on(`SIGTSTP`,t),this.tui.requestRender(!0)};return U.on(`SIGTSTP`,t),U.on(`SIGCONT`,n),()=>{U.removeListener(`SIGTSTP`,t),U.removeListener(`SIGCONT`,n)}}waitUntilExit(){return this.exitPromise}getRootNode(){return this.rootNode}};function LB(e,t){let n=new IB(t),r=Y.createElement(dz,{tui:n.tui,terminal:n.terminal,terminalOutput:n.terminalOutput,exit:e=>n.exit(e),children:e});return n.render(r),n.start(),{rerender(e){let t=Y.createElement(dz,{tui:n.tui,terminal:n.terminal,terminalOutput:n.terminalOutput,exit:e=>n.exit(e),children:e});n.render(t)},unmount(){n.unmount()},waitUntilExit(){return n.waitUntilExit()},cleanupTerminal(){n.cleanupTerminal()}}}function X({children:e,...t}){return(0,J.jsx)(`jar-view`,{style:{flexWrap:`nowrap`,flexDirection:`row`,flexGrow:0,flexShrink:1,...t,overflowX:t.overflowX??t.overflow??`visible`,overflowY:t.overflowY??t.overflow??`visible`},children:e})}function Z({color:e,backgroundColor:t,dimColor:n=!1,bold:r=!1,italic:i=!1,underline:a=!1,strikethrough:o=!1,inverse:s=!1,wrap:c=`wrap`,transform:l,children:u}){if(u==null)return null;let d=(0,Y.useCallback)(c=>(n&&(c=nB().dim().render(c)),e&&(c=eB(c,e,`foreground`)),t&&(c=eB(c,t,`background`)),r&&(c=nB().bold().render(c)),i&&(c=nB().italic().render(c)),a&&(c=nB().underline().render(c)),o&&(c=nB().strikethrough().render(c)),s&&(c=nB().reverse().render(c)),l&&(c=l(c)),c),[e,t,n,r,i,a,o,s,l]);return(0,J.jsx)(`jar-text`,{style:{flexGrow:0,flexShrink:0,flexDirection:`row`,textWrap:c},internal_transform:d,children:u})}const RB=/\x1b\[[\d:]*;(\d+)/;function zB(e){let t=RB.exec(e);return t?(parseInt(t[1],10)-1&8)!=0:!1}const BB={upArrow:!1,downArrow:!1,leftArrow:!1,rightArrow:!1,pageDown:!1,pageUp:!1,home:!1,end:!1,return:!1,escape:!1,ctrl:!1,shift:!1,tab:!1,backspace:!1,delete:!1,meta:!1,super:!1,paste:!1,raw:``},VB=(e,t={})=>{let{addInputListener:n}=(0,Y.use)(cz),r=(0,Y.useRef)(e);r.current=e,(0,Y.useEffect)(()=>{if(t.isActive!==!1)return n(e=>{if(BI(e))return;if(e.startsWith(`\x1B[200~`)){let t=e.indexOf(`\x1B[201~`),n=t===-1?e.slice(6):e.slice(6,t);BB.upArrow=!1,BB.downArrow=!1,BB.leftArrow=!1,BB.rightArrow=!1,BB.pageDown=!1,BB.pageUp=!1,BB.home=!1,BB.end=!1,BB.return=!1,BB.escape=!1,BB.ctrl=!1,BB.shift=!1,BB.tab=!1,BB.backspace=!1,BB.delete=!1,BB.meta=!1,BB.super=!1,BB.paste=!0,BB.raw=e,r.current(n,{...BB});return}let t=JI(e),n=t?t.split(`+`):[],i=n[n.length-1]??``,a=n.includes(`ctrl`),o=n.includes(`shift`),s=n.includes(`alt`);BB.upArrow=i===`up`,BB.downArrow=i===`down`,BB.leftArrow=i===`left`,BB.rightArrow=i===`right`,BB.pageDown=i===`pagedown`,BB.pageUp=i===`pageup`,BB.home=i===`home`,BB.end=i===`end`,BB.return=i===`return`||i===`enter`,BB.escape=i===`escape`,BB.ctrl=a,BB.shift=o,BB.tab=i===`tab`,BB.backspace=i===`backspace`,BB.delete=i===`delete`,BB.meta=s,BB.super=zB(e),BB.paste=!1,BB.raw=e;let c=BB,l=``;if(a&&i)l=i;else if(!c.upArrow&&!c.downArrow&&!c.leftArrow&&!c.rightArrow&&!c.pageDown&&!c.pageUp&&!c.home&&!c.end&&!c.return&&!c.escape&&!c.tab&&!c.backspace&&!c.delete){let t=ZI(e);t===void 0?e.length===1?l=e:i.length===1&&(l=i):l=t}r.current(l,{...c})})},[t.isActive,n])},HB=({isActive:e=!0,autoFocus:t=!1,id:n}={})=>{let{activeId:r,add:i,remove:a,activate:o,deactivate:s,focus:c}=(0,Y.use)(oz),l=(0,Y.useMemo)(()=>n??Math.random().toString().slice(2,7),[n]);return(0,Y.useEffect)(()=>(i(l,{autoFocus:t}),()=>{a(l)}),[l,t]),(0,Y.useEffect)(()=>{e?o(l):s(l)},[e,l]),{isFocused:!!l&&r===l,focus:c}};function UB(){return(0,Y.use)(sz)}const WB=()=>{let e=(0,Y.use)(uz);if(!e)throw Error(`useTerminal must be used within a jar render context`);return e.output},GB=RegExp(`[\\x1b\\x9b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]|\\x1b\\][\\s\\S]*?(?:\\x07|\\x1b\\\\)`,`g`);function KB(){return new RegExp(GB.source,`g`)}function qB(e){return e.replace(GB,``)}function JB(e){return e.replace(/[\x07\x1b\x9c]/g,``)}function YB(e){return`\x1B]2;`+JB(e)+`\x07`}var XB=W(((e,t)=>{t.exports={name:`@codellm/cli`,version:`2.4.6-canary.3`,private:!0,bin:{abacusai:`dist/index.mjs`},files:[`dist`,`LICENSE.txt`],type:`module`,scripts:{"prepare-publish":`bun ./scripts/prepare-publish.ts`,build:`tsdown`,"check-types":`tsgo -b --noEmit`,test:`FORCE_COLOR=1 vitest run`,"test:watch":`FORCE_COLOR=1 vitest`,"test:ui":`FORCE_COLOR=1 vitest --ui`,"test:coverage":`FORCE_COLOR=1 vitest run --coverage`},dependencies:{"@clack/prompts":`^0.11.0`,"@codellm/agent":`workspace:*`,"@codellm/api":`workspace:*`,"@codellm/auth":`workspace:*`,"@codellm/comms":`workspace:*`,"@codellm/jar":`workspace:*`,"@codellm/logging":`workspace:*`,"@codellm/product":`workspace:*`,"@logtape/logtape":`^2.0.5`,"@orpc/client":`catalog:`,"@orpc/contract":`catalog:`,"@orpc/server":`catalog:`,"@sentry/node-core":`10.46.0`,"@slack/web-api":`^7.0.0`,"@tanstack/react-query":`^5.90.19`,"@vscode/ripgrep":`1.17.0`,"ansi-styles":`^6.2.3`,"beautiful-mermaid":`^1.1.3`,"cli-boxes":`^4.0.1`,"cli-highlight":`^2.1.11`,conf:`^15.0.2`,diff:`^8.0.3`,fzf:`^0.5.2`,"gradient-string":`^3.0.0`,immer:`^11.1.4`,"isomorphic-git":`^1.36.1`,marked:`^17.0.4`,"patchright-core":`^1.58.2`,react:`^19.2.3`,"react-compiler-runtime":`^1.0.0`,remend:`^1.2.2`,semver:`^7.7.4`,"shell-history":`^2.0.1`,"string-width":`^8.1.0`,"strip-ansi":`^7.2.0`,trash:`^9.0.0`,zod:`catalog:`},devDependencies:{"@codellm/configs":`workspace:*`,"@playwright/mcp":`^0.0.68`,"@types/diff":`^8.0.0`,"@types/node":`catalog:`,"@types/react":`^19.2.9`,"@types/semver":`^7.7.1`,"@typescript/native-preview":`catalog:`,"@vitejs/plugin-react":`^5.1.2`,"@vitest/coverage-v8":`^4.0.18`,"@vitest/ui":`^4.0.18`,"@xterm/addon-serialize":`^0.14.0`,"@xterm/headless":`^6.0.0`,"babel-plugin-react-compiler":`^1.0.0`,"cli-testing-library":`^3.0.1`,jsdom:`^27.4.0`,"node-pty":`^1.1.0`,"react-devtools-core":`^6.1.5`,"svg-term-cli":`^2.1.1`,tsdown:`^0.21.0`,vite:`catalog:`,vitest:`^4.0.18`},engines:{node:`>=18`}}})),ZB=Ge(XB(),1);let QB=null;function $B(e){let t=(0,_F.prerelease)(e);return t&&t.length>0&&typeof t[0]==`string`?t[0]:`latest`}function eV(){let e=process.env.npm_command;if(e===`exec`||e===`dlx`)return!0;let t=process.argv[1]??``;return!!/_npx[/\\]|[/\\]dlx[/\\]|\.cache[/\\]/.test(t)}function tV(){if(process.versions.bun===void 0)return!1;let e=process.argv[1]??process.argv[0]??``;return/[/\\]\.abacusai[/\\]bin[/\\]/.test(e)}function nV(){let e=`${cn.internalEnvPrefix}DEV`,t=process.env[e];if(t===`1`||t===`true`)return!0;let n=process.argv[1]??``;try{n=v(n)}catch{}if(/[/\\]\.abacusai[/\\]bin[/\\]/.test(n))return!1;let r=/[/\\]node_modules[/\\]/.test(n)||/[/\\]\.npm[/\\]/.test(n)||/[/\\]\.bun[/\\]/.test(n),i=!!process.env.npm_config_user_agent;return!r&&!i}function rV(){return`${process.platform===`win32`?`win32`:process.platform===`darwin`?`darwin`:`linux`}-${process.arch===`arm64`?`arm64`:`x64`}`}function iV(){let e=process.env.npm_config_user_agent;if(e){let t=e.split(`/`)[0];if(t===`yarn`||t===`pnpm`||t===`bun`||t===`npm`)return t}if(process.versions.bun!==void 0)return`bun`;let t=process.argv[1]??``;return/[/\\]\.?yarn[/\\]/.test(t)?`yarn`:/[/\\]\.?pnpm[/\\]/.test(t)?`pnpm`:/[/\\]\.bun[/\\]/.test(t)?`bun`:`npm`}async function aV(e){let t=Date.now();if(QB&&t-QB.timestamp<6e4)return QB.tags;let n=await fetch(`https://registry.npmjs.org/${e}`,{signal:AbortSignal.timeout(1e4),headers:{accept:`application/json`}});if(!n.ok)throw Error(`Registry returned ${n.status}`);let r=(await n.json())[`dist-tags`]??{};return QB={tags:r,timestamp:t},r}async function oV(e,t,n,r){let i=t??$B(e),a=(r??`https://apps.abacus.ai`).replace(/\/$/,``),o=new URL(`${a}/api/v0/_getCodellmCliVersion`);o.searchParams.set(`channel`,i),n&&o.searchParams.set(`platform`,n),o.searchParams.set(`cli_version`,e);let s=await fetch(o.toString(),{signal:AbortSignal.timeout(1e4)});if(s.status===204)return null;if(!s.ok)throw Error(`API returned ${s.status}`);let c=await s.json();return{currentVersion:e,latestVersion:c.result.version,tag:c.result.channel,packageManager:iV(),isEphemeral:eV(),downloadUrl:c.result.url}}async function sV(e){let t=$B(e),n=iV(),r=eV(),i=(await aV(ln.publishName))[t];return!i&&t!==`latest`||!i||i===e?null:{currentVersion:e,latestVersion:i,tag:t,packageManager:n,isEphemeral:r}}async function cV(e,t,n){if(tV())try{return await oV(e,t,rV(),n)}catch{return null}return await sV(e)}function lV(){return`${cn.binName} upgrade`}function uV(e){let t=`${ln.publishName}@${e.tag}`;switch(e.packageManager){case`yarn`:return`yarn global add ${t}`;case`pnpm`:return`pnpm add -g ${t}`;case`bun`:return`bun add -g ${t}`;default:return`npm install -g ${t}`}}function dV(e){try{return se(uV(e),{stdio:`pipe`}),!0}catch{return!1}}function fV(e){try{return{ok:!0,output:se(uV(e),{stdio:`pipe`,encoding:`utf-8`}).trim()}}catch(e){return{ok:!1,output:e instanceof Error&&`stderr`in e?String(e.stderr).trim():e instanceof Error?e.message:`Unknown error`}}}async function pV(e){if(!e.downloadUrl)return{ok:!1,output:`No download URL`};let t=T.join(M.tmpdir(),`abacusai-update-${Date.now()}`),n=T.join(M.homedir(),`.${cn.configDirName}`,`bin`),r=process.platform===`win32`,i=r?`${cn.binName}.exe`:cn.binName;try{await ye.mkdir(t,{recursive:!0});let a=T.join(t,r?`update.zip`:`update.tar.gz`),o=await fetch(e.downloadUrl);if(!o.ok)throw Error(`Download failed: ${o.status}`);let s=Buffer.from(await o.arrayBuffer());await ye.writeFile(a,s),se(r?`powershell -Command "Expand-Archive -Path '${a}' -DestinationPath '${t}' -Force"`:`tar -xzf "${a}" -C "${t}"`,{stdio:`pipe`});let c=T.join(t,i),l=T.join(n,i);return await ye.copyFile(c,l),r||await ye.chmod(l,493),{ok:!0,output:`Updated to ${e.latestVersion}`}}catch(e){return{ok:!1,output:e instanceof Error?e.message:`Unknown error`}}finally{await ye.rm(t,{recursive:!0,force:!0}).catch(()=>{})}}function mV(e,t){let n=e=>{let n=e.toLowerCase();if(n===t)return 1e3;if(n.startsWith(t))return 900;let r=0,i=-1;for(let e of t){let t=n.indexOf(e,i+1);if(t===-1)return 0;r+=100-(t-i),i=t}return r+=Math.max(0,50-n.length),r},r=null,i=0;for(let t of e){let e=Math.max(n(t.name??``),n(t.llmName));e>i&&(i=e,r=t.llmName)}return i>=100?r:null}async function hV(e,t){let n=(await e.listLLMModels())?.result??[];return n.length||(process.stderr.write(`Error: No models available.
|
|
73328
73328
|
`),process.exit(1)),t?mV(n,t.toLowerCase())||(process.stderr.write(`Warning: Model "${t}" not found. Using default: ${n[0].llmName}\n`),n[0].llmName):n[0].llmName}const gV=it([`codellm`,`cli`,`exit`]),_V=new Set,vV=new Set,yV=new Set;let bV=!1,xV=!1,SV=null,CV;async function wV(e){let t=e.map(e=>new Promise(t=>{let n=`writableLength`in e?e.writableLength:0;if((`bufferSize`in e?e.bufferSize:n)===0){t();return}let r=e.write.bind(e),i=!1,a=()=>{let n=`writableLength`in e?e.writableLength:0;(`bufferSize`in e?e.bufferSize:n)===0&&!i&&(i=!0,e.write=r,t())};e.once(`drain`,a),e.write(``,`utf-8`,()=>{a()}),e.write=function(){return!1}}));await Promise.all(t)}async function TV(e,t,n,r){if(bV)return;r?.debug?.(`Executing exit handlers`,{shouldManuallyExit:e,isSynchronous:t,signal:n,asyncCallbacks:_V.size,syncCallbacks:vV.size}),bV=!0,_V.size>0&&t&&gV.error`SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.`;let i=0;n>0?i=128+n:CV===void 0?(typeof U.exitCode==`number`||typeof U.exitCode==`string`)&&(i=Number(U.exitCode)):i=CV;let a=(t=!1)=>{(t||e)&&(SV?SV.call(U,i):U.exit(i))};for(let e of vV)try{e(i)}catch(e){gV.error`Error in synchronous exit hook: ${e}`}if(t){a();return}let o=[],s=0;for(let[e,t]of _V)s=Math.max(s,t),o.push(Promise.resolve(e(i)).catch(e=>{gV.error`Error in asynchronous exit hook: ${e}`}));let c=Array.from(yV);c.length>0&&o.push(wV(c));let l=setTimeout(()=>{a(!0)},s);try{await Promise.all(o),clearTimeout(l),a()}catch(e){clearTimeout(l),gV.error`Error during exit cleanup: ${e}`,a(!0)}}function EV(){xV||(xV=!0,U.once(`beforeExit`,()=>{TV(!0,!1,-128)}),U.once(`SIGINT`,()=>{TV(!0,!1,2)}),U.once(`SIGTERM`,()=>{TV(!0,!1,15)}),U.once(`exit`,()=>{TV(!1,!0,0)}),U.on(`message`,e=>{e===`shutdown`&&TV(!0,!0,-128)}),SV||(SV=U.exit.bind(U),U.exit=function(e){if(CV===void 0&&(CV=e??0),_V.size===0&&yV.size===0){if(SV){SV(e??0);return}U.exit(e??0)}TV(!0,!1,-128).catch(e=>{gV.error`Error during exit: ${e}`,SV?SV(1):U.exit(1)})}))}function DV(e,t){if(typeof e!=`function`)throw TypeError(`callback must be a function`);if(bV)throw Error(`Cannot install exit hook while exit handlers are running`);t?.logger?.debug?.(`Registering exit hook`,{wait:t?.wait,hasStreams:t?.streams!==void 0}),EV();let n=t?.wait??0,r=t?.streams??[U.stdout,U.stderr];if(n>0){let t=[e,n];_V.add(t);for(let e of r)yV.add(e);return()=>{_V.delete(t);for(let e of r)yV.delete(e)}}return vV.add(e),()=>{vV.delete(e)}}function OV(e){e!==void 0&&(U.exitCode=e),TV(!0,!1,-128)}const kV=`${cn.internalEnvPrefix}CLIENT_KIND`;function AV(){let e=process.env[kV]?.trim();if(!e)return Je.CLI;try{return Ye(e)}catch{throw Error(`Invalid ${kV} value: ${e}. Expected one of ${Object.values(Je).join(`, `)}.`)}}function jV(e){process.stdout.write(JSON.stringify(e)+`
|
|
73329
73329
|
`)}function MV(e){try{return JSON.parse(e)}catch{return null}}async function NV({agentArgs:e}){Sl(`ndjson IPC host started`,`cli`);let t=AV(),n=await FF.create(),r=new Fl(n,hn(),ln.userAgentNames.desktop,ZB.default.version);if(!n.isAuthenticated())try{(await r.getUserInfo())?.result?.email||(process.stderr.write(`Error: Not authenticated. Set ABACUS_DEVICE_CODE environment variable.
|
|
73330
73330
|
`),process.exit(1))}catch{process.stderr.write(`Error: Not authenticated. Set ABACUS_DEVICE_CODE environment variable.
|