@frumu/tandem-panel 0.4.8 → 0.4.9
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{u as e,d as w,A as Pt,y as be,T as L,q as ut,R as Oi,x as Ei,k as ta,h as Di,e as ji,f as Ui}from"./preact-vendor-jo0muZ28.js";import{u as Z,a as aa,b as xe,c as Bi,Q as Fi}from"./react-query-CeeFMKtE.js";import{c as ie,o as $t,d as un,r as Tr,e as mn,f as ha,g as Fa,h as Ki,W as Li,U as Wi,C as zi,X as Ji,T as Qi,j as Gi,S as Hi,k as Vi,l as Yi,m as Xi,p as Zi,q as eo,t as to,u as ao,v as no,w as ro,x as so,y as io,z as oo,R as lo,A as co,B as uo,P as mo,D as po,E as ho,F as go,G as fo,H as bo,I as vo,J as yo,N as wo,K as xo,L as ko,O as No,V as _o,Y as So,Z as Io,_ as Co,$ as Ao,a0 as Po,a1 as To,a2 as Ro,a3 as qo,a4 as Mo,a5 as $o,a6 as Oo,a7 as Eo,a8 as Do,a9 as jo,aa as Uo,ab as Bo,ac as Fo,ad as Ko,ae as Lo,af as Wo,ag as zo,ah as Jo,ai as Qo,aj as Go,ak as Ho,al as Vo,am as Yo,an as Xo,ao as Zo,ap as el,aq as tl,ar as al,as as nl,at as rl,au as sl,av as il,aw as nr,ax as ol}from"./vendor-UXzYZoAT.js";import{m as Me,A as Tt,u as Fs}from"./motion-BCvrfAt1.js";import{g as Ks,p as ll}from"./markdown-DMcD1LHz.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const l of s)if(l.type==="childList")for(const d of l.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&r(d)}).observe(document,{childList:!0,subtree:!0});function n(s){const l={};return s.integrity&&(l.integrity=s.integrity),s.referrerPolicy&&(l.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?l.credentials="include":s.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(s){if(s.ep)return;s.ep=!0;const l=n(s);fetch(s.href,l)}})();class cl extends Error{constructor(t,n,r,s){super(`Tandem API Validation Error [${n}] at ${t}: ${r.length} issues found.`),this.endpoint=t,this.status=n,this.issues=r,this.rawSnippet=s,this.name="TandemValidationError"}}const Vr=ie().or($t({id:ie().optional(),runID:ie().optional(),runId:ie().optional(),run_id:ie().optional(),sessionID:ie().optional(),sessionId:ie().optional(),session_id:ie().optional(),missionID:ie().optional(),missionId:ie().optional(),mission_id:ie().optional(),instanceID:ie().optional(),instanceId:ie().optional(),instance_id:ie().optional()})).transform(a=>typeof a=="string"?a:a.id||a.runID||a.runId||a.run_id||a.sessionID||a.sessionId||a.session_id||a.missionID||a.missionId||a.mission_id||a.instanceID||a.instanceId||a.instance_id);un().transform(a=>a);Tr(ie(),un()).transform(a=>a);const dl=$t({ready:mn().optional(),phase:ie().optional(),workspace_root:ie().optional(),workspaceRoot:ie().optional()}).passthrough().transform(a=>({...a,workspaceRoot:a.workspace_root??a.workspaceRoot})),Jn=$t({id:ie(),title:ie(),created_at_ms:ha().optional(),createdAtMs:ha().optional(),directory:ie().optional(),workspace_root:ie().optional(),workspaceRoot:ie().optional(),archived:mn().optional()}).passthrough().transform(a=>({...a,createdAtMs:a.created_at_ms??a.createdAtMs??0,workspaceRoot:a.workspace_root??a.workspaceRoot})),Yr=$t({sessions:Fa(Jn).optional().default([]),count:ha().optional().default(0)}).passthrough(),ul=$t({active:$t({runID:ie().optional(),runId:ie().optional(),run_id:ie().optional(),attachEventStream:ie().optional()}).passthrough().nullable().optional()}).passthrough().transform(a=>a.active?{active:{...a.active,runId:a.active.runId||a.active.runID||a.active.run_id}}:{active:null}),Ls=$t({ok:mn().optional(),runID:ie().optional(),runId:ie().optional(),run_id:ie().optional(),status:ie().optional()}).passthrough().transform(a=>({...a,runId:a.runId||a.runID||a.run_id})),Ws=$t({id:ie().optional(),runID:ie().optional(),runId:ie().optional(),run_id:ie().optional(),routine_id:ie().optional(),automation_id:ie().optional(),status:ie().optional(),started_at_ms:ha().optional(),finished_at_ms:ha().optional()}).passthrough().transform(a=>({...a,runId:a.runId||a.runID||a.run_id,routineId:a.routine_id,automationId:a.automation_id,startedAtMs:a.started_at_ms,finishedAtMs:a.finished_at_ms})),Xr=$t({ok:mn().default(!0),rev:ha().optional()}).passthrough(),zs=$t({key:ie(),value:un(),rev:ha().optional(),updated_at_ms:ha().optional(),updated_by:ie().optional()}).passthrough().transform(a=>({...a,updatedAtMs:a.updated_at_ms,updatedBy:a.updated_by})),ml=$t({items:Fa(zs).optional().default([]),count:ha().optional().default(0)}).passthrough(),pl=$t({id:ie().optional(),text:ie().optional(),content:ie().optional(),user_id:ie().optional(),userID:ie().optional(),source_type:ie().optional(),sourceType:ie().optional(),tags:Fa(ie()).optional(),source:ie().optional(),session_id:ie().optional(),sessionID:ie().optional(),run_id:ie().optional(),runID:ie().optional()}).passthrough().transform(a=>({...a,text:a.text||a.content,content:a.content||a.text,userId:a.userID||a.user_id,sourceType:a.sourceType||a.source_type,sessionId:a.session_id||a.sessionID,runId:a.run_id||a.runID})),hl=$t({items:Fa(pl).optional().default([]),count:ha().optional().default(0)}).passthrough(),gl=$t({id:ie(),text:ie().optional(),content:ie().optional(),score:ha().optional(),source_type:ie().optional(),sourceType:ie().optional(),run_id:ie().optional(),runID:ie().optional(),tags:Fa(ie()).optional()}).passthrough().transform(a=>({...a,text:a.text||a.content,content:a.content||a.text,sourceType:a.sourceType||a.source_type,runId:a.runID||a.run_id})),fl=$t({results:Fa(gl).optional().default([]),count:ha().optional().default(0)}).passthrough(),Js=$t({id:ie(),uri:ie(),parent_uri:ie().optional(),node_type:ie(),created_at:ie(),updated_at:ie(),metadata:Tr(ie(),un()).optional()}).passthrough(),bl=$t({l0_preview:ie().optional(),l1_preview:ie().optional(),has_l2:mn()}).passthrough(),vl=$t({node:Js,children:Fa(un()).optional().default([]),layer_summary:bl.optional()}).passthrough(),yl=$t({node:Js.optional()}).passthrough(),wl=$t({tree:Fa(vl).optional().default([])}).passthrough(),xl=$t({ok:mn(),distillation_id:ie().optional(),session_id:ie().optional(),facts_extracted:ha().optional()}).passthrough(),kl=$t({type:ie(),properties:Tr(ie(),un()).optional().default({}),sessionID:ie().optional(),session_id:ie().optional(),sessionId:ie().optional(),runID:ie().optional(),run_id:ie().optional(),runId:ie().optional(),timestamp:ie().optional()}).passthrough().transform(a=>({...a,properties:a.properties,sessionId:a.sessionId||a.sessionID||a.session_id,runId:a.runId||a.runID||a.run_id}));function jt(a,t,n,r){const s=a.safeParse(t);if(!s.success){const l=JSON.stringify(t).substring(0,200);throw new cl(n,r,s.error.issues,l)}return s.data}function Nl(a){const t=a.trim();if(!t||t===": keep-alive"||t.startsWith(":"))return null;try{const n=JSON.parse(t),r=kl.safeParse(n);return r.success?r.data:null}catch{return null}}async function*Ya(a,t,n){const r=n?.connectTimeoutMs??3e4,s=new AbortController,l=setTimeout(()=>s.abort(),r),d=n?.signal?_l([s.signal,n.signal]):s.signal;let u;try{u=await fetch(a,{headers:{Accept:"text/event-stream",Authorization:`Bearer ${t}`,"Cache-Control":"no-cache"},signal:d})}finally{clearTimeout(l)}if(!u.ok){const x=await u.text().catch(()=>"");throw new Error(`SSE connect failed (${u.status} ${u.statusText}): ${x}`)}if(!u.body)throw new Error("SSE response has no body");const p=new TextDecoder,_=u.body.getReader();let D="";try{for(;;){const{done:x,value:P}=await _.read();if(x)break;D+=p.decode(P,{stream:!0});const O=D.split(`
|
|
2
|
-
`);D=O.pop()??"";let k="";for(const J of O)if(J.startsWith("data:"))k+=J.slice(5).trimStart();else if(J===""&&k){const A=Nl(k);A&&(yield A),k=""}}}finally{_.releaseLock()}}function _l(a){const t=new AbortController;for(const n of a){if(n.aborted){t.abort(n.reason);break}n.addEventListener("abort",()=>t.abort(n.reason),{once:!0})}return t.signal}const da=a=>typeof a=="string"&&a.trim().length>0?a:null,Sl=a=>{try{const t=Vr.parse(a);if(t)return t}catch{const t=a.run||null;if(t)try{const n=Vr.parse(t);if(n)return n}catch{}}throw new Error("Run ID missing in engine response")};class Il{constructor(t){this.baseUrl=t.baseUrl.replace(/\/+$/,""),this.token=t.token,this.timeoutMs=t.timeoutMs??2e4;const n=this._request.bind(this);this.sessions=new Tl(this.baseUrl,this.token,this.timeoutMs,n),this.permissions=new Rl(n),this.questions=new ql(n),this.providers=new Ml(n),this.identity=new $l(n),this.channels=new Ol(n),this.mcp=new El(n,this._requestText.bind(this));const r=()=>this.token;this.routines=new Ll(this.baseUrl,r,n),this.automations=new zl(this.baseUrl,r,n),this.automationsV2=new Jl(this.baseUrl,r,n),this.optimizations=new Ql(n),this.workflowPlans=new Wl(n),this.memory=new Dl(n),this.skills=new jl(n),this.packs=new Ul(n),this.capabilities=new Bl(n),this.resources=new Fl(this.baseUrl,r,n),this.browser=new Cl(n),this.workflows=new Al(this.baseUrl,r,n),this.bugMonitor=new Pl(n),this.coder=new Kl(n),this.agentTeams=new Gl(n),this.missions=new Hl(n)}setToken(t){this.token=t,this.sessions.setToken(t)}async health(){const t=await this._request("/global/health");return jt(dl,t,"/global/health",200)}async listToolIds(){return this._request("/tool/ids")}async listTools(){const t=await this._request("/tool");return Array.isArray(t)?t:[]}async executeTool(t,n){return this._request("/tool/execute",{method:"POST",body:JSON.stringify({tool:t,args:n??{}})})}stream(t,n,r){const s=new URLSearchParams({sessionID:t});n&&s.set("runID",n);const l=`${this.baseUrl}/event?${s.toString()}`;return Ya(l,this.token,r)}globalStream(t){const n=`${this.baseUrl}/global/event`;return Ya(n,this.token,t)}async runEvents(t,n){const r=new URLSearchParams;n?.sinceSeq!==void 0&&r.set("since_seq",String(n.sinceSeq)),n?.tail!==void 0&&r.set("tail",String(n.tail));const s=r.toString()?`?${r.toString()}`:"",l=await this._request(`/run/${encodeURIComponent(t)}/events${s}`);return Array.isArray(l)?l:[]}async _request(t,n={}){const r=new AbortController,s=setTimeout(()=>r.abort(),this.timeoutMs);let l;try{l=await fetch(`${this.baseUrl}${t}`,{...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers??{}},signal:r.signal})}catch(d){throw d instanceof Error&&d.name==="AbortError"?new Error(`Request timed out after ${this.timeoutMs}ms: ${t}`):d}finally{clearTimeout(s)}if(l.status!==204){if(!l.ok){const d=await l.text().catch(()=>"");throw new Error(`Request failed (${l.status} ${l.statusText}): ${d}`)}return l.json()}}async _requestText(t,n={}){const r=new AbortController,s=setTimeout(()=>r.abort(),this.timeoutMs);let l;try{l=await fetch(`${this.baseUrl}${t}`,{...n,headers:{Authorization:`Bearer ${this.token}`,...n.headers??{}},signal:r.signal})}catch(d){throw d instanceof Error&&d.name==="AbortError"?new Error(`Request timed out after ${this.timeoutMs}ms: ${t}`):d}finally{clearTimeout(s)}if(!l.ok){const d=await l.text().catch(()=>"");throw new Error(`Request failed (${l.status} ${l.statusText}): ${d}`)}return l.text()}}class Cl{constructor(t){this.req=t}async status(){return this.req("/browser/status")}async install(){return this.req("/browser/install",{method:"POST"})}async smokeTest(t){return this.req("/browser/smoke-test",{method:"POST",body:JSON.stringify(t??{})})}}class Al{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(){const n=await this.req("/workflows")??{},r=Array.isArray(n.workflows)?n.workflows:[];return{workflows:r,count:typeof n.count=="number"?n.count:r.length}}async get(t){return(await this.req(`/workflows/${encodeURIComponent(t)}`)).workflow??{}}async validate(t){return this.req("/workflows/validate",{method:"POST",body:JSON.stringify(t??{})})}async simulate(t){return this.req("/workflows/simulate",{method:"POST",body:JSON.stringify(t)})}events(t){const n=new URLSearchParams,r=t?.workflow_id??t?.workflowId,s=t?.run_id??t?.runId;r&&n.set("workflow_id",r),s&&n.set("run_id",s);const l=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/workflows/events${l}`,this.getToken(),{signal:t?.signal})}async listRuns(t){const n=new URLSearchParams,r=t?.workflow_id??t?.workflowId;r&&n.set("workflow_id",r),t?.limit!==void 0&&n.set("limit",String(t.limit));const s=n.toString()?`?${n.toString()}`:"",d=await this.req(`/workflows/runs${s}`)??{},u=Array.isArray(d.runs)?d.runs:[];return{runs:u,count:typeof d.count=="number"?d.count:u.length}}async getRun(t){return(await this.req(`/workflows/runs/${encodeURIComponent(t)}`)).run??{}}async run(t,n){return this.req(`/workflows/${encodeURIComponent(t)}/run`,{method:"POST",body:JSON.stringify(n??{})})}async listHooks(t){const n=new URLSearchParams,r=t?.workflow_id??t?.workflowId;r&&n.set("workflow_id",r);const s=n.toString()?`?${n.toString()}`:"",d=await this.req(`/workflow-hooks${s}`)??{},u=Array.isArray(d.hooks)?d.hooks:[];return{hooks:u,count:typeof d.count=="number"?d.count:u.length}}async patchHook(t,n){return this.req(`/workflow-hooks/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}}class Pl{constructor(t){this.req=t}async getConfig(){return this.req("/config/bug-monitor")}async patchConfig(t){return this.req("/config/bug-monitor",{method:"PATCH",body:JSON.stringify(t)})}async getStatus(){return this.req("/bug-monitor/status")}async recomputeStatus(){return this.req("/bug-monitor/status/recompute",{method:"POST"})}async pause(){return this.req("/bug-monitor/pause",{method:"POST"})}async resume(){return this.req("/bug-monitor/resume",{method:"POST"})}async debug(){return this.req("/bug-monitor/debug")}async listIncidents(t){const n=t?.limit!==void 0?`?limit=${t.limit}`:"";return this.req(`/bug-monitor/incidents${n}`)}async getIncident(t){return(await this.req(`/bug-monitor/incidents/${encodeURIComponent(t)}`)).incident??{}}async replayIncident(t,n){return this.req(`/bug-monitor/incidents/${encodeURIComponent(t)}/replay`,{method:"POST",body:JSON.stringify(n??{})})}async listDrafts(t){const n=t?.limit!==void 0?`?limit=${t.limit}`:"";return this.req(`/bug-monitor/drafts${n}`)}async listPosts(t){const n=t?.limit!==void 0?`?limit=${t.limit}`:"";return this.req(`/bug-monitor/posts${n}`)}async getDraft(t){return(await this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}`)).draft??{}}async approveDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n})})}async denyDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n})})}async report(t){return this.req("/bug-monitor/report",{method:"POST",body:JSON.stringify(t)})}async createTriageRun(t){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/triage-run`,{method:"POST"})}async createTriageSummary(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/triage-summary`,{method:"POST",body:JSON.stringify(n)})}async createIssueDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/issue-draft`,{method:"POST",body:JSON.stringify(n??{})})}async publishDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/publish`,{method:"POST",body:JSON.stringify(n??{})})}async recheckMatch(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/recheck-match`,{method:"POST",body:JSON.stringify(n??{})})}}class Tl{constructor(t,n,r,s){this.baseUrl=t,this.token=n,this.timeoutMs=r,this.req=s}setToken(t){this.token=t}async create(t={}){const n={title:t.title??"Tandem SDK Session",directory:t.directory??"."};return t.permissions&&(n.permission=t.permissions),t.model&&t.provider&&(n.model={providerID:t.provider,modelID:t.model},n.provider=t.provider),(await this.req("/session",{method:"POST",body:JSON.stringify(n)})).id}async list(t={}){const n=new URLSearchParams;t.q&&n.set("q",t.q),t.page!==void 0&&n.set("page",String(t.page)),t.pageSize!==void 0&&n.set("page_size",String(t.pageSize)),t.archived!==void 0&&n.set("archived",String(t.archived)),t.scope&&n.set("scope",t.scope),t.workspace&&n.set("workspace",t.workspace);const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/session${r}`);return jt(Yr,s,"/session",200)}async get(t){const n=await this.req(`/session/${encodeURIComponent(t)}`);return jt(Jn,n,`/session/${t}`,200)}async update(t,n){const r=await this.req(`/session/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)});return jt(Jn,r,`/session/${t}`,200)}async archive(t){return this.update(t,{archived:!0})}async delete(t){await this.req(`/session/${encodeURIComponent(t)}`,{method:"DELETE"})}async messages(t){return this.req(`/session/${encodeURIComponent(t)}/message`)}async todos(t){const n=await this.req(`/session/${encodeURIComponent(t)}/todo`);return Array.isArray(n)?n:n.todos??[]}async activeRun(t){const n=await this.req(`/session/${encodeURIComponent(t)}/run`);return jt(ul,n,`/session/${t}/run`,200)}async promptAsync(t,n,r,s){return this.promptAsyncParts(t,[{type:"text",text:n}],r,s)}async promptAsyncParts(t,n,r,s){const l={parts:n};r?.provider&&r?.model&&(l.model={providerID:r.provider,modelID:r.model}),s?.toolMode&&(l.toolMode=s.toolMode),s?.toolAllowlist?.length&&(l.toolAllowlist=s.toolAllowlist),s?.contextMode&&(l.contextMode=s.contextMode);const d=`/session/${encodeURIComponent(t)}/prompt_async?return=run`,u=new AbortController,p=setTimeout(()=>u.abort(),this.timeoutMs);let _;try{_=await fetch(`${this.baseUrl}${d}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify(l),signal:u.signal})}finally{clearTimeout(p)}if(_.status===409){const P=(await _.json().catch(()=>({}))).activeRun,O=da(P?.runID)||da(P?.runId)||da(P?.run_id);if(O)return{runId:O}}if(!_.ok){const x=await _.text().catch(()=>"");throw new Error(`promptAsyncParts failed (${_.status}): ${x}`)}const D=await _.json();return{runId:Sl(D)}}async promptSync(t,n){const r={parts:[{type:"text",text:n}]},s=await this.req(`/session/${encodeURIComponent(t)}/prompt_sync`,{method:"POST",body:JSON.stringify(r)});return da(s.reply)||da(s.text)||da(s.output)||""}async abort(t){return this.req(`/session/${encodeURIComponent(t)}/abort`,{method:"POST",body:JSON.stringify({})})}async cancel(t){return this.req(`/session/${encodeURIComponent(t)}/cancel`,{method:"POST",body:JSON.stringify({})})}async cancelRun(t,n){return this.req(`/session/${encodeURIComponent(t)}/run/${encodeURIComponent(n)}/cancel`,{method:"POST",body:JSON.stringify({})})}async fork(t){const n=await this.req(`/session/${encodeURIComponent(t)}/fork`,{method:"POST",body:JSON.stringify({})});return jt(Jn,n,`/session/${t}/fork`,200)}async diff(t){return this.req(`/session/${encodeURIComponent(t)}/diff`)}async revert(t){return this.req(`/session/${encodeURIComponent(t)}/revert`,{method:"POST",body:JSON.stringify({})})}async unrevert(t){return this.req(`/session/${encodeURIComponent(t)}/unrevert`,{method:"POST",body:JSON.stringify({})})}async children(t){const n=await this.req(`/session/${encodeURIComponent(t)}/children`);return jt(Yr,n,`/session/${t}/children`,200).sessions}async summarize(t){return this.req(`/session/${encodeURIComponent(t)}/summarize`,{method:"POST",body:JSON.stringify({})})}async attach(t,n){return this.req(`/session/${encodeURIComponent(t)}/attach`,{method:"POST",body:JSON.stringify({target_workspace:n})})}}class Rl{constructor(t){this.req=t}async list(){return this.req("/permission")}async reply(t,n){const r=await this.req(`/permission/${encodeURIComponent(t)}/reply`,{method:"POST",body:JSON.stringify({reply:n})});if(!r.ok)throw new Error(`Permission reply rejected: ${r.error??t}`);return{ok:!0}}}class ql{constructor(t){this.req=t}async list(){const t=await this.req("/question");return Array.isArray(t)?{questions:t}:t}async reply(t,n){return this.req(`/question/${encodeURIComponent(t)}/reply`,{method:"POST",body:JSON.stringify({answer:n})})}async reject(t){return this.req(`/question/${encodeURIComponent(t)}/reject`,{method:"POST",body:JSON.stringify({})})}}class Ml{constructor(t){this.req=t}async catalog(){return this.req("/provider")}async config(){return this.req("/config/providers")}async setDefaults(t,n){await this.req("/config",{method:"PATCH",body:JSON.stringify({default_provider:t,providers:{[t]:{default_model:n}}})})}async setApiKey(t,n){await this.req(`/auth/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({apiKey:n})})}async authStatus(){return this.req("/provider/auth")}}class $l{constructor(t){this.req=t}async get(){return this.req("/config/identity")}async patch(t){return this.req("/config/identity",{method:"PATCH",body:JSON.stringify(t)})}}class Ol{constructor(t){this.req=t}async config(){return this.req("/channels/config")}async status(){return this.req("/channels/status")}async put(t,n){return this.req(`/channels/${t}`,{method:"PUT",body:JSON.stringify(n)})}async delete(t){return this.req(`/channels/${t}`,{method:"DELETE"})}async verify(t,n={}){return this.req(`/channels/${t}/verify`,{method:"POST",body:JSON.stringify(n)})}}class El{constructor(t,n){this.req=t,this.reqText=n}async list(){return this.req("/mcp")}async listTools(){return this.req("/mcp/tools")}async listResources(){const t=await this.req("/mcp/resources");return Array.isArray(t)?t:[]}async add(t){return this.req("/mcp",{method:"POST",body:JSON.stringify(t)})}async connect(t){return this.req(`/mcp/${encodeURIComponent(t)}/connect`,{method:"POST"})}async disconnect(t){return this.req(`/mcp/${encodeURIComponent(t)}/disconnect`,{method:"POST"})}async refresh(t){return this.req(`/mcp/${encodeURIComponent(t)}/refresh`,{method:"POST"})}async setEnabled(t,n){return this.req(`/mcp/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({enabled:n})})}async delete(t){return this.req(`/mcp/${encodeURIComponent(t)}`,{method:"DELETE"})}async auth(t,n){return this.req(`/mcp/${encodeURIComponent(t)}/auth`,{method:"POST",body:JSON.stringify(n??{})})}async deleteAuth(t){return this.req(`/mcp/${encodeURIComponent(t)}/auth`,{method:"DELETE"})}async authCallback(t,n){return this.req(`/mcp/${encodeURIComponent(t)}/auth/callback`,{method:"POST",body:JSON.stringify(n)})}async authenticate(t,n){return this.req(`/mcp/${encodeURIComponent(t)}/auth/authenticate`,{method:"POST",body:JSON.stringify(n??{})})}async catalogToml(t){if(!this.reqText)throw new Error("Text request helper unavailable");return this.reqText(`/mcp/catalog/${encodeURIComponent(t)}/toml`)}}class Dl{constructor(t){this.req=t}async put(t){return this.req("/memory/put",{method:"POST",body:JSON.stringify(t)})}async search(t){const n=await this.req("/memory/search",{method:"POST",body:JSON.stringify(t)});return jt(fl,n,"/memory/search",200)}async list(t){const n=new URLSearchParams;t?.q&&n.set("q",t.q),t?.limit!==void 0&&n.set("limit",String(t.limit)),t?.offset!==void 0&&n.set("offset",String(t.offset)),t?.userId&&n.set("user_id",t.userId);const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/memory${r}`);return jt(hl,s,"/memory",200)}async delete(t){return this.req(`/memory/${encodeURIComponent(t)}`,{method:"DELETE"})}async promote(t){return this.req("/memory/promote",{method:"POST",body:JSON.stringify(t)})}async demote(t){const n={id:t.id,run_id:t.runId};return this.req("/memory/demote",{method:"POST",body:JSON.stringify(n)})}async audit(t){const n=new URLSearchParams;t?.run_id&&n.set("run_id",t.run_id),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/memory/audit${r}`);return Array.isArray(s)?{entries:s,count:s.length}:s}async contextResolveUri(t){const n=await this.req("/memory/context/resolve",{method:"POST",body:JSON.stringify({uri:t})});return jt(yl,n,"/memory/context/resolve",200)}async contextTree(t,n){const r=new URLSearchParams;r.set("uri",t),n!==void 0&&r.set("max_depth",String(n));const s=r.toString()?`?${r.toString()}`:"",l=await this.req(`/memory/context/tree${s}`);return jt(wl,l,"/memory/context/tree",200)}async contextGenerateLayers(t){return this.req("/memory/context/layers/generate",{method:"POST",body:JSON.stringify({node_id:t})})}async contextDistill(t,n){const r=await this.req("/memory/context/distill",{method:"POST",body:JSON.stringify({session_id:t,conversation:n})});return jt(xl,r,"/memory/context/distill",200)}}class jl{constructor(t){this.req=t}async list(t){const n=t?`?location=${encodeURIComponent(t)}`:"",r=await this.req(`/skills${n}`);return Array.isArray(r)?{skills:r,count:r.length}:r}async get(t){return this.req(`/skills/${encodeURIComponent(t)}`)}async import(t){const n={content:t.content,file_or_path:t.file_or_path??t.fileOrPath,location:t.location,namespace:t.namespace,conflict_policy:t.conflict_policy??t.conflictPolicy};return this.req("/skills/import",{method:"POST",body:JSON.stringify(n)})}async preview(t){const n={content:t.content,file_or_path:t.file_or_path??t.fileOrPath,location:t.location,namespace:t.namespace,conflict_policy:t.conflict_policy??t.conflictPolicy};return this.req("/skills/import/preview",{method:"POST",body:JSON.stringify(n)})}async templates(){const t=await this.req("/skills/templates");return Array.isArray(t)?{templates:t,count:t.length}:t}async catalog(){const t=await this.req("/skills/catalog"),n=Array.isArray(t)?t:[];return{skills:n,count:n.length}}async validate(t){const n={content:t.content,file_or_path:t.file_or_path??t.fileOrPath};return this.req("/skills/validate",{method:"POST",body:JSON.stringify(n)})}async match(t){const n={goal:t.goal,max_matches:t.max_matches??t.maxMatches,threshold:t.threshold};return this.req("/skills/router/match",{method:"POST",body:JSON.stringify(n)})}async evalBenchmark(t){const n={threshold:t.threshold,cases:t.cases.map(r=>({prompt:r.prompt,expected_skill:r.expected_skill??r.expectedSkill}))};return this.req("/skills/evals/benchmark",{method:"POST",body:JSON.stringify(n)})}async evalTriggers(t){const n={skill_name:t.skill_name??t.skillName,prompts:t.prompts,threshold:t.threshold};return this.req("/skills/evals/triggers",{method:"POST",body:JSON.stringify(n)})}async compile(t){const n={skill_name:t.skill_name??t.skillName,goal:t.goal,threshold:t.threshold,max_matches:t.max_matches??t.maxMatches,schedule:t.schedule};return this.req("/skills/compile",{method:"POST",body:JSON.stringify(n)})}async generate(t){return this.req("/skills/generate",{method:"POST",body:JSON.stringify(t)})}async generateInstall(t){const n={prompt:t.prompt,threshold:t.threshold,location:t.location,conflict_policy:t.conflictPolicy,artifacts:t.artifacts?{"SKILL.md":t.artifacts["SKILL.md"],"workflow.yaml":t.artifacts["workflow.yaml"],"automation.example.yaml":t.artifacts["automation.example.yaml"]}:void 0};return this.req("/skills/generate/install",{method:"POST",body:JSON.stringify(n)})}}class Ul{constructor(t){this.req=t}async list(){return this.req("/packs")}async inspect(t){return this.req(`/packs/${encodeURIComponent(t)}`)}async install(t){return this.req("/packs/install",{method:"POST",body:JSON.stringify(t)})}async installFromAttachment(t){return this.req("/packs/install_from_attachment",{method:"POST",body:JSON.stringify(t)})}async uninstall(t){return this.req("/packs/uninstall",{method:"POST",body:JSON.stringify(t)})}async export(t){return this.req("/packs/export",{method:"POST",body:JSON.stringify(t)})}async detect(t){return this.req("/packs/detect",{method:"POST",body:JSON.stringify(t)})}async updates(t){const r=await this.req(`/packs/${encodeURIComponent(t)}/updates`)||{},s=Array.isArray(r.updates)?r.updates:[];return{pack_id:da(r.pack_id)??void 0,name:da(r.name)??void 0,current_version:da(r.current_version)??void 0,updates:s}}async update(t,n){const r=await this.req(`/packs/${encodeURIComponent(t)}/update`,{method:"POST",body:JSON.stringify(n??{})});return{updated:!!r.updated,pack_id:da(r.pack_id)??void 0,name:da(r.name)??void 0,current_version:da(r.current_version)??void 0,target_version:da(r.target_version)??void 0,reason:da(r.reason)??void 0}}}class Bl{constructor(t){this.req=t}async getBindings(){return(await this.req("/capabilities/bindings")).bindings}async setBindings(t){return this.req("/capabilities/bindings",{method:"PUT",body:JSON.stringify(t)})}async discovery(){return this.req("/capabilities/discovery")}async resolve(t){return this.req("/capabilities/resolve",{method:"POST",body:JSON.stringify(t)})}async readiness(t){return this.req("/capabilities/readiness",{method:"POST",body:JSON.stringify(t)})}}class Fl{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(t){const n=new URLSearchParams;t?.prefix&&n.set("prefix",t.prefix),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/resource${r}`);return jt(ml,s,"/resource",200)}async write(t){return this.req("/resource",{method:"PUT",body:JSON.stringify(t)})}async get(t){const n=await this.req(`/resource/${encodeURIComponent(t)}`);return jt(zs,n,`/resource/${t}`,200)}async putKey(t,n,r){const s=await this.req(`/resource/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({value:n,...r??{}})});return jt(Xr,s,`/resource/${t}`,200)}async patchKey(t,n){const r=await this.req(`/resource/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)});return jt(Xr,r,`/resource/${t}`,200)}async delete(t,n){return this.req("/resource",{method:"DELETE",body:JSON.stringify({key:t,...n})})}async deleteKey(t){return this.req(`/resource/${encodeURIComponent(t)}`,{method:"DELETE"})}events(t){const n=new URLSearchParams;t?.sinceSeq!==void 0&&n.set("since_seq",String(t.sinceSeq)),t?.tail!==void 0&&n.set("tail",String(t.tail));const r=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/resource/events${r}`,this.getToken())}}class Kl{constructor(t){this.req=t}async createRun(t){return this.req("/coder/runs",{method:"POST",body:JSON.stringify(t)})}async listRuns(t){const n=new URLSearchParams;t?.limit!==void 0&&n.set("limit",String(t.limit));const r=t?.workflow_mode??t?.workflowMode,s=t?.repo_slug??t?.repoSlug;r&&n.set("workflow_mode",r),s&&n.set("repo_slug",s);const l=n.toString()?`?${n.toString()}`:"",u=await this.req(`/coder/runs${l}`)??{},p=Array.isArray(u.runs)?u.runs:[];return{runs:p,count:typeof u.count=="number"?u.count:p.length}}async getRun(t){const r=await this.req(`/coder/runs/${encodeURIComponent(t)}`)??{};return{...r,coderRun:r.coder_run??void 0,coder_run:r.coder_run??void 0,run:r.run??void 0}}async executeNext(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/execute-next`,{method:"POST",body:JSON.stringify(n??{})})}async executeAll(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/execute-all`,{method:"POST",body:JSON.stringify(n??{})})}async createFollowOnRun(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/follow-on-run`,{method:"POST",body:JSON.stringify(n)})}async approveRun(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n})})}async cancelRun(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/cancel`,{method:"POST",body:JSON.stringify({reason:n})})}async listArtifacts(t){const r=await this.req(`/coder/runs/${encodeURIComponent(t)}/artifacts`)??{},s=Array.isArray(r.artifacts)?r.artifacts:[];return{...r,artifacts:s,count:typeof r.count=="number"?r.count:s.length}}async getMemoryHits(t,n){const r=new URLSearchParams;n?.query&&r.set("q",n.query),n?.limit!==void 0&&r.set("limit",String(n.limit));const s=r.toString()?`?${r.toString()}`:"",d=await this.req(`/coder/runs/${encodeURIComponent(t)}/memory-hits${s}`)??{},u=Array.isArray(d.hits)?d.hits:[];return{...d,hits:u,count:typeof d.count=="number"?d.count:u.length}}async createTriageInspectionReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/triage-inspection-report`,{method:"POST",body:JSON.stringify(n)})}async createTriageReproductionReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/triage-reproduction-report`,{method:"POST",body:JSON.stringify(n)})}async createTriageSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/triage-summary`,{method:"POST",body:JSON.stringify(n)})}async createPrReviewEvidence(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-review-evidence`,{method:"POST",body:JSON.stringify(n)})}async createPrReviewSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-review-summary`,{method:"POST",body:JSON.stringify(n)})}async createIssueFixValidationReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/issue-fix-validation-report`,{method:"POST",body:JSON.stringify(n)})}async createIssueFixSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/issue-fix-summary`,{method:"POST",body:JSON.stringify(n)})}async createPrDraft(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-draft`,{method:"POST",body:JSON.stringify(n??{})})}async submitPr(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-submit`,{method:"POST",body:JSON.stringify(n??{})})}async createMergeReadinessReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/merge-readiness-report`,{method:"POST",body:JSON.stringify(n)})}async createMergeRecommendationSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/merge-recommendation-summary`,{method:"POST",body:JSON.stringify(n)})}async listMemoryCandidates(t){const r=await this.req(`/coder/runs/${encodeURIComponent(t)}/memory-candidates`)??{},s=Array.isArray(r.candidates)?r.candidates:[];return{...r,candidates:s,count:typeof r.count=="number"?r.count:s.length}}async createMemoryCandidate(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/memory-candidates`,{method:"POST",body:JSON.stringify(n)})}async promoteMemoryCandidate(t,n,r){return this.req(`/coder/runs/${encodeURIComponent(t)}/memory-candidates/${encodeURIComponent(n)}/promote`,{method:"POST",body:JSON.stringify(r??{})})}}class Ll{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(){return this.req("/routines")}async create(t){const n={...t};return"prompt"in n&&!("entrypoint"in n)&&(n.entrypoint=n.prompt),this.req("/routines",{method:"POST",body:JSON.stringify(n)})}async update(t,n){return this.req(`/routines/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async delete(t){await this.req(`/routines/${encodeURIComponent(t)}`,{method:"DELETE"})}async runNow(t){const n=await this.req(`/routines/${encodeURIComponent(t)}/run_now`,{method:"POST",body:JSON.stringify({})});return jt(Ls,n,`/routines/${t}/run_now`,200)}async listRuns(t){const n=new URLSearchParams;t?.routine_id&&n.set("routine_id",t.routine_id),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"";return this.req(`/routines/runs${r}`)}async getRunsForRoutine(t,n=25){return this.req(`/routines/${encodeURIComponent(t)}/runs?limit=${n}`)}async getRun(t){const n=await this.req(`/routines/runs/${encodeURIComponent(t)}`);return jt(Ws,n,`/routines/runs/${t}`,200)}async listArtifacts(t){return this.req(`/routines/runs/${encodeURIComponent(t)}/artifacts`)}async approveRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n??""})})}async denyRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n??""})})}async pauseRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resumeRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({reason:n??""})})}async history(t,n){const r=n!==void 0?`?limit=${n}`:"",s=await this.req(`/routines/${encodeURIComponent(t)}/history${r}`);return Array.isArray(s)?{history:s,count:s.length}:s}events(t){const n=new URLSearchParams,r=t?.routine_id??t?.routineId;r&&n.set("routine_id",r);const s=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/routines/events${s}`,this.getToken(),{signal:t?.signal})}addArtifact(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/artifacts`,{method:"POST",body:JSON.stringify(n)})}}class Wl{constructor(t){this.req=t}async preview(t){return this.req("/workflow-plans/preview",{method:"POST",body:JSON.stringify({prompt:t.prompt,schedule:t.schedule,plan_source:t.plan_source??t.planSource,allowed_mcp_servers:t.allowed_mcp_servers??t.allowedMcpServers,workspace_root:t.workspace_root??t.workspaceRoot,operator_preferences:t.operator_preferences??t.operatorPreferences})})}async apply(t){return this.req("/workflow-plans/apply",{method:"POST",body:JSON.stringify({plan_id:t.plan_id??t.planId,plan:t.plan,creator_id:t.creator_id??t.creatorId,pack_builder_export:t.pack_builder_export??t.packBuilderExport})})}async chatStart(t){return this.req("/workflow-plans/chat/start",{method:"POST",body:JSON.stringify({prompt:t.prompt,schedule:t.schedule,plan_source:t.plan_source??t.planSource,allowed_mcp_servers:t.allowed_mcp_servers??t.allowedMcpServers,workspace_root:t.workspace_root??t.workspaceRoot,operator_preferences:t.operator_preferences??t.operatorPreferences})})}async get(t){return this.req(`/workflow-plans/${encodeURIComponent(t)}`)}async chatMessage(t){return this.req("/workflow-plans/chat/message",{method:"POST",body:JSON.stringify({plan_id:t.plan_id??t.planId,message:t.message})})}async chatReset(t){return this.req("/workflow-plans/chat/reset",{method:"POST",body:JSON.stringify({plan_id:t.plan_id??t.planId})})}}class zl{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(){return this.req("/automations")}async create(t){return this.req("/automations",{method:"POST",body:JSON.stringify(t)})}async update(t,n){return this.req(`/automations/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async delete(t){await this.req(`/automations/${encodeURIComponent(t)}`,{method:"DELETE"})}async runNow(t){const n=await this.req(`/automations/${encodeURIComponent(t)}/run_now`,{method:"POST",body:JSON.stringify({})});return jt(Ls,n,`/automations/${t}/run_now`,200)}async listRuns(t){const n=new URLSearchParams;t?.automation_id&&n.set("automation_id",t.automation_id),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"";return this.req(`/automations/runs${r}`)}async getRunsForAutomation(t,n=25){return this.req(`/automations/${encodeURIComponent(t)}/runs?limit=${n}`)}async getRun(t){const n=await this.req(`/automations/runs/${encodeURIComponent(t)}`);return jt(Ws,n,`/automations/runs/${t}`,200)}async listArtifacts(t){return this.req(`/automations/runs/${encodeURIComponent(t)}/artifacts`)}async approveRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n??""})})}async denyRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n??""})})}async pauseRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resumeRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({reason:n??""})})}async history(t,n){const r=n!==void 0?`?limit=${n}`:"",s=await this.req(`/automations/${encodeURIComponent(t)}/history${r}`);return Array.isArray(s)?{history:s,count:s.length}:s}events(t){const n=new URLSearchParams,r=t?.automation_id??t?.automationId,s=t?.run_id??t?.runId;r&&n.set("automation_id",r),s&&n.set("run_id",s);const l=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/automations/events${l}`,this.getToken(),{signal:t?.signal})}addArtifact(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/artifacts`,{method:"POST",body:JSON.stringify(n)})}}class Jl{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async create(t){return this.req("/automations/v2",{method:"POST",body:JSON.stringify(t)})}async list(){return this.req("/automations/v2")}async get(t){return this.req(`/automations/v2/${encodeURIComponent(t)}`)}async update(t,n){return this.req(`/automations/v2/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async delete(t){return this.req(`/automations/v2/${encodeURIComponent(t)}`,{method:"DELETE"})}async runNow(t){return this.req(`/automations/v2/${encodeURIComponent(t)}/run_now`,{method:"POST",body:JSON.stringify({})})}async pause(t,n){return this.req(`/automations/v2/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resume(t){return this.req(`/automations/v2/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({})})}async listRuns(t,n=50){return this.req(`/automations/v2/${encodeURIComponent(t)}/runs?limit=${n}`)}async getRun(t){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}`)}async pauseRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resumeRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({reason:n??""})})}async recoverRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/recover`,{method:"POST",body:JSON.stringify({reason:n??""})})}async repairRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/repair`,{method:"POST",body:JSON.stringify(n)})}async retryTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/retry`,{method:"POST",body:JSON.stringify({reason:r??""})})}async previewTaskReset(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/reset_preview`)}async continueTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/continue`,{method:"POST",body:JSON.stringify({reason:r??""})})}async requeueTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/requeue`,{method:"POST",body:JSON.stringify({reason:r??""})})}async claimBacklogTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/backlog/tasks/${encodeURIComponent(n)}/claim`,{method:"POST",body:JSON.stringify(r||{})})}async requeueBacklogTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/backlog/tasks/${encodeURIComponent(n)}/requeue`,{method:"POST",body:JSON.stringify({reason:r??""})})}async cancelRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/cancel`,{method:"POST",body:JSON.stringify({reason:n??""})})}events(t){const n=new URLSearchParams,r=t?.automation_id??t?.automationId,s=t?.run_id??t?.runId;r&&n.set("automation_id",r),s&&n.set("run_id",s);const l=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/automations/v2/events${l}`,this.getToken(),{signal:t?.signal})}}class Ql{constructor(t){this.req=t}async list(){return this.req("/optimizations")}async create(t){return this.req("/optimizations",{method:"POST",body:JSON.stringify(t)})}async get(t){return this.req(`/optimizations/${encodeURIComponent(t)}`)}async action(t,n){return this.req(`/optimizations/${encodeURIComponent(t)}/actions`,{method:"POST",body:JSON.stringify(n)})}async listExperiments(t){return this.req(`/optimizations/${encodeURIComponent(t)}/experiments`)}async getExperiment(t,n){return this.req(`/optimizations/${encodeURIComponent(t)}/experiments/${encodeURIComponent(n)}`)}async applyWinner(t,n){return this.req(`/optimizations/${encodeURIComponent(t)}/experiments/${encodeURIComponent(n)}`,{method:"POST",body:JSON.stringify({})})}}class Gl{constructor(t){this.req=t}async listTemplates(){return this.req("/agent-team/templates")}async createTemplate(t){return this.req("/agent-team/templates",{method:"POST",body:JSON.stringify(t)})}async updateTemplate(t,n){return this.req(`/agent-team/templates/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async deleteTemplate(t){return this.req(`/agent-team/templates/${encodeURIComponent(t)}`,{method:"DELETE"})}async composeStandup(t){return this.req("/agent-standup/compose",{method:"POST",body:JSON.stringify({name:t.name,workspace_root:t.workspaceRoot,schedule:t.schedule,participant_template_ids:t.participantTemplateIds,report_path_template:t.reportPathTemplate})})}async listInstances(t){const n=new URLSearchParams;t?.missionID&&n.set("missionID",t.missionID),t?.parentInstanceID&&n.set("parentInstanceID",t.parentInstanceID),t?.status&&n.set("status",t.status);const r=n.toString()?`?${n.toString()}`:"";return this.req(`/agent-team/instances${r}`)}async listMissions(){return this.req("/agent-team/missions")}async listApprovals(){return this.req("/agent-team/approvals")}async spawn(t){return this.req("/agent-team/spawn",{method:"POST",body:JSON.stringify(t)})}async approveSpawn(t,n){return this.req(`/agent-team/approvals/spawn/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n??""})})}async denySpawn(t,n){return this.req(`/agent-team/approvals/spawn/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n??""})})}}class Hl{constructor(t){this.req=t}async list(){return this.req("/mission")}async create(t){return this.req("/mission",{method:"POST",body:JSON.stringify(t)})}async get(t){return this.req(`/mission/${encodeURIComponent(t)}`)}async applyEvent(t,n){return this.req(`/mission/${encodeURIComponent(t)}/event`,{method:"POST",body:JSON.stringify({event:n})})}}const Xn="charcoal_fire",ln=[{id:"charcoal_fire",name:"Charcoal & Fire",description:"Deep charcoal surfaces with solar-yellow power accents and crimson security cues.",cssVars:{"--color-background":"#121212","--color-surface":"#141414","--color-surface-elevated":"#1a1a1a","--color-border":"rgba(245, 245, 245, 0.10)","--color-border-subtle":"rgba(245, 245, 245, 0.06)","--color-primary":"#F59E0B","--color-primary-hover":"#D97706","--color-primary-muted":"#B45309","--color-secondary":"#EF4444","--color-secondary-hover":"#DC2626","--color-success":"#10B981","--color-warning":"#F59E0B","--color-error":"#EF4444","--color-text":"#F5F5F5","--color-text-muted":"rgba(245, 245, 245, 0.70)","--color-text-subtle":"rgba(245, 245, 245, 0.50)","--color-glass":"rgba(255, 255, 255, 0.03)","--color-glass-border":"rgba(255, 255, 255, 0.08)","--font-sans":'"Manrope", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(245, 158, 11, 0.16)","--tcp-glow-b":"rgba(239, 68, 68, 0.12)"}},{id:"electric_blue",name:"Electric Blue",description:"The original Tandem look: electric-blue primary with purple secondary.",cssVars:{"--color-background":"#0a0a0f","--color-surface":"#12121a","--color-surface-elevated":"#1a1a24","--color-border":"#2a2a3a","--color-border-subtle":"#1f1f2e","--color-primary":"#3b82f6","--color-primary-hover":"#2563eb","--color-primary-muted":"#1d4ed8","--color-secondary":"#8b5cf6","--color-secondary-hover":"#7c3aed","--color-success":"#10b981","--color-warning":"#f59e0b","--color-error":"#ef4444","--color-text":"#f8fafc","--color-text-muted":"#94a3b8","--color-text-subtle":"#64748b","--color-glass":"rgba(18, 18, 26, 0.8)","--color-glass-border":"rgba(255, 255, 255, 0.1)","--font-sans":'"Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(59, 130, 246, 0.16)","--tcp-glow-b":"rgba(139, 92, 246, 0.12)"}},{id:"emerald_night",name:"Emerald Night",description:"Dark glass with emerald primary and cyan secondary highlights.",cssVars:{"--color-background":"#0b1010","--color-surface":"#0f1616","--color-surface-elevated":"#142020","--color-border":"rgba(226, 232, 240, 0.12)","--color-border-subtle":"rgba(226, 232, 240, 0.08)","--color-primary":"#10B981","--color-primary-hover":"#059669","--color-primary-muted":"#047857","--color-secondary":"#22D3EE","--color-secondary-hover":"#06B6D4","--color-success":"#22C55E","--color-warning":"#F59E0B","--color-error":"#EF4444","--color-text":"#F1F5F9","--color-text-muted":"rgba(241, 245, 249, 0.72)","--color-text-subtle":"rgba(241, 245, 249, 0.52)","--color-glass":"rgba(15, 22, 22, 0.75)","--color-glass-border":"rgba(255, 255, 255, 0.10)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(16, 185, 129, 0.16)","--tcp-glow-b":"rgba(34, 211, 238, 0.12)"}},{id:"hello_bunny",name:"Hello Bunny",description:"Soft pink glass with berry accents and a cozy, playful vibe.",cssVars:{"--color-background":"#140A12","--color-surface":"#1C0E1A","--color-surface-elevated":"#251022","--color-border":"rgba(255, 228, 242, 0.12)","--color-border-subtle":"rgba(255, 228, 242, 0.08)","--color-primary":"#FB7185","--color-primary-hover":"#F43F5E","--color-primary-muted":"#E11D48","--color-secondary":"#C084FC","--color-secondary-hover":"#A855F7","--color-success":"#34D399","--color-warning":"#FBBF24","--color-error":"#FB7185","--color-text":"#FFEAF4","--color-text-muted":"rgba(255, 234, 244, 0.74)","--color-text-subtle":"rgba(255, 234, 244, 0.52)","--color-glass":"rgba(255, 255, 255, 0.04)","--color-glass-border":"rgba(255, 228, 242, 0.10)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(251, 113, 133, 0.16)","--tcp-glow-b":"rgba(192, 132, 252, 0.12)"}},{id:"porcelain",name:"Porcelain",description:"Plain, bright whites with soft pastel accents and glassy structure.",cssVars:{"--color-background":"#F8FAFC","--color-surface":"#FFFFFF","--color-surface-elevated":"#F1F5F9","--color-border":"rgba(15, 23, 42, 0.12)","--color-border-subtle":"rgba(15, 23, 42, 0.08)","--color-primary":"#6366F1","--color-primary-hover":"#4F46E5","--color-primary-muted":"#4338CA","--color-secondary":"#F472B6","--color-secondary-hover":"#EC4899","--color-success":"#10B981","--color-warning":"#F59E0B","--color-error":"#EF4444","--color-text":"#0F172A","--color-text-muted":"rgba(15, 23, 42, 0.70)","--color-text-subtle":"rgba(15, 23, 42, 0.50)","--color-glass":"rgba(255, 255, 255, 0.72)","--color-glass-border":"rgba(15, 23, 42, 0.10)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(99, 102, 241, 0.13)","--tcp-glow-b":"rgba(244, 114, 182, 0.11)"}},{id:"neon_riot",name:"Neon Riot",description:"Electric cyan and magenta over deep space surfaces.",cssVars:{"--color-background":"#050014","--color-surface":"#0B0720","--color-surface-elevated":"#140A3A","--color-border":"rgba(248, 250, 252, 0.16)","--color-border-subtle":"rgba(248, 250, 252, 0.10)","--color-primary":"#00E5FF","--color-primary-hover":"#00B8D4","--color-primary-muted":"#00838F","--color-secondary":"#FF3DF5","--color-secondary-hover":"#D500F9","--color-success":"#22C55E","--color-warning":"#FBBF24","--color-error":"#FB7185","--color-text":"#F8FAFC","--color-text-muted":"rgba(248, 250, 252, 0.72)","--color-text-subtle":"rgba(248, 250, 252, 0.52)","--color-glass":"rgba(5, 0, 20, 0.55)","--color-glass-border":"rgba(255, 255, 255, 0.14)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(0, 229, 255, 0.20)","--tcp-glow-b":"rgba(255, 61, 245, 0.14)"}},{id:"cosmic_glass",name:"Cosmic Glass",description:"Transparent nebula glass panels with deep-space glow.",cssVars:{"--color-background":"#03020F","--color-surface":"rgba(9, 6, 28, 0.72)","--color-surface-elevated":"rgba(18, 12, 40, 0.82)","--color-border":"rgba(120, 105, 255, 0.22)","--color-border-subtle":"rgba(120, 105, 255, 0.12)","--color-primary":"#7C5CFF","--color-primary-hover":"#6A40FF","--color-primary-muted":"#4C2ED8","--color-secondary":"#FF7AD9","--color-secondary-hover":"#FF4FC3","--color-success":"#3BE4C0","--color-warning":"#F9D86B","--color-error":"#FF5C7A","--color-text":"#F3F0FF","--color-text-muted":"rgba(243, 240, 255, 0.74)","--color-text-subtle":"rgba(243, 240, 255, 0.52)","--color-glass":"rgba(14, 10, 40, 0.48)","--color-glass-border":"rgba(255, 255, 255, 0.16)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(124, 92, 255, 0.20)","--tcp-glow-b":"rgba(255, 122, 217, 0.14)"}},{id:"pink_pony",name:"Pink Pony",description:"Candy pinks and dreamy pastels with brighter glass accents.",cssVars:{"--color-background":"#240818","--color-surface":"rgba(56, 12, 38, 0.94)","--color-surface-elevated":"rgba(72, 16, 48, 0.96)","--color-border":"rgba(255, 184, 217, 0.36)","--color-border-subtle":"rgba(255, 184, 217, 0.22)","--color-primary":"#FF5FB1","--color-primary-hover":"#FF3B9A","--color-primary-muted":"#D91E7D","--color-secondary":"#FFB8E6","--color-secondary-hover":"#FF98D8","--color-success":"#58E5C1","--color-warning":"#FFD166","--color-error":"#FF5C8A","--color-text":"#FFF7FC","--color-text-muted":"rgba(255, 247, 252, 0.86)","--color-text-subtle":"rgba(255, 247, 252, 0.68)","--color-glass":"rgba(74, 17, 50, 0.78)","--color-glass-border":"rgba(255, 220, 238, 0.30)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(255, 95, 177, 0.20)","--tcp-glow-b":"rgba(255, 184, 230, 0.14)"}},{id:"zen_dusk",name:"Zen Dusk",description:"Muted green dusk tones for calmer long-session work.",cssVars:{"--color-background":"#0B1110","--color-surface":"#101716","--color-surface-elevated":"#141D1C","--color-border":"rgba(226, 232, 240, 0.12)","--color-border-subtle":"rgba(226, 232, 240, 0.06)","--color-primary":"#7CC8A4","--color-primary-hover":"#6AB690","--color-primary-muted":"#559B7B","--color-secondary":"#9FB8B0","--color-secondary-hover":"#8AA59C","--color-success":"#5EC79B","--color-warning":"#E6C17B","--color-error":"#E38B8B","--color-text":"#E6EFEA","--color-text-muted":"rgba(230, 239, 234, 0.72)","--color-text-subtle":"rgba(230, 239, 234, 0.50)","--color-glass":"rgba(20, 28, 26, 0.72)","--color-glass-border":"rgba(255, 255, 255, 0.08)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(124, 200, 164, 0.16)","--tcp-glow-b":"rgba(159, 184, 176, 0.12)"}}],Aa={duration:{normal:.22},easing:{standard:[.22,1,.36,1]},spring:{gentle:{type:"spring",stiffness:220,damping:26,mass:.9},snappy:{type:"spring",stiffness:320,damping:30,mass:.82},drawer:{type:"spring",stiffness:340,damping:34,mass:.82}}};function Rr(a){let t=String(a||"").trim()||Xn;return t==="web_control"&&(t=Xn),ln.find(n=>n.id===t)||ln[0]}function Vl(a){const t=Rr(a).id,n=ln.findIndex(r=>r.id===t);return n<0?Xn:ln[(n+1)%ln.length].id}function Qs(a,t=typeof document<"u"?document.documentElement:null){const n=Rr(a);if(!t)return n;for(const[r,s]of Object.entries(n.cssVars))s!=null&&t.style.setProperty(r,s);return t.dataset.theme=n.id,t.style.colorScheme=n.id==="porcelain"?"light":"dark",n}function Gs(){return typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Hs="tandem.themeId";function Yl(){try{const a=localStorage.getItem(Hs);return Rr(a).id}catch{return Xn}}function Xl(a){return Qs(a)}function Zl(a){const t=Qs(a);try{localStorage.setItem(Hs,t.id)}catch{}return t}function qn(){const[a,t]=w(()=>Gs());return be(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>t(n.matches);return r(),typeof n.addEventListener=="function"?(n.addEventListener("change",r),()=>n.removeEventListener("change",r)):(n.addListener(r),()=>n.removeListener(r))},[]),a}function ec(a,t,n){return Math.min(n,Math.max(t,a))}function Zn({className:a="",children:t}){return e("div",{className:`tcp-glow-layer ${a}`.trim(),children:t})}function Mn({className:a="",children:t}){const n=qn();return e(Me.div,{className:a,initial:n?!1:{opacity:0,y:14},animate:n?void 0:{opacity:1,y:0},exit:n?void 0:{opacity:0,y:-10},transition:n?void 0:{duration:Aa.duration.normal,ease:Aa.easing.standard},children:t})}function tc({className:a="",children:t}){const n=qn();return e(Me.div,{className:a,initial:n?!1:"hidden",animate:n?void 0:"show",variants:n?void 0:{hidden:{},show:{transition:{staggerChildren:.06,delayChildren:.02}}},children:t})}function Vs({className:a="",children:t,as:n="div"}){const r=qn(),s=n==="section"?Me.section:n==="article"?Me.article:Me.div;return e(s,{className:a,variants:r?void 0:{hidden:{opacity:0,y:12,scale:.985},show:{opacity:1,y:0,scale:1,transition:{duration:Aa.duration.normal,ease:Aa.easing.standard}}},initial:r?!1:"hidden",animate:r?void 0:"show",children:t})}function ac({value:a,format:t=r=>String(r),className:n=""}){const r=qn(),[s,l]=w(()=>Number(a||0)),d=Pt(Number(a||0));return be(()=>{const u=Number(a||0);if(!Number.isFinite(u)){l(0),d.current=0;return}if(r){l(u),d.current=u;return}const p=d.current,_=u-p;if(!_){l(u),d.current=u;return}const D=performance.now();let x=0;const P=O=>{const k=ec((O-D)/420,0,1),J=1-Math.pow(1-k,3),A=p+_*J;l(A),k<1?x=window.requestAnimationFrame(P):d.current=u};return x=window.requestAnimationFrame(P),()=>window.cancelAnimationFrame(x)},[r,a]),e("span",{className:n,children:t(Number.isFinite(s)?s:0)})}function ka({tone:a="ok",text:t,className:n=""}){return e("span",{className:`tcp-status-pulse ${a} ${n}`.trim(),children:[e("span",{className:"tcp-status-pulse-dot","aria-hidden":"true"}),t?e("span",{children:t}):null]})}function va({className:a="",children:t}){return e("div",{className:`tcp-toolbar ${a}`.trim(),children:t})}function Nn({className:a="",title:t,children:n,...r}){return e("button",{type:"button",title:t,className:`tcp-icon-btn ${a}`.trim(),...r,children:n})}function je({tone:a="info",className:t="",children:n}){return e("span",{className:`${a==="ok"?"tcp-badge-ok":a==="warn"?"tcp-badge-warn":a==="err"?"tcp-badge-err":a==="ghost"?"tcp-badge tcp-badge-ghost":"tcp-badge-info"} ${t}`.trim(),children:n})}function or({active:a=!1,className:t="",children:n,...r}){return e("button",{type:"button",className:`tcp-filter-chip ${a?"active":""} ${t}`.trim(),...r,children:n})}function ft({title:a,subtitle:t,actions:n,className:r="",children:s}){return e(Vs,{as:"section",className:`tcp-panel-card ${r}`.trim(),children:[a||t||n?e("div",{className:"tcp-panel-card-head",children:[e("div",{className:"min-w-0",children:[a?e("h3",{className:"tcp-title",children:a}):null,t?e("p",{className:"tcp-subtle mt-1",children:t}):null]}),n?e("div",{className:"shrink-0",children:n}):null]}):null,s]})}function nc({text:a,title:t="Nothing here yet",action:n,className:r=""}){return e("div",{className:`tcp-empty-state ${r}`.trim(),children:[e("div",{className:"tcp-empty-state-orb"}),e("div",{className:"relative z-10",children:[e("div",{className:"tcp-empty-state-title",children:t}),e("p",{className:"tcp-subtle mt-1",children:a}),n?e("div",{className:"mt-3",children:n}):null]})]})}function rc({eyebrow:a,title:t,subtitle:n,badges:r,actions:s,className:l=""}){return e(Vs,{className:`tcp-page-header ${l}`.trim(),children:[e(Zn,{className:"tcp-page-header-glow"}),e("div",{className:"relative z-10 flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[e("div",{className:"min-w-0",children:[a?e("div",{className:"tcp-page-eyebrow",children:a}):null,e("h1",{className:"tcp-page-title",children:t}),n?e("p",{className:"tcp-subtle mt-2 max-w-3xl",children:n}):null,r?e("div",{className:"mt-3 flex flex-wrap gap-2",children:r}):null]}),s?e(va,{className:"justify-start lg:justify-end",children:s}):null]})]})}function In({className:a="",mainClassName:t="",asideClassName:n="",main:r,aside:s}){return e("div",{className:`tcp-split-view ${a}`.trim(),children:[e("div",{className:`min-w-0 ${t}`.trim(),children:r}),s?e("div",{className:`min-w-0 ${n}`.trim(),children:s}):null]})}function er({open:a,title:t,onClose:n,children:r}){const s=qn();return e(Tt,{children:a?e(Me.div,{className:"tcp-drawer-root",initial:s?!1:{opacity:0},animate:s?void 0:{opacity:1},exit:s?void 0:{opacity:0},children:[e("button",{type:"button",className:"tcp-drawer-backdrop","aria-label":"Close",onClick:n}),e(Me.aside,{className:"tcp-drawer-panel",initial:s?!1:{x:"100%"},animate:s?void 0:{x:0},exit:s?void 0:{x:"100%"},transition:s?void 0:Aa.spring.drawer,children:[e("div",{className:"tcp-drawer-head",children:[e("div",{className:"min-w-0",children:t?e("h3",{className:"tcp-title",children:t}):null}),e(Nn,{title:"Close drawer",onClick:n,children:e("i",{"data-lucide":"x"})})]}),e("div",{className:"min-h-0 flex-1 overflow-auto p-4",children:r})]})]}):null})}function sc({loginMutation:a,savedToken:t,onCheckEngine:n,controlPanelName:r}){const[s,l]=w(t),[d,u]=w(!0),[p,_]=w(""),[D,x]=w(!1);return e("main",{className:"relative min-h-screen overflow-hidden px-5 py-8",children:[e(Zn,{className:"tcp-shell-background",children:[e("div",{className:"tcp-shell-glow tcp-shell-glow-a"}),e("div",{className:"tcp-shell-glow tcp-shell-glow-b"})]}),e("div",{className:"relative z-10 mx-auto grid min-h-[calc(100vh-4rem)] w-full max-w-6xl items-center gap-6 lg:grid-cols-[1.05fr_0.95fr]",children:[e("section",{className:"grid gap-4",children:[e("div",{className:"tcp-page-eyebrow",children:"Tandem Control"}),e("h1",{className:"tcp-page-title max-w-3xl",children:"Sign in to continue."}),e("p",{className:"tcp-subtle max-w-2xl text-base",children:"Enter your engine token to access chat, orchestrator, automations, memory, live feed, and settings."})]}),e(ft,{title:r,subtitle:"Authenticate against your Tandem engine to continue.",children:e("form",{className:"grid gap-3",onSubmit:P=>{if(P.preventDefault(),!s.trim()){x(!1),_("Token is required.");return}a.mutate({token:s.trim(),remember:d})},children:[e("label",{className:"text-sm tcp-subtle",children:"Engine token"}),e("input",{className:"tcp-input",type:"password",value:s,onInput:P=>l(P.target.value),placeholder:"tk_...",autoComplete:"off"}),e("label",{className:"inline-flex items-center gap-2 text-xs tcp-subtle",children:[e("input",{type:"checkbox",className:"h-4 w-4 accent-slate-400",checked:d,onChange:P=>u(P.target.checked)}),"Remember token on this browser"]}),e("div",{className:"grid gap-2 sm:grid-cols-2",children:[e("button",{disabled:a.isPending,type:"submit",className:"tcp-btn-primary w-full",children:[e("i",{"data-lucide":"key-round"}),"Sign in"]}),e("button",{type:"button",className:"tcp-btn w-full",onClick:async()=>{try{const P=await n();x(!0),_(P)}catch(P){x(!1),_(P instanceof Error?P.message:String(P))}},children:[e("i",{"data-lucide":"activity"}),"Check engine"]})]}),e("div",{className:`min-h-[1.2rem] text-sm ${D?"text-lime-300":"text-rose-300"}`,children:a.error?.message||p}),e("div",{className:"rounded-xl border border-slate-700/60 bg-slate-950/30 p-3",children:[e("div",{className:"mb-2 flex items-center justify-between gap-3",children:[e("div",{className:"font-medium",children:"Readiness"}),e(ka,{tone:D?"ok":"warn",text:D?"Engine reachable":"Waiting"})]}),e("p",{className:"tcp-subtle text-xs",children:"Connectivity checks are non-destructive and help verify the local panel can reach the engine before authentication."})]})]})})]})]})}function ic(a){be(()=>{const t=n=>{(n.metaKey||n.ctrlKey)&&n.key.toLowerCase()==="k"&&(n.preventDefault(),a())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[a])}function oc({open:a,onClose:t,actions:n}){const[r,s]=w("");be(()=>{a||s("")},[a]),be(()=>{if(!a)return;const d=u=>{u.key==="Escape"&&t()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a,t]);const l=L(()=>{const d=r.trim().toLowerCase();return d?n.filter(u=>`${u.label} ${u.group}`.toLowerCase().includes(d)):n},[n,r]);return e(Tt,{children:a?e(Me.div,{className:"tcp-confirm-overlay",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:t,children:e(Me.div,{className:"tcp-doc-dialog w-[min(44rem,96vw)]",initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.98},transition:{duration:.16,ease:"easeOut"},onClick:d=>d.stopPropagation(),children:[e("div",{className:"tcp-doc-header",children:[e("h3",{className:"tcp-doc-title",children:"Command Palette"}),e("kbd",{className:"tcp-subtle text-xs",children:"Ctrl/Cmd + K"})]}),e("div",{className:"p-3",children:[e("input",{autoFocus:!0,value:r,onInput:d=>s(d.target.value),placeholder:"Jump to route or action",className:"tcp-input"}),e("div",{className:"mt-3 grid max-h-[50vh] gap-2 overflow-auto",children:[l.map(d=>e("button",{type:"button",className:"tcp-btn w-full justify-between",onClick:()=>{d.onSelect(),t()},children:[e("span",{className:"inline-flex items-center gap-1.5",children:[e("i",{"data-lucide":"list"}),e("span",{children:d.label})]}),e("span",{className:"tcp-subtle text-xs",children:d.group})]},d.id)),l.length?null:e("p",{className:"tcp-subtle px-1 py-2",children:"No matching action."})]})]})]})}):null})}const Ys=[["dashboard","Dashboard","home"],["chat","Chat","message-square"],["studio","Studio","network"],["automations","Automations","bot"],["agents","Agents","users"],["orchestrator","Orchestrator","sparkles"],["memory","Memory","database"],["feed","Live Feed","radio"],["settings","Settings","settings"],["packs","Packs","package"],["teams","Teams","users"],["channels","Channels","message-circle"],["mcp","MCP","link"],["bug-monitor","Bug Monitor","bug-play"],["files","Files","folder-open"],["packs-detail","Packs","package"],["teams-detail","Teams","users"]],lc=Ys.filter(([a])=>["dashboard","chat","studio","automations","agents","orchestrator","memory","feed","settings"].includes(a)),Xs={openai:{label:"OpenAI",keyUrl:"https://platform.openai.com/api-keys",placeholder:"sk-proj-..."},anthropic:{label:"Anthropic",keyUrl:"https://console.anthropic.com/settings/keys",placeholder:"sk-ant-..."},google:{label:"Google",keyUrl:"https://aistudio.google.com/app/apikey",placeholder:"AIza..."},groq:{label:"Groq",keyUrl:"https://console.groq.com/keys",placeholder:"gsk_..."},mistral:{label:"Mistral",keyUrl:"https://console.mistral.ai/api-keys/",placeholder:"..."},together:{label:"Together",keyUrl:"https://api.together.xyz/settings/api-keys",placeholder:"..."},cohere:{label:"Cohere",keyUrl:"https://dashboard.cohere.com/api-keys",placeholder:"..."},openrouter:{label:"OpenRouter",keyUrl:"https://openrouter.ai/settings/keys",placeholder:"sk-or-v1-..."},azure:{label:"Azure OpenAI",keyUrl:"https://portal.azure.com/",placeholder:"..."},bedrock:{label:"Bedrock",keyUrl:"https://console.aws.amazon.com/bedrock/",placeholder:"..."},vertex:{label:"Vertex",keyUrl:"https://console.cloud.google.com/vertex-ai",placeholder:"..."},copilot:{label:"GitHub Copilot",keyUrl:"https://github.com/settings/tokens",placeholder:"ghp_..."},ollama:{label:"Ollama",keyUrl:"",placeholder:"No key required"}},Zs=Ys,cc=lc,dc=new Map([["packs","automations"],["teams","automations"],["swarm","orchestrator"],["failure-reporter","bug-monitor"]]),uc=new Set(Zs.map(([a])=>a));function qr(a,t="dashboard"){const n=dc.get(String(a||"").trim());return n||(uc.has(a)?a:t)}function Zr(a="dashboard"){const t=(window.location.hash||`#/${a}`).replace(/^#\//,"");return qr(t.split("?")[0].split("/")[0].trim(),a)}function mc(a){window.location.hash=`#/${a}`}function pc(){const[a,t]=w(()=>Zr());be(()=>{const r=()=>t(Zr());return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const n=ut(r=>{const s=qr(r);if(window.location.hash!==`#/${s}`){mc(s);return}t(s)},[]);return{route:a,navigate:n}}const ei=Oi({toast:()=>{}});function hc({children:a}){const[t,n]=w([]),r=ut((l,d)=>{const u=Math.random().toString(36).slice(2);n(p=>[...p,{id:u,kind:l,text:d}].slice(-4)),window.setTimeout(()=>{n(p=>p.filter(_=>_.id!==u))},3500)},[]),s=L(()=>({toast:r}),[r]);return e(ei.Provider,{value:s,children:[a,e("div",{className:"toasts","aria-live":"polite","aria-atomic":"true",children:e(Tt,{children:t.map(l=>e(Me.div,{initial:{opacity:0,y:-8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.16,ease:"easeOut"},className:`toast toast-${l.kind}`,children:l.text},l.id))})})]})}function gc(){return Ei(ei)}function Kt({title:a,subtitle:t,children:n,actions:r,className:s}){return e(ft,{title:a,subtitle:t,actions:r,className:s||"",children:n})}function We({text:a,title:t,action:n}){return e(nc,{text:a,title:t,action:n})}function Ht(a){return JSON.stringify(a,null,2)}function lr(a,t){return Array.isArray(a)?a:Array.isArray(a?.[t])?a[t]:[]}function fc(a){return new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1}).format(Number(a||0))}function bc(a){const{api:t,client:n,navigate:r,providerStatus:s}=a,[l,d]=w(""),u=new Set(["workflow","bug_monitor_triage"]),p=Z({queryKey:["dashboard","health"],queryFn:()=>t("/api/system/health"),refetchInterval:15e3}),_=Z({queryKey:["dashboard","sessions"],queryFn:()=>n.sessions.list({pageSize:8}).catch(()=>[]),refetchInterval:15e3}),D=Z({queryKey:["dashboard","routines"],queryFn:()=>n.routines.list().catch(()=>({routines:[]})),refetchInterval:2e4}),x=Z({queryKey:["dashboard","swarm"],queryFn:()=>t("/api/swarm/status").catch(()=>({status:"unknown",activeRuns:0})),refetchInterval:6e3}),P=Z({queryKey:["dashboard","workflow-context-runs"],queryFn:()=>t("/api/engine/context/runs?limit=12").catch(()=>({runs:[]})),refetchInterval:6e3}),O=Z({queryKey:["dashboard","workflow-context-run",l],enabled:!!l,queryFn:()=>t(`/api/engine/context/runs/${encodeURIComponent(l)}`).catch(()=>({run:null}))}),k=Z({queryKey:["dashboard","workflow-context-blackboard",l],enabled:!!l,queryFn:()=>t(`/api/engine/context/runs/${encodeURIComponent(l)}/blackboard`).catch(()=>({blackboard:null}))}),J=lr(_.data,"sessions"),A=lr(D.data,"routines"),G=lr(P.data,"runs").filter(R=>u.has(String(R?.run_type||"").trim().toLowerCase())),ee=!!(p.data?.engine?.ready||p.data?.engine?.healthy),de=String(x.data?.status||"unknown"),S=["planning","awaiting_approval","running","executing"].includes(de.toLowerCase()),I=G.filter(R=>["queued","planning","running","awaiting_approval"].includes(String(R?.status||"").trim().toLowerCase())),Q=L(()=>[{label:"Recent sessions",value:J.length,tone:"info",helper:"Latest active conversation surfaces"},{label:"Automations",value:A.length,tone:"ok",helper:"Configured routines and schedules"},{label:"Swarm status",value:S?1:0,tone:S?"warn":"ghost",helper:de},{label:"Provider ready",value:s.ready?1:0,tone:s.ready?"ok":"warn",helper:s.ready?s.defaultModel:"Needs setup"},{label:"Context runs",value:G.length,tone:I.length?"warn":"info",helper:I.length?`${I.length} active`:"Workflow + triage visibility"}],[I.length,s.defaultModel,s.ready,A.length,J.length,S,de,G.length]);return e(Mn,{className:"grid gap-4",children:[e(ft,{className:"overflow-hidden",children:[e("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)] xl:items-start",children:[e("div",{className:"min-w-0",children:[e("div",{className:"tcp-page-eyebrow",children:"Overview"}),e("h1",{className:"tcp-page-title",children:"Command center"}),e("p",{className:"tcp-subtle mt-2 max-w-3xl",children:"A higher-signal home screen with animated state, quick entry points, and a clearer read on what the system is doing right now."}),e("div",{className:"mt-3 flex flex-wrap gap-2",children:[e(je,{tone:ee?"ok":"warn",children:ee?"Engine healthy":"Engine checking"}),e(je,{tone:s.ready?"ok":"warn",children:s.ready?s.defaultProvider:"Provider setup required"}),S?e(ka,{tone:"live",text:`Swarm ${de}`}):e(je,{tone:"ghost",children:["Swarm ",de]})]})]}),e("div",{className:"grid gap-3",children:e(va,{className:"justify-start",children:[e("button",{className:"tcp-btn-primary w-full sm:w-auto",onClick:()=>r("chat"),children:[e("i",{"data-lucide":"message-square"}),"Chat session"]}),e("button",{className:"tcp-btn w-full sm:w-auto",onClick:()=>r("orchestrator"),children:[e("i",{"data-lucide":"sparkles"}),"Plan work"]}),e("button",{className:"tcp-btn w-full sm:w-auto",onClick:()=>r("automations"),children:[e("i",{"data-lucide":"bot"}),"Automations"]}),e("button",{className:"tcp-btn w-full sm:w-auto",onClick:()=>r("settings"),children:[e("i",{"data-lucide":"settings"}),"Configure runtime"]})]})})]}),e("div",{className:"mt-5",children:[e("div",{className:"dashboard-kpis",children:Q.map(R=>e("div",{children:[e("div",{className:"flex items-start justify-between gap-3",children:[e("span",{className:"dashboard-kpi-label",children:R.label}),e(je,{tone:R.tone,children:R.helper})]}),e("strong",{children:e(ac,{value:R.value,format:fc})})]},R.label))}),e("div",{className:"mt-4 dashboard-bars",children:[e("div",{className:"dashboard-bar-row",children:[e("div",{className:"dashboard-bar-meta",children:[e("span",{children:"Engine readiness"}),e("span",{className:"dashboard-bar-count",children:ee?"100%":"45%"})]}),e("div",{className:"dashboard-bar-track",children:e("span",{className:"dashboard-bar-fill completed",style:{width:ee?"100%":"45%"}})})]}),e("div",{className:"dashboard-bar-row",children:[e("div",{className:"dashboard-bar-meta",children:[e("span",{children:"Provider confidence"}),e("span",{className:"dashboard-bar-count",children:s.ready?"100%":"30%"})]}),e("div",{className:"dashboard-bar-track",children:e("span",{className:`dashboard-bar-fill ${s.ready?"running":"queued"}`,style:{width:s.ready?"100%":"30%"}})})]}),e("div",{className:"dashboard-bar-row",children:[e("div",{className:"dashboard-bar-meta",children:[e("span",{children:"Automation activity"}),e("span",{className:"dashboard-bar-count",children:[A.length," routines"]})]}),e("div",{className:"dashboard-bar-track",children:e("span",{className:`dashboard-bar-fill ${A.length?"scheduled":"manual"}`,style:{width:`${Math.min(100,Math.max(12,A.length*12))}%`}})})]})]})]})]}),e(In,{main:e(ft,{title:"Recent sessions",subtitle:"Latest conversations, ready to reopen.",children:e("div",{className:"grid gap-2",children:J.length?J.map(R=>e("button",{className:"tcp-list-item text-left",onClick:()=>r("chat"),children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"messages-square"}),String(R.title||R.id||"Session")]}),e("div",{className:"tcp-subtle mt-1 text-xs",children:String(R.id||R.session_id||"")})]},String(R.id||R.session_id||Math.random()))):e(We,{text:"Start a conversation to populate recent sessions here."})})}),aside:e("div",{className:"grid gap-4",children:[e(ft,{title:"Context visibility",subtitle:"Recent workflow and failure-triage context runs with their current projection state.",children:[e(va,{className:"mb-3",children:[e(je,{tone:I.length?"warn":"info",children:[G.length," recent"]}),e("button",{className:"tcp-btn",onClick:()=>r("orchestrator"),children:[e("i",{"data-lucide":"workflow"}),"Open orchestrator"]})]}),e("div",{className:"grid gap-2",children:G.length?G.slice(0,5).map(R=>e("button",{className:"tcp-list-item text-left",onClick:()=>d(String(R?.run_id||"").trim()),children:[e("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e("div",{className:"font-medium",children:String(R?.objective||R?.run_id||"Context run")}),e("div",{className:"flex flex-wrap items-center gap-2",children:[e(je,{tone:"ghost",children:String(R?.run_type||"context")}),e(je,{tone:["failed","cancelled"].includes(String(R?.status||"").toLowerCase())?"err":["running","queued","planning"].includes(String(R?.status||"").toLowerCase())?"warn":"ok",children:String(R?.status||"unknown")})]})]}),e("div",{className:"tcp-subtle text-xs",children:String(R?.run_id||"")}),e("div",{className:"tcp-subtle mt-1 text-xs",children:[Array.isArray(R?.tasks)?R.tasks.length:0," tasks ·"," ",Array.isArray(R?.steps)?R.steps.length:0," steps"]})]},String(R?.run_id||Math.random()))):e(We,{text:"Workflow and failure-triage context runs will appear here once they execute."})})]}),e(ft,{title:"Automation snapshot",subtitle:"Schedules and run-ready routines.",children:[e(va,{className:"mb-3",children:[e(je,{tone:"info",children:[A.length," loaded"]}),e("button",{className:"tcp-btn",onClick:()=>r("automations"),children:[e("i",{"data-lucide":"bot"}),"Manage"]})]}),e("div",{className:"grid gap-2",children:A.length?A.slice(0,4).map(R=>e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium",children:String(R.name||R.id||"Routine")}),e("div",{className:"tcp-subtle mt-1 text-xs",children:String(R.schedule||R.status||"manual")})]},String(R.id||R.routine_id||Math.random()))):e(We,{text:"No routines are configured yet."})})]}),e(ft,{title:"Health notes",subtitle:"Direct links for the next likely action.",children:e("div",{className:"grid gap-2",children:[e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"activity"}),"Engine endpoint"]}),e("div",{className:"tcp-subtle mt-1 text-xs",children:String(p.data?.engineUrl||"Unavailable")})]}),e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"radio"}),"Swarm"]}),e("div",{className:"tcp-subtle mt-1 text-xs",children:["Status: ",de]})]}),e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"database"}),"Memory & feed"]}),e("div",{className:"mt-2 flex flex-wrap gap-2",children:[e("button",{className:"tcp-btn h-8 px-3 text-xs",onClick:()=>r("memory"),children:"Open memory"}),e("button",{className:"tcp-btn h-8 px-3 text-xs",onClick:()=>r("feed"),children:"Open live feed"})]})]})]})})]})}),e(er,{open:!!l,onClose:()=>d(""),title:l||"Workflow context run",children:l?e("div",{className:"grid gap-3",children:[e("div",{className:"tcp-list-item",children:[e("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e("strong",{children:String(O.data?.run?.objective||l)}),e(je,{tone:"info",children:String(O.data?.run?.status||"unknown")})]}),e("div",{className:"tcp-subtle text-xs",children:["type: ",String(O.data?.run?.run_type||"workflow")]})]}),e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium mb-2",children:"Projected blackboard"}),e("div",{className:"tcp-subtle text-xs",children:["tasks:"," ",Array.isArray(k.data?.blackboard?.tasks)?k.data.blackboard.tasks.length:0," · ","artifacts:"," ",Array.isArray(k.data?.blackboard?.artifacts)?k.data.blackboard.artifacts.length:0]})]}),e("pre",{className:"tcp-code",children:Ht({run:O.data?.run||null,blackboard:k.data?.blackboard||null})})]}):null})]})}const vc={Activity:il,Archive:sl,ArrowLeftToLine:rl,ArrowUpCircle:nl,BadgeCheck:al,Binary:tl,Bug:el,BugPlay:Zo,Bot:Xo,BookOpen:Yo,Check:Vo,ChevronDown:Ho,ChevronRight:Go,ClipboardList:Qo,Clock:Jo,Clock3:zo,Copy:Wo,CopyPlus:Lo,ExternalLink:Ko,Cpu:Fo,Database:Bo,Download:Uo,FileUp:jo,Filter:Do,FilterX:Eo,FlaskConical:Oo,FolderOpen:$o,History:Mo,Home:qo,Info:Ro,KeyRound:To,Link:Po,LoaderCircle:Ao,List:Co,LogOut:Io,MessageCircle:So,MessageSquare:_o,MessagesSquare:No,Menu:ko,MonitorCog:xo,Network:wo,Paperclip:yo,Package:vo,PaintBucket:bo,Pencil:fo,Play:go,PlugZap:ho,Plus:po,Pause:mo,Radio:uo,RefreshCw:co,RotateCw:lo,Save:oo,Search:io,Send:so,Settings:ro,Settings2:no,ShieldAlert:ao,ShieldCheck:to,SlidersHorizontal:eo,Sparkles:Zi,Siren:Xi,Share2:Yi,Shield:Vi,Square:Hi,Trash2:Gi,TriangleAlert:Qi,X:Ji,XCircle:zi,Users:Wi,Workflow:Li},xr=new Set;let kr=0;function yc(){kr=0;const a=[...xr];xr.clear();for(const t of a)Ki({icons:vc,attrs:{width:"16",height:"16","stroke-width":"1.8"},...t?{root:t}:{}})}function ya(a){xr.add(a||null),!kr&&(kr=window.requestAnimationFrame(yc))}Ks.setOptions({gfm:!0,breaks:!0});function cn(a){const t=String(a||""),n=Ks.parse(t,{async:!1});return ll.sanitize(n)}const Nr="tcp.chat.session";function ti(a){return String(a?.id||a?.session_id||a?.sessionID||"").trim()}function wc(a){const t=String(a?.title||a?.name||"").trim();if(t)return t;const n=ti(a);return n?`Session ${n.slice(0,8)}`:"Session"}function xc(a){return Array.isArray(a)?a:Array.isArray(a?.sessions)?a.sessions:[]}function kc(a){return String(a?.title||"").trim().toLowerCase().startsWith("__provider_test__")}function es(a){return xc(a).filter(t=>!kc(t)).map(t=>({id:ti(t),title:wc(t),raw:t})).filter(t=>!!t.id)}async function Nc(a,t){try{const n=await a.sessions.list({pageSize:50}),r=es(n);if(r.length>0)return r}catch{}try{const n=await t("/api/engine/session?page_size=50",{method:"GET"});return es(n)}catch{return[]}}function ts(){try{return localStorage.getItem(Nr)||""}catch{return""}}function _c(a){try{a?localStorage.setItem(Nr,a):localStorage.removeItem(Nr)}catch{}}function Sc(a){return Array.isArray(a)?a.map(n=>n?typeof n=="string"?n:typeof n.text=="string"?n.text:typeof n.delta=="string"?n.delta:typeof n.content=="string"?n.content:"":"").filter(Boolean).join(`
|
|
2
|
+
`);D=O.pop()??"";let k="";for(const J of O)if(J.startsWith("data:"))k+=J.slice(5).trimStart();else if(J===""&&k){const A=Nl(k);A&&(yield A),k=""}}}finally{_.releaseLock()}}function _l(a){const t=new AbortController;for(const n of a){if(n.aborted){t.abort(n.reason);break}n.addEventListener("abort",()=>t.abort(n.reason),{once:!0})}return t.signal}const da=a=>typeof a=="string"&&a.trim().length>0?a:null,Sl=a=>{try{const t=Vr.parse(a);if(t)return t}catch{const t=a.run||null;if(t)try{const n=Vr.parse(t);if(n)return n}catch{}}throw new Error("Run ID missing in engine response")};class Il{constructor(t){this.baseUrl=t.baseUrl.replace(/\/+$/,""),this.token=t.token,this.timeoutMs=t.timeoutMs??2e4;const n=this._request.bind(this);this.sessions=new Tl(this.baseUrl,this.token,this.timeoutMs,n),this.permissions=new Rl(n),this.questions=new ql(n),this.providers=new Ml(n),this.identity=new $l(n),this.channels=new Ol(n),this.mcp=new El(n,this._requestText.bind(this));const r=()=>this.token;this.routines=new Ll(this.baseUrl,r,n),this.automations=new zl(this.baseUrl,r,n),this.automationsV2=new Jl(this.baseUrl,r,n),this.optimizations=new Ql(n),this.workflowPlans=new Wl(n),this.memory=new Dl(n),this.skills=new jl(n),this.packs=new Ul(n),this.capabilities=new Bl(n),this.resources=new Fl(this.baseUrl,r,n),this.browser=new Cl(n),this.workflows=new Al(this.baseUrl,r,n),this.bugMonitor=new Pl(n),this.coder=new Kl(n),this.agentTeams=new Gl(n),this.missions=new Hl(n)}setToken(t){this.token=t,this.sessions.setToken(t)}async health(){const t=await this._request("/global/health");return jt(dl,t,"/global/health",200)}async listToolIds(){return this._request("/tool/ids")}async listTools(){const t=await this._request("/tool");return Array.isArray(t)?t:[]}async executeTool(t,n){return this._request("/tool/execute",{method:"POST",body:JSON.stringify({tool:t,args:n??{}})})}stream(t,n,r){const s=new URLSearchParams({sessionID:t});n&&s.set("runID",n);const l=`${this.baseUrl}/event?${s.toString()}`;return Ya(l,this.token,r)}globalStream(t){const n=`${this.baseUrl}/global/event`;return Ya(n,this.token,t)}async runEvents(t,n){const r=new URLSearchParams;n?.sinceSeq!==void 0&&r.set("since_seq",String(n.sinceSeq)),n?.tail!==void 0&&r.set("tail",String(n.tail));const s=r.toString()?`?${r.toString()}`:"",l=await this._request(`/run/${encodeURIComponent(t)}/events${s}`);return Array.isArray(l)?l:[]}async _request(t,n={}){const r=new AbortController,s=setTimeout(()=>r.abort(),this.timeoutMs);let l;try{l=await fetch(`${this.baseUrl}${t}`,{...n,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`,...n.headers??{}},signal:r.signal})}catch(d){throw d instanceof Error&&d.name==="AbortError"?new Error(`Request timed out after ${this.timeoutMs}ms: ${t}`):d}finally{clearTimeout(s)}if(l.status!==204){if(!l.ok){const d=await l.text().catch(()=>"");throw new Error(`Request failed (${l.status} ${l.statusText}): ${d}`)}return l.json()}}async _requestText(t,n={}){const r=new AbortController,s=setTimeout(()=>r.abort(),this.timeoutMs);let l;try{l=await fetch(`${this.baseUrl}${t}`,{...n,headers:{Authorization:`Bearer ${this.token}`,...n.headers??{}},signal:r.signal})}catch(d){throw d instanceof Error&&d.name==="AbortError"?new Error(`Request timed out after ${this.timeoutMs}ms: ${t}`):d}finally{clearTimeout(s)}if(!l.ok){const d=await l.text().catch(()=>"");throw new Error(`Request failed (${l.status} ${l.statusText}): ${d}`)}return l.text()}}class Cl{constructor(t){this.req=t}async status(){return this.req("/browser/status")}async install(){return this.req("/browser/install",{method:"POST"})}async smokeTest(t){return this.req("/browser/smoke-test",{method:"POST",body:JSON.stringify(t??{})})}}class Al{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(){const n=await this.req("/workflows")??{},r=Array.isArray(n.workflows)?n.workflows:[];return{workflows:r,count:typeof n.count=="number"?n.count:r.length}}async get(t){return(await this.req(`/workflows/${encodeURIComponent(t)}`)).workflow??{}}async validate(t){return this.req("/workflows/validate",{method:"POST",body:JSON.stringify(t??{})})}async simulate(t){return this.req("/workflows/simulate",{method:"POST",body:JSON.stringify(t)})}events(t){const n=new URLSearchParams,r=t?.workflow_id??t?.workflowId,s=t?.run_id??t?.runId;r&&n.set("workflow_id",r),s&&n.set("run_id",s);const l=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/workflows/events${l}`,this.getToken(),{signal:t?.signal})}async listRuns(t){const n=new URLSearchParams,r=t?.workflow_id??t?.workflowId;r&&n.set("workflow_id",r),t?.limit!==void 0&&n.set("limit",String(t.limit));const s=n.toString()?`?${n.toString()}`:"",d=await this.req(`/workflows/runs${s}`)??{},u=Array.isArray(d.runs)?d.runs:[];return{runs:u,count:typeof d.count=="number"?d.count:u.length}}async getRun(t){return(await this.req(`/workflows/runs/${encodeURIComponent(t)}`)).run??{}}async run(t,n){return this.req(`/workflows/${encodeURIComponent(t)}/run`,{method:"POST",body:JSON.stringify(n??{})})}async listHooks(t){const n=new URLSearchParams,r=t?.workflow_id??t?.workflowId;r&&n.set("workflow_id",r);const s=n.toString()?`?${n.toString()}`:"",d=await this.req(`/workflow-hooks${s}`)??{},u=Array.isArray(d.hooks)?d.hooks:[];return{hooks:u,count:typeof d.count=="number"?d.count:u.length}}async patchHook(t,n){return this.req(`/workflow-hooks/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}}class Pl{constructor(t){this.req=t}async getConfig(){return this.req("/config/bug-monitor")}async patchConfig(t){return this.req("/config/bug-monitor",{method:"PATCH",body:JSON.stringify(t)})}async getStatus(){return this.req("/bug-monitor/status")}async recomputeStatus(){return this.req("/bug-monitor/status/recompute",{method:"POST"})}async pause(){return this.req("/bug-monitor/pause",{method:"POST"})}async resume(){return this.req("/bug-monitor/resume",{method:"POST"})}async debug(){return this.req("/bug-monitor/debug")}async listIncidents(t){const n=t?.limit!==void 0?`?limit=${t.limit}`:"";return this.req(`/bug-monitor/incidents${n}`)}async getIncident(t){return(await this.req(`/bug-monitor/incidents/${encodeURIComponent(t)}`)).incident??{}}async replayIncident(t,n){return this.req(`/bug-monitor/incidents/${encodeURIComponent(t)}/replay`,{method:"POST",body:JSON.stringify(n??{})})}async listDrafts(t){const n=t?.limit!==void 0?`?limit=${t.limit}`:"";return this.req(`/bug-monitor/drafts${n}`)}async listPosts(t){const n=t?.limit!==void 0?`?limit=${t.limit}`:"";return this.req(`/bug-monitor/posts${n}`)}async getDraft(t){return(await this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}`)).draft??{}}async approveDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n})})}async denyDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n})})}async report(t){return this.req("/bug-monitor/report",{method:"POST",body:JSON.stringify(t)})}async createTriageRun(t){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/triage-run`,{method:"POST"})}async createTriageSummary(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/triage-summary`,{method:"POST",body:JSON.stringify(n)})}async createIssueDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/issue-draft`,{method:"POST",body:JSON.stringify(n??{})})}async publishDraft(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/publish`,{method:"POST",body:JSON.stringify(n??{})})}async recheckMatch(t,n){return this.req(`/bug-monitor/drafts/${encodeURIComponent(t)}/recheck-match`,{method:"POST",body:JSON.stringify(n??{})})}}class Tl{constructor(t,n,r,s){this.baseUrl=t,this.token=n,this.timeoutMs=r,this.req=s}setToken(t){this.token=t}async create(t={}){const n={title:t.title??"Tandem SDK Session",directory:t.directory??"."};return t.permissions&&(n.permission=t.permissions),t.model&&t.provider&&(n.model={providerID:t.provider,modelID:t.model},n.provider=t.provider),(await this.req("/session",{method:"POST",body:JSON.stringify(n)})).id}async list(t={}){const n=new URLSearchParams;t.q&&n.set("q",t.q),t.page!==void 0&&n.set("page",String(t.page)),t.pageSize!==void 0&&n.set("page_size",String(t.pageSize)),t.archived!==void 0&&n.set("archived",String(t.archived)),t.scope&&n.set("scope",t.scope),t.workspace&&n.set("workspace",t.workspace);const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/session${r}`);return jt(Yr,s,"/session",200)}async get(t){const n=await this.req(`/session/${encodeURIComponent(t)}`);return jt(Jn,n,`/session/${t}`,200)}async update(t,n){const r=await this.req(`/session/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)});return jt(Jn,r,`/session/${t}`,200)}async archive(t){return this.update(t,{archived:!0})}async delete(t){await this.req(`/session/${encodeURIComponent(t)}`,{method:"DELETE"})}async messages(t){return this.req(`/session/${encodeURIComponent(t)}/message`)}async todos(t){const n=await this.req(`/session/${encodeURIComponent(t)}/todo`);return Array.isArray(n)?n:n.todos??[]}async activeRun(t){const n=await this.req(`/session/${encodeURIComponent(t)}/run`);return jt(ul,n,`/session/${t}/run`,200)}async promptAsync(t,n,r,s){return this.promptAsyncParts(t,[{type:"text",text:n}],r,s)}async promptAsyncParts(t,n,r,s){const l={parts:n};r?.provider&&r?.model&&(l.model={providerID:r.provider,modelID:r.model}),s?.toolMode&&(l.toolMode=s.toolMode),s?.toolAllowlist?.length&&(l.toolAllowlist=s.toolAllowlist),s?.contextMode&&(l.contextMode=s.contextMode);const d=`/session/${encodeURIComponent(t)}/prompt_async?return=run`,u=new AbortController,p=setTimeout(()=>u.abort(),this.timeoutMs);let _;try{_=await fetch(`${this.baseUrl}${d}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify(l),signal:u.signal})}finally{clearTimeout(p)}if(_.status===409){const P=(await _.json().catch(()=>({}))).activeRun,O=da(P?.runID)||da(P?.runId)||da(P?.run_id);if(O)return{runId:O}}if(!_.ok){const x=await _.text().catch(()=>"");throw new Error(`promptAsyncParts failed (${_.status}): ${x}`)}const D=await _.json();return{runId:Sl(D)}}async promptSync(t,n){const r={parts:[{type:"text",text:n}]},s=await this.req(`/session/${encodeURIComponent(t)}/prompt_sync`,{method:"POST",body:JSON.stringify(r)});return da(s.reply)||da(s.text)||da(s.output)||""}async abort(t){return this.req(`/session/${encodeURIComponent(t)}/abort`,{method:"POST",body:JSON.stringify({})})}async cancel(t){return this.req(`/session/${encodeURIComponent(t)}/cancel`,{method:"POST",body:JSON.stringify({})})}async cancelRun(t,n){return this.req(`/session/${encodeURIComponent(t)}/run/${encodeURIComponent(n)}/cancel`,{method:"POST",body:JSON.stringify({})})}async fork(t){const n=await this.req(`/session/${encodeURIComponent(t)}/fork`,{method:"POST",body:JSON.stringify({})});return jt(Jn,n,`/session/${t}/fork`,200)}async diff(t){return this.req(`/session/${encodeURIComponent(t)}/diff`)}async revert(t){return this.req(`/session/${encodeURIComponent(t)}/revert`,{method:"POST",body:JSON.stringify({})})}async unrevert(t){return this.req(`/session/${encodeURIComponent(t)}/unrevert`,{method:"POST",body:JSON.stringify({})})}async children(t){const n=await this.req(`/session/${encodeURIComponent(t)}/children`);return jt(Yr,n,`/session/${t}/children`,200).sessions}async summarize(t){return this.req(`/session/${encodeURIComponent(t)}/summarize`,{method:"POST",body:JSON.stringify({})})}async attach(t,n){return this.req(`/session/${encodeURIComponent(t)}/attach`,{method:"POST",body:JSON.stringify({target_workspace:n})})}}class Rl{constructor(t){this.req=t}async list(){return this.req("/permission")}async reply(t,n){const r=await this.req(`/permission/${encodeURIComponent(t)}/reply`,{method:"POST",body:JSON.stringify({reply:n})});if(!r.ok)throw new Error(`Permission reply rejected: ${r.error??t}`);return{ok:!0}}}class ql{constructor(t){this.req=t}async list(){const t=await this.req("/question");return Array.isArray(t)?{questions:t}:t}async reply(t,n){return this.req(`/question/${encodeURIComponent(t)}/reply`,{method:"POST",body:JSON.stringify({answer:n})})}async reject(t){return this.req(`/question/${encodeURIComponent(t)}/reject`,{method:"POST",body:JSON.stringify({})})}}class Ml{constructor(t){this.req=t}async catalog(){return this.req("/provider")}async config(){return this.req("/config/providers")}async setDefaults(t,n){await this.req("/config",{method:"PATCH",body:JSON.stringify({default_provider:t,providers:{[t]:{default_model:n}}})})}async setApiKey(t,n){await this.req(`/auth/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({apiKey:n})})}async authStatus(){return this.req("/provider/auth")}}class $l{constructor(t){this.req=t}async get(){return this.req("/config/identity")}async patch(t){return this.req("/config/identity",{method:"PATCH",body:JSON.stringify(t)})}}class Ol{constructor(t){this.req=t}async config(){return this.req("/channels/config")}async status(){return this.req("/channels/status")}async put(t,n){return this.req(`/channels/${t}`,{method:"PUT",body:JSON.stringify(n)})}async delete(t){return this.req(`/channels/${t}`,{method:"DELETE"})}async verify(t,n={}){return this.req(`/channels/${t}/verify`,{method:"POST",body:JSON.stringify(n)})}}class El{constructor(t,n){this.req=t,this.reqText=n}async list(){return this.req("/mcp")}async listTools(){return this.req("/mcp/tools")}async listResources(){const t=await this.req("/mcp/resources");return Array.isArray(t)?t:[]}async add(t){return this.req("/mcp",{method:"POST",body:JSON.stringify(t)})}async connect(t){return this.req(`/mcp/${encodeURIComponent(t)}/connect`,{method:"POST"})}async disconnect(t){return this.req(`/mcp/${encodeURIComponent(t)}/disconnect`,{method:"POST"})}async refresh(t){return this.req(`/mcp/${encodeURIComponent(t)}/refresh`,{method:"POST"})}async setEnabled(t,n){return this.req(`/mcp/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({enabled:n})})}async delete(t){return this.req(`/mcp/${encodeURIComponent(t)}`,{method:"DELETE"})}async auth(t,n){return this.req(`/mcp/${encodeURIComponent(t)}/auth`,{method:"POST",body:JSON.stringify(n??{})})}async deleteAuth(t){return this.req(`/mcp/${encodeURIComponent(t)}/auth`,{method:"DELETE"})}async authCallback(t,n){return this.req(`/mcp/${encodeURIComponent(t)}/auth/callback`,{method:"POST",body:JSON.stringify(n)})}async authenticate(t,n){return this.req(`/mcp/${encodeURIComponent(t)}/auth/authenticate`,{method:"POST",body:JSON.stringify(n??{})})}async catalogToml(t){if(!this.reqText)throw new Error("Text request helper unavailable");return this.reqText(`/mcp/catalog/${encodeURIComponent(t)}/toml`)}}class Dl{constructor(t){this.req=t}async put(t){return this.req("/memory/put",{method:"POST",body:JSON.stringify(t)})}async search(t){const n=await this.req("/memory/search",{method:"POST",body:JSON.stringify(t)});return jt(fl,n,"/memory/search",200)}async list(t){const n=new URLSearchParams;t?.q&&n.set("q",t.q),t?.limit!==void 0&&n.set("limit",String(t.limit)),t?.offset!==void 0&&n.set("offset",String(t.offset)),t?.userId&&n.set("user_id",t.userId);const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/memory${r}`);return jt(hl,s,"/memory",200)}async delete(t){return this.req(`/memory/${encodeURIComponent(t)}`,{method:"DELETE"})}async promote(t){return this.req("/memory/promote",{method:"POST",body:JSON.stringify(t)})}async demote(t){const n={id:t.id,run_id:t.runId};return this.req("/memory/demote",{method:"POST",body:JSON.stringify(n)})}async audit(t){const n=new URLSearchParams;t?.run_id&&n.set("run_id",t.run_id),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/memory/audit${r}`);return Array.isArray(s)?{entries:s,count:s.length}:s}async contextResolveUri(t){const n=await this.req("/memory/context/resolve",{method:"POST",body:JSON.stringify({uri:t})});return jt(yl,n,"/memory/context/resolve",200)}async contextTree(t,n){const r=new URLSearchParams;r.set("uri",t),n!==void 0&&r.set("max_depth",String(n));const s=r.toString()?`?${r.toString()}`:"",l=await this.req(`/memory/context/tree${s}`);return jt(wl,l,"/memory/context/tree",200)}async contextGenerateLayers(t){return this.req("/memory/context/layers/generate",{method:"POST",body:JSON.stringify({node_id:t})})}async contextDistill(t,n){const r=await this.req("/memory/context/distill",{method:"POST",body:JSON.stringify({session_id:t,conversation:n})});return jt(xl,r,"/memory/context/distill",200)}}class jl{constructor(t){this.req=t}async list(t){const n=t?`?location=${encodeURIComponent(t)}`:"",r=await this.req(`/skills${n}`);return Array.isArray(r)?{skills:r,count:r.length}:r}async get(t){return this.req(`/skills/${encodeURIComponent(t)}`)}async import(t){const n={content:t.content,file_or_path:t.file_or_path??t.fileOrPath,location:t.location,namespace:t.namespace,conflict_policy:t.conflict_policy??t.conflictPolicy};return this.req("/skills/import",{method:"POST",body:JSON.stringify(n)})}async preview(t){const n={content:t.content,file_or_path:t.file_or_path??t.fileOrPath,location:t.location,namespace:t.namespace,conflict_policy:t.conflict_policy??t.conflictPolicy};return this.req("/skills/import/preview",{method:"POST",body:JSON.stringify(n)})}async templates(){const t=await this.req("/skills/templates");return Array.isArray(t)?{templates:t,count:t.length}:t}async catalog(){const t=await this.req("/skills/catalog"),n=Array.isArray(t)?t:[];return{skills:n,count:n.length}}async validate(t){const n={content:t.content,file_or_path:t.file_or_path??t.fileOrPath};return this.req("/skills/validate",{method:"POST",body:JSON.stringify(n)})}async match(t){const n={goal:t.goal,max_matches:t.max_matches??t.maxMatches,threshold:t.threshold};return this.req("/skills/router/match",{method:"POST",body:JSON.stringify(n)})}async evalBenchmark(t){const n={threshold:t.threshold,cases:t.cases.map(r=>({prompt:r.prompt,expected_skill:r.expected_skill??r.expectedSkill}))};return this.req("/skills/evals/benchmark",{method:"POST",body:JSON.stringify(n)})}async evalTriggers(t){const n={skill_name:t.skill_name??t.skillName,prompts:t.prompts,threshold:t.threshold};return this.req("/skills/evals/triggers",{method:"POST",body:JSON.stringify(n)})}async compile(t){const n={skill_name:t.skill_name??t.skillName,goal:t.goal,threshold:t.threshold,max_matches:t.max_matches??t.maxMatches,schedule:t.schedule};return this.req("/skills/compile",{method:"POST",body:JSON.stringify(n)})}async generate(t){return this.req("/skills/generate",{method:"POST",body:JSON.stringify(t)})}async generateInstall(t){const n={prompt:t.prompt,threshold:t.threshold,location:t.location,conflict_policy:t.conflictPolicy,artifacts:t.artifacts?{"SKILL.md":t.artifacts["SKILL.md"],"workflow.yaml":t.artifacts["workflow.yaml"],"automation.example.yaml":t.artifacts["automation.example.yaml"]}:void 0};return this.req("/skills/generate/install",{method:"POST",body:JSON.stringify(n)})}}class Ul{constructor(t){this.req=t}async list(){return this.req("/packs")}async inspect(t){return this.req(`/packs/${encodeURIComponent(t)}`)}async install(t){return this.req("/packs/install",{method:"POST",body:JSON.stringify(t)})}async installFromAttachment(t){return this.req("/packs/install_from_attachment",{method:"POST",body:JSON.stringify(t)})}async uninstall(t){return this.req("/packs/uninstall",{method:"POST",body:JSON.stringify(t)})}async export(t){return this.req("/packs/export",{method:"POST",body:JSON.stringify(t)})}async detect(t){return this.req("/packs/detect",{method:"POST",body:JSON.stringify(t)})}async updates(t){const r=await this.req(`/packs/${encodeURIComponent(t)}/updates`)||{},s=Array.isArray(r.updates)?r.updates:[];return{pack_id:da(r.pack_id)??void 0,name:da(r.name)??void 0,current_version:da(r.current_version)??void 0,updates:s}}async update(t,n){const r=await this.req(`/packs/${encodeURIComponent(t)}/update`,{method:"POST",body:JSON.stringify(n??{})});return{updated:!!r.updated,pack_id:da(r.pack_id)??void 0,name:da(r.name)??void 0,current_version:da(r.current_version)??void 0,target_version:da(r.target_version)??void 0,reason:da(r.reason)??void 0}}}class Bl{constructor(t){this.req=t}async getBindings(){return(await this.req("/capabilities/bindings")).bindings}async setBindings(t){return this.req("/capabilities/bindings",{method:"PUT",body:JSON.stringify(t)})}async discovery(){return this.req("/capabilities/discovery")}async resolve(t){return this.req("/capabilities/resolve",{method:"POST",body:JSON.stringify(t)})}async readiness(t){return this.req("/capabilities/readiness",{method:"POST",body:JSON.stringify(t)})}}class Fl{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(t){const n=new URLSearchParams;t?.prefix&&n.set("prefix",t.prefix),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"",s=await this.req(`/resource${r}`);return jt(ml,s,"/resource",200)}async write(t){return this.req("/resource",{method:"PUT",body:JSON.stringify(t)})}async get(t){const n=await this.req(`/resource/${encodeURIComponent(t)}`);return jt(zs,n,`/resource/${t}`,200)}async putKey(t,n,r){const s=await this.req(`/resource/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({value:n,...r??{}})});return jt(Xr,s,`/resource/${t}`,200)}async patchKey(t,n){const r=await this.req(`/resource/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)});return jt(Xr,r,`/resource/${t}`,200)}async delete(t,n){return this.req("/resource",{method:"DELETE",body:JSON.stringify({key:t,...n})})}async deleteKey(t){return this.req(`/resource/${encodeURIComponent(t)}`,{method:"DELETE"})}events(t){const n=new URLSearchParams;t?.sinceSeq!==void 0&&n.set("since_seq",String(t.sinceSeq)),t?.tail!==void 0&&n.set("tail",String(t.tail));const r=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/resource/events${r}`,this.getToken())}}class Kl{constructor(t){this.req=t}async createRun(t){return this.req("/coder/runs",{method:"POST",body:JSON.stringify(t)})}async listRuns(t){const n=new URLSearchParams;t?.limit!==void 0&&n.set("limit",String(t.limit));const r=t?.workflow_mode??t?.workflowMode,s=t?.repo_slug??t?.repoSlug;r&&n.set("workflow_mode",r),s&&n.set("repo_slug",s);const l=n.toString()?`?${n.toString()}`:"",u=await this.req(`/coder/runs${l}`)??{},p=Array.isArray(u.runs)?u.runs:[];return{runs:p,count:typeof u.count=="number"?u.count:p.length}}async getRun(t){const r=await this.req(`/coder/runs/${encodeURIComponent(t)}`)??{};return{...r,coderRun:r.coder_run??void 0,coder_run:r.coder_run??void 0,run:r.run??void 0}}async getProjectBinding(t){const r=await this.req(`/coder/projects/${encodeURIComponent(t)}/bindings`)??{};return{...r,binding:r.binding??null}}async putProjectBinding(t,n){const s=await this.req(`/coder/projects/${encodeURIComponent(t)}/bindings`,{method:"PUT",body:JSON.stringify(n)})??{};return{...s,binding:s.binding}}async getProjectGithubInbox(t){const r=await this.req(`/coder/projects/${encodeURIComponent(t)}/github-project/inbox`)??{};return{...r,items:Array.isArray(r.items)?r.items:[],binding:r.binding,project_id:String(r.project_id||r.projectId||""),schema_drift:!!(r.schema_drift??r.schemaDrift),live_schema_fingerprint:String(r.live_schema_fingerprint||r.liveSchemaFingerprint||"")}}async intakeProjectItem(t,n){const s=await this.req(`/coder/projects/${encodeURIComponent(t)}/github-project/intake`,{method:"POST",body:JSON.stringify(n)})??{};return{...s,coder_run:s.coder_run??void 0,coderRun:s.coder_run??void 0,run:s.run??void 0}}async executeNext(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/execute-next`,{method:"POST",body:JSON.stringify(n??{})})}async executeAll(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/execute-all`,{method:"POST",body:JSON.stringify(n??{})})}async createFollowOnRun(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/follow-on-run`,{method:"POST",body:JSON.stringify(n)})}async approveRun(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n})})}async cancelRun(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/cancel`,{method:"POST",body:JSON.stringify({reason:n})})}async listArtifacts(t){const r=await this.req(`/coder/runs/${encodeURIComponent(t)}/artifacts`)??{},s=Array.isArray(r.artifacts)?r.artifacts:[];return{...r,artifacts:s,count:typeof r.count=="number"?r.count:s.length}}async getMemoryHits(t,n){const r=new URLSearchParams;n?.query&&r.set("q",n.query),n?.limit!==void 0&&r.set("limit",String(n.limit));const s=r.toString()?`?${r.toString()}`:"",d=await this.req(`/coder/runs/${encodeURIComponent(t)}/memory-hits${s}`)??{},u=Array.isArray(d.hits)?d.hits:[];return{...d,hits:u,count:typeof d.count=="number"?d.count:u.length}}async createTriageInspectionReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/triage-inspection-report`,{method:"POST",body:JSON.stringify(n)})}async createTriageReproductionReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/triage-reproduction-report`,{method:"POST",body:JSON.stringify(n)})}async createTriageSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/triage-summary`,{method:"POST",body:JSON.stringify(n)})}async createPrReviewEvidence(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-review-evidence`,{method:"POST",body:JSON.stringify(n)})}async createPrReviewSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-review-summary`,{method:"POST",body:JSON.stringify(n)})}async createIssueFixValidationReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/issue-fix-validation-report`,{method:"POST",body:JSON.stringify(n)})}async createIssueFixSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/issue-fix-summary`,{method:"POST",body:JSON.stringify(n)})}async createPrDraft(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-draft`,{method:"POST",body:JSON.stringify(n??{})})}async submitPr(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/pr-submit`,{method:"POST",body:JSON.stringify(n??{})})}async createMergeReadinessReport(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/merge-readiness-report`,{method:"POST",body:JSON.stringify(n)})}async createMergeRecommendationSummary(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/merge-recommendation-summary`,{method:"POST",body:JSON.stringify(n)})}async listMemoryCandidates(t){const r=await this.req(`/coder/runs/${encodeURIComponent(t)}/memory-candidates`)??{},s=Array.isArray(r.candidates)?r.candidates:[];return{...r,candidates:s,count:typeof r.count=="number"?r.count:s.length}}async createMemoryCandidate(t,n){return this.req(`/coder/runs/${encodeURIComponent(t)}/memory-candidates`,{method:"POST",body:JSON.stringify(n)})}async promoteMemoryCandidate(t,n,r){return this.req(`/coder/runs/${encodeURIComponent(t)}/memory-candidates/${encodeURIComponent(n)}/promote`,{method:"POST",body:JSON.stringify(r??{})})}}class Ll{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(){return this.req("/routines")}async create(t){const n={...t};return"prompt"in n&&!("entrypoint"in n)&&(n.entrypoint=n.prompt),this.req("/routines",{method:"POST",body:JSON.stringify(n)})}async update(t,n){return this.req(`/routines/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async delete(t){await this.req(`/routines/${encodeURIComponent(t)}`,{method:"DELETE"})}async runNow(t){const n=await this.req(`/routines/${encodeURIComponent(t)}/run_now`,{method:"POST",body:JSON.stringify({})});return jt(Ls,n,`/routines/${t}/run_now`,200)}async listRuns(t){const n=new URLSearchParams;t?.routine_id&&n.set("routine_id",t.routine_id),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"";return this.req(`/routines/runs${r}`)}async getRunsForRoutine(t,n=25){return this.req(`/routines/${encodeURIComponent(t)}/runs?limit=${n}`)}async getRun(t){const n=await this.req(`/routines/runs/${encodeURIComponent(t)}`);return jt(Ws,n,`/routines/runs/${t}`,200)}async listArtifacts(t){return this.req(`/routines/runs/${encodeURIComponent(t)}/artifacts`)}async approveRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n??""})})}async denyRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n??""})})}async pauseRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resumeRun(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({reason:n??""})})}async history(t,n){const r=n!==void 0?`?limit=${n}`:"",s=await this.req(`/routines/${encodeURIComponent(t)}/history${r}`);return Array.isArray(s)?{history:s,count:s.length}:s}events(t){const n=new URLSearchParams,r=t?.routine_id??t?.routineId;r&&n.set("routine_id",r);const s=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/routines/events${s}`,this.getToken(),{signal:t?.signal})}addArtifact(t,n){return this.req(`/routines/runs/${encodeURIComponent(t)}/artifacts`,{method:"POST",body:JSON.stringify(n)})}}class Wl{constructor(t){this.req=t}async preview(t){return this.req("/workflow-plans/preview",{method:"POST",body:JSON.stringify({prompt:t.prompt,schedule:t.schedule,plan_source:t.plan_source??t.planSource,allowed_mcp_servers:t.allowed_mcp_servers??t.allowedMcpServers,workspace_root:t.workspace_root??t.workspaceRoot,operator_preferences:t.operator_preferences??t.operatorPreferences})})}async apply(t){return this.req("/workflow-plans/apply",{method:"POST",body:JSON.stringify({plan_id:t.plan_id??t.planId,plan:t.plan,creator_id:t.creator_id??t.creatorId,pack_builder_export:t.pack_builder_export??t.packBuilderExport})})}async chatStart(t){return this.req("/workflow-plans/chat/start",{method:"POST",body:JSON.stringify({prompt:t.prompt,schedule:t.schedule,plan_source:t.plan_source??t.planSource,allowed_mcp_servers:t.allowed_mcp_servers??t.allowedMcpServers,workspace_root:t.workspace_root??t.workspaceRoot,operator_preferences:t.operator_preferences??t.operatorPreferences})})}async get(t){return this.req(`/workflow-plans/${encodeURIComponent(t)}`)}async chatMessage(t){return this.req("/workflow-plans/chat/message",{method:"POST",body:JSON.stringify({plan_id:t.plan_id??t.planId,message:t.message})})}async chatReset(t){return this.req("/workflow-plans/chat/reset",{method:"POST",body:JSON.stringify({plan_id:t.plan_id??t.planId})})}}class zl{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async list(){return this.req("/automations")}async create(t){return this.req("/automations",{method:"POST",body:JSON.stringify(t)})}async update(t,n){return this.req(`/automations/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async delete(t){await this.req(`/automations/${encodeURIComponent(t)}`,{method:"DELETE"})}async runNow(t){const n=await this.req(`/automations/${encodeURIComponent(t)}/run_now`,{method:"POST",body:JSON.stringify({})});return jt(Ls,n,`/automations/${t}/run_now`,200)}async listRuns(t){const n=new URLSearchParams;t?.automation_id&&n.set("automation_id",t.automation_id),t?.limit!==void 0&&n.set("limit",String(t.limit));const r=n.toString()?`?${n.toString()}`:"";return this.req(`/automations/runs${r}`)}async getRunsForAutomation(t,n=25){return this.req(`/automations/${encodeURIComponent(t)}/runs?limit=${n}`)}async getRun(t){const n=await this.req(`/automations/runs/${encodeURIComponent(t)}`);return jt(Ws,n,`/automations/runs/${t}`,200)}async listArtifacts(t){return this.req(`/automations/runs/${encodeURIComponent(t)}/artifacts`)}async approveRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n??""})})}async denyRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n??""})})}async pauseRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resumeRun(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({reason:n??""})})}async history(t,n){const r=n!==void 0?`?limit=${n}`:"",s=await this.req(`/automations/${encodeURIComponent(t)}/history${r}`);return Array.isArray(s)?{history:s,count:s.length}:s}events(t){const n=new URLSearchParams,r=t?.automation_id??t?.automationId,s=t?.run_id??t?.runId;r&&n.set("automation_id",r),s&&n.set("run_id",s);const l=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/automations/events${l}`,this.getToken(),{signal:t?.signal})}addArtifact(t,n){return this.req(`/automations/runs/${encodeURIComponent(t)}/artifacts`,{method:"POST",body:JSON.stringify(n)})}}class Jl{constructor(t,n,r){this.baseUrl=t,this.getToken=n,this.req=r}async create(t){return this.req("/automations/v2",{method:"POST",body:JSON.stringify(t)})}async list(){return this.req("/automations/v2")}async get(t){return this.req(`/automations/v2/${encodeURIComponent(t)}`)}async update(t,n){return this.req(`/automations/v2/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async delete(t){return this.req(`/automations/v2/${encodeURIComponent(t)}`,{method:"DELETE"})}async runNow(t){return this.req(`/automations/v2/${encodeURIComponent(t)}/run_now`,{method:"POST",body:JSON.stringify({})})}async pause(t,n){return this.req(`/automations/v2/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resume(t){return this.req(`/automations/v2/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({})})}async listRuns(t,n=50){return this.req(`/automations/v2/${encodeURIComponent(t)}/runs?limit=${n}`)}async getRun(t){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}`)}async pauseRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/pause`,{method:"POST",body:JSON.stringify({reason:n??""})})}async resumeRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/resume`,{method:"POST",body:JSON.stringify({reason:n??""})})}async recoverRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/recover`,{method:"POST",body:JSON.stringify({reason:n??""})})}async repairRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/repair`,{method:"POST",body:JSON.stringify(n)})}async retryTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/retry`,{method:"POST",body:JSON.stringify({reason:r??""})})}async previewTaskReset(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/reset_preview`)}async continueTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/continue`,{method:"POST",body:JSON.stringify({reason:r??""})})}async requeueTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}/requeue`,{method:"POST",body:JSON.stringify({reason:r??""})})}async claimBacklogTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/backlog/tasks/${encodeURIComponent(n)}/claim`,{method:"POST",body:JSON.stringify(r||{})})}async requeueBacklogTask(t,n,r){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/backlog/tasks/${encodeURIComponent(n)}/requeue`,{method:"POST",body:JSON.stringify({reason:r??""})})}async cancelRun(t,n){return this.req(`/automations/v2/runs/${encodeURIComponent(t)}/cancel`,{method:"POST",body:JSON.stringify({reason:n??""})})}events(t){const n=new URLSearchParams,r=t?.automation_id??t?.automationId,s=t?.run_id??t?.runId;r&&n.set("automation_id",r),s&&n.set("run_id",s);const l=n.toString()?`?${n.toString()}`:"";return Ya(`${this.baseUrl}/automations/v2/events${l}`,this.getToken(),{signal:t?.signal})}}class Ql{constructor(t){this.req=t}async list(){return this.req("/optimizations")}async create(t){return this.req("/optimizations",{method:"POST",body:JSON.stringify(t)})}async get(t){return this.req(`/optimizations/${encodeURIComponent(t)}`)}async action(t,n){return this.req(`/optimizations/${encodeURIComponent(t)}/actions`,{method:"POST",body:JSON.stringify(n)})}async listExperiments(t){return this.req(`/optimizations/${encodeURIComponent(t)}/experiments`)}async getExperiment(t,n){return this.req(`/optimizations/${encodeURIComponent(t)}/experiments/${encodeURIComponent(n)}`)}async applyWinner(t,n){return this.req(`/optimizations/${encodeURIComponent(t)}/experiments/${encodeURIComponent(n)}`,{method:"POST",body:JSON.stringify({})})}}class Gl{constructor(t){this.req=t}async listTemplates(){return this.req("/agent-team/templates")}async createTemplate(t){return this.req("/agent-team/templates",{method:"POST",body:JSON.stringify(t)})}async updateTemplate(t,n){return this.req(`/agent-team/templates/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(n)})}async deleteTemplate(t){return this.req(`/agent-team/templates/${encodeURIComponent(t)}`,{method:"DELETE"})}async composeStandup(t){return this.req("/agent-standup/compose",{method:"POST",body:JSON.stringify({name:t.name,workspace_root:t.workspaceRoot,schedule:t.schedule,participant_template_ids:t.participantTemplateIds,report_path_template:t.reportPathTemplate})})}async listInstances(t){const n=new URLSearchParams;t?.missionID&&n.set("missionID",t.missionID),t?.parentInstanceID&&n.set("parentInstanceID",t.parentInstanceID),t?.status&&n.set("status",t.status);const r=n.toString()?`?${n.toString()}`:"";return this.req(`/agent-team/instances${r}`)}async listMissions(){return this.req("/agent-team/missions")}async listApprovals(){return this.req("/agent-team/approvals")}async spawn(t){return this.req("/agent-team/spawn",{method:"POST",body:JSON.stringify(t)})}async approveSpawn(t,n){return this.req(`/agent-team/approvals/spawn/${encodeURIComponent(t)}/approve`,{method:"POST",body:JSON.stringify({reason:n??""})})}async denySpawn(t,n){return this.req(`/agent-team/approvals/spawn/${encodeURIComponent(t)}/deny`,{method:"POST",body:JSON.stringify({reason:n??""})})}}class Hl{constructor(t){this.req=t}async list(){return this.req("/mission")}async create(t){return this.req("/mission",{method:"POST",body:JSON.stringify(t)})}async get(t){return this.req(`/mission/${encodeURIComponent(t)}`)}async applyEvent(t,n){return this.req(`/mission/${encodeURIComponent(t)}/event`,{method:"POST",body:JSON.stringify({event:n})})}}const Xn="charcoal_fire",ln=[{id:"charcoal_fire",name:"Charcoal & Fire",description:"Deep charcoal surfaces with solar-yellow power accents and crimson security cues.",cssVars:{"--color-background":"#121212","--color-surface":"#141414","--color-surface-elevated":"#1a1a1a","--color-border":"rgba(245, 245, 245, 0.10)","--color-border-subtle":"rgba(245, 245, 245, 0.06)","--color-primary":"#F59E0B","--color-primary-hover":"#D97706","--color-primary-muted":"#B45309","--color-secondary":"#EF4444","--color-secondary-hover":"#DC2626","--color-success":"#10B981","--color-warning":"#F59E0B","--color-error":"#EF4444","--color-text":"#F5F5F5","--color-text-muted":"rgba(245, 245, 245, 0.70)","--color-text-subtle":"rgba(245, 245, 245, 0.50)","--color-glass":"rgba(255, 255, 255, 0.03)","--color-glass-border":"rgba(255, 255, 255, 0.08)","--font-sans":'"Manrope", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(245, 158, 11, 0.16)","--tcp-glow-b":"rgba(239, 68, 68, 0.12)"}},{id:"electric_blue",name:"Electric Blue",description:"The original Tandem look: electric-blue primary with purple secondary.",cssVars:{"--color-background":"#0a0a0f","--color-surface":"#12121a","--color-surface-elevated":"#1a1a24","--color-border":"#2a2a3a","--color-border-subtle":"#1f1f2e","--color-primary":"#3b82f6","--color-primary-hover":"#2563eb","--color-primary-muted":"#1d4ed8","--color-secondary":"#8b5cf6","--color-secondary-hover":"#7c3aed","--color-success":"#10b981","--color-warning":"#f59e0b","--color-error":"#ef4444","--color-text":"#f8fafc","--color-text-muted":"#94a3b8","--color-text-subtle":"#64748b","--color-glass":"rgba(18, 18, 26, 0.8)","--color-glass-border":"rgba(255, 255, 255, 0.1)","--font-sans":'"Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(59, 130, 246, 0.16)","--tcp-glow-b":"rgba(139, 92, 246, 0.12)"}},{id:"emerald_night",name:"Emerald Night",description:"Dark glass with emerald primary and cyan secondary highlights.",cssVars:{"--color-background":"#0b1010","--color-surface":"#0f1616","--color-surface-elevated":"#142020","--color-border":"rgba(226, 232, 240, 0.12)","--color-border-subtle":"rgba(226, 232, 240, 0.08)","--color-primary":"#10B981","--color-primary-hover":"#059669","--color-primary-muted":"#047857","--color-secondary":"#22D3EE","--color-secondary-hover":"#06B6D4","--color-success":"#22C55E","--color-warning":"#F59E0B","--color-error":"#EF4444","--color-text":"#F1F5F9","--color-text-muted":"rgba(241, 245, 249, 0.72)","--color-text-subtle":"rgba(241, 245, 249, 0.52)","--color-glass":"rgba(15, 22, 22, 0.75)","--color-glass-border":"rgba(255, 255, 255, 0.10)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(16, 185, 129, 0.16)","--tcp-glow-b":"rgba(34, 211, 238, 0.12)"}},{id:"hello_bunny",name:"Hello Bunny",description:"Soft pink glass with berry accents and a cozy, playful vibe.",cssVars:{"--color-background":"#140A12","--color-surface":"#1C0E1A","--color-surface-elevated":"#251022","--color-border":"rgba(255, 228, 242, 0.12)","--color-border-subtle":"rgba(255, 228, 242, 0.08)","--color-primary":"#FB7185","--color-primary-hover":"#F43F5E","--color-primary-muted":"#E11D48","--color-secondary":"#C084FC","--color-secondary-hover":"#A855F7","--color-success":"#34D399","--color-warning":"#FBBF24","--color-error":"#FB7185","--color-text":"#FFEAF4","--color-text-muted":"rgba(255, 234, 244, 0.74)","--color-text-subtle":"rgba(255, 234, 244, 0.52)","--color-glass":"rgba(255, 255, 255, 0.04)","--color-glass-border":"rgba(255, 228, 242, 0.10)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(251, 113, 133, 0.16)","--tcp-glow-b":"rgba(192, 132, 252, 0.12)"}},{id:"porcelain",name:"Porcelain",description:"Plain, bright whites with soft pastel accents and glassy structure.",cssVars:{"--color-background":"#F8FAFC","--color-surface":"#FFFFFF","--color-surface-elevated":"#F1F5F9","--color-border":"rgba(15, 23, 42, 0.12)","--color-border-subtle":"rgba(15, 23, 42, 0.08)","--color-primary":"#6366F1","--color-primary-hover":"#4F46E5","--color-primary-muted":"#4338CA","--color-secondary":"#F472B6","--color-secondary-hover":"#EC4899","--color-success":"#10B981","--color-warning":"#F59E0B","--color-error":"#EF4444","--color-text":"#0F172A","--color-text-muted":"rgba(15, 23, 42, 0.70)","--color-text-subtle":"rgba(15, 23, 42, 0.50)","--color-glass":"rgba(255, 255, 255, 0.72)","--color-glass-border":"rgba(15, 23, 42, 0.10)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(99, 102, 241, 0.13)","--tcp-glow-b":"rgba(244, 114, 182, 0.11)"}},{id:"neon_riot",name:"Neon Riot",description:"Electric cyan and magenta over deep space surfaces.",cssVars:{"--color-background":"#050014","--color-surface":"#0B0720","--color-surface-elevated":"#140A3A","--color-border":"rgba(248, 250, 252, 0.16)","--color-border-subtle":"rgba(248, 250, 252, 0.10)","--color-primary":"#00E5FF","--color-primary-hover":"#00B8D4","--color-primary-muted":"#00838F","--color-secondary":"#FF3DF5","--color-secondary-hover":"#D500F9","--color-success":"#22C55E","--color-warning":"#FBBF24","--color-error":"#FB7185","--color-text":"#F8FAFC","--color-text-muted":"rgba(248, 250, 252, 0.72)","--color-text-subtle":"rgba(248, 250, 252, 0.52)","--color-glass":"rgba(5, 0, 20, 0.55)","--color-glass-border":"rgba(255, 255, 255, 0.14)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(0, 229, 255, 0.20)","--tcp-glow-b":"rgba(255, 61, 245, 0.14)"}},{id:"cosmic_glass",name:"Cosmic Glass",description:"Transparent nebula glass panels with deep-space glow.",cssVars:{"--color-background":"#03020F","--color-surface":"rgba(9, 6, 28, 0.72)","--color-surface-elevated":"rgba(18, 12, 40, 0.82)","--color-border":"rgba(120, 105, 255, 0.22)","--color-border-subtle":"rgba(120, 105, 255, 0.12)","--color-primary":"#7C5CFF","--color-primary-hover":"#6A40FF","--color-primary-muted":"#4C2ED8","--color-secondary":"#FF7AD9","--color-secondary-hover":"#FF4FC3","--color-success":"#3BE4C0","--color-warning":"#F9D86B","--color-error":"#FF5C7A","--color-text":"#F3F0FF","--color-text-muted":"rgba(243, 240, 255, 0.74)","--color-text-subtle":"rgba(243, 240, 255, 0.52)","--color-glass":"rgba(14, 10, 40, 0.48)","--color-glass-border":"rgba(255, 255, 255, 0.16)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(124, 92, 255, 0.20)","--tcp-glow-b":"rgba(255, 122, 217, 0.14)"}},{id:"pink_pony",name:"Pink Pony",description:"Candy pinks and dreamy pastels with brighter glass accents.",cssVars:{"--color-background":"#240818","--color-surface":"rgba(56, 12, 38, 0.94)","--color-surface-elevated":"rgba(72, 16, 48, 0.96)","--color-border":"rgba(255, 184, 217, 0.36)","--color-border-subtle":"rgba(255, 184, 217, 0.22)","--color-primary":"#FF5FB1","--color-primary-hover":"#FF3B9A","--color-primary-muted":"#D91E7D","--color-secondary":"#FFB8E6","--color-secondary-hover":"#FF98D8","--color-success":"#58E5C1","--color-warning":"#FFD166","--color-error":"#FF5C8A","--color-text":"#FFF7FC","--color-text-muted":"rgba(255, 247, 252, 0.86)","--color-text-subtle":"rgba(255, 247, 252, 0.68)","--color-glass":"rgba(74, 17, 50, 0.78)","--color-glass-border":"rgba(255, 220, 238, 0.30)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(255, 95, 177, 0.20)","--tcp-glow-b":"rgba(255, 184, 230, 0.14)"}},{id:"zen_dusk",name:"Zen Dusk",description:"Muted green dusk tones for calmer long-session work.",cssVars:{"--color-background":"#0B1110","--color-surface":"#101716","--color-surface-elevated":"#141D1C","--color-border":"rgba(226, 232, 240, 0.12)","--color-border-subtle":"rgba(226, 232, 240, 0.06)","--color-primary":"#7CC8A4","--color-primary-hover":"#6AB690","--color-primary-muted":"#559B7B","--color-secondary":"#9FB8B0","--color-secondary-hover":"#8AA59C","--color-success":"#5EC79B","--color-warning":"#E6C17B","--color-error":"#E38B8B","--color-text":"#E6EFEA","--color-text-muted":"rgba(230, 239, 234, 0.72)","--color-text-subtle":"rgba(230, 239, 234, 0.50)","--color-glass":"rgba(20, 28, 26, 0.72)","--color-glass-border":"rgba(255, 255, 255, 0.08)","--font-sans":'"Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-display":'"Rubik", "Geist Sans", "Inter", system-ui, -apple-system, sans-serif',"--font-mono":'"Geist Mono", "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace',"--tcp-glow-a":"rgba(124, 200, 164, 0.16)","--tcp-glow-b":"rgba(159, 184, 176, 0.12)"}}],Aa={duration:{normal:.22},easing:{standard:[.22,1,.36,1]},spring:{gentle:{type:"spring",stiffness:220,damping:26,mass:.9},snappy:{type:"spring",stiffness:320,damping:30,mass:.82},drawer:{type:"spring",stiffness:340,damping:34,mass:.82}}};function Rr(a){let t=String(a||"").trim()||Xn;return t==="web_control"&&(t=Xn),ln.find(n=>n.id===t)||ln[0]}function Vl(a){const t=Rr(a).id,n=ln.findIndex(r=>r.id===t);return n<0?Xn:ln[(n+1)%ln.length].id}function Qs(a,t=typeof document<"u"?document.documentElement:null){const n=Rr(a);if(!t)return n;for(const[r,s]of Object.entries(n.cssVars))s!=null&&t.style.setProperty(r,s);return t.dataset.theme=n.id,t.style.colorScheme=n.id==="porcelain"?"light":"dark",n}function Gs(){return typeof window>"u"||typeof window.matchMedia!="function"?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Hs="tandem.themeId";function Yl(){try{const a=localStorage.getItem(Hs);return Rr(a).id}catch{return Xn}}function Xl(a){return Qs(a)}function Zl(a){const t=Qs(a);try{localStorage.setItem(Hs,t.id)}catch{}return t}function qn(){const[a,t]=w(()=>Gs());return be(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>t(n.matches);return r(),typeof n.addEventListener=="function"?(n.addEventListener("change",r),()=>n.removeEventListener("change",r)):(n.addListener(r),()=>n.removeListener(r))},[]),a}function ec(a,t,n){return Math.min(n,Math.max(t,a))}function Zn({className:a="",children:t}){return e("div",{className:`tcp-glow-layer ${a}`.trim(),children:t})}function Mn({className:a="",children:t}){const n=qn();return e(Me.div,{className:a,initial:n?!1:{opacity:0,y:14},animate:n?void 0:{opacity:1,y:0},exit:n?void 0:{opacity:0,y:-10},transition:n?void 0:{duration:Aa.duration.normal,ease:Aa.easing.standard},children:t})}function tc({className:a="",children:t}){const n=qn();return e(Me.div,{className:a,initial:n?!1:"hidden",animate:n?void 0:"show",variants:n?void 0:{hidden:{},show:{transition:{staggerChildren:.06,delayChildren:.02}}},children:t})}function Vs({className:a="",children:t,as:n="div"}){const r=qn(),s=n==="section"?Me.section:n==="article"?Me.article:Me.div;return e(s,{className:a,variants:r?void 0:{hidden:{opacity:0,y:12,scale:.985},show:{opacity:1,y:0,scale:1,transition:{duration:Aa.duration.normal,ease:Aa.easing.standard}}},initial:r?!1:"hidden",animate:r?void 0:"show",children:t})}function ac({value:a,format:t=r=>String(r),className:n=""}){const r=qn(),[s,l]=w(()=>Number(a||0)),d=Pt(Number(a||0));return be(()=>{const u=Number(a||0);if(!Number.isFinite(u)){l(0),d.current=0;return}if(r){l(u),d.current=u;return}const p=d.current,_=u-p;if(!_){l(u),d.current=u;return}const D=performance.now();let x=0;const P=O=>{const k=ec((O-D)/420,0,1),J=1-Math.pow(1-k,3),A=p+_*J;l(A),k<1?x=window.requestAnimationFrame(P):d.current=u};return x=window.requestAnimationFrame(P),()=>window.cancelAnimationFrame(x)},[r,a]),e("span",{className:n,children:t(Number.isFinite(s)?s:0)})}function ka({tone:a="ok",text:t,className:n=""}){return e("span",{className:`tcp-status-pulse ${a} ${n}`.trim(),children:[e("span",{className:"tcp-status-pulse-dot","aria-hidden":"true"}),t?e("span",{children:t}):null]})}function va({className:a="",children:t}){return e("div",{className:`tcp-toolbar ${a}`.trim(),children:t})}function Nn({className:a="",title:t,children:n,...r}){return e("button",{type:"button",title:t,className:`tcp-icon-btn ${a}`.trim(),...r,children:n})}function je({tone:a="info",className:t="",children:n}){return e("span",{className:`${a==="ok"?"tcp-badge-ok":a==="warn"?"tcp-badge-warn":a==="err"?"tcp-badge-err":a==="ghost"?"tcp-badge tcp-badge-ghost":"tcp-badge-info"} ${t}`.trim(),children:n})}function or({active:a=!1,className:t="",children:n,...r}){return e("button",{type:"button",className:`tcp-filter-chip ${a?"active":""} ${t}`.trim(),...r,children:n})}function ft({title:a,subtitle:t,actions:n,className:r="",children:s}){return e(Vs,{as:"section",className:`tcp-panel-card ${r}`.trim(),children:[a||t||n?e("div",{className:"tcp-panel-card-head",children:[e("div",{className:"min-w-0",children:[a?e("h3",{className:"tcp-title",children:a}):null,t?e("p",{className:"tcp-subtle mt-1",children:t}):null]}),n?e("div",{className:"shrink-0",children:n}):null]}):null,s]})}function nc({text:a,title:t="Nothing here yet",action:n,className:r=""}){return e("div",{className:`tcp-empty-state ${r}`.trim(),children:[e("div",{className:"tcp-empty-state-orb"}),e("div",{className:"relative z-10",children:[e("div",{className:"tcp-empty-state-title",children:t}),e("p",{className:"tcp-subtle mt-1",children:a}),n?e("div",{className:"mt-3",children:n}):null]})]})}function rc({eyebrow:a,title:t,subtitle:n,badges:r,actions:s,className:l=""}){return e(Vs,{className:`tcp-page-header ${l}`.trim(),children:[e(Zn,{className:"tcp-page-header-glow"}),e("div",{className:"relative z-10 flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[e("div",{className:"min-w-0",children:[a?e("div",{className:"tcp-page-eyebrow",children:a}):null,e("h1",{className:"tcp-page-title",children:t}),n?e("p",{className:"tcp-subtle mt-2 max-w-3xl",children:n}):null,r?e("div",{className:"mt-3 flex flex-wrap gap-2",children:r}):null]}),s?e(va,{className:"justify-start lg:justify-end",children:s}):null]})]})}function In({className:a="",mainClassName:t="",asideClassName:n="",main:r,aside:s}){return e("div",{className:`tcp-split-view ${a}`.trim(),children:[e("div",{className:`min-w-0 ${t}`.trim(),children:r}),s?e("div",{className:`min-w-0 ${n}`.trim(),children:s}):null]})}function er({open:a,title:t,onClose:n,children:r}){const s=qn();return e(Tt,{children:a?e(Me.div,{className:"tcp-drawer-root",initial:s?!1:{opacity:0},animate:s?void 0:{opacity:1},exit:s?void 0:{opacity:0},children:[e("button",{type:"button",className:"tcp-drawer-backdrop","aria-label":"Close",onClick:n}),e(Me.aside,{className:"tcp-drawer-panel",initial:s?!1:{x:"100%"},animate:s?void 0:{x:0},exit:s?void 0:{x:"100%"},transition:s?void 0:Aa.spring.drawer,children:[e("div",{className:"tcp-drawer-head",children:[e("div",{className:"min-w-0",children:t?e("h3",{className:"tcp-title",children:t}):null}),e(Nn,{title:"Close drawer",onClick:n,children:e("i",{"data-lucide":"x"})})]}),e("div",{className:"min-h-0 flex-1 overflow-auto p-4",children:r})]})]}):null})}function sc({loginMutation:a,savedToken:t,onCheckEngine:n,controlPanelName:r}){const[s,l]=w(t),[d,u]=w(!0),[p,_]=w(""),[D,x]=w(!1);return e("main",{className:"relative min-h-screen overflow-hidden px-5 py-8",children:[e(Zn,{className:"tcp-shell-background",children:[e("div",{className:"tcp-shell-glow tcp-shell-glow-a"}),e("div",{className:"tcp-shell-glow tcp-shell-glow-b"})]}),e("div",{className:"relative z-10 mx-auto grid min-h-[calc(100vh-4rem)] w-full max-w-6xl items-center gap-6 lg:grid-cols-[1.05fr_0.95fr]",children:[e("section",{className:"grid gap-4",children:[e("div",{className:"tcp-page-eyebrow",children:"Tandem Control"}),e("h1",{className:"tcp-page-title max-w-3xl",children:"Sign in to continue."}),e("p",{className:"tcp-subtle max-w-2xl text-base",children:"Enter your engine token to access chat, orchestrator, automations, memory, live feed, and settings."})]}),e(ft,{title:r,subtitle:"Authenticate against your Tandem engine to continue.",children:e("form",{className:"grid gap-3",onSubmit:P=>{if(P.preventDefault(),!s.trim()){x(!1),_("Token is required.");return}a.mutate({token:s.trim(),remember:d})},children:[e("label",{className:"text-sm tcp-subtle",children:"Engine token"}),e("input",{className:"tcp-input",type:"password",value:s,onInput:P=>l(P.target.value),placeholder:"tk_...",autoComplete:"off"}),e("label",{className:"inline-flex items-center gap-2 text-xs tcp-subtle",children:[e("input",{type:"checkbox",className:"h-4 w-4 accent-slate-400",checked:d,onChange:P=>u(P.target.checked)}),"Remember token on this browser"]}),e("div",{className:"grid gap-2 sm:grid-cols-2",children:[e("button",{disabled:a.isPending,type:"submit",className:"tcp-btn-primary w-full",children:[e("i",{"data-lucide":"key-round"}),"Sign in"]}),e("button",{type:"button",className:"tcp-btn w-full",onClick:async()=>{try{const P=await n();x(!0),_(P)}catch(P){x(!1),_(P instanceof Error?P.message:String(P))}},children:[e("i",{"data-lucide":"activity"}),"Check engine"]})]}),e("div",{className:`min-h-[1.2rem] text-sm ${D?"text-lime-300":"text-rose-300"}`,children:a.error?.message||p}),e("div",{className:"rounded-xl border border-slate-700/60 bg-slate-950/30 p-3",children:[e("div",{className:"mb-2 flex items-center justify-between gap-3",children:[e("div",{className:"font-medium",children:"Readiness"}),e(ka,{tone:D?"ok":"warn",text:D?"Engine reachable":"Waiting"})]}),e("p",{className:"tcp-subtle text-xs",children:"Connectivity checks are non-destructive and help verify the local panel can reach the engine before authentication."})]})]})})]})]})}function ic(a){be(()=>{const t=n=>{(n.metaKey||n.ctrlKey)&&n.key.toLowerCase()==="k"&&(n.preventDefault(),a())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[a])}function oc({open:a,onClose:t,actions:n}){const[r,s]=w("");be(()=>{a||s("")},[a]),be(()=>{if(!a)return;const d=u=>{u.key==="Escape"&&t()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a,t]);const l=L(()=>{const d=r.trim().toLowerCase();return d?n.filter(u=>`${u.label} ${u.group}`.toLowerCase().includes(d)):n},[n,r]);return e(Tt,{children:a?e(Me.div,{className:"tcp-confirm-overlay",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:t,children:e(Me.div,{className:"tcp-doc-dialog w-[min(44rem,96vw)]",initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.98},transition:{duration:.16,ease:"easeOut"},onClick:d=>d.stopPropagation(),children:[e("div",{className:"tcp-doc-header",children:[e("h3",{className:"tcp-doc-title",children:"Command Palette"}),e("kbd",{className:"tcp-subtle text-xs",children:"Ctrl/Cmd + K"})]}),e("div",{className:"p-3",children:[e("input",{autoFocus:!0,value:r,onInput:d=>s(d.target.value),placeholder:"Jump to route or action",className:"tcp-input"}),e("div",{className:"mt-3 grid max-h-[50vh] gap-2 overflow-auto",children:[l.map(d=>e("button",{type:"button",className:"tcp-btn w-full justify-between",onClick:()=>{d.onSelect(),t()},children:[e("span",{className:"inline-flex items-center gap-1.5",children:[e("i",{"data-lucide":"list"}),e("span",{children:d.label})]}),e("span",{className:"tcp-subtle text-xs",children:d.group})]},d.id)),l.length?null:e("p",{className:"tcp-subtle px-1 py-2",children:"No matching action."})]})]})]})}):null})}const Ys=[["dashboard","Dashboard","home"],["chat","Chat","message-square"],["studio","Studio","network"],["automations","Automations","bot"],["agents","Agents","users"],["orchestrator","Orchestrator","sparkles"],["memory","Memory","database"],["feed","Live Feed","radio"],["settings","Settings","settings"],["packs","Packs","package"],["teams","Teams","users"],["channels","Channels","message-circle"],["mcp","MCP","link"],["bug-monitor","Bug Monitor","bug-play"],["files","Files","folder-open"],["packs-detail","Packs","package"],["teams-detail","Teams","users"]],lc=Ys.filter(([a])=>["dashboard","chat","studio","automations","agents","orchestrator","memory","feed","settings"].includes(a)),Xs={openai:{label:"OpenAI",keyUrl:"https://platform.openai.com/api-keys",placeholder:"sk-proj-..."},anthropic:{label:"Anthropic",keyUrl:"https://console.anthropic.com/settings/keys",placeholder:"sk-ant-..."},google:{label:"Google",keyUrl:"https://aistudio.google.com/app/apikey",placeholder:"AIza..."},groq:{label:"Groq",keyUrl:"https://console.groq.com/keys",placeholder:"gsk_..."},mistral:{label:"Mistral",keyUrl:"https://console.mistral.ai/api-keys/",placeholder:"..."},together:{label:"Together",keyUrl:"https://api.together.xyz/settings/api-keys",placeholder:"..."},cohere:{label:"Cohere",keyUrl:"https://dashboard.cohere.com/api-keys",placeholder:"..."},openrouter:{label:"OpenRouter",keyUrl:"https://openrouter.ai/settings/keys",placeholder:"sk-or-v1-..."},azure:{label:"Azure OpenAI",keyUrl:"https://portal.azure.com/",placeholder:"..."},bedrock:{label:"Bedrock",keyUrl:"https://console.aws.amazon.com/bedrock/",placeholder:"..."},vertex:{label:"Vertex",keyUrl:"https://console.cloud.google.com/vertex-ai",placeholder:"..."},copilot:{label:"GitHub Copilot",keyUrl:"https://github.com/settings/tokens",placeholder:"ghp_..."},ollama:{label:"Ollama",keyUrl:"",placeholder:"No key required"}},Zs=Ys,cc=lc,dc=new Map([["packs","automations"],["teams","automations"],["swarm","orchestrator"],["failure-reporter","bug-monitor"]]),uc=new Set(Zs.map(([a])=>a));function qr(a,t="dashboard"){const n=dc.get(String(a||"").trim());return n||(uc.has(a)?a:t)}function Zr(a="dashboard"){const t=(window.location.hash||`#/${a}`).replace(/^#\//,"");return qr(t.split("?")[0].split("/")[0].trim(),a)}function mc(a){window.location.hash=`#/${a}`}function pc(){const[a,t]=w(()=>Zr());be(()=>{const r=()=>t(Zr());return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const n=ut(r=>{const s=qr(r);if(window.location.hash!==`#/${s}`){mc(s);return}t(s)},[]);return{route:a,navigate:n}}const ei=Oi({toast:()=>{}});function hc({children:a}){const[t,n]=w([]),r=ut((l,d)=>{const u=Math.random().toString(36).slice(2);n(p=>[...p,{id:u,kind:l,text:d}].slice(-4)),window.setTimeout(()=>{n(p=>p.filter(_=>_.id!==u))},3500)},[]),s=L(()=>({toast:r}),[r]);return e(ei.Provider,{value:s,children:[a,e("div",{className:"toasts","aria-live":"polite","aria-atomic":"true",children:e(Tt,{children:t.map(l=>e(Me.div,{initial:{opacity:0,y:-8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.16,ease:"easeOut"},className:`toast toast-${l.kind}`,children:l.text},l.id))})})]})}function gc(){return Ei(ei)}function Kt({title:a,subtitle:t,children:n,actions:r,className:s}){return e(ft,{title:a,subtitle:t,actions:r,className:s||"",children:n})}function We({text:a,title:t,action:n}){return e(nc,{text:a,title:t,action:n})}function Ht(a){return JSON.stringify(a,null,2)}function lr(a,t){return Array.isArray(a)?a:Array.isArray(a?.[t])?a[t]:[]}function fc(a){return new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1}).format(Number(a||0))}function bc(a){const{api:t,client:n,navigate:r,providerStatus:s}=a,[l,d]=w(""),u=new Set(["workflow","bug_monitor_triage"]),p=Z({queryKey:["dashboard","health"],queryFn:()=>t("/api/system/health"),refetchInterval:15e3}),_=Z({queryKey:["dashboard","sessions"],queryFn:()=>n.sessions.list({pageSize:8}).catch(()=>[]),refetchInterval:15e3}),D=Z({queryKey:["dashboard","routines"],queryFn:()=>n.routines.list().catch(()=>({routines:[]})),refetchInterval:2e4}),x=Z({queryKey:["dashboard","swarm"],queryFn:()=>t("/api/swarm/status").catch(()=>({status:"unknown",activeRuns:0})),refetchInterval:6e3}),P=Z({queryKey:["dashboard","workflow-context-runs"],queryFn:()=>t("/api/engine/context/runs?limit=12").catch(()=>({runs:[]})),refetchInterval:6e3}),O=Z({queryKey:["dashboard","workflow-context-run",l],enabled:!!l,queryFn:()=>t(`/api/engine/context/runs/${encodeURIComponent(l)}`).catch(()=>({run:null}))}),k=Z({queryKey:["dashboard","workflow-context-blackboard",l],enabled:!!l,queryFn:()=>t(`/api/engine/context/runs/${encodeURIComponent(l)}/blackboard`).catch(()=>({blackboard:null}))}),J=lr(_.data,"sessions"),A=lr(D.data,"routines"),G=lr(P.data,"runs").filter(R=>u.has(String(R?.run_type||"").trim().toLowerCase())),ee=!!(p.data?.engine?.ready||p.data?.engine?.healthy),de=String(x.data?.status||"unknown"),S=["planning","awaiting_approval","running","executing"].includes(de.toLowerCase()),I=G.filter(R=>["queued","planning","running","awaiting_approval"].includes(String(R?.status||"").trim().toLowerCase())),Q=L(()=>[{label:"Recent sessions",value:J.length,tone:"info",helper:"Latest active conversation surfaces"},{label:"Automations",value:A.length,tone:"ok",helper:"Configured routines and schedules"},{label:"Swarm status",value:S?1:0,tone:S?"warn":"ghost",helper:de},{label:"Provider ready",value:s.ready?1:0,tone:s.ready?"ok":"warn",helper:s.ready?s.defaultModel:"Needs setup"},{label:"Context runs",value:G.length,tone:I.length?"warn":"info",helper:I.length?`${I.length} active`:"Workflow + triage visibility"}],[I.length,s.defaultModel,s.ready,A.length,J.length,S,de,G.length]);return e(Mn,{className:"grid gap-4",children:[e(ft,{className:"overflow-hidden",children:[e("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)] xl:items-start",children:[e("div",{className:"min-w-0",children:[e("div",{className:"tcp-page-eyebrow",children:"Overview"}),e("h1",{className:"tcp-page-title",children:"Command center"}),e("p",{className:"tcp-subtle mt-2 max-w-3xl",children:"A higher-signal home screen with animated state, quick entry points, and a clearer read on what the system is doing right now."}),e("div",{className:"mt-3 flex flex-wrap gap-2",children:[e(je,{tone:ee?"ok":"warn",children:ee?"Engine healthy":"Engine checking"}),e(je,{tone:s.ready?"ok":"warn",children:s.ready?s.defaultProvider:"Provider setup required"}),S?e(ka,{tone:"live",text:`Swarm ${de}`}):e(je,{tone:"ghost",children:["Swarm ",de]})]})]}),e("div",{className:"grid gap-3",children:e(va,{className:"justify-start",children:[e("button",{className:"tcp-btn-primary w-full sm:w-auto",onClick:()=>r("chat"),children:[e("i",{"data-lucide":"message-square"}),"Chat session"]}),e("button",{className:"tcp-btn w-full sm:w-auto",onClick:()=>r("orchestrator"),children:[e("i",{"data-lucide":"sparkles"}),"Plan work"]}),e("button",{className:"tcp-btn w-full sm:w-auto",onClick:()=>r("automations"),children:[e("i",{"data-lucide":"bot"}),"Automations"]}),e("button",{className:"tcp-btn w-full sm:w-auto",onClick:()=>r("settings"),children:[e("i",{"data-lucide":"settings"}),"Configure runtime"]})]})})]}),e("div",{className:"mt-5",children:[e("div",{className:"dashboard-kpis",children:Q.map(R=>e("div",{children:[e("div",{className:"flex items-start justify-between gap-3",children:[e("span",{className:"dashboard-kpi-label",children:R.label}),e(je,{tone:R.tone,children:R.helper})]}),e("strong",{children:e(ac,{value:R.value,format:fc})})]},R.label))}),e("div",{className:"mt-4 dashboard-bars",children:[e("div",{className:"dashboard-bar-row",children:[e("div",{className:"dashboard-bar-meta",children:[e("span",{children:"Engine readiness"}),e("span",{className:"dashboard-bar-count",children:ee?"100%":"45%"})]}),e("div",{className:"dashboard-bar-track",children:e("span",{className:"dashboard-bar-fill completed",style:{width:ee?"100%":"45%"}})})]}),e("div",{className:"dashboard-bar-row",children:[e("div",{className:"dashboard-bar-meta",children:[e("span",{children:"Provider confidence"}),e("span",{className:"dashboard-bar-count",children:s.ready?"100%":"30%"})]}),e("div",{className:"dashboard-bar-track",children:e("span",{className:`dashboard-bar-fill ${s.ready?"running":"queued"}`,style:{width:s.ready?"100%":"30%"}})})]}),e("div",{className:"dashboard-bar-row",children:[e("div",{className:"dashboard-bar-meta",children:[e("span",{children:"Automation activity"}),e("span",{className:"dashboard-bar-count",children:[A.length," routines"]})]}),e("div",{className:"dashboard-bar-track",children:e("span",{className:`dashboard-bar-fill ${A.length?"scheduled":"manual"}`,style:{width:`${Math.min(100,Math.max(12,A.length*12))}%`}})})]})]})]})]}),e(In,{main:e(ft,{title:"Recent sessions",subtitle:"Latest conversations, ready to reopen.",children:e("div",{className:"grid gap-2",children:J.length?J.map(R=>e("button",{className:"tcp-list-item text-left",onClick:()=>r("chat"),children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"messages-square"}),String(R.title||R.id||"Session")]}),e("div",{className:"tcp-subtle mt-1 text-xs",children:String(R.id||R.session_id||"")})]},String(R.id||R.session_id||Math.random()))):e(We,{text:"Start a conversation to populate recent sessions here."})})}),aside:e("div",{className:"grid gap-4",children:[e(ft,{title:"Context visibility",subtitle:"Recent workflow and failure-triage context runs with their current projection state.",children:[e(va,{className:"mb-3",children:[e(je,{tone:I.length?"warn":"info",children:[G.length," recent"]}),e("button",{className:"tcp-btn",onClick:()=>r("orchestrator"),children:[e("i",{"data-lucide":"workflow"}),"Open orchestrator"]})]}),e("div",{className:"grid gap-2",children:G.length?G.slice(0,5).map(R=>e("button",{className:"tcp-list-item text-left",onClick:()=>d(String(R?.run_id||"").trim()),children:[e("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e("div",{className:"font-medium",children:String(R?.objective||R?.run_id||"Context run")}),e("div",{className:"flex flex-wrap items-center gap-2",children:[e(je,{tone:"ghost",children:String(R?.run_type||"context")}),e(je,{tone:["failed","cancelled"].includes(String(R?.status||"").toLowerCase())?"err":["running","queued","planning"].includes(String(R?.status||"").toLowerCase())?"warn":"ok",children:String(R?.status||"unknown")})]})]}),e("div",{className:"tcp-subtle text-xs",children:String(R?.run_id||"")}),e("div",{className:"tcp-subtle mt-1 text-xs",children:[Array.isArray(R?.tasks)?R.tasks.length:0," tasks ·"," ",Array.isArray(R?.steps)?R.steps.length:0," steps"]})]},String(R?.run_id||Math.random()))):e(We,{text:"Workflow and failure-triage context runs will appear here once they execute."})})]}),e(ft,{title:"Automation snapshot",subtitle:"Schedules and run-ready routines.",children:[e(va,{className:"mb-3",children:[e(je,{tone:"info",children:[A.length," loaded"]}),e("button",{className:"tcp-btn",onClick:()=>r("automations"),children:[e("i",{"data-lucide":"bot"}),"Manage"]})]}),e("div",{className:"grid gap-2",children:A.length?A.slice(0,4).map(R=>e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium",children:String(R.name||R.id||"Routine")}),e("div",{className:"tcp-subtle mt-1 text-xs",children:String(R.schedule||R.status||"manual")})]},String(R.id||R.routine_id||Math.random()))):e(We,{text:"No routines are configured yet."})})]}),e(ft,{title:"Health notes",subtitle:"Direct links for the next likely action.",children:e("div",{className:"grid gap-2",children:[e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"activity"}),"Engine endpoint"]}),e("div",{className:"tcp-subtle mt-1 text-xs",children:String(p.data?.engineUrl||"Unavailable")})]}),e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"radio"}),"Swarm"]}),e("div",{className:"tcp-subtle mt-1 text-xs",children:["Status: ",de]})]}),e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium inline-flex items-center gap-2",children:[e("i",{"data-lucide":"database"}),"Memory & feed"]}),e("div",{className:"mt-2 flex flex-wrap gap-2",children:[e("button",{className:"tcp-btn h-8 px-3 text-xs",onClick:()=>r("memory"),children:"Open memory"}),e("button",{className:"tcp-btn h-8 px-3 text-xs",onClick:()=>r("feed"),children:"Open live feed"})]})]})]})})]})}),e(er,{open:!!l,onClose:()=>d(""),title:l||"Workflow context run",children:l?e("div",{className:"grid gap-3",children:[e("div",{className:"tcp-list-item",children:[e("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e("strong",{children:String(O.data?.run?.objective||l)}),e(je,{tone:"info",children:String(O.data?.run?.status||"unknown")})]}),e("div",{className:"tcp-subtle text-xs",children:["type: ",String(O.data?.run?.run_type||"workflow")]})]}),e("div",{className:"tcp-list-item",children:[e("div",{className:"font-medium mb-2",children:"Projected blackboard"}),e("div",{className:"tcp-subtle text-xs",children:["tasks:"," ",Array.isArray(k.data?.blackboard?.tasks)?k.data.blackboard.tasks.length:0," · ","artifacts:"," ",Array.isArray(k.data?.blackboard?.artifacts)?k.data.blackboard.artifacts.length:0]})]}),e("pre",{className:"tcp-code",children:Ht({run:O.data?.run||null,blackboard:k.data?.blackboard||null})})]}):null})]})}const vc={Activity:il,Archive:sl,ArrowLeftToLine:rl,ArrowUpCircle:nl,BadgeCheck:al,Binary:tl,Bug:el,BugPlay:Zo,Bot:Xo,BookOpen:Yo,Check:Vo,ChevronDown:Ho,ChevronRight:Go,ClipboardList:Qo,Clock:Jo,Clock3:zo,Copy:Wo,CopyPlus:Lo,ExternalLink:Ko,Cpu:Fo,Database:Bo,Download:Uo,FileUp:jo,Filter:Do,FilterX:Eo,FlaskConical:Oo,FolderOpen:$o,History:Mo,Home:qo,Info:Ro,KeyRound:To,Link:Po,LoaderCircle:Ao,List:Co,LogOut:Io,MessageCircle:So,MessageSquare:_o,MessagesSquare:No,Menu:ko,MonitorCog:xo,Network:wo,Paperclip:yo,Package:vo,PaintBucket:bo,Pencil:fo,Play:go,PlugZap:ho,Plus:po,Pause:mo,Radio:uo,RefreshCw:co,RotateCw:lo,Save:oo,Search:io,Send:so,Settings:ro,Settings2:no,ShieldAlert:ao,ShieldCheck:to,SlidersHorizontal:eo,Sparkles:Zi,Siren:Xi,Share2:Yi,Shield:Vi,Square:Hi,Trash2:Gi,TriangleAlert:Qi,X:Ji,XCircle:zi,Users:Wi,Workflow:Li},xr=new Set;let kr=0;function yc(){kr=0;const a=[...xr];xr.clear();for(const t of a)Ki({icons:vc,attrs:{width:"16",height:"16","stroke-width":"1.8"},...t?{root:t}:{}})}function ya(a){xr.add(a||null),!kr&&(kr=window.requestAnimationFrame(yc))}Ks.setOptions({gfm:!0,breaks:!0});function cn(a){const t=String(a||""),n=Ks.parse(t,{async:!1});return ll.sanitize(n)}const Nr="tcp.chat.session";function ti(a){return String(a?.id||a?.session_id||a?.sessionID||"").trim()}function wc(a){const t=String(a?.title||a?.name||"").trim();if(t)return t;const n=ti(a);return n?`Session ${n.slice(0,8)}`:"Session"}function xc(a){return Array.isArray(a)?a:Array.isArray(a?.sessions)?a.sessions:[]}function kc(a){return String(a?.title||"").trim().toLowerCase().startsWith("__provider_test__")}function es(a){return xc(a).filter(t=>!kc(t)).map(t=>({id:ti(t),title:wc(t),raw:t})).filter(t=>!!t.id)}async function Nc(a,t){try{const n=await a.sessions.list({pageSize:50}),r=es(n);if(r.length>0)return r}catch{}try{const n=await t("/api/engine/session?page_size=50",{method:"GET"});return es(n)}catch{return[]}}function ts(){try{return localStorage.getItem(Nr)||""}catch{return""}}function _c(a){try{a?localStorage.setItem(Nr,a):localStorage.removeItem(Nr)}catch{}}function Sc(a){return Array.isArray(a)?a.map(n=>n?typeof n=="string"?n:typeof n.text=="string"?n.text:typeof n.delta=="string"?n.delta:typeof n.content=="string"?n.content:"":"").filter(Boolean).join(`
|
|
3
3
|
`).trim():""}function Ic(a){return String(a?.info?.role||a?.role||a?.message_role||a?.type||a?.author||"assistant").trim().toLowerCase()}function Cc(a){const t=Sc(a?.parts);if(t)return t;const n=[a?.content,a?.text,a?.message,a?.delta,a?.body].map(s=>typeof s=="string"?s:"").find(s=>s.trim().length>0);if(n)return n.trim();const r=a?.content;if(Array.isArray(r)){const s=r.map(l=>l?typeof l=="string"?l:typeof l?.text=="string"?l.text:typeof l?.content=="string"?l.content:"":"").filter(Boolean);if(s.length)return s.join(`
|
|
4
4
|
`).trim()}return""}function Ac(a,t){return a==="assistant"?t||"Assistant":a==="user"?"User":a==="system"?"System":a||"Assistant"}function Pc(a,t,n){const r=Ic(a),s=Cc(a),l=r==="assistant"||r==="system";return{id:String(a?.id||a?.messageID||a?.message_id||a?.event_id||`${r}-${t}`).trim()||`${r}-${t}`,role:r,displayRole:Ac(r,n),text:s,markdown:l}}function ai(a,t){return(Array.isArray(a)?a:Array.isArray(a?.messages)?a.messages:[]).map((r,s)=>Pc(r,s,t))}const as=new Set(["tool.called","tool_call.started","session.tool_call"]),ns=new Set(["tool.result","tool_call.completed","tool_call.failed","session.tool_result"]),Tc=new Set(["run.complete","run.completed","session.run.finished","session.run.completed"]),Rc=new Set(["run.failed","session.run.failed","run.cancelled","run.canceled","session.run.cancelled","session.run.canceled"]);function ni(a){return String(a||"").trim().replace(/\s+/g," ").replace(/[<>]/g,"")}function rn(a){const t=a||{},n=t.call||t.toolCall||t.part||{};return ni(t.tool||t.name||t.toolName||t.tool_id||t.toolID||n.tool||n.name||n.toolName||"")}function bn(a){const t=a||{},n=t.call||t.toolCall||t.part||{};return String(t.callID||t.toolCallID||t.tool_call_id||t.id||n.callID||n.toolCallID||n.tool_call_id||n.id||"").trim()}function cr(a,t=""){const n=a?.properties||{};return String(a?.runId||a?.runID||a?.run_id||n.runID||n.runId||n.run_id||n.run?.id||t).trim()}function jn(a){if(!a)return null;const t=a.request||a.approval||a.permission||{},n=String(a.id||a.requestID||a.requestId||a.approvalID||t.id||t.requestID||"").trim();return n?{id:n,tool:ni(a.tool||t.tool||t.name||"tool")||"tool",permission:String(a.permission||t.permission||"").trim(),pattern:String(a.pattern||t.pattern||"").trim(),sessionId:String(a.sessionId||a.sessionID||a.session_id||t.sessionId||t.sessionID||"").trim(),status:String(a.status||t.status||"").trim().toLowerCase()}:null}function rs(a){const t=String(a||"").trim().toLowerCase();return t?t.includes("approved")||t.includes("rejected")||t.includes("denied")||t.includes("resolved")||t.includes("expired")||t.includes("cancel")||t.includes("complete")||t.includes("done")||t.includes("timeout")?!1:t.includes("pending")||t.includes("request")||t.includes("ask")||t.includes("await")||t.includes("open")||t.includes("queue")||t.includes("new")||t.includes("progress")||t==="unknown":!0}function qc(a,t){const n=t&&typeof t=="object"?t:{},r=String(a||"").trim()||"pack.event",s=String(n.path||"").trim(),l=String(n.attachment_id||n.attachmentId||"").trim(),d=String(n.connector||"").trim(),u=String(n.channel_id||n.channelId||"").trim(),p=String(n.sender_id||n.senderId||"").trim(),_=String(n.name||"").trim(),D=String(n.version||"").trim(),x=String(n.error||"").trim(),P=[];_&&P.push(_),D&&P.push(D),s&&P.push(s),d&&P.push(d),u&&P.push(`channel=${u}`),p&&P.push(`sender=${p}`);const O=P.join(" · ");return{id:`${r}:${l||s||_||"event"}`,type:r,path:s,attachmentId:l,connector:d,channelId:u,senderId:p,error:x,summary:O||r,at:Date.now()}}const Cn=new Map;function ri(a,t){return`${t?"cred":"anon"}:${a}`}function Mc(a,t=!0){const n=ri(a,t),r=Cn.get(n);if(r&&!r.closed)return r;const s=new EventSource(a,{withCredentials:t}),l={source:s,listeners:new Set,errorListeners:new Set,refs:0,closed:!1};return s.onmessage=d=>{for(const u of[...l.listeners])try{u(d)}catch{}},s.onerror=d=>{for(const u of[...l.errorListeners])try{u(d)}catch{}s.readyState===EventSource.CLOSED&&(l.closed=!0,Cn.delete(n))},Cn.set(n,l),l}function Mr(a,t,n={}){const r=n.withCredentials!==!1,s=ri(a,r),l=Mc(a,r);return l.refs+=1,l.listeners.add(t),typeof n.onError=="function"&&l.errorListeners.add(n.onError),()=>{const d=Cn.get(s);d&&(d.listeners.delete(t),typeof n.onError=="function"&&d.errorListeners.delete(n.onError),d.refs=Math.max(0,d.refs-1),d.refs===0&&(d.closed=!0,d.source.close(),Cn.delete(s)))}}const $c="control-panel",si="tandem_control_panel_chat_auto_approve_tools",Oc="tandem.automations.plannerSeed",Ec={md:"text/markdown",txt:"text/plain",csv:"text/csv",json:"application/json",pdf:"application/pdf",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp"};function ss(a=""){const t=String(a).toLowerCase().split(".").pop()||"";return Ec[t]||"application/octet-stream"}function Dc(a="",t=""){if(!a||!t)return t||"";const n=String(a).replace(/[\\/]+$/,""),r=String(t).replace(/^[\\/]+/,"");return`${n}/${r}`}function jc(a){const t=Number(a||0);return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function dr(a,t){return!a||!t?!0:String(a).trim()===String(t).trim()}function Uc(a){const t=String(a||"").trim();return t!=="server.connected"&&t!=="engine.lifecycle.ready"}function Bc(a){return a==="completed"?"chat-tool-chip-ok":a==="failed"?"chat-tool-chip-failed":"chat-tool-chip-running"}function Fc(){try{return localStorage.getItem(si)==="1"}catch{return!1}}function Kc(a){try{localStorage.setItem(si,a?"1":"0")}catch{}}function Lc(a){try{const t=String(a?.prompt||a?.goal||"").trim();if(!t)return;sessionStorage.setItem(Oc,JSON.stringify({prompt:t,plan_source:String(a?.plan_source||"chat_setup").trim()||"chat_setup"}))}catch{}}function Ja(a){return a instanceof Error?a.message:String(a)}function Wc(a){return a.decision==="pass_through"?null:a.intent_kind==="provider_setup"?{title:"Provider setup",body:`Configure ${a.slots.provider_ids[0]||"a provider"} in Settings.`,cta:"Open Settings",actionType:"open_provider_setup",payload:a.proposed_action.payload||{}}:a.intent_kind==="integration_setup"?{title:"Tool connection",body:`Connect ${a.slots.integration_targets[0]||"the matching tool"} through MCP.`,cta:"Open MCP",actionType:"open_mcp_setup",payload:a.proposed_action.payload||{}}:a.intent_kind==="automation_create"?{title:"Automation setup",body:a.slots.goal||"Create an automation from this request.",cta:"Open Automations",actionType:"open_automations",payload:a.proposed_action.payload||{}}:{title:"Setup help",body:a.clarifier?.question||"Choose a setup path.",cta:"Open Settings",actionType:"open_provider_setup",payload:a.proposed_action.payload||{},clarifier:a.clarifier||void 0}}function zc({client:a,api:t,toast:n,providerStatus:r,identity:s,navigate:l}){const d=aa(),u=!!Fs(),p=Pt(null),_=Pt(null),D=Pt(null),x=Pt(null),P=Pt(null),O=Pt(!0),k=Pt(null),J=Pt(null),[A,G]=w([]),[ee,de]=w(!1),[S,I]=w(ts()),[Q,R]=w([]),[we,y]=w(!1),[v,U]=w(""),[pe,X]=w([]),[$e,Oe]=w([]),[Ke,ae]=w(!1),[ue,M]=w(""),[he,Te]=w(!1),[Re,re]=w([]),[Ue,qe]=w(new Set),[ze,V]=w([]),[He,ne]=w(new Set),[Ie,ht]=w([]),[se,F]=w(new Set),[rt,mt]=w(Fc()),[ot,St]=w(!1),[Ee,Rt]=w([]),[yt,Ot]=w(null),[Je,Qe]=w(null),nt=L(()=>A.find(j=>j.id===S)?.title||"Chat",[S,A]);be(()=>(O.current=!0,()=>{O.current=!1,P.current?.abort(),k.current&&window.clearTimeout(k.current),J.current&&window.clearTimeout(J.current)}),[]),be(()=>{const h=p.current;h&&ya(h)},[A,pe,$e,Ie,Re,ze,Q,ee,he,ue]),be(()=>{_c(S)},[S]),be(()=>{const h=_.current;h&&(h.style.height="0px",h.style.height=`${Math.min(h.scrollHeight,180)}px`)},[v]),be(()=>{const h=x.current;h&&(h.scrollTop=h.scrollHeight)},[Q,ue,he]);const ye=ut(async()=>{const h=await Nc(a,t);O.current&&(G(h),I(j=>{if(j&&h.some(K=>K.id===j))return j;const z=ts();return z&&h.some(K=>K.id===z)?z:h[0]?.id||""}))},[t,a]),Ne=ut(async()=>{const h=String(r.defaultProvider||"").trim(),j=String(r.defaultModel||"").trim();if(h&&j)return{providerID:h,modelID:j};try{const z=await a.providers.config(),K=String(z?.default||"").trim(),H=String(z?.providers?.[K]?.defaultModel||"").trim();if(K&&H)return{providerID:K,modelID:H}}catch{}return null},[a.providers,r.defaultModel,r.defaultProvider]),Ve=ut(async()=>{const h=await Ne(),j={title:`Chat ${new Date().toLocaleTimeString()}`};h&&(j.provider=h.providerID,j.model=h.modelID);const z=await a.sessions.create(j),K=String(z||"").trim();if(!K)throw new Error("Failed to create session.");return I(K),await ye(),K},[a.sessions,ye,Ne]),le=ut(h=>{const j=ai(h,s.botName||"Assistant");R(j)},[s.botName]),it=ut(async()=>{if(!S){R([]);return}y(!0);try{const h=await a.sessions.messages(S).catch(()=>({messages:[]}));if(!O.current)return;le(h)}finally{O.current&&y(!1)}},[a.sessions,le,S]),N=ut(()=>{re([]),qe(new Set)},[]),W=ut(()=>{V([]),ne(new Set)},[]),ve=ut((h,j,z="")=>{const K=String(h||"").trim();if(!K)return;let H=!0;z&&(qe(fe=>{if(fe.has(z))return H=!1,fe;const Be=new Set(fe);return Be.add(z),Be.size>1e3?new Set([z]):Be}),!H)||re(fe=>[{id:`${K}:${j}:${Date.now()}:${Math.random().toString(36).slice(2,8)}`,tool:K,status:j,at:Date.now()},...fe].slice(0,80))},[]),De=ut((h,j)=>{const z=qc(h,j);if(!String(z.type).toLowerCase().startsWith("pack."))return;let H=!0;ne(fe=>{if(fe.has(z.id))return H=!1,fe;const Be=new Set(fe);return Be.add(z.id),Be.size>400?new Set([z.id]):Be}),H&&V(fe=>[z,...fe].slice(0,80))},[]),o=ut(h=>{rs(h?.status||"")&&ht(j=>{const z=j.findIndex(K=>K.id===h.id);if(z>=0){const K=[...j];return K[z]={...K[z],...h},K}return[h,...j]})},[]),b=ut(h=>{ht(j=>j.filter(z=>z.id!==h))},[]),T=ut(async()=>{const h=await a.permissions.list().catch(()=>({requests:[]})),z=(Array.isArray(h?.requests)?h.requests:[]).map(K=>jn(K)).filter(K=>!!K).filter(K=>dr(K.sessionId,S)).filter(K=>rs(K.status));O.current&&ht(z.slice(0,80))},[a.permissions,S]),C=ut(async(h,j,z=!1)=>{if(!(!h||se.has(h))){F(H=>{const fe=new Set(H);return fe.add(h),fe});try{await a.permissions.reply(h,j),b(h),z||n("ok",`Permission ${j==="deny"?"denied":"approved"} (${h}).`)}catch(H){z||n("err",Ja(H))}finally{F(H=>{const fe=new Set(H);return fe.delete(h),fe}),T()}}},[a.permissions,se,T,b,n]),$=ut(async()=>{if(!(!rt||ot||Ie.length===0)){St(!0);try{for(const h of[...Ie])await C(h.id,"always",!0)}finally{O.current&&St(!1)}}},[rt,ot,Ie,C]),Ye=ut(h=>(Array.isArray(h)?h:Array.isArray(h?.tools)?h.tools:[]).map(z=>{if(typeof z=="string")return z;const K=z||{};return String(K.name||K.id||K.tool||"").trim()}).filter(Boolean),[]),Ze=ut(async()=>{try{const h=await a.listTools?.().catch(()=>null);let j=Ye(h||[]);if(!j.length){const z=await t("/api/engine/tool",{method:"GET"}).catch(()=>[]);j=Ye(z||[])}if(O.current){const z=[...new Set(j)].sort((K,H)=>K.localeCompare(H));Rt(z)}}catch{O.current&&Rt([])}},[t,a,Ye]),bt=ut(h=>new Promise((j,z)=>{const K=`${Date.now()}-${Math.random().toString(16).slice(2)}`;Oe(fe=>[...fe,{id:K,name:h.name,progress:0,error:""}]);const H=new XMLHttpRequest;H.open("POST",`/api/files/upload?dir=${encodeURIComponent($c)}`),H.withCredentials=!0,H.responseType="json",H.setRequestHeader("x-file-name",encodeURIComponent(h.name)),H.upload.onprogress=fe=>{if(!fe.lengthComputable)return;const Be=fe.loaded/fe.total*100;Oe(pt=>pt.map(lt=>lt.id===K?{...lt,progress:Be}:lt))},H.onerror=()=>{Oe(fe=>fe.map(Be=>Be.id===K?{...Be,error:"Network error"}:Be)),window.setTimeout(()=>{Oe(fe=>fe.filter(Be=>Be.id!==K))},1200),z(new Error(`Upload failed: ${h.name}`))},H.onload=()=>{const fe=H.response||{};if(H.status<200||H.status>=300||fe?.ok===!1){const Be=String(fe?.error||`Upload failed (${H.status})`);Oe(pt=>pt.map(lt=>lt.id===K?{...lt,error:Be}:lt)),window.setTimeout(()=>{Oe(pt=>pt.filter(lt=>lt.id!==K))},1600),z(new Error(Be));return}Oe(Be=>Be.filter(pt=>pt.id!==K)),j(fe)},H.send(h)}),[]),qt=ut(async h=>{const j=[...h||[]];if(!j.length)return;let z=0;for(const K of j)try{const H=await bt(K);X(fe=>[{name:String(H?.name||K.name),path:String(H?.path||K.name),size:Number(H?.size||K.size||0),mime:K.type||ss(String(H?.name||K.name)),url:String(H?.absPath||Dc(H?.root,H?.path)||H?.path||K.name)},...fe]),z+=1}catch(H){n("err",Ja(H))}z>0&&n("ok",`Uploaded ${z} file${z===1?"":"s"}.`)},[n,bt]),Ae=ut(async h=>{if(await a.sessions.delete(h),G(j=>j.filter(z=>z.id!==h)),Ot(null),n("ok","Session deleted."),S===h){const j=A.find(z=>z.id!==h)?.id||"";if(j)I(j);else{const z=await Ve();I(z)}}},[a.sessions,Ve,S,A,n]),wt=ut((h,j)=>{const z=String(h||"").trim();if(!z)return;const K=j>0?`
|
|
5
5
|
|
package/dist/index.html
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Rubik:wght@500;700;800&family=Manrope:wght@400;500;600;700&display=swap"
|
|
12
12
|
rel="stylesheet"
|
|
13
13
|
/>
|
|
14
|
-
<script type="module" crossorigin src="/assets/index-
|
|
14
|
+
<script type="module" crossorigin src="/assets/index-VDmCg_3Z.js"></script>
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/preact-vendor-jo0muZ28.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/vendor-UXzYZoAT.js">
|
|
17
17
|
<link rel="modulepreload" crossorigin href="/assets/react-query-CeeFMKtE.js">
|