opencami 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/client/assets/{CSPContext-BBLAL_m_.js → CSPContext-Bq8j4nl9.js} +1 -1
- package/dist/client/assets/DirectionContext-BdX86BHP.js +1 -0
- package/dist/client/assets/_sessionKey-DsjnpErt.js +14 -0
- package/dist/client/assets/agents-DwxKcpP6.js +2 -0
- package/dist/client/assets/agents-screen-DwIY8hze.js +1 -0
- package/dist/client/assets/bots-CRlm-3-d.js +2 -0
- package/dist/client/assets/bots-screen-c78I920d.js +1 -0
- package/dist/client/assets/button-Dg7VFQQn.js +1 -0
- package/dist/client/assets/composite-DBl8R3ae.js +1 -0
- package/dist/client/assets/{connect-DHr3hhUR.js → connect-NYvOqiBJ.js} +1 -1
- package/dist/client/assets/file-explorer-screen-BSMbs0vi.js +1 -0
- package/dist/client/assets/files-BJbMx0_w.js +2 -0
- package/dist/client/assets/{index-B2iG4EM1.js → index-CMATW8VA.js} +1 -1
- package/dist/client/assets/{index-GTR-Xzl2.js → index-rOIRO-8E.js} +1 -1
- package/dist/client/assets/keyboard-shortcuts-dialog-BTGWdJMl.js +1 -0
- package/dist/client/assets/{main-mIHr_ble.js → main-B_dlfHME.js} +9 -9
- package/dist/client/assets/markdown-BVzT7z4x.js +87 -0
- package/dist/client/assets/memory-S3Yws6a5.js +2 -0
- package/dist/client/assets/memory-screen-C-Z9o31m.js +1 -0
- package/dist/client/assets/menu-DHNgWk_8.js +1 -0
- package/dist/client/assets/{opencami-logo-CRIdKbbZ.js → opencami-logo-BQQETnJG.js} +1 -1
- package/dist/client/assets/owner-CpRnf1fI.js +1 -0
- package/dist/client/assets/popupStateMapping-BRPDXnjv.js +1 -0
- package/dist/client/assets/proxy-BcUh9kMA.js +9 -0
- package/dist/client/assets/{react-Cfq4ot0g.js → react-irH8OzhB.js} +1 -1
- package/dist/client/assets/search-dialog-B96zx_ng.js +1 -0
- package/dist/client/assets/session-export-dialog-DPuHnhgv.js +1 -0
- package/dist/client/assets/settings-dialog-DZcRCaPj.js +1 -0
- package/dist/client/assets/skills-YZe3I63y.js +2 -0
- package/dist/client/assets/{skills-panel-Cv-N_MDk.js → skills-panel-WDUfIwnI.js} +2 -2
- package/dist/client/assets/styles-Bwo-K6Y4.css +1 -0
- package/dist/client/assets/{switch-Bh9tVOYh.js → switch-DPocNFRG.js} +1 -1
- package/dist/client/assets/tabs-B0cro1hL.js +1 -0
- package/dist/client/assets/tooltip-Dg9fy-vT.js +1 -0
- package/dist/client/assets/use-file-explorer-state-DzT0bksg.js +12 -0
- package/dist/client/assets/{useButton-DsMdJPGn.js → useButton-Cbl_9oFG.js} +1 -1
- package/dist/client/assets/useCompositeItem-BDAzTxVe.js +1 -0
- package/dist/client/assets/{useControlled-wOKVgKF4.js → useControlled-Dscz_s4f.js} +1 -1
- package/dist/client/assets/{useMutation-fJnleJAb.js → useMutation-B1FlDsNN.js} +1 -1
- package/dist/client/assets/visuallyHidden-ONmQ-0U2.js +1 -0
- package/dist/server/assets/{_sessionKey-B5UHBd2U.js → _sessionKey-B0ZlLAjH.js} +172 -567
- package/dist/server/assets/_tanstack-start-manifest_v-D5UVTs1o.js +4 -0
- package/dist/server/assets/{file-explorer-screen-CVlFiAFu.js → file-explorer-screen-DH4UFK03.js} +3 -2
- package/dist/server/assets/{files-BIEcSPGp.js → files-DYdXlQDr.js} +1 -1
- package/dist/server/assets/{index--_jH_0mX.js → index-CiUjUD0t.js} +1 -1
- package/dist/server/assets/{keyboard-shortcuts-dialog-CsNP85q8.js → keyboard-shortcuts-dialog-Cr6fOqHz.js} +1 -2
- package/dist/server/assets/markdown-BFE5y9YH.js +565 -0
- package/dist/server/assets/memory-BqZOoD7Q.js +11 -0
- package/dist/server/assets/memory-screen-BK5phS8K.js +235 -0
- package/dist/server/assets/menu-D90CDTi2.js +45 -0
- package/dist/server/assets/{router-DJA7GtMo.js → router-Uuagl6O7.js} +55 -45
- package/dist/server/assets/{search-dialog-C2a3OYm_.js → search-dialog-DZTS5SEi.js} +6 -4
- package/dist/server/assets/{session-export-dialog-CwclV0Aj.js → session-export-dialog-C53RRAah.js} +1 -2
- package/dist/server/assets/{settings-dialog-CHVzrou9.js → settings-dialog-CSYDj2qm.js} +75 -20
- package/dist/server/assets/{use-file-explorer-state-Il1LlBAe.js → use-file-explorer-state-s7CS50ho.js} +0 -41
- package/dist/server/server.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/DirectionContext-DXnZc0zz.js +0 -1
- package/dist/client/assets/_sessionKey-BidmO1-D.js +0 -100
- package/dist/client/assets/agents-CtZs_u1j.js +0 -2
- package/dist/client/assets/agents-screen-Basce5qo.js +0 -1
- package/dist/client/assets/bots-C_dWjy3z.js +0 -2
- package/dist/client/assets/bots-screen-n_xhYOEE.js +0 -1
- package/dist/client/assets/button-BaHefIXU.js +0 -1
- package/dist/client/assets/file-explorer-screen-8t6M4Xco.js +0 -1
- package/dist/client/assets/files-BdlpK3Cy.js +0 -2
- package/dist/client/assets/keyboard-shortcuts-dialog-CcKSlK52.js +0 -1
- package/dist/client/assets/search-dialog-D19x_xaG.js +0 -1
- package/dist/client/assets/session-export-dialog-DRlJwhMa.js +0 -1
- package/dist/client/assets/settings-dialog-BA5FjiyP.js +0 -1
- package/dist/client/assets/skills-lmNPZksG.js +0 -2
- package/dist/client/assets/styles-JgjN_ZCd.css +0 -1
- package/dist/client/assets/tabs-BfaEc9zS.js +0 -1
- package/dist/client/assets/tooltip-w9D-e_R-.js +0 -1
- package/dist/client/assets/use-file-explorer-state-CLaDuI9X.js +0 -12
- package/dist/client/assets/useCompositeItem-CaYygSfB.js +0 -1
- package/dist/client/assets/visuallyHidden-CqGRL_Oq.js +0 -9
- package/dist/server/assets/_tanstack-start-manifest_v-D11xMFUx.js +0 -4
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# OpenCami 🦎
|
|
2
2
|
|
|
3
|
+
**Version 1.6.0**
|
|
4
|
+
|
|
3
5
|
A beautiful web client for [OpenClaw](https://github.com/openclaw/openclaw).
|
|
4
6
|
|
|
5
7
|
```bash
|
|
@@ -46,6 +48,7 @@ docker run -p 3000:3000 opencami
|
|
|
46
48
|
🔊 **Voice playback (TTS)** — ElevenLabs → OpenAI → Edge TTS fallback chain\
|
|
47
49
|
🎤 **Voice input (STT)** — ElevenLabs Scribe → OpenAI Whisper → Browser Web Speech API\
|
|
48
50
|
🔧 **TTS/STT provider selection** — choose provider and voice in Settings\
|
|
51
|
+
🔧 **Workspace Settings** — Unified toggles for Files, Memory, Agents, Skills & Cron Jobs\
|
|
49
52
|
📂 **File explorer** — 30+ file types, built-in editor, path jailing\
|
|
50
53
|
🎭 **Persona picker** — 20 personas, integrated with the personas skill\
|
|
51
54
|
🤖 **Agent manager** — sidebar panel for managing agents\
|
|
@@ -79,7 +82,7 @@ Then open the URL printed by Vite in your terminal.
|
|
|
79
82
|
|
|
80
83
|
> Dev port notes: this repo's `npm run dev` script uses port `3002`. If you run Vite directly with the config default, it targets `3003` and auto-falls back to the next free port.
|
|
81
84
|
|
|
82
|
-
## 🖥️ Desktop App (Tauri)
|
|
85
|
+
## 🖥️ Desktop App (Tauri)
|
|
83
86
|
|
|
84
87
|
> **Note:** The desktop app is experimental and under active development. The primary focus of OpenCami is the **web app**. Native builds (desktop & mobile) are secondary.
|
|
85
88
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t}from"./main-
|
|
1
|
+
import{r as t}from"./main-B_dlfHME.js";const e=t.createContext(void 0),o={disableStyleElements:!1};function s(){return t.useContext(e)??o}export{s as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as l}from"./main-B_dlfHME.js";const E=["top","right","bottom","left"],p=Math.min,h=Math.max,L=Math.round,k=Math.floor,q=t=>({x:t,y:t}),x={left:"right",right:"left",bottom:"top",top:"bottom"},d={start:"end",end:"start"};function R(t,e,n){return h(t,p(e,n))}function T(t,e){return typeof t=="function"?t(e):t}function m(t){return t.split("-")[0]}function g(t){return t.split("-")[1]}function b(t){return t==="x"?"y":"x"}function A(t){return t==="y"?"height":"width"}const P=new Set(["top","bottom"]);function y(t){return P.has(m(t))?"y":"x"}function M(t){return b(y(t))}function v(t,e,n){n===void 0&&(n=!1);const s=g(t),i=M(t),o=A(i);let r=i==="x"?s===(n?"end":"start")?"right":"left":s==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(r=a(r)),[r,a(r)]}function z(t){const e=a(t);return[c(t),e,c(e)]}function c(t){return t.replace(/start|end/g,e=>d[e])}const u=["left","right"],f=["right","left"],O=["top","bottom"],S=["bottom","top"];function C(t,e,n){switch(t){case"top":case"bottom":return n?e?f:u:e?u:f;case"left":case"right":return e?O:S;default:return[]}}function B(t,e,n,s){const i=g(t);let o=C(m(t),n==="start",s);return i&&(o=o.map(r=>r+"-"+i),e&&(o=o.concat(o.map(c)))),o}function a(t){return t.replace(/left|right|bottom|top/g,e=>x[e])}function w(t){return{top:0,right:0,bottom:0,left:0,...t}}function F(t){return typeof t!="number"?w(t):{top:t,right:t,bottom:t,left:t}}function G(t){const{x:e,y:n,width:s,height:i}=t;return{width:s,height:i,top:n,left:e,right:e+s,bottom:n+i,x:e,y:n}}const j=l.createContext(void 0);function H(){return l.useContext(j)?.direction??"ltr"}export{y as a,a as b,z as c,B as d,T as e,k as f,m as g,v as h,g as i,h as j,M as k,F as l,p as m,G as n,A as o,R as p,b as q,L as r,E as s,q as t,H as u};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-dialog-DZcRCaPj.js","assets/main-B_dlfHME.js","assets/button-Dg7VFQQn.js","assets/use-file-explorer-state-DzT0bksg.js","assets/useButton-Cbl_9oFG.js","assets/owner-CpRnf1fI.js","assets/popupStateMapping-BRPDXnjv.js","assets/visuallyHidden-ONmQ-0U2.js","assets/composite-DBl8R3ae.js","assets/react-irH8OzhB.js","assets/switch-DPocNFRG.js","assets/useControlled-Dscz_s4f.js","assets/tabs-B0cro1hL.js","assets/useCompositeItem-BDAzTxVe.js","assets/DirectionContext-BdX86BHP.js","assets/CSPContext-Bq8j4nl9.js","assets/index-CMATW8VA.js","assets/tooltip-Dg9fy-vT.js","assets/menu-DHNgWk_8.js","assets/useMutation-B1FlDsNN.js","assets/opencami-logo-BQQETnJG.js","assets/proxy-BcUh9kMA.js","assets/markdown-BVzT7z4x.js","assets/index-T4TOjvD0.js","assets/session-export-dialog-DPuHnhgv.js","assets/keyboard-shortcuts-dialog-BTGWdJMl.js","assets/search-dialog-B96zx_ng.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as n,r as o,L as qe,u as lt,_ as _t,w as Gr,a as qr,d as un,z as Vr}from"./main-B_dlfHME.js";import{u as Rt}from"./visuallyHidden-ONmQ-0U2.js";import{T as Ae,a as Ie,b as Oe,c as De,s as Ue,d as Jr,g as Cn}from"./tooltip-Dg9fy-vT.js";import{B as he,u as Qr,c as M,ac as dn,ag as Xe,t as Zr,H as B,J as Vn,V as Kt,aj as es,ak as ts,al as ns,a as Jn,am as rs,C as ss,an as os,M as fn,b as st,I as is,ao as as,a3 as ls,s as tn,ap as cs,G as us,l as Qn,L as ds,O as fs,X as mn,x as ms,h as hs,aq as Zn,ar as ps,Y as hn,p as er,as as Wt,at as Nn,au as gs,n as xs,av as ys,aw as ws}from"./button-Dg7VFQQn.js";import{D as bs,a as Ss,b as vs,c as js,d as ks,j as Cs,k as Ns,l as Es,m as Ts,n as Rs,o as Ms,p as As,q as Is,r as Os,s as tr}from"./use-file-explorer-state-DzT0bksg.js";import{d as nr,a as Fe,g as rr,t as Ds,u as Ee,f as Ls,n as Ps}from"./useButton-Cbl_9oFG.js";import{u as _s}from"./useControlled-Dscz_s4f.js";import{_ as Ks,$ as zs,a0 as En,t as sr,u as Hs,V as Ce,e as $s,a as Mt}from"./popupStateMapping-BRPDXnjv.js";import{u as Us,e as Fs,q as Ws}from"./owner-CpRnf1fI.js";import{u as Ys}from"./CSPContext-Bq8j4nl9.js";import{u as or}from"./DirectionContext-BdX86BHP.js";import{M as zt,a as Ht,b as $t,c as We}from"./menu-DHNgWk_8.js";import{u as ir}from"./useMutation-B1FlDsNN.js";import{O as Xs,a as Bs}from"./opencami-logo-BQQETnJG.js";import{m as we,A as Me}from"./proxy-BcUh9kMA.js";import{M as Gs}from"./markdown-BVzT7z4x.js";import{u as qs,p as ar}from"./index-CMATW8VA.js";import{c as lr}from"./react-irH8OzhB.js";function nn(e){if(!e)return"main";const t=e.trim();if(t.length===0)return"main";const r=t.split(":"),i=(r[r.length-1]??"").trim();return i.length>0?i:t}function Te(e){return(Array.isArray(e.content)?e.content:[]).map(r=>r.type==="text"?String(r.text??""):"").join("").trim()}function Je(e){return(Array.isArray(e.content)?e.content:[]).filter(r=>r.type==="toolCall")}function Vs(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function rn(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=Vs(r);if(s)return s}return Date.now()}const Js=["agent:main:main","main"];function sn(e){return Js.includes(e)}const Qs=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Zs(e){if(e.includes(":subagent:")||e.startsWith("agent:codex:")||e.includes(":openai:"))return"subagent";if(e.startsWith("isolated:")||e.includes(":cron:"))return"cron";if(e.startsWith("agent:")&&!e.startsWith("agent:main:"))return"other";if(e.startsWith("agent:main:")){const t=e.slice(11);return Qs.test(t)?"webchat":"chat"}return"other"}function eo(e){return Array.isArray(e)?e.map(t=>{const r=typeof t.key=="string"&&t.key.trim().length>0?t.key.trim():nn(t.friendlyId??t.key),s=typeof t.friendlyId=="string"&&t.friendlyId.trim().length>0?t.friendlyId.trim():nn(r),i=Zs(r),a=t,l=typeof a.totalTokens=="number"?a.totalTokens:void 0,c=typeof a.contextTokens=="number"?a.contextTokens:void 0,u=typeof a.status=="string"?a.status:void 0;return{key:r,friendlyId:s,title:typeof t.title=="string"?t.title:void 0,derivedTitle:typeof t.derivedTitle=="string"?t.derivedTitle:void 0,label:typeof t.label=="string"?t.label:void 0,updatedAt:typeof t.updatedAt=="number"?t.updatedAt:void 0,lastMessage:t.lastMessage??null,kind:i,status:u,totalTokens:l,contextTokens:c}}):[]}async function Le(e){try{const t=await e.json();return t?.error?String(t.error):t?.message?String(t.message):JSON.stringify(t)}catch{try{return await e.text()}catch{return e.statusText||"Request failed"}}}const to="Missing gateway auth. Set CLAWDBOT_GATEWAY_TOKEN (recommended) or CLAWDBOT_GATEWAY_PASSWORD in the server environment.";function Tn(e){return e.includes(to)}function Rn(e,t){const r=crypto.randomUUID(),s=`opt-${r}`,i=Date.now(),a=[];if(t&&t.length>0)for(const c of t)c.type==="image"&&c.base64&&a.push({type:"image",source:{type:"base64",media_type:c.file.type,data:c.base64}});return e.trim()?a.push({type:"text",text:e}):t&&t.length>0&&a.push({type:"text",text:""}),{clientId:r,optimisticId:s,optimisticMessage:{role:"user",content:a,__optimisticId:s,clientId:r,status:"sending",timestamp:i}}}const oe={sessions:["chat","sessions"],history:function(t,r){return["chat","history",t,r]}};async function no(){const e=await fetch("/api/sessions");if(!e.ok)throw new Error(await Le(e));const t=await e.json();return eo(t.sessions)}async function ro(e){const t=new URLSearchParams({limit:"200"});e.sessionKey&&t.set("sessionKey",e.sessionKey),e.friendlyId&&t.set("friendlyId",e.friendlyId);const r=await fetch(`/api/history?${t.toString()}`);if(!r.ok)throw new Error(await Le(r));return await r.json()}async function so(){const e=new AbortController,t=window.setTimeout(()=>e.abort(),2500);try{const r=await fetch("/api/ping",{signal:e.signal});if(!r.ok)throw new Error(await Le(r));return await r.json()}catch(r){throw r instanceof DOMException&&r.name==="AbortError"?new Error("Gateway check timed out"):r}finally{window.clearTimeout(t)}}function pn(e,t,r,s){const i=oe.history(t,r);e.setQueryData(i,function(l){const c=l,u=Array.isArray(c?.messages)?c.messages:[],d=s(u);return{sessionKey:c?.sessionKey??r,sessionId:c?.sessionId,messages:d}})}function Yt(e,t,r,s){pn(e,t,r,function(a){return[...a,s]})}function oo(e,t,r,s,i){const a=`opt-${s}`;pn(e,t,r,function(c){return c.map(u=>u.clientId===s||u.__optimisticId===s||u.__optimisticId===a?i(u):u)})}function io(e,t,r,s,i){pn(e,t,r,function(l){return l.filter(c=>!(c.clientId===s||c.__optimisticId===s||i&&c.__optimisticId===i))})}function on(e,t,r){const s=oe.history(t,r);e.setQueryData(s,{sessionKey:r,messages:[]})}function ao(e,t,r,s,i){const a=oe.history(t,r),l=oe.history(s,i),c=e.getQueryData(a);if(!c)return;const u=Array.isArray(c.messages)?c.messages:[];e.setQueryData(l,{sessionKey:i,sessionId:c.sessionId,messages:u}),e.removeQueries({queryKey:a,exact:!0})}function lo(e,t,r,s){e.setQueryData(oe.sessions,function(a){return Array.isArray(a)?a.map(l=>l.key!==t&&l.friendlyId!==r?l:{...l,lastMessage:s}):a})}function co(e,t,r){e.setQueryData(oe.sessions,function(i){return Array.isArray(i)?i.filter(a=>a.key!==t&&a.friendlyId!==r):i}),e.removeQueries({queryKey:["chat","history",r],exact:!1}),t&&t!==r&&e.removeQueries({queryKey:["chat","history",t],exact:!1})}async function uo(e,t,r,s){e.setQueryData(oe.sessions,function(a){return Array.isArray(a)?a.map(l=>l.key===t||l.friendlyId===r?{...l,label:s}:l):a});try{const i=await fetch("/api/sessions",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionKey:t,friendlyId:r,label:s})});if(!i.ok){const a=await Le(i);console.error("[updateSessionLabel] Failed to persist:",a)}}catch(i){console.error("[updateSessionLabel] Network error:",i)}}function cr(e){return!e.content||!Array.isArray(e.content)?"":e.content.filter(t=>t.type==="text").map(t=>t.text||"").join(`
|
|
3
|
+
`)}function fo(e,t,r){const s=[];s.push(`# Conversation: ${e}`),s.push(`Date: ${r.toLocaleString()}`),s.push("");for(const i of t){const a=i.role||"unknown",l=cr(i);if(l){const c=a==="user"?"User":"Assistant";s.push(`## ${c}`),s.push(""),s.push(l),s.push("")}}return s.join(`
|
|
4
|
+
`)}function mo(e,t,r){const s={title:e,exportDate:r.toISOString(),messages:t.map(i=>({role:i.role,content:i.content,timestamp:i.timestamp}))};return JSON.stringify(s,null,2)}function ho(e,t,r){const s=[];s.push(`Conversation: ${e}`),s.push(`Date: ${r.toLocaleString()}`),s.push("─".repeat(60)),s.push("");for(const i of t){const a=i.role||"unknown",l=cr(i);if(l){const c=a==="user"?"User":"Assistant";s.push(`${c}:`),s.push(l),s.push("")}}return s.join(`
|
|
5
|
+
`)}function po(e,t,r){const s=new Date;let i,a,l;switch(r){case"markdown":i=fo(e,t,s),a=`${Xt(e)}.md`,l="text/markdown";break;case"json":i=mo(e,t,s),a=`${Xt(e)}.json`,l="application/json";break;case"txt":i=ho(e,t,s),a=`${Xt(e)}.txt`,l="text/plain";break;default:throw new Error(`Unsupported format: ${r}`)}go(i,a,l)}function Xt(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function go(e,t,r){const s=new Blob([e],{type:r}),i=URL.createObjectURL(s),a=document.createElement("a");a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}function xo({open:e,onOpenChange:t,sessionTitle:r,onSave:s,onCancel:i}){return n.jsx(bs,{open:e,onOpenChange:t,children:n.jsx(Ss,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(vs,{className:"mb-1",children:"Rename"}),n.jsx(js,{className:"mb-4",children:"Enter a new name for this session."}),n.jsx("input",{type:"text",defaultValue:r,onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),s(a.currentTarget.value))},className:"w-full rounded-lg border border-primary-200 bg-primary-50 px-3 py-2 text-sm text-primary-900 outline-none focus:border-primary-400",placeholder:"Session name",autoFocus:!0}),n.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[n.jsx(ks,{onClick:i,children:"Cancel"}),n.jsx(he,{onClick:a=>{const l=a.currentTarget.parentElement?.previousElementSibling;s(l.value)},children:"Save"})]})]})})})}function yo(e){const{children:t,open:r,defaultOpen:s=!1,onOpenChange:i,onOpenChangeComplete:a,actionsRef:l,handle:c,triggerId:u,defaultTriggerId:d=null}=e,f=Cs(),h=!!f,m=Qr(()=>c?.store??new Ns({open:r??s,activeTriggerId:u!==void 0?u:d,modal:!0,disablePointerDismissal:!0,nested:h,role:"alertdialog"})).current;m.useControlledProp("open",r,s),m.useControlledProp("activeTriggerId",u,d),m.useSyncedValue("nested",h),m.useContextCallback("onOpenChange",i),m.useContextCallback("onOpenChangeComplete",a);const p=m.useState("payload");Es({store:m,actionsRef:l,parentContext:f?.store.context});const w=o.useMemo(()=>({store:m}),[m]);return n.jsx(Ts.Provider,{value:w,children:typeof t=="function"?t({payload:p}):t})}function wo({children:e,...t}){return n.jsx(yo,{...t,children:e})}function bo({className:e,children:t}){return n.jsxs(Rs,{children:[n.jsx(Ms,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),n.jsx(As,{className:M("fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2","w-[min(400px,92vw)] rounded-xl border border-primary-200 bg-primary-50 p-0 shadow-xl","transition-all duration-150","data-[state=open]:opacity-100 data-[state=closed]:opacity-0","data-[state=open]:scale-100 data-[state=closed]:scale-95",e),children:t})]})}function So({className:e,...t}){return n.jsx(Is,{className:M("text-lg font-medium text-primary-900",e),...t})}function vo({className:e,...t}){return n.jsx(Os,{className:M("text-sm text-primary-600",e),...t})}function jo({className:e,...t}){return n.jsx(tr,{render:n.jsx(he,{variant:"outline",className:M(e)}),...t})}function ko({className:e,...t}){return n.jsx(tr,{render:n.jsx(he,{variant:"destructive",className:M(e)}),...t})}function Co({open:e,onOpenChange:t,sessionTitle:r,onConfirm:s,onCancel:i}){return n.jsx(wo,{open:e,onOpenChange:t,children:n.jsx(bo,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(So,{className:"mb-1",children:"Delete Session"}),n.jsxs(vo,{className:"mb-4",children:['Are you sure you want to delete "',r,'"? This action cannot be undone.']}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(jo,{onClick:i,children:"Cancel"}),n.jsx(ko,{onClick:s,children:"Delete"})]})]})})})}function No(e){const{open:t,defaultOpen:r,onOpenChange:s,disabled:i}=e,a=t!==void 0,[l,c]=_s({controlled:t,default:r,name:"Collapsible",state:"open"}),{mounted:u,setMounted:d,transitionStatus:f}=Ks(l,!0,!0),[h,m]=o.useState(l),[{height:p,width:w},g]=o.useState({height:void 0,width:void 0}),k=nr(),[v,y]=o.useState(),P=v??k,[A,K]=o.useState(!1),[N,$]=o.useState(!1),G=o.useRef(null),T=o.useRef(null),X=o.useRef(null),W=o.useRef(null),C=zs(W,!1),L=Fe(R=>{const E=!l,H=rr(Ds,R.nativeEvent);if(s(E,H),H.isCanceled)return;const x=W.current;T.current==="css-animation"&&x!=null&&x.style.removeProperty("animation-name"),!A&&!N&&(T.current!=null&&T.current!=="css-animation"&&!u&&E&&d(!0),T.current==="css-animation"&&(!h&&E&&m(!0),!u&&E&&d(!0))),c(E),T.current==="none"&&u&&!E&&d(!1)});return Ee(()=>{a&&T.current==="none"&&!N&&!l&&d(!1)},[a,N,l,t,d]),o.useMemo(()=>({abortControllerRef:G,animationTypeRef:T,disabled:i,handleTrigger:L,height:p,mounted:u,open:l,panelId:P,panelRef:W,runOnceAnimationsFinish:C,setDimensions:g,setHiddenUntilFound:K,setKeepMounted:$,setMounted:d,setOpen:c,setPanelIdState:y,setVisible:m,transitionDimensionRef:X,transitionStatus:f,visible:h,width:w}),[G,T,i,L,p,u,l,P,W,C,g,K,$,d,c,m,X,f,h,w])}const ur=o.createContext(void 0);function dr(){const e=o.useContext(ur);if(e===void 0)throw new Error(dn(15));return e}let pt=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=En.startingStyle]="startingStyle",e[e.endingStyle=En.endingStyle]="endingStyle",e})({}),Eo=(function(e){return e.panelOpen="data-panel-open",e})({});const To={[pt.open]:""},Ro={[pt.closed]:""},Mo={open(e){return e?{[Eo.panelOpen]:""}:null}},Ao={open(e){return e?To:Ro}},fr={...Ao,...sr},Io=o.forwardRef(function(t,r){const{render:s,className:i,defaultOpen:a=!1,disabled:l=!1,onOpenChange:c,open:u,...d}=t,f=Fe(c),h=No({open:u,defaultOpen:a,onOpenChange:f,disabled:l}),m=o.useMemo(()=>({open:h.open,disabled:h.disabled,transitionStatus:h.transitionStatus}),[h.open,h.disabled,h.transitionStatus]),p=o.useMemo(()=>({...h,onOpenChange:f,state:m}),[h,f,m]),w=Xe("div",t,{state:m,ref:r,props:d,stateAttributesMapping:fr});return n.jsx(ur.Provider,{value:p,children:w})}),Oo={...Mo,...sr},Do=o.forwardRef(function(t,r){const{panelId:s,open:i,handleTrigger:a,state:l,disabled:c}=dr(),{className:u,disabled:d=c,id:f,render:h,nativeButton:m=!0,...p}=t,{getButtonProps:w,buttonRef:g}=Ls({disabled:d,focusableWhenDisabled:!0,native:m}),k=o.useMemo(()=>({"aria-controls":i?s:void 0,"aria-expanded":i,onClick:a}),[s,i,a]);return Xe("button",t,{state:l,ref:[r,g],props:[k,p,w],stateAttributesMapping:Oo})});let Lo=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function Po(e){const{abortControllerRef:t,animationTypeRef:r,externalRef:s,height:i,hiddenUntilFound:a,keepMounted:l,id:c,mounted:u,onOpenChange:d,open:f,panelRef:h,runOnceAnimationsFinish:m,setDimensions:p,setMounted:w,setOpen:g,setVisible:k,transitionDimensionRef:v,visible:y,width:P}=e,A=o.useRef(!1),K=o.useRef(null),N=o.useRef(f),$=o.useRef(f),G=Hs(),T=o.useMemo(()=>r.current==="css-animation"?!y:!f&&!u,[f,u,y,r]),X=Fe(C=>{if(!C)return;if(r.current==null||v.current==null){const E=getComputedStyle(C),H=E.animationName!=="none"&&E.animationName!=="",x=E.transitionDuration!=="0s"&&E.transitionDuration!=="";H&&x||(E.animationName==="none"&&E.transitionDuration!=="0s"?r.current="css-transition":E.animationName!=="none"&&E.transitionDuration==="0s"?r.current="css-animation":r.current="none"),C.getAttribute(Lo.orientation)==="horizontal"||E.transitionProperty.indexOf("width")>-1?v.current="width":v.current="height"}if(r.current!=="css-transition")return;(i===void 0||P===void 0)&&(p({height:C.scrollHeight,width:C.scrollWidth}),$.current&&C.style.setProperty("transition-duration","0s"));let L=-1,R=-1;return L=Ce.request(()=>{$.current=!1,R=Ce.request(()=>{setTimeout(()=>{C.style.removeProperty("transition-duration")})})}),()=>{Ce.cancel(L),Ce.cancel(R)}}),W=Zr(s,h,X);return Ee(()=>{if(r.current!=="css-transition")return;const C=h.current;if(!C)return;let L=-1;if(t.current!=null&&(t.current.abort(),t.current=null),f){const R={"justify-content":C.style.justifyContent,"align-items":C.style.alignItems,"align-content":C.style.alignContent,"justify-items":C.style.justifyItems};Object.keys(R).forEach(E=>{C.style.setProperty(E,"initial","important")}),!$.current&&!l&&C.setAttribute(pt.startingStyle,""),p({height:C.scrollHeight,width:C.scrollWidth}),L=Ce.request(()=>{Object.entries(R).forEach(([E,H])=>{H===""?C.style.removeProperty(E):C.style.setProperty(E,H)})})}else{if(C.scrollHeight===0&&C.scrollWidth===0)return;p({height:C.scrollHeight,width:C.scrollWidth});const R=new AbortController;t.current=R;const E=R.signal;let H=null;const x=pt.endingStyle;return H=new MutationObserver(D=>{D.some(I=>I.type==="attributes"&&I.attributeName===x)&&(H?.disconnect(),H=null,m(()=>{p({height:0,width:0}),C.style.removeProperty("content-visibility"),w(!1),t.current===R&&(t.current=null)},E))}),H.observe(C,{attributes:!0,attributeFilter:[x]}),()=>{H?.disconnect(),G.cancel(),t.current===R&&(R.abort(),t.current=null)}}return()=>{Ce.cancel(L)}},[t,r,G,a,l,u,f,h,m,p,w]),Ee(()=>{if(r.current!=="css-animation")return;const C=h.current;C&&(K.current=C.style.animationName||K.current,C.style.setProperty("animation-name","none"),p({height:C.scrollHeight,width:C.scrollWidth}),!N.current&&!A.current&&C.style.removeProperty("animation-name"),f?(t.current!=null&&(t.current.abort(),t.current=null),w(!0),k(!0)):(t.current=new AbortController,m(()=>{w(!1),k(!1),t.current=null},t.current.signal)))},[t,r,f,h,m,p,w,k,y]),Us(()=>{const C=Ce.request(()=>{N.current=!1});return()=>Ce.cancel(C)}),Ee(()=>{if(!a)return;const C=h.current;if(!C)return;let L=-1,R=-1;return f&&A.current&&(C.style.transitionDuration="0s",p({height:C.scrollHeight,width:C.scrollWidth}),L=Ce.request(()=>{A.current=!1,R=Ce.request(()=>{setTimeout(()=>{C.style.removeProperty("transition-duration")})})})),()=>{Ce.cancel(L),Ce.cancel(R)}},[a,f,h,p]),Ee(()=>{const C=h.current;C&&a&&T&&(C.setAttribute("hidden","until-found"),r.current==="css-transition"&&C.setAttribute(pt.startingStyle,""))},[a,T,r,h]),o.useEffect(function(){const L=h.current;if(!L)return;function R(E){A.current=!0,g(!0),d(!0,rr(Ps,E))}return L.addEventListener("beforematch",R),()=>{L.removeEventListener("beforematch",R)}},[d,h,g]),o.useMemo(()=>({props:{hidden:T,id:c,ref:W}}),[T,c,W])}let Mn=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const _o=o.forwardRef(function(t,r){const{className:s,hiddenUntilFound:i,keepMounted:a,render:l,id:c,...u}=t,{abortControllerRef:d,animationTypeRef:f,height:h,mounted:m,onOpenChange:p,open:w,panelId:g,panelRef:k,runOnceAnimationsFinish:v,setDimensions:y,setHiddenUntilFound:P,setKeepMounted:A,setMounted:K,setPanelIdState:N,setOpen:$,setVisible:G,state:T,transitionDimensionRef:X,visible:W,width:C,transitionStatus:L}=dr(),R=i??!1,E=a??!1;Ee(()=>{if(c)return N(c),()=>{N(void 0)}},[c,N]),Ee(()=>{P(R)},[P,R]),Ee(()=>{A(E)},[A,E]);const{props:H}=Po({abortControllerRef:d,animationTypeRef:f,externalRef:r,height:h,hiddenUntilFound:R,id:g,keepMounted:E,mounted:m,onOpenChange:p,open:w,panelRef:k,runOnceAnimationsFinish:v,setDimensions:y,setMounted:K,setOpen:$,setVisible:G,transitionDimensionRef:X,visible:W,width:C});$s({open:w&&L==="idle",ref:k,onComplete(){w&&y({height:void 0,width:void 0})}});const x=o.useMemo(()=>({...T,transitionStatus:L}),[T,L]),D=Xe("div",t,{state:x,ref:[r,k],props:[H,{style:{[Mn.collapsiblePanelHeight]:h===void 0?"auto":`${h}px`,[Mn.collapsiblePanelWidth]:C===void 0?"auto":`${C}px`}},u],stateAttributesMapping:fr});return E||R||!E&&m?D:null});function At(e){return n.jsx(Io,{...e})}function It({className:e,...t}){return n.jsx(Do,{className:M("group inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-left text-xs font-medium text-primary-500 transition-colors hover:bg-primary-100 hover:text-primary-700 data-panel-open:text-primary-700",e),...t})}function Ot({className:e,contentClassName:t,children:r,...s}){return n.jsx(_o,{className:M('flex h-(--collapsible-panel-height) flex-col overflow-hidden text-sm transition-all duration-150 ease-out data-ending-style:h-0 data-starting-style:h-0 [&[hidden]:not([hidden="until-found"])]:hidden',e),...s,children:n.jsx("div",{className:M("pt-1",t),children:r})})}const mr=o.createContext(void 0);function Ut(){const e=o.useContext(mr);if(e===void 0)throw new Error(dn(53));return e}let Dt=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const vt=500,An=16;function Ne(e,t,r){if(!e)return 0;const s=getComputedStyle(e),i=r==="x"?"Inline":"Block";return r==="x"&&t==="margin"?parseFloat(s[`${t}InlineStart`])*2:parseFloat(s[`${t}${i}Start`])+parseFloat(s[`${t}${i}End`])}let Ko=(function(e){return e.orientation="data-orientation",e.hovering="data-hovering",e.scrolling="data-scrolling",e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const jt="base-ui-disable-scrollbar",hr={className:jt,getElement(e){return n.jsx("style",{nonce:e,href:jt,precedence:"base-ui:low",children:`.${jt}{scrollbar-width:none}.${jt}::-webkit-scrollbar{display:none}`})}};let ot=(function(e){return e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const gn={hasOverflowX:e=>e?{[ot.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[ot.hasOverflowY]:""}:null,overflowXStart:e=>e?{[ot.overflowXStart]:""}:null,overflowXEnd:e=>e?{[ot.overflowXEnd]:""}:null,overflowYStart:e=>e?{[ot.overflowYStart]:""}:null,overflowYEnd:e=>e?{[ot.overflowYEnd]:""}:null,cornerHidden:()=>null},zo={x:0,y:0},In={width:0,height:0},Ho={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},$o={x:!1,y:!1,corner:!1},Uo=o.forwardRef(function(t,r){const{render:s,className:i,overflowEdgeThreshold:a,...l}=t,c=Fo(a),u=nr(),d=Mt(),f=Mt(),{nonce:h,disableStyleElements:m}=Ys(),[p,w]=o.useState(!1),[g,k]=o.useState(!1),[v,y]=o.useState(!1),[P,A]=o.useState(!1),[K,N]=o.useState(In),[$,G]=o.useState(In),[T,X]=o.useState(Ho),[W,C]=o.useState($o),L=o.useRef(null),R=o.useRef(null),E=o.useRef(null),H=o.useRef(null),x=o.useRef(null),D=o.useRef(null),S=o.useRef(null),I=o.useRef(!1),_=o.useRef(0),U=o.useRef(0),F=o.useRef(0),te=o.useRef(0),ee=o.useRef("vertical"),q=o.useRef(zo),Q=Fe(j=>{const Y=j.x-q.current.x,ie=j.y-q.current.y;q.current=j,ie!==0&&(y(!0),d.start(vt,()=>{y(!1)})),Y!==0&&(k(!0),f.start(vt,()=>{k(!1)}))}),re=Fe(j=>{j.button===0&&(I.current=!0,_.current=j.clientY,U.current=j.clientX,ee.current=j.currentTarget.getAttribute(Ko.orientation),R.current&&(F.current=R.current.scrollTop,te.current=R.current.scrollLeft),x.current&&ee.current==="vertical"&&x.current.setPointerCapture(j.pointerId),D.current&&ee.current==="horizontal"&&D.current.setPointerCapture(j.pointerId))}),V=Fe(j=>{if(!I.current)return;const Y=j.clientY-_.current,ie=j.clientX-U.current;if(R.current){const Z=R.current.scrollHeight,ae=R.current.clientHeight,ge=R.current.scrollWidth,Be=R.current.clientWidth;if(x.current&&E.current&&ee.current==="vertical"){const de=Ne(E.current,"padding","y"),je=Ne(x.current,"margin","y"),Pe=x.current.offsetHeight,ke=E.current.offsetHeight-Pe-de-je,ze=Y/ke;R.current.scrollTop=F.current+ze*(Z-ae),j.preventDefault(),y(!0),d.start(vt,()=>{y(!1)})}if(D.current&&H.current&&ee.current==="horizontal"){const de=Ne(H.current,"padding","x"),je=Ne(D.current,"margin","x"),Pe=D.current.offsetWidth,ke=H.current.offsetWidth-Pe-de-je,ze=ie/ke;R.current.scrollLeft=te.current+ze*(ge-Be),j.preventDefault(),k(!0),f.start(vt,()=>{k(!1)})}}}),J=Fe(j=>{I.current=!1,x.current&&ee.current==="vertical"&&x.current.releasePointerCapture(j.pointerId),D.current&&ee.current==="horizontal"&&D.current.releasePointerCapture(j.pointerId)});function pe(j){A(j.pointerType==="touch")}function ve(j){if(pe(j),j.pointerType!=="touch"){const Y=Fs(L.current,j.target);w(Y)}}const ue=o.useMemo(()=>({hasOverflowX:!W.x,hasOverflowY:!W.y,overflowXStart:T.xStart,overflowXEnd:T.xEnd,overflowYStart:T.yStart,overflowYEnd:T.yEnd,cornerHidden:W.corner}),[W.x,W.y,W.corner,T]),ce={role:"presentation",onPointerEnter:ve,onPointerMove:ve,onPointerDown:pe,onPointerLeave(){w(!1)},style:{position:"relative",[Dt.scrollAreaCornerHeight]:`${K.height}px`,[Dt.scrollAreaCornerWidth]:`${K.width}px`}},me=Xe("div",t,{state:ue,ref:[r,L],props:[ce,l],stateAttributesMapping:gn}),O=o.useMemo(()=>({handlePointerDown:re,handlePointerMove:V,handlePointerUp:J,handleScroll:Q,cornerSize:K,setCornerSize:N,thumbSize:$,setThumbSize:G,touchModality:P,cornerRef:S,scrollingX:g,setScrollingX:k,scrollingY:v,setScrollingY:y,hovering:p,setHovering:w,viewportRef:R,rootRef:L,scrollbarYRef:E,scrollbarXRef:H,thumbYRef:x,thumbXRef:D,rootId:u,hiddenState:W,setHiddenState:C,overflowEdges:T,setOverflowEdges:X,viewportState:ue,overflowEdgeThreshold:c}),[re,V,J,Q,K,$,P,g,k,v,y,p,w,u,W,T,ue,c]);return n.jsxs(mr.Provider,{value:O,children:[!m&&hr.getElement(h),me]})});function Fo(e){if(typeof e=="number"){const t=Math.max(0,e);return{xStart:t,xEnd:t,yStart:t,yEnd:t}}return{xStart:Math.max(0,e?.xStart||0),xEnd:Math.max(0,e?.xEnd||0),yStart:Math.max(0,e?.yStart||0),yEnd:Math.max(0,e?.yEnd||0)}}const Wo=o.createContext(void 0);function Ke(e,t=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,r))}function Yo(e,t){if(typeof IntersectionObserver>"u")return()=>{};const r=new IntersectionObserver(s=>{s.forEach(i=>{i.intersectionRatio>0&&(t(),r.disconnect())})});return r.observe(e),()=>{r.disconnect()}}let Ye=(function(e){return e.scrollAreaOverflowXStart="--scroll-area-overflow-x-start",e.scrollAreaOverflowXEnd="--scroll-area-overflow-x-end",e.scrollAreaOverflowYStart="--scroll-area-overflow-y-start",e.scrollAreaOverflowYEnd="--scroll-area-overflow-y-end",e})({}),On=!1;function Xo(){On||Ws||(typeof CSS<"u"&&"registerProperty"in CSS&&[Ye.scrollAreaOverflowXStart,Ye.scrollAreaOverflowXEnd,Ye.scrollAreaOverflowYStart,Ye.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),On=!0)}const Bo=o.forwardRef(function(t,r){const{render:s,className:i,...a}=t,{viewportRef:l,scrollbarYRef:c,scrollbarXRef:u,thumbYRef:d,thumbXRef:f,cornerRef:h,cornerSize:m,setCornerSize:p,setThumbSize:w,rootId:g,setHiddenState:k,hiddenState:v,handleScroll:y,setHovering:P,setOverflowEdges:A,overflowEdges:K,overflowEdgeThreshold:N}=Ut(),$=or(),G=o.useRef(!0),T=Mt(),X=Mt(),W=Fe(()=>{const x=l.current,D=c.current,S=u.current,I=d.current,_=f.current,U=h.current;if(!x)return;const F=x.scrollHeight,te=x.scrollWidth,ee=x.clientHeight,q=x.clientWidth,Q=x.scrollTop,re=x.scrollLeft;if(F===0||te===0)return;const V=ee>=F,J=q>=te,pe=q/te,ve=ee/F,ue=Math.max(0,te-q),ce=Math.max(0,F-ee);let me=0,O=0;J||($==="rtl"?me=Ke(-re,0,ue):me=Ke(re,0,ue),O=ue-me);const j=V?0:Ke(Q,0,ce),Y=V?0:ce-j,ie=J?0:q,Z=V?0:ee;let ae=0,ge=0;!J&&!V&&(ae=D?.offsetWidth||0,ge=S?.offsetHeight||0);const Be=m.width===0&&m.height===0,de=Be?ae:0,je=Be?ge:0,Pe=Ne(S,"padding","x"),ke=Ne(D,"padding","y"),ze=Ne(_,"margin","x"),ct=Ne(I,"margin","y"),gt=ie-Pe-ze,Ge=Z-ke-ct,Ze=S?Math.min(S.offsetWidth-de,gt):gt,xt=D?Math.min(D.offsetHeight-je,Ge):Ge,et=Math.max(An,Ze*pe),tt=Math.max(An,xt*ve);if(w(ne=>ne.height===tt&&ne.width===et?ne:{width:et,height:tt}),D&&I){const ne=D.offsetHeight-tt-ke-ct,ye=F-ee,_e=ye===0?0:Q/ye,ft=Math.min(ne,Math.max(0,_e*ne));I.style.transform=`translate3d(0,${ft}px,0)`}if(S&&_){const ne=S.offsetWidth-et-Pe-ze,ye=te-q,_e=ye===0?0:re/ye,ft=$==="rtl"?Ke(_e*ne,-ne,0):Ke(_e*ne,0,ne);_.style.transform=`translate3d(${ft}px,0,0)`}const ut=Ke(me,0,ue),yt=Ke(O,0,ue),wt=Ke(j,0,ce),dt=Ke(Y,0,ce),bt=[[Ye.scrollAreaOverflowXStart,ut],[Ye.scrollAreaOverflowXEnd,yt],[Ye.scrollAreaOverflowYStart,wt],[Ye.scrollAreaOverflowYEnd,dt]];for(const[ne,ye]of bt)x.style.setProperty(ne,`${ye}px`);U&&(J||V?p({width:0,height:0}):!J&&!V&&p({width:ae,height:ge})),k(ne=>{const ye=V||J;return ne.y===V&&ne.x===J&&ne.corner===ye?ne:{y:V,x:J,corner:ye}});const be={xStart:!J&&ut>N.xStart,xEnd:!J&&yt>N.xEnd,yStart:!V&&wt>N.yStart,yEnd:!V&&dt>N.yEnd};A(ne=>ne.xStart===be.xStart&&ne.xEnd===be.xEnd&&ne.yStart===be.yStart&&ne.yEnd===be.yEnd?ne:be)});Ee(()=>{if(!l.current)return;Xo();let x=!1;return Yo(l.current,()=>{if(!x){x=!0;return}W()})},[W,l]),Ee(()=>{queueMicrotask(W)},[W,v,$]),Ee(()=>{l.current?.matches(":hover")&&P(!0)},[l,P]),o.useEffect(()=>{const x=l.current;if(typeof ResizeObserver>"u"||!x)return;let D=!1;const S=new ResizeObserver(()=>{if(!D){D=!0;return}W()});return S.observe(x),X.start(0,()=>{const I=x.getAnimations({subtree:!0});I.length!==0&&Promise.all(I.map(_=>_.finished)).then(W).catch(()=>{})}),()=>{S.disconnect(),X.clear()}},[W,l,X]);function C(){G.current=!1}const L={role:"presentation",...g&&{"data-id":`${g}-viewport`},...(!v.x||!v.y)&&{tabIndex:0},className:hr.className,style:{overflow:"scroll"},onScroll(){l.current&&(W(),G.current||y({x:l.current.scrollLeft,y:l.current.scrollTop}),T.start(100,()=>{G.current=!0}))},onWheel:C,onTouchMove:C,onPointerMove:C,onPointerEnter:C,onKeyDown:C},R=o.useMemo(()=>({hasOverflowX:!v.x,hasOverflowY:!v.y,overflowXStart:K.xStart,overflowXEnd:K.xEnd,overflowYStart:K.yStart,overflowYEnd:K.yEnd,cornerHidden:v.corner}),[v.x,v.y,v.corner,K]),E=Xe("div",t,{ref:[r,l],state:R,props:[L,a],stateAttributesMapping:gn}),H=o.useMemo(()=>({computeThumbPosition:W}),[W]);return n.jsx(Wo.Provider,{value:H,children:E})}),pr=o.createContext(void 0);function Go(){const e=o.useContext(pr);if(e===void 0)throw new Error(dn(54));return e}let Lt=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const qo=o.forwardRef(function(t,r){const{render:s,className:i,orientation:a="vertical",keepMounted:l=!1,...c}=t,{hovering:u,scrollingX:d,scrollingY:f,hiddenState:h,overflowEdges:m,scrollbarYRef:p,scrollbarXRef:w,viewportRef:g,thumbYRef:k,thumbXRef:v,handlePointerDown:y,handlePointerUp:P,rootId:A,thumbSize:K}=Ut(),N=o.useMemo(()=>({hovering:u,scrolling:{horizontal:d,vertical:f}[a],orientation:a,hasOverflowX:!h.x,hasOverflowY:!h.y,overflowXStart:m.xStart,overflowXEnd:m.xEnd,overflowYStart:m.yStart,overflowYEnd:m.yEnd,cornerHidden:h.corner}),[u,d,f,a,h,m]),$=or();o.useEffect(()=>{const L=g.current,R=a==="vertical"?p.current:w.current;if(!R)return;function E(H){if(!(!L||!R||H.ctrlKey)){if(H.preventDefault(),a==="vertical"){if(L.scrollTop===0&&H.deltaY<0)return}else if(L.scrollLeft===0&&H.deltaX<0)return;if(a==="vertical"){if(L.scrollTop===L.scrollHeight-L.clientHeight&&H.deltaY>0)return}else if(L.scrollLeft===L.scrollWidth-L.clientWidth&&H.deltaX>0)return;a==="vertical"?L.scrollTop+=H.deltaY:L.scrollLeft+=H.deltaX}}return R.addEventListener("wheel",E,{passive:!1}),()=>{R.removeEventListener("wheel",E)}},[a,w,p,g]);const G={...A&&{"data-id":`${A}-scrollbar`},onPointerDown(L){if(L.button===0&&L.currentTarget===L.target&&g.current){if(k.current&&p.current&&a==="vertical"){const R=Ne(k.current,"margin","y"),E=Ne(p.current,"padding","y"),H=k.current.offsetHeight,x=p.current.getBoundingClientRect(),D=L.clientY-x.top-H/2-E+R/2,S=g.current.scrollHeight,I=g.current.clientHeight,_=p.current.offsetHeight-H-E-R,F=D/_*(S-I);g.current.scrollTop=F}if(v.current&&w.current&&a==="horizontal"){const R=Ne(v.current,"margin","x"),E=Ne(w.current,"padding","x"),H=v.current.offsetWidth,x=w.current.getBoundingClientRect(),D=L.clientX-x.left-H/2-E+R/2,S=g.current.scrollWidth,I=g.current.clientWidth,_=w.current.offsetWidth-H-E-R,U=D/_;let F;$==="rtl"?(F=(1-U)*(S-I),g.current.scrollLeft<=0&&(F=-F)):F=U*(S-I),g.current.scrollLeft=F}y(L)}},onPointerUp:P,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...a==="vertical"&&{top:0,bottom:`var(${Dt.scrollAreaCornerHeight})`,insetInlineEnd:0,[Lt.scrollAreaThumbHeight]:`${K.height}px`},...a==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${Dt.scrollAreaCornerWidth})`,bottom:0,[Lt.scrollAreaThumbWidth]:`${K.width}px`}}},T=Xe("div",t,{ref:[r,a==="vertical"?p:w],state:N,props:[G,c],stateAttributesMapping:gn}),X=o.useMemo(()=>({orientation:a}),[a]),W=a==="vertical"?h.y:h.x;return l||!W?n.jsx(pr.Provider,{value:X,children:T}):null}),Vo=o.forwardRef(function(t,r){const{render:s,className:i,...a}=t,{thumbYRef:l,thumbXRef:c,handlePointerDown:u,handlePointerMove:d,handlePointerUp:f,setScrollingX:h,setScrollingY:m}=Ut(),{orientation:p}=Go(),w=o.useMemo(()=>({orientation:p}),[p]);return Xe("div",t,{ref:[r,p==="vertical"?l:c],state:w,props:[{onPointerDown:u,onPointerMove:d,onPointerUp(k){p==="vertical"&&m(!1),p==="horizontal"&&h(!1),f(k)},style:{...p==="vertical"&&{height:`var(${Lt.scrollAreaThumbHeight})`},...p==="horizontal"&&{width:`var(${Lt.scrollAreaThumbWidth})`}}},a]})}),Jo=o.forwardRef(function(t,r){const{render:s,className:i,...a}=t,{cornerRef:l,cornerSize:c,hiddenState:u}=Ut(),d=Xe("div",t,{ref:[r,l],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:c.width,height:c.height}},a]});return u.corner?null:d});function gr({className:e,...t}){return n.jsx(Uo,{className:M("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function xr({className:e,...t}){return n.jsx(Bo,{className:M("h-full w-full outline-none focus-visible:outline-none",e),...t})}function yr({className:e,...t}){return n.jsx(qo,{className:M("flex w-2 touch-none select-none p-0.5 outline-none focus-visible:outline-none","opacity-0 transition-opacity duration-150","data-hovering:opacity-100 data-scrolling:opacity-100 group-hover/scroll-area:opacity-100",e),...t})}function wr({className:e,...t}){return n.jsx(Vo,{className:M("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function Qo({className:e,...t}){return n.jsx(Jo,{className:M("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function Zo(e){return e==="subagent"?rs:e==="cron"?ss:os}function ei(e){return!e||!Array.isArray(e.content)?"":e.content.map(r=>r.type==="text"?String(r.text??""):"").join(" ").replace(/\s+/g," ").trim()}function ti(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function ni(e){if(!e)return null;const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=ti(r);if(s)return s}return null}function ri(e){const t=e-Date.now(),r=Math.abs(t),s=[["minute",6e4],["hour",36e5],["day",864e5]];let i="minute",a=6e4;r>=s[2][1]?[i,a]=s[2]:r>=s[1][1]&&([i,a]=s[1]);const l=Math.round(t/a);return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(l,i)}function si(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function oi({session:e,active:t,isGenerating:r=!1,isPinned:s,selectionMode:i=!1,selected:a=!1,onToggleSelect:l,onSelect:c,onTogglePin:u,onRename:d,onDelete:f,onExport:h}){const m=e.label||e.title||e.derivedTitle||e.friendlyId,p=Zo(e.kind),w=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?ei(e.lastMessage):"",g=w.length>50?`${w.slice(0,50).trimEnd()}…`:w,k=e.kind==="subagent"?si(e.status):null,v=e.kind==="cron"?ni(e.lastMessage):null;return n.jsxs(qe,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:y=>{if(i){y.preventDefault(),y.stopPropagation(),l?.(e);return}c?.()},className:M("group inline-flex items-center justify-between","w-full text-left pl-1.5 pr-0.5 min-h-8 py-1 rounded-lg transition-colors duration-0","select-none",t?"bg-[var(--opencami-accent-light)] text-[var(--opencami-accent)]":"bg-transparent text-primary-950 [&:hover:not(:has(button:hover))]:bg-primary-200"),children:[n.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[i?n.jsx("span",{"aria-hidden":"true",className:M("inline-flex items-center justify-center size-4 shrink-0 rounded border transition-colors",a?"bg-primary-700 border-primary-700 text-white":"border-primary-300 bg-surface"),children:a?n.jsx("svg",{viewBox:"0 0 12 12",className:"size-3",fill:"none",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{d:"M2.5 6l2.5 2.5 4.5-5"})}):null}):null,n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.jsx(B,{icon:p,size:12,strokeWidth:1.75,className:"text-primary-500/70 shrink-0"}),n.jsxs("div",{className:"min-w-0 truncate text-sm font-[450]",title:m,children:[s?n.jsx("span",{className:"mr-1 text-xs text-primary-700","aria-hidden":"true",children:"📌"}):null,m]}),e.kind==="subagent"?r?n.jsx("span",{"aria-label":"Session active",className:"size-1.5 rounded-full bg-green-500 shrink-0"}):k==="success"?n.jsx(B,{icon:Vn,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):k==="error"?n.jsx(B,{icon:Kt,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),g?n.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:g}):null,e.kind==="cron"&&v?n.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:ri(v)}):null]})]}),i?null:n.jsxs(zt,{children:[n.jsx(Ht,{type:"button",onClick:y=>{y.preventDefault(),y.stopPropagation()},className:M("ml-2 inline-flex size-7 items-center justify-center rounded-md text-primary-700","opacity-0 transition-opacity group-hover:opacity-100 hover:bg-primary-200","aria-expanded:opacity-100 aria-expanded:bg-primary-200"),children:n.jsx(B,{icon:es,size:20,strokeWidth:1.5})}),n.jsxs($t,{side:"bottom",align:"end",children:[n.jsxs(We,{onClick:y=>{y.preventDefault(),y.stopPropagation(),u(e)},className:"gap-2",children:[n.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",s?"Unpin Session":"Pin Session"]}),n.jsxs(We,{onClick:y=>{y.preventDefault(),y.stopPropagation(),d(e)},className:"gap-2",children:[n.jsx(B,{icon:ts,size:20,strokeWidth:1.5})," ","Rename"]}),n.jsxs(We,{onClick:y=>{y.preventDefault(),y.stopPropagation(),h(e)},className:"gap-2",children:[n.jsx(B,{icon:ns,size:20,strokeWidth:1.5})," ","Export"]}),sn(e.key)?null:n.jsxs(We,{onClick:y=>{y.preventDefault(),y.stopPropagation(),f(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[n.jsx(B,{icon:Jn,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function ii(e,t){return e.active!==t.active||e.isGenerating!==t.isGenerating||e.isPinned!==t.isPinned||e.selectionMode!==t.selectionMode||e.selected!==t.selected||e.onToggleSelect!==t.onToggleSelect||e.onSelect!==t.onSelect||e.onTogglePin!==t.onTogglePin||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport?!1:e.session===t.session?!0:e.session.key===t.session.key&&e.session.friendlyId===t.session.friendlyId&&e.session.label===t.session.label&&e.session.title===t.session.title&&e.session.derivedTitle===t.session.derivedTitle&&e.session.updatedAt===t.session.updatedAt&&e.session.kind===t.session.kind&&e.session.status===t.session.status&&e.session.lastMessage===t.session.lastMessage}const Bt=o.memo(oi,ii),br="opencami-pinned-sessions",Sr="opencami-sidebar-folders",$e={webchat:!1,subagent:!1,cron:!1,other:!1};async function ai(e){const t=new URLSearchParams;e&&t.set("sessionKey",e);const r=await fetch(`/api/sessions?${t.toString()}`,{method:"DELETE"});if(!r.ok)throw new Error(await Le(r))}async function li(e,t,r){const s=[];let i=0;const a=Array.from({length:Math.min(t,e.length)},async function(){for(;i<e.length;){const c=i;i+=1;try{await r(e[c])}catch(u){s.push(u)}}});return await Promise.all(a),s}function ci(){if(typeof window>"u")return[];try{const e=localStorage.getItem(br);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}catch{return[]}}function ui(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(br,JSON.stringify(t))}catch{}}function di(){if(typeof window>"u")return{...$e};try{const e=localStorage.getItem(Sr);if(!e)return{...$e};const t=JSON.parse(e);return!t||typeof t!="object"?{...$e}:{webchat:typeof t.webchat=="boolean"?t.webchat:$e.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:$e.subagent,cron:typeof t.cron=="boolean"?t.cron:$e.cron,other:typeof t.other=="boolean"?t.other:$e.other}}catch{return{...$e}}}function fi(e){if(!(typeof window>"u"))try{localStorage.setItem(Sr,JSON.stringify(e))}catch{}}function Nt(e,t,r){return r&&e.key?e.key===r:e.friendlyId===t}function mi(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function Gt(e,t,r,s){return Nt(e,t,r)&&s?!0:mi(e.status)}const hi=o.memo(function({sessions:t,activeFriendlyId:r,activeSessionKey:s,isStreaming:i=!1,defaultOpen:a=!0,onSelect:l,onRename:c,onDelete:u,onExport:d}){const f=o.useDeferredValue(t),h=lt(),[m,p]=o.useState(()=>ci()),[w,g]=o.useState(()=>di()),[k,v]=o.useState(!1),[y,P]=o.useState(()=>new Set),A=o.useMemo(()=>new Set(m),[m]),K=f.filter(S=>A.has(S.key)),N=f.filter(S=>!A.has(S.key)),$=K.length>0&&N.length>0,G=o.useMemo(()=>{const S={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const I of N){const _=I.kind??"other";S[_].push(I)}return S},[N]),T=o.useMemo(()=>f.filter(S=>y.has(S.key)),[y,f]),X=T.length,W=o.useCallback(()=>{v(S=>(S&&P(new Set),!S))},[]),C=o.useCallback(S=>{sn(S.key)||P(I=>{const _=new Set(I);return _.has(S.key)?_.delete(S.key):_.add(S.key),_})},[]),L=o.useCallback(()=>{P(new Set(f.filter(S=>!sn(S.key)).map(S=>S.key)))},[f]),R=o.useCallback(()=>{v(!1),P(new Set)},[]),E=o.useCallback(async()=>{if(T.length===0||!window.confirm(`Delete ${T.length} sessions? This will archive them.`))return;const I=[];await li(T,10,async _=>{try{await ai(_.key)}catch(U){throw I.push(_.label||_.title||_.derivedTitle||_.friendlyId),U}}),I.length>0&&(console.error("[sidebar] Bulk delete failed for some sessions",I),window.alert(`Could not delete ${I.length} session${I.length!==1?"s":""}:
|
|
6
|
+
|
|
7
|
+
${I.join(`
|
|
8
|
+
`)}`)),v(!1),P(new Set),h.invalidateQueries({queryKey:oe.sessions})},[h,T]),H=o.useCallback(S=>{p(I=>{const U=I.includes(S.key)?I.filter(F=>F!==S.key):[...I,S.key];return ui(U),U})},[]),x=o.useCallback((S,I)=>{g(_=>{const U={..._,[S]:I};return fi(U),U})},[]);function D(S,I,_){return _.length===0?null:n.jsxs(At,{className:"flex flex-col",open:w[S],onOpenChange:U=>x(S,U),children:[n.jsxs(It,{className:M("w-full justify-between border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:[n.jsx("span",{className:"truncate",children:I}),n.jsx("span",{className:M("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:_.length})]}),n.jsx(Ot,{contentClassName:"flex flex-col gap-px",children:_.map(U=>n.jsx(Bt,{session:U,active:Nt(U,r,s),isGenerating:Gt(U,r,s,i),isPinned:!1,selectionMode:k,selected:y.has(U.key),onToggleSelect:C,onSelect:l,onTogglePin:H,onRename:c,onDelete:u,onExport:d},U.key))})]})}return n.jsxs(At,{className:"flex h-full flex-col flex-1 min-h-0 w-full",defaultOpen:a,children:[n.jsxs("div",{className:"flex items-center justify-between pr-2 shrink-0",children:[n.jsxs(It,{className:"w-fit pl-1.5 text-balance",children:["Sessions",n.jsx("span",{className:"opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:n.jsx(B,{icon:fn,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),n.jsx("button",{type:"button",onClick:W,className:M("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",k?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:k?"Done":"Select"})]}),n.jsx(Ot,{className:"w-full flex-1 min-h-0 h-auto data-starting-style:h-0 data-ending-style:h-0",contentClassName:"flex flex-1 min-h-0 flex-col overflow-y-auto",children:n.jsxs(gr,{className:"flex-1 min-h-0",children:[n.jsx(xr,{className:"min-h-0",children:n.jsxs("div",{className:"flex flex-col gap-2 pl-2 pr-2",children:[K.length>0?n.jsx("div",{className:"flex flex-col gap-px",children:K.map(S=>n.jsx(Bt,{session:S,active:Nt(S,r,s),isGenerating:Gt(S,r,s,i),isPinned:!0,selectionMode:k,selected:y.has(S.key),onToggleSelect:C,onSelect:l,onTogglePin:H,onRename:c,onDelete:u,onExport:d},S.key))}):null,$?n.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,G.chat.length>0?n.jsxs("div",{className:"flex flex-col gap-px",children:[n.jsx("div",{className:M("border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:"💬 Chats"}),n.jsx("div",{className:"flex flex-col gap-px",children:G.chat.map(S=>n.jsx(Bt,{session:S,active:Nt(S,r,s),isGenerating:Gt(S,r,s,i),isPinned:!1,selectionMode:k,selected:y.has(S.key),onToggleSelect:C,onSelect:l,onTogglePin:H,onRename:c,onDelete:u,onExport:d},S.key))})]}):null,D("webchat","🦎 OpenCami",G.webchat),D("subagent","🤖 Sub-agents",G.subagent),D("cron","⏰ Cron / Isolated",G.cron),D("other","📁 Other",G.other)]})}),n.jsx(yr,{orientation:"vertical",children:n.jsx(wr,{})})]})}),k?n.jsxs("div",{className:"shrink-0 border-t border-primary-200 bg-surface px-2 py-2 flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-xs text-primary-600 font-medium",children:[X," selected"]}),n.jsx("button",{type:"button",onClick:L,className:"text-[11px] font-medium text-primary-600 hover:text-primary-800",children:"Select all"})]}),n.jsxs("div",{className:"flex gap-1.5",children:[n.jsxs("button",{type:"button",onClick:E,disabled:X===0,className:M("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",X>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[n.jsx(B,{icon:Jn,size:14,strokeWidth:1.5}),"Delete"]}),n.jsx("button",{type:"button",onClick:R,className:"flex-1 inline-flex items-center justify-center rounded-md px-2 py-1.5 text-xs font-medium bg-primary-100 text-primary-700 hover:bg-primary-200 transition-colors",children:"Cancel"})]})]}):null]})},pi);function pi(e,t){if(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.defaultOpen!==t.defaultOpen||e.onSelect!==t.onSelect||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport)return!1;if(e.sessions===t.sessions)return!0;if(e.sessions.length!==t.sessions.length)return!1;for(let r=0;r<e.sessions.length;r+=1){const s=e.sessions[r],i=t.sessions[r];if(s.key!==i.key||s.friendlyId!==i.friendlyId||s.label!==i.label||s.title!==i.title||s.derivedTitle!==i.derivedTitle||s.updatedAt!==i.updatedAt||s.kind!==i.kind||s.status!==i.status||s.lastMessage!==i.lastMessage)return!1}return!0}function gi(){const[e,t]=o.useState(!1),[r,s]=o.useState(!1),[i,a]=o.useState(null),[l,c]=o.useState(null),u=o.useCallback(async()=>{if(t(!0),a(null),!(r||l)){s(!0);try{const p=await fetch("/api/paths");if(!p.ok)throw new Error(await Le(p));const w=await p.json();c({agentId:String(w.agentId??"main"),stateDir:String(w.stateDir??""),sessionsDir:String(w.sessionsDir??""),storePath:String(w.storePath??"")})}catch(p){a(p instanceof Error?p.message:String(p))}finally{s(!1)}}},[l,r]),d=o.useCallback(()=>{u()},[u]),f=o.useCallback(()=>{t(!1)},[]),h=o.useCallback(()=>{if(l?.sessionsDir)try{navigator.clipboard.writeText(l.sessionsDir)}catch{}},[l]),m=o.useCallback(()=>{if(l?.storePath)try{navigator.clipboard.writeText(l.storePath)}catch{}},[l]);return{settingsOpen:e,setSettingsOpen:t,pathsLoading:r,pathsError:i,paths:l,handleOpenSettings:d,closeSettings:f,copySessionsDir:h,copyStorePath:m}}let Se=null,xn=!1,Et=null;function xi(e){Se=e}function qt(){return Se!==null}function ht(e){xn=e}function Vt(){return xn}function Pt(){Se=null,xn=!1}function yi(e,t){if(Se){if(e&&Se.sessionKey===e){Pt();return}t&&Se.friendlyId===t&&Pt()}}function wi(e){Et={friendlyId:e,at:Date.now()}}function vr(e,t=15e3){return!(!Et||Et.friendlyId!==e||Date.now()-Et.at>t)}function bi(e,t){if(!Se)return null;if(e&&Se.sessionKey===e){const r=Se;return Se=null,r}if(t&&Se.friendlyId===t){const r=Se;return Se=null,r}return null}const Si=8e3,Ve=new Map;function vi(e){e&&Ve.set(e,{id:e,expiresAt:Date.now()+Si})}function ji(e){e&&Ve.delete(e)}function ki(e){if(Ve.size===0)return e;const t=Date.now();let r=!1;const s=e.filter(i=>{const a=Ve.get(i.key),l=Ve.get(i.friendlyId);return a&&a.expiresAt<=t||l&&l.expiresAt<=t?(a&&a.expiresAt<=t&&Ve.delete(i.key),l&&l.expiresAt<=t&&Ve.delete(i.friendlyId),!0):a||l?(r=!0,!1):!0});return r?s:e}function Ci(){const e=lt(),[t,r]=o.useState(!1),[s,i]=o.useState(null),a=ir({mutationFn:async function(u){const d=new URLSearchParams;u.sessionKey&&d.set("sessionKey",u.sessionKey),u.friendlyId&&d.set("friendlyId",u.friendlyId);const f=await fetch(`/api/sessions?${d.toString()}`,{method:"DELETE"});if(!f.ok)throw new Error(await Le(f));return u},onMutate:async function(u){i(null),vi(u.sessionKey||u.friendlyId),yi(u.sessionKey,u.friendlyId),await e.cancelQueries({queryKey:oe.sessions});const d=e.getQueryData(oe.sessions);return co(e,u.sessionKey,u.friendlyId),u.isActive&&(u.sessionKey||u.friendlyId)&&on(e,u.friendlyId||u.sessionKey,u.sessionKey||u.friendlyId),{previousSessions:d,isActive:u.isActive}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(oe.sessions,f.previousSessions),ji(d.sessionKey||d.friendlyId),i(u instanceof Error?u.message:String(u))},onSuccess:function(u){u.isActive&&Pt(),e.invalidateQueries({queryKey:oe.sessions})},onSettled:function(){r(!1)}});return{deleteSession:o.useCallback(async(c,u,d)=>{!c&&!u||(r(!0),await a.mutateAsync({sessionKey:c,friendlyId:u,isActive:d}))},[a]),deleting:t,error:s}}function Ni(){const e=lt(),[t,r]=o.useState(!1),[s,i]=o.useState(null),a=ir({mutationFn:async function(u){const d=await fetch("/api/sessions",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:u.sessionKey,label:u.newTitle})});if(!d.ok)throw new Error(await Le(d));return u},onMutate:async function(u){i(null),await e.cancelQueries({queryKey:oe.sessions});const d=e.getQueryData(oe.sessions);return e.setQueryData(oe.sessions,function(h){return Array.isArray(h)?h.map(m=>m.key!==u.sessionKey?m:{...m,label:u.newTitle,title:u.newTitle}):h}),{previousSessions:d}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(oe.sessions,f.previousSessions),i(u instanceof Error?u.message:String(u))},onSuccess:function(){e.invalidateQueries({queryKey:oe.sessions})},onSettled:function(){r(!1)}});return{renameSession:o.useCallback(async(c,u)=>{!c||!u.trim()||(r(!0),await a.mutateAsync({sessionKey:c,newTitle:u.trim()}))},[a]),renaming:t,error:s}}const Ei=o.lazy(()=>_t(()=>import("./settings-dialog-DZcRCaPj.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])).then(e=>({default:e.SettingsDialog}))),Ti=o.lazy(()=>_t(()=>import("./session-export-dialog-DPuHnhgv.js"),__vite__mapDeps([24,1,3,2,4,5,6,7,8,9])).then(e=>({default:e.SessionExportDialog})));function Ri({sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s=!1,creatingSession:i,onCreateSession:a,isCollapsed:l,onToggleCollapse:c,onSelectSession:u,onActiveSessionDelete:d,onOpenSearch:f}){const{settingsOpen:h,setSettingsOpen:m,pathsLoading:p,pathsError:w,paths:g,handleOpenSettings:k,closeSettings:v,copySessionsDir:y,copyStorePath:P}=gi(),{deleteSession:A}=Ci(),{renameSession:K}=Ni(),N={duration:.15,ease:l?"easeIn":"easeOut"},[$,G]=o.useState(!1),[T,X]=o.useState(null),[W,C]=o.useState(""),[L,R]=o.useState(!1),[E,H]=o.useState(null),[x,D]=o.useState(null),[S,I]=o.useState(""),[_,U]=o.useState(!1),[F,te]=o.useState(null),[ee,q]=o.useState(null),[Q,re]=o.useState(""),V=lt();function J(j){X(j.key),C(j.label||j.title||j.derivedTitle||""),G(!0)}function pe(j){T&&K(T,j),G(!1),X(null)}function ve(j){H(j.key),D(j.friendlyId),I(j.label||j.title||j.derivedTitle||j.friendlyId),R(!0)}function ue(){if(E&&x){const j=x===t;j&&d&&d(),A(E,x,j)}R(!1),H(null),D(null)}function ce(j){te(j.key),q(j.friendlyId),re(j.label||j.title||j.derivedTitle||j.friendlyId),U(!0)}function me(j){if(F&&ee){const Y=oe.history(ee,F),ie=V.getQueryData(Y);ie?.messages&&po(Q,ie.messages,j)}U(!1),te(null),q(null)}const O={className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col"};return n.jsxs(we.aside,{initial:!1,animate:{width:l?48:"var(--opencami-sidebar-width)"},transition:N,className:O.className,children:[n.jsxs(we.div,{layout:!0,transition:{layout:N},className:M("flex items-center h-12 px-2 justify-between"),children:[n.jsx(Me,{initial:!1,children:l?null:n.jsx(we.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,children:n.jsxs(qe,{to:"/new",className:M(st({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[n.jsx(Xs,{className:"size-5"}),n.jsx(Bs,{})]})})}),n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{onClick:c,render:n.jsx(he,{size:"icon-sm",variant:"ghost",children:n.jsx(B,{icon:is,size:20,strokeWidth:1.5})})}),n.jsx(De,{side:"right",children:l?"Open Sidebar":"Close Sidebar"})]})})]}),n.jsxs("div",{className:"px-2 mb-4 flex flex-col gap-1",children:[n.jsxs(we.div,{layout:!0,transition:{layout:N},className:"w-full space-y-2",children:[n.jsxs(he,{disabled:i,variant:"ghost",size:"sm",onClick:a,onMouseUp:u,className:"w-full pl-1.5 justify-start",children:[n.jsx(B,{icon:as,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),(()=>{try{const j=localStorage.getItem("opencami-file-explorer");return j===null?!0:j==="true"}catch{return!0}})()&&n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{asChild:!0,children:n.jsxs(qe,{to:"/files",className:M(st({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(B,{icon:ls,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),l&&n.jsx(De,{side:"right",children:"Files"})]})}),(()=>{try{const j=localStorage.getItem("opencami-memory-viewer");return j===null?!0:j==="true"}catch{return!0}})()&&n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{asChild:!0,children:n.jsxs(qe,{to:"/memory",className:M(st({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(B,{icon:tn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Memory"})})]})}),l&&n.jsx(De,{side:"right",children:"Memory"})]})}),(()=>{try{return localStorage.getItem("opencami-skills-browser")==="true"}catch{return!1}})()&&n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{asChild:!0,children:n.jsxs(qe,{to:"/skills",className:M(st({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(B,{icon:cs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Skills"})})]})}),l&&n.jsx(De,{side:"right",children:"Skills"})]})}),(()=>{try{return localStorage.getItem("opencami-agent-manager")==="true"}catch{return!1}})()&&n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{asChild:!0,children:n.jsxs(qe,{to:"/agents",className:M(st({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(B,{icon:tn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Agents"})})]})}),l&&n.jsx(De,{side:"right",children:"Agents"})]})}),(()=>{try{return localStorage.getItem("opencami-cron-manager")==="true"}catch{return!1}})()&&n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{asChild:!0,children:n.jsxs(qe,{to:"/bots",className:M(st({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(B,{icon:us,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Cron Jobs"})})]})}),l&&n.jsx(De,{side:"right",children:"Cron Jobs"})]})})]}),n.jsx(we.div,{layout:!0,transition:{layout:N},className:"w-full",children:n.jsxs(he,{variant:"ghost",size:"sm",onClick:f,className:"w-full pl-1.5 justify-start",children:[n.jsx(B,{icon:Qn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(Me,{initial:!1,children:!l&&n.jsx(we.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"pt-0 flex flex-col w-full min-h-0 h-full",children:n.jsx("div",{className:"flex-1 min-h-0",children:n.jsx(hi,{sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s,onSelect:u,onRename:J,onDelete:ve,onExport:ce})})},"content")})}),n.jsx("div",{className:"px-2 py-3 border-t border-primary-200 bg-primary-100",children:n.jsx(we.div,{layout:!0,transition:{layout:N},className:"w-full",children:n.jsxs(he,{variant:"ghost",size:"sm",onClick:k,title:l?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[n.jsx(B,{icon:ds,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(we.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:N,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),h&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Ei,{open:h,onOpenChange:m,pathsLoading:p,pathsError:w,paths:g,onClose:v,onCopySessionsDir:y,onCopyStorePath:P})}),n.jsx(xo,{open:$,onOpenChange:G,sessionTitle:W,onSave:pe,onCancel:()=>G(!1)}),n.jsx(Co,{open:L,onOpenChange:R,sessionTitle:S,onConfirm:ue,onCancel:()=>R(!1)}),_&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Ti,{open:_,onOpenChange:U,sessionTitle:Q,onExport:me,onCancel:()=>U(!1)})})]})}function Mi(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1){const s=e[r],i=t[r];if(s.key!==i.key||s.friendlyId!==i.friendlyId||s.label!==i.label||s.title!==i.title||s.derivedTitle!==i.derivedTitle||s.updatedAt!==i.updatedAt||s.kind!==i.kind||s.status!==i.status||s.lastMessage!==i.lastMessage)return!1}return!0}function Ai(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!Mi(e.sessions,t.sessions))}const Ii=o.memo(Ri,Ai);function Dn(e){if(e<=0)return"0";if(e>=1e6){const t=e/1e6,r=t.toFixed(1);return r.endsWith(".0")?`${Math.round(t)}M`:`${r}M`}if(e>=1e5)return`${Math.round(e/1e3)}K`;if(e>=1e4)return`${Math.round(e/1e3)}K`;if(e>=1e3){const t=e/1e3,r=t.toFixed(1);return r.endsWith(".0")?`${Math.round(t)}K`:`${r}K`}return String(Math.round(e))}function Ln(e){return e>=90?{bar:"bg-red-500",text:"text-red-600 dark:text-red-400"}:e>=70?{bar:"bg-yellow-500",text:"text-yellow-600 dark:text-yellow-400"}:{bar:"bg-emerald-500",text:"text-emerald-600 dark:text-emerald-400"}}function Oi({totalTokens:e,contextTokens:t,className:r}){const{percentage:s,usedStr:i,maxStr:a,colors:l,hasData:c,isNearlyFull:u}=o.useMemo(()=>{if(typeof t!="number"||t<=0)return{percentage:0,usedStr:"",maxStr:"",colors:Ln(0),hasData:!1,isNearlyFull:!1};const h=typeof e=="number"&&e>0?e:0,m=Math.min(100,Math.round(h/t*100));return{percentage:m,usedStr:Dn(h),maxStr:Dn(t),colors:Ln(m),hasData:!0,isNearlyFull:m>=95}},[e,t]);if(!c)return null;const d=typeof e=="number"&&e>0?e.toLocaleString():"0",f=typeof t=="number"?t.toLocaleString():"0";return n.jsxs("div",{className:M("group relative flex items-center gap-1.5",r),title:`Context: ${d} / ${f} tokens (${s}%)`,children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("div",{className:"w-12 h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden shrink-0 group-hover:h-2 transition-all",children:n.jsx("div",{className:M("h-full rounded-full transition-all duration-500 ease-out",l.bar,u&&"animate-pulse"),style:{width:`${s}%`}})}),n.jsx("span",{className:M("text-[10px] leading-none font-medium tabular-nums whitespace-nowrap",u?l.text:"text-primary-500 dark:text-primary-400"),children:i})]}),n.jsx("div",{className:M("absolute right-0 top-full mt-1 z-50","pointer-events-none opacity-0 scale-95","group-hover:pointer-events-auto group-hover:opacity-100 group-hover:scale-100","transition-all duration-150 origin-top-right"),children:n.jsxs("div",{className:M("rounded-md border border-primary-200 dark:border-primary-700","bg-surface shadow-lg px-3 py-2","text-xs whitespace-nowrap"),children:[n.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[n.jsx("span",{className:"text-primary-500 dark:text-primary-400",children:"Context window"}),n.jsxs("span",{className:M("font-semibold",l.text),children:[s,"%"]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-primary-700 dark:text-primary-300",children:[n.jsx("span",{className:"font-medium",children:i}),n.jsx("span",{className:"text-primary-400",children:"/"}),n.jsx("span",{children:a}),n.jsx("span",{className:"text-primary-400",children:"tokens"})]}),n.jsx("div",{className:"w-full h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden mt-1.5",children:n.jsx("div",{className:M("h-full rounded-full transition-all duration-500 ease-out",l.bar),style:{width:`${s}%`}})}),u&&n.jsx("div",{className:"mt-1.5 text-[10px] text-red-500 dark:text-red-400 font-medium",children:"⚠ Context nearly full — consider /compact"})]})})]})}const Di=o.memo(Oi);function Li({activeTitle:e,wrapperRef:t,showSidebarButton:r=!1,onOpenSidebar:s,totalTokens:i,contextTokens:a}){return n.jsxs("div",{ref:t,"data-tauri-drag-region":!0,className:"border-b border-primary-200 px-4 h-12 flex min-w-0 items-center overflow-x-hidden bg-surface tauri-drag-header",children:[r?n.jsx(he,{size:"icon-sm",variant:"ghost",onClick:s,className:"mr-2 text-primary-800 hover:bg-primary-100",style:{WebkitAppRegion:"no-drag"},"aria-label":"Open sidebar",children:n.jsx(B,{icon:fs,size:18,strokeWidth:1.6})}):null,n.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:n.jsx("div",{className:"truncate text-sm font-medium",children:e})}),n.jsx(Di,{totalTokens:i,contextTokens:a,className:"ml-3 hidden sm:flex"})]})}const Pi=o.memo(Li);function _i(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function Ki(e){const t=new Date(e);return _i(t,new Date)?new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit"}).format(t):new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short"}).format(t)}function zi(e){return new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(e))}function Hi({timestamp:e}){const t=Ki(e),r=zi(e);return n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{className:"inline-flex items-center text-xs text-primary-600",children:t}),n.jsx(De,{side:"top",children:r})]})})}function $i({text:e,align:t,timestamp:r,forceVisible:s=!1}){const[i,a]=o.useState(!1),[l,c]=o.useState("idle"),u=o.useRef(null),d=o.useRef(null),f=o.useRef(null),[h,m]=o.useState(()=>{if(typeof window>"u")return!0;try{const v=localStorage.getItem("opencami-tts-enabled");return v===null?!0:v==="true"}catch{return!0}});o.useEffect(()=>{function v(y){y.key==="opencami-tts-enabled"&&m(y.newValue===null?!0:y.newValue==="true")}return window.addEventListener("storage",v),()=>window.removeEventListener("storage",v)},[]),o.useEffect(()=>()=>{f.current?.abort(),u.current&&(u.current.pause(),u.current=null),d.current&&(URL.revokeObjectURL(d.current),d.current=null)},[]);const p=async()=>{try{await navigator.clipboard.writeText(e),a(!0),window.setTimeout(()=>a(!1),1400)}catch{a(!1)}},w=async()=>{if(l==="playing"){f.current?.abort(),u.current&&(u.current.pause(),u.current=null),d.current&&(URL.revokeObjectURL(d.current),d.current=null),c("idle");return}f.current?.abort();const v=new AbortController;f.current=v,c("loading");try{const y=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e}),signal:v.signal});if(!y.ok)throw new Error("TTS failed");const P=await y.blob(),A=URL.createObjectURL(P);d.current=A;const K=new Audio(A);u.current=K,K.onended=()=>{c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null},K.onerror=()=>{c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null},await K.play(),c("playing")}catch(y){if(y instanceof Error&&y.name==="AbortError"){c("idle");return}c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null}},g=t==="end"?"justify-end":"justify-start",k=t==="start"&&h&&e.trim().length>0;return n.jsxs("div",{className:M("flex items-center gap-2 text-xs text-primary-600 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 duration-100 ease-out",s?"opacity-100":"opacity-0",g),children:[n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{type:"button",onClick:()=>{p().catch(()=>{})},className:"inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",children:n.jsx(B,{icon:i?mn:ms,size:16,strokeWidth:1.6})}),n.jsx(De,{side:"top",children:"Copy"})]})}),k&&n.jsx(Ae,{children:n.jsxs(Ie,{children:[n.jsx(Oe,{type:"button",onClick:()=>{w().catch(()=>{})},disabled:l==="loading",className:M("inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",l==="loading"&&"opacity-60 cursor-wait"),children:n.jsx(B,{icon:l==="loading"?hs:l==="playing"?Zn:ps,size:16,strokeWidth:1.6,className:M(l==="loading"&&"animate-spin")})}),n.jsx(De,{side:"top",children:l==="loading"?"Generating speech…":l==="playing"?"Stop":"Listen"})]})}),n.jsx(Hi,{timestamp:r})]})}function jr({children:e,className:t,...r}){return n.jsx("div",{className:M("flex gap-3 w-full",t),...r,children:e})}function Ui({children:e,markdown:t=!1,className:r,...s}){const i=M("rounded-[12px] break-words whitespace-normal min-w-0 max-w-full overflow-x-hidden",r);return t?n.jsx(Gs,{className:i,...s,children:e}):n.jsx("div",{className:i,...s,children:e})}function Fi(){const[e,t]=o.useState(()=>typeof window<"u"?window.innerWidth<768:!1);return o.useEffect(()=>{if(typeof window>"u")return;const r=window.matchMedia("(max-width: 767px)"),s=i=>t(i.matches);return r.addEventListener("change",s),t(r.matches),()=>r.removeEventListener("change",s)},[]),e}function Wi({content:e}){const t=Fi();return n.jsx("div",{className:"inline-flex flex-col",children:n.jsxs(At,{defaultOpen:!t,children:[n.jsxs(It,{render:n.jsx(he,{variant:"ghost",className:"h-auto gap-1.5 px-1.5 py-0.5 -mx-2"}),children:[n.jsx("span",{className:"text-sm font-medium text-primary-900",children:"Thinking"}),n.jsx(B,{icon:hn,size:14,strokeWidth:1.5,className:"text-primary-900 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),n.jsx(Ot,{children:n.jsx("div",{className:"pt-1 mb-3",children:n.jsx("p",{className:"text-sm text-primary-700 whitespace-pre-wrap",children:e})})})]})})}function Yi({toolPart:e,defaultOpen:t=!1}){const{state:r,input:s,output:i,toolCallId:a}=e,l=(d,f=3200)=>{const h=d===void 0?"undefined":d;let m;if(typeof h=="string")try{m=JSON.stringify(JSON.parse(h),null,2)}catch{m=h}else m=JSON.stringify(h,null,2);return m.length<=f?m:`${m.slice(0,f).trimEnd()}
|
|
9
|
+
…[truncated]`},c=r==="output-error"?Kt:r==="output-available"?Vn:er,u=r==="output-error"?"text-red-600/80":r==="output-available"?"text-green-600/80":"text-primary-500/80";return n.jsx("div",{className:"inline-flex flex-col w-full",children:n.jsxs(At,{defaultOpen:t,children:[n.jsxs(It,{render:n.jsx(he,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[n.jsx(B,{icon:c,size:12,strokeWidth:1.7,className:u}),n.jsx("span",{className:"text-sm font-medium text-primary-900",children:e.type}),n.jsx(B,{icon:hn,size:14,strokeWidth:1.5,className:"ml-auto text-primary-700/80 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),n.jsx(Ot,{className:"mt-1",children:n.jsxs("div",{className:"space-y-2 rounded-md border border-primary-200 bg-primary-100/70 p-2",children:[n.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[n.jsx("div",{className:"text-[11px] font-medium text-primary-600",children:"Tool"}),n.jsx("div",{className:"font-mono text-xs text-primary-800 break-all",children:e.type})]}),s&&Object.keys(s).length>0&&n.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[n.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Input"}),n.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:l(s)})]}),i!=null&&n.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[n.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Output"}),n.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:l(i)})]}),r==="output-error"&&e.errorText&&n.jsxs("div",{className:"rounded border border-red-200 bg-red-50 px-2 py-1.5",children:[n.jsx("h4",{className:"mb-1 text-[11px] font-medium text-red-600",children:"Error"}),n.jsx("div",{className:"text-xs text-red-700",children:e.errorText})]}),a&&n.jsxs("div",{className:"text-[11px] text-primary-500/80 font-mono tabular-nums",children:["ID: ",a.slice(0,16),"..."]})]})})]})})}function Pn(e){try{return new URL(e).hostname.replace("www.","")}catch{return e}}function _n({domain:e}){return n.jsx("div",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-white dark:bg-zinc-800 border border-cyan-500/20 overflow-hidden",title:e,children:n.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${e}&sz=32`,alt:"",className:"w-4 h-4 object-contain",loading:"lazy",onError:t=>{const r=t.target;r.style.display="none";const s=r.parentElement;s&&(s.textContent=e.charAt(0).toUpperCase(),s.classList.add("text-[10px]","font-medium","text-cyan-400"))}})})}function Xi({sources:e}){const[t,r]=o.useState(!1);if(!e.length)return null;const s=[...new Set(e.map(i=>Pn(i.url)))];return n.jsxs("div",{className:"mt-2 w-full",children:[n.jsxs("button",{onClick:()=>r(!t),className:M("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs","bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-500/30","text-cyan-300 transition-colors"),children:[n.jsx(B,{icon:Qn,size:14}),n.jsx("span",{className:"font-medium",children:"Sources"}),n.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-cyan-500/20 text-cyan-400 font-semibold",children:e.length}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-1",children:[s.slice(0,3).map(i=>n.jsx(_n,{domain:i},i)),s.length>3&&n.jsxs("span",{className:"text-cyan-500/70 text-[10px] ml-0.5",children:["+",s.length-3]})]}),n.jsx(B,{icon:fn,size:12,className:M("transition-transform",t&&"rotate-90")})]}),t&&n.jsx("div",{className:"mt-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 max-h-80 overflow-y-auto",children:e.map((i,a)=>{const l=Pn(i.url);return n.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-start gap-2 p-2.5 border-b border-cyan-500/10 last:border-b-0 hover:bg-cyan-500/5 transition-colors",children:[n.jsx(_n,{domain:l}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-primary-900 hover:underline line-clamp-1",children:i.title||l}),n.jsx("div",{className:"text-xs text-muted-foreground",children:l}),i.snippet&&n.jsx("p",{className:"text-xs text-muted-foreground/80 line-clamp-2 mt-0.5",children:i.snippet})]})]},`${i.url}-${a}`)})})]})}function Bi(e,t){const r=t!==void 0,s=t?.isError??!1;let i;r?s?i="output-error":i="output-available":i="input-available";let a;s&&t?.content?.[0]?.type==="text"&&(a=t.content[0].text||"Unknown error");const l=t?.content?.map(u=>u.type==="text"?String(u.text??""):"").join("").trim(),c=t?.details??(l&&l.length>0?l:void 0);return{type:e.name||"unknown",state:i,input:e.arguments,output:c,toolCallId:e.id,errorText:a}}function Kn(e){return Je(e).map(r=>{const s=r.id??"",i=r.name??"",a=r.partialJson??"",l=r.arguments?JSON.stringify(r.arguments):"";return`${s}|${i}|${a}|${l}`}).join("||")}function Gi(e){if(!e)return"missing";const r=(Array.isArray(e.content)?e.content:[]).map(i=>i.type==="text"?String(i.text??""):"").join("").trim(),s=e.details?JSON.stringify(e.details):"";return`${e.toolCallId??""}|${e.toolName??""}|${e.isError?"1":"0"}|${r}|${s}`}function zn(e,t){if(!t)return"";const r=Je(e);return r.length===0?"":r.map(s=>s.id?Gi(t.get(s.id)):"missing").join("||")}function qi(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function Hn(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=qi(r);if(s)return s}return null}function an(e){const r=(Array.isArray(e.content)?e.content:[]).find(s=>s.type==="thinking");return r&&"thinking"in r?String(r.thinking??""):null}function Vi(e){const t=Array.isArray(e.content)?e.content:[],r=[];for(const s of t)s.type==="image"&&"source"in s&&typeof s.source?.data=="string"&&r.push(s);return r}function Ji({message:e,toolResultsByCallId:t,forceActionsVisible:r=!1,isStreaming:s=!1,isLastAssistant:i=!1,aggregatedSearchSources:a,wrapperRef:l,wrapperClassName:c,wrapperScrollMarginTop:u,messageDomId:d,highlighted:f=!1}){const{settings:h}=qs(),m=e.role||"assistant",p=Te(e),w=an(e),g=Vi(e),k=m==="user",v=rn(e),y=m==="assistant"?Je(e):[],P=y.length>0,A=i&&!s&&h.showSearchSources&&a?a:[];return n.jsxs("div",{ref:l,id:d,"data-message-id":d,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px",...typeof u=="number"?{scrollMarginTop:`${u}px`}:void 0},className:M("opencami-message-item group mx-auto flex w-full max-w-[var(--opencami-chat-width)] flex-col gap-1 py-[var(--opencami-msg-padding-y)]",c,f&&"opencami-message-highlight",k?"items-end":"items-start"),children:[w&&h.showReasoningBlocks&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(Wi,{content:w})}),g.length>0&&n.jsx("div",{className:M("flex flex-wrap gap-2 mb-2",k?"justify-end":"justify-start"),children:g.map((K,N)=>n.jsx("img",{src:`data:${K.source.media_type};base64,${K.source.data}`,alt:`Attachment ${N+1}`,loading:"lazy",decoding:"async",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},N))}),n.jsx(jr,{className:M("min-w-0 max-w-full",k?"flex-row-reverse":""),children:n.jsx(Ui,{markdown:!k,className:M("text-primary-900 opencami-text-size min-w-0 max-w-full",k?"opencami-message-user bg-primary-100 px-4 py-[var(--opencami-user-bubble-py)] max-w-[85%]":"opencami-message-assistant bg-transparent w-full",!k&&s&&"stream-fade-in"),children:p})}),P&&h.showToolMessages&&n.jsx("div",{className:"mt-2 flex w-full min-w-0 max-w-[var(--opencami-chat-width)] flex-col gap-3 overflow-x-hidden",children:y.map(K=>{const N=K.id?t?.get(K.id):void 0,$=Bi(K,N);return n.jsx(Yi,{toolPart:$,defaultOpen:!1},K.id||K.name)})}),A.length>0&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(Xi,{sources:A})}),!P&&n.jsx($i,{text:p,timestamp:v,align:k?"end":"start",forceVisible:r})]})}function Qi(e,t){return!(e.forceActionsVisible!==t.forceActionsVisible||e.isStreaming!==t.isStreaming||e.isLastAssistant!==t.isLastAssistant||e.aggregatedSearchSources!==t.aggregatedSearchSources||e.wrapperClassName!==t.wrapperClassName||e.wrapperRef!==t.wrapperRef||e.wrapperScrollMarginTop!==t.wrapperScrollMarginTop||e.messageDomId!==t.messageDomId||e.highlighted!==t.highlighted||(e.message.role||"assistant")!==(t.message.role||"assistant")||Te(e.message)!==Te(t.message)||an(e.message)!==an(t.message)||Kn(e.message)!==Kn(t.message)||zn(e.message,e.toolResultsByCallId)!==zn(t.message,t.toolResultsByCallId)||Hn(e.message)!==Hn(t.message))}const Jt=o.memo(Ji,Qi),Zi=[/```[\s\S]*?```/g,/`[^`]+`/g,/\b(function|const|let|var|class|import|export|return|async|await)\b/g];function ea(e){const t=[],r=e.match(/"([^"]+)"|'([^']+)'/g);r&&t.push(...r.map(a=>a.replace(/['"]/g,"")));const s=e.match(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g);s&&t.push(...s.filter(a=>!["I","The","A","An","This"].includes(a)));const i=e.match(/`([^`]+)`/g);return i&&t.push(...i.map(a=>a.replace(/`/g,""))),[...new Set(t)].slice(0,5)}function ta(e){return Zi.some(t=>t.test(e))}function na(e){return/^[\s]*[-*•\d]+[.)\s]/m.test(e)||/\b(first|second|third|1\.|2\.|3\.)/i.test(e)}function ra(e){return/\b(alternatively|another|other option|could also|you might|consider)\b/i.test(e)}function sa(e){return/\b(because|since|due to|reason|why|how|what|when|where)\b/i.test(e)}function oa(e){return/\b(however|but|note|warning|caution|careful|important|keep in mind|be aware)\b/i.test(e)}function ia(e){const t=[],r=ea(e);if(ta(e)&&(t.push({text:"Can you explain this code step by step?",type:"clarify"}),t.push({text:"How would I modify this for my use case?",type:"actionable"})),na(e)&&(t.push({text:"Can you elaborate on the first point?",type:"expand"}),t.push({text:"Which of these is most important to start with?",type:"actionable"})),ra(e)&&(t.push({text:"What are the pros and cons of each approach?",type:"alternative"}),t.push({text:"Which option would you recommend and why?",type:"clarify"})),sa(e)&&t.length<3&&t.push({text:"Can you give me a practical example?",type:"example"}),oa(e)&&t.length<3&&t.push({text:"What potential issues should I watch out for?",type:"clarify"}),r.length>0&&t.length<3){const a=r[0];t.push({text:`Tell me more about ${a}`,type:"expand"})}const s=[{text:"Can you give me a concrete example?",type:"example"},{text:"What would be the next steps?",type:"actionable"},{text:"How does this work in practice?",type:"expand"},{text:"Are there any common mistakes to avoid?",type:"clarify"},{text:"Can you simplify this explanation?",type:"clarify"}],i=new Set(t.map(a=>a.type));for(const a of s){if(t.length>=3)break;i.has(a.type)||(t.push(a),i.add(a.type))}for(const a of s){if(t.length>=3)break;t.some(l=>l.text===a.text)||t.push(a)}return t.slice(0,3)}function $n(e){return ia(e).map(t=>t.text)}const aa={openai:{baseUrl:"https://api.openai.com/v1",model:"gpt-4.1-nano"},openrouter:{baseUrl:"https://openrouter.ai/api/v1",model:"openai/gpt-oss-120b"},ollama:{baseUrl:"http://localhost:11434/v1",model:"llama3.2"},custom:{baseUrl:"",model:""}},Tt={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function kr(e){return aa[e]}function la(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():kr(e.llmProvider).baseUrl}function ca(e){return e.llmModel.trim()?e.llmModel.trim():kr(e.llmProvider).model}function Un(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||e.llmBaseUrl.trim()&&e.llmModel.trim():t||!!e.llmApiKey.trim()}function ua(e){if(!e||typeof e!="object")return{settings:Tt};const{settings:t}=e;if(!t)return{settings:Tt};const{openaiApiKey:r,...s}=t,i=s.llmApiKey??r??"";return{settings:{...Tt,...s,llmApiKey:i}}}const Qe=lr()(ar(e=>({settings:{...Tt},updateSettings:t=>e(r=>({settings:{...r.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>ua(e)}));function Wl(){const e=Qe(l=>l.settings),t=Qe(l=>l.updateSettings),r=Qe(l=>l.clearApiKey),[s,i]=o.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:Un(e,!1),isLoading:!0,error:null});o.useEffect(()=>{let l=!1;async function c(){try{const u=await fetch("/api/llm-features");if(!u.ok)throw new Error("Failed to check LLM status");const d=await u.json();if(l)return;const f=!!e.llmApiKey,h=e.llmProvider==="openrouter"?!!d.hasOpenRouterKey:d.hasEnvKey;i({hasEnvKey:d.hasEnvKey,hasOpenRouterKey:!!d.hasOpenRouterKey,hasUserKey:f,isAvailable:Un(e,h),isLoading:!1,error:null})}catch(u){if(l)return;i(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to check status"}))}}return c(),()=>{l=!0}},[e.llmApiKey,e.llmProvider,e.llmBaseUrl,e.llmModel]);const a=o.useCallback(async l=>{try{const c=Cr({...e,llmApiKey:l}),d=await(await fetch("/api/llm-features",{method:"POST",headers:{"Content-Type":"application/json",...c},body:JSON.stringify({action:"test"})})).json();return d.ok?{valid:d.valid??!1,error:d.error}:{valid:!1,error:d.error||"Test failed"}}catch(c){return{valid:!1,error:c instanceof Error?c.message:"Network error"}}},[e]);return{settings:e,updateSettings:t,clearApiKey:r,status:s,testApiKey:a}}function Cr(e){const t=e.llmApiKey,r=la(e),s=ca(e);return t?{"X-OpenAI-API-Key":t,...r?{"X-LLM-Base-URL":r}:{},...s?{"X-LLM-Model":s}:{}}:{...r?{"X-LLM-Base-URL":r}:{},...s?{"X-LLM-Model":s}:{}}}function Nr(){const e=Qe.getState().settings;return Cr(e)}async function da(e,t){const r={"Content-Type":"application/json",...Nr()},s=await fetch("/api/llm-features",{method:"POST",headers:r,body:JSON.stringify({action:"followups",conversationContext:e}),signal:t});if(!s.ok)throw new Error(`API error: ${s.status}`);const i=await s.json();return i.ok&&Array.isArray(i.suggestions)&&i.suggestions.length>0?i.suggestions:[]}function fa(e,t,r){const s=Qe(P=>P.settings),i=s.useLlmFollowUps,{minResponseLength:a=50,timeoutMs:l=8e3,heuristicsOnly:c}=r??{},u=c??!i,[d,f]=o.useState([]),[h,m]=o.useState(!1),[p,w]=o.useState(null),[g,k]=o.useState(null),v=o.useRef(""),y=o.useRef(null);return o.useEffect(()=>{if(!e||e.trim().length<a){f([]),k(null),m(!1),w(null);return}const P=e.slice(0,200)+e.length;if(P===v.current)return;if(v.current=P,y.current&&y.current.abort(),u){const $=$n(e);f($),k("heuristic"),m(!1),w(null);return}const A=new AbortController;y.current=A,m(!0),w(null);const K=$n(e);f(K),k("heuristic");const N=t?`Context: ${t}
|
|
10
|
+
|
|
11
|
+
Assistant's response:
|
|
12
|
+
${e.slice(0,2e3)}`:`Assistant's response:
|
|
13
|
+
${e.slice(0,2e3)}`;return da(N,A.signal).then($=>{A.signal.aborted||($.length>0&&(f($),k("llm")),m(!1))}).catch($=>{A.signal.aborted||(w($ instanceof Error?$.message:String($)),m(!1))}),()=>{}},[e,t,a,l,u,s.llmApiKey,s.llmBaseUrl,s.llmModel,s.llmProvider]),{suggestions:d,isLoading:h,error:p,source:g}}function ma({responseText:e,contextSummary:t,onSuggestionClick:r,disabled:s=!1,className:i}){const{suggestions:a,isLoading:l,source:c}=fa(e,t,{minResponseLength:50,timeoutMs:8e3});return a.length===0&&!l?null:n.jsxs("div",{className:M("flex flex-col gap-2 mt-3",i),children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-primary-500",children:[n.jsx("span",{className:"text-primary-400",children:"✨"}),n.jsx("span",{children:l?n.jsxs("span",{className:"flex items-center gap-1",children:["Thinking of follow-ups",n.jsx(B,{icon:er,size:12,strokeWidth:2,className:"animate-spin text-primary-400"})]}):c==="llm"?"AI suggestions":"Follow-up suggestions"})]}),n.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((u,d)=>n.jsxs("button",{type:"button",disabled:s,onClick:()=>r(u),className:M("group inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full","text-sm text-primary-700 bg-primary-50 border border-primary-200","hover:bg-primary-100 hover:border-primary-300 hover:text-primary-900","focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:ring-offset-1","transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-primary-50 disabled:hover:border-primary-200",l&&"opacity-75"),children:[n.jsx("span",{children:u}),n.jsx(B,{icon:fn,size:14,strokeWidth:2,className:"text-primary-400 group-hover:text-primary-600 group-hover:translate-x-0.5 transition-all duration-150"})]},`${d}-${u.slice(0,20)}`))})]})}const Fn=o.memo(ma);function ha({className:e,variant:t="outline",scrollRef:r,...s}){const[i,a]=o.useState(!0),[l,c]=o.useState(!1),u=o.useRef(0),d=o.useCallback(()=>{const f=r.current;if(!f)return;const h=Math.abs(f.scrollHeight-f.scrollTop-f.clientHeight)<100;a(h)},[r]);return o.useLayoutEffect(()=>{const f=r.current;if(!f)return;const h=()=>{u.current=f.scrollTop,d()},m=new MutationObserver(()=>{f&&(f.scrollTop!==u.current&&(u.current=f.scrollTop),d())});return d(),f.addEventListener("scroll",h),m.observe(f,{childList:!0,subtree:!0}),()=>{f.removeEventListener("scroll",h),m.disconnect()}},[d,r]),o.useLayoutEffect(()=>{if(i){c(!1);return}const f=window.setTimeout(()=>{c(!0)},200);return()=>window.clearTimeout(f)},[i]),n.jsx(he,{variant:"secondary",size:"icon-sm",className:M("pointer-events-auto rounded-full shadow-md","transition-all duration-100 ease-in-out",!i&&l?"translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-4 scale-98 opacity-0",e),onClick:()=>{const f=r.current;f&&(f.scrollTop=f.scrollHeight,a(!0))},...s,children:n.jsx(B,{icon:hn,size:18,strokeWidth:1.8})})}function pa({className:e,viewportRef:t,scrollRef:r,viewportProps:s}){return n.jsxs(gr,{className:M("relative flex flex-1 min-h-0 flex-col",e),children:[n.jsx(xr,{className:"relative will-change-transform overflow-x-hidden",ref:t,...s}),n.jsx("div",{className:"relative mx-auto w-full min-w-0 max-w-full px-5 sm:max-w-[768px]",children:n.jsx("div",{className:"pointer-events-none absolute bottom-10 right-10 z-50",children:n.jsx(ha,{scrollRef:r})})}),n.jsx(yr,{orientation:"vertical",children:n.jsx(wr,{})}),n.jsx(Qo,{})]})}function ga(e,t){if(e===t)return!0;const r=Object.keys(e),s=Object.keys(t);if(r.length!==s.length)return!1;for(const i of r)if(e[i]!==t[i])return!1;return!0}function xa(e,t){return!(e.className!==t.className||e.viewportRef!==t.viewportRef||e.scrollRef!==t.scrollRef||!ga(e.viewportProps,t.viewportProps))}const ya=o.memo(pa,xa);function wa({viewportNode:e,children:t}){return e?Gr.createPortal(n.jsx("div",{className:"relative flex w-full min-w-0 max-w-full flex-col overflow-x-hidden",children:t}),e):null}function ba({children:e,className:t,onUserScroll:r,...s}){const i=o.useRef(null),[a,l]=o.useState(null),c=o.useCallback(function(d){i.current=d,l(d)},[]);return o.useLayoutEffect(()=>{const u=i.current;if(!u)return;const d=()=>{r?.(u.scrollTop)};return u.addEventListener("scroll",d),()=>u.removeEventListener("scroll",d)},[r]),n.jsxs(n.Fragment,{children:[n.jsx(ya,{className:t,viewportRef:c,scrollRef:i,viewportProps:s}),n.jsx(wa,{viewportNode:a,children:e})]})}const Sa=o.memo(ba);function va({children:e,className:t,...r}){return n.jsx("div",{className:M("flex w-full min-w-0 max-w-full flex-col min-h-full overflow-x-hidden",t),...r,children:n.jsx("div",{className:"mx-auto w-full min-w-0 max-w-full px-2 md:px-5 sm:max-w-[768px] flex flex-col flex-1 min-h-full overflow-x-hidden",children:n.jsx("div",{className:"flex min-w-0 max-w-full flex-col space-y-3 md:space-y-6",children:e})})})}function ja({...e}){return n.jsx("div",{className:"h-px w-full shrink-0 scroll-mt-4 pt-6","aria-hidden":"true",...e})}function ka({as:e="span",className:t,duration:r=4,spread:s=20,children:i,...a}){const l=Math.min(Math.max(s,5),45),c=e;return n.jsx(c,{className:M("bg-size-[200%_auto] bg-clip-text font-medium text-transparent","animate-[shimmer_4s_infinite_linear]",t),style:{backgroundImage:`linear-gradient(to right, var(--color-primary-600) ${50-l}%, var(--color-primary-950) 50%, var(--color-primary-600) ${50+l}%)`,animationDuration:`${r}s`},...a,children:i})}function Ca({className:e}){return n.jsxs("div",{className:M("flex items-center gap-2",e),children:[n.jsxs("div",{className:"relative flex h-1.5 w-1.5",children:[n.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-primary-400 opacity-75"}),n.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-size-[200%_auto] animate-[shimmer_2s_infinite_linear]",style:{backgroundImage:"linear-gradient(to right, var(--color-primary-600) 0%, var(--color-primary-950) 50%, var(--color-primary-600) 100%)"}})]}),n.jsx(ka,{className:"text-sm",duration:2,children:"Generating..."})]})}function Na({messages:e,loading:t,empty:r,emptyState:s,notice:i,noticePosition:a="start",waitingForResponse:l,isStreaming:c=!1,sessionKey:u,pinToTop:d,pinGroupMinHeight:f,headerHeight:h,contentStyle:m,onFollowUpClick:p,jumpToMessageId:w}){const g=o.useRef(null),k=o.useRef(null),v=o.useRef(!1),y=o.useRef(d),P=o.useRef(void 0),[A,K]=o.useState(null),N=o.useMemo(()=>e.filter(x=>x.role!=="toolResult"),[e]),$=o.useMemo(()=>{const x=new Map;for(const D of e){if(D.role!=="toolResult")continue;const S=D.toolCallId;typeof S=="string"&&S.trim().length>0&&x.set(S,D)}return x},[e]),G=o.useMemo(()=>{const x=_=>_?_.replace(/SECURITY NOTICE:[\s\S]*?<<<EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?END_EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/Source: Web (?:Search|Fetch)\n---/g,"").replace(/\n{2,}/g,`
|
|
14
|
+
`).trim():"",D=(_,U,F)=>{try{const te=JSON.parse(_),ee=Array.isArray(te)?te:te?.results??te?.web?.results??[];if(!Array.isArray(ee))return!1;let q=!1;for(const Q of ee)Q?.url&&Q?.title&&!F.has(Q.url)&&(F.add(Q.url),U.push({title:x(Q.title),url:Q.url,snippet:x(Q.description||Q.snippet||Q.content||"")}),q=!0);return q}catch{return!1}},S=[],I=new Set;for(const _ of N){if(_.role!=="assistant")continue;const U=Je(_);for(const F of U){if(!F.id)continue;const te=F.name==="web_search",ee=F.name==="web_fetch",q=F.name==="exec";if(!te&&!ee&&!q)continue;const Q=$.get(F.id);if(!Q)continue;const re=Q.content?.map(V=>V.type==="text"?String(V.text??""):"").join("").trim();if(re){if(te||q){if(q&&(!re.includes('"results"')||!re.includes('"url"')))continue;let V=re;const J=re.indexOf("{");J>0&&(V=re.slice(J));const pe=V.lastIndexOf("}");pe>0&&(V=V.slice(0,pe+1)),D(V,S,I)}else if(ee){const V=F.arguments?.url;if(V&&!I.has(V)){I.add(V);let J;try{J=new URL(V).hostname}catch{J=V}S.push({title:J,url:V})}}}}}return S},[N,$]),T=N.map((x,D)=>({message:x,index:D})).filter(({message:x})=>x.role!=="user").map(({index:x})=>x).pop(),X=N.map((x,D)=>({message:x,index:D})).filter(({message:x})=>x.role==="user").map(({index:x})=>x).pop(),W=l&&(typeof X!="number"||typeof T!="number"||T<X),C=typeof X=="number"?X:-1,L=d&&C>=0,R=typeof T=="number"?N[T]:void 0,E=R?Te(R):"",H=!l&&!c&&E.length>0&&p!==void 0&&(typeof X!="number"||typeof T!="number"||T>X);return o.useLayoutEffect(()=>{if(!t){if(d){const x=!y.current||P.current!==X;y.current=!0,P.current=X,x&&k.current&&(v.current=!0,k.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{v.current=!1},0));return}y.current=!1,P.current=X,g.current&&(v.current=!0,g.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{v.current=!1},0))}},[t,N.length,u,d,X]),o.useEffect(()=>{if(!w||t)return;const x=document.getElementById(`message-${w}`);if(!x)return;x.scrollIntoView({behavior:"smooth",block:"center"}),K(w);const D=window.setTimeout(()=>{K(S=>S===w?null:S)},1800);return()=>window.clearTimeout(D)},[w,t,N]),n.jsx(Sa,{className:"flex-1 min-h-0 -mb-4",children:n.jsxs(va,{className:"pt-6",style:m,children:[i&&a==="start"?i:null,r&&!i?s??n.jsx("div",{"aria-hidden":!0}):L?n.jsxs(n.Fragment,{children:[N.slice(0,C).map((x,D)=>{const S=typeof x.id=="string"?x.id:void 0,I=S||D,_=typeof T=="number"&&D===T,U=typeof T=="number"&&D===T,F=x.role==="assistant"&&Je(x).length>0;return n.jsx(Jt,{message:x,toolResultsByCallId:F?$:void 0,forceActionsVisible:_,isStreaming:U&&c,isLastAssistant:U,aggregatedSearchSources:U?G:void 0,messageDomId:S?`message-${S}`:void 0,highlighted:A===S},I)}),n.jsxs("div",{className:"flex flex-col gap-[var(--opencami-msg-gap)]",style:{minHeight:`${Math.max(0,f)}px`},children:[N.slice(C).map((x,D)=>{const S=C+D,I=typeof x.id=="string"?x.id:void 0,_=I||S,U=typeof T=="number"&&S===T,F=typeof T=="number"&&S===T,te=S===X?k:void 0,ee=S===X?"scroll-mt-0":void 0,q=S===X?h:void 0,Q=x.role==="assistant"&&Je(x).length>0;return n.jsx(Jt,{message:x,toolResultsByCallId:Q?$:void 0,forceActionsVisible:U,isStreaming:F&&c,isLastAssistant:F,aggregatedSearchSources:F?G:void 0,wrapperRef:te,wrapperClassName:ee,wrapperScrollMarginTop:q,messageDomId:I?`message-${I}`:void 0,highlighted:A===I},_)}),W?n.jsx("div",{className:"py-2",children:n.jsx(Ca,{})}):null,H&&p?n.jsx(Fn,{responseText:E,onSuggestionClick:p,disabled:l}):null]})]}):n.jsxs(n.Fragment,{children:[N.map((x,D)=>{const S=typeof x.id=="string"?x.id:void 0,I=S||D,_=typeof T=="number"&&D===T,U=typeof T=="number"&&D===T,F=x.role==="assistant"&&Je(x).length>0;return n.jsx(Jt,{message:x,toolResultsByCallId:F?$:void 0,forceActionsVisible:_,isStreaming:U&&c,isLastAssistant:U,aggregatedSearchSources:U?G:void 0,messageDomId:S?`message-${S}`:void 0,highlighted:A===S},I)}),H&&p?n.jsx(Fn,{responseText:E,onSuggestionClick:p,disabled:l}):null]}),i&&a==="end"?i:null,n.jsx(ja,{ref:g})]})})}function Ea(e,t){return e.messages===t.messages&&e.loading===t.loading&&e.empty===t.empty&&e.emptyState===t.emptyState&&e.notice===t.notice&&e.noticePosition===t.noticePosition&&e.waitingForResponse===t.waitingForResponse&&e.isStreaming===t.isStreaming&&e.sessionKey===t.sessionKey&&e.pinToTop===t.pinToTop&&e.pinGroupMinHeight===t.pinGroupMinHeight&&e.headerHeight===t.headerHeight&&e.contentStyle===t.contentStyle&&e.onFollowUpClick===t.onFollowUpClick&&e.jumpToMessageId===t.jumpToMessageId}const Ta=o.memo(Na,Ea),Er=o.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:qr.createRef()});let at=null,Wn=!1;function Ra(){Wn||typeof window>"u"||(Wn=!0,window.addEventListener("keydown",e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey)return;const t=e.target;if(!t)return;const r=t.tagName.toLowerCase();if(r==="input"||r==="textarea"||r==="select"||t.isContentEditable)return;const s=e.key.length===1,i=e.key==="Backspace";!s&&!i||!at||at.disabled||at.focus()}))}function Tr(){return o.useContext(Er)}function Ma({className:e,isLoading:t=!1,maxHeight:r=240,value:s,onValueChange:i,onSubmit:a,children:l,disabled:c=!1,onClick:u,...d}){const[f,h]=o.useState(s||""),m=o.useRef(null);Ra();function p(g){h(g),i?.(g)}function w(g){c||m.current?.focus(),u?.(g)}return n.jsx(Ae,{children:n.jsx(Er.Provider,{value:{isLoading:t,value:s??f,setValue:i??p,maxHeight:r,onSubmit:a,disabled:c,textareaRef:m},children:n.jsx("div",{onClick:w,className:M("bg-surface cursor-text rounded-[22px] outline outline-ink/10 shadow-[0px_12px_32px_0px_rgba(0,0,0,0.05)] py-3 gap-3 flex flex-col",c&&"cursor-not-allowed opacity-60",e),...d,children:l})})})}function Aa({className:e,onKeyDown:t,disableAutosize:r=!1,inputRef:s,...i}){const{value:a,setValue:l,maxHeight:c,onSubmit:u,disabled:d,textareaRef:f}=Tr();function h(g){!g||r||(g.style.height="auto",typeof c=="number"?g.style.height=`${Math.min(g.scrollHeight,c)}px`:g.style.height=`min(${g.scrollHeight}px, ${c})`)}function m(g){f.current=g,typeof s=="function"?s(g):s&&"current"in s&&(s.current=g),g?at=g:at===g&&(at=null),h(g)}o.useLayoutEffect(()=>{if(!f.current||r)return;const g=f.current;g.style.height="auto",typeof c=="number"?g.style.height=`${Math.min(g.scrollHeight,c)}px`:g.style.height=`min(${g.scrollHeight}px, ${c})`},[a,c,r]);function p(g){h(g.target),l(g.target.value)}function w(g){g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),u?.()),t?.(g)}return n.jsx("textarea",{ref:m,value:a,onChange:p,onKeyDown:w,className:M("text-primary-950 opencami-text-size min-h-[28px] w-full resize-none border-none bg-transparent shadow-none outline-none focus-visible:ring-0 pl-4 pr-1 placeholder:text-primary-500",e),rows:1,readOnly:d,"aria-disabled":d,...i})}function Ia({children:e,className:t,...r}){return n.jsx("div",{className:M("flex items-center gap-2",t),...r,children:e})}function Yn({tooltip:e,children:t,className:r,side:s="top",...i}){const{disabled:a}=Tr();return n.jsxs(Ie,{...i,children:[n.jsx(Oe,{disabled:a,onClick:l=>l.stopPropagation(),children:t}),n.jsx(De,{side:s,className:r,children:e})]})}const Rr="opencami-selected-model";function Oa(){if(typeof window>"u")return null;try{return localStorage.getItem(Rr)}catch{return null}}function Da(e){if(!(typeof window>"u"))try{localStorage.setItem(Rr,e)}catch{}}function La({className:e,onModelChange:t}){const[r,s]=o.useState([]),[i,a]=o.useState(""),[l,c]=o.useState(!0),[u,d]=o.useState(null),f=o.useRef(null);o.useEffect(()=>{let g=!0;async function k(){f.current?.abort();const v=new AbortController;f.current=v;try{c(!0),d(null);const y=await fetch("/api/models",{signal:v.signal});if(!y.ok)throw new Error("Failed to fetch models");const P=await y.json();if(!g)return;if(P.ok&&P.models.length>0){s(P.models);const A=Oa(),K=A&&P.models.some(N=>N.id===A)?A:P.defaultModel;a(K),t?.(K)}else throw new Error("No models available")}catch(y){if(y instanceof Error&&y.name==="AbortError"||!g)return;console.error("[model-selector] Error fetching models:",y),d(y instanceof Error?y.message:"Failed to load models"),s([{id:"default",name:"Default Model"}]),a("default")}finally{g&&c(!1)}}return k(),()=>{g=!1,f.current?.abort()}},[t]);function h(g){a(g),Da(g),t?.(g)}if(l)return n.jsxs("div",{className:M("flex items-center gap-2 text-xs text-primary-500",e),children:[n.jsx(B,{icon:Wt,size:14}),n.jsx("span",{children:"Loading..."})]});if(u||r.length===0)return null;const m=r.find(g=>g.id===i),p=m?.name||"Select Model",w=(()=>{if(!m?.name)return p;const k=m.name.replace(/\s*\([^)]*\)\s*$/,"").trim(),v=k.split(/\s+/);return v.length>3?v.slice(0,3).join(" "):k})();return r.length===1?n.jsxs("div",{className:M("flex items-center gap-2 text-xs text-primary-500",e),children:[n.jsx(B,{icon:Wt,size:14}),n.jsx("span",{className:"font-[450] md:hidden",children:w}),n.jsx("span",{className:"font-[450] hidden md:inline",children:p})]}):n.jsxs(zt,{children:[n.jsxs(Ht,{className:M("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[n.jsx(B,{icon:Wt,size:14}),n.jsx("span",{className:"md:hidden",children:w}),n.jsx("span",{className:"hidden md:inline",children:p})]}),n.jsx($t,{side:"top",align:"start",children:r.map(g=>n.jsxs(We,{onClick:()=>h(g.id),className:"justify-between min-w-[180px]",children:[n.jsx("span",{children:g.name}),i===g.id&&n.jsx(B,{icon:mn,size:14,className:"text-primary-600"})]},g.id))})]})}const Mr="opencami-personas-enabled",ln="opencami-active-persona";function Pa(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(Mr);return e===null?!0:e==="true"}catch{return!0}}function _a(){if(typeof window>"u")return null;try{const e=localStorage.getItem(ln);return e?JSON.parse(e):null}catch{return null}}function Xn(e){if(!(typeof window>"u"))try{e?localStorage.setItem(ln,JSON.stringify(e)):localStorage.removeItem(ln)}catch{}}const Ka={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function za({className:e,onSelect:t}){const[r,s]=o.useState({}),[i,a]=o.useState(null),[l,c]=o.useState(!0),[u,d]=o.useState(!1),[f,h]=o.useState(Pa),m=o.useRef(null);o.useEffect(()=>{const k=v=>{v.key===Mr&&h(v.newValue===null?!0:v.newValue==="true")};return window.addEventListener("storage",k),()=>window.removeEventListener("storage",k)},[]),o.useEffect(()=>{let k=!0;async function v(){m.current?.abort();const y=new AbortController;m.current=y;try{c(!0);const P=await fetch("/api/personas",{signal:y.signal});if(!P.ok){d(!1);return}const A=await P.json();if(!k)return;A.ok&&A.available?(s(A.personas),d(!0),a(_a())):d(!1)}catch(P){if(P instanceof Error&&P.name==="AbortError"||!k)return;d(!1)}finally{k&&c(!1)}}return v(),()=>{k=!1,m.current?.abort()}},[]);const p=o.useCallback(k=>{a(k),Xn(k),t(`/persona ${k.id}`)},[t]),w=o.useCallback(()=>{a(null),Xn(null),t("/persona exit")},[t]);if(l||!u||!f)return null;const g=Object.entries(r);return g.length===0?null:n.jsxs(zt,{children:[n.jsxs(Ht,{className:M("inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[n.jsx("span",{className:"text-sm","aria-hidden":"true",children:"🎭"}),i?n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{children:i.emoji}),n.jsx("span",{children:i.name})]}):n.jsx("span",{children:"Persona"})]}),n.jsxs($t,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[i&&n.jsxs(n.Fragment,{children:[n.jsxs(We,{onClick:w,className:"text-red-600 hover:bg-red-50",children:[n.jsx("span",{className:"text-sm",children:"✕"}),n.jsx("span",{children:"Exit Persona"}),n.jsxs("span",{className:"ml-auto text-[10px] text-primary-400",children:[i.emoji," ",i.name]})]}),n.jsx("div",{className:"my-1 h-px bg-primary-200"})]}),g.map(([k,v])=>n.jsxs("div",{children:[n.jsx("div",{className:"px-2 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-primary-400",children:Ka[k]??k}),v.map(y=>n.jsxs(We,{onClick:()=>p(y),className:"justify-between",children:[n.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-sm flex-shrink-0",children:y.emoji}),n.jsx("span",{className:"truncate",children:y.name})]}),n.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:y.description})]},y.id))]},k))]})]})}const Ha=[{command:"/new",description:"Start a new conversation",usage:"/new"},{command:"/reset",description:"Reset conversation context",usage:"/reset"},{command:"/abort",description:"Abort current generation",usage:"/abort"},{command:"/status",description:"Show session status card",usage:"/status"},{command:"/usage",description:"Show token usage",usage:"/usage [off|tokens|full]"},{command:"/models",description:"List available models",usage:"/models"},{command:"/agents",description:"List available agents",usage:"/agents"},{command:"/sessions",description:"List active sessions",usage:"/sessions"},{command:"/model",description:"Switch model for this session",usage:"/model <alias>"},{command:"/reasoning",description:"Toggle reasoning mode",usage:"/reasoning [on|off|stream]"},{command:"/think",description:"Set thinking budget",usage:"/think [off|minimal|low|medium|high]"},{command:"/verbose",description:"Toggle verbose output",usage:"/verbose [on|full|off]"},{command:"/tts",description:"Text-to-speech controls",usage:"/tts [status|off|always]"},{command:"/settings",description:"Show current settings",usage:"/settings"},{command:"/help",description:"Show help",usage:"/help"}];function $a({className:e,onCommandSelect:t}){const[r,s]=o.useState(!1);function i(a){t?.(a),s(!1)}return n.jsxs(n.Fragment,{children:[n.jsx(he,{variant:"ghost",size:"sm",onClick:()=>s(!0),className:M("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:n.jsx(B,{icon:Nn,size:16,className:"text-primary-500"})}),r&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:n.jsxs("div",{className:"bg-white dark:bg-neutral-900 border border-primary-200 dark:border-neutral-700 rounded-xl shadow-2xl w-full max-w-lg max-h-[80vh] overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(B,{icon:Nn,size:18,className:"text-primary-600 dark:text-primary-400"}),n.jsx("h2",{className:"font-semibold text-primary-900 dark:text-white",children:"Slash Commands"})]}),n.jsx(he,{variant:"ghost",size:"sm",onClick:()=>s(!1),className:"h-7 w-7 p-0",children:n.jsx(B,{icon:Kt,size:16})})]}),n.jsxs("div",{className:"overflow-y-auto max-h-[60vh] p-2 bg-white dark:bg-neutral-900",children:[n.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-400 px-2 py-1 mb-2",children:"Type these commands in the chat input"}),Ha.map(a=>n.jsxs("button",{onClick:()=>i(a.command),className:"w-full flex items-start gap-3 px-3 py-2 rounded-lg hover:bg-primary-100 dark:hover:bg-neutral-800 transition-colors text-left",children:[n.jsx("code",{className:"text-sm font-mono font-medium text-primary-700 dark:text-primary-300 bg-primary-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded min-w-[80px]",children:a.command}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-primary-900 dark:text-neutral-100",children:a.description}),a.usage&&a.usage!==a.command&&n.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-500 font-mono mt-0.5",children:a.usage})]})]},a.command))]}),n.jsx("div",{className:"px-4 py-2 border-t border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:n.jsxs("div",{className:"text-xs text-primary-500 dark:text-neutral-400",children:["Press ",n.jsx("kbd",{className:"px-1 py-0.5 bg-primary-200 dark:bg-neutral-700 rounded text-primary-700 dark:text-neutral-300",children:"Esc"})," to close"]})})]})})]})}const Ua=10*1024*1024,it=1280,Fa=.75,Wa=300*1024,Ya=["image/png","image/jpeg","image/gif","image/webp"],Xa=".png,.jpg,.jpeg,.gif,.webp";function Ba(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function Ga(e){if(!Ba())throw new Error("Image compression not available in this browser");return new Promise((t,r)=>{const s=new Image,i=URL.createObjectURL(e),a=()=>{URL.revokeObjectURL(i)};s.onload=()=>{try{let l=s.width,c=s.height;(l>it||c>it)&&(l>c?(c=Math.round(c*it/l),l=it):(l=Math.round(l*it/c),c=it));const u=document.createElement("canvas");u.width=l,u.height=c;const d=u.getContext("2d");if(!d){a(),r(new Error("Failed to get canvas context"));return}d.drawImage(s,0,0,l,c);const f=e.type==="image/png"?"image/png":"image/jpeg";let h=Fa,m=u.toDataURL(f,h);if(f==="image/jpeg"){const w=Wa*1.37;for(;m.length>w&&h>.3;)h-=.1,m=u.toDataURL(f,h)}const p=m.split(",")[1];if(!p){a(),r(new Error("Failed to encode image"));return}a(),t(p)}catch(l){a(),r(l instanceof Error?l:new Error("Image compression failed"))}},s.onerror=()=>{a(),r(new Error("Failed to load image"))},s.src=i})}function Ar(e){return Ya.includes(e.type)}async function Ir(e){const t=crypto.randomUUID();if(!Ar(e))return{id:t,file:e,preview:null,type:"image",base64:null,error:"Unsupported file type. Please use PNG, JPG, GIF, or WebP images."};if(e.size>Ua)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const r=await Ga(e),s=URL.createObjectURL(e);return{id:t,file:e,preview:s,type:"image",base64:r}}catch(r){return{id:t,file:e,preview:null,type:"image",base64:null,error:r instanceof Error?r.message:"Failed to process image"}}}function qa({onFileSelect:e,disabled:t=!1,className:r}){const s=o.useRef(null),i=o.useCallback(()=>{s.current?.click()},[]),a=o.useCallback(async l=>{const c=l.target.files?.[0];if(!c)return;l.target.value="";const u=await Ir(c);e(u)},[e]);return n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:s,type:"file",accept:Xa,onChange:a,className:"hidden","aria-hidden":"true"}),n.jsx(he,{variant:"ghost",size:"icon-sm",onClick:i,disabled:t,className:r,"aria-label":"Attach image",type:"button",children:n.jsx(B,{icon:gs,size:18,strokeWidth:1.8})})]})}function Va(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ja(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function Qa({attachment:e,onRemove:t,className:r}){o.useEffect(()=>()=>{e.preview&&URL.revokeObjectURL(e.preview)},[e.preview]);const s=!!e.error;return n.jsxs("div",{className:M("relative flex items-center gap-3 rounded-xl border p-2 pr-3",s?"border-red-300 bg-red-50":"border-primary-200 bg-primary-50",r),children:[n.jsx("div",{className:"relative shrink-0",children:e.type==="image"&&e.preview?n.jsx("img",{src:e.preview,alt:e.file.name,className:"h-12 w-12 rounded-lg object-cover"}):n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-lg bg-primary-100",children:n.jsx(B,{icon:xs,size:24,className:"text-primary-500"})})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"truncate text-sm font-medium text-primary-900",children:e.file.name}),s?n.jsx("p",{className:"text-xs text-red-600",children:e.error}):n.jsxs("p",{className:"text-xs text-primary-500",children:[Ja(e.file.name)," •"," ",Va(e.file.size)]})]}),n.jsx(he,{variant:"ghost",size:"icon-sm",onClick:()=>t(e.id),className:"h-6 w-6 shrink-0 rounded-full hover:bg-primary-200","aria-label":"Remove attachment",type:"button",children:n.jsx(B,{icon:Kt,size:14})})]})}function Za({attachments:e,onRemove:t,className:r}){return e.length===0?null:n.jsx("div",{className:M("flex flex-col gap-2 px-4",r),children:e.map(s=>n.jsx(Qa,{attachment:s,onRemove:t},s.id))})}function el({commands:e,selectedIndex:t,onSelect:r,className:s}){return e.length===0?null:n.jsx("div",{className:M("absolute left-2 right-2 md:left-5 md:right-5 bottom-full mb-2 z-20 rounded-xl border border-white/10 bg-neutral-900/95 shadow-2xl backdrop-blur-sm overflow-hidden",s),role:"listbox","aria-label":"Slash commands",children:n.jsx("div",{className:"max-h-56 overflow-y-auto p-1",children:e.map((i,a)=>{const l=a===t;return n.jsx("button",{type:"button",role:"option","aria-selected":l,onMouseDown:c=>{c.preventDefault(),r(i)},className:M("w-full rounded-md px-3 py-2 text-left transition-colors",l?"bg-neutral-800":"hover:bg-neutral-800/80"),children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("code",{className:"min-w-[90px] font-mono text-xs text-primary-300",children:i.command}),n.jsx("span",{className:"text-xs text-neutral-300",children:i.description})]})},i.command)})})})}const tl=o.memo(el),cn=lr()(ar(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function nl(){const e=cn(r=>r.level),t=cn(r=>r.setLevel);return{level:e,setLevel:t}}const Qt=[{value:"off",label:"Off",description:"No reasoning",shortLabel:"Off"},{value:"low",label:"Low",description:"Think",shortLabel:"Low"},{value:"medium",label:"Medium",description:"Think harder",shortLabel:"Medium"},{value:"high",label:"High",description:"Ultrathink",shortLabel:"High"}];function rl({className:e}){const{level:t,setLevel:r}=nl(),s=Qt.find(i=>i.value===t)??Qt[1];return n.jsxs(zt,{children:[n.jsxs(Ht,{className:M("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[n.jsx(B,{icon:tn,size:20,strokeWidth:1.5,className:M(t==="off"?"text-primary-400":"text-primary-700")}),n.jsx("span",{className:"text-pretty",children:s.shortLabel})]}),n.jsx($t,{side:"top",align:"start",className:"min-w-[190px]",children:Qt.map(i=>n.jsxs(We,{onClick:()=>r(i.value),className:"justify-between",children:[n.jsxs("span",{className:"flex flex-col text-pretty",children:[n.jsx("span",{className:"text-sm text-primary-900",children:i.label}),n.jsx("span",{className:"text-xs text-primary-500",children:i.description})]}),t===i.value&&n.jsx(B,{icon:mn,size:20,strokeWidth:1.5,className:"text-primary-600"})]},i.value))})]})}const Bn=[{command:"/haiku",description:"Switch to Claude Haiku 4.5"},{command:"/sonnet",description:"Switch to Claude Sonnet 4.5"},{command:"/opus",description:"Switch to Claude Opus 4.5"},{command:"/opus46",description:"Switch to Claude Opus 4.6"},{command:"/codex",description:"Switch to GPT 5.3 Codex"},{command:"/glm",description:"Switch to GLM 4.7"},{command:"/kimi",description:"Switch to Kimi K2.5"},{command:"/minimax",description:"Switch to MiniMax M2.1"},{command:"/grok",description:"Switch to Grok 4.1 Fast"},{command:"/model",description:"Show model picker or switch model"},{command:"/new",description:"New chat (optional: /new model)"},{command:"/reset",description:"Reset session"},{command:"/stop",description:"Stop current generation"},{command:"/compact",description:"Compact conversation context"},{command:"/help",description:"Show available commands"},{command:"/commands",description:"List all commands"},{command:"/status",description:"Show session status & usage"},{command:"/whoami",description:"Show your sender ID"},{command:"/context",description:"Show context window details"},{command:"/usage",description:"Toggle usage footer (off/tokens/full/cost)"},{command:"/think",description:"Set thinking level (off/low/medium/high)"},{command:"/reasoning",description:"Toggle reasoning (on/off/stream)"},{command:"/verbose",description:"Toggle verbose mode (on/full/off)"},{command:"/elevated",description:"Toggle elevated permissions (on/off/ask)"},{command:"/exec",description:"Configure exec settings"},{command:"/queue",description:"Show/configure message queue"},{command:"/tts",description:"Text-to-speech (off/always/tagged/status)"},{command:"/subagents",description:"List/stop/log sub-agent runs"},{command:"/followups",description:"Show follow-up suggestions"},{command:"/skill",description:"Run a skill by name"},{command:"/allowlist",description:"List/add/remove allowlist entries"},{command:"/approve",description:"Resolve exec approval (allow/deny)"},{command:"/config",description:"Show/get/set config (owner-only)"},{command:"/debug",description:"Runtime overrides (owner-only)"},{command:"/send",description:"Toggle message sending (on/off)"},{command:"/restart",description:"Restart gateway"},{command:"/activation",description:"Set activation mode (mention/always)"},{command:"/dock-telegram",description:"Switch replies to Telegram"},{command:"/dock-discord",description:"Switch replies to Discord"},{command:"/bash",description:"Run host shell command"}];function sl({onSubmit:e,isLoading:t,disabled:r,wrapperRef:s,inputRef:i}){const[a,l]=o.useState(""),[c,u]=o.useState(""),[d,f]=o.useState([]),[h,m]=o.useState(0),[p,w]=o.useState(!1),[g,k]=o.useState(!1),[v,y]=o.useState(!1),[P,A]=o.useState(0),[K,N]=o.useState(!1),$=o.useRef(null),G=o.useRef([]),T=o.useRef(null),X=o.useRef(null),W=o.useRef(null),C=o.useRef(null),L=o.useMemo(()=>/^\/\S*$/.test(a)&&!p,[a,p]),R=o.useMemo(()=>L?a.slice(1).toLowerCase():"",[L,a]),E=o.useMemo(()=>L?R?Bn.filter(O=>O.command.slice(1).toLowerCase().startsWith(R)):Bn:[],[L,R]),H=o.useCallback(O=>{C.current=O,i&&(typeof i=="function"?i(O):i.current=O)},[i]),x=o.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{C.current?.focus()})},[]),D=o.useCallback(()=>{l(""),f([]),m(0),w(!1),x()},[x]),S=o.useCallback(O=>{f(j=>[...j,O])},[]),I=o.useCallback(O=>{f(j=>j.filter(Y=>Y.id!==O))},[]),_=o.useCallback(O=>{Array.from(O.dataTransfer.types).includes("Files")&&(O.preventDefault(),O.dataTransfer.dropEffect="copy",k(!0))},[]),U=o.useCallback(O=>{O.preventDefault();const j=O.relatedTarget;j&&O.currentTarget.contains(j)||k(!1)},[]),F=o.useCallback(async O=>{O.preventDefault(),k(!1);const j=Array.from(O.dataTransfer.files??[]);if(j.length===0)return;const Y=j.filter(Z=>Ar(Z));if(Y.length===0)return;const ie=await Promise.all(Y.map(Z=>Ir(Z)));f(Z=>[...Z,...ie]),x()},[x]),te=o.useCallback(O=>{l(O),m(0),w(!1),x()},[x]),ee=o.useCallback(O=>{l(O),m(0),w(!1)},[]),q=o.useCallback(O=>{l(`${O.command} `),m(0),w(!1),x()},[x]),Q=o.useCallback(()=>{if(r)return;if(L&&E.length>0){const Y=Math.min(h,E.length-1);q(E[Y]);return}const O=a.trim(),j=d.filter(Y=>!Y.error&&Y.base64);O.length===0&&j.length===0||(e(O,{reset:D,setValue:te,model:c||void 0,attachments:j}),x())},[r,L,E,h,q,a,d,e,D,te,c,x]),re=o.useCallback(O=>{e(O,{reset:D,setValue:te,model:c||void 0,attachments:[]}),x()},[x,e,D,te,c]),V=o.useCallback(O=>{if(L){if(O.key==="Escape"){O.preventDefault(),w(!0),m(0);return}if(E.length!==0){if(O.key==="ArrowDown"){O.preventDefault(),m(j=>(j+1)%E.length);return}if(O.key==="ArrowUp"){O.preventDefault(),m(j=>(j-1+E.length)%E.length);return}if(O.key==="Tab"){O.preventDefault();const j=Math.min(h,E.length-1);q(E[j])}}}},[L,E,h,q]);o.useEffect(()=>()=>{X.current?.abort(),T.current&&clearInterval(T.current),$.current&&$.current.state!=="inactive"&&$.current.stop(),W.current&&W.current.abort()},[]);const J=o.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),pe=o.useCallback(()=>{$.current&&$.current.state!=="inactive"&&$.current.stop(),W.current&&W.current.stop(),T.current&&(clearInterval(T.current),T.current=null),y(!1),A(0)},[]),ve=o.useCallback(async()=>{const O=J();if(O==="browser"){const j=window.SpeechRecognition||window.webkitSpeechRecognition;if(!j){alert("Web Speech API is not supported in this browser.");return}const Y=new j;Y.continuous=!0,Y.interimResults=!1,Y.lang=navigator.language||"en-US",W.current=Y,y(!0),A(0),T.current=setInterval(()=>{A(Z=>Z>=119?(pe(),0):Z+1)},1e3);let ie="";Y.onresult=Z=>{for(let ae=Z.resultIndex;ae<Z.results.length;ae++)Z.results[ae].isFinal&&(ie+=Z.results[ae][0].transcript)},Y.onend=()=>{y(!1),A(0),T.current&&clearInterval(T.current),ie.trim()&&(l(Z=>Z+(Z?" ":"")+ie.trim()),x())},Y.onerror=()=>{y(!1),A(0),T.current&&clearInterval(T.current)},Y.start();return}try{const j=await navigator.mediaDevices.getUserMedia({audio:!0}),Y=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",ie=new MediaRecorder(j,{mimeType:Y});$.current=ie,G.current=[],ie.ondataavailable=Z=>{Z.data.size>0&&G.current.push(Z.data)},ie.onstop=async()=>{j.getTracks().forEach(ae=>ae.stop());const Z=new Blob(G.current,{type:Y});if(Z.size!==0){N(!0);try{const ae=new FormData;ae.append("audio",Z,`recording.${Y==="audio/webm"?"webm":"mp4"}`),O!=="auto"&&ae.append("provider",O),X.current?.abort();const ge=new AbortController;X.current=ge;const de=await(await fetch("/api/stt",{method:"POST",body:ae,signal:ge.signal})).json();de.ok&&de.text?(l(je=>je+(je?" ":"")+de.text),x()):de.ok||(console.warn("STT failed:",de.error),alert(de.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(ae){if(ae instanceof Error&&ae.name==="AbortError")return;console.warn("STT request failed:",ae),alert("Could not reach speech-to-text service.")}finally{N(!1)}}},y(!0),A(0),T.current=setInterval(()=>{A(Z=>Z>=119?(pe(),0):Z+1)},1e3),ie.start()}catch(j){const Y=j instanceof Error?j.message:String(j);if(Y.includes("NotAllowedError")||Y.includes("Permission"))try{(await navigator.permissions.query({name:"microphone"})).state==="denied"?alert("Microphone access is blocked. Please enable it in your browser/app settings."):alert("Microphone permission was not granted. Please try again and allow access when prompted.")}catch{alert("Could not access microphone. Please check your browser settings and allow microphone access for this site.")}else alert("Could not access microphone: "+Y)}},[J,pe,x]),ue=o.useCallback(()=>{v?pe():ve()},[v,pe,ve]),ce=d.filter(O=>!O.error&&O.base64),me=r||a.trim().length===0&&ce.length===0;return n.jsxs("div",{className:"mx-auto w-full max-w-[var(--opencami-chat-width)] px-2 md:px-5 relative pb-1 md:pb-3",ref:s,onDragOver:_,onDragLeave:U,onDrop:F,children:[g&&n.jsx("div",{className:"pointer-events-none absolute inset-2 z-20 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary-400 bg-primary-50/90 text-sm font-medium text-primary-700",children:"Drop image here"}),n.jsxs(Ma,{value:a,onValueChange:ee,onSubmit:Q,isLoading:t,disabled:r,children:[n.jsx(Za,{attachments:d,onRemove:I}),L&&E.length>0&&n.jsx(tl,{commands:E,selectedIndex:Math.min(h,E.length-1),onSelect:q}),n.jsx(Aa,{placeholder:"Type a message…",inputRef:H,onKeyDown:V}),n.jsxs(Ia,{className:"justify-between px-3",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(La,{onModelChange:u}),n.jsx(rl,{}),n.jsx(za,{onSelect:re}),n.jsx($a,{onCommandSelect:O=>ee(O+" ")})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(qa,{onFileSelect:S,disabled:r}),n.jsx(Yn,{tooltip:v?"Stop recording":"Voice input",children:n.jsx(he,{onClick:ue,disabled:r||K,size:"icon-sm",variant:v?"destructive":"ghost",className:`rounded-full ${v?"animate-pulse":""}`,"aria-label":v?"Stop recording":"Voice input",children:K?n.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):v?n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"size-2 rounded-full bg-red-500"}),n.jsxs("span",{className:"text-xs tabular-nums",children:[Math.floor(P/60),":",String(P%60).padStart(2,"0")]}),n.jsx(B,{icon:Zn,size:14,strokeWidth:2})]}):n.jsx(B,{icon:ys,size:18,strokeWidth:2})})}),n.jsx(Yn,{tooltip:"Send message",children:n.jsx(he,{onClick:Q,disabled:me,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:n.jsx(B,{icon:ws,size:18,strokeWidth:2})})})]})]})]})]})}const ol=o.memo(sl);function il({title:e,description:t,detail:r,actionLabel:s,onAction:i,className:a}){return n.jsx("div",{className:M("w-full max-w-[var(--opencami-chat-width)]",a),children:n.jsx(jr,{children:n.jsxs("div",{className:"w-full rounded-xl border border-primary-200 bg-primary-50 p-4 text-primary-900",children:[n.jsx("div",{className:"text-balance font-medium",children:e}),n.jsx("div",{className:"mt-2 text-pretty text-primary-700",children:t}),r?n.jsx("div",{className:"mt-2 text-xs text-primary-600",children:r}):null,s&&i?n.jsx("div",{className:"mt-3",children:n.jsx(he,{size:"sm",variant:"outline",onClick:i,children:s})}):null]})})})}function al({state:e,error:t,onRetry:r,className:s}){const i=e==="checking",a=i?"Checking gateway connection...":"OpenClaw gateway is unreachable",l=i?"This dashboard needs access to the OpenClaw gateway configured by your server environment variables.":"";return n.jsx(il,{title:a,description:i?l:n.jsxs(n.Fragment,{children:["We could not reach the gateway from the dashboard server. Start the gateway and confirm your server environment has"," ",n.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_URL"})," plus"," ",n.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_TOKEN"})," (or"," ",n.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_PASSWORD"}),")."]}),detail:i?null:t,actionLabel:i?void 0:"Retry",onAction:i?void 0:r,className:s})}function ll(){const e=o.useRef(null),t=o.useRef(null),r=o.useRef(null),[s,i]=o.useState(0),[a,l]=o.useState(0);return o.useLayoutEffect(()=>{const c=e.current,u=t.current,d=r.current;if(!d)return;const f=()=>{const m=c?.offsetHeight??0,p=u?.offsetHeight??0,w=d.clientHeight;d.style.setProperty("--chat-header-height",`${Math.max(0,m)}px`),d.style.setProperty("--chat-composer-height",`${Math.max(0,p)}px`),l(m),i(Math.max(0,w-m-p))};f();const h=new ResizeObserver(()=>f());return c&&h.observe(c),u&&h.observe(u),()=>h.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:r,pinGroupMinHeight:s,headerHeight:a}}function cl({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:r,isNewChat:s,isRedirecting:i,activeExists:a,sessionsReady:l,queryClient:c}){const u=r||t||e,d=oe.history(e,u),f=Rt({queryKey:d,queryFn:async function(){const y=c.getQueryData(d),P=Array.isArray(y?.messages)?y.messages.filter(N=>N.status==="sending"||N.__optimisticId?!0:!!N.clientId):[],A=await ro({sessionKey:u,friendlyId:e});if(!P.length)return A;const K=ul(A.messages,P);return{...A,messages:K}},enabled:!s&&!!e&&!i&&(!l||a),placeholderData:function(){return c.getQueryData(d)},gcTime:1e3*60*10}),h=o.useRef(""),m=o.useRef([]),p=o.useMemo(()=>{const v=Array.isArray(f.data?.messages)?f.data.messages:[],y=v[v.length-1],P=y&&typeof y.id=="string"?y.id:"",A=`${v.length}:${y?.role??""}:${P}:${Te(y??{content:[]}).slice(-32)}`;return A===h.current?m.current:(h.current=A,m.current=v,v)},[f.data?.messages]),w=f.error instanceof Error?f.error.message:null,g=o.useMemo(()=>{if(r)return r;const v=f.data?.sessionKey;return typeof v=="string"&&v.trim().length>0?v.trim():t},[t,r,f.data?.sessionKey]);return{historyQuery:f,historyMessages:p,displayMessages:p,historyError:w,resolvedSessionKey:g,activeCanonicalKey:s?"new":g||e,sessionKeyForHistory:u}}function ul(e,t){if(!t.length)return e;const r=[...e];for(const s of t)e.some(a=>{if(s.clientId&&a.clientId&&s.clientId===a.clientId||s.__optimisticId&&a.__optimisticId&&s.__optimisticId===a.__optimisticId)return!0;if(s.role&&a.role&&s.role!==a.role)return!1;const l=Te(s);if(!l||l!==Te(a))return!1;const c=rn(s),u=rn(a);return Math.abs(c-u)<=1e4})||r.push(s);return r}function dl(e){const[t,r]=o.useState(!1);return o.useLayoutEffect(()=>{const s=window.matchMedia("(max-width: 768px)"),i=()=>r(s.matches);return i(),s.addEventListener("change",i),()=>s.removeEventListener("change",i)},[]),o.useLayoutEffect(()=>{t&&Ue(e,function(i){return{...i,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function fl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}){const s=Rt({queryKey:oe.sessions,queryFn:no,refetchInterval:3e4}),i=o.useMemo(()=>{const h=s.data??[];return ki(h)},[s.data]),a=o.useMemo(()=>i.find(h=>h.friendlyId===e),[i,e]),l=o.useMemo(()=>t||r||vr(e)?!0:i.some(h=>h.friendlyId===e),[e,r,t,i]),c=a?.key??"",u=o.useMemo(()=>a?a.label||a.title||a.derivedTitle||a.friendlyId:e,[e,a]),d=s.error instanceof Error?s.error.message:null,f=o.useMemo(()=>({totalTokens:a?.totalTokens,contextTokens:a?.contextTokens}),[a?.totalTokens,a?.contextTokens]);return{sessionsQuery:s,sessions:i,activeSession:a,activeExists:l,activeSessionKey:c,activeTitle:u,activeTokens:f,sessionsError:d}}function ml(){const e=Qe(d=>d.settings),[t,r]=o.useState(!1),[s,i]=o.useState(null),[a,l]=o.useState(null),c=o.useRef(null);return{generateTitle:o.useCallback(async d=>{c.current&&c.current.abort();const f=new AbortController;c.current=f,r(!0);try{const h={"Content-Type":"application/json",...Nr()},m=await fetch("/api/llm-features",{method:"POST",headers:h,body:JSON.stringify({action:"title",message:d}),signal:f.signal});if(!m.ok)throw new Error(`API error: ${m.status}`);const p=await m.json();if(f.signal.aborted)throw new Error("Aborted");const w=p.title||d.slice(0,50),g=w.length>64?w.slice(0,61)+"...":w,k=p.source||"heuristic";return i(g),l(k),{title:g,source:k,error:p.error}}catch(h){if(h instanceof Error&&h.name==="AbortError")throw h;const m=hl(d);return i(m),l("heuristic"),{title:m,source:"heuristic",error:h instanceof Error?h.message:"Unknown error"}}finally{r(!1),c.current===f&&(c.current=null)}},[e.llmApiKey,e.llmBaseUrl,e.llmModel,e.llmProvider]),isGenerating:t,lastTitle:s,lastSource:a}}function hl(e){let t=e.replace(/```[\s\S]*?```/g," ");t=t.replace(/`[^`]+`/g," "),t=t.replace(/https?:\/\/[^\s]+/g," "),t=t.replace(/[^\w\s.,!?'-]/g," "),t=t.replace(/\s+/g," ").trim();let i=t.split(/\s+/).filter(a=>{if(a.length<=2){const l=a.toUpperCase();return["AI","ML","UI","UX","API","CSS","JS"].includes(l)}return!0}).slice(0,6).join(" ");return i=i.replace(/[.,!?]+$/,""),i.length>60&&(i=i.slice(0,57)+"..."),i||e.slice(0,50)}function pl(){return Qe(e=>e.settings.useLlmTitles)}const Zt={active:!1,text:"",tools:[],sessionKey:null};function gl(e){const[t,r]=o.useState(Zt),s=o.useRef(null),i=o.useRef(e.onDone),a=o.useRef(e.onError),l=o.useRef(e.onAssistantDelta);i.current=e.onDone,a.current=e.onError,l.current=e.onAssistantDelta;const c=o.useCallback(d=>{if(s.current&&(s.current.close(),s.current=null),d?.preserveState){r(f=>({...f,active:!1}));return}r(Zt)},[]),u=o.useCallback(d=>{s.current&&(s.current.close(),s.current=null),r({active:!0,text:"",tools:[],sessionKey:d});const f=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(d)}`);s.current=f,f.addEventListener("delta",h=>{try{const m=JSON.parse(h.data);r(p=>({...p,text:p.text+m.text})),l.current?.({text:m.text,sessionKey:m.sessionKey})}catch{}}),f.addEventListener("tool",h=>{try{const m=JSON.parse(h.data);r(p=>{const w=p.tools.findIndex(k=>k.id===m.id),g=[...p.tools];return w>=0?g[w]={name:m.name,status:m.status,id:m.id}:g.push({name:m.name,status:m.status,id:m.id}),{...p,tools:g}})}catch{}}),f.addEventListener("done",h=>{try{const m=JSON.parse(h.data);f.close(),s.current=null,r(p=>({...p,active:!1})),i.current(m.sessionKey)}catch{}}),f.onerror=()=>{f.readyState===EventSource.CLOSED&&(f.close(),s.current=null,r(Zt),a.current?.("Stream connection lost"))}},[]);return{streaming:t,startStream:u,stopStream:c}}function xl(e){const t=o.useCallback(r=>{const s=r.target,i=s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable;if(r.key==="Escape"){e.onEscape?.();return}if(r.key==="?"&&!i&&!r.metaKey&&!r.ctrlKey){r.preventDefault(),e.onShowHelp?.();return}if(i)return;const l=navigator.platform.toUpperCase().indexOf("MAC")>=0?r.metaKey:r.ctrlKey;if(l&&r.key==="k"&&!r.shiftKey){r.preventDefault(),e.onNewChat?.();return}if(l&&r.key==="/"){r.preventDefault(),e.onFocusInput?.();return}if(l&&r.shiftKey&&r.key==="C"){r.preventDefault(),e.onCopyLastResponse?.();return}if(l&&r.key==="f"&&!r.shiftKey){r.preventDefault(),e.onSearch?.();return}if(l&&r.shiftKey&&r.key==="F"){r.preventDefault(),e.onSearchGlobal?.();return}},[e]);o.useEffect(()=>(window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}),[t])}function Gn(e){const{threshold:t=50,edgeWidth:r,onMove:s,onSwipe:i,onCancel:a,direction:l,enabled:c=!0}=e,u=o.useRef({startX:0,startY:0,tracking:!1,directionLocked:!1}),d=o.useCallback(m=>{if(!c)return;const p=m.touches[0];p&&(r!==void 0&&p.clientX>r||(u.current={startX:p.clientX,startY:p.clientY,tracking:!0,directionLocked:!1}))},[c,r]),f=o.useCallback(m=>{const p=u.current;if(!p.tracking)return;const w=m.touches[0];if(!w)return;const g=w.clientX-p.startX,k=w.clientY-p.startY,v=Math.abs(g),y=Math.abs(k);if(!p.directionLocked){if(v<5&&y<5)return;if(y>v){p.tracking=!1,a?.();return}p.directionLocked=!0}l==="left"&&g>0||l==="right"&&g<0||(m.preventDefault(),s?.(g))},[l,s,a]),h=o.useCallback(m=>{const p=u.current;if(!p.tracking)return;p.tracking=!1;const w=m.changedTouches[0];if(!w){a?.();return}const g=w.clientX-p.startX,k=Math.abs(g);if(!p.directionLocked||k<t){a?.();return}const v=g>0?"right":"left";if(l&&v!==l){a?.();return}i(v)},[l,a,i,t]);return{onTouchStart:d,onTouchMove:f,onTouchEnd:h}}const Or="opencami-browser-notifications-enabled",en="opencami-browser-notifications-permission-asked",yl=5e3;function kt(){return typeof window<"u"&&"Notification"in window}function qn(){if(typeof window>"u")return!1;try{return localStorage.getItem(Or)==="true"}catch{return!1}}function wl(){const e=un(),t=o.useRef(0),[r,s]=o.useState(()=>qn()),i=o.useCallback(async()=>{if(!kt())return"denied";try{return await Notification.requestPermission()}catch{return"denied"}},[]),a=o.useCallback(async c=>{s(c);try{localStorage.setItem(Or,String(c))}catch{}if(c&&kt()&&Notification.permission==="default"){await i();try{localStorage.setItem(en,"true")}catch{}}},[i]),l=o.useCallback(c=>{if(!r||!kt()||document.hidden!==!0||Notification.permission!=="granted")return;const u=Date.now();if(u-t.current<yl)return;t.current=u;const d=c.text.slice(0,100),f=new Notification("OpenCami",{body:d,icon:"/pwa-192x192.png"});f.onclick=()=>{window.focus(),e({to:"/chat/$sessionKey",params:{sessionKey:c.sessionFriendlyId}}),f.close()}},[r,e]);return o.useEffect(()=>{if(!kt())return;const c=()=>{if(Notification.permission!=="default")return;let d=!1;try{d=localStorage.getItem(en)==="true"}catch{d=!1}d||i().finally(()=>{try{localStorage.setItem(en,"true")}catch{}})},u={once:!0,passive:!0};return window.addEventListener("pointerdown",c,u),window.addEventListener("keydown",c,{once:!0}),()=>{window.removeEventListener("pointerdown",c),window.removeEventListener("keydown",c)}},[i]),o.useEffect(()=>{const c=()=>s(qn());return window.addEventListener("storage",c),()=>window.removeEventListener("storage",c)},[]),{notificationsEnabled:r,setNotificationsEnabled:a,requestNotificationPermission:i,maybeNotifyAssistantMessage:l}}const bl=o.lazy(()=>_t(()=>import("./keyboard-shortcuts-dialog-BTGWdJMl.js"),__vite__mapDeps([25,1,3,2,4,5,6,7,8,9])).then(e=>({default:e.KeyboardShortcutsDialog}))),Sl=o.lazy(()=>_t(()=>import("./search-dialog-B96zx_ng.js"),__vite__mapDeps([26,1,2,3,4,5,6,7,8,9,17,14,11,15,18,13,19,20,21,22,16,23])).then(e=>({default:e.SearchDialog}))),Ct="opencami-search-jump-target";function vl({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:r,forcedSessionKey:s}){const i=un(),a=lt(),[l,c]=o.useState(!1),[u,d]=o.useState(!1),[f,h]=o.useState(null),[m,p]=o.useState(!1),{headerRef:w,composerRef:g,mainRef:k,pinGroupMinHeight:v,headerHeight:y}=ll(),[P,A]=o.useState(()=>qt()||Vt()),[K,N]=o.useState(()=>qt()||Vt()),[$,G]=o.useState(!1),[T,X]=o.useState(!1),[W,C]=o.useState("global"),[L,R]=o.useState(null),[E,H]=o.useState(!1),x=cn(b=>b.level),{maybeNotifyAssistantMessage:D}=wl(),S=o.useRef(null),I=o.useRef(null),_=o.useRef(null),U=o.useRef(""),F=o.useRef(()=>{}),te=o.useRef(!1),ee=o.useRef(""),{isMobile:q}=dl(a),{sessionsQuery:Q,sessions:re,activeExists:V,activeSessionKey:J,activeTitle:pe,activeTokens:ve,sessionsError:ue}=fl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:s}),{historyQuery:ce,historyMessages:me,displayMessages:O,historyError:j,resolvedSessionKey:Y,activeCanonicalKey:ie,sessionKeyForHistory:Z}=cl({activeFriendlyId:e,activeSessionKey:J,forcedSessionKey:s,isNewChat:t,isRedirecting:m,activeExists:V,sessionsReady:Q.isSuccess,queryClient:a}),ae=Rt({queryKey:Jr,queryFn:function(){return Cn(a)},initialData:function(){return Cn(a)},staleTime:1/0}),ge=Rt({queryKey:["gateway","status"],queryFn:so,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:"always"}),Be=o.useRef(Date.now()),de=ge.error instanceof Error?ge.error.message:ge.data&&!ge.data.ok?ge.data.error||"Gateway unavailable":null,je=de??ue??j,Pe=o.useCallback(()=>{ge.refetch()},[ge]),ke=ae.data?.isSidebarCollapsed??!1,ze=Gn({enabled:q&&ke,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{Ue(a,b=>({...b,isSidebarCollapsed:!1}))}}),ct=Gn({enabled:q&&!ke,threshold:50,direction:"left",onSwipe:()=>{Ue(a,b=>({...b,isSidebarCollapsed:!0}))}}),gt=o.useCallback(()=>{h(null),p(!0),i({to:"/new",replace:!0})},[i]),Ge=o.useCallback(()=>{I.current&&(window.clearInterval(I.current),I.current=null),_.current&&(window.clearTimeout(_.current),_.current=null)},[]),Ze=o.useCallback(()=>{Ge(),ht(!1),A(!1),H(!1)},[Ge]),xt=pl(),{generateTitle:et}=ml(),tt=o.useRef(new Set),ut=150,yt=600,wt=o.useCallback(()=>{!e||t||(I.current&&window.clearInterval(I.current),H(!0),I.current=window.setInterval(()=>{F.current()},ut))},[e,t]),dt=o.useRef(()=>{}),bt=o.useRef(()=>{}),{streaming:be,startStream:ne,stopStream:ye}=gl({onDone:b=>dt.current(b),onError:b=>bt.current(b),onAssistantDelta:({text:b})=>{ee.current+=b,D({text:ee.current,sessionFriendlyId:e})}});dt.current=o.useCallback(async b=>{await ce.refetch(),ye({preserveState:!0}),Ze(),a.invalidateQueries({queryKey:oe.sessions})},[ce,a,ye,Ze]),bt.current=o.useCallback(b=>{console.warn("[stream] SSE error, falling back to polling")},[]);const _e=o.useMemo(()=>{if(!be.text)return null;const b=[];for(const z of be.tools)b.push({type:"toolCall",name:z.name,id:z.id});return b.push({type:"text",text:be.text}),{role:"assistant",content:b,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[be.text,be.tools]),ft=o.useMemo(()=>{if(!_e)return O;const b=[...O].map((se,fe)=>({message:se,index:fe})).filter(({message:se})=>se.role==="assistant").map(({index:se})=>se).pop(),z=[...O].map((se,fe)=>({message:se,index:fe})).filter(({message:se})=>se.role==="user").map(({index:se})=>se).pop();if(typeof b=="number"&&(typeof z!="number"||b>z)&&typeof b=="number"){const se=O[b];if(Te(se).length>=be.text.length)return O;const Re=[...O];return Re[b]=_e,Re}return[...O,_e]},[O,_e,be.text]),Dr=o.useMemo(()=>({}),[]);F.current=function(){ce.refetch()},o.useEffect(()=>{if(m){f&&h(null);return}if(nt){f&&h(null);return}if(Q.isSuccess&&!V){f&&h(null);return}const b=ue??j??de;if(!b){f?.startsWith("Failed to load")&&h(null);return}Tn(b)&&i({to:"/connect",replace:!0});const z=ue?`Failed to load sessions. ${ue}`:j?`Failed to load history. ${j}`:de?`Gateway unavailable. ${de}`:null;z&&h(z)},[f,de,j,m,i,ue]);const nt=!t&&!s&&!vr(e)&&Q.isSuccess&&re.length>0&&!re.some(b=>b.friendlyId===e)&&!ce.isFetching&&!ce.isSuccess;o.useEffect(()=>{if(m){if(t){p(!1);return}!nt&&Q.isSuccess&&p(!1)}},[t,m,Q.isSuccess,nt]),o.useEffect(()=>{t||Q.isSuccess&&re.length!==0&&nt&&(Pt(),on(a,e,Z),i({to:"/new",replace:!0}))},[e,ce.isFetching,ce.isSuccess,t,i,a,Z,re,Q.isSuccess,nt]);const yn=nt||m,St=o.useRef("fast");o.useEffect(()=>{const b=me[me.length-1];if(!b||b.role!=="assistant")return;const z=`${me.length}:${Te(b).slice(-64)}`;z!==U.current&&(U.current=z,St.current!=="fast"&&I.current&&(window.clearInterval(I.current),I.current=window.setInterval(()=>{F.current()},ut),St.current="fast"),_.current&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{I.current&&(window.clearInterval(I.current),I.current=window.setInterval(()=>{F.current()},yt),St.current="slow"),_.current=window.setTimeout(()=>{Ze(),St.current="fast"},3e3)},1500))},[me,Ze]),o.useEffect(()=>{if(!xt||t||m)return;const b=s||Y||J;if(!b||tt.current.has(b))return;const z=me.filter(fe=>fe.role==="user"),le=me.filter(fe=>fe.role==="assistant");if(z.length===0||le.length===0||z.length!==1)return;const se=Te(z[0]);!se||se.length<5||(tt.current.add(b),(async()=>{try{const fe=await et(se);fe.title&&await uo(a,b,e,fe.title)}catch(fe){console.error("[smart-title] Error generating title:",fe)}})())},[xt,t,m,s,Y,J,e,me,et,a]),o.useEffect(()=>{if(t||e){if(Ge(),ye(),U.current="",H(!1),te.current){te.current=!1;return}if(qt()||Vt()){A(!0),N(!0);return}A(!1),N(!1)}},[e,t,Ge,ye]),o.useEffect(()=>{if(!(typeof window>"u"))try{const b=sessionStorage.getItem(Ct);if(!b){R(null);return}const z=JSON.parse(b);if(typeof z.at=="number"&&Date.now()-z.at>300*1e3){sessionStorage.removeItem(Ct),R(null);return}if(z.friendlyId===e&&typeof z.messageId=="string"&&z.messageId.length>0){R(z.messageId),sessionStorage.removeItem(Ct);return}R(null)}catch{R(null)}},[e]),o.useLayoutEffect(()=>{if(t)return;const b=bi(s||Y||J,e);if(!b)return;te.current=!0;const z=oe.history(b.friendlyId,b.sessionKey),le=a.getQueryData(z);(Array.isArray(le?.messages)?le.messages:[]).some(Re=>!!(b.optimisticMessage.clientId&&(Re.clientId===b.optimisticMessage.clientId||Re.__optimisticId===b.optimisticMessage.clientId)||b.optimisticMessage.__optimisticId&&Re.__optimisticId===b.optimisticMessage.__optimisticId))||Yt(a,b.friendlyId,b.sessionKey,b.optimisticMessage),A(!0),N(!0),Ft(b.sessionKey,b.friendlyId,b.message,!0,b.attachments)},[e,J,s,t,a,Y]);function Ft(b,z,le,se=!1,fe,Re){let rt="";if(!se){const{clientId:xe,optimisticMessage:mt}=Rn(le,fe);rt=xe,Yt(a,z,b,mt),lo(a,b,z,mt)}ht(!0),c(!0),h(null),A(!0),N(!0);const He=fe?.map(xe=>({mimeType:xe.file.type,content:xe.base64}));ee.current="",ne(b),wt(),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:b,friendlyId:z,message:le,thinking:x,idempotencyKey:crypto.randomUUID(),attachments:He,model:Re||void 0})}).then(async xe=>{if(!xe.ok)throw new Error(await Le(xe))}).catch(xe=>{const mt=xe instanceof Error?xe.message:String(xe);if(Tn(mt)){i({to:"/connect",replace:!0});return}rt&&oo(a,z,b,rt,function(Br){return{...Br,status:"error"}}),h(`Failed to send message. ${mt}`),ht(!1),A(!1),N(!1)}).finally(()=>{c(!1)})}const wn=o.useCallback(async()=>{d(!0);try{const b=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!b.ok)throw new Error(await Le(b));const z=await b.json(),le=typeof z.sessionKey=="string"?z.sessionKey:"",se=typeof z.friendlyId=="string"&&z.friendlyId.trim().length>0?z.friendlyId.trim():nn(le);if(!le||!se)throw new Error("Invalid session response");return a.invalidateQueries({queryKey:oe.sessions}),{sessionKey:le,friendlyId:se}}finally{d(!1)}},[a]),Lr=o.useCallback((b,z)=>{const le=z.attachments;if(b.length===0&&(!le||le.length===0))return;if(z.reset(),t){const{clientId:fe,optimisticId:Re,optimisticMessage:rt}=Rn(b,le);Yt(a,"new","new",rt),ht(!0),c(!0),A(!0),N(!0),wn().then(({sessionKey:He,friendlyId:xe})=>{if(wi(xe),xi({sessionKey:He,friendlyId:xe,message:b,optimisticMessage:rt,attachments:le}),r){r({sessionKey:He,friendlyId:xe});return}i({to:"/chat/$sessionKey",params:{sessionKey:xe},replace:!0})}).catch(He=>{io(a,"new","new",fe,Re),z.setValue(b),h(`Failed to create session. ${He instanceof Error?He.message:String(He)}`),ht(!1),A(!1),N(!1),c(!1)});return}Ft(s||Y||J,e,b,!1,le,z.model)},[e,J,wn,s,t,i,r,a,Y]),bn=o.useCallback(()=>{A(!1),N(!1),on(a,"new","new"),i({to:"/new"}),q&&Ue(a,function(z){return{...z,isSidebarCollapsed:!0}})},[q,i,a]),Pr=o.useCallback(()=>{Ue(a,function(z){return{...z,isSidebarCollapsed:!z.isSidebarCollapsed}})},[a]),_r=o.useCallback(()=>{q&&Ue(a,function(z){return{...z,isSidebarCollapsed:!0}})},[q,a]),Kr=o.useCallback(()=>{Ue(a,function(z){return{...z,isSidebarCollapsed:!1}})},[a]),zr=o.useCallback(b=>{if(t||!b.trim())return;const z=s||Y||J;z&&Ft(z,e,b.trim())},[e,J,s,t,Y]),Hr=o.useCallback(()=>{S.current?.focus()},[]),$r=o.useCallback(()=>{if($){G(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[$]),Ur=o.useCallback(()=>{const b=[...O].reverse().find(le=>le.role==="assistant");if(!b)return;const z=Te(b);z&&navigator.clipboard.writeText(z).catch(()=>{})},[O]),Fr=o.useCallback(()=>{G(!0)},[]),Wr=o.useCallback(()=>{C(t?"global":"current"),X(!0)},[t]),Sn=o.useCallback(()=>{C("global"),X(!0)},[]);xl({onNewChat:bn,onFocusInput:Hr,onEscape:$r,onCopyLastResponse:Ur,onShowHelp:Fr,onSearch:Wr,onSearchGlobal:Sn});const vn=ce.isLoading&&!ce.data||m,jn=!!de&&ge.errorUpdatedAt>Be.current,Yr=!vn&&O.length===0,Xr=o.useMemo(()=>!jn||!je?null:n.jsx(al,{state:"error",error:je,onRetry:Pe}),[je,Pe,jn]),kn=n.jsx(Ii,{sessions:re,activeFriendlyId:e,activeSessionKey:Z,creatingSession:u,onCreateSession:bn,isCollapsed:q?!1:ke,onToggleCollapse:Pr,onSelectSession:_r,onActiveSessionDelete:gt,onOpenSearch:Sn});return n.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[n.jsxs("div",{className:M("h-full overflow-hidden",q?"relative":"grid grid-cols-[auto_minmax(0,1fr)]"),children:[yn?null:q?n.jsxs(n.Fragment,{children:[!ke&&n.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>Ue(a,b=>({...b,isSidebarCollapsed:!0})),...ct}),n.jsx("div",{className:M("fixed inset-y-0 left-0 z-50 w-[var(--opencami-sidebar-width)] transition-transform duration-150 safe-area-top",ke?"-translate-x-full":"translate-x-0"),...ct,children:kn})]}):kn,n.jsxs("main",{className:"flex flex-col h-full min-h-0 min-w-0 overflow-x-hidden",ref:k,...ze,children:[n.jsx(Pi,{activeTitle:pe,wrapperRef:w,showSidebarButton:q,onOpenSidebar:Kr,totalTokens:ve.totalTokens,contextTokens:ve.contextTokens}),yn?null:n.jsxs(n.Fragment,{children:[n.jsx(Ta,{messages:ft,loading:vn,empty:Yr,notice:Xr,noticePosition:"end",waitingForResponse:P,isStreaming:E,sessionKey:ie,pinToTop:K,pinGroupMinHeight:v,headerHeight:y,contentStyle:Dr,onFollowUpClick:zr,jumpToMessageId:L}),n.jsx(ol,{onSubmit:Lr,isLoading:l,disabled:l,wrapperRef:g,inputRef:S})]})]})]}),$&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(bl,{open:$,onOpenChange:G})}),T&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Sl,{open:T,onOpenChange:X,sessions:re,currentFriendlyId:e,currentSessionKey:J,mode:W,onJumpToMessage:b=>{if(X(!1),!!b.friendlyId){if(b.messageId&&b.friendlyId===e){R(b.messageId);return}if(b.messageId&&typeof window<"u")try{sessionStorage.setItem(Ct,JSON.stringify({friendlyId:b.friendlyId,messageId:b.messageId,at:Date.now()}))}catch{}i({to:"/chat/$sessionKey",params:{sessionKey:b.friendlyId}})}}})})]})}function jl(){const e=lt(),t=un(),[r,s]=o.useState(null),i=Vr.useParams(),a=typeof i.sessionKey=="string"?i.sessionKey:"main",l=a==="new",c=r?.friendlyId===a?r.sessionKey:void 0,u=o.useCallback(function(f){ao(e,"new","new",f.friendlyId,f.sessionKey),s({friendlyId:f.friendlyId,sessionKey:f.sessionKey}),t({to:"/chat/$sessionKey",params:{sessionKey:f.friendlyId},replace:!0})},[t,e]);return n.jsx(vl,{activeFriendlyId:a,isNewChat:l,forcedSessionKey:c,onSessionResolved:l?u:void 0})}const Yl=Object.freeze(Object.defineProperty({__proto__:null,component:jl},Symbol.toStringTag,{value:"Module"}));export{Yl as $,oe as c,kr as g,Wl as u};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/agents-screen-DwIY8hze.js","assets/main-B_dlfHME.js","assets/visuallyHidden-ONmQ-0U2.js","assets/button-Dg7VFQQn.js","assets/switch-DPocNFRG.js","assets/useControlled-Dscz_s4f.js","assets/useButton-Cbl_9oFG.js","assets/tooltip-Dg9fy-vT.js","assets/popupStateMapping-BRPDXnjv.js","assets/owner-CpRnf1fI.js","assets/DirectionContext-BdX86BHP.js","assets/opencami-logo-BQQETnJG.js","assets/proxy-BcUh9kMA.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e,r as t,_ as r}from"./main-B_dlfHME.js";const n=t.lazy(()=>r(()=>import("./agents-screen-DwIY8hze.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(s=>({default:s.AgentsScreen})));function o(){return e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"flex h-screen items-center justify-center text-primary-500 text-sm",children:"Loading…"}),children:e.jsx(n,{})})}export{o as component};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as L,r as t,j as e,L as M}from"./main-B_dlfHME.js";import{u as q}from"./visuallyHidden-ONmQ-0U2.js";import{c as B,b as O,B as f,H as p,I as Q,r as K,w as R,h as I,U as V,a as H,V as G,q as J}from"./button-Dg7VFQQn.js";import{S as _}from"./switch-DPocNFRG.js";import{s as X,T as Y,a as Z,b as $,c as ee,d as se,g as P}from"./tooltip-Dg9fy-vT.js";import{O as re,a as ae}from"./opencami-logo-BQQETnJG.js";import{m as S,A as W}from"./proxy-BcUh9kMA.js";import"./useControlled-Dscz_s4f.js";import"./useButton-Cbl_9oFG.js";import"./popupStateMapping-BRPDXnjv.js";import"./owner-CpRnf1fI.js";import"./DirectionContext-BdX86BHP.js";async function te(){const s=await fetch("/api/agents");if(!s.ok)throw new Error("Failed to fetch agents");return(await s.json()).agents??[]}async function E(s){return await(await fetch("/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})).json()}function ie({agent:s,onEdit:d,onDelete:n}){const c=s.isDefault||s.id==="main",l=s.name||s.id.charAt(0).toUpperCase()+s.id.slice(1),m=s.model?s.model.split("/").pop():void 0;return e.jsx("div",{className:"group rounded-lg border border-primary-100 bg-surface p-4 transition-all duration-150 ease-out hover:border-primary-200 hover:shadow-sm",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"relative flex size-12 shrink-0 items-center justify-center rounded-lg bg-primary-50 text-xl",children:[s.emoji||"🤖",c&&e.jsx("span",{className:"absolute -top-1 -right-1 size-3 rounded-full bg-emerald-500 ring-2 ring-surface"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("h4",{className:"text-[13px] font-semibold text-primary-900 leading-tight truncate",children:l}),l!==s.id&&e.jsx("span",{className:"text-[10px] font-mono text-primary-400 shrink-0",children:s.id})]}),c&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-emerald-50 text-emerald-600 border border-emerald-100 shrink-0",children:"Primary"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-3",children:[m&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-mono rounded-full bg-primary-50 text-primary-600 border border-primary-100 truncate max-w-[200px]",children:m}),s.sandbox!==void 0&&e.jsx("span",{className:B("inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full border",s.sandbox?"bg-amber-50 text-amber-600 border-amber-100":"bg-primary-50 text-primary-500 border-primary-100"),children:s.sandbox?"🔒 Sandbox":"🔓 Open"}),s.sessionScope&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full bg-primary-50 text-primary-500 border border-primary-100",children:s.sessionScope==="per-sender"?"👤 Per-sender":"🌐 Global"})]}),s.tools&&s.tools.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mb-2",children:[s.tools.slice(0,6).map(i=>e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 text-[10px] font-mono rounded bg-sky-50 text-sky-600 border border-sky-100",children:i},i)),s.tools.length>6&&e.jsxs("span",{className:"text-[10px] text-primary-400",children:["+",s.tools.length-6," more"]})]}),s.channelBindings&&s.channelBindings.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:s.channelBindings.map(i=>e.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 text-[10px] rounded bg-violet-50 text-violet-600 border border-violet-100",children:["#",i]},i))}),e.jsxs("div",{className:"flex items-center gap-3 pt-2 border-t border-primary-50",children:[s.workspace&&e.jsx("span",{className:"text-[11px] font-mono text-primary-400 truncate",title:s.workspace,children:s.workspace}),s.activeSessions!==void 0&&s.activeSessions>0&&e.jsxs("span",{className:"text-[11px] text-primary-400",children:[s.activeSessions," active session",s.activeSessions!==1?"s":""]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity duration-150",children:[e.jsx(f,{size:"icon-sm",variant:"ghost",onClick:d,"aria-label":"Edit agent",children:e.jsx(p,{icon:V,size:16,strokeWidth:1.5})}),!c&&e.jsx(f,{size:"icon-sm",variant:"ghost",onClick:n,"aria-label":"Delete agent",className:"text-red-500 hover:text-red-600",children:e.jsx(p,{icon:H,size:16,strokeWidth:1.5})})]})]})})}function D({label:s,placeholder:d,values:n,onChange:c}){const[l,m]=t.useState(""),i=o=>{(o.key==="Enter"||o.key===",")&&l.trim()&&(o.preventDefault(),n.includes(l.trim())||c([...n,l.trim()]),m("")),o.key==="Backspace"&&!l&&n.length>0&&c(n.slice(0,-1))};return e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:s}),e.jsxs("div",{className:"flex flex-wrap gap-1 p-2 rounded-md border border-primary-200 bg-surface min-h-[36px]",children:[n.map(o=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-primary-100 px-2 py-0.5 text-xs text-primary-700",children:[o,e.jsx("button",{onClick:()=>c(n.filter(x=>x!==o)),className:"text-primary-400 hover:text-primary-600",children:"×"})]},o)),e.jsx("input",{value:l,onChange:o=>m(o.target.value),onKeyDown:i,placeholder:n.length===0?d:"",className:"flex-1 min-w-[80px] bg-transparent text-sm outline-none"})]})]})}function F({agent:s,onSave:d,onCancel:n,saving:c}){const[l,m]=t.useState(s?.name??""),[i,o]=t.useState(s?.workspace??""),[x,g]=t.useState(s?.emoji??""),[u,v]=t.useState(s?.avatar??""),[b,N]=t.useState(s?.model??""),[w,U]=t.useState(s?.sandbox??!1),[h,z]=t.useState(s?.tools??[]),[j,y]=t.useState(s?.deniedTools??[]),[k,A]=t.useState(s?.channelBindings??[]),[C,T]=t.useState(s?.sessionScope??"per-sender"),r=!!s;return e.jsxs("div",{className:"max-w-2xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-primary-900",children:r?"Edit Agent":"Create Agent"}),e.jsx(f,{size:"icon-sm",variant:"ghost",onClick:n,children:e.jsx(p,{icon:G,size:18,strokeWidth:1.5})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border border-primary-100 bg-surface p-4",children:[e.jsx("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3",children:"Basic Info"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"col-span-2 sm:col-span-1",children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:"Name"}),e.jsx("input",{value:l,onChange:a=>m(a.target.value),placeholder:"my-agent",className:"w-full rounded-md border border-primary-200 bg-surface px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:"Emoji"}),e.jsx("input",{value:x,onChange:a=>g(a.target.value),placeholder:"🤖",className:"w-full rounded-md border border-primary-200 bg-surface px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:"Avatar URL"}),e.jsx("input",{value:u,onChange:a=>v(a.target.value),placeholder:"https://...",className:"w-full rounded-md border border-primary-200 bg-surface px-3 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary-500"})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-primary-100 bg-surface p-4",children:[e.jsx("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3",children:"Model & Config"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:"Model"}),e.jsx("input",{value:b,onChange:a=>N(a.target.value),placeholder:"anthropic/claude-sonnet-4-20250514",className:"w-full rounded-md border border-primary-200 bg-surface px-3 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:"Workspace Path"}),e.jsx("input",{value:i,onChange:a=>o(a.target.value),placeholder:"/root/.openclaw/workspace-myagent",className:"w-full rounded-md border border-primary-200 bg-surface px-3 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-primary-800",children:"Sandbox Mode"}),e.jsx("div",{className:"text-xs text-primary-500",children:"Run agent in isolated sandbox"})]}),e.jsx(_,{checked:w,onCheckedChange:U})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-primary-600 mb-1",children:"Session Scope"}),e.jsxs("select",{value:C,onChange:a=>T(a.target.value),className:"w-full rounded-md border border-primary-200 bg-surface px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500",children:[e.jsx("option",{value:"per-sender",children:"Per-sender"}),e.jsx("option",{value:"global",children:"Global"})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-primary-100 bg-surface p-4",children:[e.jsx("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3",children:"Tools"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(D,{label:"Allowed Tools",placeholder:"Type tool name and press Enter",values:h,onChange:z}),e.jsx(D,{label:"Denied Tools",placeholder:"Type tool name and press Enter",values:j,onChange:y})]})]}),e.jsxs("div",{className:"rounded-lg border border-primary-100 bg-surface p-4",children:[e.jsx("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3",children:"Channel Bindings"}),e.jsx(D,{label:"Bound Channels",placeholder:"Type channel name and press Enter",values:k,onChange:A})]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(f,{size:"sm",variant:"outline",onClick:n,children:"Cancel"}),e.jsx(f,{size:"sm",onClick:()=>d({name:l,workspace:i,emoji:x,model:b,avatar:u,sandbox:w,tools:h,deniedTools:j,channelBindings:k,sessionScope:C}),disabled:!l.trim()||c,children:c?e.jsx(p,{icon:I,size:16,className:"animate-spin"}):r?"Save Changes":"Create Agent"})]})]})}function ne({agent:s,onConfirm:d,onCancel:n,deleting:c}){const[l,m]=t.useState(!1);return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:n,children:e.jsxs("div",{className:"w-[min(380px,90vw)] rounded-xl border border-primary-200 bg-surface p-5 shadow-xl",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(p,{icon:J,size:20,className:"text-red-500"}),e.jsx("h3",{className:"text-sm font-medium text-primary-900",children:"Delete Agent"})]}),e.jsxs("p",{className:"text-sm text-primary-600 mb-4",children:["Are you sure you want to delete ",e.jsx("strong",{children:s.name}),"? This cannot be undone."]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-primary-700 mb-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:i=>m(i.target.checked),className:"rounded border-primary-300"}),"Also delete workspace files"]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(f,{size:"sm",variant:"outline",onClick:n,children:"Cancel"}),e.jsx(f,{size:"sm",onClick:()=>d(l),disabled:c,className:"bg-red-600 text-white hover:bg-red-700",children:c?e.jsx(p,{icon:I,size:16,className:"animate-spin"}):"Delete"})]})]})})}function ye(){const s=L(),[d,n]=t.useState([]),[c,l]=t.useState(!0),[m,i]=t.useState(null),[o,x]=t.useState(!1),[g,u]=t.useState("list"),[v,b]=t.useState(null),[N,w]=t.useState(null),h=q({queryKey:se,queryFn:function(){return P(s)},initialData:function(){return P(s)},staleTime:1/0}).data?.isSidebarCollapsed??!1,z=t.useCallback(()=>{X(s,function(a){return{...a,isSidebarCollapsed:!a.isSidebarCollapsed}})},[s]),j=t.useMemo(()=>({duration:.15,ease:h?"easeIn":"easeOut"}),[h]),y=t.useCallback(async()=>{try{i(null);const r=await te();n(r)}catch(r){i(r instanceof Error?r.message:"Failed to load agents")}finally{l(!1)}},[]);t.useEffect(()=>{y()},[y]);const k=async r=>{x(!0);try{const a=await E({action:"create",name:r.name,workspace:r.workspace||void 0,emoji:r.emoji||void 0,avatar:r.avatar||void 0});if(a.error){i(a.error);return}u("list"),await y()}finally{x(!1)}},A=async r=>{if(v){x(!0);try{const a=await E({action:"update",agentId:v.id,name:r.name||void 0,workspace:r.workspace||void 0,model:r.model||void 0,avatar:r.avatar||void 0});if(a.error){i(a.error);return}b(null),u("list"),await y()}finally{x(!1)}}},C=async r=>{if(N){x(!0);try{const a=await E({action:"delete",agentId:N.id,deleteFiles:r});if(a.error){i(a.error);return}w(null),await y()}finally{x(!1)}}},T=e.jsxs(S.aside,{initial:!1,animate:{width:h?48:300},transition:j,className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col",children:[e.jsxs(S.div,{layout:!0,transition:{layout:j},className:"flex items-center h-12 px-2 justify-between",children:[e.jsx(W,{initial:!1,children:h?null:e.jsx(S.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:j,children:e.jsxs(M,{to:"/new",className:B(O({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[e.jsx(re,{className:"size-5"}),e.jsx(ae,{})]})})}),e.jsx(Y,{children:e.jsxs(Z,{children:[e.jsx($,{onClick:z,render:e.jsx(f,{size:"icon-sm",variant:"ghost",children:e.jsx(p,{icon:Q,size:20,strokeWidth:1.5})})}),e.jsx(ee,{side:"right",children:h?"Open Sidebar":"Close Sidebar"})]})})]}),e.jsx("div",{className:"px-2 mb-4",children:e.jsxs(M,{to:"/",className:B(O({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[e.jsx(p,{icon:K,size:20,strokeWidth:1.5,className:"min-w-5"}),e.jsx(W,{initial:!1,mode:"wait",children:!h&&e.jsx(S.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:j,className:"overflow-hidden whitespace-nowrap",children:"Back to Chat"})})]})})]});return e.jsx("div",{className:"h-screen bg-surface text-primary-900",children:e.jsxs("div",{className:"h-full overflow-hidden grid grid-cols-[auto_1fr]",children:[T,e.jsxs("main",{"aria-label":"Agent manager",className:"flex flex-col h-full min-h-0",children:[e.jsx("header",{className:"border-b border-primary-200 px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-primary-900",children:"Agents"}),e.jsxs("p",{className:"text-xs text-primary-500 mt-0.5",children:[d.length," agent",d.length!==1?"s":""," configured"]})]}),g==="list"&&e.jsxs(f,{size:"sm",onClick:()=>{b(null),u("create")},children:[e.jsx(p,{icon:R,size:16,strokeWidth:1.5}),e.jsx("span",{className:"ml-1",children:"Create Agent"})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto p-6",children:[m&&e.jsx("div",{className:"mb-4 rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 p-3 text-sm text-red-600 dark:text-red-400",children:m}),c?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(p,{icon:I,size:24,className:"animate-spin text-primary-400"})}):g==="list"?e.jsxs("div",{className:"max-w-3xl mx-auto space-y-3",children:[d.map(r=>e.jsx(ie,{agent:r,onEdit:()=>{b(r),u("edit")},onDelete:()=>w(r)},r.id)),d.length===0&&e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-lg bg-primary-50 mb-3",children:e.jsx("span",{className:"text-2xl",children:"🤖"})}),e.jsx("p",{className:"text-sm text-primary-500",children:"No agents found"}),e.jsx("p",{className:"text-xs text-primary-400 mt-1",children:"Create one to get started"})]})]}):g==="create"?e.jsx(F,{onSave:k,onCancel:()=>u("list"),saving:o}):g==="edit"&&v?e.jsx(F,{agent:v,onSave:A,onCancel:()=>{b(null),u("list")},saving:o}):null]}),N&&e.jsx(ne,{agent:N,onConfirm:C,onCancel:()=>w(null),deleting:o})]})]})})}export{ye as AgentsScreen};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/bots-screen-c78I920d.js","assets/main-B_dlfHME.js","assets/button-Dg7VFQQn.js","assets/switch-DPocNFRG.js","assets/useControlled-Dscz_s4f.js","assets/useButton-Cbl_9oFG.js","assets/visuallyHidden-ONmQ-0U2.js","assets/useMutation-B1FlDsNN.js","assets/proxy-BcUh9kMA.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e,r as t,_ as r}from"./main-B_dlfHME.js";const n=t.lazy(()=>r(()=>import("./bots-screen-c78I920d.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(s=>({default:s.BotsScreen})));function a(){return e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"flex h-screen items-center justify-center text-sm text-primary-500",children:"Loading…"}),children:e.jsx(n,{})})}export{a as component};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as g,j as e,r as f,L as v}from"./main-B_dlfHME.js";import{H as o,h,c as d,C as x,A as w,B as k,E as C,G as b,r as E}from"./button-Dg7VFQQn.js";import{S}from"./switch-DPocNFRG.js";import{u as j}from"./visuallyHidden-ONmQ-0U2.js";import{u as N}from"./useMutation-B1FlDsNN.js";import{m as M,A}from"./proxy-BcUh9kMA.js";import"./useControlled-Dscz_s4f.js";import"./useButton-Cbl_9oFG.js";const y=["cron-jobs"];function $(){return j({queryKey:y,queryFn:async({signal:r})=>{const t=new AbortController,n=()=>t.abort();r.addEventListener("abort",n);try{const s=await fetch("/api/cron",{signal:t.signal});if(!s.ok)throw new Error("Failed to fetch cron jobs");const i=await s.json();return Array.isArray(i.jobs)?i.jobs:[]}finally{r.removeEventListener("abort",n)}},refetchInterval:3e4})}function D(r){return j({queryKey:["cron-job-runs",r],queryFn:async({signal:t})=>{if(!r)return[];const n=new AbortController,s=()=>n.abort();t.addEventListener("abort",s);try{const i=await fetch(`/api/cron?jobId=${encodeURIComponent(r)}`,{signal:n.signal});if(!i.ok)throw new Error("Failed to fetch cron job runs");const l=await i.json();return Array.isArray(l.runs)?l.runs:[]}finally{t.removeEventListener("abort",s)}},enabled:!!r})}function R(){const r=g();return N({mutationFn:async t=>{const n=new AbortController,s=await fetch("/api/cron",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jobId:t}),signal:n.signal});if(!s.ok)throw new Error("Failed to run cron job");return s.json()},onSuccess:()=>{r.invalidateQueries({queryKey:y})}})}function L(){const r=g();return N({mutationFn:async({jobId:t,enabled:n})=>{const s=new AbortController,i=await fetch("/api/cron",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({jobId:t,patch:{enabled:n}}),signal:s.signal});if(!i.ok)throw new Error("Failed to update cron job");return i.json()},onSuccess:()=>{r.invalidateQueries({queryKey:y})}})}function J(r){return!r||r<=0?"—":r<1e3?`${r}ms`:r<6e4?`${(r/1e3).toFixed(1)}s`:`${(r/6e4).toFixed(1)}m`}function z(r){return r?new Date(r).toLocaleString():"—"}function F({job:r}){const t=D(r.id),n=t.data??[];return e.jsx(M.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsxs("div",{className:"space-y-4 border-t border-primary-100 bg-primary-50/50 px-4 py-4",children:[(r.payload.message||r.payload.prompt)&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Prompt / Message"}),e.jsx("p",{className:"whitespace-pre-wrap break-words rounded-lg bg-surface border border-primary-100 p-3 text-sm text-primary-700 leading-relaxed",children:r.payload.message??r.payload.prompt})]}),r.delivery&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Delivery"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.delivery.mode&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-surface text-primary-600 border border-primary-100",children:["Mode: ",r.delivery.mode]}),r.delivery.channel&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-surface text-primary-600 border border-primary-100",children:["Channel: ",r.delivery.channel]}),r.delivery.to&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-surface text-primary-600 border border-primary-100",children:["To: ",r.delivery.to]})]})]}),r.payload.model&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Model"}),e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-mono rounded-full bg-surface text-primary-600 border border-primary-100",children:r.payload.model})]}),r.state?.lastError&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-red-500 uppercase tracking-wider mb-2",children:"Last Error"}),e.jsx("p",{className:"rounded-lg bg-red-50 border border-red-100 p-3 font-mono text-xs text-red-600 leading-relaxed",children:r.state.lastError})]}),e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Recent Runs"}),t.isLoading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-primary-500",children:[e.jsx(o,{icon:h,size:12,className:"animate-spin"}),"Loading..."]}):n.length===0?e.jsx("p",{className:"text-xs text-primary-400",children:"No run history available"}):e.jsx("div",{className:"space-y-1.5",children:n.slice(0,5).map(s=>e.jsxs("div",{className:"flex items-center gap-3 py-1.5 px-2 rounded-md bg-surface border border-primary-50",children:[e.jsx("span",{className:d("inline-block h-2 w-2 shrink-0 rounded-full",s.status==="ok"?"bg-emerald-500":"bg-red-500")}),e.jsx(o,{icon:x,size:11,strokeWidth:1.5,className:"text-primary-400"}),e.jsx("span",{className:"tabular-nums text-[11px] text-primary-600",children:z(s.ranAt)}),e.jsx("span",{className:"tabular-nums text-[11px] text-primary-400",children:J(s.durationMs)}),s.error&&e.jsx("span",{className:"truncate text-[11px] text-red-500 ml-auto",children:s.error})]},s.id))})]})]})})}function T(r){const t=r.trim().split(/\s+/);if(t.length<5)return r;const[n,s,i,l,c]=t,a=`${s.padStart(2,"0")}:${n.padStart(2,"0")}`;if(i==="*"&&l==="*"&&c==="*")return`Daily at ${a}`;if(i==="*"&&l==="*"&&c!=="*"){const m={0:"Sun",1:"Mon",2:"Tue",3:"Wed",4:"Thu",5:"Fri",6:"Sat",7:"Sun"};return`${c.split(",").map(u=>m[u]??u).join(", ")} at ${a}`}return r}function B(r){const t=r.schedule;return t.kind==="every"&&t.expr?`Every ${t.expr}`:t.kind==="at"&&t.expr?`Once at ${t.expr}`:t.kind==="cron"&&t.expr?T(t.expr):t.expr??"Unknown"}function W(r){if(!r)return"—";const t=Date.now()-r;return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(r).toLocaleDateString()}function q(r){if(!r)return"—";const t=r-Date.now();return t<0?"overdue":t<6e4?"in <1m":t<36e5?`in ${Math.floor(t/6e4)}m`:t<864e5?`in ${Math.floor(t/36e5)}h`:new Date(r).toLocaleDateString()}function K({status:r}){return r==="ok"?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-emerald-50 text-emerald-600 border border-emerald-100",children:"ok"}):r==="error"?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-red-50 text-red-600 border border-red-100",children:"error"}):e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-primary-50 text-primary-400 border border-primary-100",children:"—"})}function O({jobs:r}){const[t,n]=f.useState(null),s=R(),i=L(),l=f.useCallback(a=>{i.mutate({jobId:a.id,enabled:!a.enabled})},[i]),c=f.useCallback(a=>{s.mutate(a)},[s]);return r.length===0?null:e.jsx("div",{className:"space-y-2",children:r.map(a=>{const m=t===a.id,p=s.isPending&&s.variables===a.id;return e.jsxs("div",{className:d("group rounded-lg border border-primary-100 bg-surface transition-all duration-150 ease-out",m?"border-primary-200 shadow-sm":"hover:border-primary-200 hover:shadow-sm"),children:[e.jsxs("button",{type:"button",onClick:()=>n(m?null:a.id),className:d("w-full p-4 text-left","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-300 focus-visible:rounded-lg"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsx("h4",{className:d("text-[13px] font-semibold leading-tight truncate",a.enabled?"text-primary-900":"text-primary-400"),children:a.name??a.id}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[!a.enabled&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-primary-50 text-primary-400 border border-primary-100",children:"Disabled"}),e.jsx(K,{status:a.state?.lastStatus})]})]}),e.jsx("p",{className:"text-xs text-primary-500 leading-relaxed mb-3",children:B(a)}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-primary-50",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-[11px] text-primary-400 flex items-center gap-1",children:[e.jsx(o,{icon:x,size:11,strokeWidth:1.5}),"Last: ",W(a.state?.lastRunAtMs)]}),e.jsxs("span",{className:"text-[11px] text-primary-400 flex items-center gap-1",children:[e.jsx(o,{icon:w,size:11,strokeWidth:1.5}),"Next: ",q(a.state?.nextRunAtMs)]})]}),e.jsxs("div",{className:"flex items-center gap-2",onClick:u=>u.stopPropagation(),children:[e.jsx(S,{checked:a.enabled,onCheckedChange:()=>l(a),"aria-label":`${a.enabled?"Disable":"Enable"} ${a.name??a.id}`,disabled:i.isPending}),e.jsx(k,{variant:"ghost",size:"icon-sm",onClick:()=>c(a.id),disabled:p,"aria-label":`Run ${a.name??a.id} now`,className:"text-primary-500 hover:text-primary-700",children:e.jsx(o,{icon:p?h:C,size:16,strokeWidth:1.5,className:d(p&&"animate-spin")})})]})]})]}),e.jsx(A,{children:m&&e.jsx(F,{job:a})})]},a.id)})})}function P(r){if(!r)return"never";const t=Date.now()-r;return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(r).toLocaleDateString()}function Q(r){for(const t of[" - "," | ",": "," / "]){const n=r.indexOf(t);if(n>0)return r.substring(0,n).trim()}return r}function I(r){const t=new Map;for(const n of r){const s=Q(n.name??n.id),i=t.get(s);i?i.push(n):t.set(s,[n])}return Array.from(t.entries()).map(([n,s])=>({name:n,jobs:s})).sort((n,s)=>n.name.localeCompare(s.name))}function H({bot:r}){const t=r.jobs.reduce((i,l)=>Math.max(i,l.state?.lastRunAtMs??0),0),n=r.jobs.some(i=>i.state?.lastStatus==="error"),s=r.jobs.filter(i=>i.enabled).length;return e.jsxs("div",{className:"group rounded-lg border border-primary-100 bg-surface p-4 transition-all duration-150 ease-out hover:border-primary-200 hover:shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:d("flex items-center justify-center w-10 h-10 rounded-lg",n?"bg-red-50":"bg-primary-50"),children:e.jsx(o,{icon:b,size:20,strokeWidth:1.5,className:n?"text-red-500":"text-primary-500"})}),e.jsx("h4",{className:"text-[13px] font-semibold text-primary-900 leading-tight truncate",children:r.name})]}),n&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-red-50 text-red-600 border border-red-100 shrink-0",children:"Error"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-primary-50",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{className:"text-[11px] text-primary-400 flex items-center gap-1",children:[e.jsx(o,{icon:x,size:11,strokeWidth:1.5}),P(t||void 0)]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full bg-primary-50 text-primary-500 border border-primary-100",children:[r.jobs.length," job",r.jobs.length!==1?"s":""]}),s<r.jobs.length&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full bg-amber-50 text-amber-600 border border-amber-100",children:[r.jobs.length-s," disabled"]})]})]})]})}function re(){const r=$(),t=r.data??[],n=f.useMemo(()=>I(t),[t]);return e.jsxs("div",{className:"flex h-screen flex-col bg-surface text-primary-900",children:[e.jsxs("div",{className:"px-4 pt-4 pb-3 border-b border-primary-100",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(v,{to:"/chat/$sessionKey",params:{sessionKey:"main"},className:"p-1.5 -ml-1.5 rounded-md text-primary-500 hover:text-primary-700 hover:bg-primary-50 transition-colors duration-150","aria-label":"Back to Chat",children:e.jsx(o,{icon:E,size:18,strokeWidth:2})}),e.jsx("h2",{className:"text-base font-semibold text-primary-900",children:"Cron Jobs"})]}),e.jsxs("p",{className:"text-xs text-primary-500",children:[t.length," job",t.length!==1?"s":""," configured"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-4 pb-4 pt-4",children:r.isLoading?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(o,{icon:h,size:18,className:"animate-spin text-primary-300"})}):r.isError?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("p",{className:"text-sm text-red-500",children:r.error instanceof Error?r.error.message:"Failed to load cron jobs"}),e.jsx("button",{onClick:()=>{r.refetch()},className:"mt-2 text-xs font-medium text-primary-500 hover:text-primary-700 transition-colors duration-150",children:"Retry"})]}):t.length===0?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-lg bg-primary-50 mb-3",children:e.jsx(o,{icon:x,size:24,className:"text-primary-400"})}),e.jsx("p",{className:"text-sm text-primary-500",children:"No cron jobs configured"}),e.jsx("p",{className:"text-xs text-primary-400 mt-1",children:"Jobs will appear here once created"})]}):e.jsxs("div",{className:"space-y-6",children:[n.length>0&&e.jsxs("section",{children:[e.jsxs("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3 flex items-center gap-2",children:[e.jsx(o,{icon:b,size:14,strokeWidth:1.5}),"Bots (",n.length,")"]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:n.map(s=>e.jsx(H,{bot:s},s.name))})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3 flex items-center gap-2",children:[e.jsx(o,{icon:x,size:14,strokeWidth:1.5}),"All Jobs (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:e.jsx(O,{jobs:t})})]})]})})]})}export{re as BotsScreen};
|