@michael-joseph-miller/ant-bot 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michael-joseph-miller/ant-bot",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Local-first daemon and web UI hosting persistent, named Claude agents.",
5
5
  "license": "MIT",
6
6
  "author": "Michael Miller",
@@ -127,4 +127,4 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
127
127
 
128
128
  `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=bn,s=!on.jitless,c=s&&xn.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Ri([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Vi(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=>!In(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=>Bn(e,r,sn())))}),t)}var Hi=M(`$ZodUnion`,(e,t)=>{F.init(e,t),N(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),N(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),N(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),N(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>fn(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=>Vi(t,r,e,i)):Vi(o,r,e,i)}}),Ui=M(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,Hi.init(e,t);let n=e._zod.parse;N(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=un(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!bn(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback||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()),input:o,path:[t.discriminator],inst:e}),i)}}),Wi=M(`$ZodIntersection`,(e,t)=>{F.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])=>Ki(e,t,n)):Ki(e,i,a)}});function Gi(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Sn(e)&&Sn(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Gi(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=Gi(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 Ki(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),In(e))return e;let o=Gi(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var qi=M(`$ZodRecord`,(e,t)=>{F.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Sn(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>Bn(e,r,sn())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...Rn(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...Rn(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Fr.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Bn(e,r,sn())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Rn(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Rn(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Ji=M(`$ZodEnum`,(e,t)=>{F.init(e,t);let n=cn(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>wn.has(typeof e)).map(e=>typeof e==`string`?Tn(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Yi=M(`$ZodLiteral`,(e,t)=>{if(F.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?Tn(e):e?Tn(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Xi=M(`$ZodTransform`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new an(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.fallback=!0,n));if(i instanceof Promise)throw new rn;return n.value=i,n.fallback=!0,n}});function Zi(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Qi=M(`$ZodOptional`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${fn(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>Zi(e,r)):Zi(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),$i=M(`$ZodExactOptional`,(e,t)=>{Qi.init(e,t),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),ea=M(`$ZodNullable`,(e,t)=>{F.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${fn(e.source)}|null)$`):void 0}),N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),ta=M(`$ZodDefault`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>na(e,t)):na(r,t)}});function na(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var ra=M(`$ZodPrefault`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),ia=M(`$ZodNonOptional`,(e,t)=>{F.init(e,t),N(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>aa(t,e)):aa(i,e)}});function aa(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var oa=M(`$ZodCatch`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Bn(e,n,sn()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Bn(e,n,sn()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),sa=M(`$ZodPipe`,(e,t)=>{F.init(e,t),N(e._zod,`values`,()=>t.in._zod.values),N(e._zod,`optin`,()=>t.in._zod.optin),N(e._zod,`optout`,()=>t.out._zod.optout),N(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>ca(e,t.in,n)):ca(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>ca(e,t.out,n)):ca(r,t.out,n)}});function ca(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var la=M(`$ZodReadonly`,(e,t)=>{F.init(e,t),N(e._zod,`propValues`,()=>t.innerType._zod.propValues),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`optin`,()=>t.innerType?._zod?.optin),N(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(ua):ua(r)}});function ua(e){return e.value=Object.freeze(e.value),e}var da=M(`$ZodCustom`,(e,t)=>{zr.init(e,t),F.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=>fa(t,n,r,e));fa(i,n,r,e)}});function fa(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(Hn(e))}}var pa,ma=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 ha(){return new ma}(pa=globalThis).__zod_globalRegistry??(pa.__zod_globalRegistry=ha());var ga=globalThis.__zod_globalRegistry;function _a(e,t){return new e({type:`string`,...P(t)})}function va(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...P(t)})}function ya(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...P(t)})}function ba(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...P(t)})}function xa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...P(t)})}function Sa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...P(t)})}function Ca(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...P(t)})}function wa(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...P(t)})}function Ta(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...P(t)})}function Ea(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...P(t)})}function Da(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...P(t)})}function Oa(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...P(t)})}function ka(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...P(t)})}function Aa(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...P(t)})}function ja(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...P(t)})}function Ma(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...P(t)})}function Na(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...P(t)})}function Pa(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...P(t)})}function Fa(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...P(t)})}function Ia(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...P(t)})}function La(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...P(t)})}function Ra(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...P(t)})}function za(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...P(t)})}function Ba(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...P(t)})}function Va(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...P(t)})}function Ha(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...P(t)})}function Ua(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...P(t)})}function Wa(e,t){return new e({type:`number`,checks:[],...P(t)})}function Ga(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...P(t)})}function Ka(e,t){return new e({type:`boolean`,...P(t)})}function qa(e){return new e({type:`unknown`})}function Ja(e,t){return new e({type:`never`,...P(t)})}function Ya(e,t){return new Vr({check:`less_than`,...P(t),value:e,inclusive:!1})}function Xa(e,t){return new Vr({check:`less_than`,...P(t),value:e,inclusive:!0})}function Za(e,t){return new Hr({check:`greater_than`,...P(t),value:e,inclusive:!1})}function Qa(e,t){return new Hr({check:`greater_than`,...P(t),value:e,inclusive:!0})}function $a(e,t){return new Ur({check:`multiple_of`,...P(t),value:e})}function eo(e,t){return new Gr({check:`max_length`,...P(t),maximum:e})}function to(e,t){return new Kr({check:`min_length`,...P(t),minimum:e})}function no(e,t){return new qr({check:`length_equals`,...P(t),length:e})}function ro(e,t){return new Yr({check:`string_format`,format:`regex`,...P(t),pattern:e})}function io(e){return new Xr({check:`string_format`,format:`lowercase`,...P(e)})}function ao(e){return new Zr({check:`string_format`,format:`uppercase`,...P(e)})}function oo(e,t){return new Qr({check:`string_format`,format:`includes`,...P(t),includes:e})}function so(e,t){return new $r({check:`string_format`,format:`starts_with`,...P(t),prefix:e})}function co(e,t){return new ei({check:`string_format`,format:`ends_with`,...P(t),suffix:e})}function lo(e){return new ti({check:`overwrite`,tx:e})}function uo(e){return lo(t=>t.normalize(e))}function fo(){return lo(e=>e.trim())}function po(){return lo(e=>e.toLowerCase())}function mo(){return lo(e=>e.toUpperCase())}function z(){return lo(e=>vn(e))}function B(e,t,n){return new e({type:`array`,element:t,...P(n)})}function ho(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...P(n)})}function go(e,t){let n=_o(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Hn(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(Hn(r))}},e(t.value,t)),t);return n}function _o(e,t){let n=new zr({check:`custom`,...P(t)});return n._zod.check=e,n}function vo(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??ga,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function yo(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,yo(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&So(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 bo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
129
129
 
130
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function xo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}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:wo(t,`input`,e.processors),output:wo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function So(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 So(r.element,n);if(r.type===`set`)return So(r.valueType,n);if(r.type===`lazy`)return So(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return So(r.innerType,n);if(r.type===`intersection`)return So(r.left,n)||So(r.right,n);if(r.type===`record`||r.type===`map`)return So(r.keyType,n)||So(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:So(r.in,n)||So(r.out,n);if(r.type===`object`){for(let e in r.shape)if(So(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(So(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(So(e,n))return!0;return!!(r.rest&&So(r.rest,n))}return!1}var Co=(e,t={})=>n=>{let r=vo({...n,processors:t});return yo(e,r),bo(r,e),xo(r,e)},wo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=vo({...i??{},target:a,io:t,processors:n});return yo(e,o),bo(o,e),xo(o,e)},To={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Eo=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=To[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Do=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},Oo=(e,t,n,r)=>{n.type=`boolean`},ko=(e,t,n,r)=>{n.not={}},Ao=(e,t,n,r)=>{let i=e._zod.def,a=cn(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},jo=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Mo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},No=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Po=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=yo(a.element,t,{...r,path:[...r.path,`items`]})},Fo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=yo(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=yo(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Io=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>yo(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Lo=(e,t,n,r)=>{let i=e._zod.def,a=yo(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=yo(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Ro=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=yo(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=yo(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=yo(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},zo=(e,t,n,r)=>{let i=e._zod.def,a=yo(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`}]},Bo=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Vo=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Ho=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Uo=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Wo=(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;yo(o,t,r);let s=t.seen.get(e);s.ref=o},Go=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Ko=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},qo=M(`ZodISODateTime`,(e,t)=>{gi.init(e,t),ys.init(e,t)});function Jo(e){return Ba(qo,e)}var Yo=M(`ZodISODate`,(e,t)=>{_i.init(e,t),ys.init(e,t)});function Xo(e){return Va(Yo,e)}var Zo=M(`ZodISOTime`,(e,t)=>{vi.init(e,t),ys.init(e,t)});function Qo(e){return Ha(Zo,e)}var $o=M(`ZodISODuration`,(e,t)=>{yi.init(e,t),ys.init(e,t)});function es(e){return Ua($o,e)}var ts=M(`ZodError`,(e,t)=>{Wn.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>qn(e,t)},flatten:{value:t=>Kn(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ln,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ln,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),ns=Jn(ts),rs=Yn(ts),is=Xn(ts),as=Qn(ts),os=er(ts),ss=tr(ts),cs=nr(ts),ls=rr(ts),us=ir(ts),ds=ar(ts),fs=or(ts),ps=sr(ts),ms=new WeakMap;function hs(e,t,n){let r=Object.getPrototypeOf(e),i=ms.get(r);if(i||(i=new Set,ms.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var gs=M(`ZodType`,(e,t)=>(F.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:wo(e,`input`),output:wo(e,`output`)}}),e.toJSONSchema=Co(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>ns(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>is(e,t,n),e.parseAsync=async(t,n)=>rs(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>as(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>os(e,t,n),e.decode=(t,n)=>ss(e,t,n),e.encodeAsync=async(t,n)=>cs(e,t,n),e.decodeAsync=async(t,n)=>ls(e,t,n),e.safeEncode=(t,n)=>us(e,t,n),e.safeDecode=(t,n)=>ds(e,t,n),e.safeEncodeAsync=async(t,n)=>fs(e,t,n),e.safeDecodeAsync=async(t,n)=>ps(e,t,n),hs(e,`ZodType`,{check(...e){let t=this.def;return this.clone(gn(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 En(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Oc(e,t))},superRefine(e,t){return this.check(kc(e,t))},overwrite(e){return this.check(lo(e))},optional(){return uc(this)},exactOptional(){return fc(this)},nullable(){return mc(this)},nullish(){return uc(mc(this))},nonoptional(e){return bc(this,e)},array(){return Ys(this)},or(e){return Qs([this,e])},and(e){return nc(this,e)},transform(e){return wc(this,cc(e))},default(e){return gc(this,e)},prefault(e){return vc(this,e)},catch(e){return Sc(this,e)},pipe(e){return wc(this,e)},readonly(){return Ec(this)},describe(e){let t=this.clone();return ga.add(t,{description:e}),t},meta(...e){if(e.length===0)return ga.get(this);let t=this.clone();return ga.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return ga.get(e)?.description},configurable:!0}),e)),_s=M(`_ZodString`,(e,t)=>{ii.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eo(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,hs(e,`_ZodString`,{regex(...e){return this.check(ro(...e))},includes(...e){return this.check(oo(...e))},startsWith(...e){return this.check(so(...e))},endsWith(...e){return this.check(co(...e))},min(...e){return this.check(to(...e))},max(...e){return this.check(eo(...e))},length(...e){return this.check(no(...e))},nonempty(...e){return this.check(to(1,...e))},lowercase(e){return this.check(io(e))},uppercase(e){return this.check(ao(e))},trim(){return this.check(fo())},normalize(...e){return this.check(uo(...e))},toLowerCase(){return this.check(po())},toUpperCase(){return this.check(mo())},slugify(){return this.check(z())}})}),vs=M(`ZodString`,(e,t)=>{ii.init(e,t),_s.init(e,t),e.email=t=>e.check(va(bs,t)),e.url=t=>e.check(wa(Cs,t)),e.jwt=t=>e.check(za(Rs,t)),e.emoji=t=>e.check(Ta(ws,t)),e.guid=t=>e.check(ya(xs,t)),e.uuid=t=>e.check(ba(Ss,t)),e.uuidv4=t=>e.check(xa(Ss,t)),e.uuidv6=t=>e.check(Sa(Ss,t)),e.uuidv7=t=>e.check(Ca(Ss,t)),e.nanoid=t=>e.check(Ea(Ts,t)),e.guid=t=>e.check(ya(xs,t)),e.cuid=t=>e.check(Da(Es,t)),e.cuid2=t=>e.check(Oa(Ds,t)),e.ulid=t=>e.check(ka(Os,t)),e.base64=t=>e.check(Ia(Fs,t)),e.base64url=t=>e.check(La(Is,t)),e.xid=t=>e.check(Aa(ks,t)),e.ksuid=t=>e.check(ja(As,t)),e.ipv4=t=>e.check(Ma(js,t)),e.ipv6=t=>e.check(Na(Ms,t)),e.cidrv4=t=>e.check(Pa(Ns,t)),e.cidrv6=t=>e.check(Fa(Ps,t)),e.e164=t=>e.check(Ra(Ls,t)),e.datetime=t=>e.check(Jo(t)),e.date=t=>e.check(Xo(t)),e.time=t=>e.check(Qo(t)),e.duration=t=>e.check(es(t))});function V(e){return _a(vs,e)}var ys=M(`ZodStringFormat`,(e,t)=>{I.init(e,t),_s.init(e,t)}),bs=M(`ZodEmail`,(e,t)=>{si.init(e,t),ys.init(e,t)}),xs=M(`ZodGUID`,(e,t)=>{ai.init(e,t),ys.init(e,t)}),Ss=M(`ZodUUID`,(e,t)=>{oi.init(e,t),ys.init(e,t)}),Cs=M(`ZodURL`,(e,t)=>{ci.init(e,t),ys.init(e,t)}),ws=M(`ZodEmoji`,(e,t)=>{li.init(e,t),ys.init(e,t)}),Ts=M(`ZodNanoID`,(e,t)=>{ui.init(e,t),ys.init(e,t)}),Es=M(`ZodCUID`,(e,t)=>{di.init(e,t),ys.init(e,t)}),Ds=M(`ZodCUID2`,(e,t)=>{fi.init(e,t),ys.init(e,t)}),Os=M(`ZodULID`,(e,t)=>{pi.init(e,t),ys.init(e,t)}),ks=M(`ZodXID`,(e,t)=>{mi.init(e,t),ys.init(e,t)}),As=M(`ZodKSUID`,(e,t)=>{hi.init(e,t),ys.init(e,t)}),js=M(`ZodIPv4`,(e,t)=>{bi.init(e,t),ys.init(e,t)}),Ms=M(`ZodIPv6`,(e,t)=>{xi.init(e,t),ys.init(e,t)}),Ns=M(`ZodCIDRv4`,(e,t)=>{Si.init(e,t),ys.init(e,t)}),Ps=M(`ZodCIDRv6`,(e,t)=>{Ci.init(e,t),ys.init(e,t)}),Fs=M(`ZodBase64`,(e,t)=>{Ti.init(e,t),ys.init(e,t)}),Is=M(`ZodBase64URL`,(e,t)=>{Di.init(e,t),ys.init(e,t)}),Ls=M(`ZodE164`,(e,t)=>{Oi.init(e,t),ys.init(e,t)}),Rs=M(`ZodJWT`,(e,t)=>{Ai.init(e,t),ys.init(e,t)}),zs=M(`ZodNumber`,(e,t)=>{ji.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Do(e,t,n,r),hs(e,`ZodNumber`,{gt(e,t){return this.check(Za(e,t))},gte(e,t){return this.check(Qa(e,t))},min(e,t){return this.check(Qa(e,t))},lt(e,t){return this.check(Ya(e,t))},lte(e,t){return this.check(Xa(e,t))},max(e,t){return this.check(Xa(e,t))},int(e){return this.check(Vs(e))},safe(e){return this.check(Vs(e))},positive(e){return this.check(Za(0,e))},nonnegative(e){return this.check(Qa(0,e))},negative(e){return this.check(Ya(0,e))},nonpositive(e){return this.check(Xa(0,e))},multipleOf(e,t){return this.check($a(e,t))},step(e,t){return this.check($a(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function H(e){return Wa(zs,e)}var Bs=M(`ZodNumberFormat`,(e,t)=>{Mi.init(e,t),zs.init(e,t)});function Vs(e){return Ga(Bs,e)}var Hs=M(`ZodBoolean`,(e,t)=>{Ni.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r)});function Us(e){return Ka(Hs,e)}var Ws=M(`ZodUnknown`,(e,t)=>{Pi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Gs(){return qa(Ws)}var Ks=M(`ZodNever`,(e,t)=>{Fi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ko(e,t,n,r)});function qs(e){return Ja(Ks,e)}var Js=M(`ZodArray`,(e,t)=>{R.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r),e.element=t.element,hs(e,`ZodArray`,{min(e,t){return this.check(to(e,t))},nonempty(e){return this.check(to(1,e))},max(e,t){return this.check(eo(e,t))},length(e,t){return this.check(no(e,t))},unwrap(){return this.element}})});function Ys(e,t){return B(Js,e,t)}var Xs=M(`ZodObject`,(e,t)=>{Bi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),N(e,`shape`,()=>t.shape),hs(e,`ZodObject`,{keyof(){return W(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Gs()})},loose(){return this.clone({...this._zod.def,catchall:Gs()})},strict(){return this.clone({...this._zod.def,catchall:qs()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return jn(this,e)},safeExtend(e){return Mn(this,e)},merge(e){return Nn(this,e)},pick(e){return kn(this,e)},omit(e){return An(this,e)},partial(...e){return Pn(lc,this,e[0])},required(...e){return Fn(yc,this,e[0])}})});function U(e,t){return new Xs({type:`object`,shape:e??{},...P(t)})}var Zs=M(`ZodUnion`,(e,t)=>{Hi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Io(e,t,n,r),e.options=t.options});function Qs(e,t){return new Zs({type:`union`,options:e,...P(t)})}var $s=M(`ZodDiscriminatedUnion`,(e,t)=>{Zs.init(e,t),Ui.init(e,t)});function ec(e,t,n){return new $s({type:`union`,options:t,discriminator:e,...P(n)})}var tc=M(`ZodIntersection`,(e,t)=>{Wi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r)});function nc(e,t){return new tc({type:`intersection`,left:e,right:t})}var rc=M(`ZodRecord`,(e,t)=>{qi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ro(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function ic(e,t,n){return!t||!t._zod?new rc({type:`record`,keyType:V(),valueType:e,...P(t)}):new rc({type:`record`,keyType:e,valueType:t,...P(n)})}var ac=M(`ZodEnum`,(e,t)=>{Ji.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new ac({...t,checks:[],...P(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 ac({...t,checks:[],...P(r),entries:i})}});function W(e,t){return new ac({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...P(t)})}var oc=M(`ZodLiteral`,(e,t)=>{Yi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(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 G(e,t){return new oc({type:`literal`,values:Array.isArray(e)?e:[e],...P(t)})}var sc=M(`ZodTransform`,(e,t)=>{Xi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new an(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Hn(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Hn(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function cc(e){return new sc({type:`transform`,transform:e})}var lc=M(`ZodOptional`,(e,t)=>{Qi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function uc(e){return new lc({type:`optional`,innerType:e})}var dc=M(`ZodExactOptional`,(e,t)=>{$i.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function fc(e){return new dc({type:`optional`,innerType:e})}var pc=M(`ZodNullable`,(e,t)=>{ea.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function mc(e){return new pc({type:`nullable`,innerType:e})}var hc=M(`ZodDefault`,(e,t)=>{ta.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function gc(e,t){return new hc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Cn(t)}})}var _c=M(`ZodPrefault`,(e,t)=>{ra.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ho(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function vc(e,t){return new _c({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Cn(t)}})}var yc=M(`ZodNonOptional`,(e,t)=>{ia.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function bc(e,t){return new yc({type:`nonoptional`,innerType:e,...P(t)})}var xc=M(`ZodCatch`,(e,t)=>{oa.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Sc(e,t){return new xc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Cc=M(`ZodPipe`,(e,t)=>{sa.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r),e.in=t.in,e.out=t.out});function wc(e,t){return new Cc({type:`pipe`,in:e,out:t})}var Tc=M(`ZodReadonly`,(e,t)=>{la.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ec(e){return new Tc({type:`readonly`,innerType:e})}var Dc=M(`ZodCustom`,(e,t)=>{da.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r)});function Oc(e,t={}){return ho(Dc,e,t)}function kc(e,t){return go(e,t)}var Ac=W([`idle`,`queued`,`running`,`waiting_approval`,`waiting_input`,`interrupted`]),jc=W([`none`,`unread`,`needs_attention`]),Mc=[`fable`,`opus`,`sonnet`,`haiku`],Nc=W(Mc);U({id:V(),slug:V().regex(/^[a-z0-9][a-z0-9-]*$/),name:V().min(1).max(60),title:V().max(120).default(``),description:V().max(8e3).default(``),avatarEmoji:V().max(8).default(`🤖`),modelTier:Nc.default(`sonnet`),pinned:Us().default(!1),hidden:Us().default(!1),notifications:Us().default(!0),sessionId:V().nullable().default(null),state:Ac.default(`idle`),attention:jc.default(`none`),threadId:V().nullable().default(null),createdAt:H(),deletedAt:H().nullable().default(null)});var Pc=W([`dm`,`group`]);U({id:V(),kind:Pc,title:V().default(``),memberBotIds:Ys(V()).default([]),pinned:Us().default(!1),hidden:Us().default(!1),lastReadAt:H().default(0),createdAt:H()});var Fc=ec(`type`,[U({type:G(`tool`),toolName:V(),summary:V(),input:Gs().optional(),result:V().optional(),status:W([`running`,`ok`,`error`,`denied`])}),U({type:G(`file`),path:V(),name:V(),mime:V(),bytes:H(),action:W([`created`,`modified`]).default(`created`)}),U({type:G(`approval`),approvalId:V()}),U({type:G(`handoff`),fromBotId:V(),toBotId:V(),note:V()}),U({type:G(`error`),message:V()})]),Ic=W([`user`,`bot`,`system`]),Lc=U({id:V(),threadId:V(),authorKind:Ic,authorBotId:V().nullable().default(null),replyToId:V().nullable().default(null),contentMd:V().default(``),cards:Ys(Fc).default([]),streaming:Us().default(!1),createdAt:H()});U({id:V(),messageId:V().nullable(),path:V(),name:V(),mime:V(),bytes:H(),createdAt:H()});var Rc=W([`pending`,`allowed`,`denied`,`expired`]),zc=U({id:V(),botId:V(),threadId:V(),toolName:V(),inputSummary:V(),rawInput:Gs(),status:Rc.default(`pending`),decidedBy:W([`user`,`rule`,`auto_review`]).nullable().default(null),reason:V().default(``),ruleId:V().nullable().default(null),createdAt:H(),decidedAt:H().nullable().default(null)}),Bc=W([`require`,`allow`]);U({id:V(),kind:Bc,toolPattern:V().default(`*`),inputPattern:V().default(``),scopeNote:V().default(``),builtin:Us().default(!1),enabled:Us().default(!0),createdAt:H()}),U({id:V(),slug:V(),name:V(),description:V().default(``),path:V(),source:W([`user`,`taught`,`imported`]).default(`user`),createdAt:H()});var Vc=/^[a-z0-9][a-z0-9-]{0,31}$/,Hc=[`antbot`,`browser`],Uc=ec(`transport`,[U({transport:G(`stdio`),command:V().min(1),args:Ys(V()).default([]),env:ic(V(),V()).default({})}),U({transport:G(`http`),url:V().url(),headers:ic(V(),V()).default({}),tools:Ys(V()).optional()}),U({transport:G(`sse`),url:V().url(),headers:ic(V(),V()).default({}),tools:Ys(V()).optional()})]),Wc=U({id:V(),name:V().regex(Vc,`lowercase letters, digits and hyphens only, max 32 characters`).refine(e=>!Hc.includes(e),{message:`"antbot" and "browser" are reserved for the built-in servers`}),description:V().default(``),enabled:Us().default(!0),config:Uc,createdAt:H()});U({id:V(),botId:V(),name:V().min(1),cronExpr:V(),timezone:V().default(`UTC`),instructionMd:V(),enabled:Us().default(!0),lastRunAt:H().nullable().default(null),nextRunAt:H().nullable().default(null),createdAt:H()});var Gc=U({id:V(),routineId:V(),startedAt:H(),finishedAt:H().nullable().default(null),status:W([`running`,`ok`,`failed`,`interrupted`]),summary:V().default(``),threadId:V().nullable().default(null),isTest:Us().default(!1)});U({id:V(),fromBotId:V(),toBotId:V(),contentMd:V(),hops:H().default(1),delivered:Us().default(!1),createdAt:H()}),U({id:V(),botId:V(),turnId:V(),model:V(),inputTokens:H().default(0),outputTokens:H().default(0),cacheReadTokens:H().default(0),costEstimate:H().default(0),createdAt:H()}),W([`user`,`bot`,`routine`,`system`]);var Kc={seq:H(),threadId:V().nullable(),botId:V().nullable()};ec(`type`,[U({...Kc,type:G(`hello`)}),U({...Kc,type:G(`message.created`),message:Lc}),U({...Kc,type:G(`message.delta`),messageId:V(),delta:V()}),U({...Kc,type:G(`message.done`),messageId:V(),contentMd:V()}),U({...Kc,type:G(`message.card`),messageId:V(),card:Fc,cardIndex:H()}),U({...Kc,type:G(`bot.state`),state:Ac,attention:jc}),U({...Kc,type:G(`approval.pending`),approval:zc}),U({...Kc,type:G(`approval.resolved`),approval:zc}),U({...Kc,type:G(`routine.run`),run:Gc}),U({...Kc,type:G(`usage.tick`),inputTokens:H(),outputTokens:H(),model:V()}),U({...Kc,type:G(`notify`),title:V(),body:V(),level:W([`info`,`warn`,`error`])}),U({...Kc,type:G(`secret.request`),requestId:V(),name:V(),reason:V()}),U({...Kc,type:G(`thread.updated`),threadId2:V()})]);var qc=ec(`kind`,[U({kind:G(`mouse`),action:W([`move`,`down`,`up`,`wheel`]),x:H().min(0).max(1),y:H().min(0).max(1),button:W([`left`,`middle`,`right`]).default(`left`),clickCount:H().int().min(0).max(3).default(1),deltaX:H().default(0),deltaY:H().default(0)}),U({kind:G(`key`),action:W([`down`,`up`]),key:V().min(1).max(32)}),U({kind:G(`text`),text:V().min(1).max(4096)})]);ec(`type`,[U({type:G(`input`),input:qc}),U({type:G(`selection-request`)})]),U({name:V().min(1).max(60),title:V().max(120).optional(),description:V().max(8e3).optional(),avatarEmoji:V().max(8).optional(),modelTier:Nc.optional()}).partial().extend({pinned:Us().optional(),hidden:Us().optional(),notifications:Us().optional()}),U({kind:W([`dm`,`group`]),title:V().optional(),memberBotIds:Ys(V())}),U({contentMd:V(),attachmentIds:Ys(V()).optional(),replyToId:V().nullable().optional(),mentionBotIds:Ys(V()).optional(),mentionEveryone:Us().optional()}),U({decision:W([`allow`,`deny`]),alwaysRule:U({toolPattern:V(),inputPattern:V().default(``),scopeNote:V().default(``)}).optional()}),U({kind:W([`require`,`allow`]),toolPattern:V().min(1),inputPattern:V().default(``),scopeNote:V().default(``)}),U({botId:V(),name:V().min(1),cronExpr:V().min(1),timezone:V().optional(),instructionMd:V().min(1),enabled:Us().optional()}),U({name:V().min(1),description:V().default(``),bodyMd:V().min(1),source:W([`user`,`taught`,`imported`]).optional()}),U({name:Wc.shape.name,description:V().default(``),config:Uc,enabled:Us().optional()}),U({description:V().optional(),config:Uc.optional(),enabled:Us().optional()});var Jc={timezone:V(),maxConcurrentSessions:H().min(1).max(8),autoReviewEnabled:Us(),theme:W([`system`,`light`,`dark`]),localExecution:W([`ask`,`always`,`never`]),dailyTokenBudget:H(),notificationsEnabled:Us(),billingMode:W([`subscription`,`api`]),computerMode:W([`host`,`container`])};U({timezone:Jc.timezone.default(`UTC`),maxConcurrentSessions:Jc.maxConcurrentSessions.default(2),autoReviewEnabled:Jc.autoReviewEnabled.default(!0),theme:Jc.theme.default(`system`),localExecution:Jc.localExecution.default(`ask`),dailyTokenBudget:Jc.dailyTokenBudget.default(0),notificationsEnabled:Jc.notificationsEnabled.default(!0),billingMode:Jc.billingMode.default(`subscription`),computerMode:Jc.computerMode.default(`host`)}),U(Jc).partial(),U({kind:W([`message`,`file`,`routine`,`bot`]),id:V(),threadId:V().nullable(),botId:V().nullable(),title:V(),snippet:V(),createdAt:H()});var Yc=tn.MAX_ATTACHMENTS_PER_MESSAGE;function Xc(e,t){let n=e.slice(0,t),r=/(^|\s)([@/])([\w-]*)$/.exec(n);if(!r)return null;let i=r[2];return i===`/`&&n.trim()!==`/${r[3]}`?null:{prefix:i,query:r[3],start:t-r[3].length-1}}function Zc({onSend:e,bots:t,skills:n,running:r,onStop:i,uploadFile:a}){let[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(null),f=(0,_.useRef)(null),p=(0,_.useRef)(null),m=(0,_.useRef)(0);(0,_.useEffect)(()=>{m.current=c.length},[c.length]);let h=(0,_.useMemo)(()=>a??(e=>T.attachments.upload(e)),[a]),g=(0,_.useMemo)(()=>{if(!u||u.prefix!==`@`)return[];let e=u.query.toLowerCase();return t.filter(t=>t.bot.name.toLowerCase().includes(e)||t.bot.slug.toLowerCase().includes(e)).slice(0,8)},[u,t]),v=(0,_.useMemo)(()=>{if(!u||u.prefix!==`/`)return[];let e=u.query.toLowerCase();return n.filter(t=>t.slug.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)).slice(0,8)},[u,n]);function y(e){let t=Array.from(e),n=Math.max(0,Yc-m.current),r=t.slice(0,n);m.current=Math.min(Yc,m.current+r.length);for(let e of r)h(e).then(e=>{l(t=>t.length>=Yc?t:[...t,e])}).catch(()=>{m.current=Math.max(0,m.current-1)})}function b(e){l(t=>t.filter(t=>t.id!==e))}function x(){let t=o.trim();t&&(e(t,c.map(e=>e.id)),s(``),l([]),d(null))}function ee(e,t){s(e),d(Xc(e,t))}function te(e){e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),x()):e.key===`Escape`&&d(null)}function S(e){if(!u)return;let t=p.current,n=t?t.selectionStart:o.length,r=o.slice(0,u.start),i=o.slice(n),a=u.prefix===`@`?`@${e} `:`/${e} `,c=`${r}${a}${i}`;s(c),d(null),requestAnimationFrame(()=>{t?.focus();let e=r.length+a.length;t?.setSelectionRange(e,e)})}function ne(e){let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);t.length>0&&(e.preventDefault(),y(t))}function re(e){e.preventDefault(),e.dataTransfer.files.length>0&&y(e.dataTransfer.files)}return(0,O.jsxs)(`div`,{className:`shrink-0 border-t border-(--color-border) bg-(--color-bg-elevated) p-3`,onDrop:re,onDragOver:e=>e.preventDefault(),children:[c.length>0&&(0,O.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:c.map(e=>(0,O.jsxs)(`span`,{"data-testid":`attachment-chip`,className:`flex items-center gap-1.5 rounded-full border border-(--color-border) bg-(--color-bg) px-2.5 py-1 text-xs`,children:[e.name,(0,O.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,className:`text-(--color-text-muted) hover:text-(--color-red)`,onClick:()=>b(e.id),children:`×`})]},e.id))}),u&&(g.length>0||v.length>0)&&(0,O.jsx)(`div`,{className:`mb-2 max-h-40 overflow-auto rounded border border-(--color-border) bg-(--color-bg) text-sm shadow-lg`,children:u.prefix===`@`?g.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-(--color-bg-hover)`,onClick:()=>S(e.bot.slug),children:[(0,O.jsx)(`span`,{children:e.bot.avatarEmoji}),(0,O.jsx)(`span`,{children:e.bot.name})]},e.bot.id)):v.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-(--color-bg-hover)`,onClick:()=>S(e.slug),children:[(0,O.jsxs)(`span`,{className:`shrink-0 font-mono text-(--color-text-muted)`,children:[`/`,e.slug]}),(0,O.jsx)(`span`,{className:`min-w-0 truncate text-(--color-text-muted)`,title:e.description,children:e.description})]},e.id))}),(0,O.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,"aria-label":`Attach files`,className:`shrink-0 rounded border border-(--color-border) px-2.5 py-2 text-sm hover:bg-(--color-bg-hover)`,onClick:()=>f.current?.click(),children:`+`}),(0,O.jsx)(`input`,{ref:f,"data-testid":`attachment-input`,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files&&y(e.target.files),e.target.value=``}}),(0,O.jsx)(`textarea`,{ref:p,value:o,rows:1,placeholder:`Message… (@ to mention, / for a skill)`,className:`max-h-40 min-h-[38px] flex-1 resize-none rounded border border-(--color-border) bg-(--color-bg) px-3 py-2 text-sm outline-none focus:border-(--color-accent)`,onChange:e=>ee(e.target.value,e.target.selectionStart),onKeyDown:te,onPaste:ne}),r&&(0,O.jsx)(`button`,{type:`button`,onClick:i,className:`shrink-0 rounded border border-(--color-red) px-3 py-2 text-sm font-medium text-(--color-red) hover:bg-(--color-red)/10`,children:`Stop`}),(0,O.jsx)(`button`,{type:`button`,onClick:x,disabled:!o.trim(),className:`shrink-0 rounded bg-(--color-accent) px-3 py-2 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Send`})]})]})}j.setOptions({breaks:!0});function Qc(e){return j.parse(e,{async:!1}).replace(/<script[\s\S]*?<\/script>/gi,``)}function $c(e,t){if(e.authorKind===`user`)return{name:`You`,emoji:`🧑`};if(e.authorKind===`system`)return{name:`System`,emoji:`⚙️`};let n=e.authorBotId?t[e.authorBotId]?.bot:void 0;return{name:n?.name??`Bot`,emoji:n?.avatarEmoji??`🤖`}}function el({message:e,botsById:t}){let{name:n,emoji:r}=$c(e,t),i=e.authorKind===`user`;return(0,O.jsxs)(`div`,{className:b(`flex gap-3 px-4 py-2`,i&&`flex-row-reverse`),children:[(0,O.jsx)(`span`,{className:`mt-0.5 text-lg leading-none`,children:r}),(0,O.jsxs)(`div`,{className:b(`min-w-0 max-w-[75%]`,i&&`items-end text-right`),children:[(0,O.jsxs)(`div`,{className:b(`mb-0.5 flex items-baseline gap-2`,i&&`flex-row-reverse`),children:[(0,O.jsx)(`span`,{className:`text-xs font-semibold text-(--color-text-muted)`,children:n}),(0,O.jsx)(`span`,{className:`text-[11px] text-(--color-text-faint)`,children:new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),e.contentMd&&(0,O.jsxs)(`div`,{className:b(`markdown-body inline-block rounded-lg px-3 py-2 text-sm`,i?`bg-(--color-accent) text-(--color-accent-fg)`:`bg-(--color-bg-elevated)`),children:[(0,O.jsx)(`span`,{dangerouslySetInnerHTML:{__html:Qc(e.contentMd)}}),e.streaming&&(0,O.jsx)(`span`,{className:`ml-0.5 inline-block w-1.5 animate-pulse bg-current align-middle`,children:`\xA0`})]}),(0,O.jsx)(en,{cards:e.cards})]})]})}function tl({thread:e,messages:t,botsById:n,bots:r,skills:i,running:a,onSend:o,onStop:s}){let c=(0,_.useRef)(null),[l,u]=(0,_.useState)(!0);(0,_.useEffect)(()=>{if(!l)return;let e=()=>{let e=c.current;e&&(e.scrollTop=e.scrollHeight)};e();let t=requestAnimationFrame(()=>{e(),requestAnimationFrame(e)});return()=>cancelAnimationFrame(t)},[t,l]);function d(){let e=c.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;u(t<80)}return e?(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,O.jsx)(`div`,{ref:c,onScroll:d,className:`min-h-0 flex-1 overflow-y-auto py-2`,children:t.length===0?(0,O.jsx)(`p`,{className:`px-4 py-8 text-center text-sm text-(--color-text-muted)`,children:`No messages yet — say hello and give this bot a job.`}):t.map(e=>(0,O.jsx)(el,{message:e,botsById:n},e.id))}),(0,O.jsx)(Zc,{onSend:o,bots:r,skills:i,running:a,onStop:s})]}):(0,O.jsx)(`div`,{className:`flex h-full flex-1 flex-col items-center justify-center text-(--color-text-muted)`,children:(0,O.jsx)(`p`,{className:`text-sm`,children:`Select a bot to start a conversation, or create a new one.`})})}var nl=`🤖.🧠.🦾.🛰️.🧭.🗂️.📚.🔍.🧮.🧰.🛠️.⚙️.🧪.🧬.📈.📊.💡.🗒️.✍️.📝.📅.⏰.📬.📡.🌐.🔐.🗝️.🧯.🚀.🛎️.🎯.🧵.🧩.🕵️.🧑‍💻.👩‍💻.🧑‍🔬.🐜.🐝.🦉`.split(`.`);function rl({onCreate:e,onClose:t,busy:n,error:r}){let[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(`🤖`),[f,p]=(0,_.useState)(`sonnet`);function m(){i.trim()&&e({name:i.trim(),title:o.trim(),description:c.trim(),avatarEmoji:u,modelTier:f})}return(0,O.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,O.jsxs)(`div`,{className:`w-full max-w-md rounded-lg border border-(--color-border) bg-(--color-bg-elevated) p-5 shadow-xl`,children:[(0,O.jsx)(`h2`,{className:`mb-4 text-base font-semibold`,children:`New bot`}),(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,O.jsx)(`div`,{className:`grid grid-cols-8 gap-1 rounded border border-(--color-border) p-1.5`,children:nl.slice(0,16).map(e=>(0,O.jsx)(`button`,{type:`button`,"aria-pressed":u===e,onClick:()=>d(e),className:`rounded p-1 text-lg ${u===e?`bg-(--color-accent)/25`:`hover:bg-(--color-bg-hover)`}`,children:e},e))})}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Name`}),(0,O.jsx)(`input`,{autoFocus:!0,className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,value:i,onChange:e=>a(e.target.value),placeholder:`Scout`})]}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Title`}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,value:o,onChange:e=>s(e.target.value),placeholder:`Research assistant`})]}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Description`}),(0,O.jsx)(`textarea`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,rows:3,value:c,onChange:e=>l(e.target.value),placeholder:`What should this bot do?`})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:`mb-1 block text-xs text-(--color-text-muted)`,children:`Model tier`}),(0,O.jsx)(`div`,{className:`inline-flex rounded border border-(--color-border) p-0.5`,children:Mc.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>p(e),className:`rounded px-3 py-1 text-xs font-medium capitalize ${f===e?`bg-(--color-accent) text-(--color-accent-fg)`:`text-(--color-text-muted)`}`,children:e},e))})]}),(0,O.jsx)(`p`,{className:`rounded border border-(--color-amber)/40 bg-(--color-amber)/10 p-2 text-xs text-(--color-amber)`,children:`Bots share one computer, workspace, browser profile and logins. Bots are not a security boundary.`}),r&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:r})]}),(0,O.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-sm text-(--color-text-muted) hover:bg-(--color-bg-hover)`,children:`Cancel`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,disabled:!i.trim()||n,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Create bot`})]})]})})}var il={running:`text-(--color-blue)`,ok:`text-(--color-green)`,failed:`text-(--color-red)`,interrupted:`text-(--color-amber)`};function al({botId:e,onCreated:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(`0 9 * * *`),[o,s]=(0,_.useState)(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null);async function m(){if(!(!n.trim()||!i.trim()||!c.trim())){d(!0),p(null);try{t(await T.routines.create({botId:e,name:n,cronExpr:i,timezone:o,instructionMd:c})),r(``),l(``)}catch(e){p(e instanceof ie?e.message:`Failed to create routine`)}finally{d(!1)}}}return(0,O.jsxs)(`div`,{className:`space-y-2 rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs font-semibold text-(--color-text-muted)`,children:`New routine`}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Name`,value:n,onChange:e=>r(e.target.value)}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`input`,{className:`flex-1 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 font-mono text-sm`,placeholder:`Cron expression (e.g. 0 9 * * *)`,value:i,onChange:e=>a(e.target.value)}),(0,O.jsx)(`input`,{className:`w-40 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Timezone`,value:o,onChange:e=>s(e.target.value)})]}),(0,O.jsx)(`textarea`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Instructions for this run…`,rows:3,value:c,onChange:e=>l(e.target.value)}),f&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:f}),(0,O.jsx)(`button`,{type:`button`,disabled:u,onClick:m,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Create routine`})]})}function ol({routine:e,onChanged:t,onDeleted:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1);async function d(){let t=await T.routines.runs(e.id);i(t.slice(0,20))}async function f(){let e=!a;o(e),e&&await d()}async function p(){t(await T.routines.update(e.id,{enabled:!e.enabled}))}async function m(){window.confirm(`Delete routine "${e.name}"?`)&&(await T.routines.remove(e.id),n(e.id))}async function h(){u(!0),c(!1);try{await T.routines.testRun(e.id),await d(),o(!0)}finally{u(!1)}}return(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`div`,{className:`text-sm font-medium`,children:e.name}),(0,O.jsxs)(`div`,{className:`font-mono text-xs text-(--color-text-muted)`,children:[e.cronExpr,` · `,e.timezone]}),e.nextRunAt&&(0,O.jsxs)(`div`,{className:`text-xs text-(--color-text-faint)`,children:[`Next run: `,new Date(e.nextRunAt).toLocaleString()]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:p}),`Enabled`]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(!0),disabled:l,className:`rounded border border-(--color-border) px-2 py-1 text-xs hover:bg-(--color-bg-hover)`,children:`Test run`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,className:`rounded border border-(--color-red)/50 px-2 py-1 text-xs text-(--color-red)`,children:`Delete`})]})]}),s&&(0,O.jsxs)(`div`,{className:`mt-2 rounded border border-(--color-amber)/50 bg-(--color-amber)/10 p-2 text-xs`,children:[(0,O.jsx)(`p`,{className:`text-(--color-amber)`,children:`A test run performs real work — it can navigate websites, change files and call connected tools.`}),(0,O.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:h,className:`rounded bg-(--color-amber) px-2 py-1 font-medium text-(--color-bg)`,children:`Run anyway`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded px-2 py-1 text-(--color-text-muted)`,children:`Cancel`})]})]}),(0,O.jsx)(`button`,{type:`button`,onClick:f,className:`mt-2 text-xs text-(--color-text-muted) hover:underline`,children:a?`Hide run history`:`Show run history`}),a&&(0,O.jsxs)(`ul`,{className:`mt-1 space-y-1`,children:[r.length===0&&(0,O.jsx)(`li`,{className:`text-xs text-(--color-text-faint)`,children:`No runs yet.`}),r.map(e=>(0,O.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,O.jsx)(`span`,{className:b(`font-medium`,il[e.status]),children:e.status}),(0,O.jsx)(`span`,{className:`text-(--color-text-faint)`,children:new Date(e.startedAt).toLocaleString()}),e.isTest&&(0,O.jsx)(`span`,{className:`rounded bg-(--color-border) px-1 text-[10px]`,children:`test`}),e.summary&&(0,O.jsx)(`span`,{className:`truncate text-(--color-text-muted)`,children:e.summary})]},e.id))]})]})}function sl({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{let t=!1;return i(!0),T.routines.list(e).then(e=>{t||n(e)}).finally(()=>{t||i(!1)}),()=>{t=!0}},[e]),(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsx)(al,{botId:e,onCreated:e=>n(t=>[e,...t])}),r&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`Loading routines…`}),!r&&t.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No routines yet.`}),t.map(e=>(0,O.jsx)(ol,{routine:e,onChanged:e=>n(t=>t.map(t=>t.id===e.id?e:t)),onDeleted:e=>n(t=>t.filter(t=>t.id!==e))},e.id))]})}function cl({bot:e,onUpdated:t}){let[n,r]=(0,_.useState)(e.name),[i,a]=(0,_.useState)(e.title),[o,s]=(0,_.useState)(e.description),[c,l]=(0,_.useState)(e.avatarEmoji),[u,d]=(0,_.useState)(e.modelTier),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1);async function y(){p(!0),h(null);try{t(await T.bots.update(e.id,{name:n,title:i,description:o,avatarEmoji:c,modelTier:u}))}catch(e){h(e instanceof ie?e.message:`Failed to save`)}finally{p(!1)}}return(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`flex h-12 w-12 items-center justify-center rounded-lg border border-(--color-border) text-2xl hover:bg-(--color-bg-hover)`,children:c}),(0,O.jsx)(`div`,{className:`flex-1`,children:(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm font-medium`,value:n,onChange:e=>r(e.target.value),"aria-label":`Name`})})]}),g&&(0,O.jsx)(`div`,{className:`grid grid-cols-10 gap-1 rounded border border-(--color-border) p-2`,children:nl.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>{l(e),v(!1)},className:`rounded p-1 text-lg hover:bg-(--color-bg-hover)`,children:e},e))}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Title`}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,value:i,onChange:e=>a(e.target.value)})]}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Description / persona`}),(0,O.jsx)(`textarea`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,rows:4,value:o,onChange:e=>s(e.target.value)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:`mb-1 block text-xs text-(--color-text-muted)`,children:`Model tier`}),(0,O.jsx)(`div`,{className:`inline-flex rounded border border-(--color-border) p-0.5`,children:Mc.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`rounded px-3 py-1 text-xs font-medium capitalize ${u===e?`bg-(--color-accent) text-(--color-accent-fg)`:`text-(--color-text-muted)`}`,children:e},e))})]}),m&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:m}),(0,O.jsx)(`button`,{type:`button`,onClick:y,disabled:f,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Save profile`})]})}function ll({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``);(0,_.useEffect)(()=>{T.bots.memory.list(e).then(n)},[e]);function l(e){i(e),o(t.find(t=>t.name===e)?.content??``)}async function u(){let t=r??s.trim();t&&(await T.bots.memory.save(e,t,a),n(e=>{let n=e.findIndex(e=>e.name===t);return n===-1?[...e,{name:t,content:a}]:e.map((e,r)=>r===n?{name:t,content:a}:e)}),i(t),c(``))}async function d(t){await T.bots.memory.remove(e,t),n(e=>e.filter(e=>e.name!==t)),r===t&&(i(null),o(``))}return(0,O.jsxs)(`div`,{className:`grid grid-cols-[160px_1fr] gap-3`,children:[(0,O.jsxs)(`div`,{className:`space-y-1`,children:[t.map(e=>(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>l(e.name),className:`flex-1 truncate rounded px-2 py-1 text-left text-xs ${r===e.name?`bg-(--color-accent)/15`:`hover:bg-(--color-bg-hover)`}`,children:e.name}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>d(e.name),"aria-label":`Delete ${e.name}`,className:`text-xs text-(--color-text-faint) hover:text-(--color-red)`,children:`×`})]},e.name)),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,placeholder:`new-file.md`,value:s,onChange:e=>{c(e.target.value),i(null),o(``)}})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`textarea`,{className:`h-40 w-full rounded border border-(--color-border) bg-(--color-bg) p-2 font-mono text-xs`,value:a,onChange:e=>o(e.target.value),placeholder:`Durable facts this bot should remember…`}),(0,O.jsx)(`button`,{type:`button`,onClick:u,className:`mt-2 rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Save memory file`})]})]})}function ul({skill:e,checked:t,onToggle:n}){let[r,i]=(0,_.useState)(!1),a=`skill-${e.id}`;return(0,O.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,O.jsx)(`input`,{id:a,type:`checkbox`,className:`mt-1 shrink-0`,checked:t,onChange:n}),(0,O.jsx)(`label`,{htmlFor:a,className:`shrink-0 cursor-pointer whitespace-nowrap font-medium`,children:e.name}),e.description&&(0,O.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,title:r?`Collapse description`:`Show the full description`,className:`min-w-0 flex-1 cursor-pointer text-left text-xs text-(--color-text-muted) hover:text-(--color-text) ${r?`whitespace-pre-wrap break-words`:`truncate`}`,children:[`— `,e.description]})]})}function dl({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(new Set),[a,o]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T.connectors.list().then(n)},[]),(0,_.useEffect)(()=>{T.bots.connectors.get(e).then(e=>i(new Set(e.map(e=>e.id))))},[e]);function s(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o(!1)}async function c(){await T.bots.connectors.set(e,Array.from(r)),o(!0)}return t.length===0?(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No connectors yet. Add one on the Connectors screen.`}):(0,O.jsxs)(`div`,{className:`space-y-2`,children:[t.map(e=>(0,O.jsxs)(`label`,{className:`flex items-start gap-2 text-xs`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:r.has(e.id),onChange:()=>s(e.id),className:`mt-0.5`}),(0,O.jsxs)(`span`,{className:`min-w-0`,children:[(0,O.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,O.jsx)(`span`,{className:`ml-1 text-(--color-text-muted)`,children:String(e.config.transport)}),!e.enabled&&(0,O.jsx)(`span`,{className:`ml-1 text-(--color-text-muted)`,children:`(disabled)`}),e.missingSecrets.length>0&&(0,O.jsxs)(`span`,{className:`ml-1 text-(--color-amber)`,children:[`missing secret: `,e.missingSecrets.join(`, `)]}),e.description&&(0,O.jsx)(`span`,{className:`block truncate text-(--color-text-muted)`,title:e.description,children:e.description})]})]},e.id)),(0,O.jsx)(`button`,{type:`button`,onClick:c,className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Save connectors`}),a&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-green)`,children:`Saved`})]})}function fl({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(new Set),[a,o]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T.skills.list().then(n)},[]),(0,_.useEffect)(()=>{T.bots.skills.get(e).then(e=>i(new Set(e.map(e=>e.id))))},[e]);function s(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o(!1)}async function c(){await T.bots.skills.set(e,Array.from(r)),o(!0)}return t.length===0?(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No skills taught yet.`}):(0,O.jsxs)(`div`,{className:`space-y-2`,children:[t.map(e=>(0,O.jsx)(ul,{skill:e,checked:r.has(e.id),onToggle:()=>s(e.id)},e.id)),(0,O.jsx)(`button`,{type:`button`,onClick:c,className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Save skills`}),a&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-green)`,children:`Saved`})]})}function pl({bot:e,onClose:t,onUpdated:n,onDuplicated:r,onDeleted:i}){let[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(null);async function d(){n(await T.bots.update(e.id,{pinned:!e.pinned}))}async function f(){n(await T.bots.update(e.id,{hidden:!e.hidden}))}async function p(){n(await T.bots.update(e.id,{notifications:!e.notifications}))}async function m(){r(await T.bots.duplicate(e.id))}async function h(){await T.bots.remove(e.id),i(e.id)}return(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto p-5`,children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,O.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e.name,` settings`]}),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`text-sm text-(--color-text-muted) hover:text-(--color-text)`,children:`Close`})]}),(0,O.jsx)(`section`,{className:`mb-6`,children:(0,O.jsx)(cl,{bot:e,onUpdated:n})}),(0,O.jsxs)(`section`,{className:`mb-6 flex flex-wrap gap-2 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:d,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:e.pinned?`Unpin`:`Pin`}),(0,O.jsx)(`button`,{type:`button`,onClick:f,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:e.hidden?`Unhide`:`Hide`}),(0,O.jsx)(`button`,{type:`button`,onClick:p,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:e.notifications?`Mute notifications`:`Unmute notifications`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:`Duplicate`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(!0),className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:`Start fresh`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>o(!0),className:`rounded border border-(--color-red)/50 px-3 py-1.5 text-xs text-(--color-red) hover:bg-(--color-red)/10`,children:`Delete`})]}),s&&(0,O.jsxs)(`div`,{className:`mb-6 rounded border border-(--color-border) bg-(--color-bg-elevated) p-3 text-sm`,children:[(0,O.jsx)(`p`,{className:`mb-1`,children:`Clear this conversation and start a fresh session?`}),(0,O.jsx)(`p`,{className:`mb-2 text-xs text-(--color-text-muted)`,children:`Deletes the messages in this thread and drops the model’s accumulated context. Keeps the Bot’s description, memory, skills, connectors, routines and files.`}),l&&(0,O.jsx)(`p`,{className:`mb-2 text-xs text-(--color-red)`,children:l}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:async()=>{u(null);try{await T.bots.reset(e.id),c(!1),n(e)}catch(e){u(e instanceof ie?e.message:`Could not start fresh`)}},className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Start fresh`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>{c(!1),u(null)},className:`rounded border border-(--color-border) px-3 py-1.5 text-xs`,children:`Cancel`})]})]}),a&&(0,O.jsxs)(`div`,{className:`mb-6 rounded border border-(--color-red)/50 bg-(--color-red)/10 p-3 text-sm`,children:[(0,O.jsxs)(`p`,{className:`text-(--color-red)`,children:[`Delete `,e.name,`? This removes it from your roster and conversation history, but its workspace files and any browser logins it used survive deletion.`]}),(0,O.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:h,className:`rounded bg-(--color-red) px-3 py-1.5 text-xs font-medium text-white`,children:`Delete permanently`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`rounded px-3 py-1.5 text-xs text-(--color-text-muted)`,children:`Cancel`})]})]}),(0,O.jsxs)(`section`,{className:`mb-6 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Memory`}),(0,O.jsx)(ll,{botId:e.id})]}),(0,O.jsxs)(`section`,{className:`mb-6 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Skills`}),(0,O.jsx)(fl,{botId:e.id})]}),(0,O.jsxs)(`section`,{className:`mb-6 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Connectors`}),(0,O.jsx)(dl,{botId:e.id})]}),(0,O.jsxs)(`section`,{className:`border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Routines`}),(0,O.jsx)(sl,{botId:e.id})]})]})}function ml({kind:e}){return(0,O.jsx)(`span`,{className:b(`rounded px-1.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide`,e===`require`?`bg-(--color-red)/15 text-(--color-red)`:`bg-(--color-green)/15 text-(--color-green)`),children:e===`require`?`Require approval`:`Always allow`})}function hl({onCreated:e}){let[t,n]=(0,_.useState)(`require`),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(null);async function d(){if(r.trim())try{e(await T.rules.create({kind:t,toolPattern:r.trim(),inputPattern:a,scopeNote:s})),i(``),o(``),c(``),u(null)}catch(e){u(e instanceof ie?e.message:`Failed to create rule`)}}return(0,O.jsxs)(`div`,{className:`mb-4 space-y-2 rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`flex gap-2`,children:[`require`,`allow`].map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>n(e),className:b(`rounded px-3 py-1 text-xs font-medium`,t===e?`bg-(--color-accent) text-(--color-accent-fg)`:`border border-(--color-border) text-(--color-text-muted)`),children:e===`require`?`Require approval`:`Always allow`},e))}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 font-mono text-sm`,placeholder:`Tool pattern (e.g. Bash, browser_*, *)`,value:r,onChange:e=>i(e.target.value)}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 font-mono text-sm`,placeholder:`Input pattern (optional regex)`,value:a,onChange:e=>o(e.target.value)}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Scope note (why this rule exists)`,value:s,onChange:e=>c(e.target.value)}),l&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:l}),(0,O.jsx)(`button`,{type:`button`,onClick:d,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg)`,children:`Add rule`})]})}function gl(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0);(0,_.useEffect)(()=>{T.rules.list().then(t).finally(()=>r(!1))},[]);async function i(e){let n=await T.rules.update(e.id,!e.enabled);t(e=>e.map(e=>e.id===n.id?n:e))}async function a(e){e.builtin||window.confirm(`Delete rule for "${e.toolPattern}"?`)&&(await T.rules.remove(e.id),t(t=>t.filter(t=>t.id!==e.id)))}return(0,O.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,O.jsx)(`h1`,{className:`mb-1 text-lg font-semibold`,children:`Rules`}),(0,O.jsx)(`p`,{className:`mb-4 text-sm text-(--color-text-muted)`,children:`Require Approval always wins over Always Allow.`}),(0,O.jsx)(hl,{onCreated:e=>t(t=>[e,...t])}),n&&(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`Loading…`}),!n&&e.length===0&&(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`No rules yet.`}),(0,O.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border border-(--color-border) p-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(ml,{kind:e.kind}),e.builtin&&(0,O.jsx)(`span`,{title:`Built-in rule`,"aria-label":`Built-in rule`,className:`text-(--color-text-faint)`,children:`🔒`}),(0,O.jsx)(`span`,{className:`truncate font-mono text-sm`,children:e.toolPattern})]}),e.inputPattern&&(0,O.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-xs text-(--color-text-muted)`,children:e.inputPattern}),e.scopeNote&&(0,O.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-(--color-text-faint)`,children:e.scopeNote})]}),(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>i(e)}),`Enabled`]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>a(e),disabled:e.builtin,className:`rounded border border-(--color-red)/50 px-2 py-1 text-xs text-(--color-red) disabled:cursor-not-allowed disabled:opacity-30`,children:`Delete`})]})]},e.id))})]})}function _l({label:e,value:t,max:n,sublabel:r}){let i=n>0?Math.max(2,Math.round(t/n*100)):0;return(0,O.jsxs)(`div`,{className:`mb-2`,children:[(0,O.jsxs)(`div`,{className:`mb-0.5 flex items-baseline justify-between text-xs`,children:[(0,O.jsx)(`span`,{className:`font-medium`,children:e}),(0,O.jsx)(`span`,{className:`text-(--color-text-muted)`,children:r??t.toLocaleString()})]}),(0,O.jsx)(`div`,{className:`h-2 rounded bg-(--color-bg)`,children:(0,O.jsx)(`div`,{className:`h-2 rounded bg-(--color-accent)`,style:{width:`${i}%`}})})]})}function vl(){let[e,t]=(0,_.useState)(null);if((0,_.useEffect)(()=>{T.usage().then(t)},[]),!e)return(0,O.jsx)(`p`,{className:`p-6 text-sm text-(--color-text-muted)`,children:`Loading usage…`});let n=e.totals.inputTokens+e.totals.outputTokens,r=Math.max(1,...e.byBot.map(e=>e.inputTokens+e.outputTokens)),i=Math.max(1,...e.byDay.map(e=>e.inputTokens+e.outputTokens)),a=Math.max(1,...e.byModel.map(e=>e.inputTokens+e.outputTokens));return(0,O.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,O.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Usage`}),(0,O.jsxs)(`section`,{className:`mb-6 grid grid-cols-3 gap-3`,children:[(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs text-(--color-text-muted)`,children:`Input tokens`}),(0,O.jsx)(`div`,{className:`text-xl font-semibold`,children:e.totals.inputTokens.toLocaleString()})]}),(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs text-(--color-text-muted)`,children:`Output tokens`}),(0,O.jsx)(`div`,{className:`text-xl font-semibold`,children:e.totals.outputTokens.toLocaleString()})]}),(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs text-(--color-text-muted)`,children:`Cache-read tokens`}),(0,O.jsx)(`div`,{className:`text-xl font-semibold`,children:e.totals.cacheReadTokens.toLocaleString()})]})]}),(0,O.jsxs)(`section`,{className:`mb-6`,children:[(0,O.jsx)(`h2`,{className:`mb-2 text-sm font-semibold`,children:`By bot`}),e.byBot.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No usage yet.`}),e.byBot.map(e=>(0,O.jsx)(_l,{label:e.botName,value:e.inputTokens+e.outputTokens,max:r},e.botId))]}),(0,O.jsxs)(`section`,{className:`mb-6`,children:[(0,O.jsx)(`h2`,{className:`mb-2 text-sm font-semibold`,children:`By day`}),(0,O.jsx)(`div`,{className:`flex items-end gap-1`,style:{height:96},children:e.byDay.map(e=>{let t=e.inputTokens+e.outputTokens,n=Math.max(2,Math.round(t/i*88));return(0,O.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-end`,title:`${e.day}: ${t.toLocaleString()} tokens`,children:[(0,O.jsx)(`div`,{className:`w-full rounded-t bg-(--color-accent)`,style:{height:n}}),(0,O.jsx)(`span`,{className:`mt-1 rotate-0 text-[9px] text-(--color-text-faint)`,children:e.day.slice(5)})]},e.day)})}),e.byDay.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No usage yet.`})]}),(0,O.jsxs)(`section`,{children:[(0,O.jsx)(`h2`,{className:`mb-2 text-sm font-semibold`,children:`By model`}),e.byModel.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No usage yet.`}),e.byModel.map(e=>(0,O.jsx)(_l,{label:e.model,value:e.inputTokens+e.outputTokens,max:a,sublabel:n>0?`${Math.round((e.inputTokens+e.outputTokens)/n*100)}%`:`0%`},e.model))]})]})}function yl({label:e,children:t}){return(0,O.jsxs)(`label`,{className:`mb-3 flex items-center justify-between gap-4 border-b border-(--color-border) py-2 text-sm`,children:[(0,O.jsx)(`span`,{className:`text-(--color-text-muted)`,children:e}),t]})}function bl({onSettingsChange:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T.settings.get().then(t=>{n(t),e?.(t)})},[]);async function a(r){if(!t)return;let a={...t,...r};n(a),i(!0);try{let t=await T.settings.update(r);n(t),e?.(t)}finally{i(!1)}}return t?(0,O.jsxs)(`div`,{className:`mx-auto max-w-xl p-6`,children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,O.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),r&&(0,O.jsx)(`span`,{className:`text-xs text-(--color-text-muted)`,children:`Saving…`})]}),(0,O.jsx)(yl,{label:`Timezone`,children:(0,O.jsx)(`input`,{className:`w-48 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.timezone,onChange:e=>a({timezone:e.target.value})})}),(0,O.jsx)(yl,{label:`Max concurrent sessions`,children:(0,O.jsx)(`input`,{type:`number`,min:1,max:8,className:`w-20 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.maxConcurrentSessions,onChange:e=>a({maxConcurrentSessions:Math.min(8,Math.max(1,Number(e.target.value)||1))})})}),(0,O.jsx)(yl,{label:`Auto-review (Haiku triage of tool calls)`,children:(0,O.jsx)(`input`,{type:`checkbox`,checked:t.autoReviewEnabled,onChange:e=>a({autoReviewEnabled:e.target.checked})})}),(0,O.jsx)(yl,{label:`Theme`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.theme,onChange:e=>a({theme:e.target.value}),children:[(0,O.jsx)(`option`,{value:`system`,children:`System`}),(0,O.jsx)(`option`,{value:`light`,children:`Light`}),(0,O.jsx)(`option`,{value:`dark`,children:`Dark`})]})}),(0,O.jsx)(yl,{label:`Local execution (run commands on this machine)`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.localExecution,onChange:e=>a({localExecution:e.target.value}),children:[(0,O.jsx)(`option`,{value:`ask`,children:`Ask`}),(0,O.jsx)(`option`,{value:`always`,children:`Always`}),(0,O.jsx)(`option`,{value:`never`,children:`Never`})]})}),(0,O.jsx)(yl,{label:`Daily token budget (0 = unlimited)`,children:(0,O.jsx)(`input`,{type:`number`,min:0,className:`w-32 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.dailyTokenBudget,onChange:e=>a({dailyTokenBudget:Math.max(0,Number(e.target.value)||0)})})}),(0,O.jsx)(yl,{label:`Desktop notifications`,children:(0,O.jsx)(`input`,{type:`checkbox`,checked:t.notificationsEnabled,onChange:e=>a({notificationsEnabled:e.target.checked})})}),(0,O.jsx)(yl,{label:`Billing mode`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.billingMode,onChange:e=>a({billingMode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`subscription`,children:`Subscription`}),(0,O.jsx)(`option`,{value:`api`,children:`API (metered)`})]})}),(0,O.jsx)(yl,{label:`Computer mode`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.computerMode,onChange:e=>a({computerMode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`host`,children:`Host`}),(0,O.jsx)(`option`,{value:`container`,children:`Container`})]})})]}):(0,O.jsx)(`p`,{className:`p-6 text-sm text-(--color-text-muted)`,children:`Loading settings…`})}var xl=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,Sl=/\.(md|markdown|txt|json|ya?ml|csv|log|ts|tsx|js|jsx|py|sh|css|html)$/i;function Cl(e){return e.startsWith(`.`)}function wl({entry:e,depth:t,showHidden:n,onOpenFile:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1);async function u(){if(!e.dir){r(e.path);return}if(!i&&o===null){l(!0);let t=await T.workspace.tree(e.path);s(t),l(!1)}a(e=>!e)}return(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`button`,{type:`button`,onClick:u,className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-left text-sm hover:bg-(--color-bg-hover)`,style:{paddingLeft:`${t*14+6}px`},children:[(0,O.jsx)(`span`,{className:`w-3 shrink-0 text-(--color-text-faint)`,children:e.dir?i?`▾`:`▸`:``}),(0,O.jsx)(`span`,{className:`shrink-0`,children:e.dir?`📁`:`📄`}),(0,O.jsx)(`span`,{className:`truncate`,children:e.name}),!e.dir&&(0,O.jsxs)(`span`,{className:`ml-auto shrink-0 text-xs text-(--color-text-faint)`,children:[e.bytes,`B`]})]}),i&&(0,O.jsxs)(`div`,{children:[c&&(0,O.jsx)(`div`,{style:{paddingLeft:`${(t+1)*14+6}px`},className:`py-1 text-xs text-(--color-text-faint)`,children:`Loading…`}),o?.filter(e=>n||!Cl(e.name)).map(e=>(0,O.jsx)(wl,{entry:e,depth:t+1,showHidden:n,onOpenFile:r},e.path))]})]})}function Tl({path:e,onClose:t}){let[n,r]=(0,_.useState)(null),i=e.split(`/`).pop()??e,a=xl.test(i),o=Sl.test(i);return(0,_.useEffect)(()=>{r(null),o&&fetch(T.workspace.fileUrl(e)).then(e=>e.text()).then(r).catch(()=>r(`(failed to load preview)`))},[e,o]),(0,O.jsxs)(`div`,{className:`flex h-full flex-col border-l border-(--color-border)`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between border-b border-(--color-border) p-2`,children:[(0,O.jsx)(`span`,{className:`truncate text-sm font-medium`,children:i}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`a`,{href:T.workspace.fileUrl(e),download:i,className:`text-xs text-(--color-accent) hover:underline`,children:`Download`}),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-(--color-text-muted) hover:text-(--color-text)`,children:`Close`})]})]}),(0,O.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[a&&(0,O.jsx)(`img`,{src:T.workspace.fileUrl(e),alt:i,className:`max-w-full`}),o&&(0,O.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-xs`,children:n??`Loading…`}),!a&&!o&&(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`No inline preview available — use Download.`})]})]})}function El(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{T.workspace.tree(``).then(t).finally(()=>s(!1))},[]),(0,O.jsxs)(`div`,{className:`flex h-full`,children:[(0,O.jsxs)(`div`,{className:`flex w-80 shrink-0 flex-col border-r border-(--color-border)`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between border-b border-(--color-border) p-2`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Workspace`}),(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),`Hidden files`]})]}),(0,O.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-1`,children:[o&&(0,O.jsx)(`p`,{className:`p-2 text-xs text-(--color-text-muted)`,children:`Loading…`}),!o&&e.length===0&&(0,O.jsx)(`p`,{className:`p-2 text-xs text-(--color-text-muted)`,children:`Workspace is empty.`}),e.filter(e=>n||!Cl(e.name)).map(e=>(0,O.jsx)(wl,{entry:e,depth:0,showHidden:n,onOpenFile:a},e.path))]})]}),i&&(0,O.jsx)(`div`,{className:`w-96 shrink-0`,children:(0,O.jsx)(Tl,{path:i,onClose:()=>a(null)})})]})}function Dl(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null);(0,_.useEffect)(()=>{T.computer.status().then(e=>{t(e),e.pages.length>0&&r(e.pages[0].botId)})},[]);async function g(e){if(!e){h(`Nothing is selected on the remote page.`);return}try{await navigator.clipboard.writeText(e),h(`Copied ${e.length.toLocaleString()} character${e.length===1?``:`s`} from the page.`)}catch{h(`The browser refused clipboard access, so the selection was not copied.`)}}(0,_.useEffect)(()=>{if(a(null),u.current?.close(),!n||!e?.available)return;let t=window.location.protocol===`https:`?`wss`:`ws`,r=new WebSocket(`${t}://${window.location.host}/api/computer/screencast/${n}`);return u.current=r,r.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`frame`?a({data:t.data,w:t.w,h:t.h}):t.type===`selection`?g(t.text??``):t.type===`input-error`&&h(t.message??`Input was rejected.`)}catch{}},()=>r.close()},[n,e?.available]),(0,_.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>h(null),4e3);return()=>clearTimeout(e)},[m]),(0,_.useEffect)(()=>{o&&d.current?.focus()},[o]);async function v(){if(!n)return;let e=await T.computer.takeover(n);s(e.ok),l(e.message??null)}async function y(){n&&(await T.computer.returnControl(n),s(!1),l(null))}function b(e){let t=u.current;if(!(!o||!t||t.readyState!==WebSocket.OPEN))try{t.send(JSON.stringify(e))}catch{}}function x(e){b({type:`input`,input:e})}function ee(e){let t=e.currentTarget.getBoundingClientRect();return t.width<=0||t.height<=0?null:{x:(e.clientX-t.left)/t.width,y:(e.clientY-t.top)/t.height}}let te=[`left`,`middle`,`right`];return e?e.available?(0,O.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-(--color-border) p-3`,children:[(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:n??``,onChange:e=>r(e.target.value||null),children:[e.pages.length===0&&(0,O.jsx)(`option`,{value:``,children:`No active pages`}),e.pages.map(e=>(0,O.jsx)(`option`,{value:e.botId,children:e.title||e.url},e.botId))]}),(0,O.jsx)(`div`,{className:`flex items-center gap-2`,children:o?(0,O.jsx)(`button`,{type:`button`,onClick:y,className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Return control`}):(0,O.jsx)(`button`,{type:`button`,onClick:v,disabled:!n,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs font-medium hover:bg-(--color-bg-hover) disabled:opacity-40`,children:`Take over`})})]}),(0,O.jsx)(`p`,{className:`border-b border-(--color-border) bg-(--color-amber)/10 px-3 py-2 text-xs text-(--color-amber)`,children:`Never paste passwords or one-time codes into chat — use takeover.`}),c&&(0,O.jsx)(`p`,{className:`border-b border-(--color-border) bg-(--color-bg-elevated) px-3 py-2 text-xs text-(--color-text-muted)`,children:c}),(0,O.jsx)(`div`,{ref:d,tabIndex:o?0:-1,onFocus:()=>p(!0),onBlur:()=>p(!1),onKeyDown:e=>{if(o&&!((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`v`)){if((e.ctrlKey||e.metaKey)&&(e.key.toLowerCase()===`c`||e.key.toLowerCase()===`x`)){e.preventDefault(),b({type:`selection-request`}),e.key.toLowerCase()===`x`&&x({kind:`key`,action:`down`,key:e.key});return}e.preventDefault(),e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey?x({kind:`text`,text:e.key}):x({kind:`key`,action:`down`,key:e.key})}},onKeyUp:e=>{o&&((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`v`||(e.preventDefault(),e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey||x({kind:`key`,action:`up`,key:e.key})))},onPaste:e=>{if(!o)return;e.preventDefault();let t=e.clipboardData.getData(`text`);t&&x({kind:`text`,text:t.slice(0,4096)})},className:`flex min-h-0 flex-1 items-center justify-center overflow-auto bg-black/20 p-3 outline-none ${o&&!f?`ring-2 ring-(--color-amber) ring-inset`:``}`,children:i?(0,O.jsx)(`img`,{src:`data:image/jpeg;base64,${i.data}`,width:i.w,height:i.h,alt:`Agent computer screencast`,draggable:!1,onPointerMove:e=>{let t=ee(e);t&&x({kind:`mouse`,action:`move`,...t,button:`left`,clickCount:1,deltaX:0,deltaY:0})},onPointerDown:e=>{let t=ee(e);t&&(d.current?.focus(),x({kind:`mouse`,action:`down`,...t,button:te[e.button]??`left`,clickCount:e.detail||1,deltaX:0,deltaY:0}))},onPointerUp:e=>{let t=ee(e);t&&x({kind:`mouse`,action:`up`,...t,button:te[e.button]??`left`,clickCount:e.detail||1,deltaX:0,deltaY:0})},onWheel:e=>{let t=ee(e);t&&x({kind:`mouse`,action:`wheel`,...t,button:`left`,clickCount:1,deltaX:e.deltaX,deltaY:e.deltaY})},onContextMenu:e=>{o&&e.preventDefault()},className:`max-h-full max-w-full rounded border border-(--color-border) ${o?`cursor-crosshair`:`pointer-events-none select-none`}`}):(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`Waiting for a screencast frame…`})}),o&&!f&&(0,O.jsx)(`p`,{className:`border-t border-(--color-border) bg-(--color-amber)/10 px-3 py-2 text-xs text-(--color-amber)`,children:`Click the screen to send keystrokes to it.`}),m&&(0,O.jsx)(`p`,{className:`border-t border-(--color-border) bg-(--color-bg-elevated) px-3 py-2 text-xs text-(--color-text-muted)`,children:m})]}):(0,O.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium`,children:`The agent computer isn't available right now.`}),(0,O.jsx)(`p`,{className:`max-w-sm text-xs text-(--color-text-muted)`,children:`Bots can still browse the web and use tools — you just won't see a live screencast until the computer service starts.`})]}):(0,O.jsx)(`p`,{className:`p-6 text-sm text-(--color-text-muted)`,children:`Checking the computer service…`})}var Ol=`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,kl=`mb-1 block text-xs text-(--color-text-muted)`,Al=0,jl=()=>({id:Al++,k:``,v:``});function Ml({pairs:e,onChange:t,keyLabel:n,secretNames:r}){let i=(n,r)=>t(e.map(e=>e.id===n?{...e,...r}:e));return(0,O.jsxs)(`div`,{className:`space-y-1`,children:[e.map(r=>(0,O.jsxs)(`div`,{className:`flex gap-1`,children:[(0,O.jsx)(`input`,{className:b(Ol,`w-2/5`),placeholder:n,value:r.k,onChange:e=>i(r.id,{k:e.target.value})}),(0,O.jsx)(`input`,{className:Ol,placeholder:`value, or {{secret:NAME}}`,list:`antbot-secret-names`,value:r.v,onChange:e=>i(r.id,{v:e.target.value})}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>t(e.filter(e=>e.id!==r.id)),className:`rounded border border-(--color-border) px-2 text-xs text-(--color-text-muted)`,children:`×`})]},r.id)),(0,O.jsxs)(`button`,{type:`button`,onClick:()=>t([...e,jl()]),className:`rounded border border-(--color-border) px-2 py-1 text-xs text-(--color-text-muted)`,children:[`+ add `,n.toLowerCase()]}),(0,O.jsx)(`datalist`,{id:`antbot-secret-names`,children:r.map(e=>(0,O.jsx)(`option`,{value:`{{secret:${e}}}`},e))})]})}function Nl({onCreated:e,secretNames:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(`stdio`),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(null),y=()=>Object.fromEntries(m.filter(e=>e.k.trim()).map(e=>[e.k.trim(),e.v]));async function b(){v(null);let t=(c.match(/"[^"]*"|'[^']*'|\S+/g)??[]).map(e=>/^["'].*["']$/.test(e)?e.slice(1,-1):e),s=o===`stdio`?{transport:`stdio`,command:t[0]??``,args:t.slice(1),env:y()}:{transport:o,url:u.trim(),headers:y(),...f.trim()?{tools:f.split(`,`).map(e=>e.trim()).filter(Boolean)}:{}};try{await T.connectors.create({name:n.trim(),description:i.trim(),config:s}),r(``),a(``),l(``),d(``),p(``),h([]),e()}catch(e){v(e instanceof ie?e.message:`Failed to add connector`)}}return(0,O.jsxs)(`div`,{className:`mb-6 space-y-2 rounded border border-(--color-border) p-3`,children:[(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(`div`,{className:`w-1/3`,children:[(0,O.jsx)(`span`,{className:kl,children:`Name`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`github`,value:n,onChange:e=>r(e.target.value)})]}),(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsx)(`span`,{className:kl,children:`Description`}),(0,O.jsx)(`input`,{className:Ol,value:i,onChange:e=>a(e.target.value)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:kl,children:`Transport`}),(0,O.jsxs)(`select`,{className:Ol,value:o,onChange:e=>s(e.target.value),children:[(0,O.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,O.jsx)(`option`,{value:`http`,children:`http`}),(0,O.jsx)(`option`,{value:`sse`,children:`sse`})]})]})]}),o===`stdio`?(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:kl,children:`Command`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`npx -y @modelcontextprotocol/server-filesystem /tmp`,value:c,onChange:e=>l(e.target.value)})]}):(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsx)(`span`,{className:kl,children:`URL`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`https://example.com/mcp`,value:u,onChange:e=>d(e.target.value)})]}),(0,O.jsxs)(`div`,{className:`w-1/3`,children:[(0,O.jsx)(`span`,{className:kl,children:`Tools (optional allowlist)`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`a, b`,value:f,onChange:e=>p(e.target.value)})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:kl,children:o===`stdio`?`Environment`:`Headers`}),(0,O.jsx)(Ml,{pairs:m,onChange:h,keyLabel:o===`stdio`?`VAR`:`Header`,secretNames:t}),(0,O.jsxs)(`p`,{className:`mt-1 text-[11px] text-(--color-text-muted)`,children:[`Reference a stored secret as `,(0,O.jsx)(`code`,{children:`{{secret:NAME}}`}),`. The daemon substitutes it when the connector starts — the value is never stored here, and a bot never sees it.`]})]}),g&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:g}),(0,O.jsx)(`button`,{type:`button`,onClick:b,disabled:!n.trim(),className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Add connector`})]})}function Pl({connector:e,onChanged:t}){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1);async function f(){s(null);try{let{authorizeUrl:t}=await T.connectors.login(e.id,c?{clientId:c}:{});window.open(t,`_blank`,`noopener`),d(!1)}catch(e){let t=e instanceof ie?e.message:`Could not start sign-in`;s(t),/client ID/i.test(t)&&d(!0)}}async function p(){await T.connectors.logout(e.id),t()}async function m(){a(!0);try{r(await T.connectors.test(e.id))}catch(e){r({ok:!1,tools:[],error:e instanceof ie?e.message:`Test failed`})}finally{a(!1)}}return(0,O.jsxs)(`div`,{className:`border-b border-(--color-border) py-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),(0,O.jsx)(`span`,{className:`ml-2 rounded bg-(--color-bg-elevated) px-1.5 py-0.5 text-[11px] text-(--color-text-muted)`,children:e.config.transport}),!e.enabled&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-text-muted)`,children:`disabled`}),e.description&&(0,O.jsx)(`p`,{className:`truncate text-xs text-(--color-text-muted)`,title:e.description,children:e.description}),e.signedIn&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-green)`,children:`signed in`}),e.missingSecrets.length>0&&(0,O.jsxs)(`p`,{className:`text-xs text-(--color-amber)`,children:[`missing secret: `,e.missingSecrets.join(`, `),` — this connector will not start`]})]}),e.config.transport!==`stdio`&&(0,O.jsx)(`button`,{type:`button`,onClick:e.signedIn?p:f,className:`rounded border border-(--color-border) px-2 py-1 text-xs`,children:e.signedIn?`Sign out`:`Sign in`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,disabled:i,className:`rounded border border-(--color-border) px-2 py-1 text-xs disabled:opacity-40`,children:i?`Testing…`:`Test`}),(0,O.jsx)(`button`,{type:`button`,onClick:async()=>{await T.connectors.update(e.id,{enabled:!e.enabled}),t()},className:`rounded border border-(--color-border) px-2 py-1 text-xs`,children:e.enabled?`Disable`:`Enable`}),(0,O.jsx)(`button`,{type:`button`,onClick:async()=>{await T.connectors.remove(e.id),t()},className:`rounded border border-(--color-border) px-2 py-1 text-xs text-(--color-red)`,children:`Delete`})]}),o&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-(--color-red)`,children:o}),u&&(0,O.jsxs)(`div`,{className:`mt-2 flex gap-1`,children:[(0,O.jsx)(`input`,{className:`flex-1 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,placeholder:`client ID from the provider's console`,value:c,onChange:e=>l(e.target.value)}),(0,O.jsx)(`button`,{type:`button`,onClick:f,disabled:!c.trim(),className:`rounded border border-(--color-border) px-2 py-1 text-xs disabled:opacity-40`,children:`Sign in`})]}),n&&(0,O.jsx)(`div`,{className:`mt-2 rounded bg-(--color-bg-elevated) p-2 text-xs`,children:n.ok?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`p`,{className:`text-(--color-green)`,children:[`Connected — `,n.tools.length,` tool(s)`]}),n.authHint&&(0,O.jsx)(`p`,{className:`mt-1 text-(--color-amber)`,children:n.authHint}),(0,O.jsx)(`ul`,{className:`mt-1 space-y-0.5`,children:n.tools.map(t=>(0,O.jsxs)(`li`,{className:`truncate`,title:t.description,children:[(0,O.jsx)(`code`,{children:`mcp__${e.name}__${t.name}`}),t.description&&(0,O.jsx)(`span`,{className:`ml-2 text-(--color-text-muted)`,children:t.description})]},t.name))})]}):(0,O.jsx)(`p`,{className:`text-(--color-red)`,children:n.error??`Could not connect`})})]})}function Fl(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),i=()=>{T.connectors.list().then(t)};return(0,_.useEffect)(()=>{i(),T.secrets.list().then(e=>r(e.names)).catch(()=>r([]))},[]),(0,O.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,O.jsx)(`h2`,{className:`mb-1 text-lg font-semibold`,children:`Connectors`}),(0,O.jsxs)(`p`,{className:`mb-4 text-xs text-(--color-text-muted)`,children:[`MCP servers your Bots can use. A connector is registered here once, then assigned to individual Bots in Bot settings — a Bot without an assignment cannot see its tools at all. Its tools reach Bots as`,` `,(0,O.jsx)(`code`,{children:`mcp__<name>__<tool>`}),` and still pass the permission gateway, so the first call asks you to approve it.`]}),(0,O.jsx)(Nl,{onCreated:i,secretNames:n}),e.length===0?(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`No connectors yet.`}):e.map(e=>(0,O.jsx)(Pl,{connector:e,onChanged:i},e.id))]})}var Il=[{label:`New bot`,target:{kind:`newBot`}},{label:`Open settings`,target:{kind:`settings`}},{label:`Open rules`,target:{kind:`rules`}},{label:`Open usage`,target:{kind:`usage`}},{label:`Open workspace`,target:{kind:`workspace`}}];function Ll({open:e,onClose:t,onNavigate:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)([]);if((0,_.useEffect)(()=>{e||(i(``),o([]))},[e]),(0,_.useEffect)(()=>{if(!r.trim()){o([]);return}let e=!1,t=setTimeout(()=>{T.search(r).then(t=>{e||o(t)})},150);return()=>{e=!0,clearTimeout(t)}},[r]),!e)return null;let s=Il.filter(e=>e.label.toLowerCase().includes(r.toLowerCase()));function c(e){n(e),t()}return(0,O.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center bg-black/50 pt-24`,onClick:t,children:(0,O.jsxs)(`div`,{className:`w-full max-w-lg rounded-lg border border-(--color-border) bg-(--color-bg-elevated) shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,O.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>e.key===`Escape`&&t(),placeholder:`Search bots, threads, messages, files… or run a command`,className:`w-full border-b border-(--color-border) bg-transparent px-4 py-3 text-sm outline-none`}),(0,O.jsxs)(`div`,{className:`max-h-96 overflow-y-auto p-1.5`,children:[s.length>0&&(0,O.jsxs)(`div`,{className:`mb-1`,children:[(0,O.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-(--color-text-faint)`,children:`Actions`}),s.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(e.target),className:`flex w-full items-center rounded px-2.5 py-1.5 text-left text-sm hover:bg-(--color-bg-hover)`,children:e.label},e.label))]}),a.length>0&&(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-(--color-text-faint)`,children:`Results`}),a.map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>e.threadId&&c({kind:`thread`,id:e.threadId}),className:`flex w-full flex-col items-start rounded px-2.5 py-1.5 text-left text-sm hover:bg-(--color-bg-hover)`,children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`rounded bg-(--color-border) px-1 text-[10px] uppercase text-(--color-text-muted)`,children:e.kind}),(0,O.jsx)(`span`,{className:`truncate font-medium`,children:e.title})]}),e.snippet&&(0,O.jsx)(`span`,{className:`truncate text-xs text-(--color-text-muted)`,children:e.snippet})]},`${e.kind}-${e.id}`))]}),r.trim()&&s.length===0&&a.length===0&&(0,O.jsx)(`p`,{className:`px-2.5 py-4 text-center text-sm text-(--color-text-muted)`,children:`No results.`})]})]})})}var Rl=[{view:`thread`,label:`Chats`},{view:`workspace`,label:`Workspace`},{view:`computer`,label:`Computer`},{view:`rules`,label:`Rules`},{view:`connectors`,label:`Connectors`},{view:`usage`,label:`Usage`},{view:`settings`,label:`Settings`}],K={connecting:`Connecting…`,open:`Connected`,closed:`Disconnected`},q={connecting:`bg-(--color-amber) animate-pulse`,open:`bg-(--color-green)`,closed:`bg-(--color-red)`};function J({connection:e,pendingCount:t,view:n,onChangeView:r,onOpenPalette:i}){return(0,O.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center justify-between border-b border-(--color-border) bg-(--color-bg-elevated) px-3`,children:[(0,O.jsx)(`nav`,{className:`flex items-center gap-1`,children:Rl.map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>r(e.view),className:b(`rounded px-2.5 py-1 text-xs font-medium`,n===e.view?`bg-(--color-accent)/15 text-(--color-accent)`:`text-(--color-text-muted) hover:bg-(--color-bg-hover)`),children:[e.label,e.view===`rules`&&t>0&&(0,O.jsx)(`span`,{className:`ml-1.5 rounded-full bg-(--color-amber) px-1.5 py-0.5 text-[10px] font-semibold text-(--color-bg)`,children:t})]},e.view))}),(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsxs)(`button`,{type:`button`,onClick:i,className:`rounded border border-(--color-border) px-2.5 py-1 text-xs text-(--color-text-muted) hover:bg-(--color-bg-hover)`,children:[`Search… `,(0,O.jsx)(`span`,{className:`ml-1 opacity-60`,children:`⌘K`})]}),t>0&&(0,O.jsxs)(`span`,{className:`flex items-center gap-1 rounded-full bg-(--color-amber)/15 px-2 py-0.5 text-xs font-medium text-(--color-amber)`,children:[t,` pending approval`,t===1?``:`s`]}),(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`span`,{className:b(`h-1.5 w-1.5 rounded-full`,q[e])}),K[e]]})]})]})}function Y({children:e}){return(0,O.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e})}function X({children:e}){return(0,O.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e})}function zl(){let e=oe(e=>e.bots),t=oe(e=>e.threads),n=oe(e=>e.activeThreadId),r=oe(e=>e.messagesByThread),i=oe(e=>e.pendingApprovals),a=oe(e=>e.connection),o=oe(e=>e.notifications),s=oe(e=>e.setBots),c=oe(e=>e.setThreads),l=oe(e=>e.setThreadMessages),u=oe(e=>e.setActiveThreadId),d=oe(e=>e.appendLocalMessage),f=oe(e=>e.dismissNotification),p=oe(e=>e.setPendingApprovals),[m,h]=(0,_.useState)(`thread`),[g,v]=(0,_.useState)(!1),[y,x]=(0,_.useState)(!1),[ee,te]=(0,_.useState)(null),[S,ne]=(0,_.useState)(null),[re,ie]=(0,_.useState)(!1),[C,w]=(0,_.useState)([]),[ae,se]=(0,_.useState)(`system`);(0,_.useEffect)(()=>{let e=document.documentElement,t=window.matchMedia(`(prefers-color-scheme: dark)`);function n(){let n=ae===`light`||ae===`system`&&!t.matches;e.classList.toggle(`light`,n)}return n(),t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},[ae]),(0,_.useEffect)(()=>{T.bots.list().then(s),T.threads.list().then(c),T.skills.list().then(w),T.approvals.list().then(p).catch(()=>{});let e=E();return()=>e.close()},[s,c,p]);let ce=oe(e=>e.threadEpoch);(0,_.useEffect)(()=>{n&&(T.threads.get(n).then(({messages:e})=>{l(n,e)}),T.threads.markRead(n).catch(()=>{}))},[n,ce,l]),(0,_.useEffect)(()=>{function e(e){let t=e.metaKey||e.ctrlKey;t&&e.key.toLowerCase()===`n`?(e.preventDefault(),v(!0)):t&&e.key.toLowerCase()===`k`&&(e.preventDefault(),ie(!0))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let le=(0,_.useMemo)(()=>{let t={};for(let n of e)t[n.bot.id]=n;return t},[e]),D=(0,_.useMemo)(()=>Object.values(t).filter(e=>e.kind===`group`),[t]),ue=n?t[n]??null:null,de=n?r[n]??[]:[],fe=ue?e.find(e=>e.thread?.id===ue.id):void 0,pe=S?le[S]?.bot??null:null;async function k(){s(await T.bots.list())}async function me(e){x(!0),te(null);try{let t=await T.bots.create(e);await k(),v(!1),t.threadId&&(c(await T.threads.list()),u(t.threadId),h(`thread`))}catch(e){te(e instanceof Error?e.message:`Failed to create bot`)}finally{x(!1)}}async function he(e,t){if(!n)return;let r=await T.threads.postMessage(n,{contentMd:e,attachmentIds:t});d(n,r)}async function _e(){fe&&await T.bots.stop(fe.bot.id)}function ve(e){u(e),ne(null),h(`thread`)}function ye(e){e.kind===`thread`?ve(e.id):e.kind===`newBot`?v(!0):h(e.kind)}return(0,O.jsxs)(`div`,{className:`flex h-dvh flex-col overflow-hidden`,children:[(0,O.jsx)(J,{connection:a,pendingCount:i.length,view:m,onChangeView:e=>{ne(null),h(e)},onOpenPalette:()=>ie(!0)}),(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,O.jsx)(ge,{entries:e,groupThreads:D,botsById:le,activeThreadId:n,onSelectThread:ve,onNewBot:()=>v(!0)}),(0,O.jsxs)(`main`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[m===`thread`&&(pe?(0,O.jsx)(pl,{bot:pe,onClose:()=>ne(null),onUpdated:t=>s(e.map(e=>e.bot.id===t.id?{...e,bot:t}:e)),onDuplicated:e=>{k(),ne(e.id)},onDeleted:()=>{ne(null),k()}}):(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[fe&&(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-(--color-border) px-4 py-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`text-lg leading-none`,children:fe.bot.avatarEmoji}),(0,O.jsx)(`span`,{className:`text-sm font-semibold`,children:fe.bot.name}),fe.bot.title&&(0,O.jsx)(`span`,{className:`text-xs text-(--color-text-muted)`,children:fe.bot.title})]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>ne(fe.bot.id),className:`text-xs text-(--color-text-muted) hover:text-(--color-text)`,children:`Bot settings`})]}),(0,O.jsx)(tl,{thread:ue,messages:de,botsById:le,bots:e,skills:C,running:fe?.bot.state===`running`||fe?.bot.state===`queued`,onSend:he,onStop:_e})]})),m===`rules`&&(0,O.jsx)(Y,{children:(0,O.jsx)(gl,{})}),m===`connectors`&&(0,O.jsx)(Y,{children:(0,O.jsx)(Fl,{})}),m===`usage`&&(0,O.jsx)(Y,{children:(0,O.jsx)(vl,{})}),m===`settings`&&(0,O.jsx)(Y,{children:(0,O.jsx)(bl,{onSettingsChange:e=>se(e.theme)})}),m===`workspace`&&(0,O.jsx)(X,{children:(0,O.jsx)(El,{})}),m===`computer`&&(0,O.jsx)(X,{children:(0,O.jsx)(Dl,{})})]})]}),o.length>0&&(0,O.jsx)(`div`,{className:`pointer-events-none fixed bottom-24 right-4 z-50 flex flex-col gap-2`,children:o.slice(-4).map(e=>(0,O.jsxs)(`div`,{className:b(`pointer-events-auto w-72 rounded-md border p-3 text-sm shadow-lg`,e.level===`error`&&`border-(--color-red)/50 bg-(--color-bg-elevated)`,e.level===`warn`&&`border-(--color-amber)/50 bg-(--color-bg-elevated)`,e.level===`info`&&`border-(--color-border) bg-(--color-bg-elevated)`),children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>f(e.id),className:`text-(--color-text-faint) hover:text-(--color-text)`,children:`×`})]}),e.body&&(0,O.jsx)(`p`,{className:`mt-0.5 text-xs text-(--color-text-muted)`,children:e.body})]},e.id))}),g&&(0,O.jsx)(rl,{onCreate:me,onClose:()=>v(!1),busy:y,error:ee}),(0,O.jsx)(Ll,{open:re,onClose:()=>ie(!1),onNavigate:ye})]})}var Bl=document.getElementById(`root`);if(!Bl)throw Error(`#root not found`);(0,v.createRoot)(Bl).render((0,O.jsx)(_.StrictMode,{children:(0,O.jsx)(zl,{})}));
130
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function xo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}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:wo(t,`input`,e.processors),output:wo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function So(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 So(r.element,n);if(r.type===`set`)return So(r.valueType,n);if(r.type===`lazy`)return So(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return So(r.innerType,n);if(r.type===`intersection`)return So(r.left,n)||So(r.right,n);if(r.type===`record`||r.type===`map`)return So(r.keyType,n)||So(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:So(r.in,n)||So(r.out,n);if(r.type===`object`){for(let e in r.shape)if(So(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(So(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(So(e,n))return!0;return!!(r.rest&&So(r.rest,n))}return!1}var Co=(e,t={})=>n=>{let r=vo({...n,processors:t});return yo(e,r),bo(r,e),xo(r,e)},wo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=vo({...i??{},target:a,io:t,processors:n});return yo(e,o),bo(o,e),xo(o,e)},To={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Eo=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=To[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Do=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},Oo=(e,t,n,r)=>{n.type=`boolean`},ko=(e,t,n,r)=>{n.not={}},Ao=(e,t,n,r)=>{let i=e._zod.def,a=cn(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},jo=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Mo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},No=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Po=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=yo(a.element,t,{...r,path:[...r.path,`items`]})},Fo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=yo(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=yo(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Io=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>yo(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Lo=(e,t,n,r)=>{let i=e._zod.def,a=yo(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=yo(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Ro=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=yo(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=yo(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=yo(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},zo=(e,t,n,r)=>{let i=e._zod.def,a=yo(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`}]},Bo=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Vo=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Ho=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Uo=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Wo=(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;yo(o,t,r);let s=t.seen.get(e);s.ref=o},Go=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Ko=(e,t,n,r)=>{let i=e._zod.def;yo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},qo=M(`ZodISODateTime`,(e,t)=>{gi.init(e,t),ys.init(e,t)});function Jo(e){return Ba(qo,e)}var Yo=M(`ZodISODate`,(e,t)=>{_i.init(e,t),ys.init(e,t)});function Xo(e){return Va(Yo,e)}var Zo=M(`ZodISOTime`,(e,t)=>{vi.init(e,t),ys.init(e,t)});function Qo(e){return Ha(Zo,e)}var $o=M(`ZodISODuration`,(e,t)=>{yi.init(e,t),ys.init(e,t)});function es(e){return Ua($o,e)}var ts=M(`ZodError`,(e,t)=>{Wn.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>qn(e,t)},flatten:{value:t=>Kn(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ln,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ln,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),ns=Jn(ts),rs=Yn(ts),is=Xn(ts),as=Qn(ts),os=er(ts),ss=tr(ts),cs=nr(ts),ls=rr(ts),us=ir(ts),ds=ar(ts),fs=or(ts),ps=sr(ts),ms=new WeakMap;function hs(e,t,n){let r=Object.getPrototypeOf(e),i=ms.get(r);if(i||(i=new Set,ms.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var gs=M(`ZodType`,(e,t)=>(F.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:wo(e,`input`),output:wo(e,`output`)}}),e.toJSONSchema=Co(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>ns(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>is(e,t,n),e.parseAsync=async(t,n)=>rs(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>as(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>os(e,t,n),e.decode=(t,n)=>ss(e,t,n),e.encodeAsync=async(t,n)=>cs(e,t,n),e.decodeAsync=async(t,n)=>ls(e,t,n),e.safeEncode=(t,n)=>us(e,t,n),e.safeDecode=(t,n)=>ds(e,t,n),e.safeEncodeAsync=async(t,n)=>fs(e,t,n),e.safeDecodeAsync=async(t,n)=>ps(e,t,n),hs(e,`ZodType`,{check(...e){let t=this.def;return this.clone(gn(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 En(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Oc(e,t))},superRefine(e,t){return this.check(kc(e,t))},overwrite(e){return this.check(lo(e))},optional(){return uc(this)},exactOptional(){return fc(this)},nullable(){return mc(this)},nullish(){return uc(mc(this))},nonoptional(e){return bc(this,e)},array(){return Ys(this)},or(e){return Qs([this,e])},and(e){return nc(this,e)},transform(e){return wc(this,cc(e))},default(e){return gc(this,e)},prefault(e){return vc(this,e)},catch(e){return Sc(this,e)},pipe(e){return wc(this,e)},readonly(){return Ec(this)},describe(e){let t=this.clone();return ga.add(t,{description:e}),t},meta(...e){if(e.length===0)return ga.get(this);let t=this.clone();return ga.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return ga.get(e)?.description},configurable:!0}),e)),_s=M(`_ZodString`,(e,t)=>{ii.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eo(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,hs(e,`_ZodString`,{regex(...e){return this.check(ro(...e))},includes(...e){return this.check(oo(...e))},startsWith(...e){return this.check(so(...e))},endsWith(...e){return this.check(co(...e))},min(...e){return this.check(to(...e))},max(...e){return this.check(eo(...e))},length(...e){return this.check(no(...e))},nonempty(...e){return this.check(to(1,...e))},lowercase(e){return this.check(io(e))},uppercase(e){return this.check(ao(e))},trim(){return this.check(fo())},normalize(...e){return this.check(uo(...e))},toLowerCase(){return this.check(po())},toUpperCase(){return this.check(mo())},slugify(){return this.check(z())}})}),vs=M(`ZodString`,(e,t)=>{ii.init(e,t),_s.init(e,t),e.email=t=>e.check(va(bs,t)),e.url=t=>e.check(wa(Cs,t)),e.jwt=t=>e.check(za(Rs,t)),e.emoji=t=>e.check(Ta(ws,t)),e.guid=t=>e.check(ya(xs,t)),e.uuid=t=>e.check(ba(Ss,t)),e.uuidv4=t=>e.check(xa(Ss,t)),e.uuidv6=t=>e.check(Sa(Ss,t)),e.uuidv7=t=>e.check(Ca(Ss,t)),e.nanoid=t=>e.check(Ea(Ts,t)),e.guid=t=>e.check(ya(xs,t)),e.cuid=t=>e.check(Da(Es,t)),e.cuid2=t=>e.check(Oa(Ds,t)),e.ulid=t=>e.check(ka(Os,t)),e.base64=t=>e.check(Ia(Fs,t)),e.base64url=t=>e.check(La(Is,t)),e.xid=t=>e.check(Aa(ks,t)),e.ksuid=t=>e.check(ja(As,t)),e.ipv4=t=>e.check(Ma(js,t)),e.ipv6=t=>e.check(Na(Ms,t)),e.cidrv4=t=>e.check(Pa(Ns,t)),e.cidrv6=t=>e.check(Fa(Ps,t)),e.e164=t=>e.check(Ra(Ls,t)),e.datetime=t=>e.check(Jo(t)),e.date=t=>e.check(Xo(t)),e.time=t=>e.check(Qo(t)),e.duration=t=>e.check(es(t))});function V(e){return _a(vs,e)}var ys=M(`ZodStringFormat`,(e,t)=>{I.init(e,t),_s.init(e,t)}),bs=M(`ZodEmail`,(e,t)=>{si.init(e,t),ys.init(e,t)}),xs=M(`ZodGUID`,(e,t)=>{ai.init(e,t),ys.init(e,t)}),Ss=M(`ZodUUID`,(e,t)=>{oi.init(e,t),ys.init(e,t)}),Cs=M(`ZodURL`,(e,t)=>{ci.init(e,t),ys.init(e,t)}),ws=M(`ZodEmoji`,(e,t)=>{li.init(e,t),ys.init(e,t)}),Ts=M(`ZodNanoID`,(e,t)=>{ui.init(e,t),ys.init(e,t)}),Es=M(`ZodCUID`,(e,t)=>{di.init(e,t),ys.init(e,t)}),Ds=M(`ZodCUID2`,(e,t)=>{fi.init(e,t),ys.init(e,t)}),Os=M(`ZodULID`,(e,t)=>{pi.init(e,t),ys.init(e,t)}),ks=M(`ZodXID`,(e,t)=>{mi.init(e,t),ys.init(e,t)}),As=M(`ZodKSUID`,(e,t)=>{hi.init(e,t),ys.init(e,t)}),js=M(`ZodIPv4`,(e,t)=>{bi.init(e,t),ys.init(e,t)}),Ms=M(`ZodIPv6`,(e,t)=>{xi.init(e,t),ys.init(e,t)}),Ns=M(`ZodCIDRv4`,(e,t)=>{Si.init(e,t),ys.init(e,t)}),Ps=M(`ZodCIDRv6`,(e,t)=>{Ci.init(e,t),ys.init(e,t)}),Fs=M(`ZodBase64`,(e,t)=>{Ti.init(e,t),ys.init(e,t)}),Is=M(`ZodBase64URL`,(e,t)=>{Di.init(e,t),ys.init(e,t)}),Ls=M(`ZodE164`,(e,t)=>{Oi.init(e,t),ys.init(e,t)}),Rs=M(`ZodJWT`,(e,t)=>{Ai.init(e,t),ys.init(e,t)}),zs=M(`ZodNumber`,(e,t)=>{ji.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Do(e,t,n,r),hs(e,`ZodNumber`,{gt(e,t){return this.check(Za(e,t))},gte(e,t){return this.check(Qa(e,t))},min(e,t){return this.check(Qa(e,t))},lt(e,t){return this.check(Ya(e,t))},lte(e,t){return this.check(Xa(e,t))},max(e,t){return this.check(Xa(e,t))},int(e){return this.check(Vs(e))},safe(e){return this.check(Vs(e))},positive(e){return this.check(Za(0,e))},nonnegative(e){return this.check(Qa(0,e))},negative(e){return this.check(Ya(0,e))},nonpositive(e){return this.check(Xa(0,e))},multipleOf(e,t){return this.check($a(e,t))},step(e,t){return this.check($a(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function H(e){return Wa(zs,e)}var Bs=M(`ZodNumberFormat`,(e,t)=>{Mi.init(e,t),zs.init(e,t)});function Vs(e){return Ga(Bs,e)}var Hs=M(`ZodBoolean`,(e,t)=>{Ni.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r)});function Us(e){return Ka(Hs,e)}var Ws=M(`ZodUnknown`,(e,t)=>{Pi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Gs(){return qa(Ws)}var Ks=M(`ZodNever`,(e,t)=>{Fi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ko(e,t,n,r)});function qs(e){return Ja(Ks,e)}var Js=M(`ZodArray`,(e,t)=>{R.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r),e.element=t.element,hs(e,`ZodArray`,{min(e,t){return this.check(to(e,t))},nonempty(e){return this.check(to(1,e))},max(e,t){return this.check(eo(e,t))},length(e,t){return this.check(no(e,t))},unwrap(){return this.element}})});function Ys(e,t){return B(Js,e,t)}var Xs=M(`ZodObject`,(e,t)=>{Bi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),N(e,`shape`,()=>t.shape),hs(e,`ZodObject`,{keyof(){return W(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Gs()})},loose(){return this.clone({...this._zod.def,catchall:Gs()})},strict(){return this.clone({...this._zod.def,catchall:qs()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return jn(this,e)},safeExtend(e){return Mn(this,e)},merge(e){return Nn(this,e)},pick(e){return kn(this,e)},omit(e){return An(this,e)},partial(...e){return Pn(lc,this,e[0])},required(...e){return Fn(yc,this,e[0])}})});function U(e,t){return new Xs({type:`object`,shape:e??{},...P(t)})}var Zs=M(`ZodUnion`,(e,t)=>{Hi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Io(e,t,n,r),e.options=t.options});function Qs(e,t){return new Zs({type:`union`,options:e,...P(t)})}var $s=M(`ZodDiscriminatedUnion`,(e,t)=>{Zs.init(e,t),Ui.init(e,t)});function ec(e,t,n){return new $s({type:`union`,options:t,discriminator:e,...P(n)})}var tc=M(`ZodIntersection`,(e,t)=>{Wi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r)});function nc(e,t){return new tc({type:`intersection`,left:e,right:t})}var rc=M(`ZodRecord`,(e,t)=>{qi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ro(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function ic(e,t,n){return!t||!t._zod?new rc({type:`record`,keyType:V(),valueType:e,...P(t)}):new rc({type:`record`,keyType:e,valueType:t,...P(n)})}var ac=M(`ZodEnum`,(e,t)=>{Ji.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new ac({...t,checks:[],...P(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 ac({...t,checks:[],...P(r),entries:i})}});function W(e,t){return new ac({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...P(t)})}var oc=M(`ZodLiteral`,(e,t)=>{Yi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(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 G(e,t){return new oc({type:`literal`,values:Array.isArray(e)?e:[e],...P(t)})}var sc=M(`ZodTransform`,(e,t)=>{Xi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new an(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Hn(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Hn(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function cc(e){return new sc({type:`transform`,transform:e})}var lc=M(`ZodOptional`,(e,t)=>{Qi.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function uc(e){return new lc({type:`optional`,innerType:e})}var dc=M(`ZodExactOptional`,(e,t)=>{$i.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function fc(e){return new dc({type:`optional`,innerType:e})}var pc=M(`ZodNullable`,(e,t)=>{ea.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function mc(e){return new pc({type:`nullable`,innerType:e})}var hc=M(`ZodDefault`,(e,t)=>{ta.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function gc(e,t){return new hc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Cn(t)}})}var _c=M(`ZodPrefault`,(e,t)=>{ra.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ho(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function vc(e,t){return new _c({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Cn(t)}})}var yc=M(`ZodNonOptional`,(e,t)=>{ia.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function bc(e,t){return new yc({type:`nonoptional`,innerType:e,...P(t)})}var xc=M(`ZodCatch`,(e,t)=>{oa.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Sc(e,t){return new xc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Cc=M(`ZodPipe`,(e,t)=>{sa.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r),e.in=t.in,e.out=t.out});function wc(e,t){return new Cc({type:`pipe`,in:e,out:t})}var Tc=M(`ZodReadonly`,(e,t)=>{la.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ec(e){return new Tc({type:`readonly`,innerType:e})}var Dc=M(`ZodCustom`,(e,t)=>{da.init(e,t),gs.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r)});function Oc(e,t={}){return ho(Dc,e,t)}function kc(e,t){return go(e,t)}var Ac=W([`idle`,`queued`,`running`,`waiting_approval`,`waiting_input`,`interrupted`]),jc=W([`none`,`unread`,`needs_attention`]),Mc=[`fable`,`opus`,`sonnet`,`haiku`],Nc=W(Mc);U({id:V(),slug:V().regex(/^[a-z0-9][a-z0-9-]*$/),name:V().min(1).max(60),title:V().max(120).default(``),description:V().max(8e3).default(``),avatarEmoji:V().max(8).default(`🤖`),modelTier:Nc.default(`sonnet`),pinned:Us().default(!1),hidden:Us().default(!1),notifications:Us().default(!0),sessionId:V().nullable().default(null),state:Ac.default(`idle`),attention:jc.default(`none`),threadId:V().nullable().default(null),createdAt:H(),deletedAt:H().nullable().default(null)});var Pc=W([`dm`,`group`]);U({id:V(),kind:Pc,title:V().default(``),memberBotIds:Ys(V()).default([]),pinned:Us().default(!1),hidden:Us().default(!1),lastReadAt:H().default(0),createdAt:H()});var Fc=ec(`type`,[U({type:G(`tool`),toolName:V(),summary:V(),input:Gs().optional(),result:V().optional(),status:W([`running`,`ok`,`error`,`denied`])}),U({type:G(`file`),path:V(),name:V(),mime:V(),bytes:H(),action:W([`created`,`modified`]).default(`created`)}),U({type:G(`approval`),approvalId:V()}),U({type:G(`handoff`),fromBotId:V(),toBotId:V(),note:V()}),U({type:G(`error`),message:V()})]),Ic=W([`user`,`bot`,`system`]),Lc=U({id:V(),threadId:V(),authorKind:Ic,authorBotId:V().nullable().default(null),replyToId:V().nullable().default(null),contentMd:V().default(``),cards:Ys(Fc).default([]),streaming:Us().default(!1),createdAt:H()});U({id:V(),messageId:V().nullable(),path:V(),name:V(),mime:V(),bytes:H(),createdAt:H()});var Rc=W([`pending`,`allowed`,`denied`,`expired`]),zc=U({id:V(),botId:V(),threadId:V(),toolName:V(),inputSummary:V(),rawInput:Gs(),status:Rc.default(`pending`),decidedBy:W([`user`,`rule`,`auto_review`]).nullable().default(null),reason:V().default(``),ruleId:V().nullable().default(null),createdAt:H(),decidedAt:H().nullable().default(null)}),Bc=W([`require`,`allow`]);U({id:V(),kind:Bc,toolPattern:V().default(`*`),inputPattern:V().default(``),scopeNote:V().default(``),builtin:Us().default(!1),enabled:Us().default(!0),createdAt:H()}),U({id:V(),slug:V(),name:V(),description:V().default(``),path:V(),source:W([`user`,`taught`,`imported`]).default(`user`),createdAt:H()});var Vc=/^[a-z0-9][a-z0-9-]{0,31}$/,Hc=[`antbot`,`browser`],Uc=ec(`transport`,[U({transport:G(`stdio`),command:V().min(1),args:Ys(V()).default([]),env:ic(V(),V()).default({})}),U({transport:G(`http`),url:V().url(),headers:ic(V(),V()).default({}),tools:Ys(V()).optional()}),U({transport:G(`sse`),url:V().url(),headers:ic(V(),V()).default({}),tools:Ys(V()).optional()})]),Wc=U({id:V(),name:V().regex(Vc,`lowercase letters, digits and hyphens only, max 32 characters`).refine(e=>!Hc.includes(e),{message:`"antbot" and "browser" are reserved for the built-in servers`}),description:V().default(``),enabled:Us().default(!0),config:Uc,createdAt:H()});U({id:V(),botId:V(),name:V().min(1),cronExpr:V(),timezone:V().default(`UTC`),instructionMd:V(),enabled:Us().default(!0),lastRunAt:H().nullable().default(null),nextRunAt:H().nullable().default(null),createdAt:H()});var Gc=U({id:V(),routineId:V(),startedAt:H(),finishedAt:H().nullable().default(null),status:W([`running`,`ok`,`failed`,`interrupted`]),summary:V().default(``),threadId:V().nullable().default(null),isTest:Us().default(!1)});U({id:V(),fromBotId:V(),toBotId:V(),contentMd:V(),hops:H().default(1),delivered:Us().default(!1),createdAt:H()}),U({id:V(),botId:V(),turnId:V(),model:V(),inputTokens:H().default(0),outputTokens:H().default(0),cacheReadTokens:H().default(0),costEstimate:H().default(0),createdAt:H()}),W([`user`,`bot`,`routine`,`system`]);var Kc={seq:H(),threadId:V().nullable(),botId:V().nullable()};ec(`type`,[U({...Kc,type:G(`hello`)}),U({...Kc,type:G(`message.created`),message:Lc}),U({...Kc,type:G(`message.delta`),messageId:V(),delta:V()}),U({...Kc,type:G(`message.done`),messageId:V(),contentMd:V()}),U({...Kc,type:G(`message.card`),messageId:V(),card:Fc,cardIndex:H()}),U({...Kc,type:G(`bot.state`),state:Ac,attention:jc}),U({...Kc,type:G(`approval.pending`),approval:zc}),U({...Kc,type:G(`approval.resolved`),approval:zc}),U({...Kc,type:G(`routine.run`),run:Gc}),U({...Kc,type:G(`usage.tick`),inputTokens:H(),outputTokens:H(),model:V()}),U({...Kc,type:G(`notify`),title:V(),body:V(),level:W([`info`,`warn`,`error`])}),U({...Kc,type:G(`secret.request`),requestId:V(),name:V(),reason:V()}),U({...Kc,type:G(`thread.updated`),threadId2:V()})]);var qc=ec(`kind`,[U({kind:G(`mouse`),action:W([`move`,`down`,`up`,`wheel`]),x:H().min(0).max(1),y:H().min(0).max(1),button:W([`left`,`middle`,`right`]).default(`left`),clickCount:H().int().min(0).max(3).default(1),deltaX:H().default(0),deltaY:H().default(0)}),U({kind:G(`key`),action:W([`down`,`up`]),key:V().min(1).max(32)}),U({kind:G(`text`),text:V().min(1).max(4096)})]);ec(`type`,[U({type:G(`input`),input:qc}),U({type:G(`selection-request`)})]),U({name:V().min(1).max(60),title:V().max(120).optional(),description:V().max(8e3).optional(),avatarEmoji:V().max(8).optional(),modelTier:Nc.optional()}).partial().extend({pinned:Us().optional(),hidden:Us().optional(),notifications:Us().optional()}),U({kind:W([`dm`,`group`]),title:V().optional(),memberBotIds:Ys(V())}),U({contentMd:V(),attachmentIds:Ys(V()).optional(),replyToId:V().nullable().optional(),mentionBotIds:Ys(V()).optional(),mentionEveryone:Us().optional()}),U({decision:W([`allow`,`deny`]),alwaysRule:U({toolPattern:V(),inputPattern:V().default(``),scopeNote:V().default(``)}).optional()}),U({kind:W([`require`,`allow`]),toolPattern:V().min(1),inputPattern:V().default(``),scopeNote:V().default(``)}),U({botId:V(),name:V().min(1),cronExpr:V().min(1),timezone:V().optional(),instructionMd:V().min(1),enabled:Us().optional()}),U({name:V().min(1),description:V().default(``),bodyMd:V().min(1),source:W([`user`,`taught`,`imported`]).optional()}),U({name:Wc.shape.name,description:V().default(``),config:Uc,enabled:Us().optional()}),U({description:V().optional(),config:Uc.optional(),enabled:Us().optional()});var Jc={timezone:V(),maxConcurrentSessions:H().min(1).max(8),autoReviewEnabled:Us(),theme:W([`system`,`light`,`dark`]),localExecution:W([`ask`,`always`,`never`]),dailyTokenBudget:H(),notificationsEnabled:Us(),billingMode:W([`subscription`,`api`]),computerMode:W([`host`,`container`])};U({timezone:Jc.timezone.default(`UTC`),maxConcurrentSessions:Jc.maxConcurrentSessions.default(2),autoReviewEnabled:Jc.autoReviewEnabled.default(!0),theme:Jc.theme.default(`system`),localExecution:Jc.localExecution.default(`ask`),dailyTokenBudget:Jc.dailyTokenBudget.default(0),notificationsEnabled:Jc.notificationsEnabled.default(!0),billingMode:Jc.billingMode.default(`subscription`),computerMode:Jc.computerMode.default(`host`)}),U(Jc).partial(),U({kind:W([`message`,`file`,`routine`,`bot`]),id:V(),threadId:V().nullable(),botId:V().nullable(),title:V(),snippet:V(),createdAt:H()});var Yc=tn.MAX_ATTACHMENTS_PER_MESSAGE;function Xc(e,t){let n=e.slice(0,t),r=/(^|\s)([@/])([\w-]*)$/.exec(n);if(!r)return null;let i=r[2];return i===`/`&&n.trim()!==`/${r[3]}`?null:{prefix:i,query:r[3],start:t-r[3].length-1}}function Zc({onSend:e,bots:t,skills:n,running:r,onStop:i,uploadFile:a}){let[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(null),f=(0,_.useRef)(null),p=(0,_.useRef)(null),m=(0,_.useRef)(0);(0,_.useEffect)(()=>{m.current=c.length},[c.length]);let h=(0,_.useMemo)(()=>a??(e=>T.attachments.upload(e)),[a]),g=(0,_.useMemo)(()=>{if(!u||u.prefix!==`@`)return[];let e=u.query.toLowerCase();return t.filter(t=>t.bot.name.toLowerCase().includes(e)||t.bot.slug.toLowerCase().includes(e)).slice(0,8)},[u,t]),v=(0,_.useMemo)(()=>{if(!u||u.prefix!==`/`)return[];let e=u.query.toLowerCase();return n.filter(t=>t.slug.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)).slice(0,8)},[u,n]);function y(e){let t=Array.from(e),n=Math.max(0,Yc-m.current),r=t.slice(0,n);m.current=Math.min(Yc,m.current+r.length);for(let e of r)h(e).then(e=>{l(t=>t.length>=Yc?t:[...t,e])}).catch(()=>{m.current=Math.max(0,m.current-1)})}function b(e){l(t=>t.filter(t=>t.id!==e))}function x(){let t=o.trim();t&&(e(t,c.map(e=>e.id)),s(``),l([]),d(null))}function ee(e,t){s(e),d(Xc(e,t))}function te(e){e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),x()):e.key===`Escape`&&d(null)}function S(e){if(!u)return;let t=p.current,n=t?t.selectionStart:o.length,r=o.slice(0,u.start),i=o.slice(n),a=u.prefix===`@`?`@${e} `:`/${e} `,c=`${r}${a}${i}`;s(c),d(null),requestAnimationFrame(()=>{t?.focus();let e=r.length+a.length;t?.setSelectionRange(e,e)})}function ne(e){let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);t.length>0&&(e.preventDefault(),y(t))}function re(e){e.preventDefault(),e.dataTransfer.files.length>0&&y(e.dataTransfer.files)}return(0,O.jsxs)(`div`,{className:`shrink-0 border-t border-(--color-border) bg-(--color-bg-elevated) p-3`,onDrop:re,onDragOver:e=>e.preventDefault(),children:[c.length>0&&(0,O.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:c.map(e=>(0,O.jsxs)(`span`,{"data-testid":`attachment-chip`,className:`flex items-center gap-1.5 rounded-full border border-(--color-border) bg-(--color-bg) px-2.5 py-1 text-xs`,children:[e.name,(0,O.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,className:`text-(--color-text-muted) hover:text-(--color-red)`,onClick:()=>b(e.id),children:`×`})]},e.id))}),u&&(g.length>0||v.length>0)&&(0,O.jsx)(`div`,{className:`mb-2 max-h-40 overflow-auto rounded border border-(--color-border) bg-(--color-bg) text-sm shadow-lg`,children:u.prefix===`@`?g.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-(--color-bg-hover)`,onClick:()=>S(e.bot.slug),children:[(0,O.jsx)(`span`,{children:e.bot.avatarEmoji}),(0,O.jsx)(`span`,{children:e.bot.name})]},e.bot.id)):v.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-(--color-bg-hover)`,onClick:()=>S(e.slug),children:[(0,O.jsxs)(`span`,{className:`shrink-0 font-mono text-(--color-text-muted)`,children:[`/`,e.slug]}),(0,O.jsx)(`span`,{className:`min-w-0 truncate text-(--color-text-muted)`,title:e.description,children:e.description})]},e.id))}),(0,O.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,"aria-label":`Attach files`,className:`shrink-0 rounded border border-(--color-border) px-2.5 py-2 text-sm hover:bg-(--color-bg-hover)`,onClick:()=>f.current?.click(),children:`+`}),(0,O.jsx)(`input`,{ref:f,"data-testid":`attachment-input`,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files&&y(e.target.files),e.target.value=``}}),(0,O.jsx)(`textarea`,{ref:p,value:o,rows:1,placeholder:`Message… (@ to mention, / for a skill)`,className:`max-h-40 min-h-[38px] flex-1 resize-none rounded border border-(--color-border) bg-(--color-bg) px-3 py-2 text-sm outline-none focus:border-(--color-accent)`,onChange:e=>ee(e.target.value,e.target.selectionStart),onKeyDown:te,onPaste:ne}),r&&(0,O.jsx)(`button`,{type:`button`,onClick:i,className:`shrink-0 rounded border border-(--color-red) px-3 py-2 text-sm font-medium text-(--color-red) hover:bg-(--color-red)/10`,children:`Stop`}),(0,O.jsx)(`button`,{type:`button`,onClick:x,disabled:!o.trim(),className:`shrink-0 rounded bg-(--color-accent) px-3 py-2 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Send`})]})]})}j.setOptions({breaks:!0});function Qc(e){return j.parse(e,{async:!1}).replace(/<script[\s\S]*?<\/script>/gi,``)}function $c(e,t){if(e.authorKind===`user`)return{name:`You`,emoji:`🧑`};if(e.authorKind===`system`)return{name:`System`,emoji:`⚙️`};let n=e.authorBotId?t[e.authorBotId]?.bot:void 0;return{name:n?.name??`Bot`,emoji:n?.avatarEmoji??`🤖`}}function el({message:e,botsById:t}){let{name:n,emoji:r}=$c(e,t),i=e.authorKind===`user`;return(0,O.jsxs)(`div`,{className:b(`flex gap-3 px-4 py-2`,i&&`flex-row-reverse`),children:[(0,O.jsx)(`span`,{className:`mt-0.5 text-lg leading-none`,children:r}),(0,O.jsxs)(`div`,{className:b(`min-w-0 max-w-[75%]`,i&&`items-end text-right`),children:[(0,O.jsxs)(`div`,{className:b(`mb-0.5 flex items-baseline gap-2`,i&&`flex-row-reverse`),children:[(0,O.jsx)(`span`,{className:`text-xs font-semibold text-(--color-text-muted)`,children:n}),(0,O.jsx)(`span`,{className:`text-[11px] text-(--color-text-faint)`,children:new Date(e.createdAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),e.contentMd&&(0,O.jsxs)(`div`,{className:b(`markdown-body inline-block rounded-lg px-3 py-2 text-sm`,i?`bg-(--color-accent) text-(--color-accent-fg)`:`bg-(--color-bg-elevated)`),children:[(0,O.jsx)(`span`,{dangerouslySetInnerHTML:{__html:Qc(e.contentMd)}}),e.streaming&&(0,O.jsx)(`span`,{className:`ml-0.5 inline-block w-1.5 animate-pulse bg-current align-middle`,children:`\xA0`})]}),(0,O.jsx)(en,{cards:e.cards})]})]})}function tl({thread:e,messages:t,botsById:n,bots:r,skills:i,running:a,onSend:o,onStop:s}){let c=(0,_.useRef)(null),[l,u]=(0,_.useState)(!0);(0,_.useEffect)(()=>{if(!l)return;let e=()=>{let e=c.current;e&&(e.scrollTop=e.scrollHeight)};e();let t=requestAnimationFrame(()=>{e(),requestAnimationFrame(e)});return()=>cancelAnimationFrame(t)},[t,l]);function d(){let e=c.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;u(t<80)}return e?(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,O.jsx)(`div`,{ref:c,onScroll:d,className:`min-h-0 flex-1 overflow-y-auto py-2`,children:t.length===0?(0,O.jsx)(`p`,{className:`px-4 py-8 text-center text-sm text-(--color-text-muted)`,children:`No messages yet — say hello and give this bot a job.`}):t.map(e=>(0,O.jsx)(el,{message:e,botsById:n},e.id))}),(0,O.jsx)(Zc,{onSend:o,bots:r,skills:i,running:a,onStop:s})]}):(0,O.jsx)(`div`,{className:`flex h-full flex-1 flex-col items-center justify-center text-(--color-text-muted)`,children:(0,O.jsx)(`p`,{className:`text-sm`,children:`Select a bot to start a conversation, or create a new one.`})})}var nl=`🤖.🧠.🦾.🛰️.🧭.🗂️.📚.🔍.🧮.🧰.🛠️.⚙️.🧪.🧬.📈.📊.💡.🗒️.✍️.📝.📅.⏰.📬.📡.🌐.🔐.🗝️.🧯.🚀.🛎️.🎯.🧵.🧩.🕵️.🧑‍💻.👩‍💻.🧑‍🔬.🐜.🐝.🦉`.split(`.`);function rl({onCreate:e,onClose:t,busy:n,error:r}){let[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(`🤖`),[f,p]=(0,_.useState)(`sonnet`);function m(){i.trim()&&e({name:i.trim(),title:o.trim(),description:c.trim(),avatarEmoji:u,modelTier:f})}return(0,O.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,O.jsxs)(`div`,{className:`w-full max-w-md rounded-lg border border-(--color-border) bg-(--color-bg-elevated) p-5 shadow-xl`,children:[(0,O.jsx)(`h2`,{className:`mb-4 text-base font-semibold`,children:`New bot`}),(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,O.jsx)(`div`,{className:`grid grid-cols-8 gap-1 rounded border border-(--color-border) p-1.5`,children:nl.slice(0,16).map(e=>(0,O.jsx)(`button`,{type:`button`,"aria-pressed":u===e,onClick:()=>d(e),className:`rounded p-1 text-lg ${u===e?`bg-(--color-accent)/25`:`hover:bg-(--color-bg-hover)`}`,children:e},e))})}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Name`}),(0,O.jsx)(`input`,{autoFocus:!0,className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,value:i,onChange:e=>a(e.target.value),placeholder:`Scout`})]}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Title`}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,value:o,onChange:e=>s(e.target.value),placeholder:`Research assistant`})]}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Description`}),(0,O.jsx)(`textarea`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,rows:3,value:c,onChange:e=>l(e.target.value),placeholder:`What should this bot do?`})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:`mb-1 block text-xs text-(--color-text-muted)`,children:`Model tier`}),(0,O.jsx)(`div`,{className:`inline-flex rounded border border-(--color-border) p-0.5`,children:Mc.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>p(e),className:`rounded px-3 py-1 text-xs font-medium capitalize ${f===e?`bg-(--color-accent) text-(--color-accent-fg)`:`text-(--color-text-muted)`}`,children:e},e))})]}),(0,O.jsx)(`p`,{className:`rounded border border-(--color-amber)/40 bg-(--color-amber)/10 p-2 text-xs text-(--color-amber)`,children:`Bots share one computer, workspace, browser profile and logins. Bots are not a security boundary.`}),r&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:r})]}),(0,O.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-sm text-(--color-text-muted) hover:bg-(--color-bg-hover)`,children:`Cancel`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,disabled:!i.trim()||n,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Create bot`})]})]})})}var il={running:`text-(--color-blue)`,ok:`text-(--color-green)`,failed:`text-(--color-red)`,interrupted:`text-(--color-amber)`};function al({botId:e,onCreated:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(`0 9 * * *`),[o,s]=(0,_.useState)(Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null);async function m(){if(!(!n.trim()||!i.trim()||!c.trim())){d(!0),p(null);try{t(await T.routines.create({botId:e,name:n,cronExpr:i,timezone:o,instructionMd:c})),r(``),l(``)}catch(e){p(e instanceof ie?e.message:`Failed to create routine`)}finally{d(!1)}}}return(0,O.jsxs)(`div`,{className:`space-y-2 rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs font-semibold text-(--color-text-muted)`,children:`New routine`}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Name`,value:n,onChange:e=>r(e.target.value)}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`input`,{className:`flex-1 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 font-mono text-sm`,placeholder:`Cron expression (e.g. 0 9 * * *)`,value:i,onChange:e=>a(e.target.value)}),(0,O.jsx)(`input`,{className:`w-40 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Timezone`,value:o,onChange:e=>s(e.target.value)})]}),(0,O.jsx)(`textarea`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Instructions for this run…`,rows:3,value:c,onChange:e=>l(e.target.value)}),f&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:f}),(0,O.jsx)(`button`,{type:`button`,disabled:u,onClick:m,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Create routine`})]})}function ol({routine:e,onChanged:t,onDeleted:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1);async function d(){let t=await T.routines.runs(e.id);i(t.slice(0,20))}async function f(){let e=!a;o(e),e&&await d()}async function p(){t(await T.routines.update(e.id,{enabled:!e.enabled}))}async function m(){window.confirm(`Delete routine "${e.name}"?`)&&(await T.routines.remove(e.id),n(e.id))}async function h(){u(!0),c(!1);try{await T.routines.testRun(e.id),await d(),o(!0)}finally{u(!1)}}return(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`div`,{className:`text-sm font-medium`,children:e.name}),(0,O.jsxs)(`div`,{className:`font-mono text-xs text-(--color-text-muted)`,children:[e.cronExpr,` · `,e.timezone]}),e.nextRunAt&&(0,O.jsxs)(`div`,{className:`text-xs text-(--color-text-faint)`,children:[`Next run: `,new Date(e.nextRunAt).toLocaleString()]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:p}),`Enabled`]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(!0),disabled:l,className:`rounded border border-(--color-border) px-2 py-1 text-xs hover:bg-(--color-bg-hover)`,children:`Test run`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,className:`rounded border border-(--color-red)/50 px-2 py-1 text-xs text-(--color-red)`,children:`Delete`})]})]}),s&&(0,O.jsxs)(`div`,{className:`mt-2 rounded border border-(--color-amber)/50 bg-(--color-amber)/10 p-2 text-xs`,children:[(0,O.jsx)(`p`,{className:`text-(--color-amber)`,children:`A test run performs real work — it can navigate websites, change files and call connected tools.`}),(0,O.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:h,className:`rounded bg-(--color-amber) px-2 py-1 font-medium text-(--color-bg)`,children:`Run anyway`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded px-2 py-1 text-(--color-text-muted)`,children:`Cancel`})]})]}),(0,O.jsx)(`button`,{type:`button`,onClick:f,className:`mt-2 text-xs text-(--color-text-muted) hover:underline`,children:a?`Hide run history`:`Show run history`}),a&&(0,O.jsxs)(`ul`,{className:`mt-1 space-y-1`,children:[r.length===0&&(0,O.jsx)(`li`,{className:`text-xs text-(--color-text-faint)`,children:`No runs yet.`}),r.map(e=>(0,O.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[(0,O.jsx)(`span`,{className:b(`font-medium`,il[e.status]),children:e.status}),(0,O.jsx)(`span`,{className:`text-(--color-text-faint)`,children:new Date(e.startedAt).toLocaleString()}),e.isTest&&(0,O.jsx)(`span`,{className:`rounded bg-(--color-border) px-1 text-[10px]`,children:`test`}),e.summary&&(0,O.jsx)(`span`,{className:`truncate text-(--color-text-muted)`,children:e.summary})]},e.id))]})]})}function sl({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{let t=!1;return i(!0),T.routines.list(e).then(e=>{t||n(e)}).finally(()=>{t||i(!1)}),()=>{t=!0}},[e]),(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsx)(al,{botId:e,onCreated:e=>n(t=>[e,...t])}),r&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`Loading routines…`}),!r&&t.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No routines yet.`}),t.map(e=>(0,O.jsx)(ol,{routine:e,onChanged:e=>n(t=>t.map(t=>t.id===e.id?e:t)),onDeleted:e=>n(t=>t.filter(t=>t.id!==e))},e.id))]})}function cl({bot:e,onUpdated:t}){let[n,r]=(0,_.useState)(e.name),[i,a]=(0,_.useState)(e.title),[o,s]=(0,_.useState)(e.description),[c,l]=(0,_.useState)(e.avatarEmoji),[u,d]=(0,_.useState)(e.modelTier),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1);async function y(){p(!0),h(null);try{t(await T.bots.update(e.id,{name:n,title:i,description:o,avatarEmoji:c,modelTier:u}))}catch(e){h(e instanceof ie?e.message:`Failed to save`)}finally{p(!1)}}return(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`flex h-12 w-12 items-center justify-center rounded-lg border border-(--color-border) text-2xl hover:bg-(--color-bg-hover)`,children:c}),(0,O.jsx)(`div`,{className:`flex-1`,children:(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm font-medium`,value:n,onChange:e=>r(e.target.value),"aria-label":`Name`})})]}),g&&(0,O.jsx)(`div`,{className:`grid grid-cols-10 gap-1 rounded border border-(--color-border) p-2`,children:nl.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>{l(e),v(!1)},className:`rounded p-1 text-lg hover:bg-(--color-bg-hover)`,children:e},e))}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Title`}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,value:i,onChange:e=>a(e.target.value)})]}),(0,O.jsxs)(`label`,{className:`block text-xs`,children:[(0,O.jsx)(`span`,{className:`mb-1 block text-(--color-text-muted)`,children:`Description / persona`}),(0,O.jsx)(`textarea`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1.5 text-sm`,rows:4,value:o,onChange:e=>s(e.target.value)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:`mb-1 block text-xs text-(--color-text-muted)`,children:`Model tier`}),(0,O.jsx)(`div`,{className:`inline-flex rounded border border-(--color-border) p-0.5`,children:Mc.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`rounded px-3 py-1 text-xs font-medium capitalize ${u===e?`bg-(--color-accent) text-(--color-accent-fg)`:`text-(--color-text-muted)`}`,children:e},e))})]}),m&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:m}),(0,O.jsx)(`button`,{type:`button`,onClick:y,disabled:f,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Save profile`})]})}function ll({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``);(0,_.useEffect)(()=>{T.bots.memory.list(e).then(n)},[e]);function l(e){i(e),o(t.find(t=>t.name===e)?.content??``)}async function u(){let t=r??s.trim();t&&(await T.bots.memory.save(e,t,a),n(e=>{let n=e.findIndex(e=>e.name===t);return n===-1?[...e,{name:t,content:a}]:e.map((e,r)=>r===n?{name:t,content:a}:e)}),i(t),c(``))}async function d(t){await T.bots.memory.remove(e,t),n(e=>e.filter(e=>e.name!==t)),r===t&&(i(null),o(``))}return(0,O.jsxs)(`div`,{className:`grid grid-cols-[160px_1fr] gap-3`,children:[(0,O.jsxs)(`div`,{className:`space-y-1`,children:[t.map(e=>(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:()=>l(e.name),className:`flex-1 truncate rounded px-2 py-1 text-left text-xs ${r===e.name?`bg-(--color-accent)/15`:`hover:bg-(--color-bg-hover)`}`,children:e.name}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>d(e.name),"aria-label":`Delete ${e.name}`,className:`text-xs text-(--color-text-faint) hover:text-(--color-red)`,children:`×`})]},e.name)),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,placeholder:`new-file.md`,value:s,onChange:e=>{c(e.target.value),i(null),o(``)}})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`textarea`,{className:`h-40 w-full rounded border border-(--color-border) bg-(--color-bg) p-2 font-mono text-xs`,value:a,onChange:e=>o(e.target.value),placeholder:`Durable facts this bot should remember…`}),(0,O.jsx)(`button`,{type:`button`,onClick:u,className:`mt-2 rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Save memory file`})]})]})}function ul({skill:e,checked:t,onToggle:n}){let[r,i]=(0,_.useState)(!1),a=`skill-${e.id}`;return(0,O.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,O.jsx)(`input`,{id:a,type:`checkbox`,className:`mt-1 shrink-0`,checked:t,onChange:n}),(0,O.jsx)(`label`,{htmlFor:a,className:`shrink-0 cursor-pointer whitespace-nowrap font-medium`,children:e.name}),e.description&&(0,O.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,title:r?`Collapse description`:`Show the full description`,className:`min-w-0 flex-1 cursor-pointer text-left text-xs text-(--color-text-muted) hover:text-(--color-text) ${r?`whitespace-pre-wrap break-words`:`truncate`}`,children:[`— `,e.description]})]})}function dl({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(new Set),[a,o]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T.connectors.list().then(n)},[]),(0,_.useEffect)(()=>{T.bots.connectors.get(e).then(e=>i(new Set(e.map(e=>e.id))))},[e]);function s(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o(!1)}async function c(){await T.bots.connectors.set(e,Array.from(r)),o(!0)}return t.length===0?(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No connectors yet. Add one on the Connectors screen.`}):(0,O.jsxs)(`div`,{className:`space-y-2`,children:[t.map(e=>(0,O.jsxs)(`label`,{className:`flex items-start gap-2 text-xs`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:r.has(e.id),onChange:()=>s(e.id),className:`mt-0.5`}),(0,O.jsxs)(`span`,{className:`min-w-0`,children:[(0,O.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,O.jsx)(`span`,{className:`ml-1 text-(--color-text-muted)`,children:String(e.config.transport)}),!e.enabled&&(0,O.jsx)(`span`,{className:`ml-1 text-(--color-text-muted)`,children:`(disabled)`}),e.missingSecrets.length>0&&(0,O.jsxs)(`span`,{className:`ml-1 text-(--color-amber)`,children:[`missing secret: `,e.missingSecrets.join(`, `)]}),e.description&&(0,O.jsx)(`span`,{className:`block truncate text-(--color-text-muted)`,title:e.description,children:e.description})]})]},e.id)),(0,O.jsx)(`button`,{type:`button`,onClick:c,className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Save connectors`}),a&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-green)`,children:`Saved`})]})}function fl({botId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(new Set),[a,o]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T.skills.list().then(n)},[]),(0,_.useEffect)(()=>{T.bots.skills.get(e).then(e=>i(new Set(e.map(e=>e.id))))},[e]);function s(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o(!1)}async function c(){await T.bots.skills.set(e,Array.from(r)),o(!0)}return t.length===0?(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No skills taught yet.`}):(0,O.jsxs)(`div`,{className:`space-y-2`,children:[t.map(e=>(0,O.jsx)(ul,{skill:e,checked:r.has(e.id),onToggle:()=>s(e.id)},e.id)),(0,O.jsx)(`button`,{type:`button`,onClick:c,className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Save skills`}),a&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-green)`,children:`Saved`})]})}function pl({bot:e,onClose:t,onUpdated:n,onDuplicated:r,onDeleted:i}){let[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(null);async function d(){n(await T.bots.update(e.id,{pinned:!e.pinned}))}async function f(){n(await T.bots.update(e.id,{hidden:!e.hidden}))}async function p(){n(await T.bots.update(e.id,{notifications:!e.notifications}))}async function m(){r(await T.bots.duplicate(e.id))}async function h(){await T.bots.remove(e.id),i(e.id)}return(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto p-5`,children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,O.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e.name,` settings`]}),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`text-sm text-(--color-text-muted) hover:text-(--color-text)`,children:`Close`})]}),(0,O.jsx)(`section`,{className:`mb-6`,children:(0,O.jsx)(cl,{bot:e,onUpdated:n})}),(0,O.jsxs)(`section`,{className:`mb-6 flex flex-wrap gap-2 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:d,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:e.pinned?`Unpin`:`Pin`}),(0,O.jsx)(`button`,{type:`button`,onClick:f,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:e.hidden?`Unhide`:`Hide`}),(0,O.jsx)(`button`,{type:`button`,onClick:p,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:e.notifications?`Mute notifications`:`Unmute notifications`}),(0,O.jsx)(`button`,{type:`button`,onClick:m,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:`Duplicate`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(!0),className:`rounded border border-(--color-border) px-3 py-1.5 text-xs hover:bg-(--color-bg-hover)`,children:`Start fresh`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>o(!0),className:`rounded border border-(--color-red)/50 px-3 py-1.5 text-xs text-(--color-red) hover:bg-(--color-red)/10`,children:`Delete`})]}),s&&(0,O.jsxs)(`div`,{className:`mb-6 rounded border border-(--color-border) bg-(--color-bg-elevated) p-3 text-sm`,children:[(0,O.jsx)(`p`,{className:`mb-1`,children:`Clear this conversation and start a fresh session?`}),(0,O.jsx)(`p`,{className:`mb-2 text-xs text-(--color-text-muted)`,children:`Deletes the messages in this thread and drops the model’s accumulated context. Keeps the Bot’s description, memory, skills, connectors, routines and files.`}),l&&(0,O.jsx)(`p`,{className:`mb-2 text-xs text-(--color-red)`,children:l}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:async()=>{u(null);try{await T.bots.reset(e.id),c(!1),n(e)}catch(e){u(e instanceof ie?e.message:`Could not start fresh`)}},className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Start fresh`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>{c(!1),u(null)},className:`rounded border border-(--color-border) px-3 py-1.5 text-xs`,children:`Cancel`})]})]}),a&&(0,O.jsxs)(`div`,{className:`mb-6 rounded border border-(--color-red)/50 bg-(--color-red)/10 p-3 text-sm`,children:[(0,O.jsxs)(`p`,{className:`text-(--color-red)`,children:[`Delete `,e.name,`? This removes it from your roster and conversation history, but its workspace files and any browser logins it used survive deletion.`]}),(0,O.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,O.jsx)(`button`,{type:`button`,onClick:h,className:`rounded bg-(--color-red) px-3 py-1.5 text-xs font-medium text-white`,children:`Delete permanently`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`rounded px-3 py-1.5 text-xs text-(--color-text-muted)`,children:`Cancel`})]})]}),(0,O.jsxs)(`section`,{className:`mb-6 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Memory`}),(0,O.jsx)(ll,{botId:e.id})]}),(0,O.jsxs)(`section`,{className:`mb-6 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Skills`}),(0,O.jsx)(fl,{botId:e.id})]}),(0,O.jsxs)(`section`,{className:`mb-6 border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Connectors`}),(0,O.jsx)(dl,{botId:e.id})]}),(0,O.jsxs)(`section`,{className:`border-t border-(--color-border) pt-4`,children:[(0,O.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:`Routines`}),(0,O.jsx)(sl,{botId:e.id})]})]})}function ml({kind:e}){return(0,O.jsx)(`span`,{className:b(`rounded px-1.5 py-0.5 text-[11px] font-semibold uppercase tracking-wide`,e===`require`?`bg-(--color-red)/15 text-(--color-red)`:`bg-(--color-green)/15 text-(--color-green)`),children:e===`require`?`Require approval`:`Always allow`})}function hl({onCreated:e}){let[t,n]=(0,_.useState)(`require`),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(null);async function d(){if(r.trim())try{e(await T.rules.create({kind:t,toolPattern:r.trim(),inputPattern:a,scopeNote:s})),i(``),o(``),c(``),u(null)}catch(e){u(e instanceof ie?e.message:`Failed to create rule`)}}return(0,O.jsxs)(`div`,{className:`mb-4 space-y-2 rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`flex gap-2`,children:[`require`,`allow`].map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>n(e),className:b(`rounded px-3 py-1 text-xs font-medium`,t===e?`bg-(--color-accent) text-(--color-accent-fg)`:`border border-(--color-border) text-(--color-text-muted)`),children:e===`require`?`Require approval`:`Always allow`},e))}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 font-mono text-sm`,placeholder:`Tool pattern (e.g. Bash, browser_*, *)`,value:r,onChange:e=>i(e.target.value)}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 font-mono text-sm`,placeholder:`Input pattern (optional regex)`,value:a,onChange:e=>o(e.target.value)}),(0,O.jsx)(`input`,{className:`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,placeholder:`Scope note (why this rule exists)`,value:s,onChange:e=>c(e.target.value)}),l&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:l}),(0,O.jsx)(`button`,{type:`button`,onClick:d,className:`rounded bg-(--color-accent) px-3 py-1.5 text-sm font-medium text-(--color-accent-fg)`,children:`Add rule`})]})}function gl(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0);(0,_.useEffect)(()=>{T.rules.list().then(t).finally(()=>r(!1))},[]);async function i(e){let n=await T.rules.update(e.id,!e.enabled);t(e=>e.map(e=>e.id===n.id?n:e))}async function a(e){e.builtin||window.confirm(`Delete rule for "${e.toolPattern}"?`)&&(await T.rules.remove(e.id),t(t=>t.filter(t=>t.id!==e.id)))}return(0,O.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,O.jsx)(`h1`,{className:`mb-1 text-lg font-semibold`,children:`Rules`}),(0,O.jsx)(`p`,{className:`mb-4 text-sm text-(--color-text-muted)`,children:`Require Approval always wins over Always Allow.`}),(0,O.jsx)(hl,{onCreated:e=>t(t=>[e,...t])}),n&&(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`Loading…`}),!n&&e.length===0&&(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`No rules yet.`}),(0,O.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border border-(--color-border) p-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(ml,{kind:e.kind}),e.builtin&&(0,O.jsx)(`span`,{title:`Built-in rule`,"aria-label":`Built-in rule`,className:`text-(--color-text-faint)`,children:`🔒`}),(0,O.jsx)(`span`,{className:`truncate font-mono text-sm`,children:e.toolPattern})]}),e.inputPattern&&(0,O.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-xs text-(--color-text-muted)`,children:e.inputPattern}),e.scopeNote&&(0,O.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-(--color-text-faint)`,children:e.scopeNote})]}),(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>i(e)}),`Enabled`]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>a(e),disabled:e.builtin,className:`rounded border border-(--color-red)/50 px-2 py-1 text-xs text-(--color-red) disabled:cursor-not-allowed disabled:opacity-30`,children:`Delete`})]})]},e.id))})]})}function _l({label:e,value:t,max:n,sublabel:r}){let i=n>0?Math.max(2,Math.round(t/n*100)):0;return(0,O.jsxs)(`div`,{className:`mb-2`,children:[(0,O.jsxs)(`div`,{className:`mb-0.5 flex items-baseline justify-between text-xs`,children:[(0,O.jsx)(`span`,{className:`font-medium`,children:e}),(0,O.jsx)(`span`,{className:`text-(--color-text-muted)`,children:r??t.toLocaleString()})]}),(0,O.jsx)(`div`,{className:`h-2 rounded bg-(--color-bg)`,children:(0,O.jsx)(`div`,{className:`h-2 rounded bg-(--color-accent)`,style:{width:`${i}%`}})})]})}function vl(){let[e,t]=(0,_.useState)(null);if((0,_.useEffect)(()=>{T.usage().then(t)},[]),!e)return(0,O.jsx)(`p`,{className:`p-6 text-sm text-(--color-text-muted)`,children:`Loading usage…`});let n=e.totals.inputTokens+e.totals.outputTokens,r=Math.max(1,...e.byBot.map(e=>e.inputTokens+e.outputTokens)),i=Math.max(1,...e.byDay.map(e=>e.inputTokens+e.outputTokens)),a=Math.max(1,...e.byModel.map(e=>e.inputTokens+e.outputTokens));return(0,O.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,O.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Usage`}),(0,O.jsxs)(`section`,{className:`mb-6 grid grid-cols-3 gap-3`,children:[(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs text-(--color-text-muted)`,children:`Input tokens`}),(0,O.jsx)(`div`,{className:`text-xl font-semibold`,children:e.totals.inputTokens.toLocaleString()})]}),(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs text-(--color-text-muted)`,children:`Output tokens`}),(0,O.jsx)(`div`,{className:`text-xl font-semibold`,children:e.totals.outputTokens.toLocaleString()})]}),(0,O.jsxs)(`div`,{className:`rounded-md border border-(--color-border) p-3`,children:[(0,O.jsx)(`div`,{className:`text-xs text-(--color-text-muted)`,children:`Cache-read tokens`}),(0,O.jsx)(`div`,{className:`text-xl font-semibold`,children:e.totals.cacheReadTokens.toLocaleString()})]})]}),(0,O.jsxs)(`section`,{className:`mb-6`,children:[(0,O.jsx)(`h2`,{className:`mb-2 text-sm font-semibold`,children:`By bot`}),e.byBot.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No usage yet.`}),e.byBot.map(e=>(0,O.jsx)(_l,{label:e.botName,value:e.inputTokens+e.outputTokens,max:r},e.botId))]}),(0,O.jsxs)(`section`,{className:`mb-6`,children:[(0,O.jsx)(`h2`,{className:`mb-2 text-sm font-semibold`,children:`By day`}),(0,O.jsx)(`div`,{className:`flex items-end gap-1`,style:{height:96},children:e.byDay.map(e=>{let t=e.inputTokens+e.outputTokens,n=Math.max(2,Math.round(t/i*88));return(0,O.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-end`,title:`${e.day}: ${t.toLocaleString()} tokens`,children:[(0,O.jsx)(`div`,{className:`w-full rounded-t bg-(--color-accent)`,style:{height:n}}),(0,O.jsx)(`span`,{className:`mt-1 rotate-0 text-[9px] text-(--color-text-faint)`,children:e.day.slice(5)})]},e.day)})}),e.byDay.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No usage yet.`})]}),(0,O.jsxs)(`section`,{children:[(0,O.jsx)(`h2`,{className:`mb-2 text-sm font-semibold`,children:`By model`}),e.byModel.length===0&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-text-muted)`,children:`No usage yet.`}),e.byModel.map(e=>(0,O.jsx)(_l,{label:e.model,value:e.inputTokens+e.outputTokens,max:a,sublabel:n>0?`${Math.round((e.inputTokens+e.outputTokens)/n*100)}%`:`0%`},e.model))]})]})}function yl({label:e,children:t}){return(0,O.jsxs)(`label`,{className:`mb-3 flex items-center justify-between gap-4 border-b border-(--color-border) py-2 text-sm`,children:[(0,O.jsx)(`span`,{className:`text-(--color-text-muted)`,children:e}),t]})}function bl({onSettingsChange:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1);(0,_.useEffect)(()=>{T.settings.get().then(t=>{n(t),e?.(t)})},[]);async function a(r){if(!t)return;let a={...t,...r};n(a),i(!0);try{let t=await T.settings.update(r);n(t),e?.(t)}finally{i(!1)}}return t?(0,O.jsxs)(`div`,{className:`mx-auto max-w-xl p-6`,children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,O.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),r&&(0,O.jsx)(`span`,{className:`text-xs text-(--color-text-muted)`,children:`Saving…`})]}),(0,O.jsx)(yl,{label:`Timezone`,children:(0,O.jsx)(`input`,{className:`w-48 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.timezone,onChange:e=>a({timezone:e.target.value})})}),(0,O.jsx)(yl,{label:`Max concurrent sessions`,children:(0,O.jsx)(`input`,{type:`number`,min:1,max:8,className:`w-20 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.maxConcurrentSessions,onChange:e=>a({maxConcurrentSessions:Math.min(8,Math.max(1,Number(e.target.value)||1))})})}),(0,O.jsx)(yl,{label:`Auto-review (Haiku triage of tool calls)`,children:(0,O.jsx)(`input`,{type:`checkbox`,checked:t.autoReviewEnabled,onChange:e=>a({autoReviewEnabled:e.target.checked})})}),(0,O.jsx)(yl,{label:`Theme`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.theme,onChange:e=>a({theme:e.target.value}),children:[(0,O.jsx)(`option`,{value:`system`,children:`System`}),(0,O.jsx)(`option`,{value:`light`,children:`Light`}),(0,O.jsx)(`option`,{value:`dark`,children:`Dark`})]})}),(0,O.jsx)(yl,{label:`Local execution (run commands on this machine)`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.localExecution,onChange:e=>a({localExecution:e.target.value}),children:[(0,O.jsx)(`option`,{value:`ask`,children:`Ask`}),(0,O.jsx)(`option`,{value:`always`,children:`Always`}),(0,O.jsx)(`option`,{value:`never`,children:`Never`})]})}),(0,O.jsx)(yl,{label:`Daily token budget (0 = unlimited)`,children:(0,O.jsx)(`input`,{type:`number`,min:0,className:`w-32 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.dailyTokenBudget,onChange:e=>a({dailyTokenBudget:Math.max(0,Number(e.target.value)||0)})})}),(0,O.jsx)(yl,{label:`Desktop notifications`,children:(0,O.jsx)(`input`,{type:`checkbox`,checked:t.notificationsEnabled,onChange:e=>a({notificationsEnabled:e.target.checked})})}),(0,O.jsx)(yl,{label:`Billing mode`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.billingMode,onChange:e=>a({billingMode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`subscription`,children:`Subscription`}),(0,O.jsx)(`option`,{value:`api`,children:`API (metered)`})]})}),(0,O.jsx)(yl,{label:`Computer mode`,children:(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:t.computerMode,onChange:e=>a({computerMode:e.target.value}),children:[(0,O.jsx)(`option`,{value:`host`,children:`Host`}),(0,O.jsx)(`option`,{value:`container`,children:`Container`})]})})]}):(0,O.jsx)(`p`,{className:`p-6 text-sm text-(--color-text-muted)`,children:`Loading settings…`})}var xl=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,Sl=/\.(md|markdown|txt|json|ya?ml|csv|log|ts|tsx|js|jsx|py|sh|css|html)$/i;function Cl(e){return e.startsWith(`.`)}function wl({entry:e,depth:t,showHidden:n,onOpenFile:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1);async function u(){if(!e.dir){r(e.path);return}if(!i&&o===null){l(!0);let t=await T.workspace.tree(e.path);s(t),l(!1)}a(e=>!e)}return(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`button`,{type:`button`,onClick:u,className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-left text-sm hover:bg-(--color-bg-hover)`,style:{paddingLeft:`${t*14+6}px`},children:[(0,O.jsx)(`span`,{className:`w-3 shrink-0 text-(--color-text-faint)`,children:e.dir?i?`▾`:`▸`:``}),(0,O.jsx)(`span`,{className:`shrink-0`,children:e.dir?`📁`:`📄`}),(0,O.jsx)(`span`,{className:`truncate`,children:e.name}),!e.dir&&(0,O.jsxs)(`span`,{className:`ml-auto shrink-0 text-xs text-(--color-text-faint)`,children:[e.bytes,`B`]})]}),i&&(0,O.jsxs)(`div`,{children:[c&&(0,O.jsx)(`div`,{style:{paddingLeft:`${(t+1)*14+6}px`},className:`py-1 text-xs text-(--color-text-faint)`,children:`Loading…`}),o?.filter(e=>n||!Cl(e.name)).map(e=>(0,O.jsx)(wl,{entry:e,depth:t+1,showHidden:n,onOpenFile:r},e.path))]})]})}function Tl({path:e,onClose:t}){let[n,r]=(0,_.useState)(null),i=e.split(`/`).pop()??e,a=xl.test(i),o=Sl.test(i);return(0,_.useEffect)(()=>{r(null),o&&fetch(T.workspace.fileUrl(e)).then(e=>e.text()).then(r).catch(()=>r(`(failed to load preview)`))},[e,o]),(0,O.jsxs)(`div`,{className:`flex h-full flex-col border-l border-(--color-border)`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between border-b border-(--color-border) p-2`,children:[(0,O.jsx)(`span`,{className:`truncate text-sm font-medium`,children:i}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`a`,{href:T.workspace.fileUrl(e),download:i,className:`text-xs text-(--color-accent) hover:underline`,children:`Download`}),(0,O.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-(--color-text-muted) hover:text-(--color-text)`,children:`Close`})]})]}),(0,O.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[a&&(0,O.jsx)(`img`,{src:T.workspace.fileUrl(e),alt:i,className:`max-w-full`}),o&&(0,O.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-xs`,children:n??`Loading…`}),!a&&!o&&(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`No inline preview available — use Download.`})]})]})}function El(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{T.workspace.tree(``).then(t).finally(()=>s(!1))},[]),(0,O.jsxs)(`div`,{className:`flex h-full`,children:[(0,O.jsxs)(`div`,{className:`flex w-80 shrink-0 flex-col border-r border-(--color-border)`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between border-b border-(--color-border) p-2`,children:[(0,O.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Workspace`}),(0,O.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),`Hidden files`]})]}),(0,O.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-1`,children:[o&&(0,O.jsx)(`p`,{className:`p-2 text-xs text-(--color-text-muted)`,children:`Loading…`}),!o&&e.length===0&&(0,O.jsx)(`p`,{className:`p-2 text-xs text-(--color-text-muted)`,children:`Workspace is empty.`}),e.filter(e=>n||!Cl(e.name)).map(e=>(0,O.jsx)(wl,{entry:e,depth:0,showHidden:n,onOpenFile:a},e.path))]})]}),i&&(0,O.jsx)(`div`,{className:`w-96 shrink-0`,children:(0,O.jsx)(Tl,{path:i,onClose:()=>a(null)})})]})}function Dl(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null);(0,_.useEffect)(()=>{T.computer.status().then(e=>{t(e),e.pages.length>0&&r(e.pages[0].botId)})},[]);async function g(e){if(!e){h(`Nothing is selected on the remote page.`);return}try{await navigator.clipboard.writeText(e),h(`Copied ${e.length.toLocaleString()} character${e.length===1?``:`s`} from the page.`)}catch{h(`The browser refused clipboard access, so the selection was not copied.`)}}(0,_.useEffect)(()=>{if(a(null),u.current?.close(),!n||!e?.available)return;let t=window.location.protocol===`https:`?`wss`:`ws`,r=new WebSocket(`${t}://${window.location.host}/api/computer/screencast/${n}`);return u.current=r,r.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`frame`?a({data:t.data,w:t.w,h:t.h}):t.type===`selection`?g(t.text??``):t.type===`input-error`&&h(t.message??`Input was rejected.`)}catch{}},()=>r.close()},[n,e?.available]),(0,_.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>h(null),4e3);return()=>clearTimeout(e)},[m]),(0,_.useEffect)(()=>{o&&d.current?.focus()},[o]);async function v(){if(!n)return;let e=await T.computer.takeover(n);s(e.ok),l(e.message??null)}async function y(){n&&(await T.computer.returnControl(n),s(!1),l(null))}function b(e){let t=u.current;if(!(!o||!t||t.readyState!==WebSocket.OPEN))try{t.send(JSON.stringify(e))}catch{}}function x(e){b({type:`input`,input:e})}function ee(e){let t=e.currentTarget.getBoundingClientRect();return t.width<=0||t.height<=0?null:{x:(e.clientX-t.left)/t.width,y:(e.clientY-t.top)/t.height}}let te=[`left`,`middle`,`right`];return e?e.available?(0,O.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-(--color-border) p-3`,children:[(0,O.jsxs)(`select`,{className:`rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-sm`,value:n??``,onChange:e=>r(e.target.value||null),children:[e.pages.length===0&&(0,O.jsx)(`option`,{value:``,children:`No active pages`}),e.pages.map(e=>(0,O.jsx)(`option`,{value:e.botId,children:e.title||e.url},e.botId))]}),(0,O.jsx)(`div`,{className:`flex items-center gap-2`,children:o?(0,O.jsx)(`button`,{type:`button`,onClick:y,className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg)`,children:`Return control`}):(0,O.jsx)(`button`,{type:`button`,onClick:v,disabled:!n,className:`rounded border border-(--color-border) px-3 py-1.5 text-xs font-medium hover:bg-(--color-bg-hover) disabled:opacity-40`,children:`Take over`})})]}),(0,O.jsx)(`p`,{className:`border-b border-(--color-border) bg-(--color-amber)/10 px-3 py-2 text-xs text-(--color-amber)`,children:`Never paste passwords or one-time codes into chat — use takeover.`}),c&&(0,O.jsx)(`p`,{className:`border-b border-(--color-border) bg-(--color-bg-elevated) px-3 py-2 text-xs text-(--color-text-muted)`,children:c}),(0,O.jsx)(`div`,{ref:d,tabIndex:o?0:-1,onFocus:()=>p(!0),onBlur:()=>p(!1),onKeyDown:e=>{if(o&&!((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`v`)){if((e.ctrlKey||e.metaKey)&&(e.key.toLowerCase()===`c`||e.key.toLowerCase()===`x`)){e.preventDefault(),b({type:`selection-request`}),e.key.toLowerCase()===`x`&&x({kind:`key`,action:`down`,key:e.key});return}e.preventDefault(),e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey?x({kind:`text`,text:e.key}):x({kind:`key`,action:`down`,key:e.key})}},onKeyUp:e=>{o&&((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`v`||(e.preventDefault(),e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey||x({kind:`key`,action:`up`,key:e.key})))},onPaste:e=>{if(!o)return;e.preventDefault();let t=e.clipboardData.getData(`text`);t&&x({kind:`text`,text:t.slice(0,4096)})},className:`flex min-h-0 flex-1 items-center justify-center overflow-auto bg-black/20 p-3 outline-none ${o&&!f?`ring-2 ring-(--color-amber) ring-inset`:``}`,children:i?(0,O.jsx)(`img`,{src:`data:image/jpeg;base64,${i.data}`,width:i.w,height:i.h,alt:`Agent computer screencast`,draggable:!1,onPointerMove:e=>{let t=ee(e);t&&x({kind:`mouse`,action:`move`,...t,button:`left`,clickCount:1,deltaX:0,deltaY:0})},onPointerDown:e=>{let t=ee(e);t&&(d.current?.focus(),x({kind:`mouse`,action:`down`,...t,button:te[e.button]??`left`,clickCount:e.detail||1,deltaX:0,deltaY:0}))},onPointerUp:e=>{let t=ee(e);t&&x({kind:`mouse`,action:`up`,...t,button:te[e.button]??`left`,clickCount:e.detail||1,deltaX:0,deltaY:0})},onWheel:e=>{let t=ee(e);t&&x({kind:`mouse`,action:`wheel`,...t,button:`left`,clickCount:1,deltaX:e.deltaX,deltaY:e.deltaY})},onContextMenu:e=>{o&&e.preventDefault()},className:`max-h-full max-w-full rounded border border-(--color-border) ${o?`cursor-crosshair`:`pointer-events-none select-none`}`}):(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`Waiting for a screencast frame…`})}),o&&!f&&(0,O.jsx)(`p`,{className:`border-t border-(--color-border) bg-(--color-amber)/10 px-3 py-2 text-xs text-(--color-amber)`,children:`Click the screen to send keystrokes to it.`}),m&&(0,O.jsx)(`p`,{className:`border-t border-(--color-border) bg-(--color-bg-elevated) px-3 py-2 text-xs text-(--color-text-muted)`,children:m})]}):(0,O.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 p-6 text-center`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium`,children:`The agent computer isn't available right now.`}),(0,O.jsx)(`p`,{className:`max-w-sm text-xs text-(--color-text-muted)`,children:`Bots can still browse the web and use tools — you just won't see a live screencast until the computer service starts.`})]}):(0,O.jsx)(`p`,{className:`p-6 text-sm text-(--color-text-muted)`,children:`Checking the computer service…`})}var Ol=`w-full rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,kl=`mb-1 block text-xs text-(--color-text-muted)`,Al=0,jl=()=>({id:Al++,k:``,v:``});function Ml({pairs:e,onChange:t,keyLabel:n,secretNames:r}){let i=(n,r)=>t(e.map(e=>e.id===n?{...e,...r}:e));return(0,O.jsxs)(`div`,{className:`space-y-1`,children:[e.map(r=>(0,O.jsxs)(`div`,{className:`flex gap-1`,children:[(0,O.jsx)(`input`,{className:b(Ol,`w-2/5`),placeholder:n,value:r.k,onChange:e=>i(r.id,{k:e.target.value})}),(0,O.jsx)(`input`,{className:Ol,placeholder:`value, or {{secret:NAME}}`,list:`antbot-secret-names`,value:r.v,onChange:e=>i(r.id,{v:e.target.value})}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>t(e.filter(e=>e.id!==r.id)),className:`rounded border border-(--color-border) px-2 text-xs text-(--color-text-muted)`,children:`×`})]},r.id)),(0,O.jsxs)(`button`,{type:`button`,onClick:()=>t([...e,jl()]),className:`rounded border border-(--color-border) px-2 py-1 text-xs text-(--color-text-muted)`,children:[`+ add `,n.toLowerCase()]}),(0,O.jsx)(`datalist`,{id:`antbot-secret-names`,children:r.map(e=>(0,O.jsx)(`option`,{value:`{{secret:${e}}}`},e))})]})}function Nl({onCreated:e,secretNames:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(`stdio`),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(null),y=()=>Object.fromEntries(m.filter(e=>e.k.trim()).map(e=>[e.k.trim(),e.v]));async function b(){v(null);let t=(c.match(/"[^"]*"|'[^']*'|\S+/g)??[]).map(e=>/^["'].*["']$/.test(e)?e.slice(1,-1):e),s=o===`stdio`?{transport:`stdio`,command:t[0]??``,args:t.slice(1),env:y()}:{transport:o,url:u.trim(),headers:y(),...f.trim()?{tools:f.split(`,`).map(e=>e.trim()).filter(Boolean)}:{}};try{await T.connectors.create({name:n.trim(),description:i.trim(),config:s}),r(``),a(``),l(``),d(``),p(``),h([]),e()}catch(e){v(e instanceof ie?e.message:`Failed to add connector`)}}return(0,O.jsxs)(`div`,{className:`mb-6 space-y-2 rounded border border-(--color-border) p-3`,children:[(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(`div`,{className:`w-1/3`,children:[(0,O.jsx)(`span`,{className:kl,children:`Name`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`github`,value:n,onChange:e=>r(e.target.value)})]}),(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsx)(`span`,{className:kl,children:`Description`}),(0,O.jsx)(`input`,{className:Ol,value:i,onChange:e=>a(e.target.value)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:kl,children:`Transport`}),(0,O.jsxs)(`select`,{className:Ol,value:o,onChange:e=>s(e.target.value),children:[(0,O.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,O.jsx)(`option`,{value:`http`,children:`http`}),(0,O.jsx)(`option`,{value:`sse`,children:`sse`})]})]})]}),o===`stdio`?(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:kl,children:`Command`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`npx -y @modelcontextprotocol/server-filesystem /tmp`,value:c,onChange:e=>l(e.target.value)})]}):(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsx)(`span`,{className:kl,children:`URL`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`https://example.com/mcp`,value:u,onChange:e=>d(e.target.value)})]}),(0,O.jsxs)(`div`,{className:`w-1/3`,children:[(0,O.jsx)(`span`,{className:kl,children:`Tools (optional allowlist)`}),(0,O.jsx)(`input`,{className:Ol,placeholder:`a, b`,value:f,onChange:e=>p(e.target.value)})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`span`,{className:kl,children:o===`stdio`?`Environment`:`Headers`}),(0,O.jsx)(Ml,{pairs:m,onChange:h,keyLabel:o===`stdio`?`VAR`:`Header`,secretNames:t}),(0,O.jsxs)(`p`,{className:`mt-1 text-[11px] text-(--color-text-muted)`,children:[`Reference a stored secret as `,(0,O.jsx)(`code`,{children:`{{secret:NAME}}`}),`. The daemon substitutes it when the connector starts — the value is never stored here, and a bot never sees it.`]})]}),g&&(0,O.jsx)(`p`,{className:`text-xs text-(--color-red)`,children:g}),(0,O.jsx)(`button`,{type:`button`,onClick:b,disabled:!n.trim(),className:`rounded bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-(--color-accent-fg) disabled:opacity-40`,children:`Add connector`})]})}function Pl({connector:e,onChanged:t}){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1);async function m(){s(null);try{let t={};c.trim()&&(t.clientId=c.trim()),u.trim()&&(t.clientSecret=u.trim());let{authorizeUrl:n}=await T.connectors.login(e.id,t);window.open(n,`_blank`,`noopener`),p(!1)}catch(e){let t=e instanceof ie?e.message:`Could not start sign-in`;s(t),/client ID|client secret/i.test(t)&&p(!0)}}async function h(){await T.connectors.logout(e.id),t()}async function g(){a(!0);try{r(await T.connectors.test(e.id))}catch(e){r({ok:!1,tools:[],error:e instanceof ie?e.message:`Test failed`})}finally{a(!1)}}return(0,O.jsxs)(`div`,{className:`border-b border-(--color-border) py-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),(0,O.jsx)(`span`,{className:`ml-2 rounded bg-(--color-bg-elevated) px-1.5 py-0.5 text-[11px] text-(--color-text-muted)`,children:e.config.transport}),!e.enabled&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-text-muted)`,children:`disabled`}),e.description&&(0,O.jsx)(`p`,{className:`truncate text-xs text-(--color-text-muted)`,title:e.description,children:e.description}),e.signedIn&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-(--color-green)`,children:`signed in`}),e.missingSecrets.length>0&&(0,O.jsxs)(`p`,{className:`text-xs text-(--color-amber)`,children:[`missing secret: `,e.missingSecrets.join(`, `),` — this connector will not start`]})]}),e.config.transport!==`stdio`&&(0,O.jsx)(`button`,{type:`button`,onClick:e.signedIn?h:m,className:`rounded border border-(--color-border) px-2 py-1 text-xs`,children:e.signedIn?`Sign out`:`Sign in`}),(0,O.jsx)(`button`,{type:`button`,onClick:g,disabled:i,className:`rounded border border-(--color-border) px-2 py-1 text-xs disabled:opacity-40`,children:i?`Testing…`:`Test`}),(0,O.jsx)(`button`,{type:`button`,onClick:async()=>{await T.connectors.update(e.id,{enabled:!e.enabled}),t()},className:`rounded border border-(--color-border) px-2 py-1 text-xs`,children:e.enabled?`Disable`:`Enable`}),(0,O.jsx)(`button`,{type:`button`,onClick:async()=>{await T.connectors.remove(e.id),t()},className:`rounded border border-(--color-border) px-2 py-1 text-xs text-(--color-red)`,children:`Delete`})]}),o&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-(--color-red)`,children:o}),f&&(0,O.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,O.jsxs)(`div`,{className:`flex gap-1`,children:[(0,O.jsx)(`input`,{className:`flex-1 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,placeholder:`client ID from the provider's console`,value:c,onChange:e=>l(e.target.value)}),(0,O.jsx)(`input`,{type:`password`,className:`flex-1 rounded border border-(--color-border) bg-(--color-bg) px-2 py-1 text-xs`,placeholder:`client secret (if the provider issued one)`,value:u,onChange:e=>d(e.target.value)}),(0,O.jsx)(`button`,{type:`button`,onClick:m,disabled:!c.trim(),className:`rounded border border-(--color-border) px-2 py-1 text-xs disabled:opacity-40`,children:`Sign in`})]}),(0,O.jsxs)(`p`,{className:`text-[11px] text-(--color-text-muted)`,children:[`Google’s “Web application” clients need both. Authorised redirect URI:`,` `,(0,O.jsx)(`code`,{children:`http://127.0.0.1:4780/api/connectors/oauth/callback`})]})]}),n&&(0,O.jsx)(`div`,{className:`mt-2 rounded bg-(--color-bg-elevated) p-2 text-xs`,children:n.ok?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`p`,{className:`text-(--color-green)`,children:[`Connected — `,n.tools.length,` tool(s)`]}),n.authHint&&(0,O.jsx)(`p`,{className:`mt-1 text-(--color-amber)`,children:n.authHint}),(0,O.jsx)(`ul`,{className:`mt-1 space-y-0.5`,children:n.tools.map(t=>(0,O.jsxs)(`li`,{className:`truncate`,title:t.description,children:[(0,O.jsx)(`code`,{children:`mcp__${e.name}__${t.name}`}),t.description&&(0,O.jsx)(`span`,{className:`ml-2 text-(--color-text-muted)`,children:t.description})]},t.name))})]}):(0,O.jsx)(`p`,{className:`text-(--color-red)`,children:n.error??`Could not connect`})})]})}function Fl(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),i=()=>{T.connectors.list().then(t)};return(0,_.useEffect)(()=>{i(),T.secrets.list().then(e=>r(e.names)).catch(()=>r([]))},[]),(0,O.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[(0,O.jsx)(`h2`,{className:`mb-1 text-lg font-semibold`,children:`Connectors`}),(0,O.jsxs)(`p`,{className:`mb-4 text-xs text-(--color-text-muted)`,children:[`MCP servers your Bots can use. A connector is registered here once, then assigned to individual Bots in Bot settings — a Bot without an assignment cannot see its tools at all. Its tools reach Bots as`,` `,(0,O.jsx)(`code`,{children:`mcp__<name>__<tool>`}),` and still pass the permission gateway, so the first call asks you to approve it.`]}),(0,O.jsx)(Nl,{onCreated:i,secretNames:n}),e.length===0?(0,O.jsx)(`p`,{className:`text-sm text-(--color-text-muted)`,children:`No connectors yet.`}):e.map(e=>(0,O.jsx)(Pl,{connector:e,onChanged:i},e.id))]})}var Il=[{label:`New bot`,target:{kind:`newBot`}},{label:`Open settings`,target:{kind:`settings`}},{label:`Open rules`,target:{kind:`rules`}},{label:`Open usage`,target:{kind:`usage`}},{label:`Open workspace`,target:{kind:`workspace`}}];function Ll({open:e,onClose:t,onNavigate:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)([]);if((0,_.useEffect)(()=>{e||(i(``),o([]))},[e]),(0,_.useEffect)(()=>{if(!r.trim()){o([]);return}let e=!1,t=setTimeout(()=>{T.search(r).then(t=>{e||o(t)})},150);return()=>{e=!0,clearTimeout(t)}},[r]),!e)return null;let s=Il.filter(e=>e.label.toLowerCase().includes(r.toLowerCase()));function c(e){n(e),t()}return(0,O.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center bg-black/50 pt-24`,onClick:t,children:(0,O.jsxs)(`div`,{className:`w-full max-w-lg rounded-lg border border-(--color-border) bg-(--color-bg-elevated) shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,O.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>e.key===`Escape`&&t(),placeholder:`Search bots, threads, messages, files… or run a command`,className:`w-full border-b border-(--color-border) bg-transparent px-4 py-3 text-sm outline-none`}),(0,O.jsxs)(`div`,{className:`max-h-96 overflow-y-auto p-1.5`,children:[s.length>0&&(0,O.jsxs)(`div`,{className:`mb-1`,children:[(0,O.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-(--color-text-faint)`,children:`Actions`}),s.map(e=>(0,O.jsx)(`button`,{type:`button`,onClick:()=>c(e.target),className:`flex w-full items-center rounded px-2.5 py-1.5 text-left text-sm hover:bg-(--color-bg-hover)`,children:e.label},e.label))]}),a.length>0&&(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`div`,{className:`px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-(--color-text-faint)`,children:`Results`}),a.map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>e.threadId&&c({kind:`thread`,id:e.threadId}),className:`flex w-full flex-col items-start rounded px-2.5 py-1.5 text-left text-sm hover:bg-(--color-bg-hover)`,children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`rounded bg-(--color-border) px-1 text-[10px] uppercase text-(--color-text-muted)`,children:e.kind}),(0,O.jsx)(`span`,{className:`truncate font-medium`,children:e.title})]}),e.snippet&&(0,O.jsx)(`span`,{className:`truncate text-xs text-(--color-text-muted)`,children:e.snippet})]},`${e.kind}-${e.id}`))]}),r.trim()&&s.length===0&&a.length===0&&(0,O.jsx)(`p`,{className:`px-2.5 py-4 text-center text-sm text-(--color-text-muted)`,children:`No results.`})]})]})})}var Rl=[{view:`thread`,label:`Chats`},{view:`workspace`,label:`Workspace`},{view:`computer`,label:`Computer`},{view:`rules`,label:`Rules`},{view:`connectors`,label:`Connectors`},{view:`usage`,label:`Usage`},{view:`settings`,label:`Settings`}],K={connecting:`Connecting…`,open:`Connected`,closed:`Disconnected`},q={connecting:`bg-(--color-amber) animate-pulse`,open:`bg-(--color-green)`,closed:`bg-(--color-red)`};function J({connection:e,pendingCount:t,view:n,onChangeView:r,onOpenPalette:i}){return(0,O.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center justify-between border-b border-(--color-border) bg-(--color-bg-elevated) px-3`,children:[(0,O.jsx)(`nav`,{className:`flex items-center gap-1`,children:Rl.map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>r(e.view),className:b(`rounded px-2.5 py-1 text-xs font-medium`,n===e.view?`bg-(--color-accent)/15 text-(--color-accent)`:`text-(--color-text-muted) hover:bg-(--color-bg-hover)`),children:[e.label,e.view===`rules`&&t>0&&(0,O.jsx)(`span`,{className:`ml-1.5 rounded-full bg-(--color-amber) px-1.5 py-0.5 text-[10px] font-semibold text-(--color-bg)`,children:t})]},e.view))}),(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsxs)(`button`,{type:`button`,onClick:i,className:`rounded border border-(--color-border) px-2.5 py-1 text-xs text-(--color-text-muted) hover:bg-(--color-bg-hover)`,children:[`Search… `,(0,O.jsx)(`span`,{className:`ml-1 opacity-60`,children:`⌘K`})]}),t>0&&(0,O.jsxs)(`span`,{className:`flex items-center gap-1 rounded-full bg-(--color-amber)/15 px-2 py-0.5 text-xs font-medium text-(--color-amber)`,children:[t,` pending approval`,t===1?``:`s`]}),(0,O.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-(--color-text-muted)`,children:[(0,O.jsx)(`span`,{className:b(`h-1.5 w-1.5 rounded-full`,q[e])}),K[e]]})]})]})}function Y({children:e}){return(0,O.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:e})}function X({children:e}){return(0,O.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e})}function zl(){let e=oe(e=>e.bots),t=oe(e=>e.threads),n=oe(e=>e.activeThreadId),r=oe(e=>e.messagesByThread),i=oe(e=>e.pendingApprovals),a=oe(e=>e.connection),o=oe(e=>e.notifications),s=oe(e=>e.setBots),c=oe(e=>e.setThreads),l=oe(e=>e.setThreadMessages),u=oe(e=>e.setActiveThreadId),d=oe(e=>e.appendLocalMessage),f=oe(e=>e.dismissNotification),p=oe(e=>e.setPendingApprovals),[m,h]=(0,_.useState)(`thread`),[g,v]=(0,_.useState)(!1),[y,x]=(0,_.useState)(!1),[ee,te]=(0,_.useState)(null),[S,ne]=(0,_.useState)(null),[re,ie]=(0,_.useState)(!1),[C,w]=(0,_.useState)([]),[ae,se]=(0,_.useState)(`system`);(0,_.useEffect)(()=>{let e=document.documentElement,t=window.matchMedia(`(prefers-color-scheme: dark)`);function n(){let n=ae===`light`||ae===`system`&&!t.matches;e.classList.toggle(`light`,n)}return n(),t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},[ae]),(0,_.useEffect)(()=>{T.bots.list().then(s),T.threads.list().then(c),T.skills.list().then(w),T.approvals.list().then(p).catch(()=>{});let e=E();return()=>e.close()},[s,c,p]);let ce=oe(e=>e.threadEpoch);(0,_.useEffect)(()=>{n&&(T.threads.get(n).then(({messages:e})=>{l(n,e)}),T.threads.markRead(n).catch(()=>{}))},[n,ce,l]),(0,_.useEffect)(()=>{function e(e){let t=e.metaKey||e.ctrlKey;t&&e.key.toLowerCase()===`n`?(e.preventDefault(),v(!0)):t&&e.key.toLowerCase()===`k`&&(e.preventDefault(),ie(!0))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let le=(0,_.useMemo)(()=>{let t={};for(let n of e)t[n.bot.id]=n;return t},[e]),D=(0,_.useMemo)(()=>Object.values(t).filter(e=>e.kind===`group`),[t]),ue=n?t[n]??null:null,de=n?r[n]??[]:[],fe=ue?e.find(e=>e.thread?.id===ue.id):void 0,pe=S?le[S]?.bot??null:null;async function k(){s(await T.bots.list())}async function me(e){x(!0),te(null);try{let t=await T.bots.create(e);await k(),v(!1),t.threadId&&(c(await T.threads.list()),u(t.threadId),h(`thread`))}catch(e){te(e instanceof Error?e.message:`Failed to create bot`)}finally{x(!1)}}async function he(e,t){if(!n)return;let r=await T.threads.postMessage(n,{contentMd:e,attachmentIds:t});d(n,r)}async function _e(){fe&&await T.bots.stop(fe.bot.id)}function ve(e){u(e),ne(null),h(`thread`)}function ye(e){e.kind===`thread`?ve(e.id):e.kind===`newBot`?v(!0):h(e.kind)}return(0,O.jsxs)(`div`,{className:`flex h-dvh flex-col overflow-hidden`,children:[(0,O.jsx)(J,{connection:a,pendingCount:i.length,view:m,onChangeView:e=>{ne(null),h(e)},onOpenPalette:()=>ie(!0)}),(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,O.jsx)(ge,{entries:e,groupThreads:D,botsById:le,activeThreadId:n,onSelectThread:ve,onNewBot:()=>v(!0)}),(0,O.jsxs)(`main`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[m===`thread`&&(pe?(0,O.jsx)(pl,{bot:pe,onClose:()=>ne(null),onUpdated:t=>s(e.map(e=>e.bot.id===t.id?{...e,bot:t}:e)),onDuplicated:e=>{k(),ne(e.id)},onDeleted:()=>{ne(null),k()}}):(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[fe&&(0,O.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-(--color-border) px-4 py-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`text-lg leading-none`,children:fe.bot.avatarEmoji}),(0,O.jsx)(`span`,{className:`text-sm font-semibold`,children:fe.bot.name}),fe.bot.title&&(0,O.jsx)(`span`,{className:`text-xs text-(--color-text-muted)`,children:fe.bot.title})]}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>ne(fe.bot.id),className:`text-xs text-(--color-text-muted) hover:text-(--color-text)`,children:`Bot settings`})]}),(0,O.jsx)(tl,{thread:ue,messages:de,botsById:le,bots:e,skills:C,running:fe?.bot.state===`running`||fe?.bot.state===`queued`,onSend:he,onStop:_e})]})),m===`rules`&&(0,O.jsx)(Y,{children:(0,O.jsx)(gl,{})}),m===`connectors`&&(0,O.jsx)(Y,{children:(0,O.jsx)(Fl,{})}),m===`usage`&&(0,O.jsx)(Y,{children:(0,O.jsx)(vl,{})}),m===`settings`&&(0,O.jsx)(Y,{children:(0,O.jsx)(bl,{onSettingsChange:e=>se(e.theme)})}),m===`workspace`&&(0,O.jsx)(X,{children:(0,O.jsx)(El,{})}),m===`computer`&&(0,O.jsx)(X,{children:(0,O.jsx)(Dl,{})})]})]}),o.length>0&&(0,O.jsx)(`div`,{className:`pointer-events-none fixed bottom-24 right-4 z-50 flex flex-col gap-2`,children:o.slice(-4).map(e=>(0,O.jsxs)(`div`,{className:b(`pointer-events-auto w-72 rounded-md border p-3 text-sm shadow-lg`,e.level===`error`&&`border-(--color-red)/50 bg-(--color-bg-elevated)`,e.level===`warn`&&`border-(--color-amber)/50 bg-(--color-bg-elevated)`,e.level===`info`&&`border-(--color-border) bg-(--color-bg-elevated)`),children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>f(e.id),className:`text-(--color-text-faint) hover:text-(--color-text)`,children:`×`})]}),e.body&&(0,O.jsx)(`p`,{className:`mt-0.5 text-xs text-(--color-text-muted)`,children:e.body})]},e.id))}),g&&(0,O.jsx)(rl,{onCreate:me,onClose:()=>v(!1),busy:y,error:ee}),(0,O.jsx)(Ll,{open:re,onClose:()=>ie(!1),onNavigate:ye})]})}var Bl=document.getElementById(`root`);if(!Bl)throw Error(`#root not found`);(0,v.createRoot)(Bl).render((0,O.jsx)(_.StrictMode,{children:(0,O.jsx)(zl,{})}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>ant-bot</title>
7
- <script type="module" crossorigin src="/assets/index-uIFP-bJK.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-B74AZxue.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-B90EjIDl.css">
9
9
  </head>
10
10
  <body>