offsite 0.0.76 → 0.0.77

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.
@@ -54,4 +54,4 @@ import{i as e,t}from"./rolldown-runtime-COiEfhsA.js";import{c as n,l as r,r as i
54
54
 
55
55
  `)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=$a,c=!R.jitless,l=c&&eo.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?wl([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function Dl(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=>!bo(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=>Eo(e,r,Xo())))}),t)}var Ol=L(`$ZodUnion`,(e,t)=>{B.init(e,t),I(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),I(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),I(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),I(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>Va(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Dl(t,r,e,i)):Dl(o,r,e,i)}});function kl(e){let t=new Map;for(let n of e.options){let r=n._zod.propValues?.[e.discriminator];if(!r||r.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(n)}"`);for(let e of r)if(t.has(e)){if(e!==void 0)throw Error(`Duplicate discriminator value "${String(e)}"`);t.set(e,null)}else t.set(e,n)}return t}var Al=L(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,Ol.init(e,t);let n=e._zod.parse;I(e,`propValues`,e=>{let t={},n=0;for(let r of e.def.options){let i=r._zod.propValues;if(!i||Object.keys(i).length===0)throw Error(`Invalid discriminated union option at index "${e.def.options.indexOf(r)}"`);i[e.def.discriminator]?.has(void 0)&&n++;for(let[e,n]of Object.entries(i)){Object.prototype.hasOwnProperty.call(t,e)||Ua(t,e,new Set);for(let r of n)t[e].add(r)}}return!e.def.unionFallback&&n>1&&t[e.def.discriminator]?.delete(void 0),t}),t.options.forEach((e,n)=>{let r=Wa(e._zod.def);if(r&&!Object.prototype.hasOwnProperty.call(r,t.discriminator))throw Error(`Invalid discriminated union option at index "${n}"`)});let r=za(()=>kl(t));e._zod.parse=(i,a)=>{let o=i.value;if(!$a(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=o?.[t.discriminator],c=r.value.get(s);return c&&(s!==void 0||a.direction!==`backward`)?c._zod.run(i,a):t.unionFallback||a.direction===`backward`?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,options:Array.from(r.value.keys()).filter(e=>r.value.get(e)!==null),input:o,path:[t.discriminator],inst:e}),i)}}),jl=L(`$ZodIntersection`,(e,t)=>{B.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])=>Nl(e,t,n)):Nl(e,i,a)}});function Ml(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(to(e)&&to(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=Ml(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=Ml(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 Nl(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=Ml(t.value,n.value);if(!c.valid){if(bo(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var Pl=L(`$ZodEnum`,(e,t)=>{B.init(e,t);let n=Fa(t.entries),r=new Set(n);e._zod.values=r,I(e,`pattern`,e=>{let t=Fa(e.def.entries).filter(e=>ro.has(typeof e));return RegExp(t.length?`^(${t.map(e=>io(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),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}}),Fl=L(`$ZodLiteral`,(e,t)=>{B.init(e,t);let n=new Set(t.values);e._zod.values=n,I(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?io(e):e?io(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`)}),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}}),Il=L(`$ZodTransform`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,R.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yo(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 Jo;return n.value=i,n}});function Ll(e,t){return e.value=t.issues.length?void 0:t.value,e}var Rl=L(`$ZodOptional`,(e,t)=>{B.init(e,t),I(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,I(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),I(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Va(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>Ll(e,t)):Ll(e,r)}return t.innerType._zod.run(e,n)}}),zl=L(`$ZodExactOptional`,(e,t)=>{Rl.init(e,t),I(e,`values`,e=>e.def.innerType._zod.values),I(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Bl=L(`$ZodNullable`,(e,t)=>{B.init(e,t),I(e,`optin`,e=>e.def.innerType._zod.optin),I(e,`optout`,e=>e.def.innerType._zod.optout),I(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Va(t.source)}|null)$`):void 0}),I(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Vl=L(`$ZodDefault`,(e,t)=>{B.init(e,t),e._zod.optin=`defaulted`,I(e,`values`,e=>e.def.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=>Hl(e,t)):Hl(r,t)}});function Hl(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Ul=L(`$ZodPrefault`,(e,t)=>{B.init(e,t),e._zod.optin=`defaulted`,I(e,`values`,e=>e.def.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))}),Wl=L(`$ZodNonOptional`,(e,t)=>{B.init(e,t),I(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].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=>Gl(t,e)):Gl(i,e)}});function Gl(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function Kl(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>Eo(e,r,Xo()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}var ql=L(`$ZodCatch`,(e,t)=>{B.init(e,t),I(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),I(e,`optout`,e=>e.def.innerType._zod.optout),I(e,`values`,e=>e.def.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({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>Kl(e,r,t,n)):Kl(e,r,t,n)}}),Jl=L(`$ZodPipe`,(e,t)=>{B.init(e,t),I(e,`values`,e=>e.def.in._zod.values),I(e,`optin`,e=>e.def.in._zod.optin),I(e,`optout`,e=>e.def.out._zod.optout),I(e,`propValues`,e=>e.def.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=>Yl(e,t.in,n)):Yl(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Yl(e,t.out,n)):Yl(r,t.out,n)}});function Yl(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}var Xl=L(`$ZodReadonly`,(e,t)=>{B.init(e,t),I(e,`propValues`,e=>e.def.innerType._zod.propValues),I(e,`values`,e=>e.def.innerType._zod.values),I(e,`optin`,e=>e.def.innerType?._zod?.optin),I(e,`optout`,e=>e.def.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(Zl):Zl(r)}});function Zl(e){return e.memo||(e.value=Object.freeze(e.value)),e}var Ql=L(`$ZodCustom`,(e,t)=>{z.init(e,t),B.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=>$l(t,n,r,e));$l(i,n,r,e)}});function $l(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(jo(e))}}var eu=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}},tu=`~memo`,nu=[];function ru(e){return typeof e==`object`&&!!e}function iu(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}var au=new WeakMap,ou=0,su=1,cu=2;function lu(e,t,n){let r=au.get(e);if(r!==void 0)return r?cu:ou;if(t.has(e))return cu;t.add(e);let i=ou,a=e=>{if(i!==cu&&e?._zod){let r=lu(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=ou;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?su:o.value?._zod?lu(o.value,t,n):ou;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=Wa(c);s(e?o(e,!0):su),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?lu(r,t,!1):su);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),uu(e,i)}function uu(e,t){return t!==su&&au.set(e,t===cu),t}function du(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}var fu,pu=[],mu={alloc(e,t,n){let r=fu;if(!r)return n;fu=void 0;let i={value:n,issues:null};return r.set(t.value,i),pu.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&gu(n,e.value))throw new eu;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=lu(e,new Set,!1);if(i===ou)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===cu||r?n=!0:r=!0}let l=s.value;if(!ru(l))return t(s,c);let u=c[tu];u||(u={buckets:new WeakMap,backEdges:void 0},c[tu]=u);let d;i===c?d=a:(d=du(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...iu(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;fu=d;let p=pu.length,m=t(s,c);fu=void 0;let h=pu.length>p?pu.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?iu(e.issues):nu),e)):(h&&(h.issues=m.issues.length?iu(m.issues):nu),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function hu(){return mu}function gu(e,t){let n=e[tu]?.backEdges;return n!==void 0&&ru(t)&&n.has(t)}var _u=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(Ao(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${oo(e.values[0])}`:`Invalid option: expected one of ${Ia(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${Ia(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function vu(){return{localeError:_u()}}var yu,bu=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 xu(){return new bu}(yu=globalThis).__zod_globalRegistry??(yu.__zod_globalRegistry=xu());var Su=globalThis.__zod_globalRegistry;function Cu(e){return e.checks&&=[...e.checks],e}function wu(e,t){return new e(Cu({type:`string`,...F(t)}))}function Tu(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...F(t)})}function Eu(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...F(t)})}function Du(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...F(t)})}function Ou(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...F(t)})}function ku(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...F(t)})}function Au(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...F(t)})}function ju(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...F(t)})}function Mu(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...F(t)})}function Nu(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...F(t)})}function Pu(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...F(t)})}function Fu(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...F(t)})}function Iu(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...F(t)})}function Lu(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...F(t)})}function Ru(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...F(t)})}function zu(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...F(t)})}function Bu(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...F(t)})}function Vu(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...F(t)})}function Hu(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...F(t)})}function Uu(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...F(t)})}function Wu(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...F(t)})}function Gu(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...F(t)})}function Ku(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...F(t)})}function qu(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...F(t)})}function Ju(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...F(t)})}function Yu(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...F(t)})}function Xu(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...F(t)})}function Zu(e,t){return new e(Cu({type:`number`,checks:[],...F(t)}))}function Qu(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...F(t)})}function $u(e,t){return new e({type:`boolean`,...F(t)})}function ed(e){return new e({type:`unknown`})}function td(e,t){return new e({type:`never`,...F(t)})}function nd(e,t){return new sc({check:`less_than`,...F(t),value:e,inclusive:!1})}function rd(e,t){return new sc({check:`less_than`,...F(t),value:e,inclusive:!0})}function id(e,t){return new cc({check:`greater_than`,...F(t),value:e,inclusive:!1})}function ad(e,t){return new cc({check:`greater_than`,...F(t),value:e,inclusive:!0})}function od(e,t){return new lc({check:`multiple_of`,...F(t),value:e})}function sd(e,t){return new dc({check:`max_length`,...F(t),maximum:e})}function cd(e,t){return new fc({check:`min_length`,...F(t),minimum:e})}function ld(e,t){return new pc({check:`length_equals`,...F(t),length:e})}function ud(e,t){return new hc({check:`string_format`,format:`regex`,...F(t),pattern:e})}function dd(e){return new gc({check:`string_format`,format:`lowercase`,...F(e)})}function fd(e){return new _c({check:`string_format`,format:`uppercase`,...F(e)})}function pd(e,t){return new vc({check:`string_format`,format:`includes`,...F(t),includes:e})}function md(e,t){return new yc({check:`string_format`,format:`starts_with`,...F(t),prefix:e})}function hd(e,t){return new bc({check:`string_format`,format:`ends_with`,...F(t),suffix:e})}function gd(e){return new xc({check:`overwrite`,tx:e})}function _d(e){return gd(t=>t.normalize(e))}function vd(){return gd(e=>e.trim())}function yd(){return gd(e=>e.toLowerCase())}function bd(){return gd(e=>e.toUpperCase())}function xd(){return gd(e=>Za(e))}function Sd(e,t,n){return new e({type:`array`,element:t,...F(n)})}function Cd(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...F(n)})}function wd(e,t){let n=Td(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(jo(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(jo(r))}},e(t.value,t)),t);return n}function Td(e,t){let n=new z({check:`custom`,...F(t)});return n._zod.check=e,n}function Ed(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Ua(e,t,n[t]);return e}function Dd(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??Su,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function Od(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function H(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),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;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,H(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Ed(o.schema,c),t.io===`input`&&U(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function kd(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Ad(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;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}/${kd(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+kd(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>
56
56
 
57
- 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);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function jd(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;jd(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var Md=new Set([`type`,`properties`,`required`,`additionalProperties`]),Nd=[`oneOf`,`anyOf`];function Pd(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Fd(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Md.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Pd(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Ua(n,r,e.length===1?e[0]:Fd(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Pd(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Id(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Md)if(t in e)return;let n=t.filter(e=>Nd.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Fd(t);else{let e=n[0],i=Nd.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Fd([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,Ed(e,r))}function Ld(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)):Ed(i,s),Ed(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??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())jd(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Id(e)}}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)}Ed(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Ua(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:zd(t,`input`,e.processors),output:zd(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function U(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 U(r.element,n);if(r.type===`set`)return U(r.valueType,n);if(r.type===`lazy`)return U(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`||r.type===`catch`)return U(r.innerType,n);if(r.type===`intersection`)return U(r.left,n)||U(r.right,n);if(r.type===`record`||r.type===`map`)return U(r.keyType,n)||U(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:U(r.in,n)||U(r.out,n);if(r.type===`object`){for(let e in r.shape)if(U(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(U(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(U(e,n))return!0;return!!(r.rest&&U(r.rest,n))}return!1}var Rd=(e,t={})=>n=>{let r=Dd({...n,processors:t});return H(e,r),Ad(r,e),Ld(r,e)},zd=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Dd({...i??{},target:a,io:t,processors:n});return H(e,o),Ad(o,e),Ld(o,e)},Bd=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Vd=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Hd=(e,t)=>{Bd(e,`minimum`,t),Vd(e,`maximum`,t)},Ud=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Wd=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Gd=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Kd=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},qd=(e,t)=>Bd(e,`minimum`,t.minimum),Jd=(e,t)=>Vd(e,`maximum`,t.maximum),Yd=e=>(t,n)=>{Kd(t,n.format);let[r,i]=e[n.format];Bd(t,`minimum`,r),Vd(t,`maximum`,i)},Xd={greater_than:(e,t)=>Bd(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Vd(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Ud(e,t.value),number_format:Yd(co),bigint_format:Yd(lo),min_length:qd,max_length:Jd,length_equals:(e,t)=>Hd(e,t.length),min_size:qd,max_size:Jd,size_equals:(e,t)=>Hd(e,t.size),string_format:(e,t)=>{Kd(e,t.format),t.pattern&&Wd(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Gd(e,t.mime)};function Zd(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Xd[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Bd(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Bd(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Vd(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Vd(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Ud(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Gd(t,i.mime);for(let e of i.patterns??[])Wd(t,e);return t}var Qd={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},$d=new Map([[il,Ws],[ol,Gs]]),ef=e=>$d.get(e)??e,tf=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Zd(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Qd[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(ef);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}))])}},nf=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Zd(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Od(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},rf=(e,t,n,r)=>{n.type=`boolean`},af=(e,t,n,r)=>{n.not={}},of=(e,t,n,r)=>{let i=e._zod.def,a=Fa(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},sf=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(Od(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Od(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);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}},cf=(e,t,n,r)=>{Od(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},lf=(e,t,n,r)=>{Od(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},uf=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Zd(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=H(a.element,t,{...r,path:[...r.path,`items`]})};function df(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?df(t.out):t.type===`catch`?df(t.innerType):e._zod.optin}var ff=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Od(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Ua(i.properties,e,H(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?df(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=H(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},pf=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>H(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},mf=(e,t,n,r)=>{let i=e._zod.def,a=H(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=H(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},hf=(e,t,n,r)=>{let i=e._zod.def,a=H(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`}]},gf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},_f=Symbol();function vf(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Od(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),_f):JSON.parse(o)}var yf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=vf(i.defaultValue,e,t,n,r);o!==_f&&(n.default=o)},bf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=vf(i.defaultValue,e,t,n,r);o!==_f&&(n._prefault=o)},xf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Od(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Sf=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;H(o,t,r);let s=t.seen.get(e);s.ref=o},Cf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},wf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Tf=new WeakSet([Object.prototype,Error.prototype]);function Ef(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var W=L(`ZodError`,(e,t)=>{ns.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);Tf.has(n)||(Tf.add(n),Ef(n,`format`,e=>t=>as(e,t)),Ef(n,`flatten`,e=>t=>is(e,t)),Ef(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,La,2)}),Ef(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,La,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),Df=ls(W),Of=us(W),kf=ds(W),Af=ps(W),jf=ys(W),Mf=bs(W),Nf=xs(W),Pf=Ss(W),Ff=Cs(W),If=ws(W),Lf=Ts(W),Rf=Es(W);function zf(){R.localeError||Xo(vu())}function Bf(){R.memoizer||Xo({memoizer:hu()})}var G=L(`ZodType`,(e,t)=>(zf(),B.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(P(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ao(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(im(e,t))},superRefine(e,t){return this.check(am(e,t))},overwrite(e){return this.check(gd(e))},optional(){return Bp(this)},exactOptional(){return Hp(this)},nullable(){return Wp(this)},nullish(){return Bp(Wp(this))},nonoptional(e){return Xp(this,e)},array(){return Cp(this)},or(e){return Op([this,e])},and(e){return Mp(this,e)},transform(e){return em(this,Rp(e))},default(e){return Kp(this,e)},prefault(e){return Jp(this,e)},catch(e){return Qp(this,e)},pipe(e){return em(this,e)},readonly(){return nm(this)},describe(e){let t=this.clone();return Su.add(t,{description:e}),t},meta(...e){if(e.length===0)return Su.get(this);let t=this.clone();return Su.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Po(this,`~standard`,{...Ec(this),jsonSchema:{input:zd(this,`input`),output:zd(this,`output`)}})},set"~standard"(e){No(this,`~standard`,e)},parse:function e(t,n){return Df(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await Of(this,t,n,{callee:e})},safeParse(e,t){return kf(this,e,t)},async safeParseAsync(e,t){return Af(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){No(this,`spa`,e)},validate(e,t){return gs(this,e,t)},validateAsync(e,t){return vs(this,e,t)},encode:function e(t,n){return jf(this,t,n,{callee:e})},decode:function e(t,n){return Mf(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await Nf(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await Pf(this,t,n,{callee:e})},safeEncode(e,t){return Ff(this,e,t)},safeDecode(e,t){return If(this,e,t)},async safeEncodeAsync(e,t){return Lf(this,e,t)},async safeDecodeAsync(e,t){return Rf(this,e,t)},toJSONSchema(e){return Rd(this,{})(e)},get description(){return Su.get(this)?.description},get _def(){return this._zod.def}}),Vf=L(`_ZodString`,(e,t)=>{Dc.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>tf(e,t,n,r)},Fo({format:e=>Zd(e).format??null,minLength:e=>Zd(e).minimum??null,maxLength:e=>Zd(e).maximum??null},{regex(...e){return this.check(ud(...e))},includes(...e){return this.check(pd(...e))},startsWith(...e){return this.check(md(...e))},endsWith(...e){return this.check(hd(...e))},min(...e){return this.check(cd(...e))},max(...e){return this.check(sd(...e))},length(...e){return this.check(ld(...e))},nonempty(...e){return this.check(cd(1,...e))},lowercase(e){return this.check(dd(e))},uppercase(e){return this.check(fd(e))},trim(){return this.check(vd())},normalize(...e){return this.check(_d(...e))},toLowerCase(){return this.check(yd())},toUpperCase(){return this.check(bd())},slugify(){return this.check(xd())}})),Hf=L(`ZodString`,(e,t)=>{Dc.init(e,t),Vf.init(e,t)},{email(e){return this.check(Tu(Jf,e))},url(e){return this.check(ju(Zf,e))},jwt(e){return this.check(Ku(fp,e))},emoji(e){return this.check(Mu(Qf,e))},guid(e){return this.check(Eu(Yf,e))},uuid(e){return this.check(Du(Xf,e))},uuidv4(e){return this.check(Ou(Xf,e))},uuidv6(e){return this.check(ku(Xf,e))},uuidv7(e){return this.check(Au(Xf,e))},nanoid(e){return this.check(Nu($f,e))},cuid(e){return this.check(Pu(ep,e))},cuid2(e){return this.check(Fu(tp,e))},ulid(e){return this.check(Iu(np,e))},base64(e){return this.check(Uu(lp,e))},base64url(e){return this.check(Wu(up,e))},xid(e){return this.check(Lu(rp,e))},ksuid(e){return this.check(Ru(ip,e))},ipv4(e){return this.check(zu(ap,e))},ipv6(e){return this.check(Bu(op,e))},cidrv4(e){return this.check(Vu(sp,e))},cidrv6(e){return this.check(Hu(cp,e))},e164(e){return this.check(Gu(dp,e))},datetime(e){return this.check(qu(Wf,e))},date(e){return this.check(Ju(Gf,e))},time(e){return this.check(Yu(Kf,e))},duration(e){return this.check(Xu(qf,e))}});function Uf(e){return wu(Hf,e)}var K=L(`ZodStringFormat`,(e,t)=>{V.init(e,t),Vf.init(e,t)}),Wf=L(`ZodISODateTime`,(e,t)=>{Kc.init(e,t),K.init(e,t)}),Gf=L(`ZodISODate`,(e,t)=>{qc.init(e,t),K.init(e,t)}),Kf=L(`ZodISOTime`,(e,t)=>{Jc.init(e,t),K.init(e,t)}),qf=L(`ZodISODuration`,(e,t)=>{Yc.init(e,t),K.init(e,t)}),Jf=L(`ZodEmail`,(e,t)=>{Ac.init(e,t),K.init(e,t)}),Yf=L(`ZodGUID`,(e,t)=>{Oc.init(e,t),K.init(e,t)}),Xf=L(`ZodUUID`,(e,t)=>{kc.init(e,t),K.init(e,t)}),Zf=L(`ZodURL`,(e,t)=>{Rc.init(e,t),K.init(e,t)}),Qf=L(`ZodEmoji`,(e,t)=>{zc.init(e,t),K.init(e,t)}),$f=L(`ZodNanoID`,(e,t)=>{Bc.init(e,t),K.init(e,t)}),ep=L(`ZodCUID`,(e,t)=>{Vc.init(e,t),K.init(e,t)}),tp=L(`ZodCUID2`,(e,t)=>{Hc.init(e,t),K.init(e,t)}),np=L(`ZodULID`,(e,t)=>{Uc.init(e,t),K.init(e,t)}),rp=L(`ZodXID`,(e,t)=>{Wc.init(e,t),K.init(e,t)}),ip=L(`ZodKSUID`,(e,t)=>{Gc.init(e,t),K.init(e,t)}),ap=L(`ZodIPv4`,(e,t)=>{Xc.init(e,t),K.init(e,t)}),op=L(`ZodIPv6`,(e,t)=>{$c.init(e,t),K.init(e,t)}),sp=L(`ZodCIDRv4`,(e,t)=>{el.init(e,t),K.init(e,t)}),cp=L(`ZodCIDRv6`,(e,t)=>{nl.init(e,t),K.init(e,t)}),lp=L(`ZodBase64`,(e,t)=>{al.init(e,t),K.init(e,t)}),up=L(`ZodBase64URL`,(e,t)=>{cl.init(e,t),K.init(e,t)}),dp=L(`ZodE164`,(e,t)=>{ll.init(e,t),K.init(e,t)}),fp=L(`ZodJWT`,(e,t)=>{dl.init(e,t),K.init(e,t)}),pp=L(`ZodNumber`,(e,t)=>{fl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>nf(e,t,n,r),e.isFinite=!0},Fo({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Zd(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Zd(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Zd(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Zd(e).format??null},{gt(e,t){return this.check(id(e,t))},gte(e,t){return this.check(ad(e,t))},min(e,t){return this.check(ad(e,t))},lt(e,t){return this.check(nd(e,t))},lte(e,t){return this.check(rd(e,t))},max(e,t){return this.check(rd(e,t))},int(e){return this.check(gp(e))},safe(e){return this.check(gp(e))},positive(e){return this.check(id(0,e))},nonnegative(e){return this.check(ad(0,e))},negative(e){return this.check(nd(0,e))},nonpositive(e){return this.check(rd(0,e))},multipleOf(e,t){return this.check(od(e,t))},step(e,t){return this.check(od(e,t))},finite(){return this}}));function mp(e){return Zu(pp,e)}var hp=L(`ZodNumberFormat`,(e,t)=>{pl.init(e,t),pp.init(e,t)});function gp(e){return Qu(hp,e)}var _p=L(`ZodBoolean`,(e,t)=>{ml.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rf(e,t,n,r)});function q(e){return $u(_p,e)}var vp=L(`ZodUnknown`,(e,t)=>{hl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function yp(){return ed(vp)}var bp=L(`ZodNever`,(e,t)=>{gl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>af(e,t,n,r)});function xp(e){return td(bp,e)}var Sp=L(`ZodArray`,(e,t)=>{Bf(),bl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>uf(e,t,n,r),e.element=t.element},{min(e,t){return this.check(cd(e,t))},nonempty(e){return this.check(cd(1,e))},max(e,t){return this.check(sd(e,t))},length(e,t){return this.check(ld(e,t))},unwrap(){return this.element}});function Cp(e,t){return Sd(Sp,e,t)}var wp=L(`ZodObject`,(e,t)=>{Bf(),El.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ff(e,t,n,r),Vo(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Pp(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(P(this._zod.def,{catchall:e}))},passthrough(){return this.clone(P(this._zod.def,{catchall:yp()}))},loose(){return this.clone(P(this._zod.def,{catchall:yp()}))},strict(){return this.clone(P(this._zod.def,{catchall:xp()}))},strip(){return this.clone(P(this._zod.def,{catchall:void 0}))},extend(e){return mo(this,e)},safeExtend(e){return go(this,e)},merge(e){return _o(this,e)},pick(e){return uo(this,e)},omit(e){return po(this,e)},partial(...e){return vo(zp,this,e[0])},exactPartial(...e){return vo(Vp,this,e[0],`exactPartial`)},required(...e){return yo(Yp,this,e[0])}});function Tp(e,t){return new wp({type:`object`,shape:e??{},...F(t)})}function Ep(e,t){return new wp({type:`object`,shape:e,catchall:xp(),...F(t)})}var Dp=L(`ZodUnion`,(e,t)=>{Ol.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pf(e,t,n,r),e.options=t.options});function Op(e,t){return new Dp({type:`union`,options:e,...F(t)})}var kp=L(`ZodDiscriminatedUnion`,(e,t)=>{Dp.init(e,t),Al.init(e,t)});function Ap(e,t,n){return new kp({type:`union`,options:t,discriminator:e,...F(n)})}var jp=L(`ZodIntersection`,(e,t)=>{jl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mf(e,t,n,r)});function Mp(e,t){return new jp({type:`intersection`,left:e,right:t})}var Np=L(`ZodEnum`,(e,t)=>{Pl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>of(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];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 Np({...t,checks:[],...F(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 Np({...t,checks:[],...F(r),entries:i})}});function Pp(e,t){return new Np({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...F(t)})}var Fp=L(`ZodLiteral`,(e,t)=>{Fl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>sf(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 Ip(e,t){return new Fp({type:`literal`,values:Array.isArray(e)?e:[e],...F(t)})}var Lp=L(`ZodTransform`,(e,t)=>{Bf(),Il.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>lf(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yo(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jo(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(jo(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Rp(e){return new Lp({type:`transform`,transform:e})}var zp=L(`ZodOptional`,(e,t)=>{Rl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bp(e){return new zp({type:`optional`,innerType:e})}var Vp=L(`ZodExactOptional`,(e,t)=>{zl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hp(e){return new Vp({type:`optional`,innerType:e})}var Up=L(`ZodNullable`,(e,t)=>{Bl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Wp(e){return new Up({type:`nullable`,innerType:e})}var Gp=L(`ZodDefault`,(e,t)=>{Vl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Kp(e,t){return new Gp({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():no(t)}})}var qp=L(`ZodPrefault`,(e,t)=>{Ul.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Jp(e,t){return new qp({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():no(t)}})}var Yp=L(`ZodNonOptional`,(e,t)=>{Wl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Xp(e,t){return new Yp({type:`nonoptional`,innerType:e,...F(t)})}var Zp=L(`ZodCatch`,(e,t)=>{ql.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Qp(e,t){return new Zp({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Uo(t)})}var $p=L(`ZodPipe`,(e,t)=>{Jl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sf(e,t,n,r),e.in=t.in,e.out=t.out});function em(e,t){return new $p({type:`pipe`,in:e,out:t})}var tm=L(`ZodReadonly`,(e,t)=>{Xl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function nm(e){return new tm({type:`readonly`,innerType:e})}var rm=L(`ZodCustom`,(e,t)=>{Ql.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cf(e,t,n,r)});function im(e,t={}){return Cd(rm,e,t)}function am(e,t){return wd(e,t)}var om=`no-project`;function sm(){return J.parseLocation(J.history.location).search}function cm(){let e=/^\/terminal\/([^/]+)$/.exec(J.history.location.pathname);if(e===null)return null;let t=decodeURIComponent(e[1]);return Y().machines.some(e=>e.id===t)?t:null}function lm(){let e=Lr({strict:!1,select:e=>e.machine??null});return Ih(t=>t.machines.some(t=>t.id===e)?e:null)}function um(){return sm().project??`global`}function dm(){return Rr({strict:!1,select:e=>e.project??`global`})}function fm(e){let t=sm();return t.machine===void 0||t.project===void 0||!e.includes(t.machine)?null:{machine:t.machine,projectId:t.project,sessionId:t.session??null}}function pm(e){Am({...sm(),...e},!0,J.history.location.state.layer)}function mm(e,t){Am({...sm(),...e},!1,t)}function hm(e){let t=Y();if(t.selection===null)throw Error(`no project is open to show the browser in`);if(e.startsWith(`file:`)){pm({panel:`browser`,browse:decodeURIComponent(new URL(e).pathname)});return}if(/^https?:\/\//i.test(e)||e.startsWith(`/`)||/^[a-z]:[\\/]/i.test(e)){pm({panel:`browser`,browse:e});return}let n=Lh(t,t.selection.machine,t.selection.projectId);if(n===void 0)throw Error(`project ${t.selection.projectId} is not listed`);pm({panel:`browser`,browse:`${n.path}/${e}`})}function gm(e,t){J.history.location.state.layer===e?J.history.back():t()}var _m=[],vm=!1,ym=!1,bm=!1;function xm(){return J.history.location.state.guard===!0}function Sm(){return bm}function Cm(){vm||(_m.length>0&&!xm()?J.history.push(J.history.location.href,{guard:!0}):_m.length===0&&xm()&&(vm=!0,J.history.back()))}function wm(){ym=xm(),J.history.subscribe(({action:e})=>{let t=ym;ym=xm(),e.type===`PUSH`||e.type===`REPLACE`?bm=!1:(bm=t,bm&&vm?vm=!1:bm&&_m.at(-1)?.(),setTimeout(Cm))}),setTimeout(Cm)}function Tm(e,t){let n=(0,k.useEffectEvent)(t);(0,k.useEffect)(()=>{if(!e)return;function t(){n()}return _m.push(t),setTimeout(Cm),()=>{_m.splice(_m.indexOf(t),1),setTimeout(Cm)}},[e])}var Em=`terminalProjects`;function Dm(){return JSON.parse(localStorage.getItem(Em)??`[]`)}function Om(){let e=sm();if(cm()!==null||e.machine===void 0||e.project===void 0||e.session===void 0)return;let t=`${e.machine} ${e.project}`,n=Dm().filter(e=>e!==t);localStorage.setItem(Em,JSON.stringify(e.bottom===`terminal`?[...n,t]:n))}function km(e=!1){let t=Y().selection;if(t===null){Am({project:cm()===null?void 0:sm().project},!0,J.history.location.state.layer);return}let n=sm(),r=n.machine===t.machine&&n.project===t.projectId&&n.session===void 0&&(t.sessionId===null||Y().loaded),i=Dm().includes(`${t.machine} ${t.projectId}`),a={machine:t.machine,project:t.projectId,session:t.sessionId??void 0,bottom:r?n.bottom:t.sessionId!==null&&i?`terminal`:void 0};if(cm()!==null){J.navigate({to:`/`,search:a,replace:e||xm(),state:{layer:`chat`},resetScroll:!1});return}let o=n.machine===a.machine&&n.project===a.project&&n.session===a.session,s=n.machine!==void 0&&n.session===void 0&&a.session===void 0;e||o||r||s?pm(a):mm(a,`chat`)}function Am(e,t,n){let r=cm(),i=xm(),a=t&&i?{layer:n,guard:i}:{layer:n};r===null?J.navigate({to:`/`,search:e,replace:t||i,state:a,resetScroll:!1}):J.navigate({to:`/terminal/$machine`,params:{machine:r},search:e,replace:t||i,state:a,resetScroll:!1})}function jm(e,t=null,n=!1){let r=Z(Y(),e.machine),i=Y().selection;localStorage.setItem(`lastProject`,JSON.stringify({machine:e.machine,projectId:e.projectId})),X({selection:e,loaded:e.sessionId===null,items:[],earlier:[],before:null,partial:``,requests:[],queue:[],settings:e.sessionId===null?i?.sessionId===null&&i.machine===e.machine?Y().settings:lg(r):Da(Hh(e))??cg(r.composer,Y().sessions.find(t=>t.machine===e.machine&&t.id===e.sessionId)?.provider??r.composer?.provider??`claude`),context:null,paletteOpen:!1,unseen:Y().unseen.filter(t=>e.sessionId===null||t!==lh(e.machine,e.sessionId))}),km(n),pg(e.machine),e.sessionId!==null&&r.status===`online`&&Mm(e.machine,e.projectId,e.sessionId,!0,t)}function Mm(e,t,n,r,i){M(e,`sessions.open`,{projectId:t,sessionId:n,opened:r,query:i}).then(t=>{t===null||Y().sessions.some(n=>n.machine===e&&n.id===t.id)||X({sessions:[...Y().sessions,{...t,machine:e}]})}).catch($)}function Nm(){X({selection:null,loaded:!1,items:[],earlier:[],before:null,partial:``,requests:[],queue:[],context:null}),km()}function Pm(){let e=Y().machines,t=localStorage.getItem(`lastTerminal`);return t!==null&&e.some(e=>e.id===t)?t:e.at(0)?.id??null}function Fm(e,t,n=!1){jm({machine:e,projectId:Lh(Y(),e,t)?.scratch===!0?om:t,sessionId:null},null,n)}function Im(){let e=Y(),t=localStorage.getItem(`lastProject`),n=t===null?null:JSON.parse(t),r=e.machines.filter(e=>e.system?.scratchAvailable===!0);if(n!==null&&n.projectId===`no-project`&&r.some(e=>e.id===n.machine))return n;let i=(n===null?void 0:e.projects.find(e=>e.machine===n.machine&&e.id===n.projectId))??e.projects.find(e=>!e.scratch);return i===void 0?r.length>0?{machine:r[0].id,projectId:om}:null:{machine:i.machine,projectId:i.id}}function Lm(e,t){let n=cm();(n!==e||um()!==t)&&(J.navigate({to:`/terminal/$machine`,params:{machine:e},search:{project:t===`global`?void 0:t},replace:n!==null||xm(),state:{layer:`chat`},resetScroll:!1}),Nm())}async function Rm(e,t,n,r){if(n===null)throw Error(`no session selected`);`Notification`in window&&Notification.permission==="default"&&Notification.requestPermission(),X({sentAt:Date.now()}),await M(n.machine,`sessions.send`,{sessionId:n.sessionId,projectId:n.projectId,prompt:e,settings:r,delivery:t})}function zm(e){let t=Y().selection;t!==null&&t.sessionId!==null&&M(t.machine,`sessions.unqueue`,{sessionId:t.sessionId,id:e}).catch($)}function Bm(e){let t=Y().selection;t!==null&&t.sessionId!==null&&M(t.machine,`sessions.steer`,{sessionId:t.sessionId,id:e}).catch($)}function Vm(){let e=Y().selection;e!==null&&e.sessionId!==null&&M(e.machine,`sessions.interrupt`,{sessionId:e.sessionId}).catch($)}function Hm(e,t,n){M(e,`sessions.stopTask`,{sessionId:t,taskId:n}).catch($)}function Um(e,t,n){let r=Y().selection;r!==null&&r.sessionId!==null&&M(r.machine,`sessions.respond`,{sessionId:r.sessionId,requestId:e,decision:t,answers:n}).catch($)}async function Wm(e){let t=Y().selection;if(t!==null&&t.sessionId!==null)try{let n=await M(t.machine,`sessions.fork`,{sessionId:t.sessionId,projectId:t.projectId,messageId:e});jm({...t,sessionId:n.sessionId})}catch(e){$(e)}}async function Gm(){let e=Y().selection,t=Y().before;if(e!==null&&e.sessionId!==null&&t!==null)try{let n=await M(e.machine,`sessions.earlier`,{sessionId:e.sessionId,before:t});if(Y().selection!==e||Y().before!==t)return;X({earlier:[...n.items,...Y().earlier],before:n.before})}catch(e){$(e)}}async function Km(e,t){let n=Y().selection;if(n!==null&&n.sessionId!==null)try{let r=await M(n.machine,`sessions.agent`,{sessionId:n.sessionId,projectId:n.projectId,agentId:t,parent:e});if(Y().selection!==n)return;let i=new Set(r.map(e=>e.id)),a=Y().items;X({items:[...a.filter(t=>t.parent!==e),...r,...a.filter(t=>t.parent===e&&!i.has(t.id))]})}catch(e){$(e)}}async function qm(e,t,n){let r=Y();function i(n){return n.machine===e&&n.id===t}let a=[...r.sessions,...r.inactive].find(i);if(a!==void 0){let e={...a,...n};X({sessions:r.sessions.some(i)?r.sessions.map(t=>i(t)?e:t):e.status===`inactive`?r.sessions:[...r.sessions,e],inactive:e.status===`inactive`?r.inactive.some(i)?r.inactive.map(t=>i(t)?e:t):[e,...r.inactive]:r.inactive.filter(e=>!i(e))})}try{await M(e,`sessions.update`,{id:t,patch:n})}catch(e){$(e)}}async function Jm(e){let t=lh(e.machine,e.id);X({generatingTitles:[...Y().generatingTitles,t]});try{await M(e.machine,`sessions.generateTitle`,{id:e.id,projectId:e.projectId})}catch(e){$(e)}finally{X({generatingTitles:Y().generatingTitles.filter(e=>e!==t)})}}async function Ym(e,t,n){let r=Y().selection;if(r?.machine===e&&r.sessionId===t){let i=Y().sessions.filter(r=>(r.status===`pinned`||r.status===`active`||r.status===`snoozed`)&&(r.machine!==e||r.id!==t)&&(n===null||r.machine===n.machine&&(r.projectId===n.projectId||n.projectId===`no-project`&&Lh(Y(),r.machine,r.projectId)?.scratch===!0))).sort((e,t)=>t.updatedAt-e.updatedAt).at(0);i===void 0?Fm(r.machine,r.projectId,!0):jm({machine:i.machine,projectId:i.projectId,sessionId:i.id},null,!0)}await qm(e,t,{status:`inactive`})}async function Xm(e,t,n){X({sessions:Y().sessions.filter(n=>n.machine!==e||n.id!==t),inactive:Y().inactive.filter(n=>n.machine!==e||n.id!==t)}),Ta(lh(e,t));let r=Y().selection;r?.machine===e&&r.sessionId===t&&Fm(e,r.projectId,!0);try{await M(e,`sessions.remove`,{id:t,projectId:n})}catch(e){$(e)}}var Zm=Tp({machine:Uf().optional().catch(void 0),project:Uf().optional().catch(void 0),session:Uf().optional().catch(void 0),panel:Pp([`diff`,`tasks`,`browser`]).optional().catch(void 0),browse:Uf().optional().catch(void 0),bottom:Ip(`terminal`).optional().catch(void 0),terminal:Uf().optional().catch(void 0)}),Qm=oi({validateSearch:Zm}),$m=ii({getParentRoute:()=>Qm,path:`/`}),eh=ii({getParentRoute:()=>Qm,path:`/terminal`,beforeLoad:()=>{let e=Pm();throw st(e===null?{to:`/`,search:{},replace:!0}:{to:`/terminal/$machine`,params:{machine:e},search:{},replace:!0})}}),th=ii({getParentRoute:()=>Qm,path:`/terminal/$machine`});if(window.history.state?.__TSR_index===void 0&&(location.pathname.startsWith(`/terminal`)||new URLSearchParams(location.search).has(`machine`))){let e=`${location.pathname}${location.search}${location.hash}`,t=Math.random().toString(36).slice(2),n=Math.random().toString(36).slice(2);window.history.replaceState({__TSR_index:0,__TSR_key:t,key:t},``,`/`),window.history.pushState({__TSR_index:1,__TSR_key:n,key:n,layer:`chat`},``,e)}var J=ci({routeTree:Qm.addChildren([$m,eh,th]),disableGlobalCatchBoundary:!0,parseSearch:e=>Zm.parse(Object.fromEntries(new URLSearchParams(e))),stringifySearch:e=>{let t=new URLSearchParams;for(let n of Object.entries(e))n[1]!==void 0&&t.set(n[0],String(n[1]));let n=t.toString();return n===``?``:`?${n}`}}),nh=`machines`,rh=document.querySelector(`meta[name="offsite-connect"]`)?.getAttribute(`content`)?.split(` `)??null;function ih(){let e=localStorage.getItem(nh);return e===null?[]:JSON.parse(e)}function ah(e){localStorage.setItem(nh,JSON.stringify(e))}async function oh(e){if(!(`caches`in window))return;let t=e.map(e=>({id:e.id,addresses:e.addresses}));await(await caches.open(`offsite-worker`)).put(`/machines`,new Response(JSON.stringify(t)))}function sh(){if(location.pathname!==`/pair`)return null;let e=new URLSearchParams(location.hash.slice(1));J.navigate({to:`/`,replace:!0});let t=e.get(`machine`);if(t===null)throw Error(`the pairing link has no machine`);return{address:ch(t).address,code:e.get(`code`)}}function ch(e){let t=e.trim(),n=new URL(/^[a-z]+:\/\//i.test(t)?t:`http://${t}`);if(n.protocol!==`http:`&&n.protocol!==`https:`)throw Error(`Use an http:// or https:// address`);let r=new URLSearchParams(n.hash.slice(1)),i=r.get(`machine`);return{address:i===null?n.origin:ch(i).address,code:r.get(`code`)}}function lh(e,t){return`${e} ${t}`}function uh(e){return{id:e.id,addresses:e.addresses,via:null,status:`connecting`,name:e.label??e.name,hostname:e.name,label:e.label,icon:e.icon,pairedAt:e.pairedAt??null,config:null,composer:null,appIcon:null,configError:null,system:null,claudeAccounts:[],codexAccounts:[],openCode:{available:!1},notifier:!1,activity:{},providers:[],terminals:[]}}function dh(e){return e.projects.map(t=>({...t,machine:e.id}))}function fh(){let e=ih(),t=Y().machines;for(let n of t)e.some(e=>e.id===n.id)||xh(n.id);for(let n of e){let e=t.find(e=>e.id===n.id);if(e===void 0){let e=Y();X({machines:[...e.machines,uh(n)],projects:[...e.projects,...dh(n)]}),Ii(n.id,n.addresses)}else Q(n.id,{label:n.label,icon:n.icon,name:n.label??e.hostname}),(n.addresses.join(` `)!==e.addresses.join(` `)||n.pairedAt!==e.pairedAt)&&(Q(n.id,{addresses:n.addresses,pairedAt:n.pairedAt}),yh(n.id))}let n=e.map(e=>e.id);X({machines:[...Y().machines].sort((e,t)=>n.indexOf(e.id)-n.indexOf(t.id))})}async function ph(e,t){let n=Y().machines.find(t=>t.addresses.some(t=>e.includes(t)));if(n!==void 0)return t!==null&&await mh(n.id,t),n.id;let r=Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,`0`)).join(``);return t!==null&&await Si(r,await hh(e,t)),X({machines:[...Y().machines,uh({id:r,addresses:e,name:new URL(e[0]).hostname,label:null,icon:`computer`,pairedAt:t===null?null:Date.now(),projects:[]})]}),Sh(),Ii(r,e),r}async function mh(e,t){await Si(e,await hh(Z(Y(),e).addresses,t)),Q(e,{pairedAt:Date.now()}),Sh(),yh(e)}async function hh(e,t){let n;for(let r of e){let e=await fetch(`${r}/api/pair`,{method:`POST`,headers:{authorization:`Bearer ${t}`}}).catch(e=>(n??=e,null));if(e!==null){if(!e.ok)throw Error(await e.text());return(await e.json()).token}}throw Error(`Could not reach the machine to pair: ${String(n)}`)}function gh(e,t){let n=Z(Y(),e),r={...n,...t};Q(e,{...t,name:r.label??r.hostname}),Sh(),r.addresses.join(` `)!==n.addresses.join(` `)&&yh(e)}function _h(e){X({machines:[...Y().machines].sort((t,n)=>e.indexOf(t.id)-e.indexOf(n.id))}),Sh()}function vh(e){oh(e).catch(e=>console.error(`could not share the machines with the service worker`,e))}function yh(e){Li(e),Q(e,{status:`connecting`,via:null}),Ii(e,Z(Y(),e).addresses)}function bh(e){xh(e),Sh(),Ci(e).catch(e=>console.error(`could not remove the device token`,e))}function xh(e){Li(e);let t=Y(),n=t.machines.filter(t=>t.id!==e);X({machines:n,projects:t.projects.filter(t=>t.machine!==e),sessions:t.sessions.filter(t=>t.machine!==e),inactive:t.inactive.filter(t=>t.machine!==e),unseen:t.unseen.filter(t=>!t.startsWith(`${e} `)),...t.settingsMachine===e&&{settingsMachine:n.at(0)?.id??null},...t.selection?.machine===e&&{selection:null}}),km()}function Sh(){let e=Y(),t=e.machines.map(t=>({id:t.id,addresses:t.addresses,name:t.hostname,label:t.label,icon:t.icon,pairedAt:t.pairedAt,projects:e.projects.filter(e=>e.machine===t.id).map(e=>({id:e.id,path:e.path,name:e.name,logo:e.logo,hidden:e.hidden,scratch:e.scratch}))}));ah(t),vh(t)}var Ch=[{id:`one-dark-darker`,name:`One Dark Darker`,codeTheme:`one-dark-pro`,background:`#15181C`,foreground:`#ABB2BF`,cursor:`#B3BAC5`,selectionBackground:`#3B414D`,palette:[`#4A4F5A`,`#EE5D69`,`#97C775`,`#B68353`,`#61AFEF`,`#C678DD`,`#56B6C2`,`#CCCCCC`,`#616A7B`,`#FE808A`,`#C2DEAD`,`#D1A47A`,`#93CFFF`,`#E0A8F1`,`#82D2DC`,`#FFFFFF`]},{id:`one-dark-pro`,name:`One Dark Pro`,codeTheme:`one-dark-pro`,background:`#282C34`,foreground:`#ABB2BF`,cursor:`#528BFF`,selectionBackground:`#41454E`,palette:[`#3F4451`,`#E05561`,`#8CC265`,`#D18F52`,`#4AA5F0`,`#C162DE`,`#42B3C2`,`#D7DAE0`,`#4F5666`,`#FF616E`,`#A5E075`,`#F0A45D`,`#4DC4FF`,`#DE73FF`,`#4CD1E0`,`#E6E6E6`]},{id:`dracula`,name:`Dracula`,codeTheme:`dracula`,background:`#282A36`,foreground:`#F8F8F2`,cursor:`#F8F8F2`,selectionBackground:`#44475A`,palette:[`#21222C`,`#FF5555`,`#50FA7B`,`#F1FA8C`,`#BD93F9`,`#FF79C6`,`#8BE9FD`,`#F8F8F2`,`#6272A4`,`#FF6E6E`,`#69FF94`,`#FFFFA5`,`#D6ACFF`,`#FF92DF`,`#A4FFFF`,`#FFFFFF`]},{id:`tokyo-night`,name:`Tokyo Night`,codeTheme:`tokyo-night`,background:`#1A1B26`,foreground:`#C0CAF5`,cursor:`#C0CAF5`,selectionBackground:`#33467C`,palette:[`#15161E`,`#F7768E`,`#9ECE6A`,`#E0AF68`,`#7AA2F7`,`#BB9AF7`,`#7DCFFF`,`#A9B1D6`,`#414868`,`#F7768E`,`#9ECE6A`,`#E0AF68`,`#7AA2F7`,`#BB9AF7`,`#7DCFFF`,`#C0CAF5`]},{id:`catppuccin-mocha`,name:`Catppuccin Mocha`,codeTheme:`catppuccin-mocha`,background:`#1E1E2E`,foreground:`#CDD6F4`,cursor:`#F5E0DC`,selectionBackground:`#585B70`,palette:[`#45475A`,`#F38BA8`,`#A6E3A1`,`#F9E2AF`,`#89B4FA`,`#F5C2E7`,`#94E2D5`,`#BAC2DE`,`#585B70`,`#F38BA8`,`#A6E3A1`,`#F9E2AF`,`#89B4FA`,`#F5C2E7`,`#94E2D5`,`#A6ADC8`]},{id:`nord`,name:`Nord`,codeTheme:`nord`,background:`#2E3440`,foreground:`#D8DEE9`,cursor:`#D8DEE9`,selectionBackground:`#434C5E`,palette:[`#3B4252`,`#BF616A`,`#A3BE8C`,`#EBCB8B`,`#81A1C1`,`#B48EAD`,`#88C0D0`,`#E5E9F0`,`#4C566A`,`#BF616A`,`#A3BE8C`,`#EBCB8B`,`#81A1C1`,`#B48EAD`,`#8FBCBB`,`#ECEFF4`]},{id:`gruvbox-dark`,name:`Gruvbox Dark`,codeTheme:`gruvbox-dark-medium`,background:`#282828`,foreground:`#EBDBB2`,cursor:`#EBDBB2`,selectionBackground:`#504945`,palette:[`#282828`,`#CC241D`,`#98971A`,`#D79921`,`#458588`,`#B16286`,`#689D6A`,`#A89984`,`#928374`,`#FB4934`,`#B8BB26`,`#FABD2F`,`#83A598`,`#D3869B`,`#8EC07C`,`#EBDBB2`]},{id:`solarized-dark`,name:`Solarized Dark`,codeTheme:`solarized-dark`,background:`#002B36`,foreground:`#839496`,cursor:`#839496`,selectionBackground:`#073642`,palette:[`#073642`,`#DC322F`,`#859900`,`#B58900`,`#268BD2`,`#D33682`,`#2AA198`,`#EEE8D5`,`#002B36`,`#CB4B16`,`#586E75`,`#657B83`,`#839496`,`#6C71C4`,`#93A1A1`,`#FDF6E3`]},{id:`github-dark`,name:`GitHub Dark`,codeTheme:`github-dark`,background:`#0D1117`,foreground:`#E6EDF3`,cursor:`#E6EDF3`,selectionBackground:`#264F78`,palette:[`#484F58`,`#FF7B72`,`#3FB950`,`#D29922`,`#58A6FF`,`#BC8CFF`,`#39C5CF`,`#B1BAC4`,`#6E7681`,`#FFA198`,`#56D364`,`#E3B341`,`#79C0FF`,`#D2A8FF`,`#56D4DD`,`#FFFFFF`]},{id:`rose-pine`,name:`Rosé Pine`,codeTheme:`rose-pine`,background:`#191724`,foreground:`#E0DEF4`,cursor:`#E0DEF4`,selectionBackground:`#403D52`,palette:[`#26233A`,`#EB6F92`,`#31748F`,`#F6C177`,`#9CCFD8`,`#C4A7E7`,`#EBBCBA`,`#E0DEF4`,`#6E6A86`,`#EB6F92`,`#31748F`,`#F6C177`,`#9CCFD8`,`#C4A7E7`,`#EBBCBA`,`#E0DEF4`]}],wh=Ep({theme:Uf().refine(e=>Ch.some(t=>t.id===e)).default(Ch[0].id),terminal:Ep({font:Ep({family:Uf().default(`FiraCode Nerd Font`),size:mp().default(14),lineHeight:mp().default(1.35),ligatures:q().default(!0)}).prefault({}),cursor:Ep({style:Pp([`block`,`bar`,`underline`]).default(`bar`),blink:q().default(!0)}).prefault({}),padding:Ep({top:mp().default(4),right:mp().default(4),bottom:mp().default(0),left:mp().default(4)}).prefault({}),scrollback:mp().default(1e3),boldIsBright:q().default(!0),behavior:Ep({modernizeShiftEnter:q().default(!0),pasteBrowserImages:q().default(!0),captureShortcuts:q().default(!0),bellFlash:q().default(!0),bellSound:q().default(!0),clickToMoveCursor:q().default(!0),optionAsMeta:Pp([`off`,`left`,`right`,`both`]).default(`off`),windowsCopyPaste:q().default(!0),confirmCloseBusyTab:q().default(!0)}).prefault({})}).prefault({}),editor:Ep({font:Ep({family:Uf().default(`FiraCode Nerd Font`),size:mp().default(15.3),lineHeight:mp().default(1.8),ligatures:q().default(!0),features:Uf().default(`'zero', 'ss02', 'ss06', 'cv02', 'cv14', 'cv26'`)}).prefault({}),cursor:Ep({style:Pp([`block`,`bar`,`underline`]).default(`bar`),blink:q().default(!0)}).prefault({}),tabSize:mp().default(2),wordWrap:q().default(!0),graph:q().default(!0)}).prefault({}),diff:Ep({split:q().default(!1),wrap:q().default(!0),collapsed:q().default(!1)}).prefault({}),rewind:Pp([`all`,`chat`,`code`]).default(`chat`),groupActiveByProject:q().default(!1),toolbar:Cp(Pp([`diff`,`terminal`,`tasks`,`browser`,`editor`])).default([`diff`,`terminal`,`editor`])}),Th=`prefs`,Eh=wh.parse({});function Dh(){let e=localStorage.getItem(Th);if(e===null)return structuredClone(Eh);let t=wh.safeParse(JSON.parse(e));return t.success?t.data:(console.warn(`invalid stored prefs, using the defaults:\n${ss(t.error)}`),structuredClone(Eh))}function Oh(e){localStorage.setItem(Th,JSON.stringify(e))}function kh(){let e=Y().prefs.theme,t=Ch.find(t=>t.id===e);if(t===void 0)throw Error(`unknown theme ${e}`);return t}function Ah(){let e=Ih(e=>e.prefs.theme),t=Ch.find(t=>t.id===e);if(t===void 0)throw Error(`unknown theme ${e}`);return t.codeTheme}function jh(){let e=kh(),t=document.documentElement.style;t.setProperty(`--bg`,e.background),t.setProperty(`--text`,e.foreground),t.setProperty(`--blue`,e.palette[4]),t.setProperty(`--danger`,e.palette[1]),t.setProperty(`--green`,e.palette[2]),t.setProperty(`--yellow`,e.palette[3]),document.querySelector(`meta[name="theme-color"]`)?.setAttribute(`content`,e.background)}var Mh={claude:`Claude`,codex:`Codex`,opencode:`OpenCode`},Nh;function Ph(e){Nh=aa()(()=>e)}function Fh(e){return Nh.subscribe(e)}function Y(){return Nh.getState()}function Ih(e){return sa(Nh,e)}function X(e){Nh.setState(e)}function Z(e,t){let n=e.machines.find(e=>e.id===t);if(n===void 0)throw Error(`unknown machine ${t}`);return n}function Lh(e,t,n){return e.projects.find(e=>e.machine===t&&e.id===n)}function Rh(e){return e.selection?.machine??e.machines.at(0)?.id??null}function Q(e,t){X({machines:Y().machines.map(n=>n.id===e?{...n,...t}:n)})}function zh(e,t,n){if(n!==null)return e.find(e=>e.id===t)?.activity[n]}function Bh(e){let t=e.selection;if(t!==null)return zh(e.machines,t.machine,t.sessionId)}function Vh(e){return Bh(e)?.running===!0}function Hh(e){return e.sessionId===null?`new`:lh(e.machine,e.sessionId)}function Uh(e){X({draft:e})}function Wh(e){X({paletteOpen:e})}function Gh(e){X({editor:e})}function Kh(e){X({exporting:e})}function qh(e){X({settingsOpen:e,paletteOpen:!1,...e&&{settingsMachine:Rh(Y()),settingsAccount:null,settingsEditedMachine:null,settingsListing:!0}})}function Jh(e){X({settingsOpen:!0,settingsPage:e,settingsAccount:null,settingsEditedMachine:null,settingsListing:!1,paletteOpen:!1,...!Y().settingsOpen&&{settingsMachine:Rh(Y())}})}function Yh(e){X({prefs:e}),Oh(e),jh()}function $(e){X({errors:[...Y().errors,i(e)]})}function Xh(){X({errors:[]})}function Zh(e){let t=new Map;function n(t,n){Y().machines.some(e=>e.id===t)&&e.apply(t,n)}async function r(r,a){let o=await e.save(r,a),s=t.get(r);s!==void 0&&(--s.writes,s.writes>0||(o===null?await i(r):n(r,o)))}async function i(r){let i=t.get(r)?.version;try{let a=await e.load(r),o=t.get(r);o!==void 0&&o.writes===0&&o.version===i&&n(r,a)}catch(e){$(e)}}return{update(n,i){e.set(n,i);let a=t.get(n)??{writes:0,version:0,timer:void 0};t.set(n,a),a.timer===void 0&&(a.writes+=1),a.version+=1,window.clearTimeout(a.timer),a.timer=window.setTimeout(()=>{a.timer=void 0,r(n,i)},300)},receive(e,r){(t.get(e)?.writes??0)===0&&n(e,r)}}}var Qh=Zh({set:ig,save:async(e,t)=>{try{let n=await M(e,`config.save`,t);return Q(e,{configError:null}),n}catch(t){return Q(e,{configError:i(t)}),null}},load:async e=>(await M(e,`config.get`,void 0)).config,apply:ig}),$h=Zh({set:(e,t)=>Q(e,{composer:t}),save:async(e,t)=>{try{return await M(e,`composer.save`,t)}catch(e){return $(e),null}},load:e=>M(e,`composer.get`,void 0),apply:ag}),eg=Qh.update,tg=Qh.receive,ng=$h.update,rg=$h.receive;function ig(e,t){let n=Z(Y(),e).config;Q(e,{config:t}),n!==null&&ra(n.newThreads,t.newThreads)||fg(e)}function ag(e,t){let n=Z(Y(),e).composer;Q(e,{composer:t});let r=Y().selection;if(r===null||r.machine!==e)return;if(r.sessionId===null){n===null&&fg(e);return}if(zh(Y().machines,e,r.sessionId)!==void 0)return;let i=Da(Hh(r))??cg(t,Y().settings.provider),a=i.provider!==Y().settings.provider||i.accountId!==Y().settings.accountId;X({settings:i}),a&&hg()}var og=null,sg={provider:`claude`,accountId:null,model:null,effort:null,mode:null,plan:!1};function cg(e,t){return e===null?{...sg,provider:t}:{provider:t,...e[t]}}function lg(e){if(e.config===null)return sg;let t=e.config.newThreads;return{...cg(e.composer,t.provider),accountId:t.accountId,model:t.models[t.provider],effort:null}}function ug(e){let t={...Y().settings,...e};X({settings:t});let n=Y().selection;if(n===null)return;n.sessionId!==null&&Oa(Hh(n),t);let r=Z(Y(),n.machine).composer;r!==null&&ng(n.machine,{...r,provider:t.provider,[t.provider]:{accountId:t.accountId,model:t.model,effort:t.effort,mode:t.mode,plan:t.plan}}),e.accountId!==void 0&&hg(),n.sessionId!==null&&zh(Y().machines,n.machine,n.sessionId)!==void 0&&e.accountId===void 0&&M(n.machine,`sessions.configure`,{sessionId:n.sessionId,settings:t}).catch($)}function dg(e,t){if(Q(e,{claudeAccounts:t.claudeAccounts,codexAccounts:t.codexAccounts,openCode:t.openCode}),Y().selection?.machine!==e)return;let n=Y().settings,r=[...[...t.claudeAccounts,...t.codexAccounts].filter(e=>e.valid).map(e=>({provider:e.provider,accountId:e.id})),...t.openCode.available?[{provider:`opencode`,accountId:null}]:[]];if(r.some(e=>e.provider===n.provider&&e.accountId===n.accountId))return;let i=r.find(e=>e.provider===n.provider),a=Y().selection?.sessionId===null?r.at(0):void 0;if(i!==void 0)ug({accountId:i.accountId});else if(a!==void 0){let t=Z(Y(),e);ug({...cg(t.composer,a.provider),accountId:a.accountId,model:t.config===null?null:t.config.newThreads.models[a.provider],effort:null})}else n.accountId!==null&&ug({accountId:null})}function fg(e){let t=Y().selection;t?.machine===e&&t.sessionId===null&&(X({settings:lg(Z(Y(),e))}),pg(e))}function pg(e){let t=Z(Y(),e);(t.claudeAccounts.length>0||t.codexAccounts.length>0||t.openCode.available)&&dg(e,{claudeAccounts:t.claudeAccounts,codexAccounts:t.codexAccounts,openCode:t.openCode}),hg()}async function mg(e){try{dg(e,await M(e,`accounts.list`,void 0))}catch(e){$(e)}}async function hg(){let e=Y().selection;if(e===null)return;let{provider:t,accountId:n}=Y().settings;if(t!==`opencode`&&n===null)X({capabilities:null});else try{let r=JSON.stringify([e.machine,t,n,e.projectId]);if(og?.key!==r){let i=M(e.machine,`capabilities`,{provider:t,accountId:n,projectId:e.projectId});function a(){og?.result===i&&(og=null)}i.then(a,a),og={key:r,result:i}}let i=await og.result;if(Y().selection?.machine!==e.machine||Y().selection?.projectId!==e.projectId||Y().settings.provider!==t||Y().settings.accountId!==n)return;X({capabilities:i});let a=Y().settings;if(a.model!==null){let e=i.models.find(e=>e.value===a.model)?.effort;a.provider!==`opencode`&&a.effort===null&&e!=null&&ug({effort:e});return}let o=i.models.find(e=>!e.hidden&&e.value===i.defaultModel)??i.models.find(e=>!e.hidden);if(o===void 0)return;ug({model:o.value,...o.effort===null?{}:{effort:o.effort}})}catch(e){$(e)}}var gg=[[`path`,{d:`M18 6L12 12M12 12L6 18M12 12L18 18M12 12L6 6`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}]];export{uh as $,Oa as $t,Fh as A,wm as At,ph as B,Ip as Bt,Q as C,gm as Ct,Wh as D,Om as Dt,Kh as E,mm as Et,kh as F,lm as Ft,mh as G,Ea as Gt,gh as H,Uf as Ht,Ah as I,dm as It,ch as J,ja as Jt,sh as K,Da as Kt,Eh as L,om as Lt,Yh as M,cm as Mt,Ih as N,um as Nt,qh as O,pm as Ot,jh as P,Tm as Pt,_h as Q,Ca as Qt,Dh as R,q as Rt,Uh as S,sm as St,$ as T,hm as Tt,ih as U,Pa as Ut,rh as V,Tp as Vt,lh as W,Sa as Wt,yh as X,ba as Xt,fh as Y,wa as Yt,bh as Z,Na as Zt,Z as _,Yt as _n,Rm as _t,mg as a,Ii as an,qm as at,Bh as b,Ae as bn,Hm as bt,rg as c,Bi as cn,Im as ct,zh as d,ui as dn,Mm as dt,Ma as en,dh as et,Ph as f,Rr as fn,jm as ft,Y as g,ir as gn,Um as gt,Hh as h,ar as hn,Xm as ht,cg as i,M as in,Ym as it,X as j,km as jt,Jh as k,fm as kt,tg as l,Vi as ln,Km as lt,Xh as m,sr as mn,Jm as mt,ug as n,ka as nn,J as nt,hg as o,zi as on,Wm as ot,Rh as p,jr as pn,Lm as pt,Sh as q,Aa as qt,sg as r,ra as rn,Nm as rt,dg as s,Ri as sn,Vm as st,gg as t,xa as tn,vh as tt,eg as u,Pi as un,Gm as ut,Lh as v,ot as vn,Fm as vt,Gh as w,Sm as wt,Vh as x,de as xn,zm as xt,Mh as y,Re as yn,Bm as yt,Ch as z,Ap as zt};
57
+ 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);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function jd(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;jd(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var Md=new Set([`type`,`properties`,`required`,`additionalProperties`]),Nd=[`oneOf`,`anyOf`];function Pd(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Fd(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Md.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Pd(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Ua(n,r,e.length===1?e[0]:Fd(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Pd(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Id(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Md)if(t in e)return;let n=t.filter(e=>Nd.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Fd(t);else{let e=n[0],i=Nd.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Fd([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,Ed(e,r))}function Ld(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)):Ed(i,s),Ed(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??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())jd(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Id(e)}}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)}Ed(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Ua(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:zd(t,`input`,e.processors),output:zd(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function U(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 U(r.element,n);if(r.type===`set`)return U(r.valueType,n);if(r.type===`lazy`)return U(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`||r.type===`catch`)return U(r.innerType,n);if(r.type===`intersection`)return U(r.left,n)||U(r.right,n);if(r.type===`record`||r.type===`map`)return U(r.keyType,n)||U(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:U(r.in,n)||U(r.out,n);if(r.type===`object`){for(let e in r.shape)if(U(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(U(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(U(e,n))return!0;return!!(r.rest&&U(r.rest,n))}return!1}var Rd=(e,t={})=>n=>{let r=Dd({...n,processors:t});return H(e,r),Ad(r,e),Ld(r,e)},zd=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Dd({...i??{},target:a,io:t,processors:n});return H(e,o),Ad(o,e),Ld(o,e)},Bd=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Vd=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Hd=(e,t)=>{Bd(e,`minimum`,t),Vd(e,`maximum`,t)},Ud=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Wd=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Gd=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Kd=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},qd=(e,t)=>Bd(e,`minimum`,t.minimum),Jd=(e,t)=>Vd(e,`maximum`,t.maximum),Yd=e=>(t,n)=>{Kd(t,n.format);let[r,i]=e[n.format];Bd(t,`minimum`,r),Vd(t,`maximum`,i)},Xd={greater_than:(e,t)=>Bd(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Vd(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Ud(e,t.value),number_format:Yd(co),bigint_format:Yd(lo),min_length:qd,max_length:Jd,length_equals:(e,t)=>Hd(e,t.length),min_size:qd,max_size:Jd,size_equals:(e,t)=>Hd(e,t.size),string_format:(e,t)=>{Kd(e,t.format),t.pattern&&Wd(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Gd(e,t.mime)};function Zd(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Xd[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Bd(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Bd(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Vd(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Vd(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Ud(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Gd(t,i.mime);for(let e of i.patterns??[])Wd(t,e);return t}var Qd={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},$d=new Map([[il,Ws],[ol,Gs]]),ef=e=>$d.get(e)??e,tf=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Zd(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Qd[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(ef);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}))])}},nf=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Zd(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Od(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},rf=(e,t,n,r)=>{n.type=`boolean`},af=(e,t,n,r)=>{n.not={}},of=(e,t,n,r)=>{let i=e._zod.def,a=Fa(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},sf=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(Od(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Od(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);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}},cf=(e,t,n,r)=>{Od(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},lf=(e,t,n,r)=>{Od(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},uf=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Zd(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=H(a.element,t,{...r,path:[...r.path,`items`]})};function df(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?df(t.out):t.type===`catch`?df(t.innerType):e._zod.optin}var ff=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Od(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Ua(i.properties,e,H(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?df(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=H(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},pf=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>H(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},mf=(e,t,n,r)=>{let i=e._zod.def,a=H(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=H(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},hf=(e,t,n,r)=>{let i=e._zod.def,a=H(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`}]},gf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},_f=Symbol();function vf(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Od(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),_f):JSON.parse(o)}var yf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=vf(i.defaultValue,e,t,n,r);o!==_f&&(n.default=o)},bf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=vf(i.defaultValue,e,t,n,r);o!==_f&&(n._prefault=o)},xf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Od(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Sf=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;H(o,t,r);let s=t.seen.get(e);s.ref=o},Cf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},wf=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Tf=new WeakSet([Object.prototype,Error.prototype]);function Ef(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var W=L(`ZodError`,(e,t)=>{ns.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);Tf.has(n)||(Tf.add(n),Ef(n,`format`,e=>t=>as(e,t)),Ef(n,`flatten`,e=>t=>is(e,t)),Ef(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,La,2)}),Ef(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,La,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),Df=ls(W),Of=us(W),kf=ds(W),Af=ps(W),jf=ys(W),Mf=bs(W),Nf=xs(W),Pf=Ss(W),Ff=Cs(W),If=ws(W),Lf=Ts(W),Rf=Es(W);function zf(){R.localeError||Xo(vu())}function Bf(){R.memoizer||Xo({memoizer:hu()})}var G=L(`ZodType`,(e,t)=>(zf(),B.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(P(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ao(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(im(e,t))},superRefine(e,t){return this.check(am(e,t))},overwrite(e){return this.check(gd(e))},optional(){return Bp(this)},exactOptional(){return Hp(this)},nullable(){return Wp(this)},nullish(){return Bp(Wp(this))},nonoptional(e){return Xp(this,e)},array(){return Cp(this)},or(e){return Op([this,e])},and(e){return Mp(this,e)},transform(e){return em(this,Rp(e))},default(e){return Kp(this,e)},prefault(e){return Jp(this,e)},catch(e){return Qp(this,e)},pipe(e){return em(this,e)},readonly(){return nm(this)},describe(e){let t=this.clone();return Su.add(t,{description:e}),t},meta(...e){if(e.length===0)return Su.get(this);let t=this.clone();return Su.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Po(this,`~standard`,{...Ec(this),jsonSchema:{input:zd(this,`input`),output:zd(this,`output`)}})},set"~standard"(e){No(this,`~standard`,e)},parse:function e(t,n){return Df(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await Of(this,t,n,{callee:e})},safeParse(e,t){return kf(this,e,t)},async safeParseAsync(e,t){return Af(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){No(this,`spa`,e)},validate(e,t){return gs(this,e,t)},validateAsync(e,t){return vs(this,e,t)},encode:function e(t,n){return jf(this,t,n,{callee:e})},decode:function e(t,n){return Mf(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await Nf(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await Pf(this,t,n,{callee:e})},safeEncode(e,t){return Ff(this,e,t)},safeDecode(e,t){return If(this,e,t)},async safeEncodeAsync(e,t){return Lf(this,e,t)},async safeDecodeAsync(e,t){return Rf(this,e,t)},toJSONSchema(e){return Rd(this,{})(e)},get description(){return Su.get(this)?.description},get _def(){return this._zod.def}}),Vf=L(`_ZodString`,(e,t)=>{Dc.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>tf(e,t,n,r)},Fo({format:e=>Zd(e).format??null,minLength:e=>Zd(e).minimum??null,maxLength:e=>Zd(e).maximum??null},{regex(...e){return this.check(ud(...e))},includes(...e){return this.check(pd(...e))},startsWith(...e){return this.check(md(...e))},endsWith(...e){return this.check(hd(...e))},min(...e){return this.check(cd(...e))},max(...e){return this.check(sd(...e))},length(...e){return this.check(ld(...e))},nonempty(...e){return this.check(cd(1,...e))},lowercase(e){return this.check(dd(e))},uppercase(e){return this.check(fd(e))},trim(){return this.check(vd())},normalize(...e){return this.check(_d(...e))},toLowerCase(){return this.check(yd())},toUpperCase(){return this.check(bd())},slugify(){return this.check(xd())}})),Hf=L(`ZodString`,(e,t)=>{Dc.init(e,t),Vf.init(e,t)},{email(e){return this.check(Tu(Jf,e))},url(e){return this.check(ju(Zf,e))},jwt(e){return this.check(Ku(fp,e))},emoji(e){return this.check(Mu(Qf,e))},guid(e){return this.check(Eu(Yf,e))},uuid(e){return this.check(Du(Xf,e))},uuidv4(e){return this.check(Ou(Xf,e))},uuidv6(e){return this.check(ku(Xf,e))},uuidv7(e){return this.check(Au(Xf,e))},nanoid(e){return this.check(Nu($f,e))},cuid(e){return this.check(Pu(ep,e))},cuid2(e){return this.check(Fu(tp,e))},ulid(e){return this.check(Iu(np,e))},base64(e){return this.check(Uu(lp,e))},base64url(e){return this.check(Wu(up,e))},xid(e){return this.check(Lu(rp,e))},ksuid(e){return this.check(Ru(ip,e))},ipv4(e){return this.check(zu(ap,e))},ipv6(e){return this.check(Bu(op,e))},cidrv4(e){return this.check(Vu(sp,e))},cidrv6(e){return this.check(Hu(cp,e))},e164(e){return this.check(Gu(dp,e))},datetime(e){return this.check(qu(Wf,e))},date(e){return this.check(Ju(Gf,e))},time(e){return this.check(Yu(Kf,e))},duration(e){return this.check(Xu(qf,e))}});function Uf(e){return wu(Hf,e)}var K=L(`ZodStringFormat`,(e,t)=>{V.init(e,t),Vf.init(e,t)}),Wf=L(`ZodISODateTime`,(e,t)=>{Kc.init(e,t),K.init(e,t)}),Gf=L(`ZodISODate`,(e,t)=>{qc.init(e,t),K.init(e,t)}),Kf=L(`ZodISOTime`,(e,t)=>{Jc.init(e,t),K.init(e,t)}),qf=L(`ZodISODuration`,(e,t)=>{Yc.init(e,t),K.init(e,t)}),Jf=L(`ZodEmail`,(e,t)=>{Ac.init(e,t),K.init(e,t)}),Yf=L(`ZodGUID`,(e,t)=>{Oc.init(e,t),K.init(e,t)}),Xf=L(`ZodUUID`,(e,t)=>{kc.init(e,t),K.init(e,t)}),Zf=L(`ZodURL`,(e,t)=>{Rc.init(e,t),K.init(e,t)}),Qf=L(`ZodEmoji`,(e,t)=>{zc.init(e,t),K.init(e,t)}),$f=L(`ZodNanoID`,(e,t)=>{Bc.init(e,t),K.init(e,t)}),ep=L(`ZodCUID`,(e,t)=>{Vc.init(e,t),K.init(e,t)}),tp=L(`ZodCUID2`,(e,t)=>{Hc.init(e,t),K.init(e,t)}),np=L(`ZodULID`,(e,t)=>{Uc.init(e,t),K.init(e,t)}),rp=L(`ZodXID`,(e,t)=>{Wc.init(e,t),K.init(e,t)}),ip=L(`ZodKSUID`,(e,t)=>{Gc.init(e,t),K.init(e,t)}),ap=L(`ZodIPv4`,(e,t)=>{Xc.init(e,t),K.init(e,t)}),op=L(`ZodIPv6`,(e,t)=>{$c.init(e,t),K.init(e,t)}),sp=L(`ZodCIDRv4`,(e,t)=>{el.init(e,t),K.init(e,t)}),cp=L(`ZodCIDRv6`,(e,t)=>{nl.init(e,t),K.init(e,t)}),lp=L(`ZodBase64`,(e,t)=>{al.init(e,t),K.init(e,t)}),up=L(`ZodBase64URL`,(e,t)=>{cl.init(e,t),K.init(e,t)}),dp=L(`ZodE164`,(e,t)=>{ll.init(e,t),K.init(e,t)}),fp=L(`ZodJWT`,(e,t)=>{dl.init(e,t),K.init(e,t)}),pp=L(`ZodNumber`,(e,t)=>{fl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>nf(e,t,n,r),e.isFinite=!0},Fo({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Zd(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Zd(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Zd(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Zd(e).format??null},{gt(e,t){return this.check(id(e,t))},gte(e,t){return this.check(ad(e,t))},min(e,t){return this.check(ad(e,t))},lt(e,t){return this.check(nd(e,t))},lte(e,t){return this.check(rd(e,t))},max(e,t){return this.check(rd(e,t))},int(e){return this.check(gp(e))},safe(e){return this.check(gp(e))},positive(e){return this.check(id(0,e))},nonnegative(e){return this.check(ad(0,e))},negative(e){return this.check(nd(0,e))},nonpositive(e){return this.check(rd(0,e))},multipleOf(e,t){return this.check(od(e,t))},step(e,t){return this.check(od(e,t))},finite(){return this}}));function mp(e){return Zu(pp,e)}var hp=L(`ZodNumberFormat`,(e,t)=>{pl.init(e,t),pp.init(e,t)});function gp(e){return Qu(hp,e)}var _p=L(`ZodBoolean`,(e,t)=>{ml.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rf(e,t,n,r)});function q(e){return $u(_p,e)}var vp=L(`ZodUnknown`,(e,t)=>{hl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function yp(){return ed(vp)}var bp=L(`ZodNever`,(e,t)=>{gl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>af(e,t,n,r)});function xp(e){return td(bp,e)}var Sp=L(`ZodArray`,(e,t)=>{Bf(),bl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>uf(e,t,n,r),e.element=t.element},{min(e,t){return this.check(cd(e,t))},nonempty(e){return this.check(cd(1,e))},max(e,t){return this.check(sd(e,t))},length(e,t){return this.check(ld(e,t))},unwrap(){return this.element}});function Cp(e,t){return Sd(Sp,e,t)}var wp=L(`ZodObject`,(e,t)=>{Bf(),El.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ff(e,t,n,r),Vo(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Pp(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(P(this._zod.def,{catchall:e}))},passthrough(){return this.clone(P(this._zod.def,{catchall:yp()}))},loose(){return this.clone(P(this._zod.def,{catchall:yp()}))},strict(){return this.clone(P(this._zod.def,{catchall:xp()}))},strip(){return this.clone(P(this._zod.def,{catchall:void 0}))},extend(e){return mo(this,e)},safeExtend(e){return go(this,e)},merge(e){return _o(this,e)},pick(e){return uo(this,e)},omit(e){return po(this,e)},partial(...e){return vo(zp,this,e[0])},exactPartial(...e){return vo(Vp,this,e[0],`exactPartial`)},required(...e){return yo(Yp,this,e[0])}});function Tp(e,t){return new wp({type:`object`,shape:e??{},...F(t)})}function Ep(e,t){return new wp({type:`object`,shape:e,catchall:xp(),...F(t)})}var Dp=L(`ZodUnion`,(e,t)=>{Ol.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pf(e,t,n,r),e.options=t.options});function Op(e,t){return new Dp({type:`union`,options:e,...F(t)})}var kp=L(`ZodDiscriminatedUnion`,(e,t)=>{Dp.init(e,t),Al.init(e,t)});function Ap(e,t,n){return new kp({type:`union`,options:t,discriminator:e,...F(n)})}var jp=L(`ZodIntersection`,(e,t)=>{jl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mf(e,t,n,r)});function Mp(e,t){return new jp({type:`intersection`,left:e,right:t})}var Np=L(`ZodEnum`,(e,t)=>{Pl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>of(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];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 Np({...t,checks:[],...F(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 Np({...t,checks:[],...F(r),entries:i})}});function Pp(e,t){return new Np({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...F(t)})}var Fp=L(`ZodLiteral`,(e,t)=>{Fl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>sf(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 Ip(e,t){return new Fp({type:`literal`,values:Array.isArray(e)?e:[e],...F(t)})}var Lp=L(`ZodTransform`,(e,t)=>{Bf(),Il.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>lf(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yo(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jo(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(jo(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Rp(e){return new Lp({type:`transform`,transform:e})}var zp=L(`ZodOptional`,(e,t)=>{Rl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bp(e){return new zp({type:`optional`,innerType:e})}var Vp=L(`ZodExactOptional`,(e,t)=>{zl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hp(e){return new Vp({type:`optional`,innerType:e})}var Up=L(`ZodNullable`,(e,t)=>{Bl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Wp(e){return new Up({type:`nullable`,innerType:e})}var Gp=L(`ZodDefault`,(e,t)=>{Vl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Kp(e,t){return new Gp({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():no(t)}})}var qp=L(`ZodPrefault`,(e,t)=>{Ul.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Jp(e,t){return new qp({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():no(t)}})}var Yp=L(`ZodNonOptional`,(e,t)=>{Wl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Xp(e,t){return new Yp({type:`nonoptional`,innerType:e,...F(t)})}var Zp=L(`ZodCatch`,(e,t)=>{ql.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Qp(e,t){return new Zp({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Uo(t)})}var $p=L(`ZodPipe`,(e,t)=>{Jl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Sf(e,t,n,r),e.in=t.in,e.out=t.out});function em(e,t){return new $p({type:`pipe`,in:e,out:t})}var tm=L(`ZodReadonly`,(e,t)=>{Xl.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cf(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function nm(e){return new tm({type:`readonly`,innerType:e})}var rm=L(`ZodCustom`,(e,t)=>{Ql.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cf(e,t,n,r)});function im(e,t={}){return Cd(rm,e,t)}function am(e,t){return wd(e,t)}var om=`no-project`;function sm(){return J.parseLocation(J.history.location).search}function cm(){let e=/^\/terminal\/([^/]+)$/.exec(J.history.location.pathname);if(e===null)return null;let t=decodeURIComponent(e[1]);return Y().machines.some(e=>e.id===t)?t:null}function lm(){let e=Lr({strict:!1,select:e=>e.machine??null});return Ih(t=>t.machines.some(t=>t.id===e)?e:null)}function um(){return sm().project??`global`}function dm(){return Rr({strict:!1,select:e=>e.project??`global`})}function fm(e){let t=sm();return t.machine===void 0||t.project===void 0||!e.includes(t.machine)?null:{machine:t.machine,projectId:t.project,sessionId:t.session??null}}function pm(e){Am({...sm(),...e},!0,J.history.location.state.layer)}function mm(e,t){Am({...sm(),...e},!1,t)}function hm(e){let t=Y();if(t.selection===null)throw Error(`no project is open to show the browser in`);if(e.startsWith(`file:`)){pm({panel:`browser`,browse:decodeURIComponent(new URL(e).pathname)});return}if(/^https?:\/\//i.test(e)||e.startsWith(`/`)||/^[a-z]:[\\/]/i.test(e)){pm({panel:`browser`,browse:e});return}let n=Lh(t,t.selection.machine,t.selection.projectId);if(n===void 0)throw Error(`project ${t.selection.projectId} is not listed`);pm({panel:`browser`,browse:`${n.path}/${e}`})}function gm(e,t){J.history.location.state.layer===e?J.history.back():t()}var _m=[],vm=!1,ym=!1,bm=!1;function xm(){return J.history.location.state.guard===!0}function Sm(){return bm}function Cm(){vm||(_m.length>0&&!xm()?J.history.push(J.history.location.href,{guard:!0}):_m.length===0&&xm()&&(vm=!0,J.history.back()))}function wm(){ym=xm(),J.history.subscribe(({action:e})=>{let t=ym;ym=xm(),e.type===`PUSH`||e.type===`REPLACE`?bm=!1:(bm=t,bm&&vm?vm=!1:bm&&_m.at(-1)?.(),setTimeout(Cm))}),setTimeout(Cm)}function Tm(e,t){let n=(0,k.useEffectEvent)(t);(0,k.useEffect)(()=>{if(!e)return;function t(){n()}return _m.push(t),setTimeout(Cm),()=>{_m.splice(_m.indexOf(t),1),setTimeout(Cm)}},[e])}var Em=`terminalProjects`;function Dm(){return JSON.parse(localStorage.getItem(Em)??`[]`)}function Om(){let e=sm();if(cm()!==null||e.machine===void 0||e.project===void 0||e.session===void 0)return;let t=`${e.machine} ${e.project}`,n=Dm().filter(e=>e!==t);localStorage.setItem(Em,JSON.stringify(e.bottom===`terminal`?[...n,t]:n))}function km(e=!1){let t=Y().selection;if(t===null){Am({project:cm()===null?void 0:sm().project},!0,J.history.location.state.layer);return}let n=sm(),r=n.machine===t.machine&&n.project===t.projectId&&n.session===void 0&&(t.sessionId===null||Y().loaded),i=Dm().includes(`${t.machine} ${t.projectId}`),a={machine:t.machine,project:t.projectId,session:t.sessionId??void 0,bottom:r?n.bottom:t.sessionId!==null&&i?`terminal`:void 0};if(cm()!==null){J.navigate({to:`/`,search:a,replace:e||xm(),state:{layer:`chat`},resetScroll:!1});return}let o=n.machine===a.machine&&n.project===a.project&&n.session===a.session,s=n.machine!==void 0&&n.session===void 0&&a.session===void 0;e||o||r||s?pm(a):mm(a,`chat`)}function Am(e,t,n){let r=cm(),i=xm(),a=t&&i?{layer:n,guard:i}:{layer:n};r===null?J.navigate({to:`/`,search:e,replace:t||i,state:a,resetScroll:!1}):J.navigate({to:`/terminal/$machine`,params:{machine:r},search:e,replace:t||i,state:a,resetScroll:!1})}function jm(e,t=null,n=!1){let r=Z(Y(),e.machine),i=Y().selection;localStorage.setItem(`lastProject`,JSON.stringify({machine:e.machine,projectId:e.projectId})),X({selection:e,loaded:e.sessionId===null,items:[],earlier:[],before:null,partial:``,requests:[],queue:[],settings:e.sessionId===null?i?.sessionId===null&&i.machine===e.machine?Y().settings:lg(r):Da(Hh(e))??cg(r.composer,Y().sessions.find(t=>t.machine===e.machine&&t.id===e.sessionId)?.provider??r.composer?.provider??`claude`),context:null,replacing:null,paletteOpen:!1,unseen:Y().unseen.filter(t=>e.sessionId===null||t!==lh(e.machine,e.sessionId))}),km(n),pg(e.machine),e.sessionId!==null&&r.status===`online`&&Mm(e.machine,e.projectId,e.sessionId,!0,t)}function Mm(e,t,n,r,i){M(e,`sessions.open`,{projectId:t,sessionId:n,opened:r,query:i}).then(t=>{t===null||Y().sessions.some(n=>n.machine===e&&n.id===t.id)||X({sessions:[...Y().sessions,{...t,machine:e}]})}).catch($)}function Nm(){X({selection:null,loaded:!1,items:[],earlier:[],before:null,partial:``,requests:[],queue:[],context:null}),km()}function Pm(){let e=Y().machines,t=localStorage.getItem(`lastTerminal`);return t!==null&&e.some(e=>e.id===t)?t:e.at(0)?.id??null}function Fm(e,t,n=!1){jm({machine:e,projectId:Lh(Y(),e,t)?.scratch===!0?om:t,sessionId:null},null,n)}function Im(){let e=Y(),t=localStorage.getItem(`lastProject`),n=t===null?null:JSON.parse(t),r=e.machines.filter(e=>e.system?.scratchAvailable===!0);if(n!==null&&n.projectId===`no-project`&&r.some(e=>e.id===n.machine))return n;let i=(n===null?void 0:e.projects.find(e=>e.machine===n.machine&&e.id===n.projectId))??e.projects.find(e=>!e.scratch);return i===void 0?r.length>0?{machine:r[0].id,projectId:om}:null:{machine:i.machine,projectId:i.id}}function Lm(e,t){let n=cm();(n!==e||um()!==t)&&(J.navigate({to:`/terminal/$machine`,params:{machine:e},search:{project:t===`global`?void 0:t},replace:n!==null||xm(),state:{layer:`chat`},resetScroll:!1}),Nm())}async function Rm(e,t,n,r){if(n===null)throw Error(`no session selected`);`Notification`in window&&Notification.permission==="default"&&Notification.requestPermission(),X({sentAt:Date.now()}),await M(n.machine,`sessions.send`,{sessionId:n.sessionId,projectId:n.projectId,prompt:e,settings:r,delivery:t});let i=Y().replacing;n.sessionId===null&&i!==null&&i.machine===n.machine&&i.sessionId!==null&&(X({replacing:null}),await Xm(i.machine,i.sessionId,i.projectId))}function zm(e){let t=Y().selection;t!==null&&t.sessionId!==null&&M(t.machine,`sessions.unqueue`,{sessionId:t.sessionId,id:e}).catch($)}function Bm(e){let t=Y().selection;t!==null&&t.sessionId!==null&&M(t.machine,`sessions.steer`,{sessionId:t.sessionId,id:e}).catch($)}function Vm(){let e=Y().selection;e!==null&&e.sessionId!==null&&M(e.machine,`sessions.interrupt`,{sessionId:e.sessionId}).catch($)}function Hm(e,t,n){M(e,`sessions.stopTask`,{sessionId:t,taskId:n}).catch($)}function Um(e,t,n){let r=Y().selection;r!==null&&r.sessionId!==null&&M(r.machine,`sessions.respond`,{sessionId:r.sessionId,requestId:e,decision:t,answers:n}).catch($)}async function Wm(e){let t=Y().selection;if(t!==null&&t.sessionId!==null)try{let n=await M(t.machine,`sessions.fork`,{sessionId:t.sessionId,projectId:t.projectId,messageId:e});jm({...t,sessionId:n.sessionId})}catch(e){$(e)}}async function Gm(){let e=Y().selection,t=Y().before;if(e!==null&&e.sessionId!==null&&t!==null)try{let n=await M(e.machine,`sessions.earlier`,{sessionId:e.sessionId,before:t});if(Y().selection!==e||Y().before!==t)return;X({earlier:[...n.items,...Y().earlier],before:n.before})}catch(e){$(e)}}async function Km(e,t){let n=Y().selection;if(n!==null&&n.sessionId!==null)try{let r=await M(n.machine,`sessions.agent`,{sessionId:n.sessionId,projectId:n.projectId,agentId:t,parent:e});if(Y().selection!==n)return;let i=new Set(r.map(e=>e.id)),a=Y().items;X({items:[...a.filter(t=>t.parent!==e),...r,...a.filter(t=>t.parent===e&&!i.has(t.id))]})}catch(e){$(e)}}async function qm(e,t,n){let r=Y();function i(n){return n.machine===e&&n.id===t}let a=[...r.sessions,...r.inactive].find(i);if(a!==void 0){let e={...a,...n};X({sessions:r.sessions.some(i)?r.sessions.map(t=>i(t)?e:t):e.status===`inactive`?r.sessions:[...r.sessions,e],inactive:e.status===`inactive`?r.inactive.some(i)?r.inactive.map(t=>i(t)?e:t):[e,...r.inactive]:r.inactive.filter(e=>!i(e))})}try{await M(e,`sessions.update`,{id:t,patch:n})}catch(e){$(e)}}async function Jm(e){let t=lh(e.machine,e.id);X({generatingTitles:[...Y().generatingTitles,t]});try{await M(e.machine,`sessions.generateTitle`,{id:e.id,projectId:e.projectId})}catch(e){$(e)}finally{X({generatingTitles:Y().generatingTitles.filter(e=>e!==t)})}}async function Ym(e,t,n){let r=Y().selection;if(r?.machine===e&&r.sessionId===t){let i=Y().sessions.filter(r=>(r.status===`pinned`||r.status===`active`||r.status===`snoozed`)&&(r.machine!==e||r.id!==t)&&(n===null||r.machine===n.machine&&(r.projectId===n.projectId||n.projectId===`no-project`&&Lh(Y(),r.machine,r.projectId)?.scratch===!0))).sort((e,t)=>t.updatedAt-e.updatedAt).at(0);i===void 0?Fm(r.machine,r.projectId,!0):jm({machine:i.machine,projectId:i.projectId,sessionId:i.id},null,!0)}await qm(e,t,{status:`inactive`})}async function Xm(e,t,n){X({sessions:Y().sessions.filter(n=>n.machine!==e||n.id!==t),inactive:Y().inactive.filter(n=>n.machine!==e||n.id!==t)}),Ta(lh(e,t));let r=Y().selection;r?.machine===e&&r.sessionId===t&&Fm(e,r.projectId,!0);try{await M(e,`sessions.remove`,{id:t,projectId:n})}catch(e){$(e)}}var Zm=Tp({machine:Uf().optional().catch(void 0),project:Uf().optional().catch(void 0),session:Uf().optional().catch(void 0),panel:Pp([`diff`,`tasks`,`browser`]).optional().catch(void 0),browse:Uf().optional().catch(void 0),bottom:Ip(`terminal`).optional().catch(void 0),terminal:Uf().optional().catch(void 0)}),Qm=oi({validateSearch:Zm}),$m=ii({getParentRoute:()=>Qm,path:`/`}),eh=ii({getParentRoute:()=>Qm,path:`/terminal`,beforeLoad:()=>{let e=Pm();throw st(e===null?{to:`/`,search:{},replace:!0}:{to:`/terminal/$machine`,params:{machine:e},search:{},replace:!0})}}),th=ii({getParentRoute:()=>Qm,path:`/terminal/$machine`});if(window.history.state?.__TSR_index===void 0&&(location.pathname.startsWith(`/terminal`)||new URLSearchParams(location.search).has(`machine`))){let e=`${location.pathname}${location.search}${location.hash}`,t=Math.random().toString(36).slice(2),n=Math.random().toString(36).slice(2);window.history.replaceState({__TSR_index:0,__TSR_key:t,key:t},``,`/`),window.history.pushState({__TSR_index:1,__TSR_key:n,key:n,layer:`chat`},``,e)}var J=ci({routeTree:Qm.addChildren([$m,eh,th]),disableGlobalCatchBoundary:!0,parseSearch:e=>Zm.parse(Object.fromEntries(new URLSearchParams(e))),stringifySearch:e=>{let t=new URLSearchParams;for(let n of Object.entries(e))n[1]!==void 0&&t.set(n[0],String(n[1]));let n=t.toString();return n===``?``:`?${n}`}}),nh=`machines`,rh=document.querySelector(`meta[name="offsite-connect"]`)?.getAttribute(`content`)?.split(` `)??null;function ih(){let e=localStorage.getItem(nh);return e===null?[]:JSON.parse(e)}function ah(e){localStorage.setItem(nh,JSON.stringify(e))}async function oh(e){if(!(`caches`in window))return;let t=e.map(e=>({id:e.id,addresses:e.addresses}));await(await caches.open(`offsite-worker`)).put(`/machines`,new Response(JSON.stringify(t)))}function sh(){if(location.pathname!==`/pair`)return null;let e=new URLSearchParams(location.hash.slice(1));J.navigate({to:`/`,replace:!0});let t=e.get(`machine`);if(t===null)throw Error(`the pairing link has no machine`);return{address:ch(t).address,code:e.get(`code`)}}function ch(e){let t=e.trim(),n=new URL(/^[a-z]+:\/\//i.test(t)?t:`http://${t}`);if(n.protocol!==`http:`&&n.protocol!==`https:`)throw Error(`Use an http:// or https:// address`);let r=new URLSearchParams(n.hash.slice(1)),i=r.get(`machine`);return{address:i===null?n.origin:ch(i).address,code:r.get(`code`)}}function lh(e,t){return`${e} ${t}`}function uh(e){return{id:e.id,addresses:e.addresses,via:null,status:`connecting`,name:e.label??e.name,hostname:e.name,label:e.label,icon:e.icon,pairedAt:e.pairedAt??null,config:null,composer:null,appIcon:null,configError:null,system:null,claudeAccounts:[],codexAccounts:[],openCode:{available:!1},notifier:!1,activity:{},providers:[],terminals:[]}}function dh(e){return e.projects.map(t=>({...t,machine:e.id}))}function fh(){let e=ih(),t=Y().machines;for(let n of t)e.some(e=>e.id===n.id)||xh(n.id);for(let n of e){let e=t.find(e=>e.id===n.id);if(e===void 0){let e=Y();X({machines:[...e.machines,uh(n)],projects:[...e.projects,...dh(n)]}),Ii(n.id,n.addresses)}else Q(n.id,{label:n.label,icon:n.icon,name:n.label??e.hostname}),(n.addresses.join(` `)!==e.addresses.join(` `)||n.pairedAt!==e.pairedAt)&&(Q(n.id,{addresses:n.addresses,pairedAt:n.pairedAt}),yh(n.id))}let n=e.map(e=>e.id);X({machines:[...Y().machines].sort((e,t)=>n.indexOf(e.id)-n.indexOf(t.id))})}async function ph(e,t){let n=Y().machines.find(t=>t.addresses.some(t=>e.includes(t)));if(n!==void 0)return t!==null&&await mh(n.id,t),n.id;let r=Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,`0`)).join(``);return t!==null&&await Si(r,await hh(e,t)),X({machines:[...Y().machines,uh({id:r,addresses:e,name:new URL(e[0]).hostname,label:null,icon:`computer`,pairedAt:t===null?null:Date.now(),projects:[]})]}),Sh(),Ii(r,e),r}async function mh(e,t){await Si(e,await hh(Z(Y(),e).addresses,t)),Q(e,{pairedAt:Date.now()}),Sh(),yh(e)}async function hh(e,t){let n;for(let r of e){let e=await fetch(`${r}/api/pair`,{method:`POST`,headers:{authorization:`Bearer ${t}`}}).catch(e=>(n??=e,null));if(e!==null){if(!e.ok)throw Error(await e.text());return(await e.json()).token}}throw Error(`Could not reach the machine to pair: ${String(n)}`)}function gh(e,t){let n=Z(Y(),e),r={...n,...t};Q(e,{...t,name:r.label??r.hostname}),Sh(),r.addresses.join(` `)!==n.addresses.join(` `)&&yh(e)}function _h(e){X({machines:[...Y().machines].sort((t,n)=>e.indexOf(t.id)-e.indexOf(n.id))}),Sh()}function vh(e){oh(e).catch(e=>console.error(`could not share the machines with the service worker`,e))}function yh(e){Li(e),Q(e,{status:`connecting`,via:null}),Ii(e,Z(Y(),e).addresses)}function bh(e){xh(e),Sh(),Ci(e).catch(e=>console.error(`could not remove the device token`,e))}function xh(e){Li(e);let t=Y(),n=t.machines.filter(t=>t.id!==e);X({machines:n,projects:t.projects.filter(t=>t.machine!==e),sessions:t.sessions.filter(t=>t.machine!==e),inactive:t.inactive.filter(t=>t.machine!==e),unseen:t.unseen.filter(t=>!t.startsWith(`${e} `)),...t.settingsMachine===e&&{settingsMachine:n.at(0)?.id??null},...t.selection?.machine===e&&{selection:null}}),km()}function Sh(){let e=Y(),t=e.machines.map(t=>({id:t.id,addresses:t.addresses,name:t.hostname,label:t.label,icon:t.icon,pairedAt:t.pairedAt,projects:e.projects.filter(e=>e.machine===t.id).map(e=>({id:e.id,path:e.path,name:e.name,logo:e.logo,hidden:e.hidden,scratch:e.scratch}))}));ah(t),vh(t)}var Ch=[{id:`one-dark-darker`,name:`One Dark Darker`,codeTheme:`one-dark-pro`,background:`#15181C`,foreground:`#ABB2BF`,cursor:`#B3BAC5`,selectionBackground:`#3B414D`,palette:[`#4A4F5A`,`#EE5D69`,`#97C775`,`#B68353`,`#61AFEF`,`#C678DD`,`#56B6C2`,`#CCCCCC`,`#616A7B`,`#FE808A`,`#C2DEAD`,`#D1A47A`,`#93CFFF`,`#E0A8F1`,`#82D2DC`,`#FFFFFF`]},{id:`one-dark-pro`,name:`One Dark Pro`,codeTheme:`one-dark-pro`,background:`#282C34`,foreground:`#ABB2BF`,cursor:`#528BFF`,selectionBackground:`#41454E`,palette:[`#3F4451`,`#E05561`,`#8CC265`,`#D18F52`,`#4AA5F0`,`#C162DE`,`#42B3C2`,`#D7DAE0`,`#4F5666`,`#FF616E`,`#A5E075`,`#F0A45D`,`#4DC4FF`,`#DE73FF`,`#4CD1E0`,`#E6E6E6`]},{id:`dracula`,name:`Dracula`,codeTheme:`dracula`,background:`#282A36`,foreground:`#F8F8F2`,cursor:`#F8F8F2`,selectionBackground:`#44475A`,palette:[`#21222C`,`#FF5555`,`#50FA7B`,`#F1FA8C`,`#BD93F9`,`#FF79C6`,`#8BE9FD`,`#F8F8F2`,`#6272A4`,`#FF6E6E`,`#69FF94`,`#FFFFA5`,`#D6ACFF`,`#FF92DF`,`#A4FFFF`,`#FFFFFF`]},{id:`tokyo-night`,name:`Tokyo Night`,codeTheme:`tokyo-night`,background:`#1A1B26`,foreground:`#C0CAF5`,cursor:`#C0CAF5`,selectionBackground:`#33467C`,palette:[`#15161E`,`#F7768E`,`#9ECE6A`,`#E0AF68`,`#7AA2F7`,`#BB9AF7`,`#7DCFFF`,`#A9B1D6`,`#414868`,`#F7768E`,`#9ECE6A`,`#E0AF68`,`#7AA2F7`,`#BB9AF7`,`#7DCFFF`,`#C0CAF5`]},{id:`catppuccin-mocha`,name:`Catppuccin Mocha`,codeTheme:`catppuccin-mocha`,background:`#1E1E2E`,foreground:`#CDD6F4`,cursor:`#F5E0DC`,selectionBackground:`#585B70`,palette:[`#45475A`,`#F38BA8`,`#A6E3A1`,`#F9E2AF`,`#89B4FA`,`#F5C2E7`,`#94E2D5`,`#BAC2DE`,`#585B70`,`#F38BA8`,`#A6E3A1`,`#F9E2AF`,`#89B4FA`,`#F5C2E7`,`#94E2D5`,`#A6ADC8`]},{id:`nord`,name:`Nord`,codeTheme:`nord`,background:`#2E3440`,foreground:`#D8DEE9`,cursor:`#D8DEE9`,selectionBackground:`#434C5E`,palette:[`#3B4252`,`#BF616A`,`#A3BE8C`,`#EBCB8B`,`#81A1C1`,`#B48EAD`,`#88C0D0`,`#E5E9F0`,`#4C566A`,`#BF616A`,`#A3BE8C`,`#EBCB8B`,`#81A1C1`,`#B48EAD`,`#8FBCBB`,`#ECEFF4`]},{id:`gruvbox-dark`,name:`Gruvbox Dark`,codeTheme:`gruvbox-dark-medium`,background:`#282828`,foreground:`#EBDBB2`,cursor:`#EBDBB2`,selectionBackground:`#504945`,palette:[`#282828`,`#CC241D`,`#98971A`,`#D79921`,`#458588`,`#B16286`,`#689D6A`,`#A89984`,`#928374`,`#FB4934`,`#B8BB26`,`#FABD2F`,`#83A598`,`#D3869B`,`#8EC07C`,`#EBDBB2`]},{id:`solarized-dark`,name:`Solarized Dark`,codeTheme:`solarized-dark`,background:`#002B36`,foreground:`#839496`,cursor:`#839496`,selectionBackground:`#073642`,palette:[`#073642`,`#DC322F`,`#859900`,`#B58900`,`#268BD2`,`#D33682`,`#2AA198`,`#EEE8D5`,`#002B36`,`#CB4B16`,`#586E75`,`#657B83`,`#839496`,`#6C71C4`,`#93A1A1`,`#FDF6E3`]},{id:`github-dark`,name:`GitHub Dark`,codeTheme:`github-dark`,background:`#0D1117`,foreground:`#E6EDF3`,cursor:`#E6EDF3`,selectionBackground:`#264F78`,palette:[`#484F58`,`#FF7B72`,`#3FB950`,`#D29922`,`#58A6FF`,`#BC8CFF`,`#39C5CF`,`#B1BAC4`,`#6E7681`,`#FFA198`,`#56D364`,`#E3B341`,`#79C0FF`,`#D2A8FF`,`#56D4DD`,`#FFFFFF`]},{id:`rose-pine`,name:`Rosé Pine`,codeTheme:`rose-pine`,background:`#191724`,foreground:`#E0DEF4`,cursor:`#E0DEF4`,selectionBackground:`#403D52`,palette:[`#26233A`,`#EB6F92`,`#31748F`,`#F6C177`,`#9CCFD8`,`#C4A7E7`,`#EBBCBA`,`#E0DEF4`,`#6E6A86`,`#EB6F92`,`#31748F`,`#F6C177`,`#9CCFD8`,`#C4A7E7`,`#EBBCBA`,`#E0DEF4`]}],wh=Ep({theme:Uf().refine(e=>Ch.some(t=>t.id===e)).default(Ch[0].id),terminal:Ep({font:Ep({family:Uf().default(`FiraCode Nerd Font`),size:mp().default(14),lineHeight:mp().default(1.35),ligatures:q().default(!0)}).prefault({}),cursor:Ep({style:Pp([`block`,`bar`,`underline`]).default(`bar`),blink:q().default(!0)}).prefault({}),padding:Ep({top:mp().default(4),right:mp().default(4),bottom:mp().default(0),left:mp().default(4)}).prefault({}),scrollback:mp().default(1e3),boldIsBright:q().default(!0),behavior:Ep({modernizeShiftEnter:q().default(!0),pasteBrowserImages:q().default(!0),captureShortcuts:q().default(!0),bellFlash:q().default(!0),bellSound:q().default(!0),clickToMoveCursor:q().default(!0),optionAsMeta:Pp([`off`,`left`,`right`,`both`]).default(`off`),windowsCopyPaste:q().default(!0),confirmCloseBusyTab:q().default(!0)}).prefault({})}).prefault({}),editor:Ep({font:Ep({family:Uf().default(`FiraCode Nerd Font`),size:mp().default(15.3),lineHeight:mp().default(1.8),ligatures:q().default(!0),features:Uf().default(`'zero', 'ss02', 'ss06', 'cv02', 'cv14', 'cv26'`)}).prefault({}),cursor:Ep({style:Pp([`block`,`bar`,`underline`]).default(`bar`),blink:q().default(!0)}).prefault({}),tabSize:mp().default(2),wordWrap:q().default(!0),graph:q().default(!0)}).prefault({}),diff:Ep({split:q().default(!1),wrap:q().default(!0),collapsed:q().default(!1)}).prefault({}),rewind:Pp([`all`,`chat`,`code`]).default(`chat`),groupActiveByProject:q().default(!1),toolbar:Cp(Pp([`diff`,`terminal`,`tasks`,`browser`,`editor`])).default([`diff`,`terminal`,`editor`])}),Th=`prefs`,Eh=wh.parse({});function Dh(){let e=localStorage.getItem(Th);if(e===null)return structuredClone(Eh);let t=wh.safeParse(JSON.parse(e));return t.success?t.data:(console.warn(`invalid stored prefs, using the defaults:\n${ss(t.error)}`),structuredClone(Eh))}function Oh(e){localStorage.setItem(Th,JSON.stringify(e))}function kh(){let e=Y().prefs.theme,t=Ch.find(t=>t.id===e);if(t===void 0)throw Error(`unknown theme ${e}`);return t}function Ah(){let e=Ih(e=>e.prefs.theme),t=Ch.find(t=>t.id===e);if(t===void 0)throw Error(`unknown theme ${e}`);return t.codeTheme}function jh(){let e=kh(),t=document.documentElement.style;t.setProperty(`--bg`,e.background),t.setProperty(`--text`,e.foreground),t.setProperty(`--blue`,e.palette[4]),t.setProperty(`--danger`,e.palette[1]),t.setProperty(`--green`,e.palette[2]),t.setProperty(`--yellow`,e.palette[3]),document.querySelector(`meta[name="theme-color"]`)?.setAttribute(`content`,e.background)}var Mh={claude:`Claude`,codex:`Codex`,opencode:`OpenCode`},Nh;function Ph(e){Nh=aa()(()=>e)}function Fh(e){return Nh.subscribe(e)}function Y(){return Nh.getState()}function Ih(e){return sa(Nh,e)}function X(e){Nh.setState(e)}function Z(e,t){let n=e.machines.find(e=>e.id===t);if(n===void 0)throw Error(`unknown machine ${t}`);return n}function Lh(e,t,n){return e.projects.find(e=>e.machine===t&&e.id===n)}function Rh(e){return e.selection?.machine??e.machines.at(0)?.id??null}function Q(e,t){X({machines:Y().machines.map(n=>n.id===e?{...n,...t}:n)})}function zh(e,t,n){if(n!==null)return e.find(e=>e.id===t)?.activity[n]}function Bh(e){let t=e.selection;if(t!==null)return zh(e.machines,t.machine,t.sessionId)}function Vh(e){return Bh(e)?.running===!0}function Hh(e){return e.sessionId===null?`new`:lh(e.machine,e.sessionId)}function Uh(e){X({draft:e})}function Wh(e){X({paletteOpen:e})}function Gh(e){X({editor:e})}function Kh(e){X({exporting:e})}function qh(e){X({settingsOpen:e,paletteOpen:!1,...e&&{settingsMachine:Rh(Y()),settingsAccount:null,settingsEditedMachine:null,settingsListing:!0}})}function Jh(e){X({settingsOpen:!0,settingsPage:e,settingsAccount:null,settingsEditedMachine:null,settingsListing:!1,paletteOpen:!1,...!Y().settingsOpen&&{settingsMachine:Rh(Y())}})}function Yh(e){X({prefs:e}),Oh(e),jh()}function $(e){X({errors:[...Y().errors,i(e)]})}function Xh(){X({errors:[]})}function Zh(e){let t=new Map;function n(t,n){Y().machines.some(e=>e.id===t)&&e.apply(t,n)}async function r(r,a){let o=await e.save(r,a),s=t.get(r);s!==void 0&&(--s.writes,s.writes>0||(o===null?await i(r):n(r,o)))}async function i(r){let i=t.get(r)?.version;try{let a=await e.load(r),o=t.get(r);o!==void 0&&o.writes===0&&o.version===i&&n(r,a)}catch(e){$(e)}}return{update(n,i){e.set(n,i);let a=t.get(n)??{writes:0,version:0,timer:void 0};t.set(n,a),a.timer===void 0&&(a.writes+=1),a.version+=1,window.clearTimeout(a.timer),a.timer=window.setTimeout(()=>{a.timer=void 0,r(n,i)},300)},receive(e,r){(t.get(e)?.writes??0)===0&&n(e,r)}}}var Qh=Zh({set:ig,save:async(e,t)=>{try{let n=await M(e,`config.save`,t);return Q(e,{configError:null}),n}catch(t){return Q(e,{configError:i(t)}),null}},load:async e=>(await M(e,`config.get`,void 0)).config,apply:ig}),$h=Zh({set:(e,t)=>Q(e,{composer:t}),save:async(e,t)=>{try{return await M(e,`composer.save`,t)}catch(e){return $(e),null}},load:e=>M(e,`composer.get`,void 0),apply:ag}),eg=Qh.update,tg=Qh.receive,ng=$h.update,rg=$h.receive;function ig(e,t){let n=Z(Y(),e).config;Q(e,{config:t}),n!==null&&ra(n.newThreads,t.newThreads)||fg(e)}function ag(e,t){let n=Z(Y(),e).composer;Q(e,{composer:t});let r=Y().selection;if(r===null||r.machine!==e)return;if(r.sessionId===null){n===null&&fg(e);return}if(zh(Y().machines,e,r.sessionId)!==void 0)return;let i=Da(Hh(r))??cg(t,Y().settings.provider),a=i.provider!==Y().settings.provider||i.accountId!==Y().settings.accountId;X({settings:i}),a&&hg()}var og=null,sg={provider:`claude`,accountId:null,model:null,effort:null,mode:null,plan:!1};function cg(e,t){return e===null?{...sg,provider:t}:{provider:t,...e[t]}}function lg(e){if(e.config===null)return sg;let t=e.config.newThreads;return{...cg(e.composer,t.provider),accountId:t.accountId,model:t.models[t.provider],effort:null}}function ug(e){let t={...Y().settings,...e};X({settings:t});let n=Y().selection;if(n===null)return;n.sessionId!==null&&Oa(Hh(n),t);let r=Z(Y(),n.machine).composer;r!==null&&ng(n.machine,{...r,provider:t.provider,[t.provider]:{accountId:t.accountId,model:t.model,effort:t.effort,mode:t.mode,plan:t.plan}}),e.accountId!==void 0&&hg(),n.sessionId!==null&&zh(Y().machines,n.machine,n.sessionId)!==void 0&&e.accountId===void 0&&M(n.machine,`sessions.configure`,{sessionId:n.sessionId,settings:t}).catch($)}function dg(e,t){if(Q(e,{claudeAccounts:t.claudeAccounts,codexAccounts:t.codexAccounts,openCode:t.openCode}),Y().selection?.machine!==e)return;let n=Y().settings,r=[...[...t.claudeAccounts,...t.codexAccounts].filter(e=>e.valid).map(e=>({provider:e.provider,accountId:e.id})),...t.openCode.available?[{provider:`opencode`,accountId:null}]:[]];if(r.some(e=>e.provider===n.provider&&e.accountId===n.accountId))return;let i=r.find(e=>e.provider===n.provider),a=Y().selection?.sessionId===null?r.at(0):void 0;if(i!==void 0)ug({accountId:i.accountId});else if(a!==void 0){let t=Z(Y(),e);ug({...cg(t.composer,a.provider),accountId:a.accountId,model:t.config===null?null:t.config.newThreads.models[a.provider],effort:null})}else n.accountId!==null&&ug({accountId:null})}function fg(e){let t=Y().selection;t?.machine===e&&t.sessionId===null&&(X({settings:lg(Z(Y(),e))}),pg(e))}function pg(e){let t=Z(Y(),e);(t.claudeAccounts.length>0||t.codexAccounts.length>0||t.openCode.available)&&dg(e,{claudeAccounts:t.claudeAccounts,codexAccounts:t.codexAccounts,openCode:t.openCode}),hg()}async function mg(e){try{dg(e,await M(e,`accounts.list`,void 0))}catch(e){$(e)}}async function hg(){let e=Y().selection;if(e===null)return;let{provider:t,accountId:n}=Y().settings;if(t!==`opencode`&&n===null)X({capabilities:null});else try{let r=JSON.stringify([e.machine,t,n,e.projectId]);if(og?.key!==r){let i=M(e.machine,`capabilities`,{provider:t,accountId:n,projectId:e.projectId});function a(){og?.result===i&&(og=null)}i.then(a,a),og={key:r,result:i}}let i=await og.result;if(Y().selection?.machine!==e.machine||Y().selection?.projectId!==e.projectId||Y().settings.provider!==t||Y().settings.accountId!==n)return;X({capabilities:i});let a=Y().settings;if(a.model!==null){let e=i.models.find(e=>e.value===a.model)?.effort;a.provider!==`opencode`&&a.effort===null&&e!=null&&ug({effort:e});return}let o=i.models.find(e=>!e.hidden&&e.value===i.defaultModel)??i.models.find(e=>!e.hidden);if(o===void 0)return;ug({model:o.value,...o.effort===null?{}:{effort:o.effort}})}catch(e){$(e)}}var gg=[[`path`,{d:`M18 6L12 12M12 12L6 18M12 12L18 18M12 12L6 6`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}]];export{uh as $,Oa as $t,Fh as A,wm as At,ph as B,Ip as Bt,Q as C,gm as Ct,Wh as D,Om as Dt,Kh as E,mm as Et,kh as F,lm as Ft,mh as G,Ea as Gt,gh as H,Uf as Ht,Ah as I,dm as It,ch as J,ja as Jt,sh as K,Da as Kt,Eh as L,om as Lt,Yh as M,cm as Mt,Ih as N,um as Nt,qh as O,pm as Ot,jh as P,Tm as Pt,_h as Q,Ca as Qt,Dh as R,q as Rt,Uh as S,sm as St,$ as T,hm as Tt,ih as U,Pa as Ut,rh as V,Tp as Vt,lh as W,Sa as Wt,yh as X,ba as Xt,fh as Y,wa as Yt,bh as Z,Na as Zt,Z as _,Yt as _n,Rm as _t,mg as a,Ii as an,qm as at,Bh as b,Ae as bn,Hm as bt,rg as c,Bi as cn,Im as ct,zh as d,ui as dn,Mm as dt,Ma as en,dh as et,Ph as f,Rr as fn,jm as ft,Y as g,ir as gn,Um as gt,Hh as h,ar as hn,Xm as ht,cg as i,M as in,Ym as it,X as j,km as jt,Jh as k,fm as kt,tg as l,Vi as ln,Km as lt,Xh as m,sr as mn,Jm as mt,ug as n,ka as nn,J as nt,hg as o,zi as on,Wm as ot,Rh as p,jr as pn,Lm as pt,Sh as q,Aa as qt,sg as r,ra as rn,Nm as rt,dg as s,Ri as sn,Vm as st,gg as t,xa as tn,vh as tt,eg as u,Pi as un,Gm as ut,Lh as v,ot as vn,Fm as vt,Gh as w,Sm as wt,Vh as x,de as xn,zm as xt,Mh as y,Re as yn,Bm as yt,Ch as z,Ap as zt};
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{a as t,i as n,n as r}from"./dist-D99rUXSZ.js";import{n as i,r as a,t as o}from"./TextWrapIcon-BRhMbXe9.js";import{t as s}from"./ChevronsDownUpIcon-BNVFd2te.js";import{I as c,M as l,N as u,g as d,in as f,t as p}from"./XIcon-D2pbIF2Y.js";import{a as m,t as h}from"./button-CWFREsRn.js";import{An as g,Ft as _,G as v,Gn as y,N as b,P as x,W as S,Wn as C,at as w,cn as T,gt as E,ot as D,zt as O}from"./dist-Jliw2AH0.js";import{c as k,l as A,r as j}from"./utils-U6QfaJBO.js";function M(e,t){let n=0;for(let r=0;r<e.length;r++)n+=t(e[r],r);return n}var N=[[`path`,{d:`M18.2505 10.5H19.6403C21.4918 10.5 22.0421 10.7655 21.9975 12.0838C21.9237 14.2674 20.939 16.8047 17 17.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M5.94627 20.6145C2.57185 18.02 2.07468 14.3401 2.00143 10.5001C1.96979 8.8413 2.45126 8.5 4.65919 8.5H15.3408C17.5487 8.5 18.0302 8.8413 17.9986 10.5001C17.9253 14.3401 17.4281 18.02 14.0537 20.6145C13.0934 21.3528 12.2831 21.5 10.9194 21.5H9.08064C7.71686 21.5 6.90658 21.3528 5.94627 20.6145Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M11.3089 2.5C10.7622 2.83861 10.0012 4 10.0012 5.5M7.53971 4C7.53971 4 7 4.5 7 5.5M14.0012 4C13.7279 4.1693 13.5 5 13.5 5.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`2`}]],P=[[`path`,{d:`M3.89124 3.89124C5.28249 2.5 7.52166 2.5 12 2.5C16.4783 2.5 18.7175 2.5 20.1088 3.89124C21.5 5.28249 21.5 7.52166 21.5 12C21.5 16.4783 21.5 18.7175 20.1088 20.1088C18.7175 21.5 16.4783 21.5 12 21.5C7.52166 21.5 5.28249 21.5 3.89124 20.1088C2.5 18.7175 2.5 16.4783 2.5 12C2.5 7.52166 2.5 5.28249 3.89124 3.89124Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M12 2.5V21.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`1`}]],F=[[`path`,{d:`M2.49219 15.5H21.4922`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M2.49219 8.5H21.4922`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M2.49219 12C2.49219 7.52166 2.49219 5.28249 3.88343 3.89124C5.27467 2.5 7.51384 2.5 11.9922 2.5C16.4705 2.5 18.7097 2.5 20.1009 3.89124C21.4922 5.28249 21.4922 7.52166 21.4922 12C21.4922 16.4783 21.4922 18.7175 20.1009 20.1088C18.7097 21.5 16.4705 21.5 11.9922 21.5C7.51384 21.5 5.27467 21.5 3.88343 20.1088C2.49219 18.7175 2.49219 16.4783 2.49219 12Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`2`}]],I=e(A(),1);function L(e){let t=(0,I.useRef)(e);return(0,I.useInsertionEffect)(()=>void(t.current=e)),(0,I.useCallback)((...e)=>t.current(...e),[])}var R=k(),z=(0,I.createContext)(void 0);function ee(){return(0,I.useContext)(z)}var B={position:`absolute`,top:0,bottom:0,textAlign:`center`,whiteSpace:`normal`,touchAction:`none`},V={display:`contents`};function H(){return null}function U({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:r,renderHeaderFilenameSuffix:i,renderHeaderMetadata:a,renderAnnotation:o,renderGutterUtility:s,renderMergeConflictUtility:c,lineAnnotations:l,getHoveredLine:u,getInstance:d,getAnnotationSlotName:f=O}){let p=n?.(e),m=r?.(e),h=i?.(e),_=a?.(e);return(0,R.jsxs)(R.Fragment,{children:[p==null?(0,R.jsxs)(R.Fragment,{children:[m!=null&&(0,R.jsx)(`div`,{slot:`header-prefix`,children:m}),h!=null&&(0,R.jsx)(`div`,{slot:`header-filename-suffix`,children:h}),_!=null&&(0,R.jsx)(`div`,{slot:`header-metadata`,children:_})]}):(0,R.jsx)(`div`,{slot:g,children:p}),o!=null&&l?.map((t,n)=>(0,R.jsx)(`div`,{slot:f(t),children:o(t,e)},n)),t!=null&&c!=null&&d!=null&&t.map(t=>{if(t==null)return;let n=te(t,e);return(0,R.jsx)(`div`,{slot:n,style:V,children:c(t,d)},n)}),s!=null&&(0,R.jsx)(`div`,{slot:`gutter-utility-slot`,style:B,children:s(u)})]})}function te(e,t){let n=b(e,t);return n==null?void 0:x({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex})}var ne=(0,I.createContext)(void 0);function re(e,t){return typeof window>`u`&&t!=null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,R.jsx)(R.Fragment,{children:e})}var ie=(0,I.createContext)(void 0);function W(){return(0,I.useContext)(ie)}function G(){let[e]=(0,I.useState)(()=>{let e=0,t;return{getSnapshot:()=>e,subscribe(e){return t=e,()=>{t=void 0}},forceUpdate(){e++,t?.()}}});return(0,I.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot),e.forceUpdate}function K(e,t){"use no memo";return e.current?.__getNextRenderData(t)}var q=typeof window>`u`?I.useEffect:I.useLayoutEffect;function J({fileDiff:e,oldFile:t,newFile:n,options:r,editorOptions:i,editStateKey:a,lineAnnotations:o,selectedLines:s,prerenderedHTML:c,metrics:l,hasGutterRenderUtility:u,hasCustomHeader:d,disableWorkerPool:f,edit:p,onEditChange:m,onEditComplete:h}){let g=W(),_=s!==void 0,b=(0,I.useContext)(ne),x=ee(),[C,w]=(0,I.useState)(),E=L(e=>m?.(e)),D=m==null?void 0:E,k=(0,I.useRef)(null),A=L(r=>{let i=h?.(r)??`reject`;return i===`accept`&&(k.current={fileDiff:{installed:r.fileDiff,stale:r.originalFileDiff},filePair:e==null?{fileDiff:r.fileDiff,installed:{oldFile:r.oldFile,newFile:r.newFile},stale:{oldFile:t??null,newFile:n??null}}:null,annotations:{installed:r.lineAnnotations,stale:r.originalLineAnnotations}}),i}),j=h==null?void 0:A,M=ae({acceptedCache:k,fileDiff:e,newFile:n,oldFile:t,parseDiffOptions:r?.parseDiffOptions}),N=(0,I.useRef)(null),P=G(),F=K(N,oe(k,M,o))??{fileDiff:M,lineAnnotations:o??y},R=(0,I.useRef)(null),z=(0,I.useRef)(null),B=L(()=>{if(x==null)throw Error(`FileDiff: EditContext is not attached`);return x(`file-diff`,i??{},a)}),V=L(e=>{if(e!=null){if(N.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);g==null?N.current=new v(Z({controlledSelection:_,hasCustomHeader:d,hasGutterRenderUtility:u,onEditChange:D,onEditComplete:j,options:r}),f?void 0:b,P):N.current=new S(Z({controlledSelection:_,hasCustomHeader:d,hasGutterRenderUtility:u,onEditChange:D,onEditComplete:j,options:r}),g,l,f?void 0:b,P),N.current.hydrate({fileDiff:M,fileContainer:e,lineAnnotations:o,prerenderedHTML:c})}else{if(N.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);z.current=null,N.current.cleanUp(),N.current=null,R.current=null}});q(()=>{let{current:e}=N;if(e==null)return;let t=Z({controlledSelection:_,hasCustomHeader:d,hasGutterRenderUtility:u,onEditChange:D,onEditComplete:j,options:r}),n=!T(e.options,t);if(e.setOptions(t),!p&&(z.current=null,R.current!=null)){let{current:e}=R;R.current=null,e()}let i=se(M,o,k);if(e.render({forceRender:n,fileDiff:i.fileDiff,lineAnnotations:i.lineAnnotations}),s!==void 0&&e.setSelectedLines(s),!p||R.current!=null)return;if(x==null)throw Error(`FileDiff: EditContext is not attached`);let a=()=>{N.current===e&&R.current==null&&e.__canAttachEditor()&&(R.current=Q(e,B),P())};if(e.__canAttachEditor()){z.current=null,a();return}let c=e.__prepareForEditing();if(c==null){z.current=null;return}if(z.current?.promise===c)return;let l={promise:c};z.current=l,c.then(()=>{z.current===l&&(a(),z.current=null)}).catch(e=>{z.current===l&&(z.current=null,w(e))})});let H=(0,I.useCallback)(()=>N.current?.getHoveredLine(),[]),U=(0,I.useCallback)(e=>N.current?.getAnnotationSlotName(e)??O(e),[]);if(C!=null)throw C;return{...F,ref:V,getHoveredLine:H,getAnnotationSlotName:U}}function ae({acceptedCache:e,fileDiff:t,newFile:n,oldFile:r,parseDiffOptions:i}){return(0,I.useMemo)(()=>{if(t!=null)return t;let{current:a}=e,o=a?.filePair;if(a!=null&&o!=null){if(Y(r,n,o.stale)||Y(r,n,o.installed))return o.fileDiff;a.filePair=null}return w(r??null,n??null,i)},[e,t,r,n,i])}function Y(e,t,n){return _(e??void 0,n.oldFile??void 0)&&_(t??void 0,n.newFile??void 0)}function oe(e,t,n){"use no memo";return X(t,n,e.current)}function X(e,t,n){return{fileDiff:n?.fileDiff!=null&&E(e,n.fileDiff.stale)?n.fileDiff.installed:e,lineAnnotations:n?.annotations!=null&&t===n.annotations.stale?n.annotations.installed:t}}function se(e,t,n){let{current:r}=n,i=X(e,t,r);return r==null||(r.fileDiff!=null&&!E(e,r.fileDiff.stale)&&(r.fileDiff=null),t!==r.annotations?.stale&&(r.annotations=null),r.fileDiff==null&&r.annotations==null&&r.filePair==null&&(n.current=null)),i}function Z({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r,onEditChange:i,onEditComplete:a}){return{...e,controlledSelection:t,renderCustomHeader:n?H:e?.renderCustomHeader,renderGutterUtility:r?H:e?.renderGutterUtility,onEditChange:i,onEditComplete:a}}function Q(e,t){let n=t();try{return n.edit(e)}catch(e){throw n.cleanUp(),e}}function ce({fileDiff:e,options:t,editorOptions:n,editStateKey:r,metrics:i,lineAnnotations:a,selectedLines:o,className:s,style:c,prerenderedHTML:l,renderAnnotation:u,renderCustomHeader:d,renderHeaderPrefix:f,renderHeaderFilenameSuffix:p,renderHeaderMetadata:m,renderGutterUtility:h,disableWorkerPool:g=!1,edit:_=!1,onEditChange:v,onEditComplete:y}){let{ref:b,getHoveredLine:x,getAnnotationSlotName:S,fileDiff:w,lineAnnotations:T}=J({fileDiff:e,options:t,editorOptions:n,editStateKey:r,metrics:i,lineAnnotations:a,selectedLines:o,prerenderedHTML:l,hasGutterRenderUtility:h!=null,hasCustomHeader:d!=null,disableWorkerPool:g,edit:_,onEditChange:v,onEditComplete:y}),E=U({fileDiff:w,renderCustomHeader:d,renderHeaderPrefix:f,renderHeaderFilenameSuffix:p,renderHeaderMetadata:m,renderAnnotation:u,renderGutterUtility:h,lineAnnotations:T,getHoveredLine:x,getAnnotationSlotName:S});return(0,R.jsx)(C,{ref:b,className:s,style:c,children:re(E,l)})}var le=3e3,ue=`text-foreground hover:bg-accent aria-pressed:bg-accent inline-flex h-7 min-w-7 cursor-pointer items-center justify-center rounded-lg px-1.5 [&_svg]:opacity-80`,$=`text-muted-foreground hover:text-foreground aria-pressed:bg-background aria-pressed:text-foreground dark:aria-pressed:bg-input/72 inline-flex h-6 cursor-pointer items-center justify-center rounded-md px-2.5 aria-pressed:shadow-xs`;function de(e){let[g,_]=(0,I.useState)(null),[v,y]=(0,I.useState)(null),[b,x]=(0,I.useState)(0),S=(0,I.useRef)({patch:null,count:0}),C=u(e=>e.prefs.diff),w=c(),[T,E]=r(`diffFlipped`,[]);function O(e){l({...d().prefs,diff:{...C,...e}})}(0,I.useEffect)(()=>{let t=!0,n=!1;async function r(){if(!n){n=!0;try{let n=await f(e.machine,`git.diff`,{projectId:e.projectId});if(!t||(y(null),n===S.current.patch))return;S.current={patch:n,count:S.current.count+1},_(n.trim()===``?[]:D(n,`${e.projectId}:${S.current.count}`).flatMap(e=>e.files))}catch(e){t&&y(j(e))}finally{n=!1}}}function i(){document.hidden||r()}r();let a=window.setInterval(i,le);return window.addEventListener(`focus`,i),()=>{t=!1,window.clearInterval(a),window.removeEventListener(`focus`,i)}},[e.machine,e.projectId,e.running,b]);let k=g??[],A=M(k,e=>M(e.hunks,e=>e.additionLines)),L=M(k,e=>M(e.hunks,e=>e.deletionLines));return(0,R.jsxs)(`div`,{className:`bg-background flex h-full min-h-0 min-w-0 flex-col`,children:[(0,R.jsxs)(`div`,{className:`border-border/60 bg-background flex h-(--workspace-topbar-height) shrink-0 items-center justify-between gap-2 border-b pr-3 pl-3`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,R.jsx)(h,{size:`icon-sm`,variant:`ghost`,title:`Close`,"aria-label":`Close`,onClick:e.onClose,children:(0,R.jsx)(m,{icon:p,className:`size-4`})}),(0,R.jsx)(`span`,{className:`text-foreground min-w-0 truncate text-xs font-medium`,children:`Uncommitted changes`})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[k.length>0&&(0,R.jsxs)(`span`,{className:`text-2xs mr-1 inline-flex items-center gap-1 font-mono tabular-nums`,children:[(0,R.jsxs)(`span`,{className:`text-diff-addition`,children:[`+`,A]}),(0,R.jsxs)(`span`,{className:`text-diff-deletion`,children:[`-`,L]})]}),(0,R.jsx)(h,{size:`icon-sm`,variant:`ghost`,title:`Refresh diff`,"aria-label":`Refresh diff`,onClick:()=>x(b+1),children:(0,R.jsx)(m,{icon:i,className:`size-4`})}),k.length>0&&(0,R.jsx)(h,{size:`icon-sm`,variant:`ghost`,title:C.collapsed?`Expand all files`:`Collapse all files`,onClick:()=>{E([]),O({collapsed:!C.collapsed})},children:(0,R.jsx)(m,{icon:C.collapsed?n:s,className:`size-4`})}),(0,R.jsxs)(`div`,{className:`bg-input/40 flex shrink-0 items-center rounded-lg p-0.5`,children:[(0,R.jsx)(`button`,{className:$,"aria-pressed":!C.split,"aria-label":`Stacked diff view`,onClick:()=>O({split:!1}),children:(0,R.jsx)(m,{icon:F,className:`size-3.5`})}),(0,R.jsx)(`button`,{className:$,"aria-pressed":C.split,"aria-label":`Split diff view`,onClick:()=>O({split:!0}),children:(0,R.jsx)(m,{icon:P,className:`size-3.5`})})]}),(0,R.jsx)(`button`,{className:ue,"aria-pressed":C.wrap,title:C.wrap?`Disable line wrapping`:`Enable line wrapping`,onClick:()=>O({wrap:!C.wrap}),children:(0,R.jsx)(m,{icon:o,className:`size-3.5`})})]})]}),(0,R.jsxs)(`div`,{className:`diff-render-surface min-h-0 flex-1 overflow-y-auto [--code-background:var(--background)]`,children:[v!==null&&(0,R.jsx)(`p`,{className:`text-muted-foreground p-4 text-center text-xs`,children:v}),v===null&&g===null&&(0,R.jsx)(`p`,{className:`text-muted-foreground p-4 text-center text-xs`,children:`Loading…`}),v===null&&g?.length===0&&(0,R.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,R.jsx)(m,{icon:N,className:`text-muted-foreground/40 size-8`}),(0,R.jsxs)(`div`,{className:`grid gap-1`,children:[(0,R.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No uncommitted changes`}),(0,R.jsx)(`p`,{className:`text-muted-foreground/50 text-xs italic`,children:`If it works, don’t touch it.`})]})]}),v===null&&k.map(e=>{let n=C.collapsed!==T.includes(e.name);function r(){E(T.includes(e.name)?T.filter(t=>t!==e.name):[...T,e.name])}return(0,R.jsx)(`div`,{onClick:e=>{e.nativeEvent.composedPath().some(e=>e instanceof Element&&e.hasAttribute(`data-title`))&&r()},children:(0,R.jsx)(ce,{fileDiff:e,options:{theme:w,themeType:`dark`,unsafeCSS:`:host,
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{a as t,i as n,n as r}from"./dist-D99rUXSZ.js";import{n as i,r as a,t as o}from"./TextWrapIcon-BRhMbXe9.js";import{t as s}from"./ChevronsDownUpIcon-BNVFd2te.js";import{I as c,M as l,N as u,g as d,in as f,t as p}from"./XIcon-hd7a6qPG.js";import{a as m,t as h}from"./button-CWFREsRn.js";import{An as g,Ft as _,G as v,Gn as y,N as b,P as x,W as S,Wn as C,at as w,cn as T,gt as E,ot as D,zt as O}from"./dist-Jliw2AH0.js";import{c as k,l as A,r as j}from"./utils-U6QfaJBO.js";function M(e,t){let n=0;for(let r=0;r<e.length;r++)n+=t(e[r],r);return n}var N=[[`path`,{d:`M18.2505 10.5H19.6403C21.4918 10.5 22.0421 10.7655 21.9975 12.0838C21.9237 14.2674 20.939 16.8047 17 17.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M5.94627 20.6145C2.57185 18.02 2.07468 14.3401 2.00143 10.5001C1.96979 8.8413 2.45126 8.5 4.65919 8.5H15.3408C17.5487 8.5 18.0302 8.8413 17.9986 10.5001C17.9253 14.3401 17.4281 18.02 14.0537 20.6145C13.0934 21.3528 12.2831 21.5 10.9194 21.5H9.08064C7.71686 21.5 6.90658 21.3528 5.94627 20.6145Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M11.3089 2.5C10.7622 2.83861 10.0012 4 10.0012 5.5M7.53971 4C7.53971 4 7 4.5 7 5.5M14.0012 4C13.7279 4.1693 13.5 5 13.5 5.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`2`}]],P=[[`path`,{d:`M3.89124 3.89124C5.28249 2.5 7.52166 2.5 12 2.5C16.4783 2.5 18.7175 2.5 20.1088 3.89124C21.5 5.28249 21.5 7.52166 21.5 12C21.5 16.4783 21.5 18.7175 20.1088 20.1088C18.7175 21.5 16.4783 21.5 12 21.5C7.52166 21.5 5.28249 21.5 3.89124 20.1088C2.5 18.7175 2.5 16.4783 2.5 12C2.5 7.52166 2.5 5.28249 3.89124 3.89124Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M12 2.5V21.5`,stroke:`currentColor`,strokeLinecap:`round`,strokeWidth:`1.5`,key:`1`}]],F=[[`path`,{d:`M2.49219 15.5H21.4922`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`0`}],[`path`,{d:`M2.49219 8.5H21.4922`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,key:`1`}],[`path`,{d:`M2.49219 12C2.49219 7.52166 2.49219 5.28249 3.88343 3.89124C5.27467 2.5 7.51384 2.5 11.9922 2.5C16.4705 2.5 18.7097 2.5 20.1009 3.89124C21.4922 5.28249 21.4922 7.52166 21.4922 12C21.4922 16.4783 21.4922 18.7175 20.1009 20.1088C18.7097 21.5 16.4705 21.5 11.9922 21.5C7.51384 21.5 5.27467 21.5 3.88343 20.1088C2.49219 18.7175 2.49219 16.4783 2.49219 12Z`,stroke:`currentColor`,strokeWidth:`1.5`,key:`2`}]],I=e(A(),1);function L(e){let t=(0,I.useRef)(e);return(0,I.useInsertionEffect)(()=>void(t.current=e)),(0,I.useCallback)((...e)=>t.current(...e),[])}var R=k(),z=(0,I.createContext)(void 0);function ee(){return(0,I.useContext)(z)}var B={position:`absolute`,top:0,bottom:0,textAlign:`center`,whiteSpace:`normal`,touchAction:`none`},V={display:`contents`};function H(){return null}function U({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:r,renderHeaderFilenameSuffix:i,renderHeaderMetadata:a,renderAnnotation:o,renderGutterUtility:s,renderMergeConflictUtility:c,lineAnnotations:l,getHoveredLine:u,getInstance:d,getAnnotationSlotName:f=O}){let p=n?.(e),m=r?.(e),h=i?.(e),_=a?.(e);return(0,R.jsxs)(R.Fragment,{children:[p==null?(0,R.jsxs)(R.Fragment,{children:[m!=null&&(0,R.jsx)(`div`,{slot:`header-prefix`,children:m}),h!=null&&(0,R.jsx)(`div`,{slot:`header-filename-suffix`,children:h}),_!=null&&(0,R.jsx)(`div`,{slot:`header-metadata`,children:_})]}):(0,R.jsx)(`div`,{slot:g,children:p}),o!=null&&l?.map((t,n)=>(0,R.jsx)(`div`,{slot:f(t),children:o(t,e)},n)),t!=null&&c!=null&&d!=null&&t.map(t=>{if(t==null)return;let n=te(t,e);return(0,R.jsx)(`div`,{slot:n,style:V,children:c(t,d)},n)}),s!=null&&(0,R.jsx)(`div`,{slot:`gutter-utility-slot`,style:B,children:s(u)})]})}function te(e,t){let n=b(e,t);return n==null?void 0:x({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex})}var ne=(0,I.createContext)(void 0);function re(e,t){return typeof window>`u`&&t!=null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`template`,{shadowrootmode:`open`,dangerouslySetInnerHTML:{__html:t}}),e]}):(0,R.jsx)(R.Fragment,{children:e})}var ie=(0,I.createContext)(void 0);function W(){return(0,I.useContext)(ie)}function G(){let[e]=(0,I.useState)(()=>{let e=0,t;return{getSnapshot:()=>e,subscribe(e){return t=e,()=>{t=void 0}},forceUpdate(){e++,t?.()}}});return(0,I.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot),e.forceUpdate}function K(e,t){"use no memo";return e.current?.__getNextRenderData(t)}var q=typeof window>`u`?I.useEffect:I.useLayoutEffect;function J({fileDiff:e,oldFile:t,newFile:n,options:r,editorOptions:i,editStateKey:a,lineAnnotations:o,selectedLines:s,prerenderedHTML:c,metrics:l,hasGutterRenderUtility:u,hasCustomHeader:d,disableWorkerPool:f,edit:p,onEditChange:m,onEditComplete:h}){let g=W(),_=s!==void 0,b=(0,I.useContext)(ne),x=ee(),[C,w]=(0,I.useState)(),E=L(e=>m?.(e)),D=m==null?void 0:E,k=(0,I.useRef)(null),A=L(r=>{let i=h?.(r)??`reject`;return i===`accept`&&(k.current={fileDiff:{installed:r.fileDiff,stale:r.originalFileDiff},filePair:e==null?{fileDiff:r.fileDiff,installed:{oldFile:r.oldFile,newFile:r.newFile},stale:{oldFile:t??null,newFile:n??null}}:null,annotations:{installed:r.lineAnnotations,stale:r.originalLineAnnotations}}),i}),j=h==null?void 0:A,M=ae({acceptedCache:k,fileDiff:e,newFile:n,oldFile:t,parseDiffOptions:r?.parseDiffOptions}),N=(0,I.useRef)(null),P=G(),F=K(N,oe(k,M,o))??{fileDiff:M,lineAnnotations:o??y},R=(0,I.useRef)(null),z=(0,I.useRef)(null),B=L(()=>{if(x==null)throw Error(`FileDiff: EditContext is not attached`);return x(`file-diff`,i??{},a)}),V=L(e=>{if(e!=null){if(N.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);g==null?N.current=new v(Z({controlledSelection:_,hasCustomHeader:d,hasGutterRenderUtility:u,onEditChange:D,onEditComplete:j,options:r}),f?void 0:b,P):N.current=new S(Z({controlledSelection:_,hasCustomHeader:d,hasGutterRenderUtility:u,onEditChange:D,onEditComplete:j,options:r}),g,l,f?void 0:b,P),N.current.hydrate({fileDiff:M,fileContainer:e,lineAnnotations:o,prerenderedHTML:c})}else{if(N.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);z.current=null,N.current.cleanUp(),N.current=null,R.current=null}});q(()=>{let{current:e}=N;if(e==null)return;let t=Z({controlledSelection:_,hasCustomHeader:d,hasGutterRenderUtility:u,onEditChange:D,onEditComplete:j,options:r}),n=!T(e.options,t);if(e.setOptions(t),!p&&(z.current=null,R.current!=null)){let{current:e}=R;R.current=null,e()}let i=se(M,o,k);if(e.render({forceRender:n,fileDiff:i.fileDiff,lineAnnotations:i.lineAnnotations}),s!==void 0&&e.setSelectedLines(s),!p||R.current!=null)return;if(x==null)throw Error(`FileDiff: EditContext is not attached`);let a=()=>{N.current===e&&R.current==null&&e.__canAttachEditor()&&(R.current=Q(e,B),P())};if(e.__canAttachEditor()){z.current=null,a();return}let c=e.__prepareForEditing();if(c==null){z.current=null;return}if(z.current?.promise===c)return;let l={promise:c};z.current=l,c.then(()=>{z.current===l&&(a(),z.current=null)}).catch(e=>{z.current===l&&(z.current=null,w(e))})});let H=(0,I.useCallback)(()=>N.current?.getHoveredLine(),[]),U=(0,I.useCallback)(e=>N.current?.getAnnotationSlotName(e)??O(e),[]);if(C!=null)throw C;return{...F,ref:V,getHoveredLine:H,getAnnotationSlotName:U}}function ae({acceptedCache:e,fileDiff:t,newFile:n,oldFile:r,parseDiffOptions:i}){return(0,I.useMemo)(()=>{if(t!=null)return t;let{current:a}=e,o=a?.filePair;if(a!=null&&o!=null){if(Y(r,n,o.stale)||Y(r,n,o.installed))return o.fileDiff;a.filePair=null}return w(r??null,n??null,i)},[e,t,r,n,i])}function Y(e,t,n){return _(e??void 0,n.oldFile??void 0)&&_(t??void 0,n.newFile??void 0)}function oe(e,t,n){"use no memo";return X(t,n,e.current)}function X(e,t,n){return{fileDiff:n?.fileDiff!=null&&E(e,n.fileDiff.stale)?n.fileDiff.installed:e,lineAnnotations:n?.annotations!=null&&t===n.annotations.stale?n.annotations.installed:t}}function se(e,t,n){let{current:r}=n,i=X(e,t,r);return r==null||(r.fileDiff!=null&&!E(e,r.fileDiff.stale)&&(r.fileDiff=null),t!==r.annotations?.stale&&(r.annotations=null),r.fileDiff==null&&r.annotations==null&&r.filePair==null&&(n.current=null)),i}function Z({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r,onEditChange:i,onEditComplete:a}){return{...e,controlledSelection:t,renderCustomHeader:n?H:e?.renderCustomHeader,renderGutterUtility:r?H:e?.renderGutterUtility,onEditChange:i,onEditComplete:a}}function Q(e,t){let n=t();try{return n.edit(e)}catch(e){throw n.cleanUp(),e}}function ce({fileDiff:e,options:t,editorOptions:n,editStateKey:r,metrics:i,lineAnnotations:a,selectedLines:o,className:s,style:c,prerenderedHTML:l,renderAnnotation:u,renderCustomHeader:d,renderHeaderPrefix:f,renderHeaderFilenameSuffix:p,renderHeaderMetadata:m,renderGutterUtility:h,disableWorkerPool:g=!1,edit:_=!1,onEditChange:v,onEditComplete:y}){let{ref:b,getHoveredLine:x,getAnnotationSlotName:S,fileDiff:w,lineAnnotations:T}=J({fileDiff:e,options:t,editorOptions:n,editStateKey:r,metrics:i,lineAnnotations:a,selectedLines:o,prerenderedHTML:l,hasGutterRenderUtility:h!=null,hasCustomHeader:d!=null,disableWorkerPool:g,edit:_,onEditChange:v,onEditComplete:y}),E=U({fileDiff:w,renderCustomHeader:d,renderHeaderPrefix:f,renderHeaderFilenameSuffix:p,renderHeaderMetadata:m,renderAnnotation:u,renderGutterUtility:h,lineAnnotations:T,getHoveredLine:x,getAnnotationSlotName:S});return(0,R.jsx)(C,{ref:b,className:s,style:c,children:re(E,l)})}var le=3e3,ue=`text-foreground hover:bg-accent aria-pressed:bg-accent inline-flex h-7 min-w-7 cursor-pointer items-center justify-center rounded-lg px-1.5 [&_svg]:opacity-80`,$=`text-muted-foreground hover:text-foreground aria-pressed:bg-background aria-pressed:text-foreground dark:aria-pressed:bg-input/72 inline-flex h-6 cursor-pointer items-center justify-center rounded-md px-2.5 aria-pressed:shadow-xs`;function de(e){let[g,_]=(0,I.useState)(null),[v,y]=(0,I.useState)(null),[b,x]=(0,I.useState)(0),S=(0,I.useRef)({patch:null,count:0}),C=u(e=>e.prefs.diff),w=c(),[T,E]=r(`diffFlipped`,[]);function O(e){l({...d().prefs,diff:{...C,...e}})}(0,I.useEffect)(()=>{let t=!0,n=!1;async function r(){if(!n){n=!0;try{let n=await f(e.machine,`git.diff`,{projectId:e.projectId});if(!t||(y(null),n===S.current.patch))return;S.current={patch:n,count:S.current.count+1},_(n.trim()===``?[]:D(n,`${e.projectId}:${S.current.count}`).flatMap(e=>e.files))}catch(e){t&&y(j(e))}finally{n=!1}}}function i(){document.hidden||r()}r();let a=window.setInterval(i,le);return window.addEventListener(`focus`,i),()=>{t=!1,window.clearInterval(a),window.removeEventListener(`focus`,i)}},[e.machine,e.projectId,e.running,b]);let k=g??[],A=M(k,e=>M(e.hunks,e=>e.additionLines)),L=M(k,e=>M(e.hunks,e=>e.deletionLines));return(0,R.jsxs)(`div`,{className:`bg-background flex h-full min-h-0 min-w-0 flex-col`,children:[(0,R.jsxs)(`div`,{className:`border-border/60 bg-background flex h-(--workspace-topbar-height) shrink-0 items-center justify-between gap-2 border-b pr-3 pl-3`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,R.jsx)(h,{size:`icon-sm`,variant:`ghost`,title:`Close`,"aria-label":`Close`,onClick:e.onClose,children:(0,R.jsx)(m,{icon:p,className:`size-4`})}),(0,R.jsx)(`span`,{className:`text-foreground min-w-0 truncate text-xs font-medium`,children:`Uncommitted changes`})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[k.length>0&&(0,R.jsxs)(`span`,{className:`text-2xs mr-1 inline-flex items-center gap-1 font-mono tabular-nums`,children:[(0,R.jsxs)(`span`,{className:`text-diff-addition`,children:[`+`,A]}),(0,R.jsxs)(`span`,{className:`text-diff-deletion`,children:[`-`,L]})]}),(0,R.jsx)(h,{size:`icon-sm`,variant:`ghost`,title:`Refresh diff`,"aria-label":`Refresh diff`,onClick:()=>x(b+1),children:(0,R.jsx)(m,{icon:i,className:`size-4`})}),k.length>0&&(0,R.jsx)(h,{size:`icon-sm`,variant:`ghost`,title:C.collapsed?`Expand all files`:`Collapse all files`,onClick:()=>{E([]),O({collapsed:!C.collapsed})},children:(0,R.jsx)(m,{icon:C.collapsed?n:s,className:`size-4`})}),(0,R.jsxs)(`div`,{className:`bg-input/40 flex shrink-0 items-center rounded-lg p-0.5`,children:[(0,R.jsx)(`button`,{className:$,"aria-pressed":!C.split,"aria-label":`Stacked diff view`,onClick:()=>O({split:!1}),children:(0,R.jsx)(m,{icon:F,className:`size-3.5`})}),(0,R.jsx)(`button`,{className:$,"aria-pressed":C.split,"aria-label":`Split diff view`,onClick:()=>O({split:!0}),children:(0,R.jsx)(m,{icon:P,className:`size-3.5`})})]}),(0,R.jsx)(`button`,{className:ue,"aria-pressed":C.wrap,title:C.wrap?`Disable line wrapping`:`Enable line wrapping`,onClick:()=>O({wrap:!C.wrap}),children:(0,R.jsx)(m,{icon:o,className:`size-3.5`})})]})]}),(0,R.jsxs)(`div`,{className:`diff-render-surface min-h-0 flex-1 overflow-y-auto [--code-background:var(--background)]`,children:[v!==null&&(0,R.jsx)(`p`,{className:`text-muted-foreground p-4 text-center text-xs`,children:v}),v===null&&g===null&&(0,R.jsx)(`p`,{className:`text-muted-foreground p-4 text-center text-xs`,children:`Loading…`}),v===null&&g?.length===0&&(0,R.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,R.jsx)(m,{icon:N,className:`text-muted-foreground/40 size-8`}),(0,R.jsxs)(`div`,{className:`grid gap-1`,children:[(0,R.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`No uncommitted changes`}),(0,R.jsx)(`p`,{className:`text-muted-foreground/50 text-xs italic`,children:`If it works, don’t touch it.`})]})]}),v===null&&k.map(e=>{let n=C.collapsed!==T.includes(e.name);function r(){E(T.includes(e.name)?T.filter(t=>t!==e.name):[...T,e.name])}return(0,R.jsx)(`div`,{onClick:e=>{e.nativeEvent.composedPath().some(e=>e instanceof Element&&e.hasAttribute(`data-title`))&&r()},children:(0,R.jsx)(ce,{fileDiff:e,options:{theme:w,themeType:`dark`,unsafeCSS:`:host,
2
2
  [data-diffs-header],
3
3
  [data-diff],
4
4
  [data-file],