morpheus-cli 0.6.6 → 0.6.7

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.
@@ -69,7 +69,7 @@ Please change the parent <Route path="${O}"> to <Route path="${O==="/"?"*":`${O}
69
69
 
70
70
  Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const l of e.seen.entries()){const f=l[1];if(t===l[0]){u(l);continue}if(e.external){const m=e.external.registry.get(l[0])?.id;if(t!==l[0]&&m){u(l);continue}}if(e.metadataRegistry.get(l[0])?.id){u(l);continue}if(f.cycle){u(l);continue}if(f.count>1&&e.reused==="ref"){u(l);continue}}}function Oj(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const a=l=>{const f=e.seen.get(l);if(f.ref===null)return;const h=f.def??f.schema,m={...h},g=f.ref;if(f.ref=null,g){a(g);const v=e.seen.get(g),b=v.schema;if(b.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(h.allOf=h.allOf??[],h.allOf.push(b)):Object.assign(h,b),Object.assign(h,m),l._zod.parent===g)for(const j in h)j==="$ref"||j==="allOf"||j in m||delete h[j];if(b.$ref&&v.def)for(const j in h)j==="$ref"||j==="allOf"||j in v.def&&JSON.stringify(h[j])===JSON.stringify(v.def[j])&&delete h[j]}const y=l._zod.parent;if(y&&y!==g){a(y);const v=e.seen.get(y);if(v?.schema.$ref&&(h.$ref=v.schema.$ref,v.def))for(const b in h)b==="$ref"||b==="allOf"||b in v.def&&JSON.stringify(h[b])===JSON.stringify(v.def[b])&&delete h[b]}e.override({zodSchema:l,jsonSchema:h,path:f.path??[]})};for(const l of[...e.seen.entries()].reverse())a(l[0]);const s={};if(e.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const l=e.external.registry.get(t)?.id;if(!l)throw new Error("Schema is missing an `id` property");s.$id=e.external.uri(l)}Object.assign(s,n.def??n.schema);const u=e.external?.defs??{};for(const l of e.seen.entries()){const f=l[1];f.def&&f.defId&&(u[f.defId]=f.def)}e.external||Object.keys(u).length>0&&(e.target==="draft-2020-12"?s.$defs=u:s.definitions=u);try{const l=JSON.parse(JSON.stringify(s));return Object.defineProperty(l,"~standard",{value:{...t["~standard"],jsonSchema:{input:Jc(t,"input",e.processors),output:Jc(t,"output",e.processors)}},enumerable:!1,writable:!1}),l}catch{throw new Error("Error converting schema to JSON.")}}function bn(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const a=e._zod.def;if(a.type==="transform")return!0;if(a.type==="array")return bn(a.element,n);if(a.type==="set")return bn(a.valueType,n);if(a.type==="lazy")return bn(a.getter(),n);if(a.type==="promise"||a.type==="optional"||a.type==="nonoptional"||a.type==="nullable"||a.type==="readonly"||a.type==="default"||a.type==="prefault")return bn(a.innerType,n);if(a.type==="intersection")return bn(a.left,n)||bn(a.right,n);if(a.type==="record"||a.type==="map")return bn(a.keyType,n)||bn(a.valueType,n);if(a.type==="pipe")return bn(a.in,n)||bn(a.out,n);if(a.type==="object"){for(const s in a.shape)if(bn(a.shape[s],n))return!0;return!1}if(a.type==="union"){for(const s of a.options)if(bn(s,n))return!0;return!1}if(a.type==="tuple"){for(const s of a.items)if(bn(s,n))return!0;return!!(a.rest&&bn(a.rest,n))}return!1}const M8=(e,t={})=>n=>{const a=Tj({...n,processors:t});return Ht(e,a),Aj(a,e),Oj(a,e)},Jc=(e,t,n={})=>a=>{const{libraryOptions:s,target:u}=a??{},l=Tj({...s??{},target:u,io:t,processors:n});return Ht(e,l),Aj(l,e),Oj(l,e)},D8={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},$8=(e,t,n,a)=>{const s=n;s.type="string";const{minimum:u,maximum:l,format:f,patterns:h,contentEncoding:m}=e._zod.bag;if(typeof u=="number"&&(s.minLength=u),typeof l=="number"&&(s.maxLength=l),f&&(s.format=D8[f]??f,s.format===""&&delete s.format,f==="time"&&delete s.format),m&&(s.contentEncoding=m),h&&h.size>0){const g=[...h];g.length===1?s.pattern=g[0].source:g.length>1&&(s.allOf=[...g.map(y=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:y.source}))])}},L8=(e,t,n,a)=>{const s=n,{minimum:u,maximum:l,format:f,multipleOf:h,exclusiveMaximum:m,exclusiveMinimum:g}=e._zod.bag;typeof f=="string"&&f.includes("int")?s.type="integer":s.type="number",typeof g=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(s.minimum=g,s.exclusiveMinimum=!0):s.exclusiveMinimum=g),typeof u=="number"&&(s.minimum=u,typeof g=="number"&&t.target!=="draft-04"&&(g>=u?delete s.minimum:delete s.exclusiveMinimum)),typeof m=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(s.maximum=m,s.exclusiveMaximum=!0):s.exclusiveMaximum=m),typeof l=="number"&&(s.maximum=l,typeof m=="number"&&t.target!=="draft-04"&&(m<=l?delete s.maximum:delete s.exclusiveMaximum)),typeof h=="number"&&(s.multipleOf=h)},P8=(e,t,n,a)=>{n.type="boolean"},U8=(e,t,n,a)=>{n.not={}},V8=(e,t,n,a)=>{},B8=(e,t,n,a)=>{const s=e._zod.def,u=uj(s.entries);u.every(l=>typeof l=="number")&&(n.type="number"),u.every(l=>typeof l=="string")&&(n.type="string"),n.enum=u},Z8=(e,t,n,a)=>{const s=e._zod.def,u=[];for(const l of s.values)if(l===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof l=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");u.push(Number(l))}else u.push(l);if(u.length!==0)if(u.length===1){const l=u[0];n.type=l===null?"null":typeof l,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[l]:n.const=l}else u.every(l=>typeof l=="number")&&(n.type="number"),u.every(l=>typeof l=="string")&&(n.type="string"),u.every(l=>typeof l=="boolean")&&(n.type="boolean"),u.every(l=>l===null)&&(n.type="null"),n.enum=u},I8=(e,t,n,a)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},H8=(e,t,n,a)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},F8=(e,t,n,a)=>{const s=n,u=e._zod.def,{minimum:l,maximum:f}=e._zod.bag;typeof l=="number"&&(s.minItems=l),typeof f=="number"&&(s.maxItems=f),s.type="array",s.items=Ht(u.element,t,{...a,path:[...a.path,"items"]})},q8=(e,t,n,a)=>{const s=n,u=e._zod.def;s.type="object",s.properties={};const l=u.shape;for(const m in l)s.properties[m]=Ht(l[m],t,{...a,path:[...a.path,"properties",m]});const f=new Set(Object.keys(l)),h=new Set([...f].filter(m=>{const g=u.shape[m]._zod;return t.io==="input"?g.optin===void 0:g.optout===void 0}));h.size>0&&(s.required=Array.from(h)),u.catchall?._zod.def.type==="never"?s.additionalProperties=!1:u.catchall?u.catchall&&(s.additionalProperties=Ht(u.catchall,t,{...a,path:[...a.path,"additionalProperties"]})):t.io==="output"&&(s.additionalProperties=!1)},G8=(e,t,n,a)=>{const s=e._zod.def,u=s.inclusive===!1,l=s.options.map((f,h)=>Ht(f,t,{...a,path:[...a.path,u?"oneOf":"anyOf",h]}));u?n.oneOf=l:n.anyOf=l},Y8=(e,t,n,a)=>{const s=e._zod.def,u=Ht(s.left,t,{...a,path:[...a.path,"allOf",0]}),l=Ht(s.right,t,{...a,path:[...a.path,"allOf",1]}),f=m=>"allOf"in m&&Object.keys(m).length===1,h=[...f(u)?u.allOf:[u],...f(l)?l.allOf:[l]];n.allOf=h},K8=(e,t,n,a)=>{const s=n,u=e._zod.def;s.type="object";const l=u.keyType,h=l._zod.bag?.patterns;if(u.mode==="loose"&&h&&h.size>0){const g=Ht(u.valueType,t,{...a,path:[...a.path,"patternProperties","*"]});s.patternProperties={};for(const y of h)s.patternProperties[y.source]=g}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(s.propertyNames=Ht(u.keyType,t,{...a,path:[...a.path,"propertyNames"]})),s.additionalProperties=Ht(u.valueType,t,{...a,path:[...a.path,"additionalProperties"]});const m=l._zod.values;if(m){const g=[...m].filter(y=>typeof y=="string"||typeof y=="number");g.length>0&&(s.required=g)}},X8=(e,t,n,a)=>{const s=e._zod.def,u=Ht(s.innerType,t,a),l=t.seen.get(e);t.target==="openapi-3.0"?(l.ref=s.innerType,n.nullable=!0):n.anyOf=[u,{type:"null"}]},J8=(e,t,n,a)=>{const s=e._zod.def;Ht(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType},Q8=(e,t,n,a)=>{const s=e._zod.def;Ht(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},W8=(e,t,n,a)=>{const s=e._zod.def;Ht(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},eV=(e,t,n,a)=>{const s=e._zod.def;Ht(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType;let l;try{l=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=l},tV=(e,t,n,a)=>{const s=e._zod.def,u=t.io==="input"?s.in._zod.def.type==="transform"?s.out:s.in:s.out;Ht(u,t,a);const l=t.seen.get(e);l.ref=u},nV=(e,t,n,a)=>{const s=e._zod.def;Ht(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,n.readOnly=!0},Rj=(e,t,n,a)=>{const s=e._zod.def;Ht(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType},rV=te("ZodISODateTime",(e,t)=>{aU.init(e,t),Ct.init(e,t)});function aV(e){return c8(rV,e)}const iV=te("ZodISODate",(e,t)=>{iU.init(e,t),Ct.init(e,t)});function sV(e){return d8(iV,e)}const oV=te("ZodISOTime",(e,t)=>{sU.init(e,t),Ct.init(e,t)});function lV(e){return f8(oV,e)}const uV=te("ZodISODuration",(e,t)=>{oU.init(e,t),Ct.init(e,t)});function cV(e){return h8(uV,e)}const dV=(e,t)=>{hj.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>J9(e,n)},flatten:{value:n=>X9(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Lp,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Lp,2)}},isEmpty:{get(){return e.issues.length===0}}})},dr=te("ZodError",dV,{Parent:Error}),fV=ex(dr),hV=tx(dr),mV=gd(dr),pV=xd(dr),gV=eP(dr),xV=tP(dr),yV=nP(dr),bV=rP(dr),vV=aP(dr),kV=iP(dr),wV=sP(dr),SV=oP(dr),Nt=te("ZodType",(e,t)=>(jt.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Jc(e,"input"),output:Jc(e,"output")}}),e.toJSONSchema=M8(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Xa(t,{checks:[...t.checks??[],...n.map(a=>typeof a=="function"?{_zod:{check:a,def:{check:"custom"},onattach:[]}}:a)]}),{parent:!0}),e.with=e.check,e.clone=(n,a)=>Ja(e,n,a),e.brand=()=>e,e.register=((n,a)=>(n.add(e,a),e)),e.parse=(n,a)=>fV(e,n,a,{callee:e.parse}),e.safeParse=(n,a)=>mV(e,n,a),e.parseAsync=async(n,a)=>hV(e,n,a,{callee:e.parseAsync}),e.safeParseAsync=async(n,a)=>pV(e,n,a),e.spa=e.safeParseAsync,e.encode=(n,a)=>gV(e,n,a),e.decode=(n,a)=>xV(e,n,a),e.encodeAsync=async(n,a)=>yV(e,n,a),e.decodeAsync=async(n,a)=>bV(e,n,a),e.safeEncode=(n,a)=>vV(e,n,a),e.safeDecode=(n,a)=>kV(e,n,a),e.safeEncodeAsync=async(n,a)=>wV(e,n,a),e.safeDecodeAsync=async(n,a)=>SV(e,n,a),e.refine=(n,a)=>e.check(xB(n,a)),e.superRefine=n=>e.check(yB(n)),e.overwrite=n=>e.check(so(n)),e.optional=()=>dw(e),e.exactOptional=()=>aB(e),e.nullable=()=>fw(e),e.nullish=()=>dw(fw(e)),e.nonoptional=n=>cB(e,n),e.array=()=>Ys(e),e.or=n=>Lj([e,n]),e.and=n=>QV(e,n),e.transform=n=>hw(e,nB(n)),e.default=n=>oB(e,n),e.prefault=n=>uB(e,n),e.catch=n=>fB(e,n),e.pipe=n=>hw(e,n),e.readonly=()=>pB(e),e.describe=n=>{const a=e.clone();return hl.add(a,{description:n}),a},Object.defineProperty(e,"description",{get(){return hl.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return hl.get(e);const a=e.clone();return hl.add(a,n[0]),a},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),Mj=te("_ZodString",(e,t)=>{nx.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>$8(e,a,s);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...a)=>e.check(b8(...a)),e.includes=(...a)=>e.check(w8(...a)),e.startsWith=(...a)=>e.check(S8(...a)),e.endsWith=(...a)=>e.check(z8(...a)),e.min=(...a)=>e.check(Xc(...a)),e.max=(...a)=>e.check(Cj(...a)),e.length=(...a)=>e.check(Ej(...a)),e.nonempty=(...a)=>e.check(Xc(1,...a)),e.lowercase=a=>e.check(v8(a)),e.uppercase=a=>e.check(k8(a)),e.trim=()=>e.check(j8()),e.normalize=(...a)=>e.check(_8(...a)),e.toLowerCase=()=>e.check(N8()),e.toUpperCase=()=>e.check(C8()),e.slugify=()=>e.check(E8())}),zV=te("ZodString",(e,t)=>{nx.init(e,t),Mj.init(e,t),e.email=n=>e.check(IU(_V,n)),e.url=n=>e.check(YU(jV,n)),e.jwt=n=>e.check(u8(BV,n)),e.emoji=n=>e.check(KU(NV,n)),e.guid=n=>e.check(rw(ow,n)),e.uuid=n=>e.check(HU(wc,n)),e.uuidv4=n=>e.check(FU(wc,n)),e.uuidv6=n=>e.check(qU(wc,n)),e.uuidv7=n=>e.check(GU(wc,n)),e.nanoid=n=>e.check(XU(CV,n)),e.guid=n=>e.check(rw(ow,n)),e.cuid=n=>e.check(JU(EV,n)),e.cuid2=n=>e.check(QU(TV,n)),e.ulid=n=>e.check(WU(AV,n)),e.base64=n=>e.check(s8(PV,n)),e.base64url=n=>e.check(o8(UV,n)),e.xid=n=>e.check(e8(OV,n)),e.ksuid=n=>e.check(t8(RV,n)),e.ipv4=n=>e.check(n8(MV,n)),e.ipv6=n=>e.check(r8(DV,n)),e.cidrv4=n=>e.check(a8($V,n)),e.cidrv6=n=>e.check(i8(LV,n)),e.e164=n=>e.check(l8(VV,n)),e.datetime=n=>e.check(aV(n)),e.date=n=>e.check(sV(n)),e.time=n=>e.check(lV(n)),e.duration=n=>e.check(cV(n))});function We(e){return ZU(zV,e)}const Ct=te("ZodStringFormat",(e,t)=>{wt.init(e,t),Mj.init(e,t)}),_V=te("ZodEmail",(e,t)=>{KP.init(e,t),Ct.init(e,t)}),ow=te("ZodGUID",(e,t)=>{GP.init(e,t),Ct.init(e,t)}),wc=te("ZodUUID",(e,t)=>{YP.init(e,t),Ct.init(e,t)}),jV=te("ZodURL",(e,t)=>{XP.init(e,t),Ct.init(e,t)}),NV=te("ZodEmoji",(e,t)=>{JP.init(e,t),Ct.init(e,t)}),CV=te("ZodNanoID",(e,t)=>{QP.init(e,t),Ct.init(e,t)}),EV=te("ZodCUID",(e,t)=>{WP.init(e,t),Ct.init(e,t)}),TV=te("ZodCUID2",(e,t)=>{eU.init(e,t),Ct.init(e,t)}),AV=te("ZodULID",(e,t)=>{tU.init(e,t),Ct.init(e,t)}),OV=te("ZodXID",(e,t)=>{nU.init(e,t),Ct.init(e,t)}),RV=te("ZodKSUID",(e,t)=>{rU.init(e,t),Ct.init(e,t)}),MV=te("ZodIPv4",(e,t)=>{lU.init(e,t),Ct.init(e,t)}),DV=te("ZodIPv6",(e,t)=>{uU.init(e,t),Ct.init(e,t)}),$V=te("ZodCIDRv4",(e,t)=>{cU.init(e,t),Ct.init(e,t)}),LV=te("ZodCIDRv6",(e,t)=>{dU.init(e,t),Ct.init(e,t)}),PV=te("ZodBase64",(e,t)=>{fU.init(e,t),Ct.init(e,t)}),UV=te("ZodBase64URL",(e,t)=>{mU.init(e,t),Ct.init(e,t)}),VV=te("ZodE164",(e,t)=>{pU.init(e,t),Ct.init(e,t)}),BV=te("ZodJWT",(e,t)=>{xU.init(e,t),Ct.init(e,t)}),Dj=te("ZodNumber",(e,t)=>{Sj.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>L8(e,a,s),e.gt=(a,s)=>e.check(iw(a,s)),e.gte=(a,s)=>e.check(Om(a,s)),e.min=(a,s)=>e.check(Om(a,s)),e.lt=(a,s)=>e.check(aw(a,s)),e.lte=(a,s)=>e.check(Am(a,s)),e.max=(a,s)=>e.check(Am(a,s)),e.int=a=>e.check(lw(a)),e.safe=a=>e.check(lw(a)),e.positive=a=>e.check(iw(0,a)),e.nonnegative=a=>e.check(Om(0,a)),e.negative=a=>e.check(aw(0,a)),e.nonpositive=a=>e.check(Am(0,a)),e.multipleOf=(a,s)=>e.check(sw(a,s)),e.step=(a,s)=>e.check(sw(a,s)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Tr(e){return m8(Dj,e)}const ZV=te("ZodNumberFormat",(e,t)=>{yU.init(e,t),Dj.init(e,t)});function lw(e){return p8(ZV,e)}const IV=te("ZodBoolean",(e,t)=>{bU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>P8(e,n,a)});function Ua(e){return g8(IV,e)}const HV=te("ZodUnknown",(e,t)=>{vU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>V8()});function uw(){return x8(HV)}const FV=te("ZodNever",(e,t)=>{kU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>U8(e,n,a)});function qV(e){return y8(FV,e)}const GV=te("ZodArray",(e,t)=>{wU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>F8(e,n,a,s),e.element=t.element,e.min=(n,a)=>e.check(Xc(n,a)),e.nonempty=n=>e.check(Xc(1,n)),e.max=(n,a)=>e.check(Cj(n,a)),e.length=(n,a)=>e.check(Ej(n,a)),e.unwrap=()=>e.element});function Ys(e,t){return T8(GV,e,t)}const YV=te("ZodObject",(e,t)=>{zU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>q8(e,n,a,s),et(e,"shape",()=>t.shape),e.keyof=()=>bd(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:uw()}),e.loose=()=>e.clone({...e._zod.def,catchall:uw()}),e.strict=()=>e.clone({...e._zod.def,catchall:qV()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>F9(e,n),e.safeExtend=n=>q9(e,n),e.merge=n=>G9(e,n),e.pick=n=>I9(e,n),e.omit=n=>H9(e,n),e.partial=(...n)=>Y9(Pj,e,n[0]),e.required=(...n)=>K9(Uj,e,n[0])});function dn(e,t){const n={type:"object",shape:e??{},...ze(t)};return new YV(n)}const $j=te("ZodUnion",(e,t)=>{jj.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>G8(e,n,a,s),e.options=t.options});function Lj(e,t){return new $j({type:"union",options:e,...ze(t)})}const KV=te("ZodDiscriminatedUnion",(e,t)=>{$j.init(e,t),_U.init(e,t)});function XV(e,t,n){return new KV({type:"union",options:t,discriminator:e,...ze(n)})}const JV=te("ZodIntersection",(e,t)=>{jU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>Y8(e,n,a,s)});function QV(e,t){return new JV({type:"intersection",left:e,right:t})}const WV=te("ZodRecord",(e,t)=>{NU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>K8(e,n,a,s),e.keyType=t.keyType,e.valueType=t.valueType});function $c(e,t,n){return new WV({type:"record",keyType:e,valueType:t,...ze(n)})}const Up=te("ZodEnum",(e,t)=>{CU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>B8(e,a,s),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(a,s)=>{const u={};for(const l of a)if(n.has(l))u[l]=t.entries[l];else throw new Error(`Key ${l} not found in enum`);return new Up({...t,checks:[],...ze(s),entries:u})},e.exclude=(a,s)=>{const u={...t.entries};for(const l of a)if(n.has(l))delete u[l];else throw new Error(`Key ${l} not found in enum`);return new Up({...t,checks:[],...ze(s),entries:u})}});function bd(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(a=>[a,a])):e;return new Up({type:"enum",entries:n,...ze(t)})}const eB=te("ZodLiteral",(e,t)=>{EU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>Z8(e,n,a),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function cw(e,t){return new eB({type:"literal",values:Array.isArray(e)?e:[e],...ze(t)})}const tB=te("ZodTransform",(e,t)=>{TU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>H8(e,n),e._zod.parse=(n,a)=>{if(a.direction==="backward")throw new oj(e.constructor.name);n.addIssue=u=>{if(typeof u=="string")n.issues.push(Rl(u,n.value,t));else{const l=u;l.fatal&&(l.continue=!1),l.code??(l.code="custom"),l.input??(l.input=n.value),l.inst??(l.inst=e),n.issues.push(Rl(l))}};const s=t.transform(n.value,n);return s instanceof Promise?s.then(u=>(n.value=u,n)):(n.value=s,n)}});function nB(e){return new tB({type:"transform",transform:e})}const Pj=te("ZodOptional",(e,t)=>{Nj.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>Rj(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function dw(e){return new Pj({type:"optional",innerType:e})}const rB=te("ZodExactOptional",(e,t)=>{AU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>Rj(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function aB(e){return new rB({type:"optional",innerType:e})}const iB=te("ZodNullable",(e,t)=>{OU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>X8(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function fw(e){return new iB({type:"nullable",innerType:e})}const sB=te("ZodDefault",(e,t)=>{RU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>Q8(e,n,a,s),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function oB(e,t){return new sB({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():dj(t)}})}const lB=te("ZodPrefault",(e,t)=>{MU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>W8(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function uB(e,t){return new lB({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():dj(t)}})}const Uj=te("ZodNonOptional",(e,t)=>{DU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>J8(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function cB(e,t){return new Uj({type:"nonoptional",innerType:e,...ze(t)})}const dB=te("ZodCatch",(e,t)=>{$U.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>eV(e,n,a,s),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function fB(e,t){return new dB({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const hB=te("ZodPipe",(e,t)=>{LU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>tV(e,n,a,s),e.in=t.in,e.out=t.out});function hw(e,t){return new hB({type:"pipe",in:e,out:t})}const mB=te("ZodReadonly",(e,t)=>{PU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>nV(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function pB(e){return new mB({type:"readonly",innerType:e})}const gB=te("ZodCustom",(e,t)=>{UU.init(e,t),Nt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>I8(e,n)});function xB(e,t={}){return A8(gB,e,t)}function yB(e){return O8(e)}const ft={agent:{name:"morpheus",personality:"helpful_dev"},logging:{enabled:!0,level:"info",retention:"14d"},audio:{provider:"google",model:"gemini-2.5-flash-lite",enabled:!0,maxDurationSeconds:300,supportedMimeTypes:["audio/ogg","audio/mp3","audio/mpeg","audio/wav"]},memory:{limit:100},runtime:{async_tasks:{enabled:!0}},llm:{provider:"openai",model:"gpt-4",temperature:.7,context_window:100},channels:{telegram:{enabled:!1,allowedUsers:[]},discord:{enabled:!1,allowedUsers:[]}},ui:{enabled:!0,port:3333}},bB=dn({provider:bd(["google","openai","openrouter","ollama"]).default(ft.audio.provider),model:We().min(1).default(ft.audio.model),enabled:Ua().default(ft.audio.enabled),apiKey:We().optional(),base_url:We().optional(),maxDurationSeconds:Tr().default(ft.audio.maxDurationSeconds),supportedMimeTypes:Ys(We()).default(ft.audio.supportedMimeTypes)}),Fl=dn({provider:bd(["openai","anthropic","openrouter","ollama","gemini"]).default(ft.llm.provider),model:We().min(1).default(ft.llm.model),temperature:Tr().min(0).max(1).default(ft.llm.temperature),max_tokens:Tr().int().positive().optional(),api_key:We().optional(),base_url:We().optional(),context_window:Tr().int().positive().optional()}),vB=Fl.extend({memory_limit:Tr().int().positive().optional(),enabled_archived_sessions:Ua().default(!0)}),kB=Fl.extend({working_dir:We().optional(),timeout_ms:Tr().int().positive().optional()}),wB=Fl,SB=Fl,zB=dn({telegram_notify_all:Ua().optional()}).optional(),_B=dn({timezone:We().default("UTC"),check_interval_ms:Tr().min(6e4).default(6e4),max_active_jobs:Tr().min(1).max(1e3).default(100)}),jB=dn({agent:dn({name:We().default(ft.agent.name),personality:We().default(ft.agent.personality)}).default(ft.agent),llm:Fl.default(ft.llm),sati:vB.optional(),neo:wB.optional(),apoc:kB.optional(),trinity:SB.optional(),webhooks:zB,audio:bB.default(ft.audio),memory:dn({limit:Tr().int().positive().optional()}).default(ft.memory),runtime:dn({async_tasks:dn({enabled:Ua().default(ft.runtime?.async_tasks.enabled)}).default(ft.runtime?.async_tasks??{enabled:!0})}).optional(),chronos:_B.optional(),channels:dn({telegram:dn({enabled:Ua().default(!1),token:We().optional(),allowedUsers:Ys(We()).default([])}).default(ft.channels.telegram),discord:dn({enabled:Ua().default(!1),token:We().optional(),allowedUsers:Ys(We()).default([])}).default(ft.channels.discord)}).default(ft.channels),ui:dn({enabled:Ua().default(ft.ui.enabled),port:Tr().default(ft.ui.port)}).default(ft.ui),logging:dn({enabled:Ua().default(ft.logging.enabled),level:bd(["debug","info","warn","error"]).default(ft.logging.level),retention:We().default(ft.logging.retention)}).default(ft.logging)}),NB=XV("transport",[dn({transport:cw("stdio"),command:We().min(1,"Command is required for stdio transport"),args:Ys(We()).optional().default([]),env:$c(We(),We()).optional().default({}),_comment:We().optional()}),dn({transport:cw("http"),url:We().url("Valid URL is required for http transport"),headers:$c(We(),We()).optional().default({}),args:Ys(We()).optional().default([]),env:$c(We(),We()).optional().default({}),_comment:We().optional()})]);$c(We(),Lj([NB,We()]));function ie(e,t,n){function a(f,h){if(f._zod||Object.defineProperty(f,"_zod",{value:{def:h,constr:l,traits:new Set},enumerable:!1}),f._zod.traits.has(e))return;f._zod.traits.add(e),t(f,h);const m=l.prototype,g=Object.keys(m);for(let y=0;y<g.length;y++){const v=g[y];v in f||(f[v]=m[v].bind(f))}}const s=n?.Parent??Object;class u extends s{}Object.defineProperty(u,"name",{value:e});function l(f){var h;const m=n?.Parent?new u:this;a(m,f),(h=m._zod).deferred??(h.deferred=[]);for(const g of m._zod.deferred)g();return m}return Object.defineProperty(l,"init",{value:a}),Object.defineProperty(l,Symbol.hasInstance,{value:f=>n?.Parent&&f instanceof n.Parent?!0:f?._zod?.traits?.has(e)}),Object.defineProperty(l,"name",{value:e}),l}class Is extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Vj extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Bj={};function Ai(e){return Bj}function Zj(e){const t=Object.values(e).filter(a=>typeof a=="number");return Object.entries(e).filter(([a,s])=>t.indexOf(+a)===-1).map(([a,s])=>s)}function Vp(e,t){return typeof t=="bigint"?t.toString():t}function rx(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function ax(e){return e==null}function ix(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const mw=Symbol("evaluating");function rt(e,t,n){let a;Object.defineProperty(e,t,{get(){if(a!==mw)return a===void 0&&(a=mw,a=n()),a},set(s){Object.defineProperty(e,t,{value:s})},configurable:!0})}function Di(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Qa(...e){const t={};for(const n of e){const a=Object.getOwnPropertyDescriptors(n);Object.assign(t,a)}return Object.defineProperties({},t)}function pw(e){return JSON.stringify(e)}function CB(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Ij="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Qc(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const EB=rx(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function Ml(e){if(Qc(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(Qc(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Hj(e){return Ml(e)?{...e}:Array.isArray(e)?[...e]:e}const TB=new Set(["string","number","symbol"]);function Ks(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Wa(e,t,n){const a=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(a._zod.parent=e),a}function Te(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function AB(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}function OB(e,t){const n=e._zod.def,a=n.checks;if(a&&a.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const u=Qa(e._zod.def,{get shape(){const l={};for(const f in t){if(!(f in n.shape))throw new Error(`Unrecognized key: "${f}"`);t[f]&&(l[f]=n.shape[f])}return Di(this,"shape",l),l},checks:[]});return Wa(e,u)}function RB(e,t){const n=e._zod.def,a=n.checks;if(a&&a.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const u=Qa(e._zod.def,{get shape(){const l={...e._zod.def.shape};for(const f in t){if(!(f in n.shape))throw new Error(`Unrecognized key: "${f}"`);t[f]&&delete l[f]}return Di(this,"shape",l),l},checks:[]});return Wa(e,u)}function MB(e,t){if(!Ml(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const u=e._zod.def.shape;for(const l in t)if(Object.getOwnPropertyDescriptor(u,l)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const s=Qa(e._zod.def,{get shape(){const u={...e._zod.def.shape,...t};return Di(this,"shape",u),u}});return Wa(e,s)}function DB(e,t){if(!Ml(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Qa(e._zod.def,{get shape(){const a={...e._zod.def.shape,...t};return Di(this,"shape",a),a}});return Wa(e,n)}function $B(e,t){const n=Qa(e._zod.def,{get shape(){const a={...e._zod.def.shape,...t._zod.def.shape};return Di(this,"shape",a),a},get catchall(){return t._zod.def.catchall},checks:[]});return Wa(e,n)}function LB(e,t,n){const s=t._zod.def.checks;if(s&&s.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const l=Qa(t._zod.def,{get shape(){const f=t._zod.def.shape,h={...f};if(n)for(const m in n){if(!(m in f))throw new Error(`Unrecognized key: "${m}"`);n[m]&&(h[m]=e?new e({type:"optional",innerType:f[m]}):f[m])}else for(const m in f)h[m]=e?new e({type:"optional",innerType:f[m]}):f[m];return Di(this,"shape",h),h},checks:[]});return Wa(t,l)}function PB(e,t,n){const a=Qa(t._zod.def,{get shape(){const s=t._zod.def.shape,u={...s};if(n)for(const l in n){if(!(l in u))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(u[l]=new e({type:"nonoptional",innerType:s[l]}))}else for(const l in s)u[l]=new e({type:"nonoptional",innerType:s[l]});return Di(this,"shape",u),u}});return Wa(t,a)}function Ds(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Fj(e,t){return t.map(n=>{var a;return(a=n).path??(a.path=[]),n.path.unshift(e),n})}function Sc(e){return typeof e=="string"?e:e?.message}function Oi(e,t,n){const a={...e,path:e.path??[]};if(!e.message){const s=Sc(e.inst?._zod.def?.error?.(e))??Sc(t?.error?.(e))??Sc(n.customError?.(e))??Sc(n.localeError?.(e))??"Invalid input";a.message=s}return delete a.inst,delete a.continue,t?.reportInput||delete a.input,a}function sx(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Dl(...e){const[t,n,a]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:a}:{...t}}const qj=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Vp,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Gj=ie("$ZodError",qj),Yj=ie("$ZodError",qj,{Parent:Error});function UB(e,t=n=>n.message){const n={},a=[];for(const s of e.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(t(s))):a.push(t(s));return{formErrors:a,fieldErrors:n}}function VB(e,t=n=>n.message){const n={_errors:[]},a=s=>{for(const u of s.issues)if(u.code==="invalid_union"&&u.errors.length)u.errors.map(l=>a({issues:l}));else if(u.code==="invalid_key")a({issues:u.issues});else if(u.code==="invalid_element")a({issues:u.issues});else if(u.path.length===0)n._errors.push(t(u));else{let l=n,f=0;for(;f<u.path.length;){const h=u.path[f];f===u.path.length-1?(l[h]=l[h]||{_errors:[]},l[h]._errors.push(t(u))):l[h]=l[h]||{_errors:[]},l=l[h],f++}}};return a(e),n}const ox=e=>(t,n,a,s)=>{const u=a?Object.assign(a,{async:!1}):{async:!1},l=t._zod.run({value:n,issues:[]},u);if(l instanceof Promise)throw new Is;if(l.issues.length){const f=new(s?.Err??e)(l.issues.map(h=>Oi(h,u,Ai())));throw Ij(f,s?.callee),f}return l.value},lx=e=>async(t,n,a,s)=>{const u=a?Object.assign(a,{async:!0}):{async:!0};let l=t._zod.run({value:n,issues:[]},u);if(l instanceof Promise&&(l=await l),l.issues.length){const f=new(s?.Err??e)(l.issues.map(h=>Oi(h,u,Ai())));throw Ij(f,s?.callee),f}return l.value},vd=e=>(t,n,a)=>{const s=a?{...a,async:!1}:{async:!1},u=t._zod.run({value:n,issues:[]},s);if(u instanceof Promise)throw new Is;return u.issues.length?{success:!1,error:new(e??Gj)(u.issues.map(l=>Oi(l,s,Ai())))}:{success:!0,data:u.value}},BB=vd(Yj),kd=e=>async(t,n,a)=>{const s=a?Object.assign(a,{async:!0}):{async:!0};let u=t._zod.run({value:n,issues:[]},s);return u instanceof Promise&&(u=await u),u.issues.length?{success:!1,error:new e(u.issues.map(l=>Oi(l,s,Ai())))}:{success:!0,data:u.value}},ZB=kd(Yj),IB=e=>(t,n,a)=>{const s=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return ox(e)(t,n,s)},HB=e=>(t,n,a)=>ox(e)(t,n,a),FB=e=>async(t,n,a)=>{const s=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return lx(e)(t,n,s)},qB=e=>async(t,n,a)=>lx(e)(t,n,a),GB=e=>(t,n,a)=>{const s=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return vd(e)(t,n,s)},YB=e=>(t,n,a)=>vd(e)(t,n,a),KB=e=>async(t,n,a)=>{const s=a?Object.assign(a,{direction:"backward"}):{direction:"backward"};return kd(e)(t,n,s)},XB=e=>async(t,n,a)=>kd(e)(t,n,a),JB=/^[cC][^\s-]{8,}$/,QB=/^[0-9a-z]+$/,WB=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,eZ=/^[0-9a-vA-V]{20}$/,tZ=/^[A-Za-z0-9]{27}$/,nZ=/^[a-zA-Z0-9_-]{21}$/,rZ=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,aZ=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,gw=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,iZ=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,sZ="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function oZ(){return new RegExp(sZ,"u")}const lZ=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,uZ=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,cZ=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,dZ=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fZ=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Kj=/^[A-Za-z0-9_-]*$/,hZ=/^\+[1-9]\d{6,14}$/,Xj="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",mZ=new RegExp(`^${Xj}$`);function Jj(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function pZ(e){return new RegExp(`^${Jj(e)}$`)}function gZ(e){const t=Jj({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const a=`${t}(?:${n.join("|")})`;return new RegExp(`^${Xj}T(?:${a})$`)}const xZ=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},yZ=/^[^A-Z]*$/,bZ=/^[^a-z]*$/,Lr=ie("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),vZ=ie("$ZodCheckMaxLength",(e,t)=>{var n;Lr.init(e,t),(n=e._zod.def).when??(n.when=a=>{const s=a.value;return!ax(s)&&s.length!==void 0}),e._zod.onattach.push(a=>{const s=a._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<s&&(a._zod.bag.maximum=t.maximum)}),e._zod.check=a=>{const s=a.value;if(s.length<=t.maximum)return;const l=sx(s);a.issues.push({origin:l,code:"too_big",maximum:t.maximum,inclusive:!0,input:s,inst:e,continue:!t.abort})}}),kZ=ie("$ZodCheckMinLength",(e,t)=>{var n;Lr.init(e,t),(n=e._zod.def).when??(n.when=a=>{const s=a.value;return!ax(s)&&s.length!==void 0}),e._zod.onattach.push(a=>{const s=a._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>s&&(a._zod.bag.minimum=t.minimum)}),e._zod.check=a=>{const s=a.value;if(s.length>=t.minimum)return;const l=sx(s);a.issues.push({origin:l,code:"too_small",minimum:t.minimum,inclusive:!0,input:s,inst:e,continue:!t.abort})}}),wZ=ie("$ZodCheckLengthEquals",(e,t)=>{var n;Lr.init(e,t),(n=e._zod.def).when??(n.when=a=>{const s=a.value;return!ax(s)&&s.length!==void 0}),e._zod.onattach.push(a=>{const s=a._zod.bag;s.minimum=t.length,s.maximum=t.length,s.length=t.length}),e._zod.check=a=>{const s=a.value,u=s.length;if(u===t.length)return;const l=sx(s),f=u>t.length;a.issues.push({origin:l,...f?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:a.value,inst:e,continue:!t.abort})}}),wd=ie("$ZodCheckStringFormat",(e,t)=>{var n,a;Lr.init(e,t),e._zod.onattach.push(s=>{const u=s._zod.bag;u.format=t.format,t.pattern&&(u.patterns??(u.patterns=new Set),u.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=s=>{t.pattern.lastIndex=0,!t.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:t.format,input:s.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(a=e._zod).check??(a.check=()=>{})}),SZ=ie("$ZodCheckRegex",(e,t)=>{wd.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),zZ=ie("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=yZ),wd.init(e,t)}),_Z=ie("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=bZ),wd.init(e,t)}),jZ=ie("$ZodCheckIncludes",(e,t)=>{Lr.init(e,t);const n=Ks(t.includes),a=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=a,e._zod.onattach.push(s=>{const u=s._zod.bag;u.patterns??(u.patterns=new Set),u.patterns.add(a)}),e._zod.check=s=>{s.value.includes(t.includes,t.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:s.value,inst:e,continue:!t.abort})}}),NZ=ie("$ZodCheckStartsWith",(e,t)=>{Lr.init(e,t);const n=new RegExp(`^${Ks(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(a=>{const s=a._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),e._zod.check=a=>{a.value.startsWith(t.prefix)||a.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:a.value,inst:e,continue:!t.abort})}}),CZ=ie("$ZodCheckEndsWith",(e,t)=>{Lr.init(e,t);const n=new RegExp(`.*${Ks(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(a=>{const s=a._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(n)}),e._zod.check=a=>{a.value.endsWith(t.suffix)||a.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:a.value,inst:e,continue:!t.abort})}}),EZ=ie("$ZodCheckOverwrite",(e,t)=>{Lr.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class TZ{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const a=t.split(`
71
71
  `).filter(l=>l),s=Math.min(...a.map(l=>l.length-l.trimStart().length)),u=a.map(l=>l.slice(s)).map(l=>" ".repeat(this.indent*2)+l);for(const l of u)this.content.push(l)}compile(){const t=Function,n=this?.args,s=[...(this?.content??[""]).map(u=>` ${u}`)];return new t(...n,s.join(`
72
- `))}}const AZ={major:4,minor:3,patch:6},Ft=ie("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=AZ;const a=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&a.unshift(e);for(const s of a)for(const u of s._zod.onattach)u(e);if(a.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const s=(l,f,h)=>{let m=Ds(l),g;for(const y of f){if(y._zod.def.when){if(!y._zod.def.when(l))continue}else if(m)continue;const v=l.issues.length,b=y._zod.check(l);if(b instanceof Promise&&h?.async===!1)throw new Is;if(g||b instanceof Promise)g=(g??Promise.resolve()).then(async()=>{await b,l.issues.length!==v&&(m||(m=Ds(l,v)))});else{if(l.issues.length===v)continue;m||(m=Ds(l,v))}}return g?g.then(()=>l):l},u=(l,f,h)=>{if(Ds(l))return l.aborted=!0,l;const m=s(f,a,h);if(m instanceof Promise){if(h.async===!1)throw new Is;return m.then(g=>e._zod.parse(g,h))}return e._zod.parse(m,h)};e._zod.run=(l,f)=>{if(f.skipChecks)return e._zod.parse(l,f);if(f.direction==="backward"){const m=e._zod.parse({value:l.value,issues:[]},{...f,skipChecks:!0});return m instanceof Promise?m.then(g=>u(g,l,f)):u(m,l,f)}const h=e._zod.parse(l,f);if(h instanceof Promise){if(f.async===!1)throw new Is;return h.then(m=>s(m,a,f))}return s(h,a,f)}}rt(e,"~standard",()=>({validate:s=>{try{const u=BB(e,s);return u.success?{value:u.data}:{issues:u.error?.issues}}catch{return ZB(e,s).then(l=>l.success?{value:l.data}:{issues:l.error?.issues})}},vendor:"zod",version:1}))}),ux=ie("$ZodString",(e,t)=>{Ft.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??xZ(e._zod.bag),e._zod.parse=(n,a)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),St=ie("$ZodStringFormat",(e,t)=>{wd.init(e,t),ux.init(e,t)}),OZ=ie("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=aZ),St.init(e,t)}),RZ=ie("$ZodUUID",(e,t)=>{if(t.version){const a={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(a===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=gw(a))}else t.pattern??(t.pattern=gw());St.init(e,t)}),MZ=ie("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=iZ),St.init(e,t)}),DZ=ie("$ZodURL",(e,t)=>{St.init(e,t),e._zod.check=n=>{try{const a=n.value.trim(),s=new URL(a);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(s.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=s.href:n.value=a;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),$Z=ie("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=oZ()),St.init(e,t)}),LZ=ie("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=nZ),St.init(e,t)}),PZ=ie("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=JB),St.init(e,t)}),UZ=ie("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=QB),St.init(e,t)}),VZ=ie("$ZodULID",(e,t)=>{t.pattern??(t.pattern=WB),St.init(e,t)}),BZ=ie("$ZodXID",(e,t)=>{t.pattern??(t.pattern=eZ),St.init(e,t)}),ZZ=ie("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=tZ),St.init(e,t)}),IZ=ie("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=gZ(t)),St.init(e,t)}),HZ=ie("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=mZ),St.init(e,t)}),FZ=ie("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=pZ(t)),St.init(e,t)}),qZ=ie("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=rZ),St.init(e,t)}),GZ=ie("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=lZ),St.init(e,t),e._zod.bag.format="ipv4"}),YZ=ie("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=uZ),St.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),KZ=ie("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=cZ),St.init(e,t)}),XZ=ie("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=dZ),St.init(e,t),e._zod.check=n=>{const a=n.value.split("/");try{if(a.length!==2)throw new Error;const[s,u]=a;if(!u)throw new Error;const l=Number(u);if(`${l}`!==u)throw new Error;if(l<0||l>128)throw new Error;new URL(`http://[${s}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Qj(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const JZ=ie("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=fZ),St.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Qj(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function QZ(e){if(!Kj.test(e))return!1;const t=e.replace(/[-_]/g,a=>a==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Qj(n)}const WZ=ie("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Kj),St.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{QZ(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),e7=ie("$ZodE164",(e,t)=>{t.pattern??(t.pattern=hZ),St.init(e,t)});function t7(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[a]=n;if(!a)return!1;const s=JSON.parse(atob(a));return!("typ"in s&&s?.typ!=="JWT"||!s.alg||t&&(!("alg"in s)||s.alg!==t))}catch{return!1}}const n7=ie("$ZodJWT",(e,t)=>{St.init(e,t),e._zod.check=n=>{t7(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),r7=ie("$ZodUnknown",(e,t)=>{Ft.init(e,t),e._zod.parse=n=>n}),a7=ie("$ZodNever",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function xw(e,t,n){e.issues.length&&t.issues.push(...Fj(n,e.issues)),t.value[n]=e.value}const i7=ie("$ZodArray",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>{const s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:e}),n;n.value=Array(s.length);const u=[];for(let l=0;l<s.length;l++){const f=s[l],h=t.element._zod.run({value:f,issues:[]},a);h instanceof Promise?u.push(h.then(m=>xw(m,n,l))):xw(h,n,l)}return u.length?Promise.all(u).then(()=>n):n}});function Wc(e,t,n,a,s){if(e.issues.length){if(s&&!(n in a))return;t.issues.push(...Fj(n,e.issues))}e.value===void 0?n in a&&(t.value[n]=void 0):t.value[n]=e.value}function Wj(e){const t=Object.keys(e.shape);for(const a of t)if(!e.shape?.[a]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=AB(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function e2(e,t,n,a,s,u){const l=[],f=s.keySet,h=s.catchall._zod,m=h.def.type,g=h.optout==="optional";for(const y in t){if(f.has(y))continue;if(m==="never"){l.push(y);continue}const v=h.run({value:t[y],issues:[]},a);v instanceof Promise?e.push(v.then(b=>Wc(b,n,y,t,g))):Wc(v,n,y,t,g)}return l.length&&n.issues.push({code:"unrecognized_keys",keys:l,input:t,inst:u}),e.length?Promise.all(e).then(()=>n):n}const s7=ie("$ZodObject",(e,t)=>{if(Ft.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const f=t.shape;Object.defineProperty(t,"shape",{get:()=>{const h={...f};return Object.defineProperty(t,"shape",{value:h}),h}})}const a=rx(()=>Wj(t));rt(e._zod,"propValues",()=>{const f=t.shape,h={};for(const m in f){const g=f[m]._zod;if(g.values){h[m]??(h[m]=new Set);for(const y of g.values)h[m].add(y)}}return h});const s=Qc,u=t.catchall;let l;e._zod.parse=(f,h)=>{l??(l=a.value);const m=f.value;if(!s(m))return f.issues.push({expected:"object",code:"invalid_type",input:m,inst:e}),f;f.value={};const g=[],y=l.shape;for(const v of l.keys){const b=y[v],S=b._zod.optout==="optional",j=b._zod.run({value:m[v],issues:[]},h);j instanceof Promise?g.push(j.then(A=>Wc(A,f,v,m,S))):Wc(j,f,v,m,S)}return u?e2(g,m,f,h,a.value,e):g.length?Promise.all(g).then(()=>f):f}}),o7=ie("$ZodObjectJIT",(e,t)=>{s7.init(e,t);const n=e._zod.parse,a=rx(()=>Wj(t)),s=v=>{const b=new TZ(["shape","payload","ctx"]),S=a.value,j=N=>{const L=pw(N);return`shape[${L}]._zod.run({ value: input[${L}], issues: [] }, ctx)`};b.write("const input = payload.value;");const A=Object.create(null);let E=0;for(const N of S.keys)A[N]=`key_${E++}`;b.write("const newResult = {};");for(const N of S.keys){const L=A[N],D=pw(N),q=v[N]?._zod?.optout==="optional";b.write(`const ${L} = ${j(N)};`),q?b.write(`
72
+ `))}}const AZ={major:4,minor:3,patch:6},Ft=ie("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=AZ;const a=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&a.unshift(e);for(const s of a)for(const u of s._zod.onattach)u(e);if(a.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const s=(l,f,h)=>{let m=Ds(l),g;for(const y of f){if(y._zod.def.when){if(!y._zod.def.when(l))continue}else if(m)continue;const v=l.issues.length,b=y._zod.check(l);if(b instanceof Promise&&h?.async===!1)throw new Is;if(g||b instanceof Promise)g=(g??Promise.resolve()).then(async()=>{await b,l.issues.length!==v&&(m||(m=Ds(l,v)))});else{if(l.issues.length===v)continue;m||(m=Ds(l,v))}}return g?g.then(()=>l):l},u=(l,f,h)=>{if(Ds(l))return l.aborted=!0,l;const m=s(f,a,h);if(m instanceof Promise){if(h.async===!1)throw new Is;return m.then(g=>e._zod.parse(g,h))}return e._zod.parse(m,h)};e._zod.run=(l,f)=>{if(f.skipChecks)return e._zod.parse(l,f);if(f.direction==="backward"){const m=e._zod.parse({value:l.value,issues:[]},{...f,skipChecks:!0});return m instanceof Promise?m.then(g=>u(g,l,f)):u(m,l,f)}const h=e._zod.parse(l,f);if(h instanceof Promise){if(f.async===!1)throw new Is;return h.then(m=>s(m,a,f))}return s(h,a,f)}}rt(e,"~standard",()=>({validate:s=>{try{const u=BB(e,s);return u.success?{value:u.data}:{issues:u.error?.issues}}catch{return ZB(e,s).then(l=>l.success?{value:l.data}:{issues:l.error?.issues})}},vendor:"zod",version:1}))}),ux=ie("$ZodString",(e,t)=>{Ft.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??xZ(e._zod.bag),e._zod.parse=(n,a)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),St=ie("$ZodStringFormat",(e,t)=>{wd.init(e,t),ux.init(e,t)}),OZ=ie("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=aZ),St.init(e,t)}),RZ=ie("$ZodUUID",(e,t)=>{if(t.version){const a={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(a===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=gw(a))}else t.pattern??(t.pattern=gw());St.init(e,t)}),MZ=ie("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=iZ),St.init(e,t)}),DZ=ie("$ZodURL",(e,t)=>{St.init(e,t),e._zod.check=n=>{try{const a=n.value.trim(),s=new URL(a);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(s.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=s.href:n.value=a;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),$Z=ie("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=oZ()),St.init(e,t)}),LZ=ie("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=nZ),St.init(e,t)}),PZ=ie("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=JB),St.init(e,t)}),UZ=ie("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=QB),St.init(e,t)}),VZ=ie("$ZodULID",(e,t)=>{t.pattern??(t.pattern=WB),St.init(e,t)}),BZ=ie("$ZodXID",(e,t)=>{t.pattern??(t.pattern=eZ),St.init(e,t)}),ZZ=ie("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=tZ),St.init(e,t)}),IZ=ie("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=gZ(t)),St.init(e,t)}),HZ=ie("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=mZ),St.init(e,t)}),FZ=ie("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=pZ(t)),St.init(e,t)}),qZ=ie("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=rZ),St.init(e,t)}),GZ=ie("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=lZ),St.init(e,t),e._zod.bag.format="ipv4"}),YZ=ie("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=uZ),St.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),KZ=ie("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=cZ),St.init(e,t)}),XZ=ie("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=dZ),St.init(e,t),e._zod.check=n=>{const a=n.value.split("/");try{if(a.length!==2)throw new Error;const[s,u]=a;if(!u)throw new Error;const l=Number(u);if(`${l}`!==u)throw new Error;if(l<0||l>128)throw new Error;new URL(`http://[${s}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Qj(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const JZ=ie("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=fZ),St.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Qj(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function QZ(e){if(!Kj.test(e))return!1;const t=e.replace(/[-_]/g,a=>a==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return Qj(n)}const WZ=ie("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Kj),St.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{QZ(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),eI=ie("$ZodE164",(e,t)=>{t.pattern??(t.pattern=hZ),St.init(e,t)});function tI(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[a]=n;if(!a)return!1;const s=JSON.parse(atob(a));return!("typ"in s&&s?.typ!=="JWT"||!s.alg||t&&(!("alg"in s)||s.alg!==t))}catch{return!1}}const nI=ie("$ZodJWT",(e,t)=>{St.init(e,t),e._zod.check=n=>{tI(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),rI=ie("$ZodUnknown",(e,t)=>{Ft.init(e,t),e._zod.parse=n=>n}),aI=ie("$ZodNever",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function xw(e,t,n){e.issues.length&&t.issues.push(...Fj(n,e.issues)),t.value[n]=e.value}const iI=ie("$ZodArray",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>{const s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:e}),n;n.value=Array(s.length);const u=[];for(let l=0;l<s.length;l++){const f=s[l],h=t.element._zod.run({value:f,issues:[]},a);h instanceof Promise?u.push(h.then(m=>xw(m,n,l))):xw(h,n,l)}return u.length?Promise.all(u).then(()=>n):n}});function Wc(e,t,n,a,s){if(e.issues.length){if(s&&!(n in a))return;t.issues.push(...Fj(n,e.issues))}e.value===void 0?n in a&&(t.value[n]=void 0):t.value[n]=e.value}function Wj(e){const t=Object.keys(e.shape);for(const a of t)if(!e.shape?.[a]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=AB(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function e2(e,t,n,a,s,u){const l=[],f=s.keySet,h=s.catchall._zod,m=h.def.type,g=h.optout==="optional";for(const y in t){if(f.has(y))continue;if(m==="never"){l.push(y);continue}const v=h.run({value:t[y],issues:[]},a);v instanceof Promise?e.push(v.then(b=>Wc(b,n,y,t,g))):Wc(v,n,y,t,g)}return l.length&&n.issues.push({code:"unrecognized_keys",keys:l,input:t,inst:u}),e.length?Promise.all(e).then(()=>n):n}const sI=ie("$ZodObject",(e,t)=>{if(Ft.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const f=t.shape;Object.defineProperty(t,"shape",{get:()=>{const h={...f};return Object.defineProperty(t,"shape",{value:h}),h}})}const a=rx(()=>Wj(t));rt(e._zod,"propValues",()=>{const f=t.shape,h={};for(const m in f){const g=f[m]._zod;if(g.values){h[m]??(h[m]=new Set);for(const y of g.values)h[m].add(y)}}return h});const s=Qc,u=t.catchall;let l;e._zod.parse=(f,h)=>{l??(l=a.value);const m=f.value;if(!s(m))return f.issues.push({expected:"object",code:"invalid_type",input:m,inst:e}),f;f.value={};const g=[],y=l.shape;for(const v of l.keys){const b=y[v],S=b._zod.optout==="optional",j=b._zod.run({value:m[v],issues:[]},h);j instanceof Promise?g.push(j.then(A=>Wc(A,f,v,m,S))):Wc(j,f,v,m,S)}return u?e2(g,m,f,h,a.value,e):g.length?Promise.all(g).then(()=>f):f}}),oI=ie("$ZodObjectJIT",(e,t)=>{sI.init(e,t);const n=e._zod.parse,a=rx(()=>Wj(t)),s=v=>{const b=new TZ(["shape","payload","ctx"]),S=a.value,j=N=>{const L=pw(N);return`shape[${L}]._zod.run({ value: input[${L}], issues: [] }, ctx)`};b.write("const input = payload.value;");const A=Object.create(null);let E=0;for(const N of S.keys)A[N]=`key_${E++}`;b.write("const newResult = {};");for(const N of S.keys){const L=A[N],D=pw(N),q=v[N]?._zod?.optout==="optional";b.write(`const ${L} = ${j(N)};`),q?b.write(`
73
73
  if (${L}.issues.length) {
74
74
  if (${D} in input) {
75
75
  payload.issues = payload.issues.concat(${L}.issues.map(iss => ({
@@ -103,9 +103,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
103
103
  newResult[${D}] = ${L}.value;
104
104
  }
105
105
 
106
- `)}b.write("payload.value = newResult;"),b.write("return payload;");const O=b.compile();return(N,L)=>O(v,N,L)};let u;const l=Qc,f=!Bj.jitless,m=f&&EB.value,g=t.catchall;let y;e._zod.parse=(v,b)=>{y??(y=a.value);const S=v.value;return l(S)?f&&m&&b?.async===!1&&b.jitless!==!0?(u||(u=s(t.shape)),v=u(v,b),g?e2([],S,v,b,y,e):v):n(v,b):(v.issues.push({expected:"object",code:"invalid_type",input:S,inst:e}),v)}});function yw(e,t,n,a){for(const u of e)if(u.issues.length===0)return t.value=u.value,t;const s=e.filter(u=>!Ds(u));return s.length===1?(t.value=s[0].value,s[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(u=>u.issues.map(l=>Oi(l,a,Ai())))}),t)}const l7=ie("$ZodUnion",(e,t)=>{Ft.init(e,t),rt(e._zod,"optin",()=>t.options.some(s=>s._zod.optin==="optional")?"optional":void 0),rt(e._zod,"optout",()=>t.options.some(s=>s._zod.optout==="optional")?"optional":void 0),rt(e._zod,"values",()=>{if(t.options.every(s=>s._zod.values))return new Set(t.options.flatMap(s=>Array.from(s._zod.values)))}),rt(e._zod,"pattern",()=>{if(t.options.every(s=>s._zod.pattern)){const s=t.options.map(u=>u._zod.pattern);return new RegExp(`^(${s.map(u=>ix(u.source)).join("|")})$`)}});const n=t.options.length===1,a=t.options[0]._zod.run;e._zod.parse=(s,u)=>{if(n)return a(s,u);let l=!1;const f=[];for(const h of t.options){const m=h._zod.run({value:s.value,issues:[]},u);if(m instanceof Promise)f.push(m),l=!0;else{if(m.issues.length===0)return m;f.push(m)}}return l?Promise.all(f).then(h=>yw(h,s,e,u)):yw(f,s,e,u)}}),u7=ie("$ZodIntersection",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>{const s=n.value,u=t.left._zod.run({value:s,issues:[]},a),l=t.right._zod.run({value:s,issues:[]},a);return u instanceof Promise||l instanceof Promise?Promise.all([u,l]).then(([h,m])=>bw(n,h,m)):bw(n,u,l)}});function Bp(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ml(e)&&Ml(t)){const n=Object.keys(t),a=Object.keys(e).filter(u=>n.indexOf(u)!==-1),s={...e,...t};for(const u of a){const l=Bp(e[u],t[u]);if(!l.valid)return{valid:!1,mergeErrorPath:[u,...l.mergeErrorPath]};s[u]=l.data}return{valid:!0,data:s}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let a=0;a<e.length;a++){const s=e[a],u=t[a],l=Bp(s,u);if(!l.valid)return{valid:!1,mergeErrorPath:[a,...l.mergeErrorPath]};n.push(l.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function bw(e,t,n){const a=new Map;let s;for(const f of t.issues)if(f.code==="unrecognized_keys"){s??(s=f);for(const h of f.keys)a.has(h)||a.set(h,{}),a.get(h).l=!0}else e.issues.push(f);for(const f of n.issues)if(f.code==="unrecognized_keys")for(const h of f.keys)a.has(h)||a.set(h,{}),a.get(h).r=!0;else e.issues.push(f);const u=[...a].filter(([,f])=>f.l&&f.r).map(([f])=>f);if(u.length&&s&&e.issues.push({...s,keys:u}),Ds(e))return e;const l=Bp(t.value,n.value);if(!l.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(l.mergeErrorPath)}`);return e.value=l.data,e}const c7=ie("$ZodEnum",(e,t)=>{Ft.init(e,t);const n=Zj(t.entries),a=new Set(n);e._zod.values=a,e._zod.pattern=new RegExp(`^(${n.filter(s=>TB.has(typeof s)).map(s=>typeof s=="string"?Ks(s):s.toString()).join("|")})$`),e._zod.parse=(s,u)=>{const l=s.value;return a.has(l)||s.issues.push({code:"invalid_value",values:n,input:l,inst:e}),s}}),d7=ie("$ZodLiteral",(e,t)=>{if(Ft.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(a=>typeof a=="string"?Ks(a):a?Ks(a.toString()):String(a)).join("|")})$`),e._zod.parse=(a,s)=>{const u=a.value;return n.has(u)||a.issues.push({code:"invalid_value",values:t.values,input:u,inst:e}),a}}),f7=ie("$ZodTransform",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>{if(a.direction==="backward")throw new Vj(e.constructor.name);const s=t.transform(n.value,n);if(a.async)return(s instanceof Promise?s:Promise.resolve(s)).then(l=>(n.value=l,n));if(s instanceof Promise)throw new Is;return n.value=s,n}});function vw(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const t2=ie("$ZodOptional",(e,t)=>{Ft.init(e,t),e._zod.optin="optional",e._zod.optout="optional",rt(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),rt(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${ix(n.source)})?$`):void 0}),e._zod.parse=(n,a)=>{if(t.innerType._zod.optin==="optional"){const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>vw(u,n.value)):vw(s,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,a)}}),h7=ie("$ZodExactOptional",(e,t)=>{t2.init(e,t),rt(e._zod,"values",()=>t.innerType._zod.values),rt(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,a)=>t.innerType._zod.run(n,a)}),m7=ie("$ZodNullable",(e,t)=>{Ft.init(e,t),rt(e._zod,"optin",()=>t.innerType._zod.optin),rt(e._zod,"optout",()=>t.innerType._zod.optout),rt(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${ix(n.source)}|null)$`):void 0}),rt(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,a)=>n.value===null?n:t.innerType._zod.run(n,a)}),p7=ie("$ZodDefault",(e,t)=>{Ft.init(e,t),e._zod.optin="optional",rt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,a)=>{if(a.direction==="backward")return t.innerType._zod.run(n,a);if(n.value===void 0)return n.value=t.defaultValue,n;const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>kw(u,t)):kw(s,t)}});function kw(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const g7=ie("$ZodPrefault",(e,t)=>{Ft.init(e,t),e._zod.optin="optional",rt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,a)=>(a.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,a))}),x7=ie("$ZodNonOptional",(e,t)=>{Ft.init(e,t),rt(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(a=>a!==void 0)):void 0}),e._zod.parse=(n,a)=>{const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>ww(u,e)):ww(s,e)}});function ww(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const y7=ie("$ZodCatch",(e,t)=>{Ft.init(e,t),rt(e._zod,"optin",()=>t.innerType._zod.optin),rt(e._zod,"optout",()=>t.innerType._zod.optout),rt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,a)=>{if(a.direction==="backward")return t.innerType._zod.run(n,a);const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>(n.value=u.value,u.issues.length&&(n.value=t.catchValue({...n,error:{issues:u.issues.map(l=>Oi(l,a,Ai()))},input:n.value}),n.issues=[]),n)):(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(u=>Oi(u,a,Ai()))},input:n.value}),n.issues=[]),n)}}),b7=ie("$ZodPipe",(e,t)=>{Ft.init(e,t),rt(e._zod,"values",()=>t.in._zod.values),rt(e._zod,"optin",()=>t.in._zod.optin),rt(e._zod,"optout",()=>t.out._zod.optout),rt(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,a)=>{if(a.direction==="backward"){const u=t.out._zod.run(n,a);return u instanceof Promise?u.then(l=>zc(l,t.in,a)):zc(u,t.in,a)}const s=t.in._zod.run(n,a);return s instanceof Promise?s.then(u=>zc(u,t.out,a)):zc(s,t.out,a)}});function zc(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const v7=ie("$ZodReadonly",(e,t)=>{Ft.init(e,t),rt(e._zod,"propValues",()=>t.innerType._zod.propValues),rt(e._zod,"values",()=>t.innerType._zod.values),rt(e._zod,"optin",()=>t.innerType?._zod?.optin),rt(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,a)=>{if(a.direction==="backward")return t.innerType._zod.run(n,a);const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(Sw):Sw(s)}});function Sw(e){return e.value=Object.freeze(e.value),e}const k7=ie("$ZodCustom",(e,t)=>{Lr.init(e,t),Ft.init(e,t),e._zod.parse=(n,a)=>n,e._zod.check=n=>{const a=n.value,s=t.fn(a);if(s instanceof Promise)return s.then(u=>zw(u,n,a,e));zw(s,n,a,e)}});function zw(e,t,n,a){if(!e){const s={code:"custom",input:n,inst:a,path:[...a._zod.def.path??[]],continue:!a._zod.def.abort};a._zod.def.params&&(s.params=a._zod.def.params),t.issues.push(Dl(s))}}var _w;class w7{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const a=n[0];return this._map.set(t,a),a&&typeof a=="object"&&"id"in a&&this._idmap.set(a.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const a={...this.get(n)??{}};delete a.id;const s={...a,...this._map.get(t)};return Object.keys(s).length?s:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function S7(){return new w7}(_w=globalThis).__zod_globalRegistry??(_w.__zod_globalRegistry=S7());const ml=globalThis.__zod_globalRegistry;function z7(e,t){return new e({type:"string",...Te(t)})}function _7(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Te(t)})}function jw(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Te(t)})}function j7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Te(t)})}function N7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Te(t)})}function C7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Te(t)})}function E7(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Te(t)})}function T7(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Te(t)})}function A7(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Te(t)})}function O7(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Te(t)})}function R7(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Te(t)})}function M7(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Te(t)})}function D7(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Te(t)})}function $7(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Te(t)})}function L7(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Te(t)})}function P7(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Te(t)})}function U7(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Te(t)})}function V7(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Te(t)})}function B7(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Te(t)})}function Z7(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Te(t)})}function I7(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Te(t)})}function H7(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Te(t)})}function F7(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Te(t)})}function q7(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Te(t)})}function G7(e,t){return new e({type:"string",format:"date",check:"string_format",...Te(t)})}function Y7(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Te(t)})}function K7(e,t){return new e({type:"string",format:"duration",check:"string_format",...Te(t)})}function X7(e){return new e({type:"unknown"})}function J7(e,t){return new e({type:"never",...Te(t)})}function n2(e,t){return new vZ({check:"max_length",...Te(t),maximum:e})}function ed(e,t){return new kZ({check:"min_length",...Te(t),minimum:e})}function r2(e,t){return new wZ({check:"length_equals",...Te(t),length:e})}function Q7(e,t){return new SZ({check:"string_format",format:"regex",...Te(t),pattern:e})}function W7(e){return new zZ({check:"string_format",format:"lowercase",...Te(e)})}function eI(e){return new _Z({check:"string_format",format:"uppercase",...Te(e)})}function tI(e,t){return new jZ({check:"string_format",format:"includes",...Te(t),includes:e})}function nI(e,t){return new NZ({check:"string_format",format:"starts_with",...Te(t),prefix:e})}function rI(e,t){return new CZ({check:"string_format",format:"ends_with",...Te(t),suffix:e})}function oo(e){return new EZ({check:"overwrite",tx:e})}function aI(e){return oo(t=>t.normalize(e))}function iI(){return oo(e=>e.trim())}function sI(){return oo(e=>e.toLowerCase())}function oI(){return oo(e=>e.toUpperCase())}function lI(){return oo(e=>CB(e))}function uI(e,t,n){return new e({type:"array",element:t,...Te(n)})}function cI(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Te(n)})}function dI(e){const t=fI(n=>(n.addIssue=a=>{if(typeof a=="string")n.issues.push(Dl(a,n.value,t._zod.def));else{const s=a;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=t),s.continue??(s.continue=!t._zod.def.abort),n.issues.push(Dl(s))}},e(n.value,n)));return t}function fI(e,t){const n=new Lr({check:"custom",...Te(t)});return n._zod.check=e,n}function a2(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??ml,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 un(e,t,n={path:[],schemaPath:[]}){var a;const s=e._zod.def,u=t.seen.get(e);if(u)return u.count++,n.schemaPath.includes(e)&&(u.cycle=n.path),u.schema;const l={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,l);const f=e._zod.toJSONSchema?.();if(f)l.schema=f;else{const g={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,l.schema,g);else{const v=l.schema,b=t.processors[s.type];if(!b)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${s.type}`);b(e,t,v,g)}const y=e._zod.parent;y&&(l.ref||(l.ref=y),un(y,t,g),t.seen.get(y).isParent=!0)}const h=t.metadataRegistry.get(e);return h&&Object.assign(l.schema,h),t.io==="input"&&vn(e)&&(delete l.schema.examples,delete l.schema.default),t.io==="input"&&l.schema._prefault&&((a=l.schema).default??(a.default=l.schema._prefault)),delete l.schema._prefault,t.seen.get(e).schema}function i2(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const a=new Map;for(const l of e.seen.entries()){const f=e.metadataRegistry.get(l[0])?.id;if(f){const h=a.get(f);if(h&&h!==l[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);a.set(f,l[0])}}const s=l=>{const f=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const y=e.external.registry.get(l[0])?.id,v=e.external.uri??(S=>S);if(y)return{ref:v(y)};const b=l[1].defId??l[1].schema.id??`schema${e.counter++}`;return l[1].defId=b,{defId:b,ref:`${v("__shared")}#/${f}/${b}`}}if(l[1]===n)return{ref:"#"};const m=`#/${f}/`,g=l[1].schema.id??`__schema${e.counter++}`;return{defId:g,ref:m+g}},u=l=>{if(l[1].schema.$ref)return;const f=l[1],{ref:h,defId:m}=s(l);f.def={...f.schema},m&&(f.defId=m);const g=f.schema;for(const y in g)delete g[y];g.$ref=h};if(e.cycles==="throw")for(const l of e.seen.entries()){const f=l[1];if(f.cycle)throw new Error(`Cycle detected: #/${f.cycle?.join("/")}/<root>
106
+ `)}b.write("payload.value = newResult;"),b.write("return payload;");const O=b.compile();return(N,L)=>O(v,N,L)};let u;const l=Qc,f=!Bj.jitless,m=f&&EB.value,g=t.catchall;let y;e._zod.parse=(v,b)=>{y??(y=a.value);const S=v.value;return l(S)?f&&m&&b?.async===!1&&b.jitless!==!0?(u||(u=s(t.shape)),v=u(v,b),g?e2([],S,v,b,y,e):v):n(v,b):(v.issues.push({expected:"object",code:"invalid_type",input:S,inst:e}),v)}});function yw(e,t,n,a){for(const u of e)if(u.issues.length===0)return t.value=u.value,t;const s=e.filter(u=>!Ds(u));return s.length===1?(t.value=s[0].value,s[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(u=>u.issues.map(l=>Oi(l,a,Ai())))}),t)}const lI=ie("$ZodUnion",(e,t)=>{Ft.init(e,t),rt(e._zod,"optin",()=>t.options.some(s=>s._zod.optin==="optional")?"optional":void 0),rt(e._zod,"optout",()=>t.options.some(s=>s._zod.optout==="optional")?"optional":void 0),rt(e._zod,"values",()=>{if(t.options.every(s=>s._zod.values))return new Set(t.options.flatMap(s=>Array.from(s._zod.values)))}),rt(e._zod,"pattern",()=>{if(t.options.every(s=>s._zod.pattern)){const s=t.options.map(u=>u._zod.pattern);return new RegExp(`^(${s.map(u=>ix(u.source)).join("|")})$`)}});const n=t.options.length===1,a=t.options[0]._zod.run;e._zod.parse=(s,u)=>{if(n)return a(s,u);let l=!1;const f=[];for(const h of t.options){const m=h._zod.run({value:s.value,issues:[]},u);if(m instanceof Promise)f.push(m),l=!0;else{if(m.issues.length===0)return m;f.push(m)}}return l?Promise.all(f).then(h=>yw(h,s,e,u)):yw(f,s,e,u)}}),uI=ie("$ZodIntersection",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>{const s=n.value,u=t.left._zod.run({value:s,issues:[]},a),l=t.right._zod.run({value:s,issues:[]},a);return u instanceof Promise||l instanceof Promise?Promise.all([u,l]).then(([h,m])=>bw(n,h,m)):bw(n,u,l)}});function Bp(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ml(e)&&Ml(t)){const n=Object.keys(t),a=Object.keys(e).filter(u=>n.indexOf(u)!==-1),s={...e,...t};for(const u of a){const l=Bp(e[u],t[u]);if(!l.valid)return{valid:!1,mergeErrorPath:[u,...l.mergeErrorPath]};s[u]=l.data}return{valid:!0,data:s}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let a=0;a<e.length;a++){const s=e[a],u=t[a],l=Bp(s,u);if(!l.valid)return{valid:!1,mergeErrorPath:[a,...l.mergeErrorPath]};n.push(l.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function bw(e,t,n){const a=new Map;let s;for(const f of t.issues)if(f.code==="unrecognized_keys"){s??(s=f);for(const h of f.keys)a.has(h)||a.set(h,{}),a.get(h).l=!0}else e.issues.push(f);for(const f of n.issues)if(f.code==="unrecognized_keys")for(const h of f.keys)a.has(h)||a.set(h,{}),a.get(h).r=!0;else e.issues.push(f);const u=[...a].filter(([,f])=>f.l&&f.r).map(([f])=>f);if(u.length&&s&&e.issues.push({...s,keys:u}),Ds(e))return e;const l=Bp(t.value,n.value);if(!l.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(l.mergeErrorPath)}`);return e.value=l.data,e}const cI=ie("$ZodEnum",(e,t)=>{Ft.init(e,t);const n=Zj(t.entries),a=new Set(n);e._zod.values=a,e._zod.pattern=new RegExp(`^(${n.filter(s=>TB.has(typeof s)).map(s=>typeof s=="string"?Ks(s):s.toString()).join("|")})$`),e._zod.parse=(s,u)=>{const l=s.value;return a.has(l)||s.issues.push({code:"invalid_value",values:n,input:l,inst:e}),s}}),dI=ie("$ZodLiteral",(e,t)=>{if(Ft.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(a=>typeof a=="string"?Ks(a):a?Ks(a.toString()):String(a)).join("|")})$`),e._zod.parse=(a,s)=>{const u=a.value;return n.has(u)||a.issues.push({code:"invalid_value",values:t.values,input:u,inst:e}),a}}),fI=ie("$ZodTransform",(e,t)=>{Ft.init(e,t),e._zod.parse=(n,a)=>{if(a.direction==="backward")throw new Vj(e.constructor.name);const s=t.transform(n.value,n);if(a.async)return(s instanceof Promise?s:Promise.resolve(s)).then(l=>(n.value=l,n));if(s instanceof Promise)throw new Is;return n.value=s,n}});function vw(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const t2=ie("$ZodOptional",(e,t)=>{Ft.init(e,t),e._zod.optin="optional",e._zod.optout="optional",rt(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),rt(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${ix(n.source)})?$`):void 0}),e._zod.parse=(n,a)=>{if(t.innerType._zod.optin==="optional"){const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>vw(u,n.value)):vw(s,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,a)}}),hI=ie("$ZodExactOptional",(e,t)=>{t2.init(e,t),rt(e._zod,"values",()=>t.innerType._zod.values),rt(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,a)=>t.innerType._zod.run(n,a)}),mI=ie("$ZodNullable",(e,t)=>{Ft.init(e,t),rt(e._zod,"optin",()=>t.innerType._zod.optin),rt(e._zod,"optout",()=>t.innerType._zod.optout),rt(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${ix(n.source)}|null)$`):void 0}),rt(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,a)=>n.value===null?n:t.innerType._zod.run(n,a)}),pI=ie("$ZodDefault",(e,t)=>{Ft.init(e,t),e._zod.optin="optional",rt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,a)=>{if(a.direction==="backward")return t.innerType._zod.run(n,a);if(n.value===void 0)return n.value=t.defaultValue,n;const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>kw(u,t)):kw(s,t)}});function kw(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const gI=ie("$ZodPrefault",(e,t)=>{Ft.init(e,t),e._zod.optin="optional",rt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,a)=>(a.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,a))}),xI=ie("$ZodNonOptional",(e,t)=>{Ft.init(e,t),rt(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(a=>a!==void 0)):void 0}),e._zod.parse=(n,a)=>{const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>ww(u,e)):ww(s,e)}});function ww(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const yI=ie("$ZodCatch",(e,t)=>{Ft.init(e,t),rt(e._zod,"optin",()=>t.innerType._zod.optin),rt(e._zod,"optout",()=>t.innerType._zod.optout),rt(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,a)=>{if(a.direction==="backward")return t.innerType._zod.run(n,a);const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(u=>(n.value=u.value,u.issues.length&&(n.value=t.catchValue({...n,error:{issues:u.issues.map(l=>Oi(l,a,Ai()))},input:n.value}),n.issues=[]),n)):(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(u=>Oi(u,a,Ai()))},input:n.value}),n.issues=[]),n)}}),bI=ie("$ZodPipe",(e,t)=>{Ft.init(e,t),rt(e._zod,"values",()=>t.in._zod.values),rt(e._zod,"optin",()=>t.in._zod.optin),rt(e._zod,"optout",()=>t.out._zod.optout),rt(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,a)=>{if(a.direction==="backward"){const u=t.out._zod.run(n,a);return u instanceof Promise?u.then(l=>zc(l,t.in,a)):zc(u,t.in,a)}const s=t.in._zod.run(n,a);return s instanceof Promise?s.then(u=>zc(u,t.out,a)):zc(s,t.out,a)}});function zc(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const vI=ie("$ZodReadonly",(e,t)=>{Ft.init(e,t),rt(e._zod,"propValues",()=>t.innerType._zod.propValues),rt(e._zod,"values",()=>t.innerType._zod.values),rt(e._zod,"optin",()=>t.innerType?._zod?.optin),rt(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,a)=>{if(a.direction==="backward")return t.innerType._zod.run(n,a);const s=t.innerType._zod.run(n,a);return s instanceof Promise?s.then(Sw):Sw(s)}});function Sw(e){return e.value=Object.freeze(e.value),e}const kI=ie("$ZodCustom",(e,t)=>{Lr.init(e,t),Ft.init(e,t),e._zod.parse=(n,a)=>n,e._zod.check=n=>{const a=n.value,s=t.fn(a);if(s instanceof Promise)return s.then(u=>zw(u,n,a,e));zw(s,n,a,e)}});function zw(e,t,n,a){if(!e){const s={code:"custom",input:n,inst:a,path:[...a._zod.def.path??[]],continue:!a._zod.def.abort};a._zod.def.params&&(s.params=a._zod.def.params),t.issues.push(Dl(s))}}var _w;class wI{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const a=n[0];return this._map.set(t,a),a&&typeof a=="object"&&"id"in a&&this._idmap.set(a.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const a={...this.get(n)??{}};delete a.id;const s={...a,...this._map.get(t)};return Object.keys(s).length?s:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function SI(){return new wI}(_w=globalThis).__zod_globalRegistry??(_w.__zod_globalRegistry=SI());const ml=globalThis.__zod_globalRegistry;function zI(e,t){return new e({type:"string",...Te(t)})}function _I(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Te(t)})}function jw(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Te(t)})}function jI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Te(t)})}function NI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Te(t)})}function CI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Te(t)})}function EI(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Te(t)})}function TI(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Te(t)})}function AI(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Te(t)})}function OI(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Te(t)})}function RI(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Te(t)})}function MI(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Te(t)})}function DI(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Te(t)})}function $I(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Te(t)})}function LI(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Te(t)})}function PI(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Te(t)})}function UI(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Te(t)})}function VI(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Te(t)})}function BI(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Te(t)})}function ZI(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Te(t)})}function II(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Te(t)})}function HI(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Te(t)})}function FI(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Te(t)})}function qI(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Te(t)})}function GI(e,t){return new e({type:"string",format:"date",check:"string_format",...Te(t)})}function YI(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Te(t)})}function KI(e,t){return new e({type:"string",format:"duration",check:"string_format",...Te(t)})}function XI(e){return new e({type:"unknown"})}function JI(e,t){return new e({type:"never",...Te(t)})}function n2(e,t){return new vZ({check:"max_length",...Te(t),maximum:e})}function ed(e,t){return new kZ({check:"min_length",...Te(t),minimum:e})}function r2(e,t){return new wZ({check:"length_equals",...Te(t),length:e})}function QI(e,t){return new SZ({check:"string_format",format:"regex",...Te(t),pattern:e})}function WI(e){return new zZ({check:"string_format",format:"lowercase",...Te(e)})}function e7(e){return new _Z({check:"string_format",format:"uppercase",...Te(e)})}function t7(e,t){return new jZ({check:"string_format",format:"includes",...Te(t),includes:e})}function n7(e,t){return new NZ({check:"string_format",format:"starts_with",...Te(t),prefix:e})}function r7(e,t){return new CZ({check:"string_format",format:"ends_with",...Te(t),suffix:e})}function oo(e){return new EZ({check:"overwrite",tx:e})}function a7(e){return oo(t=>t.normalize(e))}function i7(){return oo(e=>e.trim())}function s7(){return oo(e=>e.toLowerCase())}function o7(){return oo(e=>e.toUpperCase())}function l7(){return oo(e=>CB(e))}function u7(e,t,n){return new e({type:"array",element:t,...Te(n)})}function c7(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Te(n)})}function d7(e){const t=f7(n=>(n.addIssue=a=>{if(typeof a=="string")n.issues.push(Dl(a,n.value,t._zod.def));else{const s=a;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=t),s.continue??(s.continue=!t._zod.def.abort),n.issues.push(Dl(s))}},e(n.value,n)));return t}function f7(e,t){const n=new Lr({check:"custom",...Te(t)});return n._zod.check=e,n}function a2(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??ml,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 un(e,t,n={path:[],schemaPath:[]}){var a;const s=e._zod.def,u=t.seen.get(e);if(u)return u.count++,n.schemaPath.includes(e)&&(u.cycle=n.path),u.schema;const l={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,l);const f=e._zod.toJSONSchema?.();if(f)l.schema=f;else{const g={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,l.schema,g);else{const v=l.schema,b=t.processors[s.type];if(!b)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${s.type}`);b(e,t,v,g)}const y=e._zod.parent;y&&(l.ref||(l.ref=y),un(y,t,g),t.seen.get(y).isParent=!0)}const h=t.metadataRegistry.get(e);return h&&Object.assign(l.schema,h),t.io==="input"&&vn(e)&&(delete l.schema.examples,delete l.schema.default),t.io==="input"&&l.schema._prefault&&((a=l.schema).default??(a.default=l.schema._prefault)),delete l.schema._prefault,t.seen.get(e).schema}function i2(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const a=new Map;for(const l of e.seen.entries()){const f=e.metadataRegistry.get(l[0])?.id;if(f){const h=a.get(f);if(h&&h!==l[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);a.set(f,l[0])}}const s=l=>{const f=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const y=e.external.registry.get(l[0])?.id,v=e.external.uri??(S=>S);if(y)return{ref:v(y)};const b=l[1].defId??l[1].schema.id??`schema${e.counter++}`;return l[1].defId=b,{defId:b,ref:`${v("__shared")}#/${f}/${b}`}}if(l[1]===n)return{ref:"#"};const m=`#/${f}/`,g=l[1].schema.id??`__schema${e.counter++}`;return{defId:g,ref:m+g}},u=l=>{if(l[1].schema.$ref)return;const f=l[1],{ref:h,defId:m}=s(l);f.def={...f.schema},m&&(f.defId=m);const g=f.schema;for(const y in g)delete g[y];g.$ref=h};if(e.cycles==="throw")for(const l of e.seen.entries()){const f=l[1];if(f.cycle)throw new Error(`Cycle detected: #/${f.cycle?.join("/")}/<root>
107
107
 
108
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const l of e.seen.entries()){const f=l[1];if(t===l[0]){u(l);continue}if(e.external){const m=e.external.registry.get(l[0])?.id;if(t!==l[0]&&m){u(l);continue}}if(e.metadataRegistry.get(l[0])?.id){u(l);continue}if(f.cycle){u(l);continue}if(f.count>1&&e.reused==="ref"){u(l);continue}}}function s2(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const a=l=>{const f=e.seen.get(l);if(f.ref===null)return;const h=f.def??f.schema,m={...h},g=f.ref;if(f.ref=null,g){a(g);const v=e.seen.get(g),b=v.schema;if(b.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(h.allOf=h.allOf??[],h.allOf.push(b)):Object.assign(h,b),Object.assign(h,m),l._zod.parent===g)for(const j in h)j==="$ref"||j==="allOf"||j in m||delete h[j];if(b.$ref&&v.def)for(const j in h)j==="$ref"||j==="allOf"||j in v.def&&JSON.stringify(h[j])===JSON.stringify(v.def[j])&&delete h[j]}const y=l._zod.parent;if(y&&y!==g){a(y);const v=e.seen.get(y);if(v?.schema.$ref&&(h.$ref=v.schema.$ref,v.def))for(const b in h)b==="$ref"||b==="allOf"||b in v.def&&JSON.stringify(h[b])===JSON.stringify(v.def[b])&&delete h[b]}e.override({zodSchema:l,jsonSchema:h,path:f.path??[]})};for(const l of[...e.seen.entries()].reverse())a(l[0]);const s={};if(e.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const l=e.external.registry.get(t)?.id;if(!l)throw new Error("Schema is missing an `id` property");s.$id=e.external.uri(l)}Object.assign(s,n.def??n.schema);const u=e.external?.defs??{};for(const l of e.seen.entries()){const f=l[1];f.def&&f.defId&&(u[f.defId]=f.def)}e.external||Object.keys(u).length>0&&(e.target==="draft-2020-12"?s.$defs=u:s.definitions=u);try{const l=JSON.parse(JSON.stringify(s));return Object.defineProperty(l,"~standard",{value:{...t["~standard"],jsonSchema:{input:td(t,"input",e.processors),output:td(t,"output",e.processors)}},enumerable:!1,writable:!1}),l}catch{throw new Error("Error converting schema to JSON.")}}function vn(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const a=e._zod.def;if(a.type==="transform")return!0;if(a.type==="array")return vn(a.element,n);if(a.type==="set")return vn(a.valueType,n);if(a.type==="lazy")return vn(a.getter(),n);if(a.type==="promise"||a.type==="optional"||a.type==="nonoptional"||a.type==="nullable"||a.type==="readonly"||a.type==="default"||a.type==="prefault")return vn(a.innerType,n);if(a.type==="intersection")return vn(a.left,n)||vn(a.right,n);if(a.type==="record"||a.type==="map")return vn(a.keyType,n)||vn(a.valueType,n);if(a.type==="pipe")return vn(a.in,n)||vn(a.out,n);if(a.type==="object"){for(const s in a.shape)if(vn(a.shape[s],n))return!0;return!1}if(a.type==="union"){for(const s of a.options)if(vn(s,n))return!0;return!1}if(a.type==="tuple"){for(const s of a.items)if(vn(s,n))return!0;return!!(a.rest&&vn(a.rest,n))}return!1}const hI=(e,t={})=>n=>{const a=a2({...n,processors:t});return un(e,a),i2(a,e),s2(a,e)},td=(e,t,n={})=>a=>{const{libraryOptions:s,target:u}=a??{},l=a2({...s??{},target:u,io:t,processors:n});return un(e,l),i2(l,e),s2(l,e)},mI={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},pI=(e,t,n,a)=>{const s=n;s.type="string";const{minimum:u,maximum:l,format:f,patterns:h,contentEncoding:m}=e._zod.bag;if(typeof u=="number"&&(s.minLength=u),typeof l=="number"&&(s.maxLength=l),f&&(s.format=mI[f]??f,s.format===""&&delete s.format,f==="time"&&delete s.format),m&&(s.contentEncoding=m),h&&h.size>0){const g=[...h];g.length===1?s.pattern=g[0].source:g.length>1&&(s.allOf=[...g.map(y=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:y.source}))])}},gI=(e,t,n,a)=>{n.not={}},xI=(e,t,n,a)=>{},yI=(e,t,n,a)=>{const s=e._zod.def,u=Zj(s.entries);u.every(l=>typeof l=="number")&&(n.type="number"),u.every(l=>typeof l=="string")&&(n.type="string"),n.enum=u},bI=(e,t,n,a)=>{const s=e._zod.def,u=[];for(const l of s.values)if(l===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof l=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");u.push(Number(l))}else u.push(l);if(u.length!==0)if(u.length===1){const l=u[0];n.type=l===null?"null":typeof l,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[l]:n.const=l}else u.every(l=>typeof l=="number")&&(n.type="number"),u.every(l=>typeof l=="string")&&(n.type="string"),u.every(l=>typeof l=="boolean")&&(n.type="boolean"),u.every(l=>l===null)&&(n.type="null"),n.enum=u},vI=(e,t,n,a)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},kI=(e,t,n,a)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},wI=(e,t,n,a)=>{const s=n,u=e._zod.def,{minimum:l,maximum:f}=e._zod.bag;typeof l=="number"&&(s.minItems=l),typeof f=="number"&&(s.maxItems=f),s.type="array",s.items=un(u.element,t,{...a,path:[...a.path,"items"]})},SI=(e,t,n,a)=>{const s=n,u=e._zod.def;s.type="object",s.properties={};const l=u.shape;for(const m in l)s.properties[m]=un(l[m],t,{...a,path:[...a.path,"properties",m]});const f=new Set(Object.keys(l)),h=new Set([...f].filter(m=>{const g=u.shape[m]._zod;return t.io==="input"?g.optin===void 0:g.optout===void 0}));h.size>0&&(s.required=Array.from(h)),u.catchall?._zod.def.type==="never"?s.additionalProperties=!1:u.catchall?u.catchall&&(s.additionalProperties=un(u.catchall,t,{...a,path:[...a.path,"additionalProperties"]})):t.io==="output"&&(s.additionalProperties=!1)},zI=(e,t,n,a)=>{const s=e._zod.def,u=s.inclusive===!1,l=s.options.map((f,h)=>un(f,t,{...a,path:[...a.path,u?"oneOf":"anyOf",h]}));u?n.oneOf=l:n.anyOf=l},_I=(e,t,n,a)=>{const s=e._zod.def,u=un(s.left,t,{...a,path:[...a.path,"allOf",0]}),l=un(s.right,t,{...a,path:[...a.path,"allOf",1]}),f=m=>"allOf"in m&&Object.keys(m).length===1,h=[...f(u)?u.allOf:[u],...f(l)?l.allOf:[l]];n.allOf=h},jI=(e,t,n,a)=>{const s=e._zod.def,u=un(s.innerType,t,a),l=t.seen.get(e);t.target==="openapi-3.0"?(l.ref=s.innerType,n.nullable=!0):n.anyOf=[u,{type:"null"}]},NI=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType},CI=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},EI=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},TI=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType;let l;try{l=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=l},AI=(e,t,n,a)=>{const s=e._zod.def,u=t.io==="input"?s.in._zod.def.type==="transform"?s.out:s.in:s.out;un(u,t,a);const l=t.seen.get(e);l.ref=u},OI=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,n.readOnly=!0},o2=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType},RI=ie("ZodISODateTime",(e,t)=>{IZ.init(e,t),Et.init(e,t)});function MI(e){return q7(RI,e)}const DI=ie("ZodISODate",(e,t)=>{HZ.init(e,t),Et.init(e,t)});function $I(e){return G7(DI,e)}const LI=ie("ZodISOTime",(e,t)=>{FZ.init(e,t),Et.init(e,t)});function PI(e){return Y7(LI,e)}const UI=ie("ZodISODuration",(e,t)=>{qZ.init(e,t),Et.init(e,t)});function VI(e){return K7(UI,e)}const l2=(e,t)=>{Gj.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>VB(e,n)},flatten:{value:n=>UB(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Vp,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Vp,2)}},isEmpty:{get(){return e.issues.length===0}}})},BI=ie("ZodError",l2),fr=ie("ZodError",l2,{Parent:Error}),ZI=ox(fr),II=lx(fr),HI=vd(fr),FI=kd(fr),qI=IB(fr),GI=HB(fr),YI=FB(fr),KI=qB(fr),XI=GB(fr),JI=YB(fr),QI=KB(fr),WI=XB(fr),qt=ie("ZodType",(e,t)=>(Ft.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:td(e,"input"),output:td(e,"output")}}),e.toJSONSchema=hI(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Qa(t,{checks:[...t.checks??[],...n.map(a=>typeof a=="function"?{_zod:{check:a,def:{check:"custom"},onattach:[]}}:a)]}),{parent:!0}),e.with=e.check,e.clone=(n,a)=>Wa(e,n,a),e.brand=()=>e,e.register=((n,a)=>(n.add(e,a),e)),e.parse=(n,a)=>ZI(e,n,a,{callee:e.parse}),e.safeParse=(n,a)=>HI(e,n,a),e.parseAsync=async(n,a)=>II(e,n,a,{callee:e.parseAsync}),e.safeParseAsync=async(n,a)=>FI(e,n,a),e.spa=e.safeParseAsync,e.encode=(n,a)=>qI(e,n,a),e.decode=(n,a)=>GI(e,n,a),e.encodeAsync=async(n,a)=>YI(e,n,a),e.decodeAsync=async(n,a)=>KI(e,n,a),e.safeEncode=(n,a)=>XI(e,n,a),e.safeDecode=(n,a)=>JI(e,n,a),e.safeEncodeAsync=async(n,a)=>QI(e,n,a),e.safeDecodeAsync=async(n,a)=>WI(e,n,a),e.refine=(n,a)=>e.check(qH(n,a)),e.superRefine=n=>e.check(GH(n)),e.overwrite=n=>e.check(oo(n)),e.optional=()=>Tw(e),e.exactOptional=()=>RH(e),e.nullable=()=>Aw(e),e.nullish=()=>Tw(Aw(e)),e.nonoptional=n=>UH(e,n),e.array=()=>wH(e),e.or=n=>c2([e,n]),e.and=n=>NH(e,n),e.transform=n=>Ow(e,AH(n)),e.default=n=>$H(e,n),e.prefault=n=>PH(e,n),e.catch=n=>BH(e,n),e.pipe=n=>Ow(e,n),e.readonly=()=>HH(e),e.describe=n=>{const a=e.clone();return ml.add(a,{description:n}),a},Object.defineProperty(e,"description",{get(){return ml.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ml.get(e);const a=e.clone();return ml.add(a,n[0]),a},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),u2=ie("_ZodString",(e,t)=>{ux.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>pI(e,a,s);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...a)=>e.check(Q7(...a)),e.includes=(...a)=>e.check(tI(...a)),e.startsWith=(...a)=>e.check(nI(...a)),e.endsWith=(...a)=>e.check(rI(...a)),e.min=(...a)=>e.check(ed(...a)),e.max=(...a)=>e.check(n2(...a)),e.length=(...a)=>e.check(r2(...a)),e.nonempty=(...a)=>e.check(ed(1,...a)),e.lowercase=a=>e.check(W7(a)),e.uppercase=a=>e.check(eI(a)),e.trim=()=>e.check(iI()),e.normalize=(...a)=>e.check(aI(...a)),e.toLowerCase=()=>e.check(sI()),e.toUpperCase=()=>e.check(oI()),e.slugify=()=>e.check(lI())}),eH=ie("ZodString",(e,t)=>{ux.init(e,t),u2.init(e,t),e.email=n=>e.check(_7(tH,n)),e.url=n=>e.check(T7(nH,n)),e.jwt=n=>e.check(F7(xH,n)),e.emoji=n=>e.check(A7(rH,n)),e.guid=n=>e.check(jw(Nw,n)),e.uuid=n=>e.check(j7(_c,n)),e.uuidv4=n=>e.check(N7(_c,n)),e.uuidv6=n=>e.check(C7(_c,n)),e.uuidv7=n=>e.check(E7(_c,n)),e.nanoid=n=>e.check(O7(aH,n)),e.guid=n=>e.check(jw(Nw,n)),e.cuid=n=>e.check(R7(iH,n)),e.cuid2=n=>e.check(M7(sH,n)),e.ulid=n=>e.check(D7(oH,n)),e.base64=n=>e.check(Z7(mH,n)),e.base64url=n=>e.check(I7(pH,n)),e.xid=n=>e.check($7(lH,n)),e.ksuid=n=>e.check(L7(uH,n)),e.ipv4=n=>e.check(P7(cH,n)),e.ipv6=n=>e.check(U7(dH,n)),e.cidrv4=n=>e.check(V7(fH,n)),e.cidrv6=n=>e.check(B7(hH,n)),e.e164=n=>e.check(H7(gH,n)),e.datetime=n=>e.check(MI(n)),e.date=n=>e.check($I(n)),e.time=n=>e.check(PI(n)),e.duration=n=>e.check(VI(n))});function Rm(e){return z7(eH,e)}const Et=ie("ZodStringFormat",(e,t)=>{St.init(e,t),u2.init(e,t)}),tH=ie("ZodEmail",(e,t)=>{MZ.init(e,t),Et.init(e,t)}),Nw=ie("ZodGUID",(e,t)=>{OZ.init(e,t),Et.init(e,t)}),_c=ie("ZodUUID",(e,t)=>{RZ.init(e,t),Et.init(e,t)}),nH=ie("ZodURL",(e,t)=>{DZ.init(e,t),Et.init(e,t)}),rH=ie("ZodEmoji",(e,t)=>{$Z.init(e,t),Et.init(e,t)}),aH=ie("ZodNanoID",(e,t)=>{LZ.init(e,t),Et.init(e,t)}),iH=ie("ZodCUID",(e,t)=>{PZ.init(e,t),Et.init(e,t)}),sH=ie("ZodCUID2",(e,t)=>{UZ.init(e,t),Et.init(e,t)}),oH=ie("ZodULID",(e,t)=>{VZ.init(e,t),Et.init(e,t)}),lH=ie("ZodXID",(e,t)=>{BZ.init(e,t),Et.init(e,t)}),uH=ie("ZodKSUID",(e,t)=>{ZZ.init(e,t),Et.init(e,t)}),cH=ie("ZodIPv4",(e,t)=>{GZ.init(e,t),Et.init(e,t)}),dH=ie("ZodIPv6",(e,t)=>{YZ.init(e,t),Et.init(e,t)}),fH=ie("ZodCIDRv4",(e,t)=>{KZ.init(e,t),Et.init(e,t)}),hH=ie("ZodCIDRv6",(e,t)=>{XZ.init(e,t),Et.init(e,t)}),mH=ie("ZodBase64",(e,t)=>{JZ.init(e,t),Et.init(e,t)}),pH=ie("ZodBase64URL",(e,t)=>{WZ.init(e,t),Et.init(e,t)}),gH=ie("ZodE164",(e,t)=>{e7.init(e,t),Et.init(e,t)}),xH=ie("ZodJWT",(e,t)=>{n7.init(e,t),Et.init(e,t)}),yH=ie("ZodUnknown",(e,t)=>{r7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>xI()});function Cw(){return X7(yH)}const bH=ie("ZodNever",(e,t)=>{a7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>gI(e,n,a)});function vH(e){return J7(bH,e)}const kH=ie("ZodArray",(e,t)=>{i7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>wI(e,n,a,s),e.element=t.element,e.min=(n,a)=>e.check(ed(n,a)),e.nonempty=n=>e.check(ed(1,n)),e.max=(n,a)=>e.check(n2(n,a)),e.length=(n,a)=>e.check(r2(n,a)),e.unwrap=()=>e.element});function wH(e,t){return uI(kH,e,t)}const SH=ie("ZodObject",(e,t)=>{o7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>SI(e,n,a,s),rt(e,"shape",()=>t.shape),e.keyof=()=>CH(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Cw()}),e.loose=()=>e.clone({...e._zod.def,catchall:Cw()}),e.strict=()=>e.clone({...e._zod.def,catchall:vH()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>MB(e,n),e.safeExtend=n=>DB(e,n),e.merge=n=>$B(e,n),e.pick=n=>OB(e,n),e.omit=n=>RB(e,n),e.partial=(...n)=>LB(d2,e,n[0]),e.required=(...n)=>PB(f2,e,n[0])});function zH(e,t){const n={type:"object",shape:e??{},...Te(t)};return new SH(n)}const _H=ie("ZodUnion",(e,t)=>{l7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>zI(e,n,a,s),e.options=t.options});function c2(e,t){return new _H({type:"union",options:e,...Te(t)})}const jH=ie("ZodIntersection",(e,t)=>{u7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>_I(e,n,a,s)});function NH(e,t){return new jH({type:"intersection",left:e,right:t})}const Zp=ie("ZodEnum",(e,t)=>{c7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>yI(e,a,s),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(a,s)=>{const u={};for(const l of a)if(n.has(l))u[l]=t.entries[l];else throw new Error(`Key ${l} not found in enum`);return new Zp({...t,checks:[],...Te(s),entries:u})},e.exclude=(a,s)=>{const u={...t.entries};for(const l of a)if(n.has(l))delete u[l];else throw new Error(`Key ${l} not found in enum`);return new Zp({...t,checks:[],...Te(s),entries:u})}});function CH(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(a=>[a,a])):e;return new Zp({type:"enum",entries:n,...Te(t)})}const EH=ie("ZodLiteral",(e,t)=>{d7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>bI(e,n,a),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Ew(e,t){return new EH({type:"literal",values:Array.isArray(e)?e:[e],...Te(t)})}const TH=ie("ZodTransform",(e,t)=>{f7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>kI(e,n),e._zod.parse=(n,a)=>{if(a.direction==="backward")throw new Vj(e.constructor.name);n.addIssue=u=>{if(typeof u=="string")n.issues.push(Dl(u,n.value,t));else{const l=u;l.fatal&&(l.continue=!1),l.code??(l.code="custom"),l.input??(l.input=n.value),l.inst??(l.inst=e),n.issues.push(Dl(l))}};const s=t.transform(n.value,n);return s instanceof Promise?s.then(u=>(n.value=u,n)):(n.value=s,n)}});function AH(e){return new TH({type:"transform",transform:e})}const d2=ie("ZodOptional",(e,t)=>{t2.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>o2(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function Tw(e){return new d2({type:"optional",innerType:e})}const OH=ie("ZodExactOptional",(e,t)=>{h7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>o2(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function RH(e){return new OH({type:"optional",innerType:e})}const MH=ie("ZodNullable",(e,t)=>{m7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>jI(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function Aw(e){return new MH({type:"nullable",innerType:e})}const DH=ie("ZodDefault",(e,t)=>{p7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>CI(e,n,a,s),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function $H(e,t){return new DH({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Hj(t)}})}const LH=ie("ZodPrefault",(e,t)=>{g7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>EI(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function PH(e,t){return new LH({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Hj(t)}})}const f2=ie("ZodNonOptional",(e,t)=>{x7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>NI(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function UH(e,t){return new f2({type:"nonoptional",innerType:e,...Te(t)})}const VH=ie("ZodCatch",(e,t)=>{y7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>TI(e,n,a,s),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function BH(e,t){return new VH({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const ZH=ie("ZodPipe",(e,t)=>{b7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>AI(e,n,a,s),e.in=t.in,e.out=t.out});function Ow(e,t){return new ZH({type:"pipe",in:e,out:t})}const IH=ie("ZodReadonly",(e,t)=>{v7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>OI(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function HH(e){return new IH({type:"readonly",innerType:e})}const FH=ie("ZodCustom",(e,t)=>{k7.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>vI(e,n)});function qH(e,t={}){return cI(FH,e,t)}function GH(e){return dI(e)}const YH=[{id:"general",label:"General"},{id:"agents",label:"Agents"},{id:"audio",label:"Audio"},{id:"channels",label:"Channels"},{id:"ui",label:"Interface"},{id:"logging",label:"Logging"},{id:"chronos",label:"Chronos"}],KH=[{id:"oracle",label:"Oracle"},{id:"sati",label:"Sati"},{id:"neo",label:"Neo"},{id:"apoc",label:"Apoc"},{id:"trinity",label:"Trinity"}],cl=[{label:"OpenAI",value:"openai"},{label:"Anthropic",value:"anthropic"},{label:"OpenRouter",value:"openrouter"},{label:"Ollama",value:"ollama"},{label:"Google Gemini",value:"gemini"}];function XH(){const{data:e,error:t}=zt("/api/config",ir.fetchConfig),{data:n}=zt("/api/config/sati",ir.getSatiConfig),{data:a}=zt("/api/config/apoc",ir.getApocConfig),{data:s}=zt("/api/config/neo",ir.getNeoConfig),{data:u}=zt("/api/config/trinity",ir.getTrinityConfig),{data:l}=zt("/api/config/encryption-status",()=>ir.getEncryptionStatus()),{data:f}=zt("/api/config/env-overrides",()=>ir.getEnvOverrides()),{data:h}=Y_(),[m,g]=z.useState(null),[y,v]=z.useState(!1),[b,S]=z.useState(null),[j,A]=z.useState(null),[E,O]=z.useState(null),[N,L]=z.useState(null),[D,R]=z.useState(null),[q,V]=z.useState("general"),[X,fe]=z.useState("oracle"),[se,le]=z.useState(!1),[ee,oe]=z.useState({}),[ae,P]=z.useState(null);z.useEffect(()=>{e&&!b&&S(e)},[e]),z.useEffect(()=>{n&&!j&&A(n)},[n]),z.useEffect(()=>{a&&!N?L(a):!a&&!N&&b&&L({...b.apoc??b.llm,temperature:b.apoc?.temperature??.2,timeout_ms:b.apoc?.timeout_ms??3e4})},[a,b]),z.useEffect(()=>{s&&!E?O(s):!s&&!E&&b&&O({...b.neo??b.llm,temperature:b.neo?.temperature??.2})},[s,b]),z.useEffect(()=>{u&&!D?R(u):!u&&!D&&b&&R({...b.trinity??b.llm,temperature:b.trinity?.temperature??.2})},[u,b]),z.useEffect(()=>{h&&!m&&g(h)},[h]);const J=JSON.stringify(e)!==JSON.stringify(b)||JSON.stringify(n)!==JSON.stringify(j)||JSON.stringify(s)!==JSON.stringify(E)||JSON.stringify(a)!==JSON.stringify(N)||JSON.stringify(u)!==JSON.stringify(D),B=(Z,Ne)=>{if(!l?.apiKeysEncrypted)return null;const{morpheusSecretSet:qe,apiKeysEncrypted:Lt}=l,Me=Lt[Z];return!Ne?d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-azure-surface border border-azure-border text-azure-text-secondary dark:bg-matrix-primary/10 dark:border-matrix-primary dark:text-matrix-tertiary",children:"No API key"}):f&&f[me(Z)]?null:qe?Me?d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-emerald-100 border border-emerald-300 text-emerald-800 dark:bg-emerald-900/30 dark:border-emerald-700 dark:text-emerald-400",title:"API key encrypted with AES-256-GCM",children:"🔒 Encrypted"}):d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-amber-100 border border-amber-300 text-amber-800 dark:bg-amber-900/30 dark:border-amber-700 dark:text-amber-400",title:"Re-save this configuration to encrypt the API key",children:"⚠️ Re-save to encrypt"}):d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-amber-100 border border-amber-300 text-amber-800 dark:bg-amber-900/30 dark:border-amber-700 dark:text-amber-400",title:"Set MORPHEUS_SECRET to enable encryption",children:"⚠️ Plaintext"})},me=Z=>({oracle:"llm.api_key",sati:"sati.api_key",neo:"neo.api_key",apoc:"apoc.api_key",trinity:"trinity.api_key",audio:"audio.apiKey"})[Z],T=Z=>!f||!f[Z]?null:d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-blue-100 border border-blue-300 text-blue-800 dark:bg-blue-900/30 dark:border-blue-700 dark:text-blue-400",title:"This field is set by an environment variable and cannot be edited",children:"🔒 Env Var"}),C=Z=>!!(f&&f[Z]),I=(Z,Ne)=>{if(!b)return;const qe=JSON.parse(JSON.stringify(b));let Lt=qe;for(let Me=0;Me<Z.length-1;Me++)Lt=Lt[Z[Me]];Lt[Z[Z.length-1]]=Ne,S(qe);try{jB.parse(qe),oe({})}catch(Me){if(Me instanceof BI){const Ke={};Me.errors.forEach(at=>{const Qe=at.path.join(".");Ke[Qe]=at.message}),oe(Ke)}}},w=(Z,Ne)=>{j&&A({...j,[Z]:Ne})},Y=(Z,Ne)=>{N&&L({...N,[Z]:Ne})},de=(Z,Ne)=>{E&&O({...E,[Z]:Ne})},he=(Z,Ne)=>{D&&R({...D,[Z]:Ne})},pe=()=>{!b||!D||R({...D,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},Pe=()=>{!b||!j||A({...j,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},Ae=()=>{!b||!N||L({...N,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},pt=()=>{!b||!E||O({...E,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},Rt=async()=>{if(b){le(!0),P(null);try{await ir.updateConfig(b),j&&await ir.updateSatiConfig(j),E&&await ir.updateNeoConfig(E),N&&await ir.updateApocConfig(N),D&&await ir.updateTrinityConfig(D),On("/api/config"),On("/api/config/sati"),On("/api/config/neo"),On("/api/config/apoc"),On("/api/config/trinity"),P({type:"success",message:"Settings saved successfully. Restart Morpheus daemon for changes to take effect."})}catch(Z){if(P({type:"error",message:Z.message}),Z.details&&Array.isArray(Z.details)){const Ne={};Z.details.forEach(qe=>{const Lt=qe.path.join(".");Ne[Lt]=qe.message}),oe(Ne)}}finally{le(!1)}}};return t?d.jsx("div",{className:"p-8 text-red-500",children:"Failed to load configuration"}):b?d.jsxs("div",{className:"max-w-4xl mx-auto p-0 md:p-6 space-y-6",children:[d.jsxs("div",{className:"flex justify-between items-center",children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"Zaion Settings"}),d.jsx("button",{onClick:Rt,disabled:!J||Object.keys(ee).length>0||se,className:`px-4 py-2 rounded font-medium transition-colors ${J&&Object.keys(ee).length===0?"bg-azure-primary text-white hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90":"bg-azure-border text-azure-text-secondary cursor-not-allowed dark:bg-matrix-primary/50 dark:text-matrix-highlight/50"}`,children:se?"Saving...":"Save Changes"})]}),ae&&d.jsx("div",{className:`p-4 rounded border ${ae.type==="success"?"border-azure-primary text-azure-primary bg-azure-primary/10 dark:border-matrix-highlight dark:text-matrix-highlight dark:bg-matrix-highlight/10":"border-red-500 text-red-500 bg-red-900/10"}`,children:ae.message}),d.jsx("div",{className:"overflow-x-auto py-1 hide-scrollbar",children:d.jsx("div",{className:"flex space-x-1 border-b border-azure-border dark:border-matrix-primary pb-px min-w-max",children:YH.map(Z=>d.jsx("button",{onClick:()=>V(Z.id),className:`px-4 py-2 text-sm font-medium rounded-t-md transition-colors flex-shrink-0 ${q===Z.id?"bg-azure-surface/50 text-azure-primary border-t border-x border-azure-border dark:bg-matrix-primary/20 dark:text-matrix-highlight dark:border-t dark:border-x dark:border-matrix-primary":"text-azure-text-secondary hover:text-azure-primary dark:text-matrix-secondary dark:hover:text-matrix-highlight"}`,children:Z.label},Z.id))})}),d.jsxs("div",{className:"space-y-6",children:[q==="general"&&d.jsxs(ar,{title:"Agent Identity",children:[d.jsx(lt,{label:"Agent Name",value:b.agent.name,onChange:Z=>I(["agent","name"],Z.target.value),error:ee["agent.name"]}),d.jsx(lt,{label:"Personality",value:b.agent.personality,onChange:Z=>I(["agent","personality"],Z.target.value),error:ee["agent.personality"]})]}),q==="agents"&&d.jsxs("div",{className:"space-y-4",children:[d.jsx("div",{className:"flex space-x-1 border-b border-azure-border dark:border-matrix-primary pb-px",children:KH.map(Z=>d.jsx("button",{onClick:()=>fe(Z.id),className:`px-4 py-2 text-sm font-medium rounded-t-md transition-colors ${X===Z.id?"bg-azure-primary/10 text-azure-primary border-b-2 border-azure-primary dark:bg-matrix-highlight/10 dark:text-matrix-highlight dark:border-matrix-highlight":"text-azure-text-secondary hover:text-azure-primary dark:text-matrix-secondary dark:hover:text-matrix-highlight"}`,children:Z.label},Z.id))}),X==="oracle"&&d.jsxs(ar,{title:"Oracle Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"Main orchestration agent — handles user requests and delegates to subagents"}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("llm.provider")]}),d.jsx(jr,{label:"",value:b.llm.provider,onChange:Z=>I(["llm","provider"],Z.target.value),options:cl,error:ee["llm.provider"],disabled:C("llm.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("llm.model")]}),d.jsx(lt,{label:"",value:b.llm.model,onChange:Z=>I(["llm","model"],Z.target.value),disabled:C("llm.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("llm.temperature")]}),d.jsx(yn,{label:"",value:b.llm.temperature,onChange:Z=>I(["llm","temperature"],parseFloat(Z.target.value)),step:.1,min:0,max:1,error:ee["llm.temperature"],disabled:C("llm.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Tokens"}),T("llm.max_tokens")]}),d.jsx(yn,{label:"",value:b.llm.max_tokens??"",onChange:Z=>I(["llm","max_tokens"],Z.target.value?parseInt(Z.target.value):void 0),min:1,error:ee["llm.max_tokens"],helperText:"Maximum tokens per response. Leave empty for model default.",disabled:C("llm.max_tokens")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Context Window (Messages)"}),T("llm.context_window")]}),d.jsx(yn,{label:"",value:b.llm.context_window??100,onChange:Z=>I(["llm","context_window"],parseInt(Z.target.value)),min:1,step:1,error:ee["llm.context_window"],helperText:"Number of past interactions to load into LLM context (e.g., 100).",disabled:C("llm.context_window")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("llm.api_key"),B("oracle",b.llm.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:b.llm.api_key||"",onChange:Z=>I(["llm","api_key"],Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("llm.api_key")}),b.llm.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:b.llm.base_url||"https://openrouter.ai/api/v1",onChange:Z=>I(["llm","base_url"],Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"})]}),X==="sati"&&d.jsxs(ar,{title:"Sati Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"Background memory consolidation agent — evaluates conversations and persists important context"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:Pe,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),j&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("sati.provider")]}),d.jsx(jr,{label:"",value:j.provider,onChange:Z=>w("provider",Z.target.value),options:cl,disabled:C("sati.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("sati.model")]}),d.jsx(lt,{label:"",value:j.model,onChange:Z=>w("model",Z.target.value),disabled:C("sati.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("sati.api_key"),B("sati",j.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:j.api_key||"",onChange:Z=>w("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("sati.api_key")}),j.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:j.base_url||"https://openrouter.ai/api/v1",onChange:Z=>w("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"}),d.jsx(yn,{label:"Memory Limit",value:j.memory_limit??10,onChange:Z=>w("memory_limit",parseInt(Z.target.value)),min:1,step:1,helperText:"Number of memory items to retrieve from long-term storage."}),d.jsx(zs,{label:"Enable Archived Sessions in Memory Retrieval",checked:j.enabled_archived_sessions??!0,onChange:Z=>w("enabled_archived_sessions",Z)})]})]}),X==="neo"&&d.jsxs(ar,{title:"Neo Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"MCP + internal tools subagent — executes analytical and operational tasks delegated by Oracle"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:pt,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),E&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("neo.provider")]}),d.jsx(jr,{label:"",value:E.provider,onChange:Z=>de("provider",Z.target.value),options:cl,disabled:C("neo.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("neo.model")]}),d.jsx(lt,{label:"",value:E.model,onChange:Z=>de("model",Z.target.value),disabled:C("neo.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("neo.temperature")]}),d.jsx(yn,{label:"",value:E.temperature,onChange:Z=>de("temperature",parseFloat(Z.target.value)),step:.1,min:0,max:1,disabled:C("neo.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Tokens"}),T("neo.max_tokens")]}),d.jsx(yn,{label:"",value:E.max_tokens??"",onChange:Z=>de("max_tokens",Z.target.value?parseInt(Z.target.value):void 0),min:1,helperText:"Maximum tokens per response. Leave empty for model default.",disabled:C("neo.max_tokens")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Context Window (Messages)"}),T("neo.context_window")]}),d.jsx(yn,{label:"",value:E.context_window??100,onChange:Z=>de("context_window",parseInt(Z.target.value)),min:1,step:1,disabled:C("neo.context_window")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("neo.api_key"),B("neo",E.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:E.api_key||"",onChange:Z=>de("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("neo.api_key")}),E.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:E.base_url||"https://openrouter.ai/api/v1",onChange:Z=>de("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"})]})]}),X==="trinity"&&d.jsxs(ar,{title:"Trinity Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"Database subagent — interprets natural language queries and executes them against registered databases (PostgreSQL, MySQL, SQLite, MongoDB)"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:pe,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),D&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("trinity.provider")]}),d.jsx(jr,{label:"",value:D.provider,onChange:Z=>he("provider",Z.target.value),options:cl,disabled:C("trinity.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("trinity.model")]}),d.jsx(lt,{label:"",value:D.model,onChange:Z=>he("model",Z.target.value),disabled:C("trinity.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("trinity.temperature")]}),d.jsx(yn,{label:"",value:D.temperature,onChange:Z=>he("temperature",parseFloat(Z.target.value)),step:.1,min:0,max:1,disabled:C("trinity.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Tokens"}),T("trinity.max_tokens")]}),d.jsx(yn,{label:"",value:D.max_tokens??"",onChange:Z=>he("max_tokens",Z.target.value?parseInt(Z.target.value):void 0),min:1,helperText:"Maximum tokens per response. Leave empty for model default.",disabled:C("trinity.max_tokens")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("trinity.api_key"),B("trinity",D.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:D.api_key||"",onChange:Z=>he("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("trinity.api_key")}),D.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:D.base_url||"https://openrouter.ai/api/v1",onChange:Z=>he("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"})]})]}),X==="apoc"&&d.jsxs(ar,{title:"Apoc Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"DevTools subagent — executes file, shell, git, network, and system operations on behalf of Oracle"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:Ae,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),N&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("apoc.provider")]}),d.jsx(jr,{label:"",value:N.provider,onChange:Z=>Y("provider",Z.target.value),options:cl,disabled:C("apoc.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("apoc.model")]}),d.jsx(lt,{label:"",value:N.model,onChange:Z=>Y("model",Z.target.value),disabled:C("apoc.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("apoc.temperature")]}),d.jsx(yn,{label:"",value:N.temperature,onChange:Z=>Y("temperature",parseFloat(Z.target.value)),step:.1,min:0,max:1,disabled:C("apoc.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("apoc.api_key"),B("apoc",N.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:N.api_key||"",onChange:Z=>Y("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("apoc.api_key")}),N.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:N.base_url||"https://openrouter.ai/api/v1",onChange:Z=>Y("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"}),d.jsx(lt,{label:"Working Directory",value:N.working_dir||"",onChange:Z=>Y("working_dir",Z.target.value),placeholder:"/home/user/projects",helperText:"Root directory for file and shell operations. Leave empty to use process working directory."}),d.jsx(yn,{label:"Timeout (ms)",value:N.timeout_ms??3e4,onChange:Z=>Y("timeout_ms",parseInt(Z.target.value)),min:1e3,step:1e3,helperText:"Maximum execution time for shell and system operations in milliseconds."})]})]})]}),q==="audio"&&d.jsxs(ar,{title:"Audio Transcription",children:[d.jsx(zs,{label:"Enable Audio",checked:b.audio.enabled,onChange:Z=>I(["audio","enabled"],Z)}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("audio.provider")]}),d.jsx(jr,{label:"",value:b.audio.provider||"google",onChange:Z=>I(["audio","provider"],Z.target.value),options:[{label:"Google Gemini",value:"google"},{label:"OpenAI (Whisper)",value:"openai"},{label:"OpenRouter (multimodal)",value:"openrouter"},{label:"Ollama (Whisper local)",value:"ollama"}],error:ee["audio.provider"],disabled:C("audio.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model"}),T("audio.model")]}),d.jsx(lt,{label:"",value:b.audio.model,onChange:Z=>I(["audio","model"],Z.target.value),placeholder:"e.g. whisper-1, gemini-2.5-flash-lite...",helperText:"Model to use for audio transcription.",error:ee["audio.model"],disabled:C("audio.model")}),b.audio.provider==="ollama"&&d.jsx(lt,{label:"Base URL",value:b.audio.base_url||"",onChange:Z=>I(["audio","base_url"],Z.target.value),placeholder:"http://localhost:11434",helperText:"Ollama base URL. Requires a Whisper model loaded (ollama pull whisper)."}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("audio.apiKey"),B("audio",b.audio.apiKey)]})]}),d.jsx(lt,{label:"",type:"password",value:b.audio.apiKey||"",onChange:Z=>I(["audio","apiKey"],Z.target.value),placeholder:"If different from LLM key...",helperText:"Leave empty to use LLM API key if using the same provider.",disabled:C("audio.apiKey")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Duration (Seconds)"}),T("audio.maxDurationSeconds")]}),d.jsx(yn,{label:"",value:b.audio.maxDurationSeconds,onChange:Z=>I(["audio","maxDurationSeconds"],parseInt(Z.target.value)),min:1,disabled:C("audio.maxDurationSeconds")}),d.jsx(lt,{label:"Supported Mime Types",value:b.audio.supportedMimeTypes.join(", "),onChange:Z=>I(["audio","supportedMimeTypes"],Z.target.value.split(",").map(Ne=>Ne.trim()).filter(Boolean)),helperText:"Comma separated list (e.g. audio/ogg, audio/mp3)"})]}),q==="channels"&&d.jsxs(d.Fragment,{children:[d.jsxs(ar,{title:"Telegram",children:[d.jsx(zs,{label:"Enable Telegram",checked:b.channels.telegram.enabled,onChange:Z=>I(["channels","telegram","enabled"],Z)}),b.channels.telegram.enabled&&d.jsxs("div",{className:"space-y-4 mt-4 pl-4 border-l border-matrix-primary",children:[d.jsx(lt,{label:"Bot Token",type:"password",value:b.channels.telegram.token||"",onChange:Z=>I(["channels","telegram","token"],Z.target.value)}),d.jsx(lt,{label:"Allowed Users (comma separated)",value:b.channels.telegram.allowedUsers.join(", "),onChange:Z=>I(["channels","telegram","allowedUsers"],Z.target.value.split(",").map(Ne=>Ne.trim()).filter(Boolean)),helperText:"User IDs allowed to interact with the bot"})]})]}),d.jsxs(ar,{title:"Discord",children:[d.jsx(zs,{label:"Enable Discord",checked:b.channels.discord.enabled,onChange:Z=>I(["channels","discord","enabled"],Z)}),b.channels.discord.enabled&&d.jsxs("div",{className:"space-y-4 mt-4 pl-4 border-l border-matrix-primary",children:[d.jsx(lt,{label:"Bot Token",type:"password",value:b.channels.discord.token||"",onChange:Z=>I(["channels","discord","token"],Z.target.value)}),d.jsx(lt,{label:"Allowed Users (comma separated)",value:(b.channels.discord.allowedUsers??[]).join(", "),onChange:Z=>I(["channels","discord","allowedUsers"],Z.target.value.split(",").map(Ne=>Ne.trim()).filter(Boolean)),helperText:"Discord user IDs allowed to interact with the bot"})]})]})]}),q==="ui"&&d.jsxs(ar,{title:"Dashboard",children:[d.jsx(zs,{label:"Enable Web UI",checked:b.ui.enabled,onChange:Z=>I(["ui","enabled"],Z)}),d.jsx(yn,{label:"Port",value:b.ui.port,onChange:Z=>I(["ui","port"],parseInt(Z.target.value)),disabled:!0,helperText:"Requires restart to change."})]}),q==="logging"&&d.jsxs(ar,{title:"Logging",children:[d.jsx(zs,{label:"Enable Logging",checked:b.logging.enabled,onChange:Z=>I(["logging","enabled"],Z)}),d.jsx(jr,{label:"Log Level",value:b.logging.level,onChange:Z=>I(["logging","level"],Z.target.value),options:[{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warning",value:"warn"},{label:"Error",value:"error"}]})]}),q==="chronos"&&m&&d.jsxs(ar,{title:"Chronos — Temporal Intent Engine",children:[d.jsx(jr,{label:"Timezone",value:m.timezone,onChange:Z=>g({...m,timezone:Z.target.value}),options:[{label:"UTC",value:"UTC"},{label:"America/New_York",value:"America/New_York"},{label:"America/Chicago",value:"America/Chicago"},{label:"America/Denver",value:"America/Denver"},{label:"America/Los_Angeles",value:"America/Los_Angeles"},{label:"America/Sao_Paulo",value:"America/Sao_Paulo"},{label:"America/Buenos_Aires",value:"America/Buenos_Aires"},{label:"America/Bogota",value:"America/Bogota"},{label:"America/Lima",value:"America/Lima"},{label:"America/Santiago",value:"America/Santiago"},{label:"America/Mexico_City",value:"America/Mexico_City"},{label:"America/Toronto",value:"America/Toronto"},{label:"America/Vancouver",value:"America/Vancouver"},{label:"Europe/London",value:"Europe/London"},{label:"Europe/Paris",value:"Europe/Paris"},{label:"Europe/Berlin",value:"Europe/Berlin"},{label:"Europe/Madrid",value:"Europe/Madrid"},{label:"Europe/Rome",value:"Europe/Rome"},{label:"Europe/Amsterdam",value:"Europe/Amsterdam"},{label:"Europe/Brussels",value:"Europe/Brussels"},{label:"Europe/Zurich",value:"Europe/Zurich"},{label:"Europe/Lisbon",value:"Europe/Lisbon"},{label:"Europe/Warsaw",value:"Europe/Warsaw"},{label:"Europe/Stockholm",value:"Europe/Stockholm"},{label:"Europe/Helsinki",value:"Europe/Helsinki"},{label:"Europe/Moscow",value:"Europe/Moscow"},{label:"Asia/Dubai",value:"Asia/Dubai"},{label:"Asia/Kolkata",value:"Asia/Kolkata"},{label:"Asia/Bangkok",value:"Asia/Bangkok"},{label:"Asia/Singapore",value:"Asia/Singapore"},{label:"Asia/Hong_Kong",value:"Asia/Hong_Kong"},{label:"Asia/Shanghai",value:"Asia/Shanghai"},{label:"Asia/Tokyo",value:"Asia/Tokyo"},{label:"Asia/Seoul",value:"Asia/Seoul"},{label:"Australia/Sydney",value:"Australia/Sydney"},{label:"Australia/Melbourne",value:"Australia/Melbourne"},{label:"Pacific/Auckland",value:"Pacific/Auckland"},{label:"Africa/Cairo",value:"Africa/Cairo"},{label:"Africa/Johannesburg",value:"Africa/Johannesburg"}]}),d.jsx(yn,{label:"Check Interval (seconds)",value:Math.round(m.check_interval_ms/1e3),onChange:Z=>g({...m,check_interval_ms:Number(Z.target.value)*1e3}),min:60}),d.jsx(yn,{label:"Max Active Jobs",value:m.max_active_jobs,onChange:Z=>g({...m,max_active_jobs:Number(Z.target.value)}),min:1,max:1e3}),d.jsx("div",{className:"flex justify-end pt-2",children:d.jsx("button",{onClick:async()=>{v(!0),P(null);try{await Ei.updateConfig(m),On("/api/config/chronos"),P({type:"success",message:"Chronos settings saved."})}catch(Z){P({type:"error",message:Z.message})}finally{v(!1)}},disabled:y,className:"px-4 py-2 rounded font-medium bg-azure-primary text-white hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:y?"Saving…":"Save Chronos Settings"})})]})]})]}):d.jsx("div",{className:"p-8 text-azure-primary dark:text-matrix-highlight",children:"Loading settings..."})}function JH(){const{data:e}=O4(),[t,n]=z.useState(null),{data:a,mutate:s}=R4(t),u=z.useRef(null);return z.useEffect(()=>{!t&&e&&e.length>0&&n(e[0].name)},[e,t]),z.useEffect(()=>{u.current&&(u.current.scrollTop=u.current.scrollHeight)},[a]),d.jsxs(dt.div,{className:"flex flex-col space-y-4 md:pt-0",style:{height:"calc(100vh - 2rem)"},initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},transition:{duration:.3},children:[d.jsxs("div",{className:"shrink-0",children:[d.jsx("h2",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"SYSTEM LOGS"}),d.jsx("p",{className:"text-azure-text-secondary dark:text-matrix-secondary opacity-80",children:"View runtime logs."})]}),d.jsxs("div",{className:"flex-1 flex gap-4 min-h-0 border border-azure-border dark:border-matrix-primary rounded bg-azure-surface dark:bg-zinc-950 p-4",children:[d.jsxs("div",{className:"hidden md:flex w-64 flex-col gap-2 border-r border-azure-border dark:border-matrix-primary pr-4 overflow-y-auto shrink-0",children:[d.jsx("h3",{className:"font-bold text-azure-text-secondary dark:text-matrix-secondary mb-2 sticky top-0 bg-azure-surface dark:bg-zinc-950",children:"LOG FILES"}),e?.map(l=>d.jsxs("button",{onClick:()=>n(l.name),className:`text-left px-3 py-2 rounded text-sm truncate flex items-center gap-2 group transition-colors ${t===l.name?"bg-azure-active text-azure-primary dark:bg-matrix-primary dark:text-matrix-highlight":"text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-hover dark:hover:bg-zinc-900 group-hover:text-azure-primary dark:group-hover:text-matrix-highlight"}`,children:[d.jsx(tA,{className:"w-4 h-4 shrink-0"}),d.jsxs("div",{className:"flex flex-col overflow-hidden",children:[d.jsx("span",{className:"truncate font-bold",children:l.name}),d.jsxs("span",{className:"text-xs opacity-70",children:[(l.size/1024).toFixed(1)," KB"]})]})]},l.name))]}),d.jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-azure-bg dark:bg-black border border-azure-border dark:border-matrix-primary/50 rounded",children:[d.jsxs("div",{className:"shrink-0 flex justify-between items-center gap-2 p-2 bg-azure-hover dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary/50",children:[d.jsx("select",{value:t??"",onChange:l=>n(l.target.value),className:"md:hidden flex-1 bg-transparent text-azure-text-primary dark:text-matrix-highlight font-bold font-mono text-sm border-none outline-none cursor-pointer",children:e?.map(l=>d.jsx("option",{value:l.name,children:l.name},l.name))}),d.jsx("span",{className:"hidden md:block text-azure-text-primary dark:text-matrix-highlight font-bold font-mono text-sm truncate",children:t}),d.jsx("button",{onClick:()=>s(),className:"shrink-0 text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(xS,{className:"w-4 h-4"})})]}),d.jsx("div",{ref:u,className:"flex-1 overflow-x-hidden overflow-y-auto p-4 font-mono text-xs break-all text-azure-text-primary dark:text-white",children:a?a.lines.map((l,f)=>{const h=l.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z)\s?(.*)/s);return h?d.jsxs("div",{children:[d.jsxs("span",{className:"hidden md:inline opacity-50",children:[h[1]," "]}),d.jsx("span",{children:h[2]})]},f):d.jsx("div",{children:l},f)}):d.jsx("span",{className:"opacity-50",children:"Select a log file to view content..."})})]})]})]})}function QH(){const[e,t]=z.useState(null),[n,a]=z.useState([]),[s,u]=z.useState(!0),[l,f]=z.useState("");if(z.useEffect(()=>{async function g(){try{const[y,v]=await Promise.all([_p.fetchUsageStats(),_p.fetchGroupedUsageStats()]);t(y),a(v)}catch(y){f("Failed to load usage statistics"),console.error(y)}finally{u(!1)}}g()},[]),s)return d.jsx("div",{className:"flex items-center justify-center h-64 text-azure-accent dark:text-matrix-highlight font-mono animate-pulse",children:"LOADING_DATA_STREAM..."});if(l)return d.jsxs("div",{className:"p-4 bg-red-900/20 border border-red-500/50 text-red-500 font-mono rounded",children:["ERROR_ACCESSING_DATABASE: ",l]});const h={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.1}}},m={hidden:{y:20,opacity:0},show:{y:0,opacity:1}};return d.jsxs(dt.div,{variants:h,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsx("div",{className:"flex items-center justify-between border-b border-azure-border dark:border-matrix-primary pb-4",children:d.jsxs("div",{children:[d.jsxs("h2",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight font-mono flex items-center gap-2",children:[d.jsx(Zm,{className:"w-6 h-6"}),"USAGE_ANALYTICS"]}),d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary mt-1 font-mono text-sm",children:"Resource consumption tracking and metrics"})]})}),d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[d.jsxs(dt.div,{variants:m,className:"p-6 bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg shadow-sm backdrop-blur-sm",children:[d.jsxs("div",{className:"flex items-center gap-3 mb-2 text-azure-text-muted dark:text-matrix-secondary",children:[d.jsx(zl,{className:"w-5 h-5"}),d.jsx("h3",{className:"font-mono text-sm font-bold uppercase",children:"Total Input Tokens"})]}),d.jsx("p",{className:"text-3xl font-bold text-azure-primary dark:text-matrix-highlight font-mono",children:e?.totalInputTokens.toLocaleString()??0})]}),d.jsxs(dt.div,{variants:m,className:"p-6 bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg shadow-sm backdrop-blur-sm",children:[d.jsxs("div",{className:"flex items-center gap-3 mb-2 text-azure-text-muted dark:text-matrix-secondary",children:[d.jsx($s,{className:"w-5 h-5"}),d.jsx("h3",{className:"font-mono text-sm font-bold uppercase",children:"Total Output Tokens"})]}),d.jsx("p",{className:"text-3xl font-bold text-azure-primary dark:text-matrix-highlight font-mono",children:e?.totalOutputTokens.toLocaleString()??0})]}),d.jsxs(dt.div,{variants:m,className:"p-6 bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg shadow-sm backdrop-blur-sm",children:[d.jsxs("div",{className:"flex items-center gap-3 mb-2 text-azure-text-muted dark:text-matrix-secondary",children:[d.jsx(Pc,{className:"w-5 h-5"}),d.jsx("h3",{className:"font-mono text-sm font-bold uppercase",children:"Est. Total Cost"})]}),d.jsx("p",{className:"text-3xl font-bold text-green-600 dark:text-green-400 font-mono",children:e?.totalEstimatedCostUsd!=null?`$${e.totalEstimatedCostUsd.toFixed(4)}`:"—"})]})]}),d.jsxs(dt.div,{variants:m,className:"bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg overflow-hidden backdrop-blur-sm",children:[d.jsx("div",{className:"p-4 border-b border-azure-border dark:border-matrix-primary bg-azure-bg dark:bg-zinc-900/50",children:d.jsx("h3",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight font-mono uppercase",children:"Usage Breakdown by Model"})}),d.jsx("div",{className:"overflow-x-auto",children:d.jsxs("table",{className:"w-full text-left font-mono text-sm",children:[d.jsx("thead",{className:"bg-azure-bg dark:bg-zinc-900/50 text-azure-text-secondary dark:text-matrix-secondary border-b border-azure-border dark:border-matrix-primary",children:d.jsxs("tr",{children:[d.jsx("th",{className:"p-4",children:"Provider"}),d.jsx("th",{className:"p-4",children:"Model"}),d.jsx("th",{className:"p-4 text-right",children:"Messages"}),d.jsx("th",{className:"p-4 text-right",children:"Input Tokens"}),d.jsx("th",{className:"p-4 text-right",children:"Output Tokens"}),d.jsx("th",{className:"p-4 text-right",children:"Total Tokens"}),d.jsx("th",{className:"p-4 text-right",children:"Audio (s)"}),d.jsx("th",{className:"p-4 text-right",children:"Est. Cost (USD)"})]})}),d.jsx("tbody",{className:"divide-y divide-azure-border dark:divide-matrix-primary/30",children:n.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:8,className:"p-8 text-center text-azure-text-muted dark:text-matrix-secondary italic",children:"NO_DATA_AVAILABLE"})}):n.map((g,y)=>d.jsxs("tr",{className:"hover:bg-azure-hover dark:hover:bg-matrix-primary/10 transition-colors",children:[d.jsx("td",{className:"p-4 font-bold text-azure-text-primary dark:text-matrix-highlight",children:g.provider}),d.jsx("td",{className:"p-4 text-azure-text-secondary dark:text-matrix-secondary",children:g.model}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.messageCount.toLocaleString()}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.totalInputTokens.toLocaleString()}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.totalOutputTokens.toLocaleString()}),d.jsx("td",{className:"p-4 text-right font-bold text-azure-text-primary dark:text-matrix-highlight",children:g.totalTokens.toLocaleString()}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.totalAudioSeconds>0?g.totalAudioSeconds.toLocaleString():"—"}),d.jsx("td",{className:"p-4 text-right font-bold text-green-600 dark:text-green-400",children:g.estimatedCostUsd!=null?`$${g.estimatedCostUsd.toFixed(4)}`:"—"})]},`${g.provider}-${g.model}-${y}`))})]})})]})]})}const WH=()=>{const[e,t]=z.useState(""),[n,a]=z.useState(""),s=Yp(),u=vr(),l=f=>{f.preventDefault(),e&&(a(""),fetch("/api/config",{headers:{"x-architect-pass":e}}).then(async h=>{if(h.ok){localStorage.setItem("morpheus.auth.token",e);const m=u.state?.from?.pathname||"/";s(m,{replace:!0})}else a("Invalid architect password")}).catch(()=>{a("Connection failed")}))};return d.jsx("div",{className:"flex items-center justify-center min-h-screen bg-azure-bg dark:bg-black text-azure-primary dark:text-green-500 font-mono",children:d.jsxs("div",{className:"max-w-md w-full p-8 border border-azure-primary dark:border-green-500 shadow-xl dark:shadow-[0_0_15px_rgba(34,197,94,0.3)] bg-white dark:bg-black rounded-lg dark:rounded-none",children:[d.jsx("h1",{className:"text-2xl font-bold mb-6 text-center tracking-widest uppercase text-azure-primary dark:text-green-500",children:"> The Architect Login"}),d.jsxs("form",{onSubmit:l,className:"space-y-6",children:[d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm mb-2 opacity-70 text-azure-text-secondary dark:text-green-500",children:"ACCESS_PASS:"}),d.jsx("input",{type:"password",value:e,onChange:f=>t(f.target.value),className:"w-full bg-azure-bg dark:bg-black border border-azure-border dark:border-green-800 p-2 focus:outline-none focus:border-azure-primary dark:focus:border-green-500 text-azure-text-primary dark:text-green-500 placeholder-azure-text-secondary/50 dark:placeholder-green-900 rounded dark:rounded-none",placeholder:"••••••••",autoFocus:!0})]}),n&&d.jsxs("div",{className:"text-red-500 text-sm animate-pulse",children:["[!] ERROR: ",n]}),d.jsx("button",{type:"submit",className:"w-full bg-azure-primary hover:bg-azure-active dark:bg-green-900 dark:hover:bg-green-700 text-white dark:text-black font-bold py-2 transition-colors duration-200 uppercase tracking-wider rounded dark:rounded-none",children:"Authenticate"})]}),d.jsx("div",{className:"mt-8 text-[10px] opacity-30 text-center uppercase text-azure-text-secondary dark:text-green-500",children:"Morpheus OS v0.1.5 | Unauthorized access is logged."})]})})},eF=({children:e})=>{const{isAuthenticated:t}=d_(),n=vr();return t?d.jsx(d.Fragment,{children:e}):d.jsx(iS,{to:"/login",state:{from:n},replace:!0})},tF=({className:e,...t})=>d.jsx("div",{className:"relative w-full overflow-auto",children:d.jsx("table",{className:`w-full caption-bottom text-sm ${e}`,...t})}),nF=({...e})=>d.jsx("thead",{...e}),rF=({...e})=>d.jsx("tbody",{...e}),Mm=({...e})=>d.jsx("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 transition-colors hover:bg-azure-hover/50 dark:hover:bg-matrix-primary/10",...e}),_s=({className:e,...t})=>d.jsx("th",{className:`h-12 px-4 text-left align-middle font-medium text-azure-text-secondary dark:text-matrix-secondary/70 [&:has([role=checkbox])]:pr-0 ${e}`,...t}),vi=({className:e,...t})=>d.jsx("td",{className:`p-4 align-middle [&:has([role=checkbox])]:pr-0 ${e}`,...t}),Rw=({checked:e,onCheckedChange:t,className:n,...a})=>{const s=u=>{t&&t(u.target.checked),a.onChange&&a.onChange(u)};return d.jsx("input",{type:"checkbox",checked:e,onChange:s,className:`h-4 w-4 rounded border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-primary dark:text-matrix-highlight focus:ring-azure-primary dark:focus:ring-matrix-highlight ${n||""}`,...a})},nd=({className:e,variant:t="default",...n})=>{const s=`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 dark:focus:ring-zinc-300 ${t==="destructive"?"border-transparent bg-red-500 text-zinc-50 dark:bg-red-900 dark:text-zinc-50":t==="secondary"?"border-transparent bg-azure-surface dark:bg-zinc-800 text-azure-text-secondary dark:text-matrix-secondary":t==="outline"?"text-azure-text-primary dark:text-matrix-secondary border-azure-border dark:border-matrix-primary":"border-transparent bg-azure-primary dark:bg-matrix-highlight text-azure-text-inverse dark:text-black"} ${e||""}`;return d.jsx("div",{className:s,...n})},Dm=({className:e,...t})=>d.jsx("div",{className:`rounded-lg border border-azure-border dark:border-matrix-primary/30 bg-azure-surface dark:bg-zinc-900 text-azure-text-primary dark:text-matrix-secondary shadow-sm ${e||""}`,...t}),Mw=({className:e,...t})=>d.jsx("div",{className:`flex flex-col space-y-1.5 p-6 ${e||""}`,...t}),aF=({className:e,...t})=>d.jsx("h3",{className:`text-2xl font-semibold leading-none tracking-tight ${e||""}`,...t}),$m=({className:e,...t})=>d.jsx("div",{className:`p-6 pt-0 ${e||""}`,...t}),iF=({className:e,variant:t="default",...n})=>{const s=`relative w-full rounded-lg border p-4 ${t==="destructive"?"border-red-500/50 text-red-700 dark:border-red-900/50 dark:text-red-300":"border-azure-border dark:border-matrix-primary"} ${e||""}`;return d.jsx("div",{className:s,...n})},sF=({className:e,...t})=>d.jsx("div",{className:`text-sm [&_p]:leading-relaxed ${e||""}`,...t}),h2=({isOpen:e,onClose:t,title:n,children:a,size:s="md"})=>{if(!e)return null;const u={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl"};return d.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[d.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),d.jsxs("div",{className:`relative bg-azure-surface dark:bg-black rounded-lg border border-azure-border dark:border-matrix-primary shadow-xl w-full ${u[s]} max-h-[90vh] overflow-hidden flex flex-col`,children:[n&&d.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-azure-border dark:border-matrix-primary",children:[n&&d.jsx("h3",{className:"text-lg font-semibold text-azure-text-primary dark:text-matrix-highlight",children:n}),t&&d.jsx("button",{onClick:t,className:"text-azure-text-secondary dark:text-matrix-tertiary hover:text-azure-text-primary dark:hover:text-matrix-highlight",children:d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:d.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),d.jsx("div",{className:"overflow-y-auto flex-grow p-6",children:a})]})]})},oF=({isOpen:e,onClose:t,memory:n})=>n?d.jsx(h2,{isOpen:e,onClose:t,title:"Memory Details",size:"lg",children:d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(UA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Category"})]}),d.jsx("div",{children:d.jsx(nd,{variant:"outline",children:n.category})}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(GA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Importance"})]}),d.jsx("div",{children:d.jsx(nd,{variant:n.importance==="critical"?"destructive":n.importance==="high"?"default":n.importance==="medium"?"secondary":"outline",children:n.importance})}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(hS,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Created"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:new Date(n.created_at).toLocaleString()}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Za,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Updated"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:new Date(n.updated_at).toLocaleString()}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(sd,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Access Count"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:n.access_count}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(iA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Hash"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary break-all text-sm",children:n.hash}),n.source&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(uA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Source"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:n.source})]})]}),d.jsxs("div",{children:[d.jsx("h4",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm mb-2",children:"Summary"}),d.jsx("p",{className:"text-azure-text-primary dark:text-matrix-secondary bg-azure-surface dark:bg-zinc-900 p-3 rounded-md",children:n.summary})]}),n.details&&d.jsxs("div",{children:[d.jsx("h4",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm mb-2",children:"Details"}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary bg-azure-surface dark:bg-zinc-900 p-3 rounded-md whitespace-pre-wrap",children:n.details})]}),d.jsx("div",{className:"flex justify-end pt-4",children:d.jsx(lr,{onClick:t,children:"Close"})})]})}):null,m2=({isOpen:e,onClose:t,onConfirm:n,title:a="Confirm Deletion",message:s="Are you sure you want to delete this item? This action cannot be undone.",confirmButtonText:u="Delete",cancelButtonText:l="Cancel"})=>d.jsx(h2,{isOpen:e,onClose:t,title:a,size:"md",children:d.jsxs("div",{className:"space-y-6",children:[d.jsx("p",{className:"text-azure-text-primary dark:text-matrix-secondary",children:s}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(lr,{variant:"outline",onClick:t,children:l}),d.jsx(lr,{variant:"destructive",onClick:()=>{n(),t()},children:u})]})]})}),lF=()=>{const[e,t]=z.useState(!1),[n,a]=z.useState(null),s=z.useCallback(h=>(t(!0),a(null),xe.get(h).then(m=>m).catch(m=>{throw a(m.message||"An error occurred"),m}).finally(()=>{t(!1)})),[]),u=z.useCallback((h,m)=>(t(!0),a(null),xe.post(h,m).then(g=>g).catch(g=>{throw a(g.message||"An error occurred"),g}).finally(()=>{t(!1)})),[]),l=z.useCallback((h,m)=>(t(!0),a(null),xe.post(h,m).then(g=>g).catch(g=>{throw a(g.message||"An error occurred"),g}).finally(()=>{t(!1)})),[]),f=z.useCallback(h=>(t(!0),a(null),xe.delete(h).then(m=>m).catch(m=>{throw a(m.message||"An error occurred"),m}).finally(()=>{t(!1)})),[]);return{get:s,post:u,put:l,del:f,loading:e,error:n}},uF=()=>{const[e,t]=z.useState([]),[n,a]=z.useState(!0),[s,u]=z.useState([]),[l,f]=z.useState(""),[h,m]=z.useState("all"),[g,y]=z.useState("all"),[v,b]=z.useState(null),[S,j]=z.useState(!1),[A,E]=z.useState(null),[O,N]=z.useState(!1),[L,D]=z.useState(null),[R,q]=z.useState(!1),{get:V,del:X,post:fe}=lF();z.useEffect(()=>{se()},[]);const se=async()=>{try{a(!0);const C=await V("/sati/memories");t(C),b(null)}catch(C){b("Failed to load memories. Please try again."),console.error("Error fetching memories:",C)}finally{a(!1)}},le=()=>{s.length===B.length?u([]):u(B.map(C=>C.id))},ee=C=>{s.includes(C)?u(s.filter(I=>I!==C)):u([...s,C])},oe=async()=>{if(s.length!==0)try{await fe("/sati/memories/bulk-delete",{ids:s}),await se(),u([]),j(!1)}catch(C){b("Failed to delete memories. Please try again."),console.error("Error deleting memories:",C)}},ae=C=>{D(C),q(!0)},P=async()=>{if(L)try{await X(`/sati/memories/${L}`),await se()}catch(C){b("Failed to delete memory. Please try again."),console.error("Error deleting memory:",C)}finally{D(null),q(!1)}},J=C=>{E(C),N(!0)},B=e.filter(C=>{const I=C.summary.toLowerCase().includes(l.toLowerCase())||C.details?.toLowerCase().includes(l.toLowerCase())||C.category.toLowerCase().includes(l.toLowerCase()),w=h==="all"||C.category===h,Y=g==="all"||C.importance===g;return I&&w&&Y&&!C.archived}),me=Array.from(new Set(e.map(C=>C.category))),T=Array.from(new Set(e.map(C=>C.importance)));return n?d.jsx(Dm,{className:"w-full",children:d.jsx($m,{className:"flex justify-center items-center h-64",children:d.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-azure-primary dark:border-matrix-highlight"})})}):d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"Sati Memories"}),d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary mt-1",children:"View and manage your long-term memories stored by Sati"})]}),s.length>0&&d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs("span",{className:"text-sm text-azure-text-muted dark:text-matrix-secondary",children:[s.length," selected"]}),d.jsxs(lr,{variant:"destructive",size:"sm",onClick:()=>j(!0),disabled:s.length===0,children:[d.jsx(Ti,{className:"w-4 h-4 mr-1"}),"Delete Selected"]})]})]}),v&&d.jsx(iF,{variant:"destructive",children:d.jsx(sF,{children:v})}),d.jsxs(Dm,{children:[d.jsx(Mw,{className:"border-b border-azure-border dark:border-matrix-primary",children:d.jsxs("div",{className:"flex flex-col lg:flex-row gap-4",children:[d.jsxs("div",{className:"flex flex-col relative w-full",children:[d.jsx(OA,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-azure-text-secondary dark:text-matrix-secondary w-4 h-4"}),d.jsx("input",{type:"text",placeholder:"Search memories...",value:l,onChange:C=>f(C.target.value),className:"w-full pl-10 pr-4 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-md text-azure-text-primary dark:text-matrix-secondary focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight"})]}),d.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[d.jsxs("select",{value:h,onChange:C=>m(C.target.value),className:"px-3 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-md text-azure-text-primary dark:text-matrix-secondary focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight flex-grow",children:[d.jsx("option",{value:"all",children:"All Categories"}),me.map(C=>d.jsx("option",{value:C,children:C},C))]}),d.jsxs("select",{value:g,onChange:C=>y(C.target.value),className:"px-3 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-md text-azure-text-primary dark:text-matrix-secondary focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight flex-grow",children:[d.jsx("option",{value:"all",children:"All Importance"}),T.map(C=>d.jsx("option",{value:C,children:C},C))]})]})]})}),d.jsx($m,{className:"p-0",children:d.jsxs(tF,{children:[d.jsx(nF,{children:d.jsxs(Mm,{className:"hover:bg-transparent",children:[d.jsx(_s,{className:"w-12",children:d.jsx(Rw,{checked:B.length>0&&s.length===B.length,onCheckedChange:le})}),d.jsx(_s,{children:"Summary"}),d.jsx(_s,{children:"Category"}),d.jsx(_s,{children:"Importance"}),d.jsx(_s,{children:"Created"}),d.jsx(_s,{className:"w-32",children:"Actions"})]})}),d.jsx(rF,{children:B.length===0?d.jsx(Mm,{children:d.jsx(vi,{colSpan:6,className:"text-center py-8 text-azure-text-secondary dark:text-matrix-secondary",children:n?"Loading memories...":"No memories found"})}):B.map(C=>d.jsxs(Mm,{children:[d.jsx(vi,{children:d.jsx(Rw,{checked:s.includes(C.id),onCheckedChange:()=>ee(C.id)})}),d.jsx(vi,{className:"font-medium max-w-xs truncate",children:C.summary}),d.jsx(vi,{children:d.jsx(nd,{variant:"outline",children:C.category})}),d.jsx(vi,{children:d.jsx(nd,{variant:C.importance==="critical"?"destructive":C.importance==="high"?"default":C.importance==="medium"?"secondary":"outline",children:C.importance})}),d.jsx(vi,{children:d.jsxs("div",{className:"flex items-center gap-1 text-azure-text-secondary dark:text-matrix-secondary",children:[d.jsx(hS,{className:"w-4 h-4"}),new Date(C.created_at).toLocaleDateString()]})}),d.jsx(vi,{children:d.jsxs("div",{className:"flex gap-1",children:[d.jsx(lr,{variant:"ghost",size:"sm",onClick:()=>J(C),className:"text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",children:d.jsx(sd,{className:"w-4 h-4"})}),d.jsx(lr,{variant:"ghost",size:"sm",onClick:()=>ae(C.id),className:"text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},C.id))})]})})]}),S&&d.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:d.jsxs(Dm,{className:"w-full max-w-md mx-4",children:[d.jsx(Mw,{children:d.jsx(aF,{children:"Delete Memories"})}),d.jsxs($m,{children:[d.jsxs("p",{className:"mb-4",children:["Are you sure you want to delete ",s.length," ","memory(ies)? This action cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(lr,{variant:"outline",onClick:()=>j(!1),children:"Cancel"}),d.jsx(lr,{variant:"destructive",onClick:oe,children:"Delete"})]})]})]})}),d.jsx(oF,{isOpen:O,onClose:()=>N(!1),memory:A}),d.jsx(m2,{isOpen:R,onClose:()=>q(!1),onConfirm:P,title:"Confirm Memory Deletion",message:"Are you sure you want to delete this memory? This action cannot be undone.",confirmButtonText:"Delete Memory",cancelButtonText:"Cancel"})]})},ki=_i.getInstance(),wi={fetchServers:async()=>ki.get("/mcp/servers"),addServer:async(e,t)=>ki.post("/mcp/servers",{name:e,config:t}),updateServer:async(e,t)=>ki.put(`/mcp/servers/${encodeURIComponent(e)}`,{config:t}),deleteServer:async e=>ki.delete(`/mcp/servers/${encodeURIComponent(e)}`),toggleServer:async(e,t)=>ki.patch(`/mcp/servers/${encodeURIComponent(e)}/toggle`,{enabled:t}),reloadTools:async()=>ki.post("/mcp/reload",{}),fetchStatus:async()=>ki.get("/mcp/status")},cF=({label:e,values:t,onChange:n,placeholder:a})=>{const s=t.length>0?t:[""],u=(h,m)=>{const g=[...s];g[h]=m,n(g.filter(y=>y.trim().length>0))},l=()=>n([...s,""]),f=h=>{const m=s.filter((g,y)=>y!==h);n(m.filter(g=>g.trim().length>0))};return d.jsxs("div",{className:"space-y-2",children:[d.jsx("div",{className:"text-sm font-semibold text-azure-text-primary dark:text-matrix-secondary",children:e}),s.map((h,m)=>d.jsxs("div",{className:"flex gap-2",children:[d.jsx("input",{className:"flex-1 rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:h,placeholder:a,onChange:g=>u(m,g.target.value)}),d.jsx("button",{type:"button",className:"rounded-md border border-red-300 px-3 py-2 text-sm text-red-600 hover:border-red-400 hover:text-red-500 dark:border-red-900 dark:text-red-400",onClick:()=>f(m),children:"Remove"})]},`${e}-${m}`)),d.jsx("button",{type:"button",className:"text-sm font-semibold text-azure-primary hover:text-azure-secondary dark:text-matrix-highlight hover:dark:text-matrix-secondary",onClick:l,children:"Add argument"})]})},Dw=({label:e,values:t,onChange:n,keyPlaceholder:a,valuePlaceholder:s})=>{const u=z.useMemo(()=>t.length>0?t:[{key:"",value:""}],[t]),l=(m,g,y)=>{const v=[...u];v[m]={...v[m],[g]:y},n(v.filter(b=>b.key.trim().length>0||b.value.trim().length>0))},f=()=>n([...u,{key:"",value:""}]),h=m=>{const g=u.filter((y,v)=>v!==m);n(g.filter(y=>y.key.trim().length>0||y.value.trim().length>0))};return d.jsxs("div",{className:"space-y-2",children:[d.jsx("div",{className:"text-sm font-semibold text-azure-text-primary dark:text-matrix-secondary",children:e}),u.map((m,g)=>d.jsxs("div",{className:"grid gap-2 md:grid-cols-5",children:[d.jsx("input",{className:"col-span-2 rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:m.key,placeholder:a,onChange:y=>l(g,"key",y.target.value)}),d.jsx("input",{className:"col-span-2 rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:m.value,placeholder:s,onChange:y=>l(g,"value",y.target.value)}),d.jsx("button",{type:"button",className:"rounded-md border border-red-300 px-3 py-2 text-sm text-red-600 hover:border-red-400 hover:text-red-500 dark:border-red-900 dark:text-red-400",onClick:()=>h(g),children:"Remove"})]},`${e}-${g}`)),d.jsx("button",{type:"button",className:"text-sm font-semibold text-azure-primary hover:text-azure-secondary dark:text-matrix-highlight hover:dark:text-matrix-secondary",onClick:f,children:"Add entry"})]})},dF=({transport:e,command:t,url:n,args:a,env:s,headers:u,onCommandChange:l,onUrlChange:f,onArgsChange:h,onEnvChange:m,onHeadersChange:g})=>d.jsxs("div",{className:"space-y-4",children:[e==="stdio"&&d.jsxs(d.Fragment,{children:[d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Command",d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:t,onChange:y=>l(y.target.value),placeholder:"npx"})]}),d.jsx(cF,{label:"Arguments",values:a,onChange:h,placeholder:"--flag"})]}),e==="http"&&d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["URL",d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:n,onChange:y=>f(y.target.value),placeholder:"https://example.com/mcp"})]}),d.jsx(Dw,{label:"Environment Variables",values:s,onChange:m,keyPlaceholder:"KEY",valuePlaceholder:"value"}),e==="http"&&d.jsx(Dw,{label:"Headers",values:u,onChange:g,keyPlaceholder:"Header",valuePlaceholder:"value"})]}),fF=zH({name:Rm().min(1,"Name is required"),transport:c2([Ew("stdio"),Ew("http")]),command:Rm().optional(),url:Rm().optional()}),jc=e=>e?Object.entries(e).map(([t,n])=>({key:t,value:n})):[],Lm=e=>e.reduce((t,n)=>(n.key.trim().length===0||(t[n.key]=n.value),t),{}),hF=({open:e,mode:t,initial:n,onClose:a,onSubmit:s})=>{const[u,l]=z.useState(n?.name??""),[f,h]=z.useState(n?.config.transport??"stdio"),[m,g]=z.useState(n?.config.transport==="stdio"?n.config.command:""),[y,v]=z.useState(n?.config.transport==="http"?n.config.url:""),[b,S]=z.useState(n?.config.args??[]),[j,A]=z.useState(jc(n?.config.env)),[E,O]=z.useState(n?.config.transport==="http"?jc(n.config.headers):[]),[N,L]=z.useState(null);z.useEffect(()=>{e&&(l(n?.name??""),h(n?.config.transport??"stdio"),g(n?.config.transport==="stdio"?n.config.command:""),v(n?.config.transport==="http"?n.config.url:""),S(n?.config.args??[]),A(jc(n?.config.env)),O(n?.config.transport==="http"?jc(n.config.headers):[]),L(null))},[e,n]);const D=t==="create",R=async()=>{const V=fF.safeParse({name:u,transport:f,command:m,url:y});if(!V.success){L(V.error.issues[0]?.message??"Invalid form");return}if(f==="stdio"&&(!m||m.trim().length===0)){L("Command is required for stdio transport.");return}if(f==="http"&&(!y||y.trim().length===0)){L("URL is required for http transport.");return}const X=f==="stdio"?{transport:"stdio",command:m.trim(),args:b.length>0?b:void 0,env:j.length>0?Lm(j):void 0}:{transport:"http",url:y.trim(),headers:E.length>0?Lm(E):void 0,env:j.length>0?Lm(j):void 0};L(null),await s(u.trim(),X)},q=z.useMemo(()=>t==="create"?"Add MCP Server":"Edit MCP Server",[t]);return d.jsx(Or,{open:e,onOpenChange:a,children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:q})}),d.jsxs("div",{className:"space-y-4",children:[d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Name",d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none disabled:bg-azure-border dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary dark:disabled:bg-matrix-primary/50",value:u,onChange:V=>l(V.target.value),placeholder:"coolify",disabled:!D})]}),d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Transport",d.jsxs("select",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:f,onChange:V=>h(V.target.value),children:[d.jsx("option",{value:"stdio",children:"stdio"}),d.jsx("option",{value:"http",children:"http"})]})]}),d.jsx(dF,{transport:f,command:m,url:y,args:b,env:j,headers:E,onCommandChange:g,onUrlChange:v,onArgsChange:S,onEnvChange:A,onHeadersChange:O}),N&&d.jsx("div",{className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/50 dark:text-red-400",children:N}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx("button",{type:"button",className:"rounded-md border border-azure-border px-4 py-2 text-sm text-azure-text-primary hover:border-azure-primary hover:text-azure-primary dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:a,children:"Cancel"}),d.jsx("button",{type:"button",className:"rounded-md bg-azure-primary px-4 py-2 text-sm font-semibold text-white shadow hover:bg-azure-secondary dark:bg-matrix-highlight dark:text-matrix-bg hover:dark:bg-matrix-secondary",onClick:R,children:"Save"})]})]})]})})},mF=({server:e,probeResult:t,onEdit:n,onDelete:a,onToggle:s})=>d.jsxs("div",{className:"rounded-2xl border border-azure-border bg-azure-surface/80 p-4 shadow-sm overflow-hidden dark:border-matrix-primary dark:bg-zinc-950/70",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3",children:[d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsx("div",{className:"text-lg font-semibold text-azure-text-primary break-words dark:text-matrix-highlight",children:e.name}),d.jsx("div",{className:"text-xs uppercase tracking-wide text-azure-text-muted dark:text-matrix-secondary",children:e.config.transport})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[t&&d.jsx("span",{title:t.ok?`${t.toolCount} tools`:t.error,className:`rounded-full px-2 py-0.5 text-xs font-semibold ${t.ok?"bg-green-500/20 text-green-600 dark:bg-green-400/20 dark:text-green-400":"bg-red-500/20 text-red-600 dark:bg-red-400/20 dark:text-red-400"}`,children:t.ok?`✓ ${t.toolCount} tools`:"✗ Failed"}),d.jsx("button",{type:"button",className:`rounded-full px-3 py-1 text-xs font-semibold ${e.enabled?"bg-matrix-highlight dark:text-matrix-primary":"bg-azure-border text-azure-text-secondary dark:bg-matrix-primary/50 dark:text-matrix-secondary"}`,onClick:()=>s(e,!e.enabled),children:e.enabled?"Enabled":"Disabled"})]})]}),d.jsxs("div",{className:"mt-4 space-y-2 text-sm text-azure-text-secondary dark:text-matrix-secondary",children:[e.config.transport==="stdio"&&d.jsxs("div",{className:"break-all",children:[d.jsx("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:"Command:"})," ",e.config.command]}),e.config.transport==="http"&&d.jsxs("div",{className:"break-all",children:[d.jsx("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:"URL:"})," ",e.config.url]}),e.config.args&&e.config.args.length>0&&d.jsxs("div",{className:"break-all",children:[d.jsx("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:"Args:"})," ",e.config.args.join(" ")]}),t&&!t.ok&&t.error&&d.jsx("div",{className:"mt-1 break-all rounded border border-red-300 bg-red-50 px-2 py-1 text-xs text-red-600 dark:border-red-900 dark:bg-red-950/30 dark:text-red-400",children:t.error.length>120?t.error.slice(0,120)+"…":t.error})]}),d.jsxs("div",{className:"mt-4 flex gap-2",children:[d.jsx("button",{type:"button",className:"rounded-md border border-azure-border px-3 py-2 text-sm text-azure-text-primary hover:border-azure-primary hover:text-azure-primary dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:()=>n(e),children:"Edit"}),d.jsx("button",{type:"button",className:"rounded-md border border-red-300 px-3 py-2 text-sm text-red-600 hover:border-red-400 hover:text-red-500 dark:border-red-900 dark:text-red-400",onClick:()=>a(e),children:"Delete"})]})]}),pF=()=>{const{data:e,error:t,mutate:n,isLoading:a}=zt("/api/mcp/servers",()=>wi.fetchServers()),[s,u]=z.useState(""),[l,f]=z.useState("all"),[h,m]=z.useState(!1),[g,y]=z.useState(null),[v,b]=z.useState(!1),[S,j]=z.useState(null),[A,E]=z.useState(null),[O,N]=z.useState({}),[L,D]=z.useState(!1),[R,q]=z.useState(!1),V=e?.servers??[],X=z.useMemo(()=>V.filter(B=>{const me=B.name.toLowerCase().includes(s.toLowerCase()),T=l==="all"||B.config.transport===l;return me&&T}),[V,s,l]),fe=()=>{y(null),m(!0)},se=B=>{y(B),m(!0)},le=async(B,me)=>{try{g?await wi.updateServer(g.name,me):await wi.addServer(B,me),m(!1),y(null),await n(),E({type:"success",message:"MCPs saved successfully. Restart MCPs for changes to take effect."})}catch(T){E({type:"error",message:T.message||"Failed to save MCP server."})}},ee=async B=>{j(B),b(!0)},oe=async()=>{if(S)try{await wi.deleteServer(S.name),await n(),b(!1),j(null),E({type:"success",message:"MCPs saved successfully. Restart MCPs for changes to take effect."})}catch(B){E({type:"error",message:B.message||"Failed to delete MCP server."})}},ae=async()=>{D(!0);try{const B=await wi.fetchStatus(),me={};for(const T of B.servers)me[T.name]=T;N(me)}catch(B){E({type:"error",message:B.message||"Failed to check MCP status."})}finally{D(!1)}},P=async()=>{q(!0);try{await wi.reloadTools(),E({type:"success",message:"MCP tools reloaded successfully."})}catch(B){E({type:"error",message:B.message||"Failed to reload MCP tools."})}finally{q(!1)}},J=async(B,me)=>{try{await wi.toggleServer(B.name,me),await n(),E({type:"success",message:"MCPs saved successfully. Restart MCPs for changes to take effect."})}catch(T){E({type:"error",message:T.message||"Failed to toggle MCP server."})}};return d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-semibold text-azure-primary dark:text-matrix-highlight",children:"MCP Servers"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:"Manage MCP servers stored in mcps.json."})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx("button",{type:"button",disabled:L,className:"rounded-md border border-azure-border px-4 py-2 text-sm font-semibold text-azure-text-primary shadow hover:border-azure-primary hover:text-azure-primary disabled:opacity-50 dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:ae,children:L?"Checking…":"Check Status"}),d.jsx("button",{type:"button",disabled:R,className:"rounded-md border border-azure-border px-4 py-2 text-sm font-semibold text-azure-text-primary shadow hover:border-azure-primary hover:text-azure-primary disabled:opacity-50 dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:P,children:R?"Reloading…":"Reload MCPs"}),d.jsx("button",{type:"button",className:"rounded-md bg-azure-primary px-4 py-2 text-sm font-semibold text-white shadow hover:bg-azure-secondary dark:bg-matrix-highlight dark:text-matrix-bg hover:dark:bg-matrix-secondary",onClick:fe,children:"Add Server"})]})]}),A&&d.jsx("div",{className:`p-4 rounded border ${A.type==="success"?"border-azure-primary text-azure-primary bg-azure-primary/10 dark:border-matrix-highlight dark:text-matrix-highlight dark:bg-matrix-highlight/10":"border-red-500 text-red-500 bg-red-900/10"}`,children:A.message}),d.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center",children:[d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:s,onChange:B=>u(B.target.value),placeholder:"Search by name"}),d.jsxs("select",{className:"rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:l,onChange:B=>f(B.target.value),children:[d.jsx("option",{value:"all",children:"All"}),d.jsx("option",{value:"stdio",children:"stdio"}),d.jsx("option",{value:"http",children:"http"})]})]}),a&&d.jsx("div",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:"Loading MCP servers..."}),t&&d.jsx("div",{className:"text-sm text-red-600 dark:text-red-400",children:"Failed to load MCP servers."}),!a&&X.length===0&&d.jsx("div",{className:"rounded-2xl border border-dashed border-azure-border bg-azure-surface/60 p-6 text-center text-sm text-azure-text-secondary dark:border-matrix-primary dark:bg-zinc-950/60 dark:text-matrix-secondary",children:"No MCP servers found. Add a server to get started."}),d.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:X.map(B=>d.jsx(mF,{server:B,probeResult:O[B.name],onEdit:se,onDelete:ee,onToggle:J},`${B.name}-${B.enabled?"on":"off"}`))}),d.jsx(hF,{open:h,mode:g?"edit":"create",initial:g??void 0,onClose:()=>m(!1),onSubmit:le}),d.jsx(Or,{open:v,onOpenChange:b,children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:"Confirm Deletion"})}),d.jsxs("div",{className:"space-y-4",children:[d.jsxs("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:["Are you sure you want to delete the MCP server ",d.jsxs("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:['"',S?.name,'"']}),"? This action cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx("button",{type:"button",className:"rounded-md border border-azure-border px-4 py-2 text-sm text-azure-text-primary hover:border-azure-primary hover:text-azure-primary dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:()=>b(!1),children:"Cancel"}),d.jsx("button",{type:"button",className:"rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white shadow hover:bg-red-400 dark:bg-red-600 hover:dark:bg-red-500",onClick:oe,children:"Delete"})]})]})]})})]})},Pm={list:()=>xe.get("/model-pricing"),upsert:e=>xe.post("/model-pricing",e),update:(e,t,n)=>xe.put(`/model-pricing/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,n),delete:(e,t)=>xe.delete(`/model-pricing/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)},gF={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},$w={hidden:{opacity:0,y:10},show:{opacity:1,y:0}},xF=["anthropic","openai","google","openrouter","ollama","other"],Lw=()=>({provider:"",model:"",input_price_per_1m:0,output_price_per_1m:0}),yF=()=>{const{data:e=[],mutate:t}=zt("/api/model-pricing",()=>Pm.list()),[n,a]=z.useState(!1),[s,u]=z.useState(null),[l,f]=z.useState(Lw()),[h,m]=z.useState(null),[g,y]=z.useState(null),[v,b]=z.useState(!1),S=(N,L)=>{y({type:N,message:L}),setTimeout(()=>y(null),3e3)},j=()=>{u(null),f(Lw()),a(!0)},A=N=>{u(N),f({...N}),a(!0)},E=async()=>{if(!(!l.provider.trim()||!l.model.trim())){b(!0);try{await Pm.upsert(l),await t(),a(!1),S("success",s?"Pricing updated.":"Pricing created.")}catch{S("error","Failed to save pricing entry.")}finally{b(!1)}}},O=async()=>{if(h)try{await Pm.delete(h.provider,h.model),await t(),m(null),S("success","Pricing entry deleted.")}catch{S("error","Failed to delete pricing entry.")}};return d.jsxs(dt.div,{variants:gF,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:$w,className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Pc,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Model Pricing"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mt-0.5",children:"Manage per-model pricing to estimate LLM costs in Usage Stats."})]})]}),d.jsxs("button",{onClick:j,className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[d.jsx(od,{className:"w-4 h-4"})," Add Pricing"]})]}),g&&d.jsx(dt.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:`px-4 py-3 rounded-lg text-sm font-medium border ${g.type==="success"?"bg-green-50 dark:bg-green-900/20 border-green-300 dark:border-green-700 text-green-800 dark:text-green-400":"bg-red-50 dark:bg-red-900/20 border-red-300 dark:border-red-700 text-red-800 dark:text-red-400"}`,children:g.message}),d.jsx(dt.div,{variants:$w,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-hidden",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["Provider","Model","Input ($/1M tokens)","Output ($/1M tokens)","Actions"].map(N=>d.jsx("th",{className:"px-4 py-3 text-left font-semibold text-azure-text-secondary dark:text-matrix-secondary",children:N},N))})}),d.jsx("tbody",{children:e.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-azure-text-secondary dark:text-matrix-secondary",children:'No pricing entries. Click "Add Pricing" to get started.'})}):e.map(N=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-800/50 transition-colors",children:[d.jsx("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-text capitalize",children:N.provider}),d.jsx("td",{className:"px-4 py-3 font-mono text-azure-text-primary dark:text-matrix-highlight text-xs",children:N.model}),d.jsxs("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-text",children:["$",N.input_price_per_1m.toFixed(4)]}),d.jsxs("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-text",children:["$",N.output_price_per_1m.toFixed(4)]}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx("button",{onClick:()=>A(N),className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",title:"Edit",children:d.jsx(Wp,{className:"w-4 h-4"})}),d.jsx("button",{onClick:()=>m(N),className:"p-1.5 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-azure-text-secondary dark:text-matrix-secondary hover:text-red-600 dark:hover:text-red-400 transition-colors",title:"Delete",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},`${N.provider}/${N.model}`))})]})}),d.jsx(Or,{open:n,onOpenChange:a,children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:s?"Edit Pricing":"Add Pricing"})}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Provider"}),s?d.jsx("p",{className:"px-3 py-2 rounded-lg bg-azure-bg dark:bg-zinc-900 text-azure-text-primary dark:text-matrix-secondary text-sm capitalize",children:l.provider}):d.jsxs("select",{value:l.provider,onChange:N=>f({...l,provider:N.target.value}),className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight",children:[d.jsx("option",{value:"",children:"Select provider..."}),xF.map(N=>d.jsx("option",{value:N,children:N},N))]})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Model"}),s?d.jsx("p",{className:"px-3 py-2 rounded-lg bg-azure-bg dark:bg-zinc-900 text-azure-text-primary dark:text-matrix-secondary text-sm font-mono",children:l.model}):d.jsx("input",{type:"text",value:l.model,onChange:N=>f({...l,model:N.target.value}),placeholder:"e.g. gpt-4o",className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight"})]}),d.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Input price / 1M tokens ($)"}),d.jsx("input",{type:"number",min:0,step:.001,value:l.input_price_per_1m,onChange:N=>f({...l,input_price_per_1m:parseFloat(N.target.value)||0}),className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight"})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Output price / 1M tokens ($)"}),d.jsx("input",{type:"number",min:0,step:.001,value:l.output_price_per_1m,onChange:N=>f({...l,output_price_per_1m:parseFloat(N.target.value)||0}),className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight"})]})]}),d.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[d.jsx("button",{onClick:()=>a(!1),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:E,disabled:v||!l.provider.trim()||!l.model.trim(),className:"px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 disabled:opacity-50 transition-opacity",children:v?"Saving...":"Save"})]})]})]})}),d.jsx(Or,{open:!!h,onOpenChange:N=>!N&&m(null),children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:"Delete Pricing Entry"})}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsxs("p",{className:"text-sm text-azure-text-primary dark:text-matrix-text",children:["Are you sure you want to delete the pricing for"," ",d.jsxs("span",{className:"font-mono font-semibold text-azure-primary dark:text-matrix-highlight",children:[h?.provider,"/",h?.model]}),"? This cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-3",children:[d.jsx("button",{onClick:()=>m(null),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:O,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition-colors",children:"Delete"})]})]})]})})]})},bF={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},Pw={hidden:{opacity:0,y:10},show:{opacity:1,y:0}},vF=["ui","telegram","discord"],Uw=()=>({name:"",prompt:"",notification_channels:["ui"]}),kF=()=>{const{data:e=[],mutate:t}=zt("/webhooks",()=>Pa.list(),{refreshInterval:1e4}),[n,a]=z.useState(!1),[s,u]=z.useState(null),[l,f]=z.useState(Uw()),[h,m]=z.useState(null),[g,y]=z.useState(null),[v,b]=z.useState(!1),[S,j]=z.useState(null),[A,E]=z.useState(null),O=(ee,oe)=>{y({type:ee,message:oe}),setTimeout(()=>y(null),3500)},N=()=>{u(null),f(Uw()),E(null),a(!0)},L=ee=>{u(ee),f({name:ee.name,prompt:ee.prompt,notification_channels:ee.notification_channels}),E(null),a(!0)},D=ee=>/^[a-z0-9-_]+$/.test(ee),R=async()=>{if(!(!l.name.trim()||!l.prompt.trim())){if(!D(l.name)){E("Name must only contain lowercase letters, numbers, hyphens (-) and underscores (_).");return}if(l.notification_channels.length===0){E("Select at least one notification channel.");return}E(null),b(!0);try{s?(await Pa.update(s.id,l),O("success","Webhook updated.")):(await Pa.create(l),O("success","Webhook created.")),await t(),a(!1)}catch(ee){const oe=ee?.message||"Failed to save webhook.";E(oe)}finally{b(!1)}}},q=async ee=>{try{await Pa.update(ee.id,{enabled:!ee.enabled}),await t()}catch{O("error","Failed to toggle webhook.")}},V=async()=>{if(h)try{await Pa.delete(h.id),await t(),m(null),O("success","Webhook deleted.")}catch{O("error","Failed to delete webhook.")}},X=ee=>`${window.location.origin}/api/webhooks/trigger/${ee}`,fe=ee=>`curl -X POST ${X(ee.name)} \\
108
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const l of e.seen.entries()){const f=l[1];if(t===l[0]){u(l);continue}if(e.external){const m=e.external.registry.get(l[0])?.id;if(t!==l[0]&&m){u(l);continue}}if(e.metadataRegistry.get(l[0])?.id){u(l);continue}if(f.cycle){u(l);continue}if(f.count>1&&e.reused==="ref"){u(l);continue}}}function s2(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const a=l=>{const f=e.seen.get(l);if(f.ref===null)return;const h=f.def??f.schema,m={...h},g=f.ref;if(f.ref=null,g){a(g);const v=e.seen.get(g),b=v.schema;if(b.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(h.allOf=h.allOf??[],h.allOf.push(b)):Object.assign(h,b),Object.assign(h,m),l._zod.parent===g)for(const j in h)j==="$ref"||j==="allOf"||j in m||delete h[j];if(b.$ref&&v.def)for(const j in h)j==="$ref"||j==="allOf"||j in v.def&&JSON.stringify(h[j])===JSON.stringify(v.def[j])&&delete h[j]}const y=l._zod.parent;if(y&&y!==g){a(y);const v=e.seen.get(y);if(v?.schema.$ref&&(h.$ref=v.schema.$ref,v.def))for(const b in h)b==="$ref"||b==="allOf"||b in v.def&&JSON.stringify(h[b])===JSON.stringify(v.def[b])&&delete h[b]}e.override({zodSchema:l,jsonSchema:h,path:f.path??[]})};for(const l of[...e.seen.entries()].reverse())a(l[0]);const s={};if(e.target==="draft-2020-12"?s.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?s.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?s.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const l=e.external.registry.get(t)?.id;if(!l)throw new Error("Schema is missing an `id` property");s.$id=e.external.uri(l)}Object.assign(s,n.def??n.schema);const u=e.external?.defs??{};for(const l of e.seen.entries()){const f=l[1];f.def&&f.defId&&(u[f.defId]=f.def)}e.external||Object.keys(u).length>0&&(e.target==="draft-2020-12"?s.$defs=u:s.definitions=u);try{const l=JSON.parse(JSON.stringify(s));return Object.defineProperty(l,"~standard",{value:{...t["~standard"],jsonSchema:{input:td(t,"input",e.processors),output:td(t,"output",e.processors)}},enumerable:!1,writable:!1}),l}catch{throw new Error("Error converting schema to JSON.")}}function vn(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const a=e._zod.def;if(a.type==="transform")return!0;if(a.type==="array")return vn(a.element,n);if(a.type==="set")return vn(a.valueType,n);if(a.type==="lazy")return vn(a.getter(),n);if(a.type==="promise"||a.type==="optional"||a.type==="nonoptional"||a.type==="nullable"||a.type==="readonly"||a.type==="default"||a.type==="prefault")return vn(a.innerType,n);if(a.type==="intersection")return vn(a.left,n)||vn(a.right,n);if(a.type==="record"||a.type==="map")return vn(a.keyType,n)||vn(a.valueType,n);if(a.type==="pipe")return vn(a.in,n)||vn(a.out,n);if(a.type==="object"){for(const s in a.shape)if(vn(a.shape[s],n))return!0;return!1}if(a.type==="union"){for(const s of a.options)if(vn(s,n))return!0;return!1}if(a.type==="tuple"){for(const s of a.items)if(vn(s,n))return!0;return!!(a.rest&&vn(a.rest,n))}return!1}const h7=(e,t={})=>n=>{const a=a2({...n,processors:t});return un(e,a),i2(a,e),s2(a,e)},td=(e,t,n={})=>a=>{const{libraryOptions:s,target:u}=a??{},l=a2({...s??{},target:u,io:t,processors:n});return un(e,l),i2(l,e),s2(l,e)},m7={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},p7=(e,t,n,a)=>{const s=n;s.type="string";const{minimum:u,maximum:l,format:f,patterns:h,contentEncoding:m}=e._zod.bag;if(typeof u=="number"&&(s.minLength=u),typeof l=="number"&&(s.maxLength=l),f&&(s.format=m7[f]??f,s.format===""&&delete s.format,f==="time"&&delete s.format),m&&(s.contentEncoding=m),h&&h.size>0){const g=[...h];g.length===1?s.pattern=g[0].source:g.length>1&&(s.allOf=[...g.map(y=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:y.source}))])}},g7=(e,t,n,a)=>{n.not={}},x7=(e,t,n,a)=>{},y7=(e,t,n,a)=>{const s=e._zod.def,u=Zj(s.entries);u.every(l=>typeof l=="number")&&(n.type="number"),u.every(l=>typeof l=="string")&&(n.type="string"),n.enum=u},b7=(e,t,n,a)=>{const s=e._zod.def,u=[];for(const l of s.values)if(l===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof l=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");u.push(Number(l))}else u.push(l);if(u.length!==0)if(u.length===1){const l=u[0];n.type=l===null?"null":typeof l,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[l]:n.const=l}else u.every(l=>typeof l=="number")&&(n.type="number"),u.every(l=>typeof l=="string")&&(n.type="string"),u.every(l=>typeof l=="boolean")&&(n.type="boolean"),u.every(l=>l===null)&&(n.type="null"),n.enum=u},v7=(e,t,n,a)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},k7=(e,t,n,a)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},w7=(e,t,n,a)=>{const s=n,u=e._zod.def,{minimum:l,maximum:f}=e._zod.bag;typeof l=="number"&&(s.minItems=l),typeof f=="number"&&(s.maxItems=f),s.type="array",s.items=un(u.element,t,{...a,path:[...a.path,"items"]})},S7=(e,t,n,a)=>{const s=n,u=e._zod.def;s.type="object",s.properties={};const l=u.shape;for(const m in l)s.properties[m]=un(l[m],t,{...a,path:[...a.path,"properties",m]});const f=new Set(Object.keys(l)),h=new Set([...f].filter(m=>{const g=u.shape[m]._zod;return t.io==="input"?g.optin===void 0:g.optout===void 0}));h.size>0&&(s.required=Array.from(h)),u.catchall?._zod.def.type==="never"?s.additionalProperties=!1:u.catchall?u.catchall&&(s.additionalProperties=un(u.catchall,t,{...a,path:[...a.path,"additionalProperties"]})):t.io==="output"&&(s.additionalProperties=!1)},z7=(e,t,n,a)=>{const s=e._zod.def,u=s.inclusive===!1,l=s.options.map((f,h)=>un(f,t,{...a,path:[...a.path,u?"oneOf":"anyOf",h]}));u?n.oneOf=l:n.anyOf=l},_7=(e,t,n,a)=>{const s=e._zod.def,u=un(s.left,t,{...a,path:[...a.path,"allOf",0]}),l=un(s.right,t,{...a,path:[...a.path,"allOf",1]}),f=m=>"allOf"in m&&Object.keys(m).length===1,h=[...f(u)?u.allOf:[u],...f(l)?l.allOf:[l]];n.allOf=h},j7=(e,t,n,a)=>{const s=e._zod.def,u=un(s.innerType,t,a),l=t.seen.get(e);t.target==="openapi-3.0"?(l.ref=s.innerType,n.nullable=!0):n.anyOf=[u,{type:"null"}]},N7=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType},C7=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,n.default=JSON.parse(JSON.stringify(s.defaultValue))},E7=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(s.defaultValue)))},T7=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType;let l;try{l=s.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=l},A7=(e,t,n,a)=>{const s=e._zod.def,u=t.io==="input"?s.in._zod.def.type==="transform"?s.out:s.in:s.out;un(u,t,a);const l=t.seen.get(e);l.ref=u},O7=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType,n.readOnly=!0},o2=(e,t,n,a)=>{const s=e._zod.def;un(s.innerType,t,a);const u=t.seen.get(e);u.ref=s.innerType},R7=ie("ZodISODateTime",(e,t)=>{IZ.init(e,t),Et.init(e,t)});function M7(e){return qI(R7,e)}const D7=ie("ZodISODate",(e,t)=>{HZ.init(e,t),Et.init(e,t)});function $7(e){return GI(D7,e)}const L7=ie("ZodISOTime",(e,t)=>{FZ.init(e,t),Et.init(e,t)});function P7(e){return YI(L7,e)}const U7=ie("ZodISODuration",(e,t)=>{qZ.init(e,t),Et.init(e,t)});function V7(e){return KI(U7,e)}const l2=(e,t)=>{Gj.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>VB(e,n)},flatten:{value:n=>UB(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,Vp,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,Vp,2)}},isEmpty:{get(){return e.issues.length===0}}})},B7=ie("ZodError",l2),fr=ie("ZodError",l2,{Parent:Error}),Z7=ox(fr),I7=lx(fr),H7=vd(fr),F7=kd(fr),q7=IB(fr),G7=HB(fr),Y7=FB(fr),K7=qB(fr),X7=GB(fr),J7=YB(fr),Q7=KB(fr),W7=XB(fr),qt=ie("ZodType",(e,t)=>(Ft.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:td(e,"input"),output:td(e,"output")}}),e.toJSONSchema=h7(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Qa(t,{checks:[...t.checks??[],...n.map(a=>typeof a=="function"?{_zod:{check:a,def:{check:"custom"},onattach:[]}}:a)]}),{parent:!0}),e.with=e.check,e.clone=(n,a)=>Wa(e,n,a),e.brand=()=>e,e.register=((n,a)=>(n.add(e,a),e)),e.parse=(n,a)=>Z7(e,n,a,{callee:e.parse}),e.safeParse=(n,a)=>H7(e,n,a),e.parseAsync=async(n,a)=>I7(e,n,a,{callee:e.parseAsync}),e.safeParseAsync=async(n,a)=>F7(e,n,a),e.spa=e.safeParseAsync,e.encode=(n,a)=>q7(e,n,a),e.decode=(n,a)=>G7(e,n,a),e.encodeAsync=async(n,a)=>Y7(e,n,a),e.decodeAsync=async(n,a)=>K7(e,n,a),e.safeEncode=(n,a)=>X7(e,n,a),e.safeDecode=(n,a)=>J7(e,n,a),e.safeEncodeAsync=async(n,a)=>Q7(e,n,a),e.safeDecodeAsync=async(n,a)=>W7(e,n,a),e.refine=(n,a)=>e.check(qH(n,a)),e.superRefine=n=>e.check(GH(n)),e.overwrite=n=>e.check(oo(n)),e.optional=()=>Tw(e),e.exactOptional=()=>RH(e),e.nullable=()=>Aw(e),e.nullish=()=>Tw(Aw(e)),e.nonoptional=n=>UH(e,n),e.array=()=>wH(e),e.or=n=>c2([e,n]),e.and=n=>NH(e,n),e.transform=n=>Ow(e,AH(n)),e.default=n=>$H(e,n),e.prefault=n=>PH(e,n),e.catch=n=>BH(e,n),e.pipe=n=>Ow(e,n),e.readonly=()=>HH(e),e.describe=n=>{const a=e.clone();return ml.add(a,{description:n}),a},Object.defineProperty(e,"description",{get(){return ml.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return ml.get(e);const a=e.clone();return ml.add(a,n[0]),a},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),u2=ie("_ZodString",(e,t)=>{ux.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>p7(e,a,s);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...a)=>e.check(QI(...a)),e.includes=(...a)=>e.check(t7(...a)),e.startsWith=(...a)=>e.check(n7(...a)),e.endsWith=(...a)=>e.check(r7(...a)),e.min=(...a)=>e.check(ed(...a)),e.max=(...a)=>e.check(n2(...a)),e.length=(...a)=>e.check(r2(...a)),e.nonempty=(...a)=>e.check(ed(1,...a)),e.lowercase=a=>e.check(WI(a)),e.uppercase=a=>e.check(e7(a)),e.trim=()=>e.check(i7()),e.normalize=(...a)=>e.check(a7(...a)),e.toLowerCase=()=>e.check(s7()),e.toUpperCase=()=>e.check(o7()),e.slugify=()=>e.check(l7())}),eH=ie("ZodString",(e,t)=>{ux.init(e,t),u2.init(e,t),e.email=n=>e.check(_I(tH,n)),e.url=n=>e.check(TI(nH,n)),e.jwt=n=>e.check(FI(xH,n)),e.emoji=n=>e.check(AI(rH,n)),e.guid=n=>e.check(jw(Nw,n)),e.uuid=n=>e.check(jI(_c,n)),e.uuidv4=n=>e.check(NI(_c,n)),e.uuidv6=n=>e.check(CI(_c,n)),e.uuidv7=n=>e.check(EI(_c,n)),e.nanoid=n=>e.check(OI(aH,n)),e.guid=n=>e.check(jw(Nw,n)),e.cuid=n=>e.check(RI(iH,n)),e.cuid2=n=>e.check(MI(sH,n)),e.ulid=n=>e.check(DI(oH,n)),e.base64=n=>e.check(ZI(mH,n)),e.base64url=n=>e.check(II(pH,n)),e.xid=n=>e.check($I(lH,n)),e.ksuid=n=>e.check(LI(uH,n)),e.ipv4=n=>e.check(PI(cH,n)),e.ipv6=n=>e.check(UI(dH,n)),e.cidrv4=n=>e.check(VI(fH,n)),e.cidrv6=n=>e.check(BI(hH,n)),e.e164=n=>e.check(HI(gH,n)),e.datetime=n=>e.check(M7(n)),e.date=n=>e.check($7(n)),e.time=n=>e.check(P7(n)),e.duration=n=>e.check(V7(n))});function Rm(e){return zI(eH,e)}const Et=ie("ZodStringFormat",(e,t)=>{St.init(e,t),u2.init(e,t)}),tH=ie("ZodEmail",(e,t)=>{MZ.init(e,t),Et.init(e,t)}),Nw=ie("ZodGUID",(e,t)=>{OZ.init(e,t),Et.init(e,t)}),_c=ie("ZodUUID",(e,t)=>{RZ.init(e,t),Et.init(e,t)}),nH=ie("ZodURL",(e,t)=>{DZ.init(e,t),Et.init(e,t)}),rH=ie("ZodEmoji",(e,t)=>{$Z.init(e,t),Et.init(e,t)}),aH=ie("ZodNanoID",(e,t)=>{LZ.init(e,t),Et.init(e,t)}),iH=ie("ZodCUID",(e,t)=>{PZ.init(e,t),Et.init(e,t)}),sH=ie("ZodCUID2",(e,t)=>{UZ.init(e,t),Et.init(e,t)}),oH=ie("ZodULID",(e,t)=>{VZ.init(e,t),Et.init(e,t)}),lH=ie("ZodXID",(e,t)=>{BZ.init(e,t),Et.init(e,t)}),uH=ie("ZodKSUID",(e,t)=>{ZZ.init(e,t),Et.init(e,t)}),cH=ie("ZodIPv4",(e,t)=>{GZ.init(e,t),Et.init(e,t)}),dH=ie("ZodIPv6",(e,t)=>{YZ.init(e,t),Et.init(e,t)}),fH=ie("ZodCIDRv4",(e,t)=>{KZ.init(e,t),Et.init(e,t)}),hH=ie("ZodCIDRv6",(e,t)=>{XZ.init(e,t),Et.init(e,t)}),mH=ie("ZodBase64",(e,t)=>{JZ.init(e,t),Et.init(e,t)}),pH=ie("ZodBase64URL",(e,t)=>{WZ.init(e,t),Et.init(e,t)}),gH=ie("ZodE164",(e,t)=>{eI.init(e,t),Et.init(e,t)}),xH=ie("ZodJWT",(e,t)=>{nI.init(e,t),Et.init(e,t)}),yH=ie("ZodUnknown",(e,t)=>{rI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>x7()});function Cw(){return XI(yH)}const bH=ie("ZodNever",(e,t)=>{aI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>g7(e,n,a)});function vH(e){return JI(bH,e)}const kH=ie("ZodArray",(e,t)=>{iI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>w7(e,n,a,s),e.element=t.element,e.min=(n,a)=>e.check(ed(n,a)),e.nonempty=n=>e.check(ed(1,n)),e.max=(n,a)=>e.check(n2(n,a)),e.length=(n,a)=>e.check(r2(n,a)),e.unwrap=()=>e.element});function wH(e,t){return u7(kH,e,t)}const SH=ie("ZodObject",(e,t)=>{oI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>S7(e,n,a,s),rt(e,"shape",()=>t.shape),e.keyof=()=>CH(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Cw()}),e.loose=()=>e.clone({...e._zod.def,catchall:Cw()}),e.strict=()=>e.clone({...e._zod.def,catchall:vH()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>MB(e,n),e.safeExtend=n=>DB(e,n),e.merge=n=>$B(e,n),e.pick=n=>OB(e,n),e.omit=n=>RB(e,n),e.partial=(...n)=>LB(d2,e,n[0]),e.required=(...n)=>PB(f2,e,n[0])});function zH(e,t){const n={type:"object",shape:e??{},...Te(t)};return new SH(n)}const _H=ie("ZodUnion",(e,t)=>{lI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>z7(e,n,a,s),e.options=t.options});function c2(e,t){return new _H({type:"union",options:e,...Te(t)})}const jH=ie("ZodIntersection",(e,t)=>{uI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>_7(e,n,a,s)});function NH(e,t){return new jH({type:"intersection",left:e,right:t})}const Zp=ie("ZodEnum",(e,t)=>{cI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(a,s,u)=>y7(e,a,s),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(a,s)=>{const u={};for(const l of a)if(n.has(l))u[l]=t.entries[l];else throw new Error(`Key ${l} not found in enum`);return new Zp({...t,checks:[],...Te(s),entries:u})},e.exclude=(a,s)=>{const u={...t.entries};for(const l of a)if(n.has(l))delete u[l];else throw new Error(`Key ${l} not found in enum`);return new Zp({...t,checks:[],...Te(s),entries:u})}});function CH(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(a=>[a,a])):e;return new Zp({type:"enum",entries:n,...Te(t)})}const EH=ie("ZodLiteral",(e,t)=>{dI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>b7(e,n,a),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Ew(e,t){return new EH({type:"literal",values:Array.isArray(e)?e:[e],...Te(t)})}const TH=ie("ZodTransform",(e,t)=>{fI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>k7(e,n),e._zod.parse=(n,a)=>{if(a.direction==="backward")throw new Vj(e.constructor.name);n.addIssue=u=>{if(typeof u=="string")n.issues.push(Dl(u,n.value,t));else{const l=u;l.fatal&&(l.continue=!1),l.code??(l.code="custom"),l.input??(l.input=n.value),l.inst??(l.inst=e),n.issues.push(Dl(l))}};const s=t.transform(n.value,n);return s instanceof Promise?s.then(u=>(n.value=u,n)):(n.value=s,n)}});function AH(e){return new TH({type:"transform",transform:e})}const d2=ie("ZodOptional",(e,t)=>{t2.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>o2(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function Tw(e){return new d2({type:"optional",innerType:e})}const OH=ie("ZodExactOptional",(e,t)=>{hI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>o2(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function RH(e){return new OH({type:"optional",innerType:e})}const MH=ie("ZodNullable",(e,t)=>{mI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>j7(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function Aw(e){return new MH({type:"nullable",innerType:e})}const DH=ie("ZodDefault",(e,t)=>{pI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>C7(e,n,a,s),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function $H(e,t){return new DH({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Hj(t)}})}const LH=ie("ZodPrefault",(e,t)=>{gI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>E7(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function PH(e,t){return new LH({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Hj(t)}})}const f2=ie("ZodNonOptional",(e,t)=>{xI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>N7(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function UH(e,t){return new f2({type:"nonoptional",innerType:e,...Te(t)})}const VH=ie("ZodCatch",(e,t)=>{yI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>T7(e,n,a,s),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function BH(e,t){return new VH({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const ZH=ie("ZodPipe",(e,t)=>{bI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>A7(e,n,a,s),e.in=t.in,e.out=t.out});function Ow(e,t){return new ZH({type:"pipe",in:e,out:t})}const IH=ie("ZodReadonly",(e,t)=>{vI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>O7(e,n,a,s),e.unwrap=()=>e._zod.def.innerType});function HH(e){return new IH({type:"readonly",innerType:e})}const FH=ie("ZodCustom",(e,t)=>{kI.init(e,t),qt.init(e,t),e._zod.processJSONSchema=(n,a,s)=>v7(e,n)});function qH(e,t={}){return c7(FH,e,t)}function GH(e){return d7(e)}const YH=[{id:"general",label:"General"},{id:"agents",label:"Agents"},{id:"audio",label:"Audio"},{id:"channels",label:"Channels"},{id:"ui",label:"Interface"},{id:"logging",label:"Logging"},{id:"chronos",label:"Chronos"}],KH=[{id:"oracle",label:"Oracle"},{id:"sati",label:"Sati"},{id:"neo",label:"Neo"},{id:"apoc",label:"Apoc"},{id:"trinity",label:"Trinity"}],cl=[{label:"OpenAI",value:"openai"},{label:"Anthropic",value:"anthropic"},{label:"OpenRouter",value:"openrouter"},{label:"Ollama",value:"ollama"},{label:"Google Gemini",value:"gemini"}];function XH(){const{data:e,error:t}=zt("/api/config",ir.fetchConfig),{data:n}=zt("/api/config/sati",ir.getSatiConfig),{data:a}=zt("/api/config/apoc",ir.getApocConfig),{data:s}=zt("/api/config/neo",ir.getNeoConfig),{data:u}=zt("/api/config/trinity",ir.getTrinityConfig),{data:l}=zt("/api/config/encryption-status",()=>ir.getEncryptionStatus()),{data:f}=zt("/api/config/env-overrides",()=>ir.getEnvOverrides()),{data:h}=Y_(),[m,g]=z.useState(null),[y,v]=z.useState(!1),[b,S]=z.useState(null),[j,A]=z.useState(null),[E,O]=z.useState(null),[N,L]=z.useState(null),[D,R]=z.useState(null),[q,V]=z.useState("general"),[X,fe]=z.useState("oracle"),[se,le]=z.useState(!1),[ee,oe]=z.useState({}),[ae,P]=z.useState(null);z.useEffect(()=>{e&&!b&&S(e)},[e]),z.useEffect(()=>{n&&!j&&A(n)},[n]),z.useEffect(()=>{a&&!N?L(a):!a&&!N&&b&&L({...b.apoc??b.llm,temperature:b.apoc?.temperature??.2,timeout_ms:b.apoc?.timeout_ms??3e4})},[a,b]),z.useEffect(()=>{s&&!E?O(s):!s&&!E&&b&&O({...b.neo??b.llm,temperature:b.neo?.temperature??.2})},[s,b]),z.useEffect(()=>{u&&!D?R(u):!u&&!D&&b&&R({...b.trinity??b.llm,temperature:b.trinity?.temperature??.2})},[u,b]),z.useEffect(()=>{h&&!m&&g(h)},[h]);const J=JSON.stringify(e)!==JSON.stringify(b)||JSON.stringify(n)!==JSON.stringify(j)||JSON.stringify(s)!==JSON.stringify(E)||JSON.stringify(a)!==JSON.stringify(N)||JSON.stringify(u)!==JSON.stringify(D),B=(Z,Ne)=>{if(!l?.apiKeysEncrypted)return null;const{morpheusSecretSet:qe,apiKeysEncrypted:Lt}=l,Me=Lt[Z];return!Ne?d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-azure-surface border border-azure-border text-azure-text-secondary dark:bg-matrix-primary/10 dark:border-matrix-primary dark:text-matrix-tertiary",children:"No API key"}):f&&f[me(Z)]?null:qe?Me?d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-emerald-100 border border-emerald-300 text-emerald-800 dark:bg-emerald-900/30 dark:border-emerald-700 dark:text-emerald-400",title:"API key encrypted with AES-256-GCM",children:"🔒 Encrypted"}):d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-amber-100 border border-amber-300 text-amber-800 dark:bg-amber-900/30 dark:border-amber-700 dark:text-amber-400",title:"Re-save this configuration to encrypt the API key",children:"⚠️ Re-save to encrypt"}):d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-amber-100 border border-amber-300 text-amber-800 dark:bg-amber-900/30 dark:border-amber-700 dark:text-amber-400",title:"Set MORPHEUS_SECRET to enable encryption",children:"⚠️ Plaintext"})},me=Z=>({oracle:"llm.api_key",sati:"sati.api_key",neo:"neo.api_key",apoc:"apoc.api_key",trinity:"trinity.api_key",audio:"audio.apiKey"})[Z],T=Z=>!f||!f[Z]?null:d.jsx("span",{className:"inline-flex items-center px-2 py-1 text-xs rounded bg-blue-100 border border-blue-300 text-blue-800 dark:bg-blue-900/30 dark:border-blue-700 dark:text-blue-400",title:"This field is set by an environment variable and cannot be edited",children:"🔒 Env Var"}),C=Z=>!!(f&&f[Z]),I=(Z,Ne)=>{if(!b)return;const qe=JSON.parse(JSON.stringify(b));let Lt=qe;for(let Me=0;Me<Z.length-1;Me++)Lt=Lt[Z[Me]];Lt[Z[Z.length-1]]=Ne,S(qe);try{jB.parse(qe),oe({})}catch(Me){if(Me instanceof B7){const Ke={};Me.errors.forEach(at=>{const Qe=at.path.join(".");Ke[Qe]=at.message}),oe(Ke)}}},w=(Z,Ne)=>{j&&A({...j,[Z]:Ne})},Y=(Z,Ne)=>{N&&L({...N,[Z]:Ne})},de=(Z,Ne)=>{E&&O({...E,[Z]:Ne})},he=(Z,Ne)=>{D&&R({...D,[Z]:Ne})},pe=()=>{!b||!D||R({...D,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},Pe=()=>{!b||!j||A({...j,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},Ae=()=>{!b||!N||L({...N,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},pt=()=>{!b||!E||O({...E,provider:b.llm.provider,model:b.llm.model,api_key:b.llm.api_key})},Rt=async()=>{if(b){le(!0),P(null);try{await ir.updateConfig(b),j&&await ir.updateSatiConfig(j),E&&await ir.updateNeoConfig(E),N&&await ir.updateApocConfig(N),D&&await ir.updateTrinityConfig(D),On("/api/config"),On("/api/config/sati"),On("/api/config/neo"),On("/api/config/apoc"),On("/api/config/trinity"),P({type:"success",message:"Settings saved successfully. Restart Morpheus daemon for changes to take effect."})}catch(Z){if(P({type:"error",message:Z.message}),Z.details&&Array.isArray(Z.details)){const Ne={};Z.details.forEach(qe=>{const Lt=qe.path.join(".");Ne[Lt]=qe.message}),oe(Ne)}}finally{le(!1)}}};return t?d.jsx("div",{className:"p-8 text-red-500",children:"Failed to load configuration"}):b?d.jsxs("div",{className:"max-w-4xl mx-auto p-0 md:p-6 space-y-6",children:[d.jsxs("div",{className:"flex justify-between items-center",children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"Zaion Settings"}),d.jsx("button",{onClick:Rt,disabled:!J||Object.keys(ee).length>0||se,className:`px-4 py-2 rounded font-medium transition-colors ${J&&Object.keys(ee).length===0?"bg-azure-primary text-white hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90":"bg-azure-border text-azure-text-secondary cursor-not-allowed dark:bg-matrix-primary/50 dark:text-matrix-highlight/50"}`,children:se?"Saving...":"Save Changes"})]}),ae&&d.jsx("div",{className:`p-4 rounded border ${ae.type==="success"?"border-azure-primary text-azure-primary bg-azure-primary/10 dark:border-matrix-highlight dark:text-matrix-highlight dark:bg-matrix-highlight/10":"border-red-500 text-red-500 bg-red-900/10"}`,children:ae.message}),d.jsx("div",{className:"overflow-x-auto py-1 hide-scrollbar",children:d.jsx("div",{className:"flex space-x-1 border-b border-azure-border dark:border-matrix-primary pb-px min-w-max",children:YH.map(Z=>d.jsx("button",{onClick:()=>V(Z.id),className:`px-4 py-2 text-sm font-medium rounded-t-md transition-colors flex-shrink-0 ${q===Z.id?"bg-azure-surface/50 text-azure-primary border-t border-x border-azure-border dark:bg-matrix-primary/20 dark:text-matrix-highlight dark:border-t dark:border-x dark:border-matrix-primary":"text-azure-text-secondary hover:text-azure-primary dark:text-matrix-secondary dark:hover:text-matrix-highlight"}`,children:Z.label},Z.id))})}),d.jsxs("div",{className:"space-y-6",children:[q==="general"&&d.jsxs(ar,{title:"Agent Identity",children:[d.jsx(lt,{label:"Agent Name",value:b.agent.name,onChange:Z=>I(["agent","name"],Z.target.value),error:ee["agent.name"]}),d.jsx(lt,{label:"Personality",value:b.agent.personality,onChange:Z=>I(["agent","personality"],Z.target.value),error:ee["agent.personality"]})]}),q==="agents"&&d.jsxs("div",{className:"space-y-4",children:[d.jsx("div",{className:"flex space-x-1 border-b border-azure-border dark:border-matrix-primary pb-px",children:KH.map(Z=>d.jsx("button",{onClick:()=>fe(Z.id),className:`px-4 py-2 text-sm font-medium rounded-t-md transition-colors ${X===Z.id?"bg-azure-primary/10 text-azure-primary border-b-2 border-azure-primary dark:bg-matrix-highlight/10 dark:text-matrix-highlight dark:border-matrix-highlight":"text-azure-text-secondary hover:text-azure-primary dark:text-matrix-secondary dark:hover:text-matrix-highlight"}`,children:Z.label},Z.id))}),X==="oracle"&&d.jsxs(ar,{title:"Oracle Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"Main orchestration agent — handles user requests and delegates to subagents"}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("llm.provider")]}),d.jsx(jr,{label:"",value:b.llm.provider,onChange:Z=>I(["llm","provider"],Z.target.value),options:cl,error:ee["llm.provider"],disabled:C("llm.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("llm.model")]}),d.jsx(lt,{label:"",value:b.llm.model,onChange:Z=>I(["llm","model"],Z.target.value),disabled:C("llm.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("llm.temperature")]}),d.jsx(yn,{label:"",value:b.llm.temperature,onChange:Z=>I(["llm","temperature"],parseFloat(Z.target.value)),step:.1,min:0,max:1,error:ee["llm.temperature"],disabled:C("llm.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Tokens"}),T("llm.max_tokens")]}),d.jsx(yn,{label:"",value:b.llm.max_tokens??"",onChange:Z=>I(["llm","max_tokens"],Z.target.value?parseInt(Z.target.value):void 0),min:1,error:ee["llm.max_tokens"],helperText:"Maximum tokens per response. Leave empty for model default.",disabled:C("llm.max_tokens")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Context Window (Messages)"}),T("llm.context_window")]}),d.jsx(yn,{label:"",value:b.llm.context_window??100,onChange:Z=>I(["llm","context_window"],parseInt(Z.target.value)),min:1,step:1,error:ee["llm.context_window"],helperText:"Number of past interactions to load into LLM context (e.g., 100).",disabled:C("llm.context_window")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("llm.api_key"),B("oracle",b.llm.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:b.llm.api_key||"",onChange:Z=>I(["llm","api_key"],Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("llm.api_key")}),b.llm.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:b.llm.base_url||"https://openrouter.ai/api/v1",onChange:Z=>I(["llm","base_url"],Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"})]}),X==="sati"&&d.jsxs(ar,{title:"Sati Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"Background memory consolidation agent — evaluates conversations and persists important context"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:Pe,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),j&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("sati.provider")]}),d.jsx(jr,{label:"",value:j.provider,onChange:Z=>w("provider",Z.target.value),options:cl,disabled:C("sati.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("sati.model")]}),d.jsx(lt,{label:"",value:j.model,onChange:Z=>w("model",Z.target.value),disabled:C("sati.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("sati.api_key"),B("sati",j.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:j.api_key||"",onChange:Z=>w("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("sati.api_key")}),j.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:j.base_url||"https://openrouter.ai/api/v1",onChange:Z=>w("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"}),d.jsx(yn,{label:"Memory Limit",value:j.memory_limit??10,onChange:Z=>w("memory_limit",parseInt(Z.target.value)),min:1,step:1,helperText:"Number of memory items to retrieve from long-term storage."}),d.jsx(zs,{label:"Enable Archived Sessions in Memory Retrieval",checked:j.enabled_archived_sessions??!0,onChange:Z=>w("enabled_archived_sessions",Z)})]})]}),X==="neo"&&d.jsxs(ar,{title:"Neo Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"MCP + internal tools subagent — executes analytical and operational tasks delegated by Oracle"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:pt,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),E&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("neo.provider")]}),d.jsx(jr,{label:"",value:E.provider,onChange:Z=>de("provider",Z.target.value),options:cl,disabled:C("neo.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("neo.model")]}),d.jsx(lt,{label:"",value:E.model,onChange:Z=>de("model",Z.target.value),disabled:C("neo.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("neo.temperature")]}),d.jsx(yn,{label:"",value:E.temperature,onChange:Z=>de("temperature",parseFloat(Z.target.value)),step:.1,min:0,max:1,disabled:C("neo.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Tokens"}),T("neo.max_tokens")]}),d.jsx(yn,{label:"",value:E.max_tokens??"",onChange:Z=>de("max_tokens",Z.target.value?parseInt(Z.target.value):void 0),min:1,helperText:"Maximum tokens per response. Leave empty for model default.",disabled:C("neo.max_tokens")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Context Window (Messages)"}),T("neo.context_window")]}),d.jsx(yn,{label:"",value:E.context_window??100,onChange:Z=>de("context_window",parseInt(Z.target.value)),min:1,step:1,disabled:C("neo.context_window")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("neo.api_key"),B("neo",E.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:E.api_key||"",onChange:Z=>de("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("neo.api_key")}),E.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:E.base_url||"https://openrouter.ai/api/v1",onChange:Z=>de("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"})]})]}),X==="trinity"&&d.jsxs(ar,{title:"Trinity Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"Database subagent — interprets natural language queries and executes them against registered databases (PostgreSQL, MySQL, SQLite, MongoDB)"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:pe,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),D&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("trinity.provider")]}),d.jsx(jr,{label:"",value:D.provider,onChange:Z=>he("provider",Z.target.value),options:cl,disabled:C("trinity.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("trinity.model")]}),d.jsx(lt,{label:"",value:D.model,onChange:Z=>he("model",Z.target.value),disabled:C("trinity.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("trinity.temperature")]}),d.jsx(yn,{label:"",value:D.temperature,onChange:Z=>he("temperature",parseFloat(Z.target.value)),step:.1,min:0,max:1,disabled:C("trinity.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Tokens"}),T("trinity.max_tokens")]}),d.jsx(yn,{label:"",value:D.max_tokens??"",onChange:Z=>he("max_tokens",Z.target.value?parseInt(Z.target.value):void 0),min:1,helperText:"Maximum tokens per response. Leave empty for model default.",disabled:C("trinity.max_tokens")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("trinity.api_key"),B("trinity",D.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:D.api_key||"",onChange:Z=>he("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("trinity.api_key")}),D.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:D.base_url||"https://openrouter.ai/api/v1",onChange:Z=>he("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"})]})]}),X==="apoc"&&d.jsxs(ar,{title:"Apoc Agent",children:[d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mb-4",children:"DevTools subagent — executes file, shell, git, network, and system operations on behalf of Oracle"}),d.jsxs("div",{className:"mb-4",children:[d.jsx("button",{type:"button",onClick:Ae,className:"px-3 py-1.5 text-sm bg-azure-surface border border-azure-border rounded hover:bg-azure-primary/10 dark:bg-matrix-primary/20 dark:border-matrix-primary dark:hover:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight transition-colors",children:"Copy from Oracle Agent"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Copy Provider, Model, and API Key from Oracle Agent configuration"})]}),N&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("apoc.provider")]}),d.jsx(jr,{label:"",value:N.provider,onChange:Z=>Y("provider",Z.target.value),options:cl,disabled:C("apoc.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model Name"}),T("apoc.model")]}),d.jsx(lt,{label:"",value:N.model,onChange:Z=>Y("model",Z.target.value),disabled:C("apoc.model")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Temperature"}),T("apoc.temperature")]}),d.jsx(yn,{label:"",value:N.temperature,onChange:Z=>Y("temperature",parseFloat(Z.target.value)),step:.1,min:0,max:1,disabled:C("apoc.temperature")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("apoc.api_key"),B("apoc",N.api_key)]})]}),d.jsx(lt,{label:"",type:"password",value:N.api_key||"",onChange:Z=>Y("api_key",Z.target.value),placeholder:"sk-...",helperText:"Stored locally.",disabled:C("apoc.api_key")}),N.provider==="openrouter"&&d.jsx(lt,{label:"Base URL",value:N.base_url||"https://openrouter.ai/api/v1",onChange:Z=>Y("base_url",Z.target.value),placeholder:"https://openrouter.ai/api/v1",helperText:"Base URL for OpenRouter API"}),d.jsx(lt,{label:"Working Directory",value:N.working_dir||"",onChange:Z=>Y("working_dir",Z.target.value),placeholder:"/home/user/projects",helperText:"Root directory for file and shell operations. Leave empty to use process working directory."}),d.jsx(yn,{label:"Timeout (ms)",value:N.timeout_ms??3e4,onChange:Z=>Y("timeout_ms",parseInt(Z.target.value)),min:1e3,step:1e3,helperText:"Maximum execution time for shell and system operations in milliseconds."})]})]})]}),q==="audio"&&d.jsxs(ar,{title:"Audio Transcription",children:[d.jsx(zs,{label:"Enable Audio",checked:b.audio.enabled,onChange:Z=>I(["audio","enabled"],Z)}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Provider"}),T("audio.provider")]}),d.jsx(jr,{label:"",value:b.audio.provider||"google",onChange:Z=>I(["audio","provider"],Z.target.value),options:[{label:"Google Gemini",value:"google"},{label:"OpenAI (Whisper)",value:"openai"},{label:"OpenRouter (multimodal)",value:"openrouter"},{label:"Ollama (Whisper local)",value:"ollama"}],error:ee["audio.provider"],disabled:C("audio.provider")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Model"}),T("audio.model")]}),d.jsx(lt,{label:"",value:b.audio.model,onChange:Z=>I(["audio","model"],Z.target.value),placeholder:"e.g. whisper-1, gemini-2.5-flash-lite...",helperText:"Model to use for audio transcription.",error:ee["audio.model"],disabled:C("audio.model")}),b.audio.provider==="ollama"&&d.jsx(lt,{label:"Base URL",value:b.audio.base_url||"",onChange:Z=>I(["audio","base_url"],Z.target.value),placeholder:"http://localhost:11434",helperText:"Ollama base URL. Requires a Whisper model loaded (ollama pull whisper)."}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"API Key"}),d.jsxs("div",{className:"flex items-center gap-2",children:[T("audio.apiKey"),B("audio",b.audio.apiKey)]})]}),d.jsx(lt,{label:"",type:"password",value:b.audio.apiKey||"",onChange:Z=>I(["audio","apiKey"],Z.target.value),placeholder:"If different from LLM key...",helperText:"Leave empty to use LLM API key if using the same provider.",disabled:C("audio.apiKey")}),d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-primary dark:text-matrix-secondary",children:"Max Duration (Seconds)"}),T("audio.maxDurationSeconds")]}),d.jsx(yn,{label:"",value:b.audio.maxDurationSeconds,onChange:Z=>I(["audio","maxDurationSeconds"],parseInt(Z.target.value)),min:1,disabled:C("audio.maxDurationSeconds")}),d.jsx(lt,{label:"Supported Mime Types",value:b.audio.supportedMimeTypes.join(", "),onChange:Z=>I(["audio","supportedMimeTypes"],Z.target.value.split(",").map(Ne=>Ne.trim()).filter(Boolean)),helperText:"Comma separated list (e.g. audio/ogg, audio/mp3)"})]}),q==="channels"&&d.jsxs(d.Fragment,{children:[d.jsxs(ar,{title:"Telegram",children:[d.jsx(zs,{label:"Enable Telegram",checked:b.channels.telegram.enabled,onChange:Z=>I(["channels","telegram","enabled"],Z)}),b.channels.telegram.enabled&&d.jsxs("div",{className:"space-y-4 mt-4 pl-4 border-l border-matrix-primary",children:[d.jsx(lt,{label:"Bot Token",type:"password",value:b.channels.telegram.token||"",onChange:Z=>I(["channels","telegram","token"],Z.target.value)}),d.jsx(lt,{label:"Allowed Users (comma separated)",value:b.channels.telegram.allowedUsers.join(", "),onChange:Z=>I(["channels","telegram","allowedUsers"],Z.target.value.split(",").map(Ne=>Ne.trim()).filter(Boolean)),helperText:"User IDs allowed to interact with the bot"})]})]}),d.jsxs(ar,{title:"Discord",children:[d.jsx(zs,{label:"Enable Discord",checked:b.channels.discord.enabled,onChange:Z=>I(["channels","discord","enabled"],Z)}),b.channels.discord.enabled&&d.jsxs("div",{className:"space-y-4 mt-4 pl-4 border-l border-matrix-primary",children:[d.jsx(lt,{label:"Bot Token",type:"password",value:b.channels.discord.token||"",onChange:Z=>I(["channels","discord","token"],Z.target.value)}),d.jsx(lt,{label:"Allowed Users (comma separated)",value:(b.channels.discord.allowedUsers??[]).join(", "),onChange:Z=>I(["channels","discord","allowedUsers"],Z.target.value.split(",").map(Ne=>Ne.trim()).filter(Boolean)),helperText:"Discord user IDs allowed to interact with the bot"})]})]})]}),q==="ui"&&d.jsxs(ar,{title:"Dashboard",children:[d.jsx(zs,{label:"Enable Web UI",checked:b.ui.enabled,onChange:Z=>I(["ui","enabled"],Z)}),d.jsx(yn,{label:"Port",value:b.ui.port,onChange:Z=>I(["ui","port"],parseInt(Z.target.value)),disabled:!0,helperText:"Requires restart to change."})]}),q==="logging"&&d.jsxs(ar,{title:"Logging",children:[d.jsx(zs,{label:"Enable Logging",checked:b.logging.enabled,onChange:Z=>I(["logging","enabled"],Z)}),d.jsx(jr,{label:"Log Level",value:b.logging.level,onChange:Z=>I(["logging","level"],Z.target.value),options:[{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warning",value:"warn"},{label:"Error",value:"error"}]})]}),q==="chronos"&&m&&d.jsxs(ar,{title:"Chronos — Temporal Intent Engine",children:[d.jsx(jr,{label:"Timezone",value:m.timezone,onChange:Z=>g({...m,timezone:Z.target.value}),options:[{label:"UTC",value:"UTC"},{label:"America/New_York",value:"America/New_York"},{label:"America/Chicago",value:"America/Chicago"},{label:"America/Denver",value:"America/Denver"},{label:"America/Los_Angeles",value:"America/Los_Angeles"},{label:"America/Sao_Paulo",value:"America/Sao_Paulo"},{label:"America/Buenos_Aires",value:"America/Buenos_Aires"},{label:"America/Bogota",value:"America/Bogota"},{label:"America/Lima",value:"America/Lima"},{label:"America/Santiago",value:"America/Santiago"},{label:"America/Mexico_City",value:"America/Mexico_City"},{label:"America/Toronto",value:"America/Toronto"},{label:"America/Vancouver",value:"America/Vancouver"},{label:"Europe/London",value:"Europe/London"},{label:"Europe/Paris",value:"Europe/Paris"},{label:"Europe/Berlin",value:"Europe/Berlin"},{label:"Europe/Madrid",value:"Europe/Madrid"},{label:"Europe/Rome",value:"Europe/Rome"},{label:"Europe/Amsterdam",value:"Europe/Amsterdam"},{label:"Europe/Brussels",value:"Europe/Brussels"},{label:"Europe/Zurich",value:"Europe/Zurich"},{label:"Europe/Lisbon",value:"Europe/Lisbon"},{label:"Europe/Warsaw",value:"Europe/Warsaw"},{label:"Europe/Stockholm",value:"Europe/Stockholm"},{label:"Europe/Helsinki",value:"Europe/Helsinki"},{label:"Europe/Moscow",value:"Europe/Moscow"},{label:"Asia/Dubai",value:"Asia/Dubai"},{label:"Asia/Kolkata",value:"Asia/Kolkata"},{label:"Asia/Bangkok",value:"Asia/Bangkok"},{label:"Asia/Singapore",value:"Asia/Singapore"},{label:"Asia/Hong_Kong",value:"Asia/Hong_Kong"},{label:"Asia/Shanghai",value:"Asia/Shanghai"},{label:"Asia/Tokyo",value:"Asia/Tokyo"},{label:"Asia/Seoul",value:"Asia/Seoul"},{label:"Australia/Sydney",value:"Australia/Sydney"},{label:"Australia/Melbourne",value:"Australia/Melbourne"},{label:"Pacific/Auckland",value:"Pacific/Auckland"},{label:"Africa/Cairo",value:"Africa/Cairo"},{label:"Africa/Johannesburg",value:"Africa/Johannesburg"}]}),d.jsx(yn,{label:"Check Interval (seconds)",value:Math.round(m.check_interval_ms/1e3),onChange:Z=>g({...m,check_interval_ms:Number(Z.target.value)*1e3}),min:60}),d.jsx(yn,{label:"Max Active Jobs",value:m.max_active_jobs,onChange:Z=>g({...m,max_active_jobs:Number(Z.target.value)}),min:1,max:1e3}),d.jsx("div",{className:"flex justify-end pt-2",children:d.jsx("button",{onClick:async()=>{v(!0),P(null);try{await Ei.updateConfig(m),On("/api/config/chronos"),P({type:"success",message:"Chronos settings saved."})}catch(Z){P({type:"error",message:Z.message})}finally{v(!1)}},disabled:y,className:"px-4 py-2 rounded font-medium bg-azure-primary text-white hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:y?"Saving…":"Save Chronos Settings"})})]})]})]}):d.jsx("div",{className:"p-8 text-azure-primary dark:text-matrix-highlight",children:"Loading settings..."})}function JH(){const{data:e}=O4(),[t,n]=z.useState(null),{data:a,mutate:s}=R4(t),u=z.useRef(null);return z.useEffect(()=>{!t&&e&&e.length>0&&n(e[0].name)},[e,t]),z.useEffect(()=>{u.current&&(u.current.scrollTop=u.current.scrollHeight)},[a]),d.jsxs(dt.div,{className:"flex flex-col space-y-4 md:pt-0",style:{height:"calc(100vh - 2rem)"},initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},transition:{duration:.3},children:[d.jsxs("div",{className:"shrink-0",children:[d.jsx("h2",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"SYSTEM LOGS"}),d.jsx("p",{className:"text-azure-text-secondary dark:text-matrix-secondary opacity-80",children:"View runtime logs."})]}),d.jsxs("div",{className:"flex-1 flex gap-4 min-h-0 border border-azure-border dark:border-matrix-primary rounded bg-azure-surface dark:bg-zinc-950 p-4",children:[d.jsxs("div",{className:"hidden md:flex w-64 flex-col gap-2 border-r border-azure-border dark:border-matrix-primary pr-4 overflow-y-auto shrink-0",children:[d.jsx("h3",{className:"font-bold text-azure-text-secondary dark:text-matrix-secondary mb-2 sticky top-0 bg-azure-surface dark:bg-zinc-950",children:"LOG FILES"}),e?.map(l=>d.jsxs("button",{onClick:()=>n(l.name),className:`text-left px-3 py-2 rounded text-sm truncate flex items-center gap-2 group transition-colors ${t===l.name?"bg-azure-active text-azure-primary dark:bg-matrix-primary dark:text-matrix-highlight":"text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-hover dark:hover:bg-zinc-900 group-hover:text-azure-primary dark:group-hover:text-matrix-highlight"}`,children:[d.jsx(tA,{className:"w-4 h-4 shrink-0"}),d.jsxs("div",{className:"flex flex-col overflow-hidden",children:[d.jsx("span",{className:"truncate font-bold",children:l.name}),d.jsxs("span",{className:"text-xs opacity-70",children:[(l.size/1024).toFixed(1)," KB"]})]})]},l.name))]}),d.jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-azure-bg dark:bg-black border border-azure-border dark:border-matrix-primary/50 rounded",children:[d.jsxs("div",{className:"shrink-0 flex justify-between items-center gap-2 p-2 bg-azure-hover dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary/50",children:[d.jsx("select",{value:t??"",onChange:l=>n(l.target.value),className:"md:hidden flex-1 bg-transparent text-azure-text-primary dark:text-matrix-highlight font-bold font-mono text-sm border-none outline-none cursor-pointer",children:e?.map(l=>d.jsx("option",{value:l.name,children:l.name},l.name))}),d.jsx("span",{className:"hidden md:block text-azure-text-primary dark:text-matrix-highlight font-bold font-mono text-sm truncate",children:t}),d.jsx("button",{onClick:()=>s(),className:"shrink-0 text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(xS,{className:"w-4 h-4"})})]}),d.jsx("div",{ref:u,className:"flex-1 overflow-x-hidden overflow-y-auto p-4 font-mono text-xs break-all text-azure-text-primary dark:text-white",children:a?a.lines.map((l,f)=>{const h=l.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z)\s?(.*)/s);return h?d.jsxs("div",{children:[d.jsxs("span",{className:"hidden md:inline opacity-50",children:[h[1]," "]}),d.jsx("span",{children:h[2]})]},f):d.jsx("div",{children:l},f)}):d.jsx("span",{className:"opacity-50",children:"Select a log file to view content..."})})]})]})]})}function QH(){const[e,t]=z.useState(null),[n,a]=z.useState([]),[s,u]=z.useState(!0),[l,f]=z.useState("");if(z.useEffect(()=>{async function g(){try{const[y,v]=await Promise.all([_p.fetchUsageStats(),_p.fetchGroupedUsageStats()]);t(y),a(v)}catch(y){f("Failed to load usage statistics"),console.error(y)}finally{u(!1)}}g()},[]),s)return d.jsx("div",{className:"flex items-center justify-center h-64 text-azure-accent dark:text-matrix-highlight font-mono animate-pulse",children:"LOADING_DATA_STREAM..."});if(l)return d.jsxs("div",{className:"p-4 bg-red-900/20 border border-red-500/50 text-red-500 font-mono rounded",children:["ERROR_ACCESSING_DATABASE: ",l]});const h={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.1}}},m={hidden:{y:20,opacity:0},show:{y:0,opacity:1}};return d.jsxs(dt.div,{variants:h,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsx("div",{className:"flex items-center justify-between border-b border-azure-border dark:border-matrix-primary pb-4",children:d.jsxs("div",{children:[d.jsxs("h2",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight font-mono flex items-center gap-2",children:[d.jsx(Zm,{className:"w-6 h-6"}),"USAGE_ANALYTICS"]}),d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary mt-1 font-mono text-sm",children:"Resource consumption tracking and metrics"})]})}),d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[d.jsxs(dt.div,{variants:m,className:"p-6 bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg shadow-sm backdrop-blur-sm",children:[d.jsxs("div",{className:"flex items-center gap-3 mb-2 text-azure-text-muted dark:text-matrix-secondary",children:[d.jsx(zl,{className:"w-5 h-5"}),d.jsx("h3",{className:"font-mono text-sm font-bold uppercase",children:"Total Input Tokens"})]}),d.jsx("p",{className:"text-3xl font-bold text-azure-primary dark:text-matrix-highlight font-mono",children:e?.totalInputTokens.toLocaleString()??0})]}),d.jsxs(dt.div,{variants:m,className:"p-6 bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg shadow-sm backdrop-blur-sm",children:[d.jsxs("div",{className:"flex items-center gap-3 mb-2 text-azure-text-muted dark:text-matrix-secondary",children:[d.jsx($s,{className:"w-5 h-5"}),d.jsx("h3",{className:"font-mono text-sm font-bold uppercase",children:"Total Output Tokens"})]}),d.jsx("p",{className:"text-3xl font-bold text-azure-primary dark:text-matrix-highlight font-mono",children:e?.totalOutputTokens.toLocaleString()??0})]}),d.jsxs(dt.div,{variants:m,className:"p-6 bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg shadow-sm backdrop-blur-sm",children:[d.jsxs("div",{className:"flex items-center gap-3 mb-2 text-azure-text-muted dark:text-matrix-secondary",children:[d.jsx(Pc,{className:"w-5 h-5"}),d.jsx("h3",{className:"font-mono text-sm font-bold uppercase",children:"Est. Total Cost"})]}),d.jsx("p",{className:"text-3xl font-bold text-green-600 dark:text-green-400 font-mono",children:e?.totalEstimatedCostUsd!=null?`$${e.totalEstimatedCostUsd.toFixed(4)}`:"—"})]})]}),d.jsxs(dt.div,{variants:m,className:"bg-azure-surface dark:bg-black/40 border border-azure-border dark:border-matrix-primary rounded-lg overflow-hidden backdrop-blur-sm",children:[d.jsx("div",{className:"p-4 border-b border-azure-border dark:border-matrix-primary bg-azure-bg dark:bg-zinc-900/50",children:d.jsx("h3",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight font-mono uppercase",children:"Usage Breakdown by Model"})}),d.jsx("div",{className:"overflow-x-auto",children:d.jsxs("table",{className:"w-full text-left font-mono text-sm",children:[d.jsx("thead",{className:"bg-azure-bg dark:bg-zinc-900/50 text-azure-text-secondary dark:text-matrix-secondary border-b border-azure-border dark:border-matrix-primary",children:d.jsxs("tr",{children:[d.jsx("th",{className:"p-4",children:"Provider"}),d.jsx("th",{className:"p-4",children:"Model"}),d.jsx("th",{className:"p-4 text-right",children:"Messages"}),d.jsx("th",{className:"p-4 text-right",children:"Input Tokens"}),d.jsx("th",{className:"p-4 text-right",children:"Output Tokens"}),d.jsx("th",{className:"p-4 text-right",children:"Total Tokens"}),d.jsx("th",{className:"p-4 text-right",children:"Audio (s)"}),d.jsx("th",{className:"p-4 text-right",children:"Est. Cost (USD)"})]})}),d.jsx("tbody",{className:"divide-y divide-azure-border dark:divide-matrix-primary/30",children:n.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:8,className:"p-8 text-center text-azure-text-muted dark:text-matrix-secondary italic",children:"NO_DATA_AVAILABLE"})}):n.map((g,y)=>d.jsxs("tr",{className:"hover:bg-azure-hover dark:hover:bg-matrix-primary/10 transition-colors",children:[d.jsx("td",{className:"p-4 font-bold text-azure-text-primary dark:text-matrix-highlight",children:g.provider}),d.jsx("td",{className:"p-4 text-azure-text-secondary dark:text-matrix-secondary",children:g.model}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.messageCount.toLocaleString()}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.totalInputTokens.toLocaleString()}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.totalOutputTokens.toLocaleString()}),d.jsx("td",{className:"p-4 text-right font-bold text-azure-text-primary dark:text-matrix-highlight",children:g.totalTokens.toLocaleString()}),d.jsx("td",{className:"p-4 text-right text-azure-text-primary dark:text-gray-300",children:g.totalAudioSeconds>0?g.totalAudioSeconds.toLocaleString():"—"}),d.jsx("td",{className:"p-4 text-right font-bold text-green-600 dark:text-green-400",children:g.estimatedCostUsd!=null?`$${g.estimatedCostUsd.toFixed(4)}`:"—"})]},`${g.provider}-${g.model}-${y}`))})]})})]})]})}const WH=()=>{const[e,t]=z.useState(""),[n,a]=z.useState(""),s=Yp(),u=vr(),l=f=>{f.preventDefault(),e&&(a(""),fetch("/api/config",{headers:{"x-architect-pass":e}}).then(async h=>{if(h.ok){localStorage.setItem("morpheus.auth.token",e);const m=u.state?.from?.pathname||"/";s(m,{replace:!0})}else a("Invalid architect password")}).catch(()=>{a("Connection failed")}))};return d.jsx("div",{className:"flex items-center justify-center min-h-screen bg-azure-bg dark:bg-black text-azure-primary dark:text-green-500 font-mono",children:d.jsxs("div",{className:"max-w-md w-full p-8 border border-azure-primary dark:border-green-500 shadow-xl dark:shadow-[0_0_15px_rgba(34,197,94,0.3)] bg-white dark:bg-black rounded-lg dark:rounded-none",children:[d.jsx("h1",{className:"text-2xl font-bold mb-6 text-center tracking-widest uppercase text-azure-primary dark:text-green-500",children:"> The Architect Login"}),d.jsxs("form",{onSubmit:l,className:"space-y-6",children:[d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm mb-2 opacity-70 text-azure-text-secondary dark:text-green-500",children:"ACCESS_PASS:"}),d.jsx("input",{type:"password",value:e,onChange:f=>t(f.target.value),className:"w-full bg-azure-bg dark:bg-black border border-azure-border dark:border-green-800 p-2 focus:outline-none focus:border-azure-primary dark:focus:border-green-500 text-azure-text-primary dark:text-green-500 placeholder-azure-text-secondary/50 dark:placeholder-green-900 rounded dark:rounded-none",placeholder:"••••••••",autoFocus:!0})]}),n&&d.jsxs("div",{className:"text-red-500 text-sm animate-pulse",children:["[!] ERROR: ",n]}),d.jsx("button",{type:"submit",className:"w-full bg-azure-primary hover:bg-azure-active dark:bg-green-900 dark:hover:bg-green-700 text-white dark:text-black font-bold py-2 transition-colors duration-200 uppercase tracking-wider rounded dark:rounded-none",children:"Authenticate"})]}),d.jsx("div",{className:"mt-8 text-[10px] opacity-30 text-center uppercase text-azure-text-secondary dark:text-green-500",children:"Morpheus OS v0.1.5 | Unauthorized access is logged."})]})})},eF=({children:e})=>{const{isAuthenticated:t}=d_(),n=vr();return t?d.jsx(d.Fragment,{children:e}):d.jsx(iS,{to:"/login",state:{from:n},replace:!0})},tF=({className:e,...t})=>d.jsx("div",{className:"relative w-full overflow-auto",children:d.jsx("table",{className:`w-full caption-bottom text-sm ${e}`,...t})}),nF=({...e})=>d.jsx("thead",{...e}),rF=({...e})=>d.jsx("tbody",{...e}),Mm=({...e})=>d.jsx("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 transition-colors hover:bg-azure-hover/50 dark:hover:bg-matrix-primary/10",...e}),_s=({className:e,...t})=>d.jsx("th",{className:`h-12 px-4 text-left align-middle font-medium text-azure-text-secondary dark:text-matrix-secondary/70 [&:has([role=checkbox])]:pr-0 ${e}`,...t}),vi=({className:e,...t})=>d.jsx("td",{className:`p-4 align-middle [&:has([role=checkbox])]:pr-0 ${e}`,...t}),Rw=({checked:e,onCheckedChange:t,className:n,...a})=>{const s=u=>{t&&t(u.target.checked),a.onChange&&a.onChange(u)};return d.jsx("input",{type:"checkbox",checked:e,onChange:s,className:`h-4 w-4 rounded border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-primary dark:text-matrix-highlight focus:ring-azure-primary dark:focus:ring-matrix-highlight ${n||""}`,...a})},nd=({className:e,variant:t="default",...n})=>{const s=`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-zinc-950 focus:ring-offset-2 dark:focus:ring-zinc-300 ${t==="destructive"?"border-transparent bg-red-500 text-zinc-50 dark:bg-red-900 dark:text-zinc-50":t==="secondary"?"border-transparent bg-azure-surface dark:bg-zinc-800 text-azure-text-secondary dark:text-matrix-secondary":t==="outline"?"text-azure-text-primary dark:text-matrix-secondary border-azure-border dark:border-matrix-primary":"border-transparent bg-azure-primary dark:bg-matrix-highlight text-azure-text-inverse dark:text-black"} ${e||""}`;return d.jsx("div",{className:s,...n})},Dm=({className:e,...t})=>d.jsx("div",{className:`rounded-lg border border-azure-border dark:border-matrix-primary/30 bg-azure-surface dark:bg-zinc-900 text-azure-text-primary dark:text-matrix-secondary shadow-sm ${e||""}`,...t}),Mw=({className:e,...t})=>d.jsx("div",{className:`flex flex-col space-y-1.5 p-6 ${e||""}`,...t}),aF=({className:e,...t})=>d.jsx("h3",{className:`text-2xl font-semibold leading-none tracking-tight ${e||""}`,...t}),$m=({className:e,...t})=>d.jsx("div",{className:`p-6 pt-0 ${e||""}`,...t}),iF=({className:e,variant:t="default",...n})=>{const s=`relative w-full rounded-lg border p-4 ${t==="destructive"?"border-red-500/50 text-red-700 dark:border-red-900/50 dark:text-red-300":"border-azure-border dark:border-matrix-primary"} ${e||""}`;return d.jsx("div",{className:s,...n})},sF=({className:e,...t})=>d.jsx("div",{className:`text-sm [&_p]:leading-relaxed ${e||""}`,...t}),h2=({isOpen:e,onClose:t,title:n,children:a,size:s="md"})=>{if(!e)return null;const u={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",xl:"max-w-xl"};return d.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[d.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),d.jsxs("div",{className:`relative bg-azure-surface dark:bg-black rounded-lg border border-azure-border dark:border-matrix-primary shadow-xl w-full ${u[s]} max-h-[90vh] overflow-hidden flex flex-col`,children:[n&&d.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-azure-border dark:border-matrix-primary",children:[n&&d.jsx("h3",{className:"text-lg font-semibold text-azure-text-primary dark:text-matrix-highlight",children:n}),t&&d.jsx("button",{onClick:t,className:"text-azure-text-secondary dark:text-matrix-tertiary hover:text-azure-text-primary dark:hover:text-matrix-highlight",children:d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:d.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),d.jsx("div",{className:"overflow-y-auto flex-grow p-6",children:a})]})]})},oF=({isOpen:e,onClose:t,memory:n})=>n?d.jsx(h2,{isOpen:e,onClose:t,title:"Memory Details",size:"lg",children:d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(UA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Category"})]}),d.jsx("div",{children:d.jsx(nd,{variant:"outline",children:n.category})}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(GA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Importance"})]}),d.jsx("div",{children:d.jsx(nd,{variant:n.importance==="critical"?"destructive":n.importance==="high"?"default":n.importance==="medium"?"secondary":"outline",children:n.importance})}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(hS,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Created"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:new Date(n.created_at).toLocaleString()}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(Za,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Updated"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:new Date(n.updated_at).toLocaleString()}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(sd,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Access Count"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:n.access_count}),d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(iA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Hash"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary break-all text-sm",children:n.hash}),n.source&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(uA,{className:"w-4 h-4 text-azure-text-secondary dark:text-matrix-tertiary"}),d.jsx("span",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm",children:"Source"})]}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary",children:n.source})]})]}),d.jsxs("div",{children:[d.jsx("h4",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm mb-2",children:"Summary"}),d.jsx("p",{className:"text-azure-text-primary dark:text-matrix-secondary bg-azure-surface dark:bg-zinc-900 p-3 rounded-md",children:n.summary})]}),n.details&&d.jsxs("div",{children:[d.jsx("h4",{className:"text-azure-text-secondary dark:text-matrix-tertiary text-sm mb-2",children:"Details"}),d.jsx("div",{className:"text-azure-text-primary dark:text-matrix-secondary bg-azure-surface dark:bg-zinc-900 p-3 rounded-md whitespace-pre-wrap",children:n.details})]}),d.jsx("div",{className:"flex justify-end pt-4",children:d.jsx(lr,{onClick:t,children:"Close"})})]})}):null,m2=({isOpen:e,onClose:t,onConfirm:n,title:a="Confirm Deletion",message:s="Are you sure you want to delete this item? This action cannot be undone.",confirmButtonText:u="Delete",cancelButtonText:l="Cancel"})=>d.jsx(h2,{isOpen:e,onClose:t,title:a,size:"md",children:d.jsxs("div",{className:"space-y-6",children:[d.jsx("p",{className:"text-azure-text-primary dark:text-matrix-secondary",children:s}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(lr,{variant:"outline",onClick:t,children:l}),d.jsx(lr,{variant:"destructive",onClick:()=>{n(),t()},children:u})]})]})}),lF=()=>{const[e,t]=z.useState(!1),[n,a]=z.useState(null),s=z.useCallback(h=>(t(!0),a(null),xe.get(h).then(m=>m).catch(m=>{throw a(m.message||"An error occurred"),m}).finally(()=>{t(!1)})),[]),u=z.useCallback((h,m)=>(t(!0),a(null),xe.post(h,m).then(g=>g).catch(g=>{throw a(g.message||"An error occurred"),g}).finally(()=>{t(!1)})),[]),l=z.useCallback((h,m)=>(t(!0),a(null),xe.post(h,m).then(g=>g).catch(g=>{throw a(g.message||"An error occurred"),g}).finally(()=>{t(!1)})),[]),f=z.useCallback(h=>(t(!0),a(null),xe.delete(h).then(m=>m).catch(m=>{throw a(m.message||"An error occurred"),m}).finally(()=>{t(!1)})),[]);return{get:s,post:u,put:l,del:f,loading:e,error:n}},uF=()=>{const[e,t]=z.useState([]),[n,a]=z.useState(!0),[s,u]=z.useState([]),[l,f]=z.useState(""),[h,m]=z.useState("all"),[g,y]=z.useState("all"),[v,b]=z.useState(null),[S,j]=z.useState(!1),[A,E]=z.useState(null),[O,N]=z.useState(!1),[L,D]=z.useState(null),[R,q]=z.useState(!1),{get:V,del:X,post:fe}=lF();z.useEffect(()=>{se()},[]);const se=async()=>{try{a(!0);const C=await V("/sati/memories");t(C),b(null)}catch(C){b("Failed to load memories. Please try again."),console.error("Error fetching memories:",C)}finally{a(!1)}},le=()=>{s.length===B.length?u([]):u(B.map(C=>C.id))},ee=C=>{s.includes(C)?u(s.filter(I=>I!==C)):u([...s,C])},oe=async()=>{if(s.length!==0)try{await fe("/sati/memories/bulk-delete",{ids:s}),await se(),u([]),j(!1)}catch(C){b("Failed to delete memories. Please try again."),console.error("Error deleting memories:",C)}},ae=C=>{D(C),q(!0)},P=async()=>{if(L)try{await X(`/sati/memories/${L}`),await se()}catch(C){b("Failed to delete memory. Please try again."),console.error("Error deleting memory:",C)}finally{D(null),q(!1)}},J=C=>{E(C),N(!0)},B=e.filter(C=>{const I=C.summary.toLowerCase().includes(l.toLowerCase())||C.details?.toLowerCase().includes(l.toLowerCase())||C.category.toLowerCase().includes(l.toLowerCase()),w=h==="all"||C.category===h,Y=g==="all"||C.importance===g;return I&&w&&Y&&!C.archived}),me=Array.from(new Set(e.map(C=>C.category))),T=Array.from(new Set(e.map(C=>C.importance)));return n?d.jsx(Dm,{className:"w-full",children:d.jsx($m,{className:"flex justify-center items-center h-64",children:d.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-azure-primary dark:border-matrix-highlight"})})}):d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"Sati Memories"}),d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary mt-1",children:"View and manage your long-term memories stored by Sati"})]}),s.length>0&&d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs("span",{className:"text-sm text-azure-text-muted dark:text-matrix-secondary",children:[s.length," selected"]}),d.jsxs(lr,{variant:"destructive",size:"sm",onClick:()=>j(!0),disabled:s.length===0,children:[d.jsx(Ti,{className:"w-4 h-4 mr-1"}),"Delete Selected"]})]})]}),v&&d.jsx(iF,{variant:"destructive",children:d.jsx(sF,{children:v})}),d.jsxs(Dm,{children:[d.jsx(Mw,{className:"border-b border-azure-border dark:border-matrix-primary",children:d.jsxs("div",{className:"flex flex-col lg:flex-row gap-4",children:[d.jsxs("div",{className:"flex flex-col relative w-full",children:[d.jsx(OA,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-azure-text-secondary dark:text-matrix-secondary w-4 h-4"}),d.jsx("input",{type:"text",placeholder:"Search memories...",value:l,onChange:C=>f(C.target.value),className:"w-full pl-10 pr-4 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-md text-azure-text-primary dark:text-matrix-secondary focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight"})]}),d.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full",children:[d.jsxs("select",{value:h,onChange:C=>m(C.target.value),className:"px-3 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-md text-azure-text-primary dark:text-matrix-secondary focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight flex-grow",children:[d.jsx("option",{value:"all",children:"All Categories"}),me.map(C=>d.jsx("option",{value:C,children:C},C))]}),d.jsxs("select",{value:g,onChange:C=>y(C.target.value),className:"px-3 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-md text-azure-text-primary dark:text-matrix-secondary focus:outline-none focus:ring-2 focus:ring-azure-primary dark:focus:ring-matrix-highlight flex-grow",children:[d.jsx("option",{value:"all",children:"All Importance"}),T.map(C=>d.jsx("option",{value:C,children:C},C))]})]})]})}),d.jsx($m,{className:"p-0",children:d.jsxs(tF,{children:[d.jsx(nF,{children:d.jsxs(Mm,{className:"hover:bg-transparent",children:[d.jsx(_s,{className:"w-12",children:d.jsx(Rw,{checked:B.length>0&&s.length===B.length,onCheckedChange:le})}),d.jsx(_s,{children:"Summary"}),d.jsx(_s,{children:"Category"}),d.jsx(_s,{children:"Importance"}),d.jsx(_s,{children:"Created"}),d.jsx(_s,{className:"w-32",children:"Actions"})]})}),d.jsx(rF,{children:B.length===0?d.jsx(Mm,{children:d.jsx(vi,{colSpan:6,className:"text-center py-8 text-azure-text-secondary dark:text-matrix-secondary",children:n?"Loading memories...":"No memories found"})}):B.map(C=>d.jsxs(Mm,{children:[d.jsx(vi,{children:d.jsx(Rw,{checked:s.includes(C.id),onCheckedChange:()=>ee(C.id)})}),d.jsx(vi,{className:"font-medium max-w-xs truncate",children:C.summary}),d.jsx(vi,{children:d.jsx(nd,{variant:"outline",children:C.category})}),d.jsx(vi,{children:d.jsx(nd,{variant:C.importance==="critical"?"destructive":C.importance==="high"?"default":C.importance==="medium"?"secondary":"outline",children:C.importance})}),d.jsx(vi,{children:d.jsxs("div",{className:"flex items-center gap-1 text-azure-text-secondary dark:text-matrix-secondary",children:[d.jsx(hS,{className:"w-4 h-4"}),new Date(C.created_at).toLocaleDateString()]})}),d.jsx(vi,{children:d.jsxs("div",{className:"flex gap-1",children:[d.jsx(lr,{variant:"ghost",size:"sm",onClick:()=>J(C),className:"text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",children:d.jsx(sd,{className:"w-4 h-4"})}),d.jsx(lr,{variant:"ghost",size:"sm",onClick:()=>ae(C.id),className:"text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},C.id))})]})})]}),S&&d.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:d.jsxs(Dm,{className:"w-full max-w-md mx-4",children:[d.jsx(Mw,{children:d.jsx(aF,{children:"Delete Memories"})}),d.jsxs($m,{children:[d.jsxs("p",{className:"mb-4",children:["Are you sure you want to delete ",s.length," ","memory(ies)? This action cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx(lr,{variant:"outline",onClick:()=>j(!1),children:"Cancel"}),d.jsx(lr,{variant:"destructive",onClick:oe,children:"Delete"})]})]})]})}),d.jsx(oF,{isOpen:O,onClose:()=>N(!1),memory:A}),d.jsx(m2,{isOpen:R,onClose:()=>q(!1),onConfirm:P,title:"Confirm Memory Deletion",message:"Are you sure you want to delete this memory? This action cannot be undone.",confirmButtonText:"Delete Memory",cancelButtonText:"Cancel"})]})},ki=_i.getInstance(),wi={fetchServers:async()=>ki.get("/mcp/servers"),addServer:async(e,t)=>ki.post("/mcp/servers",{name:e,config:t}),updateServer:async(e,t)=>ki.put(`/mcp/servers/${encodeURIComponent(e)}`,{config:t}),deleteServer:async e=>ki.delete(`/mcp/servers/${encodeURIComponent(e)}`),toggleServer:async(e,t)=>ki.patch(`/mcp/servers/${encodeURIComponent(e)}/toggle`,{enabled:t}),reloadTools:async()=>ki.post("/mcp/reload",{}),fetchStatus:async()=>ki.get("/mcp/status")},cF=({label:e,values:t,onChange:n,placeholder:a})=>{const s=t.length>0?t:[""],u=(h,m)=>{const g=[...s];g[h]=m,n(g.filter(y=>y.trim().length>0))},l=()=>n([...s,""]),f=h=>{const m=s.filter((g,y)=>y!==h);n(m.filter(g=>g.trim().length>0))};return d.jsxs("div",{className:"space-y-2",children:[d.jsx("div",{className:"text-sm font-semibold text-azure-text-primary dark:text-matrix-secondary",children:e}),s.map((h,m)=>d.jsxs("div",{className:"flex gap-2",children:[d.jsx("input",{className:"flex-1 rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:h,placeholder:a,onChange:g=>u(m,g.target.value)}),d.jsx("button",{type:"button",className:"rounded-md border border-red-300 px-3 py-2 text-sm text-red-600 hover:border-red-400 hover:text-red-500 dark:border-red-900 dark:text-red-400",onClick:()=>f(m),children:"Remove"})]},`${e}-${m}`)),d.jsx("button",{type:"button",className:"text-sm font-semibold text-azure-primary hover:text-azure-secondary dark:text-matrix-highlight hover:dark:text-matrix-secondary",onClick:l,children:"Add argument"})]})},Dw=({label:e,values:t,onChange:n,keyPlaceholder:a,valuePlaceholder:s})=>{const u=z.useMemo(()=>t.length>0?t:[{key:"",value:""}],[t]),l=(m,g,y)=>{const v=[...u];v[m]={...v[m],[g]:y},n(v.filter(b=>b.key.trim().length>0||b.value.trim().length>0))},f=()=>n([...u,{key:"",value:""}]),h=m=>{const g=u.filter((y,v)=>v!==m);n(g.filter(y=>y.key.trim().length>0||y.value.trim().length>0))};return d.jsxs("div",{className:"space-y-2",children:[d.jsx("div",{className:"text-sm font-semibold text-azure-text-primary dark:text-matrix-secondary",children:e}),u.map((m,g)=>d.jsxs("div",{className:"grid gap-2 md:grid-cols-5",children:[d.jsx("input",{className:"col-span-2 rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:m.key,placeholder:a,onChange:y=>l(g,"key",y.target.value)}),d.jsx("input",{className:"col-span-2 rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:m.value,placeholder:s,onChange:y=>l(g,"value",y.target.value)}),d.jsx("button",{type:"button",className:"rounded-md border border-red-300 px-3 py-2 text-sm text-red-600 hover:border-red-400 hover:text-red-500 dark:border-red-900 dark:text-red-400",onClick:()=>h(g),children:"Remove"})]},`${e}-${g}`)),d.jsx("button",{type:"button",className:"text-sm font-semibold text-azure-primary hover:text-azure-secondary dark:text-matrix-highlight hover:dark:text-matrix-secondary",onClick:f,children:"Add entry"})]})},dF=({transport:e,command:t,url:n,args:a,env:s,headers:u,onCommandChange:l,onUrlChange:f,onArgsChange:h,onEnvChange:m,onHeadersChange:g})=>d.jsxs("div",{className:"space-y-4",children:[e==="stdio"&&d.jsxs(d.Fragment,{children:[d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Command",d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:t,onChange:y=>l(y.target.value),placeholder:"npx"})]}),d.jsx(cF,{label:"Arguments",values:a,onChange:h,placeholder:"--flag"})]}),e==="http"&&d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["URL",d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:n,onChange:y=>f(y.target.value),placeholder:"https://example.com/mcp"})]}),d.jsx(Dw,{label:"Environment Variables",values:s,onChange:m,keyPlaceholder:"KEY",valuePlaceholder:"value"}),e==="http"&&d.jsx(Dw,{label:"Headers",values:u,onChange:g,keyPlaceholder:"Header",valuePlaceholder:"value"})]}),fF=zH({name:Rm().min(1,"Name is required"),transport:c2([Ew("stdio"),Ew("http")]),command:Rm().optional(),url:Rm().optional()}),jc=e=>e?Object.entries(e).map(([t,n])=>({key:t,value:n})):[],Lm=e=>e.reduce((t,n)=>(n.key.trim().length===0||(t[n.key]=n.value),t),{}),hF=({open:e,mode:t,initial:n,onClose:a,onSubmit:s})=>{const[u,l]=z.useState(n?.name??""),[f,h]=z.useState(n?.config.transport??"stdio"),[m,g]=z.useState(n?.config.transport==="stdio"?n.config.command:""),[y,v]=z.useState(n?.config.transport==="http"?n.config.url:""),[b,S]=z.useState(n?.config.args??[]),[j,A]=z.useState(jc(n?.config.env)),[E,O]=z.useState(n?.config.transport==="http"?jc(n.config.headers):[]),[N,L]=z.useState(null);z.useEffect(()=>{e&&(l(n?.name??""),h(n?.config.transport??"stdio"),g(n?.config.transport==="stdio"?n.config.command:""),v(n?.config.transport==="http"?n.config.url:""),S(n?.config.args??[]),A(jc(n?.config.env)),O(n?.config.transport==="http"?jc(n.config.headers):[]),L(null))},[e,n]);const D=t==="create",R=async()=>{const V=fF.safeParse({name:u,transport:f,command:m,url:y});if(!V.success){L(V.error.issues[0]?.message??"Invalid form");return}if(f==="stdio"&&(!m||m.trim().length===0)){L("Command is required for stdio transport.");return}if(f==="http"&&(!y||y.trim().length===0)){L("URL is required for http transport.");return}const X=f==="stdio"?{transport:"stdio",command:m.trim(),args:b.length>0?b:void 0,env:j.length>0?Lm(j):void 0}:{transport:"http",url:y.trim(),headers:E.length>0?Lm(E):void 0,env:j.length>0?Lm(j):void 0};L(null),await s(u.trim(),X)},q=z.useMemo(()=>t==="create"?"Add MCP Server":"Edit MCP Server",[t]);return d.jsx(Or,{open:e,onOpenChange:a,children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:q})}),d.jsxs("div",{className:"space-y-4",children:[d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Name",d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none disabled:bg-azure-border dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary dark:disabled:bg-matrix-primary/50",value:u,onChange:V=>l(V.target.value),placeholder:"coolify",disabled:!D})]}),d.jsxs("label",{className:"block space-y-2 text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Transport",d.jsxs("select",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:f,onChange:V=>h(V.target.value),children:[d.jsx("option",{value:"stdio",children:"stdio"}),d.jsx("option",{value:"http",children:"http"})]})]}),d.jsx(dF,{transport:f,command:m,url:y,args:b,env:j,headers:E,onCommandChange:g,onUrlChange:v,onArgsChange:S,onEnvChange:A,onHeadersChange:O}),N&&d.jsx("div",{className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/50 dark:text-red-400",children:N}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx("button",{type:"button",className:"rounded-md border border-azure-border px-4 py-2 text-sm text-azure-text-primary hover:border-azure-primary hover:text-azure-primary dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:a,children:"Cancel"}),d.jsx("button",{type:"button",className:"rounded-md bg-azure-primary px-4 py-2 text-sm font-semibold text-white shadow hover:bg-azure-secondary dark:bg-matrix-highlight dark:text-matrix-bg hover:dark:bg-matrix-secondary",onClick:R,children:"Save"})]})]})]})})},mF=({server:e,probeResult:t,onEdit:n,onDelete:a,onToggle:s})=>d.jsxs("div",{className:"rounded-2xl border border-azure-border bg-azure-surface/80 p-4 shadow-sm overflow-hidden dark:border-matrix-primary dark:bg-zinc-950/70",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3",children:[d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsx("div",{className:"text-lg font-semibold text-azure-text-primary break-words dark:text-matrix-highlight",children:e.name}),d.jsx("div",{className:"text-xs uppercase tracking-wide text-azure-text-muted dark:text-matrix-secondary",children:e.config.transport})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[t&&d.jsx("span",{title:t.ok?`${t.toolCount} tools`:t.error,className:`rounded-full px-2 py-0.5 text-xs font-semibold ${t.ok?"bg-green-500/20 text-green-600 dark:bg-green-400/20 dark:text-green-400":"bg-red-500/20 text-red-600 dark:bg-red-400/20 dark:text-red-400"}`,children:t.ok?`✓ ${t.toolCount} tools`:"✗ Failed"}),d.jsx("button",{type:"button",className:`rounded-full px-3 py-1 text-xs font-semibold ${e.enabled?"bg-matrix-highlight dark:text-matrix-primary":"bg-azure-border text-azure-text-secondary dark:bg-matrix-primary/50 dark:text-matrix-secondary"}`,onClick:()=>s(e,!e.enabled),children:e.enabled?"Enabled":"Disabled"})]})]}),d.jsxs("div",{className:"mt-4 space-y-2 text-sm text-azure-text-secondary dark:text-matrix-secondary",children:[e.config.transport==="stdio"&&d.jsxs("div",{className:"break-all",children:[d.jsx("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:"Command:"})," ",e.config.command]}),e.config.transport==="http"&&d.jsxs("div",{className:"break-all",children:[d.jsx("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:"URL:"})," ",e.config.url]}),e.config.args&&e.config.args.length>0&&d.jsxs("div",{className:"break-all",children:[d.jsx("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:"Args:"})," ",e.config.args.join(" ")]}),t&&!t.ok&&t.error&&d.jsx("div",{className:"mt-1 break-all rounded border border-red-300 bg-red-50 px-2 py-1 text-xs text-red-600 dark:border-red-900 dark:bg-red-950/30 dark:text-red-400",children:t.error.length>120?t.error.slice(0,120)+"…":t.error})]}),d.jsxs("div",{className:"mt-4 flex gap-2",children:[d.jsx("button",{type:"button",className:"rounded-md border border-azure-border px-3 py-2 text-sm text-azure-text-primary hover:border-azure-primary hover:text-azure-primary dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:()=>n(e),children:"Edit"}),d.jsx("button",{type:"button",className:"rounded-md border border-red-300 px-3 py-2 text-sm text-red-600 hover:border-red-400 hover:text-red-500 dark:border-red-900 dark:text-red-400",onClick:()=>a(e),children:"Delete"})]})]}),pF=()=>{const{data:e,error:t,mutate:n,isLoading:a}=zt("/api/mcp/servers",()=>wi.fetchServers()),[s,u]=z.useState(""),[l,f]=z.useState("all"),[h,m]=z.useState(!1),[g,y]=z.useState(null),[v,b]=z.useState(!1),[S,j]=z.useState(null),[A,E]=z.useState(null),[O,N]=z.useState({}),[L,D]=z.useState(!1),[R,q]=z.useState(!1),V=e?.servers??[],X=z.useMemo(()=>V.filter(B=>{const me=B.name.toLowerCase().includes(s.toLowerCase()),T=l==="all"||B.config.transport===l;return me&&T}),[V,s,l]),fe=()=>{y(null),m(!0)},se=B=>{y(B),m(!0)},le=async(B,me)=>{try{g?await wi.updateServer(g.name,me):await wi.addServer(B,me),m(!1),y(null),await n(),E({type:"success",message:"MCPs saved successfully. Restart MCPs for changes to take effect."})}catch(T){E({type:"error",message:T.message||"Failed to save MCP server."})}},ee=async B=>{j(B),b(!0)},oe=async()=>{if(S)try{await wi.deleteServer(S.name),await n(),b(!1),j(null),E({type:"success",message:"MCPs saved successfully. Restart MCPs for changes to take effect."})}catch(B){E({type:"error",message:B.message||"Failed to delete MCP server."})}},ae=async()=>{D(!0);try{const B=await wi.fetchStatus(),me={};for(const T of B.servers)me[T.name]=T;N(me)}catch(B){E({type:"error",message:B.message||"Failed to check MCP status."})}finally{D(!1)}},P=async()=>{q(!0);try{await wi.reloadTools(),E({type:"success",message:"MCP tools reloaded successfully."})}catch(B){E({type:"error",message:B.message||"Failed to reload MCP tools."})}finally{q(!1)}},J=async(B,me)=>{try{await wi.toggleServer(B.name,me),await n(),E({type:"success",message:"MCPs saved successfully. Restart MCPs for changes to take effect."})}catch(T){E({type:"error",message:T.message||"Failed to toggle MCP server."})}};return d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-semibold text-azure-primary dark:text-matrix-highlight",children:"MCP Servers"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:"Manage MCP servers stored in mcps.json."})]}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx("button",{type:"button",disabled:L,className:"rounded-md border border-azure-border px-4 py-2 text-sm font-semibold text-azure-text-primary shadow hover:border-azure-primary hover:text-azure-primary disabled:opacity-50 dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:ae,children:L?"Checking…":"Check Status"}),d.jsx("button",{type:"button",disabled:R,className:"rounded-md border border-azure-border px-4 py-2 text-sm font-semibold text-azure-text-primary shadow hover:border-azure-primary hover:text-azure-primary disabled:opacity-50 dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:P,children:R?"Reloading…":"Reload MCPs"}),d.jsx("button",{type:"button",className:"rounded-md bg-azure-primary px-4 py-2 text-sm font-semibold text-white shadow hover:bg-azure-secondary dark:bg-matrix-highlight dark:text-matrix-bg hover:dark:bg-matrix-secondary",onClick:fe,children:"Add Server"})]})]}),A&&d.jsx("div",{className:`p-4 rounded border ${A.type==="success"?"border-azure-primary text-azure-primary bg-azure-primary/10 dark:border-matrix-highlight dark:text-matrix-highlight dark:bg-matrix-highlight/10":"border-red-500 text-red-500 bg-red-900/10"}`,children:A.message}),d.jsxs("div",{className:"flex flex-col gap-2 md:flex-row md:items-center",children:[d.jsx("input",{className:"w-full rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:s,onChange:B=>u(B.target.value),placeholder:"Search by name"}),d.jsxs("select",{className:"rounded-md border border-azure-border bg-azure-surface px-3 py-2 text-sm text-azure-text-primary shadow-sm focus:border-azure-primary focus:outline-none dark:border-matrix-primary dark:bg-black dark:text-matrix-secondary",value:l,onChange:B=>f(B.target.value),children:[d.jsx("option",{value:"all",children:"All"}),d.jsx("option",{value:"stdio",children:"stdio"}),d.jsx("option",{value:"http",children:"http"})]})]}),a&&d.jsx("div",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:"Loading MCP servers..."}),t&&d.jsx("div",{className:"text-sm text-red-600 dark:text-red-400",children:"Failed to load MCP servers."}),!a&&X.length===0&&d.jsx("div",{className:"rounded-2xl border border-dashed border-azure-border bg-azure-surface/60 p-6 text-center text-sm text-azure-text-secondary dark:border-matrix-primary dark:bg-zinc-950/60 dark:text-matrix-secondary",children:"No MCP servers found. Add a server to get started."}),d.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:X.map(B=>d.jsx(mF,{server:B,probeResult:O[B.name],onEdit:se,onDelete:ee,onToggle:J},`${B.name}-${B.enabled?"on":"off"}`))}),d.jsx(hF,{open:h,mode:g?"edit":"create",initial:g??void 0,onClose:()=>m(!1),onSubmit:le}),d.jsx(Or,{open:v,onOpenChange:b,children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:"Confirm Deletion"})}),d.jsxs("div",{className:"space-y-4",children:[d.jsxs("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:["Are you sure you want to delete the MCP server ",d.jsxs("span",{className:"font-semibold text-azure-text-primary dark:text-matrix-highlight",children:['"',S?.name,'"']}),"? This action cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-2",children:[d.jsx("button",{type:"button",className:"rounded-md border border-azure-border px-4 py-2 text-sm text-azure-text-primary hover:border-azure-primary hover:text-azure-primary dark:border-matrix-primary dark:text-matrix-secondary hover:dark:border-matrix-highlight hover:dark:text-matrix-highlight",onClick:()=>b(!1),children:"Cancel"}),d.jsx("button",{type:"button",className:"rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white shadow hover:bg-red-400 dark:bg-red-600 hover:dark:bg-red-500",onClick:oe,children:"Delete"})]})]})]})})]})},Pm={list:()=>xe.get("/model-pricing"),upsert:e=>xe.post("/model-pricing",e),update:(e,t,n)=>xe.put(`/model-pricing/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,n),delete:(e,t)=>xe.delete(`/model-pricing/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)},gF={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},$w={hidden:{opacity:0,y:10},show:{opacity:1,y:0}},xF=["anthropic","openai","google","openrouter","ollama","other"],Lw=()=>({provider:"",model:"",input_price_per_1m:0,output_price_per_1m:0}),yF=()=>{const{data:e=[],mutate:t}=zt("/api/model-pricing",()=>Pm.list()),[n,a]=z.useState(!1),[s,u]=z.useState(null),[l,f]=z.useState(Lw()),[h,m]=z.useState(null),[g,y]=z.useState(null),[v,b]=z.useState(!1),S=(N,L)=>{y({type:N,message:L}),setTimeout(()=>y(null),3e3)},j=()=>{u(null),f(Lw()),a(!0)},A=N=>{u(N),f({...N}),a(!0)},E=async()=>{if(!(!l.provider.trim()||!l.model.trim())){b(!0);try{await Pm.upsert(l),await t(),a(!1),S("success",s?"Pricing updated.":"Pricing created.")}catch{S("error","Failed to save pricing entry.")}finally{b(!1)}}},O=async()=>{if(h)try{await Pm.delete(h.provider,h.model),await t(),m(null),S("success","Pricing entry deleted.")}catch{S("error","Failed to delete pricing entry.")}};return d.jsxs(dt.div,{variants:gF,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:$w,className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Pc,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Model Pricing"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mt-0.5",children:"Manage per-model pricing to estimate LLM costs in Usage Stats."})]})]}),d.jsxs("button",{onClick:j,className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[d.jsx(od,{className:"w-4 h-4"})," Add Pricing"]})]}),g&&d.jsx(dt.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:`px-4 py-3 rounded-lg text-sm font-medium border ${g.type==="success"?"bg-green-50 dark:bg-green-900/20 border-green-300 dark:border-green-700 text-green-800 dark:text-green-400":"bg-red-50 dark:bg-red-900/20 border-red-300 dark:border-red-700 text-red-800 dark:text-red-400"}`,children:g.message}),d.jsx(dt.div,{variants:$w,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-hidden",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["Provider","Model","Input ($/1M tokens)","Output ($/1M tokens)","Actions"].map(N=>d.jsx("th",{className:"px-4 py-3 text-left font-semibold text-azure-text-secondary dark:text-matrix-secondary",children:N},N))})}),d.jsx("tbody",{children:e.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-azure-text-secondary dark:text-matrix-secondary",children:'No pricing entries. Click "Add Pricing" to get started.'})}):e.map(N=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-800/50 transition-colors",children:[d.jsx("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-text capitalize",children:N.provider}),d.jsx("td",{className:"px-4 py-3 font-mono text-azure-text-primary dark:text-matrix-highlight text-xs",children:N.model}),d.jsxs("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-text",children:["$",N.input_price_per_1m.toFixed(4)]}),d.jsxs("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-text",children:["$",N.output_price_per_1m.toFixed(4)]}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx("button",{onClick:()=>A(N),className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",title:"Edit",children:d.jsx(Wp,{className:"w-4 h-4"})}),d.jsx("button",{onClick:()=>m(N),className:"p-1.5 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-azure-text-secondary dark:text-matrix-secondary hover:text-red-600 dark:hover:text-red-400 transition-colors",title:"Delete",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},`${N.provider}/${N.model}`))})]})}),d.jsx(Or,{open:n,onOpenChange:a,children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:s?"Edit Pricing":"Add Pricing"})}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Provider"}),s?d.jsx("p",{className:"px-3 py-2 rounded-lg bg-azure-bg dark:bg-zinc-900 text-azure-text-primary dark:text-matrix-secondary text-sm capitalize",children:l.provider}):d.jsxs("select",{value:l.provider,onChange:N=>f({...l,provider:N.target.value}),className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight",children:[d.jsx("option",{value:"",children:"Select provider..."}),xF.map(N=>d.jsx("option",{value:N,children:N},N))]})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Model"}),s?d.jsx("p",{className:"px-3 py-2 rounded-lg bg-azure-bg dark:bg-zinc-900 text-azure-text-primary dark:text-matrix-secondary text-sm font-mono",children:l.model}):d.jsx("input",{type:"text",value:l.model,onChange:N=>f({...l,model:N.target.value}),placeholder:"e.g. gpt-4o",className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight"})]}),d.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Input price / 1M tokens ($)"}),d.jsx("input",{type:"number",min:0,step:.001,value:l.input_price_per_1m,onChange:N=>f({...l,input_price_per_1m:parseFloat(N.target.value)||0}),className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight"})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Output price / 1M tokens ($)"}),d.jsx("input",{type:"number",min:0,step:.001,value:l.output_price_per_1m,onChange:N=>f({...l,output_price_per_1m:parseFloat(N.target.value)||0}),className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight"})]})]}),d.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[d.jsx("button",{onClick:()=>a(!1),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:E,disabled:v||!l.provider.trim()||!l.model.trim(),className:"px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 disabled:opacity-50 transition-opacity",children:v?"Saving...":"Save"})]})]})]})}),d.jsx(Or,{open:!!h,onOpenChange:N=>!N&&m(null),children:d.jsxs(Fs,{children:[d.jsx(Rr,{children:d.jsx(Mr,{children:"Delete Pricing Entry"})}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsxs("p",{className:"text-sm text-azure-text-primary dark:text-matrix-text",children:["Are you sure you want to delete the pricing for"," ",d.jsxs("span",{className:"font-mono font-semibold text-azure-primary dark:text-matrix-highlight",children:[h?.provider,"/",h?.model]}),"? This cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-3",children:[d.jsx("button",{onClick:()=>m(null),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:O,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition-colors",children:"Delete"})]})]})]})})]})},bF={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},Pw={hidden:{opacity:0,y:10},show:{opacity:1,y:0}},vF=["ui","telegram","discord"],Uw=()=>({name:"",prompt:"",notification_channels:["ui"]}),kF=()=>{const{data:e=[],mutate:t}=zt("/webhooks",()=>Pa.list(),{refreshInterval:1e4}),[n,a]=z.useState(!1),[s,u]=z.useState(null),[l,f]=z.useState(Uw()),[h,m]=z.useState(null),[g,y]=z.useState(null),[v,b]=z.useState(!1),[S,j]=z.useState(null),[A,E]=z.useState(null),O=(ee,oe)=>{y({type:ee,message:oe}),setTimeout(()=>y(null),3500)},N=()=>{u(null),f(Uw()),E(null),a(!0)},L=ee=>{u(ee),f({name:ee.name,prompt:ee.prompt,notification_channels:ee.notification_channels}),E(null),a(!0)},D=ee=>/^[a-z0-9-_]+$/.test(ee),R=async()=>{if(!(!l.name.trim()||!l.prompt.trim())){if(!D(l.name)){E("Name must only contain lowercase letters, numbers, hyphens (-) and underscores (_).");return}if(l.notification_channels.length===0){E("Select at least one notification channel.");return}E(null),b(!0);try{s?(await Pa.update(s.id,l),O("success","Webhook updated.")):(await Pa.create(l),O("success","Webhook created.")),await t(),a(!1)}catch(ee){const oe=ee?.message||"Failed to save webhook.";E(oe)}finally{b(!1)}}},q=async ee=>{try{await Pa.update(ee.id,{enabled:!ee.enabled}),await t()}catch{O("error","Failed to toggle webhook.")}},V=async()=>{if(h)try{await Pa.delete(h.id),await t(),m(null),O("success","Webhook deleted.")}catch{O("error","Failed to delete webhook.")}},X=ee=>`${window.location.origin}/api/webhooks/trigger/${ee}`,fe=ee=>`curl -X POST ${X(ee.name)} \\
109
109
  -H "x-api-key: ${ee.api_key}" \\
110
110
  -H "Content-Type: application/json" \\
111
- -d '{"event":"your_payload"}'`,se=async(ee,oe)=>{await navigator.clipboard.writeText(ee),j(oe),setTimeout(()=>j(null),2e3)},le=ee=>{const oe=l.notification_channels.includes(ee);f({...l,notification_channels:oe?l.notification_channels.filter(ae=>ae!==ee):[...l.notification_channels,ee]})};return d.jsxs(dt.div,{variants:bF,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:Pw,className:"flex items-center justify-between flex-wrap gap-3",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Gm,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Webhooks"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mt-0.5",children:"Trigger Oracle agent tasks from external events."})]})]}),d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs(Va,{to:"/notifications",className:"flex items-center gap-2 px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-sm text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:[d.jsx(Sl,{className:"w-4 h-4"}),"Notifications"]}),d.jsxs("button",{onClick:N,className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[d.jsx(od,{className:"w-4 h-4"}),"New Webhook"]})]})]}),g&&d.jsx(dt.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:`px-4 py-3 rounded-lg text-sm font-medium border ${g.type==="success"?"bg-green-50 dark:bg-green-900/20 border-green-300 dark:border-green-700 text-green-800 dark:text-green-400":"bg-red-50 dark:bg-red-900/20 border-red-300 dark:border-red-700 text-red-800 dark:text-red-400"}`,children:g.message}),d.jsx(dt.div,{variants:Pw,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-hidden",children:d.jsx("div",{className:"overflow-x-auto",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["Name","API Key","Channels","Triggers","Status","Actions"].map(ee=>d.jsx("th",{className:"px-4 py-3 text-left font-semibold text-azure-text-secondary dark:text-matrix-secondary",children:ee},ee))})}),d.jsx("tbody",{children:e.length===0?d.jsx("tr",{children:d.jsxs("td",{colSpan:6,className:"px-4 py-10 text-center text-azure-text-secondary dark:text-matrix-secondary",children:["No webhooks yet."," ",d.jsx("button",{onClick:N,className:"underline text-azure-primary dark:text-matrix-highlight",children:"Create one"})]})}):e.map(ee=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-800/50 transition-colors",children:[d.jsx("td",{className:"px-4 py-3",children:d.jsx("span",{className:"font-mono text-azure-text-primary dark:text-matrix-secondary font-medium",children:ee.name})}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs("code",{className:"text-xs font-mono text-azure-text-secondary dark:text-matrix-secondary truncate max-w-[140px]",children:[ee.api_key.slice(0,16),"…"]}),d.jsx("button",{onClick:()=>se(fe(ee),`curl-${ee.id}`),className:"p-1 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary",title:"Copy curl example",children:S===`curl-${ee.id}`?d.jsx(Im,{className:"w-3.5 h-3.5 text-green-500"}):d.jsx(qm,{className:"w-3.5 h-3.5"})}),d.jsx("button",{onClick:()=>se(ee.api_key,`key-${ee.id}`),className:"p-1 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary",title:"Copy API key",children:S===`key-${ee.id}`?d.jsx(Im,{className:"w-3.5 h-3.5 text-green-500"}):d.jsx(KT,{className:"w-3.5 h-3.5"})})]})}),d.jsx("td",{className:"px-4 py-3",children:d.jsx("div",{className:"flex gap-1 flex-wrap",children:ee.notification_channels.map(oe=>d.jsx("span",{className:"px-2 py-0.5 text-xs rounded bg-azure-border dark:bg-matrix-primary/20 text-azure-text-secondary dark:text-matrix-secondary capitalize",children:oe},oe))})}),d.jsx("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-secondary",children:ee.trigger_count}),d.jsx("td",{className:"px-4 py-3",children:d.jsx("button",{onClick:()=>q(ee),className:`flex items-center gap-1.5 text-xs px-2 py-1 rounded transition-colors ${ee.enabled?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-400 hover:bg-green-100 dark:hover:bg-green-900/30":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 dark:text-zinc-400 hover:bg-zinc-200 dark:hover:bg-zinc-700"}`,children:ee.enabled?d.jsxs(d.Fragment,{children:[d.jsx(HA,{className:"w-3.5 h-3.5"})," Enabled"]}):d.jsxs(d.Fragment,{children:[d.jsx(ZA,{className:"w-3.5 h-3.5"})," Disabled"]})})}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx("button",{onClick:()=>L(ee),title:"Edit",className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(Wp,{className:"w-4 h-4"})}),d.jsx("button",{onClick:()=>m(ee),title:"Delete",className:"p-1.5 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-azure-text-secondary dark:text-matrix-secondary hover:text-red-600 dark:hover:text-red-400 transition-colors",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},ee.id))})]})})}),d.jsxs(Or,{open:n,onOpenChange:a,children:[d.jsx(Rr,{children:d.jsx(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight",children:s?"Edit Webhook":"New Webhook"})}),d.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto",children:[d.jsxs("div",{children:[d.jsxs("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:["Name ",d.jsx("span",{className:"text-azure-text-muted dark:text-matrix-secondary/60 font-normal",children:"(slug — used in URL)"})]}),d.jsx("input",{type:"text",value:l.name,onChange:ee=>{f({...l,name:ee.target.value.toLowerCase().replace(/\s+/g,"-")}),E(null)},placeholder:"e.g. deploy-done, github-issue-opened",disabled:!!s,className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight disabled:opacity-50 disabled:cursor-not-allowed"}),l.name&&d.jsxs("p",{className:"mt-1 text-xs text-azure-text-secondary dark:text-matrix-secondary",children:["Trigger URL:"," ",d.jsxs("code",{className:"font-mono text-azure-primary dark:text-matrix-highlight",children:["POST /api/webhooks/trigger/",l.name]})]})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Agent Prompt"}),d.jsx("textarea",{rows:5,value:l.prompt,onChange:ee=>f({...l,prompt:ee.target.value}),placeholder:"Describe what Apoc should do when this webhook fires. The received payload will be appended automatically.",className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight resize-none"})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:"Notification Channels"}),d.jsx("div",{className:"flex gap-4",children:vF.map(ee=>d.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[d.jsx("input",{type:"checkbox",checked:l.notification_channels.includes(ee),onChange:()=>le(ee),className:"rounded border-azure-border dark:border-matrix-primary accent-azure-primary dark:accent-matrix-highlight"}),d.jsx("span",{className:"text-sm text-azure-text-primary dark:text-matrix-secondary capitalize",children:ee})]},ee))})]}),A&&d.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded px-3 py-2",children:A}),d.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[d.jsx("button",{onClick:()=>a(!1),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:R,disabled:v||!l.name.trim()||!l.prompt.trim()||l.notification_channels.length===0,className:"px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 disabled:opacity-50 transition-opacity",children:v?"Saving…":s?"Update":"Create"})]})]})]}),d.jsxs(Or,{open:!!h,onOpenChange:ee=>!ee&&m(null),children:[d.jsx(Rr,{children:d.jsx(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight",children:"Delete Webhook"})}),d.jsxs("div",{className:"p-6 space-y-4",children:[d.jsxs("p",{className:"text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Delete"," ",d.jsx("span",{className:"font-semibold font-mono dark:text-matrix-highlight",children:h?.name}),"? This also removes all associated notifications and cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-3",children:[d.jsx("button",{onClick:()=>m(null),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:V,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition-colors",children:"Delete"})]})]})]})]})},wF={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},Vw={hidden:{opacity:0,y:10},show:{opacity:1,y:0}},Bw=({status:e})=>e==="completed"?d.jsxs("div",{className:"flex items-center gap-1.5 text-green-600 dark:text-green-400",children:[d.jsx(mS,{className:"w-4 h-4"}),d.jsx("span",{className:"text-xs",children:"Completed"})]}):e==="failed"?d.jsxs("div",{className:"flex items-center gap-1.5 text-red-600 dark:text-red-400",children:[d.jsx(Hm,{className:"w-4 h-4"}),d.jsx("span",{className:"text-xs",children:"Failed"})]}):d.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400",children:[d.jsx(Za,{className:"w-4 h-4 animate-pulse"}),d.jsx("span",{className:"text-xs",children:"Pending"})]}),Nc=e=>new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),SF=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},zF=()=>{const[e,t]=z.useState(!1),[n,a]=z.useState(null),{data:s=[],mutate:u}=zt(["/webhooks/notifications",e],()=>Pa.listNotifications({unreadOnly:e}),{refreshInterval:5e3}),l=s.filter(g=>!g.read).length,f=async g=>{g.length!==0&&(await Pa.markRead(g),await u())},h=()=>{const g=s.filter(y=>!y.read).map(y=>y.id);f(g)},m=async g=>{a(g),g.read||await f([g.id])};return d.jsxs(dt.div,{variants:wF,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:Vw,className:"flex items-center justify-between flex-wrap gap-3",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("div",{className:"relative",children:[d.jsx(Sl,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),l>0&&d.jsx("span",{className:"absolute -top-1.5 -right-1.5 bg-red-500 text-white text-[10px] font-bold rounded-full w-4 h-4 flex items-center justify-center leading-none",children:l>9?"9+":l})]}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Notifications"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-dim mt-0.5",children:"Webhook execution results from the Oracle agent."})]})]}),d.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[d.jsxs(Va,{to:"/webhooks",className:"flex items-center gap-2 text-sm text-azure-text-secondary dark:text-matrix-dim hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:[d.jsx(zT,{className:"w-4 h-4"}),"Back to Webhooks"]}),d.jsxs("button",{onClick:()=>t(!e),className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm transition-colors ${e?"border-azure-primary dark:border-matrix-highlight bg-azure-active dark:bg-matrix-primary/20 text-azure-primary dark:text-matrix-highlight":"border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-dim hover:bg-azure-surface dark:hover:bg-zinc-800"}`,children:[d.jsx(rA,{className:"w-4 h-4"}),"Unread only"]}),l>0&&d.jsxs("button",{onClick:h,className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-sm text-azure-text-secondary dark:text-matrix-dim hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:[d.jsx(LT,{className:"w-4 h-4"}),"Mark all read"]})]})]}),d.jsx(dt.div,{variants:Vw,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-hidden",children:d.jsx("div",{className:"overflow-x-auto",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["","Webhook","Status","Created","Completed","Actions"].map(g=>d.jsx("th",{className:"px-4 py-3 text-left font-semibold text-azure-text-secondary dark:text-matrix-dim",children:g},g))})}),d.jsx("tbody",{children:s.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:6,className:"px-4 py-10 text-center text-azure-text-secondary dark:text-matrix-dim",children:e?"No unread notifications.":"No notifications yet."})}):s.map(g=>d.jsxs("tr",{className:`border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-800/50 transition-colors ${g.read?"":"bg-blue-50/40 dark:bg-blue-900/10"}`,children:[d.jsx("td",{className:"px-4 py-3 w-6",children:!g.read&&d.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-blue-500 dark:bg-matrix-highlight"})}),d.jsx("td",{className:"px-4 py-3 font-mono font-medium text-azure-text-primary dark:text-matrix-text",children:g.webhook_name}),d.jsx("td",{className:"px-4 py-3",children:d.jsx(Bw,{status:g.status})}),d.jsx("td",{className:"px-4 py-3 text-xs text-azure-text-secondary dark:text-matrix-dim whitespace-nowrap",children:Nc(g.created_at)}),d.jsx("td",{className:"px-4 py-3 text-xs text-azure-text-secondary dark:text-matrix-dim whitespace-nowrap",children:g.completed_at?Nc(g.completed_at):"—"}),d.jsx("td",{className:"px-4 py-3",children:d.jsx("button",{onClick:()=>m(g),title:"View details",className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-dim hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(sd,{className:"w-4 h-4"})})})]},g.id))})]})})}),d.jsxs(Or,{open:!!n,onOpenChange:g=>!g&&a(null),children:[d.jsx(Rr,{children:d.jsxs(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight flex items-center gap-2",children:[d.jsx(Sl,{className:"w-4 h-4"}),n?.webhook_name]})}),n&&d.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto max-h-[65vh]",children:[d.jsxs("div",{className:"flex items-center gap-4 text-xs text-azure-text-secondary dark:text-matrix-dim",children:[d.jsx(Bw,{status:n.status}),d.jsx("span",{children:Nc(n.created_at)}),n.completed_at&&d.jsxs("span",{children:["→ ",Nc(n.completed_at)]})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-dim mb-1.5",children:"Received Payload"}),d.jsx("pre",{className:"bg-azure-bg dark:bg-zinc-950 rounded-lg p-3 text-xs font-mono overflow-auto max-h-44 text-azure-text-primary dark:text-matrix-text border border-azure-border dark:border-matrix-primary/30 whitespace-pre-wrap",children:SF(n.payload)})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-dim mb-1.5",children:"Agent Result"}),d.jsx("div",{className:"bg-azure-bg dark:bg-zinc-950 rounded-lg p-3 text-xs font-mono overflow-auto max-h-64 text-azure-text-primary dark:text-matrix-text border border-azure-border dark:border-matrix-primary/30 whitespace-pre-wrap",children:n.result??d.jsx("span",{className:"text-yellow-600 dark:text-yellow-400 animate-pulse",children:"Processing…"})})]}),d.jsx("div",{className:"flex justify-end pt-2",children:d.jsx("button",{onClick:()=>a(null),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-dim text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Close"})})]})]})]})},_F={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},Cc={hidden:{opacity:0,y:8},show:{opacity:1,y:0}},jF={pending:"Pending",running:"Running",completed:"Completed",failed:"Failed",cancelled:"Cancelled"};function NF({status:e}){return e==="completed"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600 dark:text-green-400",children:[d.jsx(mS,{className:"w-4 h-4"}),"Completed"]}):e==="failed"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-red-600 dark:text-red-400",children:[d.jsx(Hm,{className:"w-4 h-4"}),"Failed"]}):e==="running"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400",children:[d.jsx(hA,{className:"w-4 h-4 animate-spin"}),"Running"]}):e==="cancelled"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-zinc-500 dark:text-zinc-400",children:[d.jsx(Hm,{className:"w-4 h-4"}),"Cancelled"]}):d.jsxs("span",{className:"inline-flex items-center gap-1 text-yellow-600 dark:text-yellow-400",children:[d.jsx(Za,{className:"w-4 h-4"}),"Pending"]})}const Zw=e=>e?new Date(e).toLocaleString():"—";function CF(){const[e,t]=z.useState(""),[n,a]=z.useState(""),[s,u]=z.useState(""),[l,f]=z.useState(""),[h,m]=z.useState(null),g=z.useMemo(()=>({status:e||void 0,agent:n||void 0,origin_channel:s||void 0,session_id:l.trim()||void 0,limit:200}),[e,n,s,l]),{data:y}=zt("/tasks/stats",()=>Ns.stats(),{refreshInterval:5e3}),{data:v=[],mutate:b}=zt(["/tasks",g],()=>Ns.list(g),{refreshInterval:3e3});return d.jsxs(dt.div,{variants:_F,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:Cc,className:"flex items-center gap-3",children:[d.jsx(Fm,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Tasks"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-dim",children:"Async tasks delegated by Oracle and processed by workers."})]})]}),d.jsxs(dt.div,{variants:Cc,className:"grid grid-cols-2 md:grid-cols-6 gap-3",children:[d.jsx(js,{label:"Pending",value:y?.pending??0}),d.jsx(js,{label:"Running",value:y?.running??0}),d.jsx(js,{label:"Completed",value:y?.completed??0}),d.jsx(js,{label:"Failed",value:y?.failed??0}),d.jsx(js,{label:"Cancelled",value:y?.cancelled??0}),d.jsx(js,{label:"Total",value:y?.total??0})]}),d.jsxs(dt.div,{variants:Cc,className:"rounded-lg border border-azure-border dark:border-matrix-primary p-4 bg-azure-surface dark:bg-zinc-950 grid grid-cols-1 md:grid-cols-4 gap-3",children:[d.jsxs("select",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:e,onChange:S=>t(S.target.value||""),children:[d.jsx("option",{value:"",children:"All status"}),Object.entries(jF).map(([S,j])=>d.jsx("option",{value:S,children:j},S))]}),d.jsxs("select",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:n,onChange:S=>a(S.target.value||""),children:[d.jsx("option",{value:"",children:"All agents"}),d.jsx("option",{value:"apoc",children:"Apoc"}),d.jsx("option",{value:"neo",children:"Neo"})]}),d.jsxs("select",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:s,onChange:S=>u(S.target.value||""),children:[d.jsx("option",{value:"",children:"All channels"}),d.jsx("option",{value:"telegram",children:"Telegram"}),d.jsx("option",{value:"ui",children:"UI"}),d.jsx("option",{value:"api",children:"API"}),d.jsx("option",{value:"webhook",children:"Webhook"}),d.jsx("option",{value:"cli",children:"CLI"})]}),d.jsx("input",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:l,onChange:S=>f(S.target.value),placeholder:"Filter by session id"})]}),d.jsx(dt.div,{variants:Cc,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-x-auto",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["Task ID","Status","Agent","Channel","Session","Attempts","Created","Finished","Actions"].map(S=>d.jsx("th",{className:"text-left px-4 py-3 font-semibold text-azure-text-secondary dark:text-matrix-dim",children:S},S))})}),d.jsx("tbody",{children:v.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:9,className:"px-4 py-10 text-center text-azure-text-secondary dark:text-matrix-dim",children:"No tasks found."})}):v.map(S=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-900/40 transition-colors",children:[d.jsx("td",{className:"px-4 py-3 font-mono",children:S.id.slice(0,8)}),d.jsx("td",{className:"px-4 py-3",children:d.jsx(NF,{status:S.status})}),d.jsx("td",{className:"px-4 py-3",children:S.agent.toUpperCase()}),d.jsx("td",{className:"px-4 py-3",children:S.origin_channel.toUpperCase()}),d.jsx("td",{className:"px-4 py-3 font-mono",children:S.session_id}),d.jsxs("td",{className:"px-4 py-3",children:[S.attempt_count,"/",S.max_attempts]}),d.jsx("td",{className:"px-4 py-3",children:Zw(S.created_at)}),d.jsx("td",{className:"px-4 py-3",children:Zw(S.finished_at)}),d.jsxs("td",{className:"px-4 py-3 flex items-center gap-1",children:[d.jsx("button",{onClick:()=>m(S),className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-dim",children:d.jsx(sd,{className:"w-4 h-4"})}),(S.status==="pending"||S.status==="running")&&d.jsx("button",{onClick:async()=>{await Ns.cancel(S.id),await b()},title:"Cancel task",className:"p-1.5 rounded hover:bg-red-100 dark:hover:bg-red-900/30 text-red-500 dark:text-red-400",children:d.jsx(NT,{className:"w-4 h-4"})})]})]},S.id))})]})}),d.jsxs(Or,{open:!!h,onOpenChange:S=>!S&&m(null),children:[d.jsx(Rr,{children:d.jsx(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight",children:"Task Details"})}),h&&d.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto max-h-[70vh] text-sm",children:[d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2 text-azure-text-secondary dark:text-matrix-dim",children:[d.jsxs("div",{children:[d.jsx("b",{children:"ID:"})," ",d.jsx("span",{className:"font-mono",children:h.id})]}),d.jsxs("div",{children:[d.jsx("b",{children:"Status:"})," ",h.status]}),d.jsxs("div",{children:[d.jsx("b",{children:"Agent:"})," ",h.agent]}),d.jsxs("div",{children:[d.jsx("b",{children:"Origin:"})," ",h.origin_channel]}),d.jsxs("div",{children:[d.jsx("b",{children:"Session:"})," ",d.jsx("span",{className:"font-mono",children:h.session_id})]}),d.jsxs("div",{children:[d.jsx("b",{children:"Attempts:"})," ",h.attempt_count,"/",h.max_attempts]})]}),d.jsxs("section",{children:[d.jsx("p",{className:"font-medium mb-1",children:"Input"}),d.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded-lg border border-azure-border dark:border-matrix-primary/30 p-3 bg-azure-bg dark:bg-zinc-950",children:h.input})]}),h.output&&d.jsxs("section",{children:[d.jsx("p",{className:"font-medium mb-1",children:"Output"}),d.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded-lg border border-azure-border dark:border-matrix-primary/30 p-3 bg-azure-bg dark:bg-zinc-950",children:h.output})]}),h.error&&d.jsxs("section",{children:[d.jsx("p",{className:"font-medium mb-1 text-red-600 dark:text-red-400",children:"Error"}),d.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded-lg border border-red-200 dark:border-red-900/50 p-3 bg-red-50 dark:bg-red-950/40",children:h.error})]}),(h.status==="failed"||h.status==="pending"||h.status==="running")&&d.jsxs("div",{className:"flex justify-end gap-2",children:[(h.status==="pending"||h.status==="running")&&d.jsx("button",{onClick:async()=>{await Ns.cancel(h.id),m(null),await b()},className:"px-4 py-2 rounded-lg border border-red-400 dark:border-red-500 text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 text-sm",children:"Cancel Task"}),h.status==="failed"&&d.jsx("button",{onClick:async()=>{await Ns.retry(h.id),m(null),await b()},className:"px-4 py-2 rounded-lg bg-azure-primary text-white dark:bg-matrix-highlight dark:text-black text-sm",children:"Retry Task"})]})]})]})]})}function js({label:e,value:t}){return d.jsxs("div",{className:"rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-950 px-4 py-3",children:[d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-dim",children:e}),d.jsx("p",{className:"text-xl font-semibold text-azure-text-primary dark:text-matrix-highlight",children:t})]})}const Um={postgresql:5432,mysql:3306,mongodb:27017,sqlite:0},Iw={name:"",type:"postgresql",host:"",port:"",database_name:"",username:"",password:"",connection_string:"",allow_read:!0,allow_insert:!1,allow_update:!1,allow_delete:!1,allow_ddl:!1},EF={postgresql:[{key:"allow_read",label:"SELECT",description:"Permite consultas SELECT"},{key:"allow_insert",label:"INSERT",description:"Permite inserir registros"},{key:"allow_update",label:"UPDATE",description:"Permite atualizar registros"},{key:"allow_delete",label:"DELETE",description:"Permite excluir registros"},{key:"allow_ddl",label:"DDL",description:"CREATE / ALTER / DROP TABLE"}],mysql:[{key:"allow_read",label:"SELECT",description:"Permite consultas SELECT"},{key:"allow_insert",label:"INSERT",description:"Permite inserir registros"},{key:"allow_update",label:"UPDATE",description:"Permite atualizar registros"},{key:"allow_delete",label:"DELETE",description:"Permite excluir registros"},{key:"allow_ddl",label:"DDL",description:"CREATE / ALTER / DROP TABLE"}],sqlite:[{key:"allow_read",label:"SELECT",description:"Permite consultas SELECT"},{key:"allow_insert",label:"INSERT",description:"Permite inserir registros"},{key:"allow_update",label:"UPDATE",description:"Permite atualizar registros"},{key:"allow_delete",label:"DELETE",description:"Permite excluir registros"},{key:"allow_ddl",label:"DDL",description:"CREATE / ALTER / DROP TABLE"}],mongodb:[{key:"allow_read",label:"find / aggregate",description:"Permite consultas e agregações"},{key:"allow_insert",label:"insertOne / insertMany",description:"Permite inserir documentos"},{key:"allow_update",label:"updateOne / updateMany",description:"Permite atualizar documentos"},{key:"allow_delete",label:"deleteOne / deleteMany",description:"Permite excluir documentos"},{key:"allow_ddl",label:"Schema changes",description:"createCollection / dropCollection / createIndex"}]};async function TF(){return xe.get("/trinity/databases")}function AF(){const{data:e,error:t}=zt("/trinity/databases",TF,{refreshInterval:3e4}),[n,a]=z.useState(!1),[s,u]=z.useState(null),[l,f]=z.useState(Iw),[h,m]=z.useState(!1),[g,y]=z.useState(null),[v,b]=z.useState({}),[S,j]=z.useState(null),[A,E]=z.useState({}),[O,N]=z.useState(null),[L,D]=z.useState(null),[R,q]=z.useState(null),[V,X]=z.useState(!1),fe=()=>{u(null),f(Iw),X(!1),y(null),a(!0)},se=w=>{u(w),f({name:w.name,type:w.type,host:w.host||"",port:w.port?String(w.port):"",database_name:w.database_name||"",username:w.username||"",password:"",connection_string:"",allow_read:w.allow_read,allow_insert:w.allow_insert,allow_update:w.allow_update,allow_delete:w.allow_delete,allow_ddl:w.allow_ddl}),X(!!w.connection_string),y(null),a(!0)},le=async()=>{if(m(!0),y(null),!V&&!l.database_name.trim()){y(l.type==="sqlite"?"File path is required.":"Database name is required."),m(!1);return}try{const w={name:l.name,type:l.type,allow_read:l.allow_read,allow_insert:l.allow_insert,allow_update:l.allow_update,allow_delete:l.allow_delete,allow_ddl:l.allow_ddl};V?(!s||l.connection_string)&&(w.connection_string=l.connection_string||null):(w.host=l.host||null,w.port=l.port?parseInt(l.port):null,w.database_name=l.database_name||null,w.username=l.username||null,(!s||l.password)&&(w.password=l.password||null)),s?await xe.put(`/trinity/databases/${s.id}`,w):await xe.post("/trinity/databases",w),await On("/trinity/databases"),a(!1)}catch(w){y(w.message||"Failed to save database")}finally{m(!1)}},ee=w=>{q(w)},oe=async()=>{if(!R)return;const w=R.id;D(w);try{await xe.delete(`/trinity/databases/${w}`),await On("/trinity/databases")}catch(Y){alert(`Delete failed: ${Y.message}`)}finally{D(null),q(null)}},ae=async w=>{j(w);try{const Y=await xe.post(`/trinity/databases/${w}/test`,{});E(de=>({...de,[w]:Y.success}))}catch{E(Y=>({...Y,[w]:!1}))}finally{j(null)}},P=async w=>{N(w);try{await xe.post(`/trinity/databases/${w}/refresh-schema`,{}),await On("/trinity/databases")}catch(Y){alert(`Schema refresh failed: ${Y.message}`)}finally{N(null)}},J=w=>{b(Y=>({...Y,[w]:!Y[w]}))},B=w=>{w!=="mongodb"&&X(!1),f(Y=>({...Y,type:w,port:Um[w]?String(Um[w]):""}))},me=w=>{f(Y=>({...Y,[w]:!Y[w]}))};if(t)return d.jsxs("div",{className:"p-8 text-red-500",children:["Failed to load databases: ",t.message]});const T="w-full px-3 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded text-azure-text-primary dark:text-matrix-secondary font-mono text-sm focus:outline-none focus:border-azure-primary dark:focus:border-matrix-highlight",C="block text-xs font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",I=w=>[{key:"allow_read",badge:"R"},{key:"allow_insert",badge:"I"},{key:"allow_update",badge:"U"},{key:"allow_delete",badge:"D"},{key:"allow_ddl",badge:"DDL"}].filter(de=>w[de.key]).map(de=>de.badge);return d.jsxs("div",{className:"max-w-5xl mx-auto space-y-6",children:[d.jsxs("div",{className:"flex justify-between items-center",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx($s,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsx("h1",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"Trinity Databases"})]}),d.jsxs("button",{onClick:fe,className:"flex items-center gap-2 px-4 py-2 bg-azure-primary text-white rounded hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90 transition-colors text-sm font-medium",children:[d.jsx(od,{className:"w-4 h-4"}),"Register Database"]})]}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:"Register databases for Trinity to access. Configure permissions to control what operations Trinity can perform on each database."}),e?e.length===0?d.jsxs("div",{className:"border border-azure-border dark:border-matrix-primary rounded p-8 text-center text-azure-text-secondary dark:text-matrix-secondary",children:[d.jsx($s,{className:"w-10 h-10 mx-auto mb-3 opacity-40"}),d.jsx("p",{className:"font-medium",children:"No databases registered"}),d.jsx("p",{className:"text-sm mt-1 opacity-70",children:'Click "Register Database" to add your first database.'})]}):d.jsx("div",{className:"space-y-4",children:e.map(w=>{const Y=w.schema_json?JSON.parse(w.schema_json):null,de=!!Y?.databases,he=de?Y.databases.reduce((Ne,qe)=>Ne+qe.tables.length,0):Y?.tables?.length??0,pe=de?Y.databases.length:0,Pe=w.type==="mongodb"?"collection":"table",Ae=w.type==="mongodb"?"collections":"tables",pt=A[w.id],Rt=v[w.id],Z=I(w);return d.jsxs("div",{className:"border border-azure-border dark:border-matrix-primary rounded-lg overflow-hidden",children:[d.jsxs("div",{className:"bg-azure-surface dark:bg-black/50 px-4 py-3 flex items-center gap-3",children:[d.jsx($s,{className:"w-5 h-5 text-azure-primary dark:text-matrix-highlight flex-shrink-0"}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[d.jsx("span",{className:"font-bold text-azure-text-primary dark:text-matrix-highlight truncate",children:w.name}),d.jsx("span",{className:"text-xs px-2 py-0.5 rounded border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary uppercase flex-shrink-0",children:w.type}),pt===!0&&d.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500",children:[d.jsx(Fh,{className:"w-3 h-3"})," Connected"]}),pt===!1&&d.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[d.jsx(QA,{className:"w-3 h-3"})," Failed"]}),Z.length>0&&d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(A0,{className:"w-3 h-3 text-azure-text-secondary dark:text-matrix-secondary opacity-60"}),Z.map(Ne=>d.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-azure-primary/10 dark:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight font-mono",children:Ne},Ne))]})]}),d.jsxs("div",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary truncate mt-0.5",children:[w.host?`${w.host}:${w.port}${w.database_name?`/${w.database_name}`:""}`:w.database_name||"connection string configured",de&&pe>0&&d.jsxs("span",{className:"ml-2 opacity-70",children:["· ",pe," database",pe!==1?"s":""," · ",he," ",he!==1?Ae:Pe]}),!de&&he>0&&d.jsxs("span",{className:"ml-2 opacity-70",children:["· ",he," ",he!==1?Ae:Pe]}),w.schema_updated_at&&d.jsxs("span",{className:"ml-2 opacity-50",children:["· schema ",new Date(w.schema_updated_at).toLocaleDateString()]})]})]}),d.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[d.jsx("button",{onClick:()=>ae(w.id),disabled:S===w.id,title:"Test connection",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors",children:S===w.id?d.jsx(Fh,{className:"w-4 h-4 animate-pulse"}):d.jsx(Fh,{className:"w-4 h-4"})}),d.jsx("button",{onClick:()=>P(w.id),disabled:O===w.id,title:"Refresh schema",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors",children:d.jsx(xS,{className:`w-4 h-4 ${O===w.id?"animate-spin":""}`})}),d.jsx("button",{onClick:()=>se(w),title:"Edit",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors text-xs font-medium px-2",children:"Edit"}),d.jsx("button",{onClick:()=>ee(w),disabled:L===w.id,title:"Delete",className:"p-1.5 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-red-500 transition-colors",children:d.jsx(Ti,{className:"w-4 h-4"})}),Y&&d.jsx("button",{onClick:()=>J(w.id),title:Rt?"Hide schema":"Show schema",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors",children:Rt?d.jsx(VT,{className:"w-4 h-4"}):d.jsx(ZT,{className:"w-4 h-4"})})]})]}),Rt&&Y&&d.jsxs("div",{className:"border-t border-azure-border dark:border-matrix-primary px-4 py-3 bg-azure-bg dark:bg-black/20",children:[d.jsx("div",{className:"text-xs font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:de?`${pe} database${pe!==1?"s":""} — ${he} ${he!==1?Ae:Pe} total`:`Schema — ${he} ${he!==1?Ae:Pe}`}),d.jsx("div",{className:"space-y-2 max-h-72 overflow-y-auto",children:de?Y.databases?.map(Ne=>d.jsxs("div",{className:"text-xs",children:[d.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[d.jsx("span",{className:"font-bold text-azure-primary dark:text-matrix-highlight",children:Ne.name}),d.jsxs("span",{className:"opacity-40 text-azure-text-secondary dark:text-matrix-secondary",children:["(",Ne.tables.length," ",Ne.tables.length!==1?Ae:Pe,")"]})]}),d.jsxs("div",{className:"pl-3 space-y-1.5 border-l border-azure-border dark:border-matrix-primary/40 ml-1",children:[Ne.tables.map(qe=>d.jsxs("div",{children:[d.jsx("div",{className:"font-semibold text-azure-text-primary dark:text-matrix-secondary mb-0.5",children:qe.name}),d.jsx("div",{className:"pl-3 space-y-0.5",children:qe.columns?.map(Lt=>d.jsxs("div",{className:"text-azure-text-secondary dark:text-matrix-secondary font-mono",children:[d.jsx("span",{children:Lt.name}),d.jsx("span",{className:"opacity-50 ml-2",children:Lt.type}),Lt.nullable===!1&&d.jsx("span",{className:"ml-1 opacity-40",children:"NOT NULL"})]},Lt.name))})]},qe.name)),Ne.tables.length===0&&d.jsxs("div",{className:"text-azure-text-secondary dark:text-matrix-secondary opacity-50 italic",children:["no ",Ae]})]})]},Ne.name)):Y.tables?.map(Ne=>d.jsxs("div",{className:"text-xs",children:[d.jsx("div",{className:"font-bold text-azure-primary dark:text-matrix-highlight mb-1",children:Ne.name}),d.jsx("div",{className:"pl-3 space-y-0.5",children:Ne.columns?.map(qe=>d.jsxs("div",{className:"text-azure-text-secondary dark:text-matrix-secondary font-mono",children:[d.jsx("span",{className:"text-azure-text-primary dark:text-matrix-secondary",children:qe.name}),d.jsx("span",{className:"opacity-50 ml-2",children:qe.type}),qe.nullable===!1&&d.jsx("span",{className:"ml-1 opacity-40 text-xs",children:"NOT NULL"})]},qe.name))})]},Ne.name))})]})]},w.id)})}):d.jsx("div",{className:"text-azure-text-secondary dark:text-matrix-secondary",children:"Loading..."}),d.jsx(G_,{isOpen:!!R,onClose:()=>q(null),onConfirm:oe,title:"Delete database",description:`Remove "${R?.name}" from Trinity? The database itself won't be affected — only this registration will be deleted.`,confirmJson:"Delete",variant:"destructive"}),n&&d.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[d.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>a(!1)}),d.jsxs("div",{className:"relative bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-lg shadow-xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:[d.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-azure-border dark:border-matrix-primary",children:[d.jsx("h2",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight",children:s?"Edit Database":"Register Database"}),d.jsx("button",{onClick:()=>a(!1),className:"text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-text-primary dark:hover:text-matrix-highlight",children:d.jsx(eg,{className:"w-5 h-5"})})]}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Name *"}),d.jsx("input",{className:T,value:l.name,onChange:w=>f(Y=>({...Y,name:w.target.value})),placeholder:"My Production DB"})]}),d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Type *"}),d.jsxs("select",{className:T,value:l.type,onChange:w=>B(w.target.value),children:[d.jsx("option",{value:"postgresql",children:"PostgreSQL"}),d.jsx("option",{value:"mysql",children:"MySQL / MariaDB"}),d.jsx("option",{value:"sqlite",children:"SQLite"}),d.jsx("option",{value:"mongodb",children:"MongoDB"})]})]}),l.type==="mongodb"&&d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx("button",{type:"button",onClick:()=>X(!1),className:`text-xs px-3 py-1.5 rounded border transition-colors ${V?"border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary":"border-azure-primary dark:border-matrix-highlight bg-azure-primary/10 dark:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight"}`,children:"Individual fields"}),d.jsx("button",{type:"button",onClick:()=>X(!0),className:`text-xs px-3 py-1.5 rounded border transition-colors ${V?"border-azure-primary dark:border-matrix-highlight bg-azure-primary/10 dark:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight":"border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary"}`,children:"Connection string"})]}),l.type==="mongodb"&&V?d.jsxs("div",{children:[d.jsxs("label",{className:C,children:["Connection String ",s&&d.jsx("span",{className:"opacity-60",children:"(leave blank to keep existing)"})]}),d.jsx("input",{className:T,type:"password",value:l.connection_string,onChange:w=>f(Y=>({...Y,connection_string:w.target.value})),placeholder:s?"unchanged":"mongodb://user:pass@host:27017/dbname"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Stored encrypted with AES-256-GCM. Requires MORPHEUS_SECRET env var."})]}):d.jsxs(d.Fragment,{children:[l.type!=="sqlite"&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Host"}),d.jsx("input",{className:T,value:l.host,onChange:w=>f(Y=>({...Y,host:w.target.value})),placeholder:"localhost"})]}),d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Port"}),d.jsx("input",{className:T,type:"number",value:l.port,onChange:w=>f(Y=>({...Y,port:w.target.value})),placeholder:String(Um[l.type]||"")})]})]}),d.jsxs("div",{children:[d.jsxs("label",{className:C,children:[l.type==="sqlite"?"File Path":"Database Name"," *"]}),d.jsx("input",{className:`w-full px-3 py-2 bg-azure-surface dark:bg-black border rounded text-azure-text-primary dark:text-matrix-secondary font-mono text-sm focus:outline-none ${g&&!l.database_name.trim()?"border-red-500 dark:border-red-500":"border-azure-border dark:border-matrix-primary focus:border-azure-primary dark:focus:border-matrix-highlight"}`,value:l.database_name,onChange:w=>f(Y=>({...Y,database_name:w.target.value})),placeholder:l.type==="sqlite"?"/path/to/database.db":"mydb"})]}),l.type!=="sqlite"&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Username"}),d.jsx("input",{className:T,value:l.username,onChange:w=>f(Y=>({...Y,username:w.target.value})),placeholder:"postgres"})]}),d.jsxs("div",{children:[d.jsxs("label",{className:C,children:["Password ",s&&d.jsx("span",{className:"opacity-60",children:"(leave blank to keep existing)"})]}),d.jsx("input",{className:T,type:"password",value:l.password,onChange:w=>f(Y=>({...Y,password:w.target.value})),placeholder:s?"unchanged":"••••••••"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Stored encrypted with AES-256-GCM. Requires MORPHEUS_SECRET env var."})]})]})]}),d.jsxs("div",{className:"border-t border-azure-border dark:border-matrix-primary pt-4",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[d.jsx(A0,{className:"w-4 h-4 text-azure-primary dark:text-matrix-highlight"}),d.jsx("span",{className:"text-sm font-medium text-azure-text-primary dark:text-matrix-highlight",children:"Permissões"})]}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mb-3",children:"Defina quais operações Trinity pode executar neste banco. Operações não permitidas retornarão erro de permissão."}),d.jsx("div",{className:"space-y-2",children:EF[l.type]?.map(({key:w,label:Y,description:de})=>d.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[d.jsxs("div",{className:"relative mt-0.5 flex-shrink-0",children:[d.jsx("input",{type:"checkbox",checked:!!l[w],onChange:()=>me(w),className:"sr-only"}),d.jsx("div",{className:`w-4 h-4 rounded border transition-colors flex items-center justify-center ${l[w]?"bg-azure-primary dark:bg-matrix-highlight border-azure-primary dark:border-matrix-highlight":"border-azure-border dark:border-matrix-primary bg-transparent"}`,children:l[w]&&d.jsx("svg",{className:"w-2.5 h-2.5 text-white dark:text-black",fill:"none",viewBox:"0 0 10 10",children:d.jsx("path",{d:"M1.5 5l2.5 2.5L8.5 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),d.jsxs("div",{children:[d.jsx("span",{className:"text-sm text-azure-text-primary dark:text-matrix-secondary font-mono",children:Y}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary opacity-70",children:de})]})]},w))})]}),g&&d.jsx("div",{className:"text-sm text-red-500 border border-red-500/30 bg-red-500/10 rounded px-3 py-2",children:g})]}),d.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-azure-border dark:border-matrix-primary",children:[d.jsx("button",{onClick:()=>a(!1),className:"px-4 py-2 text-sm text-azure-text-secondary dark:text-matrix-secondary border border-azure-border dark:border-matrix-primary rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:le,disabled:h||!l.name,className:"px-4 py-2 text-sm font-medium bg-azure-primary text-white rounded hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90 transition-colors disabled:opacity-50",children:h?"Saving...":s?"Update":"Register"})]})]})]})]})}const OF={running:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",success:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",failed:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",timeout:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"};function RF({jobId:e}){const{data:t,isLoading:n}=KL(e,50);return n?d.jsx("div",{className:"p-4 dark:bg-zinc-900 rounded text-sm dark:text-matrix-secondary animate-pulse",children:"Loading history…"}):!t||t.length===0?d.jsx("div",{className:"p-4 dark:bg-zinc-900 rounded text-sm dark:text-matrix-secondary italic",children:"No executions yet."}):d.jsx("div",{className:"rounded border border-azure-border dark:border-matrix-primary dark:bg-zinc-900 overflow-hidden",children:d.jsxs("table",{className:"w-full text-xs font-mono",children:[d.jsx("thead",{children:d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary",children:[d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Triggered At"}),d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Completed At"}),d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Status"}),d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Error"})]})}),d.jsx("tbody",{children:t.map(a=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 last:border-0",children:[d.jsx("td",{className:"px-3 py-2 dark:text-matrix-secondary",children:new Date(a.triggered_at).toLocaleString()}),d.jsx("td",{className:"px-3 py-2 dark:text-matrix-secondary",children:a.completed_at?new Date(a.completed_at).toLocaleString():"—"}),d.jsx("td",{className:"px-3 py-2",children:d.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${OF[a.status]}`,children:a.status})}),d.jsx("td",{className:"px-3 py-2 dark:text-red-400 max-w-xs truncate",children:a.error??"—"})]},a.id))})]})})}function MF({enabled:e}){return d.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-bold uppercase ${e?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-zinc-800 dark:text-matrix-tertiary"}`,children:e?"Enabled":"Disabled"})}function Hw(e,t){return e.length>t?`${e.slice(0,t)}…`:e}function Fw(e){return e?new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function DF({onEdit:e}){const{data:t,isLoading:n}=YL(),[a,s]=z.useState(null),[u,l]=z.useState(null),[f,h]=z.useState(null),m=async y=>{l(y.id);try{y.enabled?await Ei.disableJob(y.id):await Ei.enableJob(y.id),await On(v=>typeof v=="string"&&v.startsWith("/chronos"))}finally{l(null)}},g=async()=>{if(f){l(f.id);try{await Ei.deleteJob(f.id),await On(y=>typeof y=="string"&&y.startsWith("/chronos"))}finally{l(null),h(null)}}};return n?d.jsx("div",{className:"rounded border border-azure-border dark:border-matrix-primary p-8 text-center dark:text-matrix-secondary animate-pulse",children:"Loading jobs…"}):!t||t.length===0?d.jsxs("div",{className:"rounded border border-azure-border dark:border-matrix-primary p-8 text-center dark:text-matrix-secondary",children:["No Chronos jobs yet. Click ",d.jsx("strong",{className:"dark:text-matrix-highlight",children:"New Job"})," to get started."]}):d.jsxs("div",{className:"rounded border border-azure-border dark:border-matrix-primary overflow-hidden",children:[d.jsxs("table",{className:"w-full text-sm font-mono",children:[d.jsx("thead",{children:d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-900",children:[d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium",children:"Prompt"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden md:table-cell",children:"Schedule"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden lg:table-cell",children:"Next Run"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden lg:table-cell",children:"Last Run"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium",children:"Status"}),d.jsx("th",{className:"px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium text-right",children:"Actions"})]})}),d.jsx("tbody",{children:t.map(y=>d.jsxs(d.Fragment,{children:[d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 last:border-0 hover:bg-azure-hover dark:hover:bg-matrix-primary/10 transition-colors",children:[d.jsxs("td",{className:"px-4 py-3 dark:text-matrix-secondary max-w-xs",children:[d.jsx("span",{title:y.prompt,children:Hw(y.prompt,50)}),d.jsx("div",{className:"text-xs text-azure-text-muted dark:text-matrix-tertiary",children:y.created_by})]}),d.jsxs("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden md:table-cell text-xs",children:[d.jsx("div",{className:"capitalize",children:y.schedule_type}),d.jsx("div",{className:"text-azure-text-muted dark:text-matrix-tertiary truncate max-w-[140px]",title:y.schedule_expression,children:y.schedule_expression})]}),d.jsx("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden lg:table-cell text-xs",children:Fw(y.next_run_at)}),d.jsx("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden lg:table-cell text-xs",children:Fw(y.last_run_at)}),d.jsx("td",{className:"px-4 py-3",children:d.jsx(MF,{enabled:y.enabled})}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center justify-end gap-1",children:[d.jsx("button",{title:a===y.id?"Hide history":"View history",onClick:()=>s(a===y.id?null:y.id),className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors",children:a===y.id?d.jsx(HT,{className:"w-4 h-4"}):d.jsx(oA,{className:"w-4 h-4"})}),d.jsx("button",{title:"Edit",onClick:()=>e(y),className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors",children:d.jsx(SA,{className:"w-4 h-4"})}),d.jsx("button",{title:y.enabled?"Disable":"Enable",onClick:()=>m(y),disabled:u===y.id,className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors disabled:opacity-40",children:y.enabled?d.jsx(kA,{className:"w-4 h-4"}):d.jsx(jA,{className:"w-4 h-4"})}),d.jsx("button",{title:"Delete",onClick:()=>h(y),disabled:u===y.id,className:"p-1.5 rounded text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-40",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},y.id),a===y.id&&d.jsx("tr",{className:"bg-azure-surface dark:bg-zinc-900/50",children:d.jsxs("td",{colSpan:6,className:"px-4 py-3",children:[d.jsx("div",{className:"text-xs font-bold dark:text-matrix-highlight mb-2",children:"Execution History"}),d.jsx(RF,{jobId:y.id})]})},`${y.id}-history`)]}))})]}),d.jsx(m2,{isOpen:!!f,onClose:()=>h(null),onConfirm:g,title:"Delete Chronos Job",message:f?`Delete job "${Hw(f.prompt,60)}"? This action cannot be undone.`:""})]})}function $F({scheduleExpression:e,scheduleType:t,timezone:n}){const[a,s]=z.useState(null),[u,l]=z.useState(null),f=z.useRef(null);return z.useEffect(()=>{if(!e.trim()){s(null),l(null);return}return f.current&&clearTimeout(f.current),f.current=setTimeout(async()=>{try{const h=await Ei.preview(e,t,n);s(h),l(null)}catch(h){l(h.message??"Invalid expression"),s(null)}},500),()=>{f.current&&clearTimeout(f.current)}},[e,t,n]),e.trim()?d.jsx("div",{className:"mt-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-900 p-3 text-sm",children:u?d.jsxs("p",{className:"text-red-500 dark:text-red-400 flex items-center gap-1.5",children:[d.jsx("span",{children:"⚠"})," ",u]}):a?d.jsxs("div",{className:"space-y-1",children:[d.jsxs("div",{className:"flex items-center gap-1.5 text-azure-text-secondary dark:text-matrix-secondary",children:[d.jsx(Za,{className:"w-3.5 h-3.5 text-azure-primary dark:text-matrix-highlight shrink-0"}),d.jsx("span",{className:"font-medium dark:text-matrix-highlight",children:"Next run:"}),d.jsx("span",{children:new Date(a.next_run_at).toLocaleString()})]}),a.human_readable&&d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary/70 pl-5",children:a.human_readable}),a.next_occurrences.length>0&&d.jsx("div",{className:"pl-5 space-y-0.5",children:a.next_occurrences.map((h,m)=>d.jsxs("p",{className:"text-azure-text-muted dark:text-matrix-tertiary text-xs",children:["#",m+2,": ",h]},m))})]}):d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-tertiary italic",children:"Parsing…"})}):null}const LF=["UTC","America/Sao_Paulo","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Mexico_City","America/Buenos_Aires","America/Bogota","America/Lima","America/Santiago","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Lisbon","Europe/Moscow","Europe/Istanbul","Asia/Dubai","Asia/Kolkata","Asia/Bangkok","Asia/Singapore","Asia/Tokyo","Asia/Shanghai","Asia/Seoul","Asia/Jakarta","Australia/Sydney","Australia/Melbourne","Pacific/Auckland","Africa/Cairo","Africa/Johannesburg","Africa/Lagos"],PF=[{value:"telegram",label:"Telegram"},{value:"discord",label:"Discord"}],UF=[{value:"once",label:"Once"},{value:"cron",label:"Recurring (Cron)"},{value:"interval",label:"Recurring (Interval)"}],VF={once:'e.g. "in 30 minutes", "tomorrow at 9am", "2026-03-01T09:00:00"',cron:'e.g. "0 9 * * 1-5" (weekdays at 9am)',interval:'e.g. "every 30 minutes", "every sunday at 9am", "every weekday"'};function BF({isOpen:e,onClose:t,onCreated:n,editJob:a}){const s=!!a,{data:u}=Y_(),[l,f]=z.useState(""),[h,m]=z.useState("once"),[g,y]=z.useState(""),[v,b]=z.useState("UTC"),[S,j]=z.useState([]),[A,E]=z.useState(null),[O,N]=z.useState(!1),L=R=>{j(q=>q.includes(R)?q.filter(V=>V!==R):[...q,R])};z.useEffect(()=>{a?(f(a.prompt),m(a.schedule_type),y(a.schedule_expression),b(a.timezone),j(a.notify_channels??[])):(f(""),m("once"),y(""),b(u?.timezone??"UTC"),j([])),E(null)},[a,e,u?.timezone]);const D=async()=>{if(E(null),!l.trim()){E("Prompt is required");return}if(!g.trim()){E("Schedule expression is required");return}N(!0);try{if(s&&a){const R={prompt:l,schedule_expression:g,timezone:v,notify_channels:S};await Ei.updateJob(a.id,R)}else{const R={prompt:l,schedule_type:h,schedule_expression:g,timezone:v,notify_channels:S};await Ei.createJob(R)}await On(R=>typeof R=="string"&&R.startsWith("/chronos")),n(),t()}catch(R){E(R.message??"Failed to save job")}finally{N(!1)}};return e?d.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[d.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),d.jsxs("div",{className:"relative z-10 w-full max-w-lg mx-4 rounded-lg border border-azure-border dark:border-matrix-primary bg-white dark:bg-black shadow-xl",children:[d.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-azure-border dark:border-matrix-primary",children:[d.jsx("h2",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight font-mono",children:s?"Edit Chronos Job":"New Chronos Job"}),d.jsx("button",{onClick:t,className:"p-1 rounded text-azure-text-muted dark:text-matrix-tertiary hover:text-azure-text-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(eg,{className:"w-5 h-5"})})]}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsx(lt,{label:"Prompt",value:l,onChange:R=>f(R.target.value),placeholder:"What should the Oracle do when this job triggers?"}),!s&&d.jsx(jr,{label:"Schedule Type",value:h,onChange:R=>m(R.target.value),options:UF}),d.jsxs("div",{children:[d.jsx(lt,{label:"Schedule Expression",value:g,onChange:R=>y(R.target.value),placeholder:VF[h]}),d.jsx($F,{scheduleExpression:g,scheduleType:h,timezone:v})]}),d.jsx(jr,{label:"Timezone",value:v,onChange:R=>b(R.target.value),options:LF.map(R=>({value:R,label:R}))}),d.jsxs("div",{children:[d.jsxs("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:["Notify Channels ",d.jsx("span",{className:"text-xs font-normal opacity-60",children:"(empty = all active channels)"})]}),d.jsx("div",{className:"flex gap-4",children:PF.map(({value:R,label:q})=>d.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[d.jsx("input",{type:"checkbox",checked:S.includes(R),onChange:()=>L(R),className:"rounded border-azure-border dark:border-matrix-primary accent-azure-primary dark:accent-matrix-highlight"}),d.jsx("span",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary capitalize",children:q})]},R))})]}),A&&d.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:A})]}),d.jsxs("div",{className:"flex justify-end gap-3 p-4 border-t border-azure-border dark:border-matrix-primary",children:[d.jsx("button",{onClick:t,className:"px-4 py-2 rounded text-sm border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors font-mono",children:"Cancel"}),d.jsx("button",{onClick:D,disabled:O,className:"px-4 py-2 rounded text-sm bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight font-bold hover:opacity-90 disabled:opacity-50 transition-opacity font-mono",children:O?"Saving…":s?"Update":"Create"})]})]})]}):null}function ZF(){const[e,t]=z.useState(!1),[n,a]=z.useState(null),s=f=>{a(f),t(!0)},u=()=>{t(!1),a(null)},l=()=>{On(f=>typeof f=="string"&&f.startsWith("/chronos"))};return d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Za,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Chronos"}),d.jsx("p",{className:"text-sm text-azure-text-muted dark:text-matrix-secondary mt-0.5",children:"Temporal Intent Engine — schedule prompts for the Oracle"})]})]}),d.jsxs("button",{onClick:()=>{a(null),t(!0)},className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[d.jsx(od,{className:"w-4 h-4"}),"New Job"]})]}),d.jsx(DF,{onEdit:s}),d.jsx(BF,{isOpen:e,onClose:u,onCreated:l,editJob:n})]})}function IF(){return d.jsx(aT,{children:d.jsxs(k0,{children:[d.jsx(on,{path:"/login",element:d.jsx(WH,{})}),d.jsx(on,{path:"/*",element:d.jsx(eF,{children:d.jsx(vD,{children:d.jsxs(k0,{children:[d.jsx(on,{path:"/",element:d.jsx(SD,{})}),d.jsx(on,{path:"/chat",element:d.jsx(GL,{})}),d.jsx(on,{path:"/zaion",element:d.jsx(XH,{})}),d.jsx(on,{path:"/logs",element:d.jsx(JH,{})}),d.jsx(on,{path:"/stats",element:d.jsx(QH,{})}),d.jsx(on,{path:"/sati-memories",element:d.jsx(uF,{})}),d.jsx(on,{path:"/mcp-servers",element:d.jsx(pF,{})}),d.jsx(on,{path:"/model-pricing",element:d.jsx(yF,{})}),d.jsx(on,{path:"/webhooks",element:d.jsx(kF,{})}),d.jsx(on,{path:"/notifications",element:d.jsx(zF,{})}),d.jsx(on,{path:"/tasks",element:d.jsx(CF,{})}),d.jsx(on,{path:"/trinity-databases",element:d.jsx(AF,{})}),d.jsx(on,{path:"/chronos",element:d.jsx(ZF,{})}),d.jsx(on,{path:"*",element:d.jsx(iS,{to:"/",replace:!0})})]})})})})]})})}PC.createRoot(document.getElementById("root")).render(d.jsx(z.StrictMode,{children:d.jsx(IF,{})}));
111
+ -d '{"event":"your_payload"}'`,se=async(ee,oe)=>{await navigator.clipboard.writeText(ee),j(oe),setTimeout(()=>j(null),2e3)},le=ee=>{const oe=l.notification_channels.includes(ee);f({...l,notification_channels:oe?l.notification_channels.filter(ae=>ae!==ee):[...l.notification_channels,ee]})};return d.jsxs(dt.div,{variants:bF,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:Pw,className:"flex items-center justify-between flex-wrap gap-3",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Gm,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Webhooks"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary mt-0.5",children:"Trigger Oracle agent tasks from external events."})]})]}),d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs(Va,{to:"/notifications",className:"flex items-center gap-2 px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-sm text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:[d.jsx(Sl,{className:"w-4 h-4"}),"Notifications"]}),d.jsxs("button",{onClick:N,className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[d.jsx(od,{className:"w-4 h-4"}),"New Webhook"]})]})]}),g&&d.jsx(dt.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},className:`px-4 py-3 rounded-lg text-sm font-medium border ${g.type==="success"?"bg-green-50 dark:bg-green-900/20 border-green-300 dark:border-green-700 text-green-800 dark:text-green-400":"bg-red-50 dark:bg-red-900/20 border-red-300 dark:border-red-700 text-red-800 dark:text-red-400"}`,children:g.message}),d.jsx(dt.div,{variants:Pw,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-hidden",children:d.jsx("div",{className:"overflow-x-auto",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["Name","API Key","Channels","Triggers","Status","Actions"].map(ee=>d.jsx("th",{className:"px-4 py-3 text-left font-semibold text-azure-text-secondary dark:text-matrix-secondary",children:ee},ee))})}),d.jsx("tbody",{children:e.length===0?d.jsx("tr",{children:d.jsxs("td",{colSpan:6,className:"px-4 py-10 text-center text-azure-text-secondary dark:text-matrix-secondary",children:["No webhooks yet."," ",d.jsx("button",{onClick:N,className:"underline text-azure-primary dark:text-matrix-highlight",children:"Create one"})]})}):e.map(ee=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-800/50 transition-colors",children:[d.jsx("td",{className:"px-4 py-3",children:d.jsx("span",{className:"font-mono text-azure-text-primary dark:text-matrix-secondary font-medium",children:ee.name})}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs("code",{className:"text-xs font-mono text-azure-text-secondary dark:text-matrix-secondary truncate max-w-[140px]",children:[ee.api_key.slice(0,16),"…"]}),d.jsx("button",{onClick:()=>se(fe(ee),`curl-${ee.id}`),className:"p-1 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary",title:"Copy curl example",children:S===`curl-${ee.id}`?d.jsx(Im,{className:"w-3.5 h-3.5 text-green-500"}):d.jsx(qm,{className:"w-3.5 h-3.5"})}),d.jsx("button",{onClick:()=>se(ee.api_key,`key-${ee.id}`),className:"p-1 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary",title:"Copy API key",children:S===`key-${ee.id}`?d.jsx(Im,{className:"w-3.5 h-3.5 text-green-500"}):d.jsx(KT,{className:"w-3.5 h-3.5"})})]})}),d.jsx("td",{className:"px-4 py-3",children:d.jsx("div",{className:"flex gap-1 flex-wrap",children:ee.notification_channels.map(oe=>d.jsx("span",{className:"px-2 py-0.5 text-xs rounded bg-azure-border dark:bg-matrix-primary/20 text-azure-text-secondary dark:text-matrix-secondary capitalize",children:oe},oe))})}),d.jsx("td",{className:"px-4 py-3 text-azure-text-primary dark:text-matrix-secondary",children:ee.trigger_count}),d.jsx("td",{className:"px-4 py-3",children:d.jsx("button",{onClick:()=>q(ee),className:`flex items-center gap-1.5 text-xs px-2 py-1 rounded transition-colors ${ee.enabled?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-400 hover:bg-green-100 dark:hover:bg-green-900/30":"bg-zinc-100 dark:bg-zinc-800 text-zinc-500 dark:text-zinc-400 hover:bg-zinc-200 dark:hover:bg-zinc-700"}`,children:ee.enabled?d.jsxs(d.Fragment,{children:[d.jsx(HA,{className:"w-3.5 h-3.5"})," Enabled"]}):d.jsxs(d.Fragment,{children:[d.jsx(ZA,{className:"w-3.5 h-3.5"})," Disabled"]})})}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx("button",{onClick:()=>L(ee),title:"Edit",className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(Wp,{className:"w-4 h-4"})}),d.jsx("button",{onClick:()=>m(ee),title:"Delete",className:"p-1.5 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-azure-text-secondary dark:text-matrix-secondary hover:text-red-600 dark:hover:text-red-400 transition-colors",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},ee.id))})]})})}),d.jsxs(Or,{open:n,onOpenChange:a,children:[d.jsx(Rr,{children:d.jsx(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight",children:s?"Edit Webhook":"New Webhook"})}),d.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto",children:[d.jsxs("div",{children:[d.jsxs("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:["Name ",d.jsx("span",{className:"text-azure-text-muted dark:text-matrix-secondary/60 font-normal",children:"(slug — used in URL)"})]}),d.jsx("input",{type:"text",value:l.name,onChange:ee=>{f({...l,name:ee.target.value.toLowerCase().replace(/\s+/g,"-")}),E(null)},placeholder:"e.g. deploy-done, github-issue-opened",disabled:!!s,className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight disabled:opacity-50 disabled:cursor-not-allowed"}),l.name&&d.jsxs("p",{className:"mt-1 text-xs text-azure-text-secondary dark:text-matrix-secondary",children:["Trigger URL:"," ",d.jsxs("code",{className:"font-mono text-azure-primary dark:text-matrix-highlight",children:["POST /api/webhooks/trigger/",l.name]})]})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",children:"Agent Prompt"}),d.jsx("textarea",{rows:5,value:l.prompt,onChange:ee=>f({...l,prompt:ee.target.value}),placeholder:"Describe what Apoc should do when this webhook fires. The received payload will be appended automatically.",className:"w-full px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary text-sm focus:outline-none focus:ring-1 focus:ring-azure-primary dark:focus:ring-matrix-highlight focus:border-azure-primary dark:focus:border-matrix-highlight resize-none"})]}),d.jsxs("div",{children:[d.jsx("label",{className:"block text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:"Notification Channels"}),d.jsx("div",{className:"flex gap-4",children:vF.map(ee=>d.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[d.jsx("input",{type:"checkbox",checked:l.notification_channels.includes(ee),onChange:()=>le(ee),className:"rounded border-azure-border dark:border-matrix-primary accent-azure-primary dark:accent-matrix-highlight"}),d.jsx("span",{className:"text-sm text-azure-text-primary dark:text-matrix-secondary capitalize",children:ee})]},ee))})]}),A&&d.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded px-3 py-2",children:A}),d.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[d.jsx("button",{onClick:()=>a(!1),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:R,disabled:v||!l.name.trim()||!l.prompt.trim()||l.notification_channels.length===0,className:"px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 disabled:opacity-50 transition-opacity",children:v?"Saving…":s?"Update":"Create"})]})]})]}),d.jsxs(Or,{open:!!h,onOpenChange:ee=>!ee&&m(null),children:[d.jsx(Rr,{children:d.jsx(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight",children:"Delete Webhook"})}),d.jsxs("div",{className:"p-6 space-y-4",children:[d.jsxs("p",{className:"text-sm text-azure-text-primary dark:text-matrix-secondary",children:["Delete"," ",d.jsx("span",{className:"font-semibold font-mono dark:text-matrix-highlight",children:h?.name}),"? This also removes all associated notifications and cannot be undone."]}),d.jsxs("div",{className:"flex justify-end gap-3",children:[d.jsx("button",{onClick:()=>m(null),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:V,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition-colors",children:"Delete"})]})]})]})]})},wF={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},Vw={hidden:{opacity:0,y:10},show:{opacity:1,y:0}},Bw=({status:e})=>e==="completed"?d.jsxs("div",{className:"flex items-center gap-1.5 text-green-600 dark:text-green-400",children:[d.jsx(mS,{className:"w-4 h-4"}),d.jsx("span",{className:"text-xs",children:"Completed"})]}):e==="failed"?d.jsxs("div",{className:"flex items-center gap-1.5 text-red-600 dark:text-red-400",children:[d.jsx(Hm,{className:"w-4 h-4"}),d.jsx("span",{className:"text-xs",children:"Failed"})]}):d.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400",children:[d.jsx(Za,{className:"w-4 h-4 animate-pulse"}),d.jsx("span",{className:"text-xs",children:"Pending"})]}),Nc=e=>new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),SF=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},zF=()=>{const[e,t]=z.useState(!1),[n,a]=z.useState(null),{data:s=[],mutate:u}=zt(["/webhooks/notifications",e],()=>Pa.listNotifications({unreadOnly:e}),{refreshInterval:5e3}),l=s.filter(g=>!g.read).length,f=async g=>{g.length!==0&&(await Pa.markRead(g),await u())},h=()=>{const g=s.filter(y=>!y.read).map(y=>y.id);f(g)},m=async g=>{a(g),g.read||await f([g.id])};return d.jsxs(dt.div,{variants:wF,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:Vw,className:"flex items-center justify-between flex-wrap gap-3",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("div",{className:"relative",children:[d.jsx(Sl,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),l>0&&d.jsx("span",{className:"absolute -top-1.5 -right-1.5 bg-red-500 text-white text-[10px] font-bold rounded-full w-4 h-4 flex items-center justify-center leading-none",children:l>9?"9+":l})]}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Notifications"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-dim mt-0.5",children:"Webhook execution results from the Oracle agent."})]})]}),d.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[d.jsxs(Va,{to:"/webhooks",className:"flex items-center gap-2 text-sm text-azure-text-secondary dark:text-matrix-dim hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:[d.jsx(zT,{className:"w-4 h-4"}),"Back to Webhooks"]}),d.jsxs("button",{onClick:()=>t(!e),className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm transition-colors ${e?"border-azure-primary dark:border-matrix-highlight bg-azure-active dark:bg-matrix-primary/20 text-azure-primary dark:text-matrix-highlight":"border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-dim hover:bg-azure-surface dark:hover:bg-zinc-800"}`,children:[d.jsx(rA,{className:"w-4 h-4"}),"Unread only"]}),l>0&&d.jsxs("button",{onClick:h,className:"flex items-center gap-2 px-3 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-sm text-azure-text-secondary dark:text-matrix-dim hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:[d.jsx(LT,{className:"w-4 h-4"}),"Mark all read"]})]})]}),d.jsx(dt.div,{variants:Vw,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-hidden",children:d.jsx("div",{className:"overflow-x-auto",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["","Webhook","Status","Created","Completed","Actions"].map(g=>d.jsx("th",{className:"px-4 py-3 text-left font-semibold text-azure-text-secondary dark:text-matrix-dim",children:g},g))})}),d.jsx("tbody",{children:s.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:6,className:"px-4 py-10 text-center text-azure-text-secondary dark:text-matrix-dim",children:e?"No unread notifications.":"No notifications yet."})}):s.map(g=>d.jsxs("tr",{className:`border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-800/50 transition-colors ${g.read?"":"bg-blue-50/40 dark:bg-blue-900/10"}`,children:[d.jsx("td",{className:"px-4 py-3 w-6",children:!g.read&&d.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-blue-500 dark:bg-matrix-highlight"})}),d.jsx("td",{className:"px-4 py-3 font-mono font-medium text-azure-text-primary dark:text-matrix-text",children:g.webhook_name}),d.jsx("td",{className:"px-4 py-3",children:d.jsx(Bw,{status:g.status})}),d.jsx("td",{className:"px-4 py-3 text-xs text-azure-text-secondary dark:text-matrix-dim whitespace-nowrap",children:Nc(g.created_at)}),d.jsx("td",{className:"px-4 py-3 text-xs text-azure-text-secondary dark:text-matrix-dim whitespace-nowrap",children:g.completed_at?Nc(g.completed_at):"—"}),d.jsx("td",{className:"px-4 py-3",children:d.jsx("button",{onClick:()=>m(g),title:"View details",className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-dim hover:text-azure-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(sd,{className:"w-4 h-4"})})})]},g.id))})]})})}),d.jsxs(Or,{open:!!n,onOpenChange:g=>!g&&a(null),children:[d.jsx(Rr,{children:d.jsxs(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight flex items-center gap-2",children:[d.jsx(Sl,{className:"w-4 h-4"}),n?.webhook_name]})}),n&&d.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto max-h-[65vh]",children:[d.jsxs("div",{className:"flex items-center gap-4 text-xs text-azure-text-secondary dark:text-matrix-dim",children:[d.jsx(Bw,{status:n.status}),d.jsx("span",{children:Nc(n.created_at)}),n.completed_at&&d.jsxs("span",{children:["→ ",Nc(n.completed_at)]})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-dim mb-1.5",children:"Received Payload"}),d.jsx("pre",{className:"bg-azure-bg dark:bg-zinc-950 rounded-lg p-3 text-xs font-mono overflow-auto max-h-44 text-azure-text-primary dark:text-matrix-text border border-azure-border dark:border-matrix-primary/30 whitespace-pre-wrap",children:SF(n.payload)})]}),d.jsxs("div",{children:[d.jsx("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-dim mb-1.5",children:"Agent Result"}),d.jsx("div",{className:"bg-azure-bg dark:bg-zinc-950 rounded-lg p-3 text-xs font-mono overflow-auto max-h-64 text-azure-text-primary dark:text-matrix-text border border-azure-border dark:border-matrix-primary/30 whitespace-pre-wrap",children:n.result??d.jsx("span",{className:"text-yellow-600 dark:text-yellow-400 animate-pulse",children:"Processing…"})})]}),d.jsx("div",{className:"flex justify-end pt-2",children:d.jsx("button",{onClick:()=>a(null),className:"px-4 py-2 rounded-lg border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-dim text-sm hover:bg-azure-surface dark:hover:bg-zinc-800 transition-colors",children:"Close"})})]})]})]})},_F={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.05}}},Cc={hidden:{opacity:0,y:8},show:{opacity:1,y:0}},jF={pending:"Pending",running:"Running",completed:"Completed",failed:"Failed",cancelled:"Cancelled"};function NF({status:e}){return e==="completed"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600 dark:text-green-400",children:[d.jsx(mS,{className:"w-4 h-4"}),"Completed"]}):e==="failed"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-red-600 dark:text-red-400",children:[d.jsx(Hm,{className:"w-4 h-4"}),"Failed"]}):e==="running"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-blue-600 dark:text-blue-400",children:[d.jsx(hA,{className:"w-4 h-4 animate-spin"}),"Running"]}):e==="cancelled"?d.jsxs("span",{className:"inline-flex items-center gap-1 text-zinc-500 dark:text-zinc-400",children:[d.jsx(Hm,{className:"w-4 h-4"}),"Cancelled"]}):d.jsxs("span",{className:"inline-flex items-center gap-1 text-yellow-600 dark:text-yellow-400",children:[d.jsx(Za,{className:"w-4 h-4"}),"Pending"]})}const Zw=e=>e?new Date(e).toLocaleString():"—";function CF(){const[e,t]=z.useState(""),[n,a]=z.useState(""),[s,u]=z.useState(""),[l,f]=z.useState(""),[h,m]=z.useState(null),g=z.useMemo(()=>({status:e||void 0,agent:n||void 0,origin_channel:s||void 0,session_id:l.trim()||void 0,limit:200}),[e,n,s,l]),{data:y}=zt("/tasks/stats",()=>Ns.stats(),{refreshInterval:5e3}),{data:v=[],mutate:b}=zt(["/tasks",g],()=>Ns.list(g),{refreshInterval:3e3});return d.jsxs(dt.div,{variants:_F,initial:"hidden",animate:"show",className:"space-y-6",children:[d.jsxs(dt.div,{variants:Cc,className:"flex items-center gap-3",children:[d.jsx(Fm,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Tasks"}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-dim",children:"Async tasks delegated by Oracle and processed by workers."})]})]}),d.jsxs(dt.div,{variants:Cc,className:"grid grid-cols-2 md:grid-cols-6 gap-3",children:[d.jsx(js,{label:"Pending",value:y?.pending??0}),d.jsx(js,{label:"Running",value:y?.running??0}),d.jsx(js,{label:"Completed",value:y?.completed??0}),d.jsx(js,{label:"Failed",value:y?.failed??0}),d.jsx(js,{label:"Cancelled",value:y?.cancelled??0}),d.jsx(js,{label:"Total",value:y?.total??0})]}),d.jsxs(dt.div,{variants:Cc,className:"rounded-lg border border-azure-border dark:border-matrix-primary p-4 bg-azure-surface dark:bg-zinc-950 grid grid-cols-1 md:grid-cols-4 gap-3",children:[d.jsxs("select",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:e,onChange:S=>t(S.target.value||""),children:[d.jsx("option",{value:"",children:"All status"}),Object.entries(jF).map(([S,j])=>d.jsx("option",{value:S,children:j},S))]}),d.jsxs("select",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:n,onChange:S=>a(S.target.value||""),children:[d.jsx("option",{value:"",children:"All agents"}),d.jsx("option",{value:"apoc",children:"Apoc"}),d.jsx("option",{value:"neo",children:"Neo"})]}),d.jsxs("select",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:s,onChange:S=>u(S.target.value||""),children:[d.jsx("option",{value:"",children:"All channels"}),d.jsx("option",{value:"telegram",children:"Telegram"}),d.jsx("option",{value:"ui",children:"UI"}),d.jsx("option",{value:"api",children:"API"}),d.jsx("option",{value:"webhook",children:"Webhook"}),d.jsx("option",{value:"cli",children:"CLI"})]}),d.jsx("input",{className:"px-3 py-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-black text-azure-text-primary dark:text-matrix-secondary",value:l,onChange:S=>f(S.target.value),placeholder:"Filter by session id"})]}),d.jsx(dt.div,{variants:Cc,className:"rounded-lg border border-azure-border dark:border-matrix-primary overflow-x-auto",children:d.jsxs("table",{className:"w-full text-sm",children:[d.jsx("thead",{className:"bg-azure-surface dark:bg-zinc-900 border-b border-azure-border dark:border-matrix-primary",children:d.jsx("tr",{children:["Task ID","Status","Agent","Channel","Session","Attempts","Created","Finished","Actions"].map(S=>d.jsx("th",{className:"text-left px-4 py-3 font-semibold text-azure-text-secondary dark:text-matrix-dim",children:S},S))})}),d.jsx("tbody",{children:v.length===0?d.jsx("tr",{children:d.jsx("td",{colSpan:9,className:"px-4 py-10 text-center text-azure-text-secondary dark:text-matrix-dim",children:"No tasks found."})}):v.map(S=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 hover:bg-azure-surface/50 dark:hover:bg-zinc-900/40 transition-colors",children:[d.jsx("td",{className:"px-4 py-3 font-mono",children:S.id.slice(0,8)}),d.jsx("td",{className:"px-4 py-3",children:d.jsx(NF,{status:S.status})}),d.jsx("td",{className:"px-4 py-3",children:S.agent.toUpperCase()}),d.jsx("td",{className:"px-4 py-3",children:S.origin_channel.toUpperCase()}),d.jsx("td",{className:"px-4 py-3 font-mono",children:S.session_id}),d.jsxs("td",{className:"px-4 py-3",children:[S.attempt_count,"/",S.max_attempts]}),d.jsx("td",{className:"px-4 py-3",children:Zw(S.created_at)}),d.jsx("td",{className:"px-4 py-3",children:Zw(S.finished_at)}),d.jsxs("td",{className:"px-4 py-3 flex items-center gap-1",children:[d.jsx("button",{onClick:()=>m(S),className:"p-1.5 rounded hover:bg-azure-border dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-dim",children:d.jsx(sd,{className:"w-4 h-4"})}),(S.status==="pending"||S.status==="running")&&d.jsx("button",{onClick:async()=>{await Ns.cancel(S.id),await b()},title:"Cancel task",className:"p-1.5 rounded hover:bg-red-100 dark:hover:bg-red-900/30 text-red-500 dark:text-red-400",children:d.jsx(NT,{className:"w-4 h-4"})})]})]},S.id))})]})}),d.jsxs(Or,{open:!!h,onOpenChange:S=>!S&&m(null),children:[d.jsx(Rr,{children:d.jsx(Mr,{className:"text-azure-text-primary dark:text-matrix-highlight",children:"Task Details"})}),h&&d.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto max-h-[70vh] text-sm",children:[d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2 text-azure-text-secondary dark:text-matrix-dim",children:[d.jsxs("div",{children:[d.jsx("b",{children:"ID:"})," ",d.jsx("span",{className:"font-mono",children:h.id})]}),d.jsxs("div",{children:[d.jsx("b",{children:"Status:"})," ",h.status]}),d.jsxs("div",{children:[d.jsx("b",{children:"Agent:"})," ",h.agent]}),d.jsxs("div",{children:[d.jsx("b",{children:"Origin:"})," ",h.origin_channel]}),d.jsxs("div",{children:[d.jsx("b",{children:"Session:"})," ",d.jsx("span",{className:"font-mono",children:h.session_id})]}),d.jsxs("div",{children:[d.jsx("b",{children:"Attempts:"})," ",h.attempt_count,"/",h.max_attempts]})]}),d.jsxs("section",{children:[d.jsx("p",{className:"font-medium mb-1",children:"Input"}),d.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded-lg border border-azure-border dark:border-matrix-primary/30 p-3 bg-azure-bg dark:bg-zinc-950",children:h.input})]}),h.output&&d.jsxs("section",{children:[d.jsx("p",{className:"font-medium mb-1",children:"Output"}),d.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded-lg border border-azure-border dark:border-matrix-primary/30 p-3 bg-azure-bg dark:bg-zinc-950",children:h.output})]}),h.error&&d.jsxs("section",{children:[d.jsx("p",{className:"font-medium mb-1 text-red-600 dark:text-red-400",children:"Error"}),d.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded-lg border border-red-200 dark:border-red-900/50 p-3 bg-red-50 dark:bg-red-950/40",children:h.error})]}),(h.status==="failed"||h.status==="pending"||h.status==="running")&&d.jsxs("div",{className:"flex justify-end gap-2",children:[(h.status==="pending"||h.status==="running")&&d.jsx("button",{onClick:async()=>{await Ns.cancel(h.id),m(null),await b()},className:"px-4 py-2 rounded-lg border border-red-400 dark:border-red-500 text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 text-sm",children:"Cancel Task"}),h.status==="failed"&&d.jsx("button",{onClick:async()=>{await Ns.retry(h.id),m(null),await b()},className:"px-4 py-2 rounded-lg bg-azure-primary text-white dark:bg-matrix-highlight dark:text-black text-sm",children:"Retry Task"})]})]})]})]})}function js({label:e,value:t}){return d.jsxs("div",{className:"rounded-lg border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-950 px-4 py-3",children:[d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-dim",children:e}),d.jsx("p",{className:"text-xl font-semibold text-azure-text-primary dark:text-matrix-highlight",children:t})]})}const Um={postgresql:5432,mysql:3306,mongodb:27017,sqlite:0},Iw={name:"",type:"postgresql",host:"",port:"",database_name:"",username:"",password:"",connection_string:"",allow_read:!0,allow_insert:!1,allow_update:!1,allow_delete:!1,allow_ddl:!1},EF={postgresql:[{key:"allow_read",label:"SELECT",description:"Permite consultas SELECT"},{key:"allow_insert",label:"INSERT",description:"Permite inserir registros"},{key:"allow_update",label:"UPDATE",description:"Permite atualizar registros"},{key:"allow_delete",label:"DELETE",description:"Permite excluir registros"},{key:"allow_ddl",label:"DDL",description:"CREATE / ALTER / DROP TABLE"}],mysql:[{key:"allow_read",label:"SELECT",description:"Permite consultas SELECT"},{key:"allow_insert",label:"INSERT",description:"Permite inserir registros"},{key:"allow_update",label:"UPDATE",description:"Permite atualizar registros"},{key:"allow_delete",label:"DELETE",description:"Permite excluir registros"},{key:"allow_ddl",label:"DDL",description:"CREATE / ALTER / DROP TABLE"}],sqlite:[{key:"allow_read",label:"SELECT",description:"Permite consultas SELECT"},{key:"allow_insert",label:"INSERT",description:"Permite inserir registros"},{key:"allow_update",label:"UPDATE",description:"Permite atualizar registros"},{key:"allow_delete",label:"DELETE",description:"Permite excluir registros"},{key:"allow_ddl",label:"DDL",description:"CREATE / ALTER / DROP TABLE"}],mongodb:[{key:"allow_read",label:"find / aggregate",description:"Permite consultas e agregações"},{key:"allow_insert",label:"insertOne / insertMany",description:"Permite inserir documentos"},{key:"allow_update",label:"updateOne / updateMany",description:"Permite atualizar documentos"},{key:"allow_delete",label:"deleteOne / deleteMany",description:"Permite excluir documentos"},{key:"allow_ddl",label:"Schema changes",description:"createCollection / dropCollection / createIndex"}]};async function TF(){return xe.get("/trinity/databases")}function AF(){const{data:e,error:t}=zt("/trinity/databases",TF,{refreshInterval:3e4}),[n,a]=z.useState(!1),[s,u]=z.useState(null),[l,f]=z.useState(Iw),[h,m]=z.useState(!1),[g,y]=z.useState(null),[v,b]=z.useState({}),[S,j]=z.useState(null),[A,E]=z.useState({}),[O,N]=z.useState(null),[L,D]=z.useState(null),[R,q]=z.useState(null),[V,X]=z.useState(!1),fe=()=>{u(null),f(Iw),X(!1),y(null),a(!0)},se=w=>{u(w),f({name:w.name,type:w.type,host:w.host||"",port:w.port?String(w.port):"",database_name:w.database_name||"",username:w.username||"",password:"",connection_string:"",allow_read:w.allow_read,allow_insert:w.allow_insert,allow_update:w.allow_update,allow_delete:w.allow_delete,allow_ddl:w.allow_ddl}),X(!!w.connection_string),y(null),a(!0)},le=async()=>{if(m(!0),y(null),!V&&!l.database_name.trim()){y(l.type==="sqlite"?"File path is required.":"Database name is required."),m(!1);return}try{const w={name:l.name,type:l.type,allow_read:l.allow_read,allow_insert:l.allow_insert,allow_update:l.allow_update,allow_delete:l.allow_delete,allow_ddl:l.allow_ddl};V?(!s||l.connection_string)&&(w.connection_string=l.connection_string||null):(w.host=l.host||null,w.port=l.port?parseInt(l.port):null,w.database_name=l.database_name||null,w.username=l.username||null,(!s||l.password)&&(w.password=l.password||null)),s?await xe.put(`/trinity/databases/${s.id}`,w):await xe.post("/trinity/databases",w),await On("/trinity/databases"),a(!1)}catch(w){y(w.message||"Failed to save database")}finally{m(!1)}},ee=w=>{q(w)},oe=async()=>{if(!R)return;const w=R.id;D(w);try{await xe.delete(`/trinity/databases/${w}`),await On("/trinity/databases")}catch(Y){alert(`Delete failed: ${Y.message}`)}finally{D(null),q(null)}},ae=async w=>{j(w);try{const Y=await xe.post(`/trinity/databases/${w}/test`,{});E(de=>({...de,[w]:Y.success}))}catch{E(Y=>({...Y,[w]:!1}))}finally{j(null)}},P=async w=>{N(w);try{await xe.post(`/trinity/databases/${w}/refresh-schema`,{}),await On("/trinity/databases")}catch(Y){alert(`Schema refresh failed: ${Y.message}`)}finally{N(null)}},J=w=>{b(Y=>({...Y,[w]:!Y[w]}))},B=w=>{w!=="mongodb"&&X(!1),f(Y=>({...Y,type:w,port:Um[w]?String(Um[w]):""}))},me=w=>{f(Y=>({...Y,[w]:!Y[w]}))};if(t)return d.jsxs("div",{className:"p-8 text-red-500",children:["Failed to load databases: ",t.message]});const T="w-full px-3 py-2 bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded text-azure-text-primary dark:text-matrix-secondary font-mono text-sm focus:outline-none focus:border-azure-primary dark:focus:border-matrix-highlight",C="block text-xs font-medium text-azure-text-secondary dark:text-matrix-secondary mb-1",I=w=>[{key:"allow_read",badge:"R"},{key:"allow_insert",badge:"I"},{key:"allow_update",badge:"U"},{key:"allow_delete",badge:"D"},{key:"allow_ddl",badge:"DDL"}].filter(de=>w[de.key]).map(de=>de.badge);return d.jsxs("div",{className:"max-w-5xl mx-auto space-y-6",children:[d.jsxs("div",{className:"flex justify-between items-center",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx($s,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsx("h1",{className:"text-2xl font-bold text-azure-primary dark:text-matrix-highlight",children:"Trinity Databases"})]}),d.jsxs("button",{onClick:fe,className:"flex items-center gap-2 px-4 py-2 bg-azure-primary text-white rounded hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90 transition-colors text-sm font-medium",children:[d.jsx(od,{className:"w-4 h-4"}),"Register Database"]})]}),d.jsx("p",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary",children:"Register databases for Trinity to access. Configure permissions to control what operations Trinity can perform on each database."}),e?e.length===0?d.jsxs("div",{className:"border border-azure-border dark:border-matrix-primary rounded p-8 text-center text-azure-text-secondary dark:text-matrix-secondary",children:[d.jsx($s,{className:"w-10 h-10 mx-auto mb-3 opacity-40"}),d.jsx("p",{className:"font-medium",children:"No databases registered"}),d.jsx("p",{className:"text-sm mt-1 opacity-70",children:'Click "Register Database" to add your first database.'})]}):d.jsx("div",{className:"space-y-4",children:e.map(w=>{const Y=w.schema_json?JSON.parse(w.schema_json):null,de=!!Y?.databases,he=de?Y.databases.reduce((Ne,qe)=>Ne+qe.tables.length,0):Y?.tables?.length??0,pe=de?Y.databases.length:0,Pe=w.type==="mongodb"?"collection":"table",Ae=w.type==="mongodb"?"collections":"tables",pt=A[w.id],Rt=v[w.id],Z=I(w);return d.jsxs("div",{className:"border border-azure-border dark:border-matrix-primary rounded-lg overflow-hidden",children:[d.jsxs("div",{className:"bg-azure-surface dark:bg-black/50 px-4 py-3 flex items-center gap-3",children:[d.jsx($s,{className:"w-5 h-5 text-azure-primary dark:text-matrix-highlight flex-shrink-0"}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[d.jsx("span",{className:"font-bold text-azure-text-primary dark:text-matrix-highlight truncate",children:w.name}),d.jsx("span",{className:"text-xs px-2 py-0.5 rounded border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary uppercase flex-shrink-0",children:w.type}),pt===!0&&d.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500",children:[d.jsx(Fh,{className:"w-3 h-3"})," Connected"]}),pt===!1&&d.jsxs("span",{className:"flex items-center gap-1 text-xs text-red-500",children:[d.jsx(QA,{className:"w-3 h-3"})," Failed"]}),Z.length>0&&d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(A0,{className:"w-3 h-3 text-azure-text-secondary dark:text-matrix-secondary opacity-60"}),Z.map(Ne=>d.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-azure-primary/10 dark:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight font-mono",children:Ne},Ne))]})]}),d.jsxs("div",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary truncate mt-0.5",children:[w.host?`${w.host}:${w.port}${w.database_name?`/${w.database_name}`:""}`:w.database_name||"connection string configured",de&&pe>0&&d.jsxs("span",{className:"ml-2 opacity-70",children:["· ",pe," database",pe!==1?"s":""," · ",he," ",he!==1?Ae:Pe]}),!de&&he>0&&d.jsxs("span",{className:"ml-2 opacity-70",children:["· ",he," ",he!==1?Ae:Pe]}),w.schema_updated_at&&d.jsxs("span",{className:"ml-2 opacity-50",children:["· schema ",new Date(w.schema_updated_at).toLocaleDateString()]})]})]}),d.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[d.jsx("button",{onClick:()=>ae(w.id),disabled:S===w.id,title:"Test connection",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors",children:S===w.id?d.jsx(Fh,{className:"w-4 h-4 animate-pulse"}):d.jsx(Fh,{className:"w-4 h-4"})}),d.jsx("button",{onClick:()=>P(w.id),disabled:O===w.id,title:"Refresh schema",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors",children:d.jsx(xS,{className:`w-4 h-4 ${O===w.id?"animate-spin":""}`})}),d.jsx("button",{onClick:()=>se(w),title:"Edit",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors text-xs font-medium px-2",children:"Edit"}),d.jsx("button",{onClick:()=>ee(w),disabled:L===w.id,title:"Delete",className:"p-1.5 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-red-500 transition-colors",children:d.jsx(Ti,{className:"w-4 h-4"})}),Y&&d.jsx("button",{onClick:()=>J(w.id),title:Rt?"Hide schema":"Show schema",className:"p-1.5 rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 text-azure-text-secondary dark:text-matrix-secondary transition-colors",children:Rt?d.jsx(VT,{className:"w-4 h-4"}):d.jsx(ZT,{className:"w-4 h-4"})})]})]}),Rt&&Y&&d.jsxs("div",{className:"border-t border-azure-border dark:border-matrix-primary px-4 py-3 bg-azure-bg dark:bg-black/20",children:[d.jsx("div",{className:"text-xs font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:de?`${pe} database${pe!==1?"s":""} — ${he} ${he!==1?Ae:Pe} total`:`Schema — ${he} ${he!==1?Ae:Pe}`}),d.jsx("div",{className:"space-y-2 max-h-72 overflow-y-auto",children:de?Y.databases?.map(Ne=>d.jsxs("div",{className:"text-xs",children:[d.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[d.jsx("span",{className:"font-bold text-azure-primary dark:text-matrix-highlight",children:Ne.name}),d.jsxs("span",{className:"opacity-40 text-azure-text-secondary dark:text-matrix-secondary",children:["(",Ne.tables.length," ",Ne.tables.length!==1?Ae:Pe,")"]})]}),d.jsxs("div",{className:"pl-3 space-y-1.5 border-l border-azure-border dark:border-matrix-primary/40 ml-1",children:[Ne.tables.map(qe=>d.jsxs("div",{children:[d.jsx("div",{className:"font-semibold text-azure-text-primary dark:text-matrix-secondary mb-0.5",children:qe.name}),d.jsx("div",{className:"pl-3 space-y-0.5",children:qe.columns?.map(Lt=>d.jsxs("div",{className:"text-azure-text-secondary dark:text-matrix-secondary font-mono",children:[d.jsx("span",{children:Lt.name}),d.jsx("span",{className:"opacity-50 ml-2",children:Lt.type}),Lt.nullable===!1&&d.jsx("span",{className:"ml-1 opacity-40",children:"NOT NULL"})]},Lt.name))})]},qe.name)),Ne.tables.length===0&&d.jsxs("div",{className:"text-azure-text-secondary dark:text-matrix-secondary opacity-50 italic",children:["no ",Ae]})]})]},Ne.name)):Y.tables?.map(Ne=>d.jsxs("div",{className:"text-xs",children:[d.jsx("div",{className:"font-bold text-azure-primary dark:text-matrix-highlight mb-1",children:Ne.name}),d.jsx("div",{className:"pl-3 space-y-0.5",children:Ne.columns?.map(qe=>d.jsxs("div",{className:"text-azure-text-secondary dark:text-matrix-secondary font-mono",children:[d.jsx("span",{className:"text-azure-text-primary dark:text-matrix-secondary",children:qe.name}),d.jsx("span",{className:"opacity-50 ml-2",children:qe.type}),qe.nullable===!1&&d.jsx("span",{className:"ml-1 opacity-40 text-xs",children:"NOT NULL"})]},qe.name))})]},Ne.name))})]})]},w.id)})}):d.jsx("div",{className:"text-azure-text-secondary dark:text-matrix-secondary",children:"Loading..."}),d.jsx(G_,{isOpen:!!R,onClose:()=>q(null),onConfirm:oe,title:"Delete database",description:`Remove "${R?.name}" from Trinity? The database itself won't be affected — only this registration will be deleted.`,confirmJson:"Delete",variant:"destructive"}),n&&d.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[d.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:()=>a(!1)}),d.jsxs("div",{className:"relative bg-azure-surface dark:bg-black border border-azure-border dark:border-matrix-primary rounded-lg shadow-xl w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto",children:[d.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-azure-border dark:border-matrix-primary",children:[d.jsx("h2",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight",children:s?"Edit Database":"Register Database"}),d.jsx("button",{onClick:()=>a(!1),className:"text-azure-text-secondary dark:text-matrix-secondary hover:text-azure-text-primary dark:hover:text-matrix-highlight",children:d.jsx(eg,{className:"w-5 h-5"})})]}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Name *"}),d.jsx("input",{className:T,value:l.name,onChange:w=>f(Y=>({...Y,name:w.target.value})),placeholder:"My Production DB"})]}),d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Type *"}),d.jsxs("select",{className:T,value:l.type,onChange:w=>B(w.target.value),children:[d.jsx("option",{value:"postgresql",children:"PostgreSQL"}),d.jsx("option",{value:"mysql",children:"MySQL / MariaDB"}),d.jsx("option",{value:"sqlite",children:"SQLite"}),d.jsx("option",{value:"mongodb",children:"MongoDB"})]})]}),l.type==="mongodb"&&d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx("button",{type:"button",onClick:()=>X(!1),className:`text-xs px-3 py-1.5 rounded border transition-colors ${V?"border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary":"border-azure-primary dark:border-matrix-highlight bg-azure-primary/10 dark:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight"}`,children:"Individual fields"}),d.jsx("button",{type:"button",onClick:()=>X(!0),className:`text-xs px-3 py-1.5 rounded border transition-colors ${V?"border-azure-primary dark:border-matrix-highlight bg-azure-primary/10 dark:bg-matrix-highlight/10 text-azure-primary dark:text-matrix-highlight":"border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary"}`,children:"Connection string"})]}),l.type==="mongodb"&&V?d.jsxs("div",{children:[d.jsxs("label",{className:C,children:["Connection String ",s&&d.jsx("span",{className:"opacity-60",children:"(leave blank to keep existing)"})]}),d.jsx("input",{className:T,type:"password",value:l.connection_string,onChange:w=>f(Y=>({...Y,connection_string:w.target.value})),placeholder:s?"unchanged":"mongodb://user:pass@host:27017/dbname"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Stored encrypted with AES-256-GCM. Requires MORPHEUS_SECRET env var."})]}):d.jsxs(d.Fragment,{children:[l.type!=="sqlite"&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Host"}),d.jsx("input",{className:T,value:l.host,onChange:w=>f(Y=>({...Y,host:w.target.value})),placeholder:"localhost"})]}),d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Port"}),d.jsx("input",{className:T,type:"number",value:l.port,onChange:w=>f(Y=>({...Y,port:w.target.value})),placeholder:String(Um[l.type]||"")})]})]}),d.jsxs("div",{children:[d.jsxs("label",{className:C,children:[l.type==="sqlite"?"File Path":"Database Name"," *"]}),d.jsx("input",{className:`w-full px-3 py-2 bg-azure-surface dark:bg-black border rounded text-azure-text-primary dark:text-matrix-secondary font-mono text-sm focus:outline-none ${g&&!l.database_name.trim()?"border-red-500 dark:border-red-500":"border-azure-border dark:border-matrix-primary focus:border-azure-primary dark:focus:border-matrix-highlight"}`,value:l.database_name,onChange:w=>f(Y=>({...Y,database_name:w.target.value})),placeholder:l.type==="sqlite"?"/path/to/database.db":"mydb"})]}),l.type!=="sqlite"&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{children:[d.jsx("label",{className:C,children:"Username"}),d.jsx("input",{className:T,value:l.username,onChange:w=>f(Y=>({...Y,username:w.target.value})),placeholder:"postgres"})]}),d.jsxs("div",{children:[d.jsxs("label",{className:C,children:["Password ",s&&d.jsx("span",{className:"opacity-60",children:"(leave blank to keep existing)"})]}),d.jsx("input",{className:T,type:"password",value:l.password,onChange:w=>f(Y=>({...Y,password:w.target.value})),placeholder:s?"unchanged":"••••••••"}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mt-1",children:"Stored encrypted with AES-256-GCM. Requires MORPHEUS_SECRET env var."})]})]})]}),d.jsxs("div",{className:"border-t border-azure-border dark:border-matrix-primary pt-4",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[d.jsx(A0,{className:"w-4 h-4 text-azure-primary dark:text-matrix-highlight"}),d.jsx("span",{className:"text-sm font-medium text-azure-text-primary dark:text-matrix-highlight",children:"Permissões"})]}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary mb-3",children:"Defina quais operações Trinity pode executar neste banco. Operações não permitidas retornarão erro de permissão."}),d.jsx("div",{className:"space-y-2",children:EF[l.type]?.map(({key:w,label:Y,description:de})=>d.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[d.jsxs("div",{className:"relative mt-0.5 flex-shrink-0",children:[d.jsx("input",{type:"checkbox",checked:!!l[w],onChange:()=>me(w),className:"sr-only"}),d.jsx("div",{className:`w-4 h-4 rounded border transition-colors flex items-center justify-center ${l[w]?"bg-azure-primary dark:bg-matrix-highlight border-azure-primary dark:border-matrix-highlight":"border-azure-border dark:border-matrix-primary bg-transparent"}`,children:l[w]&&d.jsx("svg",{className:"w-2.5 h-2.5 text-white dark:text-black",fill:"none",viewBox:"0 0 10 10",children:d.jsx("path",{d:"M1.5 5l2.5 2.5L8.5 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),d.jsxs("div",{children:[d.jsx("span",{className:"text-sm text-azure-text-primary dark:text-matrix-secondary font-mono",children:Y}),d.jsx("p",{className:"text-xs text-azure-text-secondary dark:text-matrix-secondary opacity-70",children:de})]})]},w))})]}),g&&d.jsx("div",{className:"text-sm text-red-500 border border-red-500/30 bg-red-500/10 rounded px-3 py-2",children:g})]}),d.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-azure-border dark:border-matrix-primary",children:[d.jsx("button",{onClick:()=>a(!1),className:"px-4 py-2 text-sm text-azure-text-secondary dark:text-matrix-secondary border border-azure-border dark:border-matrix-primary rounded hover:bg-azure-hover dark:hover:bg-matrix-primary/30 transition-colors",children:"Cancel"}),d.jsx("button",{onClick:le,disabled:h||!l.name,className:"px-4 py-2 text-sm font-medium bg-azure-primary text-white rounded hover:bg-azure-active dark:bg-matrix-highlight dark:text-black dark:hover:bg-matrix-highlight/90 transition-colors disabled:opacity-50",children:h?"Saving...":s?"Update":"Register"})]})]})]})]})}const OF={running:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",success:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",failed:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",timeout:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"};function RF({jobId:e}){const{data:t,isLoading:n}=KL(e,50);return n?d.jsx("div",{className:"p-4 dark:bg-zinc-900 rounded text-sm dark:text-matrix-secondary animate-pulse",children:"Loading history…"}):!t||t.length===0?d.jsx("div",{className:"p-4 dark:bg-zinc-900 rounded text-sm dark:text-matrix-secondary italic",children:"No executions yet."}):d.jsx("div",{className:"rounded border border-azure-border dark:border-matrix-primary dark:bg-zinc-900 overflow-hidden",children:d.jsxs("table",{className:"w-full text-xs font-mono",children:[d.jsx("thead",{children:d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary",children:[d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Triggered At"}),d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Completed At"}),d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Status"}),d.jsx("th",{className:"text-left px-3 py-2 text-azure-text-muted dark:text-matrix-tertiary",children:"Error"})]})}),d.jsx("tbody",{children:t.map(a=>d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 last:border-0",children:[d.jsx("td",{className:"px-3 py-2 dark:text-matrix-secondary",children:new Date(a.triggered_at).toLocaleString()}),d.jsx("td",{className:"px-3 py-2 dark:text-matrix-secondary",children:a.completed_at?new Date(a.completed_at).toLocaleString():"—"}),d.jsx("td",{className:"px-3 py-2",children:d.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold uppercase ${OF[a.status]}`,children:a.status})}),d.jsx("td",{className:"px-3 py-2 dark:text-red-400 max-w-xs truncate",children:a.error??"—"})]},a.id))})]})})}function MF({enabled:e}){return d.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-bold uppercase ${e?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-zinc-800 dark:text-matrix-tertiary"}`,children:e?"Enabled":"Disabled"})}function Hw(e,t){return e.length>t?`${e.slice(0,t)}…`:e}function Fw(e){return e?new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function DF({onEdit:e}){const{data:t,isLoading:n}=YL(),[a,s]=z.useState(null),[u,l]=z.useState(null),[f,h]=z.useState(null),m=async y=>{l(y.id);try{y.enabled?await Ei.disableJob(y.id):await Ei.enableJob(y.id),await On(v=>typeof v=="string"&&v.startsWith("/chronos"))}finally{l(null)}},g=async()=>{if(f){l(f.id);try{await Ei.deleteJob(f.id),await On(y=>typeof y=="string"&&y.startsWith("/chronos"))}finally{l(null),h(null)}}};return n?d.jsx("div",{className:"rounded border border-azure-border dark:border-matrix-primary p-8 text-center dark:text-matrix-secondary animate-pulse",children:"Loading jobs…"}):!t||t.length===0?d.jsxs("div",{className:"rounded border border-azure-border dark:border-matrix-primary p-8 text-center dark:text-matrix-secondary",children:["No Chronos jobs yet. Click ",d.jsx("strong",{className:"dark:text-matrix-highlight",children:"New Job"})," to get started."]}):d.jsxs("div",{className:"rounded border border-azure-border dark:border-matrix-primary overflow-hidden",children:[d.jsxs("table",{className:"w-full text-sm font-mono",children:[d.jsx("thead",{children:d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-900",children:[d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium",children:"Prompt"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden md:table-cell",children:"Schedule"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden lg:table-cell",children:"Next Run"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium hidden lg:table-cell",children:"Last Run"}),d.jsx("th",{className:"text-left px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium",children:"Status"}),d.jsx("th",{className:"px-4 py-3 text-azure-text-muted dark:text-matrix-tertiary font-medium text-right",children:"Actions"})]})}),d.jsx("tbody",{children:t.map(y=>d.jsxs(d.Fragment,{children:[d.jsxs("tr",{className:"border-b border-azure-border dark:border-matrix-primary/30 last:border-0 hover:bg-azure-hover dark:hover:bg-matrix-primary/10 transition-colors",children:[d.jsxs("td",{className:"px-4 py-3 dark:text-matrix-secondary max-w-xs",children:[d.jsx("span",{title:y.prompt,children:Hw(y.prompt,50)}),d.jsx("div",{className:"text-xs text-azure-text-muted dark:text-matrix-tertiary",children:y.created_by})]}),d.jsxs("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden md:table-cell text-xs",children:[d.jsx("div",{className:"capitalize",children:y.schedule_type}),d.jsx("div",{className:"text-azure-text-muted dark:text-matrix-tertiary truncate max-w-[140px]",title:y.schedule_expression,children:y.schedule_expression})]}),d.jsx("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden lg:table-cell text-xs",children:Fw(y.next_run_at)}),d.jsx("td",{className:"px-4 py-3 dark:text-matrix-secondary hidden lg:table-cell text-xs",children:Fw(y.last_run_at)}),d.jsx("td",{className:"px-4 py-3",children:d.jsx(MF,{enabled:y.enabled})}),d.jsx("td",{className:"px-4 py-3",children:d.jsxs("div",{className:"flex items-center justify-end gap-1",children:[d.jsx("button",{title:a===y.id?"Hide history":"View history",onClick:()=>s(a===y.id?null:y.id),className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors",children:a===y.id?d.jsx(HT,{className:"w-4 h-4"}):d.jsx(oA,{className:"w-4 h-4"})}),d.jsx("button",{title:"Edit",onClick:()=>e(y),className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors",children:d.jsx(SA,{className:"w-4 h-4"})}),d.jsx("button",{title:y.enabled?"Disable":"Enable",onClick:()=>m(y),disabled:u===y.id,className:"p-1.5 rounded dark:text-matrix-tertiary dark:hover:text-matrix-highlight hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors disabled:opacity-40",children:y.enabled?d.jsx(kA,{className:"w-4 h-4"}):d.jsx(jA,{className:"w-4 h-4"})}),d.jsx("button",{title:"Delete",onClick:()=>h(y),disabled:u===y.id,className:"p-1.5 rounded text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-40",children:d.jsx(Ti,{className:"w-4 h-4"})})]})})]},y.id),a===y.id&&d.jsx("tr",{className:"bg-azure-surface dark:bg-zinc-900/50",children:d.jsxs("td",{colSpan:6,className:"px-4 py-3",children:[d.jsx("div",{className:"text-xs font-bold dark:text-matrix-highlight mb-2",children:"Execution History"}),d.jsx(RF,{jobId:y.id})]})},`${y.id}-history`)]}))})]}),d.jsx(m2,{isOpen:!!f,onClose:()=>h(null),onConfirm:g,title:"Delete Chronos Job",message:f?`Delete job "${Hw(f.prompt,60)}"? This action cannot be undone.`:""})]})}function $F({scheduleExpression:e,scheduleType:t,timezone:n}){const[a,s]=z.useState(null),[u,l]=z.useState(null),f=z.useRef(null);if(z.useEffect(()=>{if(!e.trim()){s(null),l(null);return}return f.current&&clearTimeout(f.current),f.current=setTimeout(async()=>{try{const m=await Ei.preview(e,t,n);s(m),l(null)}catch(m){l(m.message??"Invalid expression"),s(null)}},500),()=>{f.current&&clearTimeout(f.current)}},[e,t,n]),!e.trim())return null;const h=(m,g)=>{try{return new Date(m).toLocaleString("pt-BR",{timeZone:g,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return new Date(m).toLocaleString()}};return d.jsx("div",{className:"mt-2 rounded border border-azure-border dark:border-matrix-primary bg-azure-surface dark:bg-zinc-900 p-3 text-sm",children:u?d.jsxs("p",{className:"text-red-500 dark:text-red-400 flex items-center gap-1.5",children:[d.jsx("span",{children:"⚠"})," ",u]}):a?d.jsxs("div",{className:"space-y-1",children:[d.jsxs("div",{className:"flex items-center gap-1.5 text-azure-text-secondary dark:text-matrix-secondary",children:[d.jsx(Za,{className:"w-3.5 h-3.5 text-azure-primary dark:text-matrix-highlight shrink-0"}),d.jsx("span",{className:"font-medium dark:text-matrix-highlight",children:"Next run:"}),d.jsx("span",{children:h(a.next_run_at,n||"UTC")})]}),a.human_readable&&d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-secondary/70 pl-5",children:a.human_readable}),a.next_occurrences.length>0&&d.jsx("div",{className:"pl-5 space-y-0.5",children:a.next_occurrences.map((m,g)=>d.jsxs("p",{className:"text-azure-text-muted dark:text-matrix-tertiary text-xs",children:["#",g+2,": ",m]},g))})]}):d.jsx("p",{className:"text-azure-text-muted dark:text-matrix-tertiary italic",children:"Parsing…"})})}const LF=["UTC","America/Sao_Paulo","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Mexico_City","America/Buenos_Aires","America/Bogota","America/Lima","America/Santiago","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Lisbon","Europe/Moscow","Europe/Istanbul","Asia/Dubai","Asia/Kolkata","Asia/Bangkok","Asia/Singapore","Asia/Tokyo","Asia/Shanghai","Asia/Seoul","Asia/Jakarta","Australia/Sydney","Australia/Melbourne","Pacific/Auckland","Africa/Cairo","Africa/Johannesburg","Africa/Lagos"],PF=[{value:"telegram",label:"Telegram"},{value:"discord",label:"Discord"}],UF=[{value:"once",label:"Once"},{value:"cron",label:"Recurring (Cron)"},{value:"interval",label:"Recurring (Interval)"}],VF={once:'e.g. "in 30 minutes", "tomorrow at 9am", "2026-03-01T09:00:00"',cron:'e.g. "0 9 * * 1-5" (weekdays at 9am)',interval:'e.g. "every 30 minutes", "every sunday at 9am", "every weekday"'};function BF({isOpen:e,onClose:t,onCreated:n,editJob:a}){const s=!!a,{data:u}=Y_(),[l,f]=z.useState(""),[h,m]=z.useState("once"),[g,y]=z.useState(""),[v,b]=z.useState("UTC"),[S,j]=z.useState([]),[A,E]=z.useState(null),[O,N]=z.useState(!1),L=R=>{j(q=>q.includes(R)?q.filter(V=>V!==R):[...q,R])};z.useEffect(()=>{a?(f(a.prompt),m(a.schedule_type),y(a.schedule_expression),b(a.timezone),j(a.notify_channels??[])):(f(""),m("once"),y(""),b(u?.timezone??"UTC"),j([])),E(null)},[a,e,u?.timezone]);const D=async()=>{if(E(null),!l.trim()){E("Prompt is required");return}if(!g.trim()){E("Schedule expression is required");return}N(!0);try{if(s&&a){const R={prompt:l,schedule_expression:g,timezone:v,notify_channels:S};await Ei.updateJob(a.id,R)}else{const R={prompt:l,schedule_type:h,schedule_expression:g,timezone:v,notify_channels:S};await Ei.createJob(R)}await On(R=>typeof R=="string"&&R.startsWith("/chronos")),n(),t()}catch(R){E(R.message??"Failed to save job")}finally{N(!1)}};return e?d.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[d.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),d.jsxs("div",{className:"relative z-10 w-full max-w-lg mx-4 rounded-lg border border-azure-border dark:border-matrix-primary bg-white dark:bg-black shadow-xl",children:[d.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-azure-border dark:border-matrix-primary",children:[d.jsx("h2",{className:"text-lg font-bold text-azure-text-primary dark:text-matrix-highlight font-mono",children:s?"Edit Chronos Job":"New Chronos Job"}),d.jsx("button",{onClick:t,className:"p-1 rounded text-azure-text-muted dark:text-matrix-tertiary hover:text-azure-text-primary dark:hover:text-matrix-highlight transition-colors",children:d.jsx(eg,{className:"w-5 h-5"})})]}),d.jsxs("div",{className:"p-4 space-y-4",children:[d.jsx(lt,{label:"Prompt",value:l,onChange:R=>f(R.target.value),placeholder:"What should the Oracle do when this job triggers?"}),!s&&d.jsx(jr,{label:"Schedule Type",value:h,onChange:R=>m(R.target.value),options:UF}),d.jsxs("div",{children:[d.jsx(lt,{label:"Schedule Expression",value:g,onChange:R=>y(R.target.value),placeholder:VF[h]}),d.jsx($F,{scheduleExpression:g,scheduleType:h,timezone:v})]}),d.jsx(jr,{label:"Timezone",value:v,onChange:R=>b(R.target.value),options:LF.map(R=>({value:R,label:R}))}),d.jsxs("div",{children:[d.jsxs("p",{className:"text-sm font-medium text-azure-text-secondary dark:text-matrix-secondary mb-2",children:["Notify Channels ",d.jsx("span",{className:"text-xs font-normal opacity-60",children:"(empty = all active channels)"})]}),d.jsx("div",{className:"flex gap-4",children:PF.map(({value:R,label:q})=>d.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[d.jsx("input",{type:"checkbox",checked:S.includes(R),onChange:()=>L(R),className:"rounded border-azure-border dark:border-matrix-primary accent-azure-primary dark:accent-matrix-highlight"}),d.jsx("span",{className:"text-sm text-azure-text-secondary dark:text-matrix-secondary capitalize",children:q})]},R))})]}),A&&d.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:A})]}),d.jsxs("div",{className:"flex justify-end gap-3 p-4 border-t border-azure-border dark:border-matrix-primary",children:[d.jsx("button",{onClick:t,className:"px-4 py-2 rounded text-sm border border-azure-border dark:border-matrix-primary text-azure-text-secondary dark:text-matrix-secondary hover:bg-azure-hover dark:hover:bg-matrix-primary/20 transition-colors font-mono",children:"Cancel"}),d.jsx("button",{onClick:D,disabled:O,className:"px-4 py-2 rounded text-sm bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight font-bold hover:opacity-90 disabled:opacity-50 transition-opacity font-mono",children:O?"Saving…":s?"Update":"Create"})]})]})]}):null}function ZF(){const[e,t]=z.useState(!1),[n,a]=z.useState(null),s=f=>{a(f),t(!0)},u=()=>{t(!1),a(null)},l=()=>{On(f=>typeof f=="string"&&f.startsWith("/chronos"))};return d.jsxs("div",{className:"space-y-6",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsx(Za,{className:"w-6 h-6 text-azure-primary dark:text-matrix-highlight"}),d.jsxs("div",{children:[d.jsx("h1",{className:"text-2xl font-bold text-azure-text-primary dark:text-matrix-highlight",children:"Chronos"}),d.jsx("p",{className:"text-sm text-azure-text-muted dark:text-matrix-secondary mt-0.5",children:"Temporal Intent Engine — schedule prompts for the Oracle"})]})]}),d.jsxs("button",{onClick:()=>{a(null),t(!0)},className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-azure-primary dark:bg-matrix-primary text-white dark:text-matrix-highlight text-sm font-medium hover:opacity-90 transition-opacity",children:[d.jsx(od,{className:"w-4 h-4"}),"New Job"]})]}),d.jsx(DF,{onEdit:s}),d.jsx(BF,{isOpen:e,onClose:u,onCreated:l,editJob:n})]})}function IF(){return d.jsx(aT,{children:d.jsxs(k0,{children:[d.jsx(on,{path:"/login",element:d.jsx(WH,{})}),d.jsx(on,{path:"/*",element:d.jsx(eF,{children:d.jsx(vD,{children:d.jsxs(k0,{children:[d.jsx(on,{path:"/",element:d.jsx(SD,{})}),d.jsx(on,{path:"/chat",element:d.jsx(GL,{})}),d.jsx(on,{path:"/zaion",element:d.jsx(XH,{})}),d.jsx(on,{path:"/logs",element:d.jsx(JH,{})}),d.jsx(on,{path:"/stats",element:d.jsx(QH,{})}),d.jsx(on,{path:"/sati-memories",element:d.jsx(uF,{})}),d.jsx(on,{path:"/mcp-servers",element:d.jsx(pF,{})}),d.jsx(on,{path:"/model-pricing",element:d.jsx(yF,{})}),d.jsx(on,{path:"/webhooks",element:d.jsx(kF,{})}),d.jsx(on,{path:"/notifications",element:d.jsx(zF,{})}),d.jsx(on,{path:"/tasks",element:d.jsx(CF,{})}),d.jsx(on,{path:"/trinity-databases",element:d.jsx(AF,{})}),d.jsx(on,{path:"/chronos",element:d.jsx(ZF,{})}),d.jsx(on,{path:"*",element:d.jsx(iS,{to:"/",replace:!0})})]})})})})]})})}PC.createRoot(document.getElementById("root")).render(d.jsx(z.StrictMode,{children:d.jsx(IF,{})}));