opencami 1.7.0 → 1.8.2
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 -2
- package/dist/client/assets/{CSPContext-a-MQmQQt.js → CSPContext-DeJH85nm.js} +1 -1
- package/dist/client/assets/{DirectionContext-DRcND-Cm.js → DirectionContext-CxhRpXkm.js} +1 -1
- package/dist/client/assets/_sessionKey-CQE0brGK.js +23 -0
- package/dist/client/assets/agents-CMTFd_sG.js +2 -0
- package/dist/client/assets/agents-screen-BNQGEqcW.js +1 -0
- package/dist/client/assets/bots-B6oGzCxP.js +2 -0
- package/dist/client/assets/bots-screen-Be3cfGgq.js +1 -0
- package/dist/client/assets/button-D9Plv7hu.js +1 -0
- package/dist/client/assets/composite-B2KCZKKL.js +1 -0
- package/dist/client/assets/{connect-BX1MWO82.js → connect-DuJfnyNK.js} +1 -1
- package/dist/client/assets/dashboard-00GpXm5V.js +1 -0
- package/dist/client/assets/event-DD8Cz4O9.js +1 -0
- package/dist/client/assets/file-explorer-screen-CxwemBES.js +1 -0
- package/dist/client/assets/files-DyBJVXBu.js +2 -0
- package/dist/client/assets/{index-BlC2sH55.js → index-DtGzE-ea.js} +1 -1
- package/dist/client/assets/{index-Dg0mbvtv.js → index-Yo5UhdZV.js} +1 -1
- package/dist/client/assets/keyboard-shortcuts-dialog-BZwd-iyV.js +1 -0
- package/dist/client/assets/{main-CEuT8-Qi.js → main-CgwdHc9W.js} +16 -8
- package/dist/client/assets/{markdown-DKD6ZLRJ.js → markdown-DtWnt4NA.js} +1 -1
- package/dist/client/assets/memory-l756yiNq.js +2 -0
- package/dist/client/assets/memory-screen-BQtVRuzE.js +1 -0
- package/dist/client/assets/menu-BsS6CDf_.js +1 -0
- package/dist/client/assets/{opencami-logo-DA69yVKc.js → opencami-logo-Bmge6-FB.js} +1 -1
- package/dist/client/assets/popupStateMapping-D0ZbJR_o.js +1 -0
- package/dist/client/assets/{proxy-Cawf6X0W.js → proxy-CYZeDXoy.js} +1 -1
- package/dist/client/assets/{react-K9goXsVv.js → react-DODKNyyU.js} +1 -1
- package/dist/client/assets/search-dialog-DW91SK30.js +1 -0
- package/dist/client/assets/session-export-dialog-CliO9Ob-.js +1 -0
- package/dist/client/assets/settings-dialog-C1u52aju.js +1 -0
- package/dist/client/assets/skills-8T_avaVb.js +2 -0
- package/dist/client/assets/{skills-panel-DFL-3BRH.js → skills-panel-DSiH-DLs.js} +1 -1
- package/dist/client/assets/styles-DvaLh0o1.css +1 -0
- package/dist/client/assets/switch-DbgQPO6i.js +1 -0
- package/dist/client/assets/tabs-BsAvZnlD.js +1 -0
- package/dist/client/assets/tooltip-DLmutB5C.js +1 -0
- package/dist/client/assets/use-file-explorer-state-Cg_yDYJl.js +12 -0
- package/dist/client/assets/useBaseUiId-KQTzRPLp.js +1 -0
- package/dist/client/assets/useCompositeItem-BPY2_hF_.js +1 -0
- package/dist/client/assets/{useControlled-Cl9XA2_f.js → useControlled-B5pEEz2V.js} +1 -1
- package/dist/client/assets/{useMutation-C5bTdeC1.js → useMutation-BsQD6FKe.js} +1 -1
- package/dist/client/assets/useQuery-CmAJuY2W.js +1 -0
- package/dist/client/assets/visuallyHidden-COI6QeQH.js +1 -0
- package/dist/client/sw.js +5 -164
- package/dist/server/assets/{_sessionKey-BBG3ZUlo.js → _sessionKey-Bq_fl7uv.js} +878 -755
- package/dist/server/assets/_tanstack-start-manifest_v-BMCAWon2.js +4 -0
- package/dist/server/assets/dashboard-GCKodTiJ.js +214 -0
- package/dist/server/assets/{index-BgMPaOsU.js → index-C2hVqxBl.js} +2 -1
- package/dist/server/assets/{router-Bl2uabfY.js → router-bN_iTo0B.js} +485 -189
- package/dist/server/assets/{search-dialog-BtSQW9SR.js → search-dialog-DReM5ZD2.js} +3 -2
- package/dist/server/assets/settings-dialog-BUOrQN3Z.js +1511 -0
- package/dist/server/server.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/_sessionKey-BAmpzUOP.js +0 -23
- package/dist/client/assets/agents-BkeWu_3a.js +0 -2
- package/dist/client/assets/agents-screen-Cb76bcxn.js +0 -1
- package/dist/client/assets/bots-CyJwr-JU.js +0 -2
- package/dist/client/assets/bots-screen-CzNjLsQH.js +0 -1
- package/dist/client/assets/button-DNC5N25i.js +0 -1
- package/dist/client/assets/composite-Bliqcmg4.js +0 -1
- package/dist/client/assets/file-explorer-screen-CpY1O_ag.js +0 -1
- package/dist/client/assets/files-HiN5rXWq.js +0 -2
- package/dist/client/assets/keyboard-shortcuts-dialog-C2Hq19LN.js +0 -1
- package/dist/client/assets/memory-lhzf-8Q4.js +0 -2
- package/dist/client/assets/memory-screen-Zq9qfnJK.js +0 -1
- package/dist/client/assets/menu-47ooFeSm.js +0 -1
- package/dist/client/assets/owner-CFRNz_Tp.js +0 -1
- package/dist/client/assets/popupStateMapping-D5k-jOeY.js +0 -1
- package/dist/client/assets/search-dialog-C5Yae9rb.js +0 -1
- package/dist/client/assets/session-export-dialog-CBeTfbll.js +0 -1
- package/dist/client/assets/settings-dialog-CoeG9M1b.js +0 -1
- package/dist/client/assets/skills-BEkw619A.js +0 -2
- package/dist/client/assets/styles-D4EBtWYc.css +0 -1
- package/dist/client/assets/switch-DAFvLxNX.js +0 -1
- package/dist/client/assets/tabs-B2Y_7MvG.js +0 -1
- package/dist/client/assets/tooltip-D57Pal0B.js +0 -1
- package/dist/client/assets/use-file-explorer-state-DppKEjcl.js +0 -12
- package/dist/client/assets/useButton-DVAfkehQ.js +0 -1
- package/dist/client/assets/useCompositeItem-CzdGhGcj.js +0 -1
- package/dist/client/assets/visuallyHidden-CO3ZD5AQ.js +0 -1
- package/dist/server/assets/_tanstack-start-manifest_v-DmMFarHb.js +0 -4
- package/dist/server/assets/settings-dialog-D3fOAswX.js +0 -1173
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenCami 🦎
|
|
2
2
|
|
|
3
|
-
**Version 1.
|
|
3
|
+
**Version 1.7.0**
|
|
4
4
|
|
|
5
5
|
A beautiful web client for [OpenClaw](https://github.com/openclaw/openclaw).
|
|
6
6
|
|
|
@@ -44,7 +44,9 @@ docker run -p 3000:3000 opencami
|
|
|
44
44
|
|
|
45
45
|
### 💬 Chat & Communication
|
|
46
46
|
- ⚡ **Real-time streaming** — persistent WebSocket + SSE, token-by-token
|
|
47
|
-
-
|
|
47
|
+
- 📎 **File attachments** — upload PDFs, text, code, CSV, JSON via attach button or drag & drop (`/uploads/` + `read` tool workflow)
|
|
48
|
+
- 📄 **File cards** — uploaded files render as clickable cards (filename, icon, size) and open in File Explorer
|
|
49
|
+
- 🖼️ **Image attachments** — drag & drop with compression (images stay Base64 for vision)
|
|
48
50
|
- 🔊 **Voice playback (TTS)** — ElevenLabs → OpenAI → Edge TTS fallback
|
|
49
51
|
- 🎤 **Voice input (STT)** — ElevenLabs Scribe → OpenAI Whisper → Browser
|
|
50
52
|
- 🔔 **Browser notifications** — background tab alerts when assistant replies
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t}from"./main-
|
|
1
|
+
import{r as t}from"./main-CgwdHc9W.js";const e=t.createContext(void 0),o={disableStyleElements:!1};function s(){return t.useContext(e)??o}export{s as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l}from"./main-
|
|
1
|
+
import{r as l}from"./main-CgwdHc9W.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,23 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-dialog-C1u52aju.js","assets/main-CgwdHc9W.js","assets/react-DODKNyyU.js","assets/button-D9Plv7hu.js","assets/use-file-explorer-state-Cg_yDYJl.js","assets/useBaseUiId-KQTzRPLp.js","assets/event-DD8Cz4O9.js","assets/popupStateMapping-D0ZbJR_o.js","assets/visuallyHidden-COI6QeQH.js","assets/composite-B2KCZKKL.js","assets/switch-DbgQPO6i.js","assets/useControlled-B5pEEz2V.js","assets/tabs-BsAvZnlD.js","assets/useCompositeItem-BPY2_hF_.js","assets/DirectionContext-CxhRpXkm.js","assets/CSPContext-DeJH85nm.js","assets/index-DtGzE-ea.js","assets/useQuery-CmAJuY2W.js","assets/tooltip-DLmutB5C.js","assets/useMutation-BsQD6FKe.js","assets/menu-BsS6CDf_.js","assets/opencami-logo-Bmge6-FB.js","assets/proxy-CYZeDXoy.js","assets/markdown-DtWnt4NA.js","assets/index-T4TOjvD0.js","assets/session-export-dialog-CliO9Ob-.js","assets/keyboard-shortcuts-dialog-BZwd-iyV.js","assets/search-dialog-DW91SK30.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as o,u as ut,j as n,L as He,_ as Kt,d as zt,w as ts,a as ns,z as rs}from"./main-CgwdHc9W.js";import{u as Mt}from"./useQuery-CmAJuY2W.js";import{T as Me,a as Ae,b as Ie,c as De,s as We,d as ss,g as En}from"./tooltip-DLmutB5C.js";import{u as os,c as A,B as xe,ac as fn,ag as Ge,t as is,H as X,J as tr,V as Ut,aj as as,ak as ls,al as cs,a as nr,am as us,C as ds,an as fs,M as mn,b as Ve,I as ms,ao as ps,a3 as hs,s as rn,ap as gs,G as xs,aq as ys,e as rr,L as ws,O as bs,X as pn,x as Ss,h as vs,ar as sr,as as js,Y as hn,p as or,n as ir,at as Yt,au as Tn,av as Ns,aw as ks,ax as Cs}from"./button-D9Plv7hu.js";import{u as ar}from"./useMutation-BsQD6FKe.js";import{j as Es,k as Ts,l as Rs,m as Ms,n as As,o as Is,p as Ds,q as Os,r as Ls,s as lr,D as Ps,a as _s,b as Ks,c as zs,d as Us,u as $s}from"./use-file-explorer-state-Cg_yDYJl.js";import{d as cr,a as Xe,g as ur,t as Fs,u as Oe,f as Hs,n as Ws}from"./useBaseUiId-KQTzRPLp.js";import{u as Xs}from"./useControlled-B5pEEz2V.js";import{_ as Ys,$ as Bs,a0 as Rn,t as dr,u as Gs,G as Ce,e as qs,a as At}from"./popupStateMapping-D0ZbJR_o.js";import{u as Vs,e as Js,q as Qs}from"./event-DD8Cz4O9.js";import{u as Zs}from"./CSPContext-DeJH85nm.js";import{u as fr}from"./DirectionContext-CxhRpXkm.js";import{M as $t,a as Ft,b as Ht,c as Ye}from"./menu-BsS6CDf_.js";import{O as eo,a as to}from"./opencami-logo-Bmge6-FB.js";import{m as be,A as Re}from"./proxy-CYZeDXoy.js";import{M as no}from"./markdown-DtWnt4NA.js";import{u as ro,p as mr}from"./index-DtGzE-ea.js";import{c as pr}from"./react-DODKNyyU.js";function sn(e){if(!e)return"main";const t=e.trim();if(t.length===0)return"main";const r=t.split(":"),a=(r[r.length-1]??"").trim();return a.length>0?a:t}const Mn=/^Conversation info \(untrusted metadata\):\s*```(?:json)?\s*[\s\S]*?```\s*/,An=/^Conversation info \(untrusted metadata\):\s*\{[\s\S]*?\}\s*/,so=/^\[(?:[A-Za-z]{3}\s+)?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s+GMT[+-]?\d+\]\s*/;function hr(e){let t=e;const r=Mn.test(t),s=!r&&An.test(t);return r?t=t.replace(Mn,""):s&&(t=t.replace(An,"")),(r||s)&&(t=t.replace(so,"")),t.trim()}function Le(e){const r=(Array.isArray(e.content)?e.content:[]).map(s=>s.type==="text"?String(s.text??""):"").join("").trim();return hr(r)}function Qe(e){return(Array.isArray(e.content)?e.content:[]).filter(r=>r.type==="toolCall")}function oo(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 on(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=oo(r);if(s)return s}return Date.now()}const io=["agent:main:main","main"];function an(e){return io.includes(e)}const ao=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function lo(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 ao.test(t)?"webchat":"chat"}return"other"}function co(e){return Array.isArray(e)?e.map(t=>{const r=typeof t.key=="string"&&t.key.trim().length>0?t.key.trim():sn(t.friendlyId??t.key),s=typeof t.friendlyId=="string"&&t.friendlyId.trim().length>0?t.friendlyId.trim():sn(r),a=lo(r),i=t,l=typeof i.totalTokens=="number"?i.totalTokens:void 0,c=typeof i.contextTokens=="number"?i.contextTokens:void 0,u=typeof i.status=="string"?i.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:a,status:u,totalTokens:l,contextTokens:c}}):[]}async function Ke(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 uo="Missing gateway auth. Set CLAWDBOT_GATEWAY_TOKEN (recommended) or CLAWDBOT_GATEWAY_PASSWORD in the server environment.";function In(e){return e.includes(uo)}function Dn(e,t){const r=crypto.randomUUID(),s=`opt-${r}`,a=Date.now(),i=[];if(t&&t.length>0)for(const c of t)c.type==="image"&&c.base64&&i.push({type:"image",source:{type:"base64",media_type:c.file.type,data:c.base64}});return e.trim()?i.push({type:"text",text:e}):t&&t.length>0&&i.push({type:"text",text:""}),{clientId:r,optimisticId:s,optimisticMessage:{role:"user",content:i,__optimisticId:s,clientId:r,status:"sending",timestamp:a}}}const ue={sessions:["chat","sessions"],history:function(t,r){return["chat","history",t,r]}};async function fo(){const e=await fetch("/api/sessions");if(!e.ok)throw new Error(await Ke(e));const t=await e.json();return co(t.sessions)}async function mo(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 Ke(r));return await r.json()}async function po(){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 Ke(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 gn(e,t,r,s){const a=ue.history(t,r);e.setQueryData(a,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 Bt(e,t,r,s){gn(e,t,r,function(i){return[...i,s]})}function ho(e,t,r,s,a){const i=`opt-${s}`;gn(e,t,r,function(c){return c.map(u=>u.clientId===s||u.__optimisticId===s||u.__optimisticId===i?a(u):u)})}function go(e,t,r,s,a){gn(e,t,r,function(l){return l.filter(c=>!(c.clientId===s||c.__optimisticId===s||a&&c.__optimisticId===a))})}function ln(e,t,r){const s=ue.history(t,r);e.setQueryData(s,{sessionKey:r,messages:[]})}function xo(e,t,r,s,a){const i=ue.history(t,r),l=ue.history(s,a),c=e.getQueryData(i);if(!c)return;const u=Array.isArray(c.messages)?c.messages:[];e.setQueryData(l,{sessionKey:a,sessionId:c.sessionId,messages:u}),e.removeQueries({queryKey:i,exact:!0})}function yo(e,t,r,s){e.setQueryData(ue.sessions,function(i){return Array.isArray(i)?i.map(l=>l.key!==t&&l.friendlyId!==r?l:{...l,lastMessage:s}):i})}function wo(e,t,r){e.setQueryData(ue.sessions,function(a){return Array.isArray(a)?a.filter(i=>i.key!==t&&i.friendlyId!==r):a}),e.removeQueries({queryKey:["chat","history",r],exact:!1}),t&&t!==r&&e.removeQueries({queryKey:["chat","history",t],exact:!1})}async function bo(e,t,r,s){e.setQueryData(ue.sessions,function(i){return Array.isArray(i)?i.map(l=>l.key===t||l.friendlyId===r?{...l,label:s}:l):i});try{const a=await fetch("/api/sessions",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionKey:t,friendlyId:r,label:s})});if(!a.ok){const i=await Ke(a);console.error("[updateSessionLabel] Failed to persist:",i)}}catch(a){console.error("[updateSessionLabel] Network error:",a)}}function So(){const[e,t]=o.useState(!1),[r,s]=o.useState(!1),[a,i]=o.useState(null),[l,c]=o.useState(null),u=o.useCallback(async()=>{if(t(!0),i(null),!(r||l)){s(!0);try{const g=await fetch("/api/paths");if(!g.ok)throw new Error(await Ke(g));const b=await g.json();c({agentId:String(b.agentId??"main"),stateDir:String(b.stateDir??""),sessionsDir:String(b.sessionsDir??""),storePath:String(b.storePath??"")})}catch(g){i(g instanceof Error?g.message:String(g))}finally{s(!1)}}},[l,r]),d=o.useCallback(()=>{u()},[u]),f=o.useCallback(()=>{t(!1)},[]),m=o.useCallback(()=>{if(l?.sessionsDir)try{navigator.clipboard.writeText(l.sessionsDir)}catch{}},[l]),p=o.useCallback(()=>{if(l?.storePath)try{navigator.clipboard.writeText(l.storePath)}catch{}},[l]);return{settingsOpen:e,setSettingsOpen:t,pathsLoading:r,pathsError:a,paths:l,handleOpenSettings:d,closeSettings:f,copySessionsDir:m,copyStorePath:p}}let ke=null,xn=!1,Et=null;function vo(e){ke=e}function Gt(){return ke!==null}function ht(e){xn=e}function qt(){return xn}function It(){ke=null,xn=!1}function jo(e,t){if(ke){if(e&&ke.sessionKey===e){It();return}t&&ke.friendlyId===t&&It()}}function No(e){Et={friendlyId:e,at:Date.now()}}function gr(e,t=15e3){return!(!Et||Et.friendlyId!==e||Date.now()-Et.at>t)}function ko(e,t){if(!ke)return null;if(e&&ke.sessionKey===e){const r=ke;return ke=null,r}if(t&&ke.friendlyId===t){const r=ke;return ke=null,r}return null}const Co=8e3,Je=new Map;function Eo(e){e&&Je.set(e,{id:e,expiresAt:Date.now()+Co})}function To(e){e&&Je.delete(e)}function Ro(e){if(Je.size===0)return e;const t=Date.now();let r=!1;const s=e.filter(a=>{const i=Je.get(a.key),l=Je.get(a.friendlyId);return i&&i.expiresAt<=t||l&&l.expiresAt<=t?(i&&i.expiresAt<=t&&Je.delete(a.key),l&&l.expiresAt<=t&&Je.delete(a.friendlyId),!0):i||l?(r=!0,!1):!0});return r?s:e}function Mo(){const e=ut(),[t,r]=o.useState(!1),[s,a]=o.useState(null),i=ar({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 Ke(f));return u},onMutate:async function(u){a(null),Eo(u.sessionKey||u.friendlyId),jo(u.sessionKey,u.friendlyId),await e.cancelQueries({queryKey:ue.sessions});const d=e.getQueryData(ue.sessions);return wo(e,u.sessionKey,u.friendlyId),u.isActive&&(u.sessionKey||u.friendlyId)&&ln(e,u.friendlyId||u.sessionKey,u.sessionKey||u.friendlyId),{previousSessions:d,isActive:u.isActive}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(ue.sessions,f.previousSessions),To(d.sessionKey||d.friendlyId),a(u instanceof Error?u.message:String(u))},onSuccess:function(u){u.isActive&&It(),e.invalidateQueries({queryKey:ue.sessions})},onSettled:function(){r(!1)}});return{deleteSession:o.useCallback(async(c,u,d)=>{!c&&!u||(r(!0),await i.mutateAsync({sessionKey:c,friendlyId:u,isActive:d}))},[i]),deleting:t,error:s}}function Ao(){const e=ut(),[t,r]=o.useState(!1),[s,a]=o.useState(null),i=ar({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 Ke(d));return u},onMutate:async function(u){a(null),await e.cancelQueries({queryKey:ue.sessions});const d=e.getQueryData(ue.sessions);return e.setQueryData(ue.sessions,function(m){return Array.isArray(m)?m.map(p=>p.key!==u.sessionKey?p:{...p,label:u.newTitle,title:u.newTitle}):m}),{previousSessions:d}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(ue.sessions,f.previousSessions),a(u instanceof Error?u.message:String(u))},onSuccess:function(){e.invalidateQueries({queryKey:ue.sessions})},onSettled:function(){r(!1)}});return{renameSession:o.useCallback(async(c,u)=>{!c||!u.trim()||(r(!0),await i.mutateAsync({sessionKey:c,newTitle:u.trim()}))},[i]),renaming:t,error:s}}function xr(e){return!e.content||!Array.isArray(e.content)?"":e.content.filter(t=>t.type==="text").map(t=>t.text||"").join(`
|
|
3
|
+
`)}function Io(e,t,r){const s=[];s.push(`# Conversation: ${e}`),s.push(`Date: ${r.toLocaleString()}`),s.push("");for(const a of t){const i=a.role||"unknown",l=xr(a);if(l){const c=i==="user"?"User":"Assistant";s.push(`## ${c}`),s.push(""),s.push(l),s.push("")}}return s.join(`
|
|
4
|
+
`)}function Do(e,t,r){const s={title:e,exportDate:r.toISOString(),messages:t.map(a=>({role:a.role,content:a.content,timestamp:a.timestamp}))};return JSON.stringify(s,null,2)}function Oo(e,t,r){const s=[];s.push(`Conversation: ${e}`),s.push(`Date: ${r.toLocaleString()}`),s.push("─".repeat(60)),s.push("");for(const a of t){const i=a.role||"unknown",l=xr(a);if(l){const c=i==="user"?"User":"Assistant";s.push(`${c}:`),s.push(l),s.push("")}}return s.join(`
|
|
5
|
+
`)}function Lo(e,t,r){const s=new Date;let a,i,l;switch(r){case"markdown":a=Io(e,t,s),i=`${Vt(e)}.md`,l="text/markdown";break;case"json":a=Do(e,t,s),i=`${Vt(e)}.json`,l="application/json";break;case"txt":a=Oo(e,t,s),i=`${Vt(e)}.txt`,l="text/plain";break;default:throw new Error(`Unsupported format: ${r}`)}Po(a,i,l)}function Vt(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function Po(e,t,r){const s=new Blob([e],{type:r}),a=URL.createObjectURL(s),i=document.createElement("a");i.href=a,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(a)}function _o(e){const{children:t,open:r,defaultOpen:s=!1,onOpenChange:a,onOpenChangeComplete:i,actionsRef:l,handle:c,triggerId:u,defaultTriggerId:d=null}=e,f=Es(),m=!!f,p=os(()=>c?.store??new Ts({open:r??s,activeTriggerId:u!==void 0?u:d,modal:!0,disablePointerDismissal:!0,nested:m,role:"alertdialog"})).current;p.useControlledProp("open",r,s),p.useControlledProp("activeTriggerId",u,d),p.useSyncedValue("nested",m),p.useContextCallback("onOpenChange",a),p.useContextCallback("onOpenChangeComplete",i);const g=p.useState("payload");Rs({store:p,actionsRef:l,parentContext:f?.store.context});const b=o.useMemo(()=>({store:p}),[p]);return n.jsx(Ms.Provider,{value:b,children:typeof t=="function"?t({payload:g}):t})}function Ko({children:e,...t}){return n.jsx(_o,{...t,children:e})}function zo({className:e,children:t}){return n.jsxs(As,{children:[n.jsx(Is,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),n.jsx(Ds,{className:A("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 Uo({className:e,...t}){return n.jsx(Os,{className:A("text-lg font-medium text-primary-900",e),...t})}function $o({className:e,...t}){return n.jsx(Ls,{className:A("text-sm text-primary-600",e),...t})}function Fo({className:e,...t}){return n.jsx(lr,{render:n.jsx(xe,{variant:"outline",className:A(e)}),...t})}function Ho({className:e,...t}){return n.jsx(lr,{render:n.jsx(xe,{variant:"destructive",className:A(e)}),...t})}function Wo({open:e,onOpenChange:t,sessionTitle:r,onConfirm:s,onCancel:a}){return n.jsx(Ko,{open:e,onOpenChange:t,children:n.jsx(zo,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(Uo,{className:"mb-1",children:"Delete Session"}),n.jsxs($o,{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(Fo,{onClick:a,children:"Cancel"}),n.jsx(Ho,{onClick:s,children:"Delete"})]})]})})})}function Xo({open:e,onOpenChange:t,sessionTitle:r,onSave:s,onCancel:a}){return n.jsx(Ps,{open:e,onOpenChange:t,children:n.jsx(_s,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(Ks,{className:"mb-1",children:"Rename"}),n.jsx(zs,{className:"mb-4",children:"Enter a new name for this session."}),n.jsx("input",{type:"text",defaultValue:r,onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),s(i.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(Us,{onClick:a,children:"Cancel"}),n.jsx(xe,{onClick:i=>{const l=i.currentTarget.parentElement?.previousElementSibling;s(l.value)},children:"Save"})]})]})})})}function Yo(e){const{open:t,defaultOpen:r,onOpenChange:s,disabled:a}=e,i=t!==void 0,[l,c]=Xs({controlled:t,default:r,name:"Collapsible",state:"open"}),{mounted:u,setMounted:d,transitionStatus:f}=Ys(l,!0,!0),[m,p]=o.useState(l),[{height:g,width:b},h]=o.useState({height:void 0,width:void 0}),w=cr(),[y,x]=o.useState(),M=y??w,[C,K]=o.useState(!1),[E,F]=o.useState(!1),q=o.useRef(null),D=o.useRef(null),V=o.useRef(null),_=o.useRef(null),S=Bs(_,!1),I=Xe(R=>{const T=!l,U=ur(Fs,R.nativeEvent);if(s(T,U),U.isCanceled)return;const L=_.current;D.current==="css-animation"&&L!=null&&L.style.removeProperty("animation-name"),!C&&!E&&(D.current!=null&&D.current!=="css-animation"&&!u&&T&&d(!0),D.current==="css-animation"&&(!m&&T&&p(!0),!u&&T&&d(!0))),c(T),D.current==="none"&&u&&!T&&d(!1)});return Oe(()=>{i&&D.current==="none"&&!E&&!l&&d(!1)},[i,E,l,t,d]),o.useMemo(()=>({abortControllerRef:q,animationTypeRef:D,disabled:a,handleTrigger:I,height:g,mounted:u,open:l,panelId:M,panelRef:_,runOnceAnimationsFinish:S,setDimensions:h,setHiddenUntilFound:K,setKeepMounted:F,setMounted:d,setOpen:c,setPanelIdState:x,setVisible:p,transitionDimensionRef:V,transitionStatus:f,visible:m,width:b}),[q,D,a,I,g,u,l,M,_,S,h,K,F,d,c,p,V,f,m,b])}const yr=o.createContext(void 0);function wr(){const e=o.useContext(yr);if(e===void 0)throw new Error(fn(15));return e}let gt=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Rn.startingStyle]="startingStyle",e[e.endingStyle=Rn.endingStyle]="endingStyle",e})({}),Bo=(function(e){return e.panelOpen="data-panel-open",e})({});const Go={[gt.open]:""},qo={[gt.closed]:""},Vo={open(e){return e?{[Bo.panelOpen]:""}:null}},Jo={open(e){return e?Go:qo}},br={...Jo,...dr},Qo=o.forwardRef(function(t,r){const{render:s,className:a,defaultOpen:i=!1,disabled:l=!1,onOpenChange:c,open:u,...d}=t,f=Xe(c),m=Yo({open:u,defaultOpen:i,onOpenChange:f,disabled:l}),p=o.useMemo(()=>({open:m.open,disabled:m.disabled,transitionStatus:m.transitionStatus}),[m.open,m.disabled,m.transitionStatus]),g=o.useMemo(()=>({...m,onOpenChange:f,state:p}),[m,f,p]),b=Ge("div",t,{state:p,ref:r,props:d,stateAttributesMapping:br});return n.jsx(yr.Provider,{value:g,children:b})}),Zo={...Vo,...dr},ei=o.forwardRef(function(t,r){const{panelId:s,open:a,handleTrigger:i,state:l,disabled:c}=wr(),{className:u,disabled:d=c,id:f,render:m,nativeButton:p=!0,...g}=t,{getButtonProps:b,buttonRef:h}=Hs({disabled:d,focusableWhenDisabled:!0,native:p}),w=o.useMemo(()=>({"aria-controls":a?s:void 0,"aria-expanded":a,onClick:i}),[s,a,i]);return Ge("button",t,{state:l,ref:[r,h],props:[w,g,b],stateAttributesMapping:Zo})});let ti=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function ni(e){const{abortControllerRef:t,animationTypeRef:r,externalRef:s,height:a,hiddenUntilFound:i,keepMounted:l,id:c,mounted:u,onOpenChange:d,open:f,panelRef:m,runOnceAnimationsFinish:p,setDimensions:g,setMounted:b,setOpen:h,setVisible:w,transitionDimensionRef:y,visible:x,width:M}=e,C=o.useRef(!1),K=o.useRef(null),E=o.useRef(f),F=o.useRef(f),q=Gs(),D=o.useMemo(()=>r.current==="css-animation"?!x:!f&&!u,[f,u,x,r]),V=Xe(S=>{if(!S)return;if(r.current==null||y.current==null){const T=getComputedStyle(S),U=T.animationName!=="none"&&T.animationName!=="",L=T.transitionDuration!=="0s"&&T.transitionDuration!=="";U&&L||(T.animationName==="none"&&T.transitionDuration!=="0s"?r.current="css-transition":T.animationName!=="none"&&T.transitionDuration==="0s"?r.current="css-animation":r.current="none"),S.getAttribute(ti.orientation)==="horizontal"||T.transitionProperty.indexOf("width")>-1?y.current="width":y.current="height"}if(r.current!=="css-transition")return;(a===void 0||M===void 0)&&(g({height:S.scrollHeight,width:S.scrollWidth}),F.current&&S.style.setProperty("transition-duration","0s"));let I=-1,R=-1;return I=Ce.request(()=>{F.current=!1,R=Ce.request(()=>{setTimeout(()=>{S.style.removeProperty("transition-duration")})})}),()=>{Ce.cancel(I),Ce.cancel(R)}}),_=is(s,m,V);return Oe(()=>{if(r.current!=="css-transition")return;const S=m.current;if(!S)return;let I=-1;if(t.current!=null&&(t.current.abort(),t.current=null),f){const R={"justify-content":S.style.justifyContent,"align-items":S.style.alignItems,"align-content":S.style.alignContent,"justify-items":S.style.justifyItems};Object.keys(R).forEach(T=>{S.style.setProperty(T,"initial","important")}),!F.current&&!l&&S.setAttribute(gt.startingStyle,""),g({height:S.scrollHeight,width:S.scrollWidth}),I=Ce.request(()=>{Object.entries(R).forEach(([T,U])=>{U===""?S.style.removeProperty(T):S.style.setProperty(T,U)})})}else{if(S.scrollHeight===0&&S.scrollWidth===0)return;g({height:S.scrollHeight,width:S.scrollWidth});const R=new AbortController;t.current=R;const T=R.signal;let U=null;const L=gt.endingStyle;return U=new MutationObserver(N=>{N.some(k=>k.type==="attributes"&&k.attributeName===L)&&(U?.disconnect(),U=null,p(()=>{g({height:0,width:0}),S.style.removeProperty("content-visibility"),b(!1),t.current===R&&(t.current=null)},T))}),U.observe(S,{attributes:!0,attributeFilter:[L]}),()=>{U?.disconnect(),q.cancel(),t.current===R&&(R.abort(),t.current=null)}}return()=>{Ce.cancel(I)}},[t,r,q,i,l,u,f,m,p,g,b]),Oe(()=>{if(r.current!=="css-animation")return;const S=m.current;S&&(K.current=S.style.animationName||K.current,S.style.setProperty("animation-name","none"),g({height:S.scrollHeight,width:S.scrollWidth}),!E.current&&!C.current&&S.style.removeProperty("animation-name"),f?(t.current!=null&&(t.current.abort(),t.current=null),b(!0),w(!0)):(t.current=new AbortController,p(()=>{b(!1),w(!1),t.current=null},t.current.signal)))},[t,r,f,m,p,g,b,w,x]),Vs(()=>{const S=Ce.request(()=>{E.current=!1});return()=>Ce.cancel(S)}),Oe(()=>{if(!i)return;const S=m.current;if(!S)return;let I=-1,R=-1;return f&&C.current&&(S.style.transitionDuration="0s",g({height:S.scrollHeight,width:S.scrollWidth}),I=Ce.request(()=>{C.current=!1,R=Ce.request(()=>{setTimeout(()=>{S.style.removeProperty("transition-duration")})})})),()=>{Ce.cancel(I),Ce.cancel(R)}},[i,f,m,g]),Oe(()=>{const S=m.current;S&&i&&D&&(S.setAttribute("hidden","until-found"),r.current==="css-transition"&&S.setAttribute(gt.startingStyle,""))},[i,D,r,m]),o.useEffect(function(){const I=m.current;if(!I)return;function R(T){C.current=!0,h(!0),d(!0,ur(Ws,T))}return I.addEventListener("beforematch",R),()=>{I.removeEventListener("beforematch",R)}},[d,m,h]),o.useMemo(()=>({props:{hidden:D,id:c,ref:_}}),[D,c,_])}let On=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const ri=o.forwardRef(function(t,r){const{className:s,hiddenUntilFound:a,keepMounted:i,render:l,id:c,...u}=t,{abortControllerRef:d,animationTypeRef:f,height:m,mounted:p,onOpenChange:g,open:b,panelId:h,panelRef:w,runOnceAnimationsFinish:y,setDimensions:x,setHiddenUntilFound:M,setKeepMounted:C,setMounted:K,setPanelIdState:E,setOpen:F,setVisible:q,state:D,transitionDimensionRef:V,visible:_,width:S,transitionStatus:I}=wr(),R=a??!1,T=i??!1;Oe(()=>{if(c)return E(c),()=>{E(void 0)}},[c,E]),Oe(()=>{M(R)},[M,R]),Oe(()=>{C(T)},[C,T]);const{props:U}=ni({abortControllerRef:d,animationTypeRef:f,externalRef:r,height:m,hiddenUntilFound:R,id:h,keepMounted:T,mounted:p,onOpenChange:g,open:b,panelRef:w,runOnceAnimationsFinish:y,setDimensions:x,setMounted:K,setOpen:F,setVisible:q,transitionDimensionRef:V,visible:_,width:S});qs({open:b&&I==="idle",ref:w,onComplete(){b&&x({height:void 0,width:void 0})}});const L=o.useMemo(()=>({...D,transitionStatus:I}),[D,I]),N=Ge("div",t,{state:L,ref:[r,w],props:[U,{style:{[On.collapsiblePanelHeight]:m===void 0?"auto":`${m}px`,[On.collapsiblePanelWidth]:S===void 0?"auto":`${S}px`}},u],stateAttributesMapping:br});return T||R||!T&&p?N:null});function Dt(e){return n.jsx(Qo,{...e})}function Ot({className:e,...t}){return n.jsx(ei,{className:A("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 Lt({className:e,contentClassName:t,children:r,...s}){return n.jsx(ri,{className:A('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:A("pt-1",t),children:r})})}const Sr=o.createContext(void 0);function Wt(){const e=o.useContext(Sr);if(e===void 0)throw new Error(fn(53));return e}let Pt=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const jt=500,Ln=16;function Ee(e,t,r){if(!e)return 0;const s=getComputedStyle(e),a=r==="x"?"Inline":"Block";return r==="x"&&t==="margin"?parseFloat(s[`${t}InlineStart`])*2:parseFloat(s[`${t}${a}Start`])+parseFloat(s[`${t}${a}End`])}let si=(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 Nt="base-ui-disable-scrollbar",vr={className:Nt,getElement(e){return n.jsx("style",{nonce:e,href:Nt,precedence:"base-ui:low",children:`.${Nt}{scrollbar-width:none}.${Nt}::-webkit-scrollbar{display:none}`})}};let it=(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 yn={hasOverflowX:e=>e?{[it.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[it.hasOverflowY]:""}:null,overflowXStart:e=>e?{[it.overflowXStart]:""}:null,overflowXEnd:e=>e?{[it.overflowXEnd]:""}:null,overflowYStart:e=>e?{[it.overflowYStart]:""}:null,overflowYEnd:e=>e?{[it.overflowYEnd]:""}:null,cornerHidden:()=>null},oi={x:0,y:0},Pn={width:0,height:0},ii={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},ai={x:!1,y:!1,corner:!1},li=o.forwardRef(function(t,r){const{render:s,className:a,overflowEdgeThreshold:i,...l}=t,c=ci(i),u=cr(),d=At(),f=At(),{nonce:m,disableStyleElements:p}=Zs(),[g,b]=o.useState(!1),[h,w]=o.useState(!1),[y,x]=o.useState(!1),[M,C]=o.useState(!1),[K,E]=o.useState(Pn),[F,q]=o.useState(Pn),[D,V]=o.useState(ii),[_,S]=o.useState(ai),I=o.useRef(null),R=o.useRef(null),T=o.useRef(null),U=o.useRef(null),L=o.useRef(null),N=o.useRef(null),j=o.useRef(null),k=o.useRef(!1),z=o.useRef(0),H=o.useRef(0),G=o.useRef(0),J=o.useRef(0),ee=o.useRef("vertical"),Q=o.useRef(oi),re=Xe(P=>{const me=P.x-Q.current.x,O=P.y-Q.current.y;Q.current=P,O!==0&&(x(!0),d.start(jt,()=>{x(!1)})),me!==0&&(w(!0),f.start(jt,()=>{w(!1)}))}),Z=Xe(P=>{P.button===0&&(k.current=!0,z.current=P.clientY,H.current=P.clientX,ee.current=P.currentTarget.getAttribute(si.orientation),R.current&&(G.current=R.current.scrollTop,J.current=R.current.scrollLeft),L.current&&ee.current==="vertical"&&L.current.setPointerCapture(P.pointerId),N.current&&ee.current==="horizontal"&&N.current.setPointerCapture(P.pointerId))}),te=Xe(P=>{if(!k.current)return;const me=P.clientY-z.current,O=P.clientX-H.current;if(R.current){const B=R.current.scrollHeight,W=R.current.clientHeight,se=R.current.scrollWidth,oe=R.current.clientWidth;if(L.current&&T.current&&ee.current==="vertical"){const ne=Ee(T.current,"padding","y"),je=Ee(L.current,"margin","y"),Pe=L.current.offsetHeight,pe=T.current.offsetHeight-Pe-ne-je,Te=me/pe;R.current.scrollTop=G.current+Te*(B-W),P.preventDefault(),x(!0),d.start(jt,()=>{x(!1)})}if(N.current&&U.current&&ee.current==="horizontal"){const ne=Ee(U.current,"padding","x"),je=Ee(N.current,"margin","x"),Pe=N.current.offsetWidth,pe=U.current.offsetWidth-Pe-ne-je,Te=O/pe;R.current.scrollLeft=J.current+Te*(se-oe),P.preventDefault(),w(!0),f.start(jt,()=>{w(!1)})}}}),Y=Xe(P=>{k.current=!1,L.current&&ee.current==="vertical"&&L.current.releasePointerCapture(P.pointerId),N.current&&ee.current==="horizontal"&&N.current.releasePointerCapture(P.pointerId)});function ye(P){C(P.pointerType==="touch")}function ve(P){if(ye(P),P.pointerType!=="touch"){const me=Js(I.current,P.target);b(me)}}const de=o.useMemo(()=>({hasOverflowX:!_.x,hasOverflowY:!_.y,overflowXStart:D.xStart,overflowXEnd:D.xEnd,overflowYStart:D.yStart,overflowYEnd:D.yEnd,cornerHidden:_.corner}),[_.x,_.y,_.corner,D]),ae={role:"presentation",onPointerEnter:ve,onPointerMove:ve,onPointerDown:ye,onPointerLeave(){b(!1)},style:{position:"relative",[Pt.scrollAreaCornerHeight]:`${K.height}px`,[Pt.scrollAreaCornerWidth]:`${K.width}px`}},ge=Ge("div",t,{state:de,ref:[r,I],props:[ae,l],stateAttributesMapping:yn}),fe=o.useMemo(()=>({handlePointerDown:Z,handlePointerMove:te,handlePointerUp:Y,handleScroll:re,cornerSize:K,setCornerSize:E,thumbSize:F,setThumbSize:q,touchModality:M,cornerRef:j,scrollingX:h,setScrollingX:w,scrollingY:y,setScrollingY:x,hovering:g,setHovering:b,viewportRef:R,rootRef:I,scrollbarYRef:T,scrollbarXRef:U,thumbYRef:L,thumbXRef:N,rootId:u,hiddenState:_,setHiddenState:S,overflowEdges:D,setOverflowEdges:V,viewportState:de,overflowEdgeThreshold:c}),[Z,te,Y,re,K,F,M,h,w,y,x,g,b,u,_,D,de,c]);return n.jsxs(Sr.Provider,{value:fe,children:[!p&&vr.getElement(m),ge]})});function ci(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 ui=o.createContext(void 0);function Ue(e,t=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,r))}function di(e,t){if(typeof IntersectionObserver>"u")return()=>{};const r=new IntersectionObserver(s=>{s.forEach(a=>{a.intersectionRatio>0&&(t(),r.disconnect())})});return r.observe(e),()=>{r.disconnect()}}let Be=(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})({}),_n=!1;function fi(){_n||Qs||(typeof CSS<"u"&&"registerProperty"in CSS&&[Be.scrollAreaOverflowXStart,Be.scrollAreaOverflowXEnd,Be.scrollAreaOverflowYStart,Be.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),_n=!0)}const mi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{viewportRef:l,scrollbarYRef:c,scrollbarXRef:u,thumbYRef:d,thumbXRef:f,cornerRef:m,cornerSize:p,setCornerSize:g,setThumbSize:b,rootId:h,setHiddenState:w,hiddenState:y,handleScroll:x,setHovering:M,setOverflowEdges:C,overflowEdges:K,overflowEdgeThreshold:E}=Wt(),F=fr(),q=o.useRef(!0),D=At(),V=At(),_=Xe(()=>{const L=l.current,N=c.current,j=u.current,k=d.current,z=f.current,H=m.current;if(!L)return;const G=L.scrollHeight,J=L.scrollWidth,ee=L.clientHeight,Q=L.clientWidth,re=L.scrollTop,Z=L.scrollLeft;if(G===0||J===0)return;const te=ee>=G,Y=Q>=J,ye=Q/J,ve=ee/G,de=Math.max(0,J-Q),ae=Math.max(0,G-ee);let ge=0,fe=0;Y||(F==="rtl"?ge=Ue(-Z,0,de):ge=Ue(Z,0,de),fe=de-ge);const P=te?0:Ue(re,0,ae),me=te?0:ae-P,O=Y?0:Q,B=te?0:ee;let W=0,se=0;!Y&&!te&&(W=N?.offsetWidth||0,se=j?.offsetHeight||0);const oe=p.width===0&&p.height===0,ne=oe?W:0,je=oe?se:0,Pe=Ee(j,"padding","x"),pe=Ee(N,"padding","y"),Te=Ee(z,"margin","x"),dt=Ee(k,"margin","y"),xt=O-Pe-Te,qe=B-pe-dt,et=j?Math.min(j.offsetWidth-ne,xt):xt,yt=N?Math.min(N.offsetHeight-je,qe):qe,tt=Math.max(Ln,et*ye),nt=Math.max(Ln,yt*ve);if(b(ie=>ie.height===nt&&ie.width===tt?ie:{width:tt,height:nt}),N&&k){const ie=N.offsetHeight-nt-pe-dt,Se=G-ee,ze=Se===0?0:re/Se,pt=Math.min(ie,Math.max(0,ze*ie));k.style.transform=`translate3d(0,${pt}px,0)`}if(j&&z){const ie=j.offsetWidth-tt-Pe-Te,Se=J-Q,ze=Se===0?0:Z/Se,pt=F==="rtl"?Ue(ze*ie,-ie,0):Ue(ze*ie,0,ie);z.style.transform=`translate3d(${pt}px,0,0)`}const ft=Ue(ge,0,de),wt=Ue(fe,0,de),bt=Ue(P,0,ae),mt=Ue(me,0,ae),St=[[Be.scrollAreaOverflowXStart,ft],[Be.scrollAreaOverflowXEnd,wt],[Be.scrollAreaOverflowYStart,bt],[Be.scrollAreaOverflowYEnd,mt]];for(const[ie,Se]of St)L.style.setProperty(ie,`${Se}px`);H&&(Y||te?g({width:0,height:0}):!Y&&!te&&g({width:W,height:se})),w(ie=>{const Se=te||Y;return ie.y===te&&ie.x===Y&&ie.corner===Se?ie:{y:te,x:Y,corner:Se}});const Ne={xStart:!Y&&ft>E.xStart,xEnd:!Y&&wt>E.xEnd,yStart:!te&&bt>E.yStart,yEnd:!te&&mt>E.yEnd};C(ie=>ie.xStart===Ne.xStart&&ie.xEnd===Ne.xEnd&&ie.yStart===Ne.yStart&&ie.yEnd===Ne.yEnd?ie:Ne)});Oe(()=>{if(!l.current)return;fi();let L=!1;return di(l.current,()=>{if(!L){L=!0;return}_()})},[_,l]),Oe(()=>{queueMicrotask(_)},[_,y,F]),Oe(()=>{l.current?.matches(":hover")&&M(!0)},[l,M]),o.useEffect(()=>{const L=l.current;if(typeof ResizeObserver>"u"||!L)return;let N=!1;const j=new ResizeObserver(()=>{if(!N){N=!0;return}_()});return j.observe(L),V.start(0,()=>{const k=L.getAnimations({subtree:!0});k.length!==0&&Promise.all(k.map(z=>z.finished)).then(_).catch(()=>{})}),()=>{j.disconnect(),V.clear()}},[_,l,V]);function S(){q.current=!1}const I={role:"presentation",...h&&{"data-id":`${h}-viewport`},...(!y.x||!y.y)&&{tabIndex:0},className:vr.className,style:{overflow:"scroll"},onScroll(){l.current&&(_(),q.current||x({x:l.current.scrollLeft,y:l.current.scrollTop}),D.start(100,()=>{q.current=!0}))},onWheel:S,onTouchMove:S,onPointerMove:S,onPointerEnter:S,onKeyDown:S},R=o.useMemo(()=>({hasOverflowX:!y.x,hasOverflowY:!y.y,overflowXStart:K.xStart,overflowXEnd:K.xEnd,overflowYStart:K.yStart,overflowYEnd:K.yEnd,cornerHidden:y.corner}),[y.x,y.y,y.corner,K]),T=Ge("div",t,{ref:[r,l],state:R,props:[I,i],stateAttributesMapping:yn}),U=o.useMemo(()=>({computeThumbPosition:_}),[_]);return n.jsx(ui.Provider,{value:U,children:T})}),jr=o.createContext(void 0);function pi(){const e=o.useContext(jr);if(e===void 0)throw new Error(fn(54));return e}let _t=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const hi=o.forwardRef(function(t,r){const{render:s,className:a,orientation:i="vertical",keepMounted:l=!1,...c}=t,{hovering:u,scrollingX:d,scrollingY:f,hiddenState:m,overflowEdges:p,scrollbarYRef:g,scrollbarXRef:b,viewportRef:h,thumbYRef:w,thumbXRef:y,handlePointerDown:x,handlePointerUp:M,rootId:C,thumbSize:K}=Wt(),E=o.useMemo(()=>({hovering:u,scrolling:{horizontal:d,vertical:f}[i],orientation:i,hasOverflowX:!m.x,hasOverflowY:!m.y,overflowXStart:p.xStart,overflowXEnd:p.xEnd,overflowYStart:p.yStart,overflowYEnd:p.yEnd,cornerHidden:m.corner}),[u,d,f,i,m,p]),F=fr();o.useEffect(()=>{const I=h.current,R=i==="vertical"?g.current:b.current;if(!R)return;function T(U){if(!(!I||!R||U.ctrlKey)){if(U.preventDefault(),i==="vertical"){if(I.scrollTop===0&&U.deltaY<0)return}else if(I.scrollLeft===0&&U.deltaX<0)return;if(i==="vertical"){if(I.scrollTop===I.scrollHeight-I.clientHeight&&U.deltaY>0)return}else if(I.scrollLeft===I.scrollWidth-I.clientWidth&&U.deltaX>0)return;i==="vertical"?I.scrollTop+=U.deltaY:I.scrollLeft+=U.deltaX}}return R.addEventListener("wheel",T,{passive:!1}),()=>{R.removeEventListener("wheel",T)}},[i,b,g,h]);const q={...C&&{"data-id":`${C}-scrollbar`},onPointerDown(I){if(I.button===0&&I.currentTarget===I.target&&h.current){if(w.current&&g.current&&i==="vertical"){const R=Ee(w.current,"margin","y"),T=Ee(g.current,"padding","y"),U=w.current.offsetHeight,L=g.current.getBoundingClientRect(),N=I.clientY-L.top-U/2-T+R/2,j=h.current.scrollHeight,k=h.current.clientHeight,z=g.current.offsetHeight-U-T-R,G=N/z*(j-k);h.current.scrollTop=G}if(y.current&&b.current&&i==="horizontal"){const R=Ee(y.current,"margin","x"),T=Ee(b.current,"padding","x"),U=y.current.offsetWidth,L=b.current.getBoundingClientRect(),N=I.clientX-L.left-U/2-T+R/2,j=h.current.scrollWidth,k=h.current.clientWidth,z=b.current.offsetWidth-U-T-R,H=N/z;let G;F==="rtl"?(G=(1-H)*(j-k),h.current.scrollLeft<=0&&(G=-G)):G=H*(j-k),h.current.scrollLeft=G}x(I)}},onPointerUp:M,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...i==="vertical"&&{top:0,bottom:`var(${Pt.scrollAreaCornerHeight})`,insetInlineEnd:0,[_t.scrollAreaThumbHeight]:`${K.height}px`},...i==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${Pt.scrollAreaCornerWidth})`,bottom:0,[_t.scrollAreaThumbWidth]:`${K.width}px`}}},D=Ge("div",t,{ref:[r,i==="vertical"?g:b],state:E,props:[q,c],stateAttributesMapping:yn}),V=o.useMemo(()=>({orientation:i}),[i]),_=i==="vertical"?m.y:m.x;return l||!_?n.jsx(jr.Provider,{value:V,children:D}):null}),gi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{thumbYRef:l,thumbXRef:c,handlePointerDown:u,handlePointerMove:d,handlePointerUp:f,setScrollingX:m,setScrollingY:p}=Wt(),{orientation:g}=pi(),b=o.useMemo(()=>({orientation:g}),[g]);return Ge("div",t,{ref:[r,g==="vertical"?l:c],state:b,props:[{onPointerDown:u,onPointerMove:d,onPointerUp(w){g==="vertical"&&p(!1),g==="horizontal"&&m(!1),f(w)},style:{...g==="vertical"&&{height:`var(${_t.scrollAreaThumbHeight})`},...g==="horizontal"&&{width:`var(${_t.scrollAreaThumbWidth})`}}},i]})}),xi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{cornerRef:l,cornerSize:c,hiddenState:u}=Wt(),d=Ge("div",t,{ref:[r,l],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:c.width,height:c.height}},i]});return u.corner?null:d});function Nr({className:e,...t}){return n.jsx(li,{className:A("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function kr({className:e,...t}){return n.jsx(mi,{className:A("h-full w-full outline-none focus-visible:outline-none",e),...t})}function Cr({className:e,...t}){return n.jsx(hi,{className:A("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 Er({className:e,...t}){return n.jsx(gi,{className:A("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function yi({className:e,...t}){return n.jsx(xi,{className:A("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function wi(e){return e==="subagent"?us:e==="cron"?ds:fs}function bi(e){if(!e||!Array.isArray(e.content))return"";const t=e.content.map(s=>s.type==="text"?String(s.text??""):"").join(" ");return hr(t).replace(/\s+/g," ").trim()}function Si(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 vi(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=Si(r);if(s)return s}return null}function ji(e){const t=e-Date.now(),r=Math.abs(t),s=[["minute",6e4],["hour",36e5],["day",864e5]];let a="minute",i=6e4;r>=s[2][1]?[a,i]=s[2]:r>=s[1][1]&&([a,i]=s[1]);const l=Math.round(t/i);return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(l,a)}function Ni(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function ki({session:e,active:t,isGenerating:r=!1,isPinned:s,selectionMode:a=!1,selected:i=!1,onToggleSelect:l,onSelect:c,onTogglePin:u,onRename:d,onDelete:f,onExport:m}){const p=e.label||e.title||e.derivedTitle||e.friendlyId,g=wi(e.kind),b=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?bi(e.lastMessage):"",h=b.length>50?`${b.slice(0,50).trimEnd()}…`:b,w=e.kind==="subagent"?Ni(e.status):null,y=e.kind==="cron"?vi(e.lastMessage):null;return n.jsxs(He,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:x=>{if(a){x.preventDefault(),x.stopPropagation(),l?.(e);return}c?.()},className:A("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:[a?n.jsx("span",{"aria-hidden":"true",className:A("inline-flex items-center justify-center size-4 shrink-0 rounded border transition-colors",i?"bg-primary-700 border-primary-700 text-white":"border-primary-300 bg-surface"),children:i?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(X,{icon:g,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:p,children:[s?n.jsx("span",{className:"mr-1 text-xs text-primary-700","aria-hidden":"true",children:"📌"}):null,p]}),e.kind==="subagent"?r?n.jsx("span",{"aria-label":"Session active",className:"size-1.5 rounded-full bg-green-500 shrink-0"}):w==="success"?n.jsx(X,{icon:tr,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):w==="error"?n.jsx(X,{icon:Ut,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),h?n.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:h}):null,e.kind==="cron"&&y?n.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:ji(y)}):null]})]}),a?null:n.jsxs($t,{children:[n.jsx(Ft,{type:"button",onClick:x=>{x.preventDefault(),x.stopPropagation()},className:A("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(X,{icon:as,size:20,strokeWidth:1.5})}),n.jsxs(Ht,{side:"bottom",align:"end",children:[n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),u(e)},className:"gap-2",children:[n.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",s?"Unpin Session":"Pin Session"]}),n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),d(e)},className:"gap-2",children:[n.jsx(X,{icon:ls,size:20,strokeWidth:1.5})," ","Rename"]}),n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),m(e)},className:"gap-2",children:[n.jsx(X,{icon:cs,size:20,strokeWidth:1.5})," ","Export"]}),an(e.key)?null:n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),f(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[n.jsx(X,{icon:nr,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function Ci(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 Jt=o.memo(ki,Ci),Tr="opencami-pinned-sessions",Rr="opencami-sidebar-folders",Fe={webchat:!1,subagent:!1,cron:!1,other:!1};async function Ei(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 Ke(r))}async function Ti(e,t,r){const s=[];let a=0;const i=Array.from({length:Math.min(t,e.length)},async function(){for(;a<e.length;){const c=a;a+=1;try{await r(e[c])}catch(u){s.push(u)}}});return await Promise.all(i),s}function Ri(){if(typeof window>"u")return[];try{const e=localStorage.getItem(Tr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}catch{return[]}}function Mi(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(Tr,JSON.stringify(t))}catch{}}function Ai(){if(typeof window>"u")return{...Fe};try{const e=localStorage.getItem(Rr);if(!e)return{...Fe};const t=JSON.parse(e);return!t||typeof t!="object"?{...Fe}:{webchat:typeof t.webchat=="boolean"?t.webchat:Fe.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:Fe.subagent,cron:typeof t.cron=="boolean"?t.cron:Fe.cron,other:typeof t.other=="boolean"?t.other:Fe.other}}catch{return{...Fe}}}function Ii(e){if(!(typeof window>"u"))try{localStorage.setItem(Rr,JSON.stringify(e))}catch{}}function Tt(e,t,r){return r&&e.key?e.key===r:e.friendlyId===t}function Di(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function Qt(e,t,r,s){return Tt(e,t,r)&&s?!0:Di(e.status)}const Oi=o.memo(function({sessions:t,activeFriendlyId:r,activeSessionKey:s,isStreaming:a=!1,defaultOpen:i=!0,onSelect:l,onRename:c,onDelete:u,onExport:d}){const f=o.useDeferredValue(t),m=ut(),[p,g]=o.useState(()=>Ri()),[b,h]=o.useState(()=>Ai()),[w,y]=o.useState(!1),[x,M]=o.useState(()=>new Set),C=o.useMemo(()=>new Set(p),[p]),K=f.filter(j=>C.has(j.key)),E=f.filter(j=>!C.has(j.key)),F=K.length>0&&E.length>0,q=o.useMemo(()=>{const j={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const k of E){const z=k.kind??"other";j[z].push(k)}return j},[E]),D=o.useMemo(()=>f.filter(j=>x.has(j.key)),[x,f]),V=D.length,_=o.useCallback(()=>{y(j=>(j&&M(new Set),!j))},[]),S=o.useCallback(j=>{an(j.key)||M(k=>{const z=new Set(k);return z.has(j.key)?z.delete(j.key):z.add(j.key),z})},[]),I=o.useCallback(()=>{M(new Set(f.filter(j=>!an(j.key)).map(j=>j.key)))},[f]),R=o.useCallback(()=>{y(!1),M(new Set)},[]),T=o.useCallback(async()=>{if(D.length===0||!window.confirm(`Delete ${D.length} sessions? This will archive them.`))return;const k=[];await Ti(D,10,async z=>{try{await Ei(z.key)}catch(H){throw k.push(z.label||z.title||z.derivedTitle||z.friendlyId),H}}),k.length>0&&(console.error("[sidebar] Bulk delete failed for some sessions",k),window.alert(`Could not delete ${k.length} session${k.length!==1?"s":""}:
|
|
6
|
+
|
|
7
|
+
${k.join(`
|
|
8
|
+
`)}`)),y(!1),M(new Set),m.invalidateQueries({queryKey:ue.sessions})},[m,D]),U=o.useCallback(j=>{g(k=>{const H=k.includes(j.key)?k.filter(G=>G!==j.key):[...k,j.key];return Mi(H),H})},[]),L=o.useCallback((j,k)=>{h(z=>{const H={...z,[j]:k};return Ii(H),H})},[]);function N(j,k,z){return z.length===0?null:n.jsxs(Dt,{className:"flex flex-col",open:b[j],onOpenChange:H=>L(j,H),children:[n.jsxs(Ot,{className:A("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:k}),n.jsx("span",{className:A("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:z.length})]}),n.jsx(Lt,{contentClassName:"flex flex-col gap-px",children:z.map(H=>n.jsx(Jt,{session:H,active:Tt(H,r,s),isGenerating:Qt(H,r,s,a),isPinned:!1,selectionMode:w,selected:x.has(H.key),onToggleSelect:S,onSelect:l,onTogglePin:U,onRename:c,onDelete:u,onExport:d},H.key))})]})}return n.jsxs(Dt,{className:"flex h-full flex-col flex-1 min-h-0 w-full",defaultOpen:i,children:[n.jsxs("div",{className:"flex items-center justify-between pr-2 shrink-0",children:[n.jsxs(Ot,{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(X,{icon:mn,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),n.jsx("button",{type:"button",onClick:_,className:A("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",w?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:w?"Done":"Select"})]}),n.jsx(Lt,{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(Nr,{className:"flex-1 min-h-0",children:[n.jsx(kr,{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(j=>n.jsx(Jt,{session:j,active:Tt(j,r,s),isGenerating:Qt(j,r,s,a),isPinned:!0,selectionMode:w,selected:x.has(j.key),onToggleSelect:S,onSelect:l,onTogglePin:U,onRename:c,onDelete:u,onExport:d},j.key))}):null,F?n.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,q.chat.length>0?n.jsxs("div",{className:"flex flex-col gap-px",children:[n.jsx("div",{className:A("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:q.chat.map(j=>n.jsx(Jt,{session:j,active:Tt(j,r,s),isGenerating:Qt(j,r,s,a),isPinned:!1,selectionMode:w,selected:x.has(j.key),onToggleSelect:S,onSelect:l,onTogglePin:U,onRename:c,onDelete:u,onExport:d},j.key))})]}):null,N("webchat","🦎 OpenCami",q.webchat),N("subagent","🤖 Sub-agents",q.subagent),N("cron","⏰ Cron / Isolated",q.cron),N("other","📁 Other",q.other)]})}),n.jsx(Cr,{orientation:"vertical",children:n.jsx(Er,{})})]})}),w?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:[V," selected"]}),n.jsx("button",{type:"button",onClick:I,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:T,disabled:V===0,className:A("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",V>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[n.jsx(X,{icon:nr,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]})},Li);function Li(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],a=t.sessions[r];if(s.key!==a.key||s.friendlyId!==a.friendlyId||s.label!==a.label||s.title!==a.title||s.derivedTitle!==a.derivedTitle||s.updatedAt!==a.updatedAt||s.kind!==a.kind||s.status!==a.status||s.lastMessage!==a.lastMessage)return!1}return!0}const Pi=o.lazy(()=>Kt(()=>import("./settings-dialog-C1u52aju.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,24])).then(e=>({default:e.SettingsDialog}))),_i=o.lazy(()=>Kt(()=>import("./session-export-dialog-CliO9Ob-.js"),__vite__mapDeps([25,1,4,3,5,6,7,8,9,2])).then(e=>({default:e.SessionExportDialog})));function Ki({sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s=!1,creatingSession:a,onCreateSession:i,isCollapsed:l,onToggleCollapse:c,onSelectSession:u,onActiveSessionDelete:d,onOpenSearch:f}){const{settingsOpen:m,setSettingsOpen:p,pathsLoading:g,pathsError:b,paths:h,handleOpenSettings:w,closeSettings:y,copySessionsDir:x,copyStorePath:M}=So(),{deleteSession:C}=Mo(),{renameSession:K}=Ao(),E={duration:.15,ease:l?"easeIn":"easeOut"},[F,q]=o.useState(!1),[D,V]=o.useState(null),[_,S]=o.useState(""),[I,R]=o.useState(!1),[T,U]=o.useState(null),[L,N]=o.useState(null),[j,k]=o.useState(""),[z,H]=o.useState(!1),[G,J]=o.useState(null),[ee,Q]=o.useState(null),[re,Z]=o.useState(""),te=ut();function Y(P){V(P.key),S(P.label||P.title||P.derivedTitle||""),q(!0)}function ye(P){D&&K(D,P),q(!1),V(null)}function ve(P){U(P.key),N(P.friendlyId),k(P.label||P.title||P.derivedTitle||P.friendlyId),R(!0)}function de(){if(T&&L){const P=L===t;P&&d&&d(),C(T,L,P)}R(!1),U(null),N(null)}function ae(P){J(P.key),Q(P.friendlyId),Z(P.label||P.title||P.derivedTitle||P.friendlyId),H(!0)}function ge(P){if(G&&ee){const me=ue.history(ee,G),O=te.getQueryData(me);O?.messages&&Lo(re,O.messages,P)}H(!1),J(null),Q(null)}const fe={className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col"};return n.jsxs(be.aside,{initial:!1,animate:{width:l?48:"var(--opencami-sidebar-width)"},transition:E,className:fe.className,children:[n.jsxs(be.div,{layout:!0,transition:{layout:E},className:A("flex items-center h-12 px-2 justify-between"),children:[n.jsx(Re,{initial:!1,children:l?null:n.jsx(be.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,children:n.jsxs(He,{to:"/new",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[n.jsx(eo,{className:"size-5"}),n.jsx(to,{})]})})}),n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{onClick:c,render:n.jsx(xe,{size:"icon-sm",variant:"ghost",children:n.jsx(X,{icon:ms,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(be.div,{layout:!0,transition:{layout:E},className:"w-full space-y-2",children:[n.jsxs(xe,{disabled:a,variant:"ghost",size:"sm",onClick:i,onMouseUp:u,className:"w-full pl-1.5 justify-start",children:[n.jsx(X,{icon:ps,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),(()=>{try{const P=localStorage.getItem("opencami-file-explorer");return P===null?!0:P==="true"}catch{return!0}})()&&n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{asChild:!0,children:n.jsxs(He,{to:"/files",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(X,{icon:hs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),l&&n.jsx(De,{side:"right",children:"Files"})]})}),(()=>{try{const P=localStorage.getItem("opencami-memory-viewer");return P===null?!0:P==="true"}catch{return!0}})()&&n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{asChild:!0,children:n.jsxs(He,{to:"/memory",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(X,{icon:rn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,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(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{asChild:!0,children:n.jsxs(He,{to:"/skills",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(X,{icon:gs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,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(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{asChild:!0,children:n.jsxs(He,{to:"/agents",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(X,{icon:rn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,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(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{asChild:!0,children:n.jsxs(He,{to:"/bots",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(X,{icon:xs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,className:"overflow-hidden whitespace-nowrap",children:"Cron Jobs"})})]})}),l&&n.jsx(De,{side:"right",children:"Cron Jobs"})]})}),(()=>{try{return localStorage.getItem("feature_dashboard")==="true"}catch{return!1}})()&&n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{asChild:!0,children:n.jsxs(He,{to:"/dashboard",className:A(Ve({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(X,{icon:ys,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,className:"overflow-hidden whitespace-nowrap",children:"Dashboard"})})]})}),l&&n.jsx(De,{side:"right",children:"Dashboard"})]})})]}),n.jsx(be.div,{layout:!0,transition:{layout:E},className:"w-full",children:n.jsxs(xe,{variant:"ghost",size:"sm",onClick:f,className:"w-full pl-1.5 justify-start",children:[n.jsx(X,{icon:rr,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(Re,{initial:!1,children:!l&&n.jsx(be.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,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(Oi,{sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s,onSelect:u,onRename:Y,onDelete:ve,onExport:ae})})},"content")})}),n.jsx("div",{className:"px-2 py-3 border-t border-primary-200 bg-primary-100",children:n.jsx(be.div,{layout:!0,transition:{layout:E},className:"w-full",children:n.jsxs(xe,{variant:"ghost",size:"sm",onClick:w,title:l?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[n.jsx(X,{icon:ws,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Re,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:E,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),m&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Pi,{open:m,onOpenChange:p,pathsLoading:g,pathsError:b,paths:h,onClose:y,onCopySessionsDir:x,onCopyStorePath:M})}),n.jsx(Xo,{open:F,onOpenChange:q,sessionTitle:_,onSave:ye,onCancel:()=>q(!1)}),n.jsx(Wo,{open:I,onOpenChange:R,sessionTitle:j,onConfirm:de,onCancel:()=>R(!1)}),z&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(_i,{open:z,onOpenChange:H,sessionTitle:re,onExport:ge,onCancel:()=>H(!1)})})]})}function zi(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],a=t[r];if(s.key!==a.key||s.friendlyId!==a.friendlyId||s.label!==a.label||s.title!==a.title||s.derivedTitle!==a.derivedTitle||s.updatedAt!==a.updatedAt||s.kind!==a.kind||s.status!==a.status||s.lastMessage!==a.lastMessage)return!1}return!0}function Ui(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!zi(e.sessions,t.sessions))}const $i=o.memo(Ki,Ui);function Kn(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 zn(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 Fi({totalTokens:e,contextTokens:t,className:r}){const{percentage:s,usedStr:a,maxStr:i,colors:l,hasData:c,isNearlyFull:u}=o.useMemo(()=>{if(typeof t!="number"||t<=0)return{percentage:0,usedStr:"",maxStr:"",colors:zn(0),hasData:!1,isNearlyFull:!1};const m=typeof e=="number"&&e>0?e:0,p=Math.min(100,Math.round(m/t*100));return{percentage:p,usedStr:Kn(m),maxStr:Kn(t),colors:zn(p),hasData:!0,isNearlyFull:p>=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:A("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:A("h-full rounded-full transition-all duration-500 ease-out",l.bar,u&&"animate-pulse"),style:{width:`${s}%`}})}),n.jsx("span",{className:A("text-[10px] leading-none font-medium tabular-nums whitespace-nowrap",u?l.text:"text-primary-500 dark:text-primary-400"),children:a})]}),n.jsx("div",{className:A("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:A("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:A("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:a}),n.jsx("span",{className:"text-primary-400",children:"/"}),n.jsx("span",{children:i}),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:A("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 Hi=o.memo(Fi);function Wi({activeTitle:e,wrapperRef:t,showSidebarButton:r=!1,onOpenSidebar:s,totalTokens:a,contextTokens:i}){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(xe,{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(X,{icon:bs,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(Hi,{totalTokens:a,contextTokens:i,className:"ml-3 hidden sm:flex"})]})}const Xi=o.memo(Wi);function Yi(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function Bi(e){const t=new Date(e);return Yi(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 Gi(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 qi({timestamp:e}){const t=Bi(e),r=Gi(e);return n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{className:"inline-flex items-center text-xs text-primary-600",children:t}),n.jsx(De,{side:"top",children:r})]})})}function Vi({text:e,align:t,timestamp:r,forceVisible:s=!1}){const[a,i]=o.useState(!1),[l,c]=o.useState("idle"),u=o.useRef(null),d=o.useRef(null),f=o.useRef(null),[m,p]=o.useState(()=>{if(typeof window>"u")return!0;try{const y=localStorage.getItem("opencami-tts-enabled");return y===null?!0:y==="true"}catch{return!0}});o.useEffect(()=>{function y(x){x.key==="opencami-tts-enabled"&&p(x.newValue===null?!0:x.newValue==="true")}return window.addEventListener("storage",y),()=>window.removeEventListener("storage",y)},[]),o.useEffect(()=>()=>{f.current?.abort(),u.current&&(u.current.pause(),u.current=null),d.current&&(URL.revokeObjectURL(d.current),d.current=null)},[]);const g=async()=>{try{await navigator.clipboard.writeText(e),i(!0),window.setTimeout(()=>i(!1),1400)}catch{i(!1)}},b=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 y=new AbortController;f.current=y,c("loading");try{const x=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e}),signal:y.signal});if(!x.ok)throw new Error("TTS failed");const M=await x.blob(),C=URL.createObjectURL(M);d.current=C;const K=new Audio(C);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(x){if(x instanceof Error&&x.name==="AbortError"){c("idle");return}c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null}},h=t==="end"?"justify-end":"justify-start",w=t==="start"&&m&&e.trim().length>0;return n.jsxs("div",{className:A("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",h),children:[n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{type:"button",onClick:()=>{g().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(X,{icon:a?pn:Ss,size:16,strokeWidth:1.6})}),n.jsx(De,{side:"top",children:"Copy"})]})}),w&&n.jsx(Me,{children:n.jsxs(Ae,{children:[n.jsx(Ie,{type:"button",onClick:()=>{b().catch(()=>{})},disabled:l==="loading",className:A("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(X,{icon:l==="loading"?vs:l==="playing"?sr:js,size:16,strokeWidth:1.6,className:A(l==="loading"&&"animate-spin")})}),n.jsx(De,{side:"top",children:l==="loading"?"Generating speech…":l==="playing"?"Stop":"Listen"})]})}),n.jsx(qi,{timestamp:r})]})}function Mr({children:e,className:t,...r}){return n.jsx("div",{className:A("flex gap-3 w-full",t),...r,children:e})}function Ji({children:e,markdown:t=!1,className:r,...s}){const a=A("rounded-[12px] break-words whitespace-normal min-w-0 max-w-full overflow-x-hidden",r);return t?n.jsx(no,{className:a,...s,children:e}):n.jsx("div",{className:a,...s,children:e})}function Qi(){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=a=>t(a.matches);return r.addEventListener("change",s),t(r.matches),()=>r.removeEventListener("change",s)},[]),e}function Zi({content:e}){const t=Qi();return n.jsx("div",{className:"inline-flex flex-col",children:n.jsxs(Dt,{defaultOpen:!t,children:[n.jsxs(Ot,{render:n.jsx(xe,{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(X,{icon:hn,size:14,strokeWidth:1.5,className:"text-primary-900 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),n.jsx(Lt,{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 ea({toolPart:e,defaultOpen:t=!1}){const{state:r,input:s,output:a,toolCallId:i}=e,l=(d,f=3200)=>{const m=d===void 0?"undefined":d;let p;if(typeof m=="string")try{p=JSON.stringify(JSON.parse(m),null,2)}catch{p=m}else p=JSON.stringify(m,null,2);return p.length<=f?p:`${p.slice(0,f).trimEnd()}
|
|
9
|
+
…[truncated]`},c=r==="output-error"?Ut:r==="output-available"?tr:or,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(Dt,{defaultOpen:t,children:[n.jsxs(Ot,{render:n.jsx(xe,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[n.jsx(X,{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(X,{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(Lt,{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)})]}),a!=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(a)})]}),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})]}),i&&n.jsxs("div",{className:"text-[11px] text-primary-500/80 font-mono tabular-nums",children:["ID: ",i.slice(0,16),"..."]})]})})]})})}function Un(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 ta({sources:e}){const[t,r]=o.useState(!1);if(!e.length)return null;const s=[...new Set(e.map(a=>Un(a.url)))];return n.jsxs("div",{className:"mt-2 w-full",children:[n.jsxs("button",{onClick:()=>r(!t),className:A("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(X,{icon:rr,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(a=>n.jsx($n,{domain:a},a)),s.length>3&&n.jsxs("span",{className:"text-cyan-500/70 text-[10px] ml-0.5",children:["+",s.length-3]})]}),n.jsx(X,{icon:mn,size:12,className:A("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((a,i)=>{const l=Un(a.url);return n.jsxs("a",{href:a.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:a.title||l}),n.jsx("div",{className:"text-xs text-muted-foreground",children:l}),a.snippet&&n.jsx("p",{className:"text-xs text-muted-foreground/80 line-clamp-2 mt-0.5",children:a.snippet})]})]},`${a.url}-${i}`)})})]})}function na(e,t){const r=t!==void 0,s=t?.isError??!1;let a;r?s?a="output-error":a="output-available":a="input-available";let i;s&&t?.content?.[0]?.type==="text"&&(i=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:a,input:e.arguments,output:c,toolCallId:e.id,errorText:i}}function Fn(e){return Qe(e).map(r=>{const s=r.id??"",a=r.name??"",i=r.partialJson??"",l=r.arguments?JSON.stringify(r.arguments):"";return`${s}|${a}|${i}|${l}`}).join("||")}function ra(e){if(!e)return"missing";const r=(Array.isArray(e.content)?e.content:[]).map(a=>a.type==="text"?String(a.text??""):"").join("").trim(),s=e.details?JSON.stringify(e.details):"";return`${e.toolCallId??""}|${e.toolName??""}|${e.isError?"1":"0"}|${r}|${s}`}function Hn(e,t){if(!t)return"";const r=Qe(e);return r.length===0?"":r.map(s=>s.id?ra(t.get(s.id)):"missing").join("||")}function sa(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 Wn(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=sa(r);if(s)return s}return null}function cn(e){const r=(Array.isArray(e.content)?e.content:[]).find(s=>s.type==="thinking");return r&&"thinking"in r?String(r.thinking??""):null}function oa(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}const lt=/^📎 Uploaded file:\s*(\/uploads\/\S+)\s*$/;function ia(e){if(e===null||Number.isNaN(e))return"Unknown size";if(e<1024)return`${e} B`;const t=["KB","MB","GB","TB"];let r=e/1024,s=0;for(;r>=1024&&s<t.length-1;)r/=1024,s++;return`${r.toFixed(1)} ${t[s]}`}function aa(e){if(!e)return[];const t=e.trimStart();if(t.startsWith(">")||t.startsWith("```"))return[];const r=e.split(`
|
|
10
|
+
`),s=[];for(const i of r){if(lt.test(i)){s.push(i);continue}if(s.length>0&&i.trim()===""){s.push(i);continue}break}const a=r[0]??"";return lt.test(a)?s.filter(i=>lt.test(i)):[]}function la(e){const t=[],r=new Set;for(const s of aa(e)){const i=s.match(lt)?.[1];!i||r.has(i)||(r.add(i),t.push({path:i,filename:i.split("/").pop()||i}))}return t}function ca(e){const t=e.split(`
|
|
11
|
+
`);if(!lt.test(t[0]??""))return e.trim();let r=0;for(;r<t.length&<.test(t[r]);)r++;for(;r<t.length&&t[r].trim()==="";)r++;return t.slice(r).join(`
|
|
12
|
+
`).replace(/\n{3,}/g,`
|
|
13
|
+
|
|
14
|
+
`).trim()}function ua({message:e,toolResultsByCallId:t,forceActionsVisible:r=!1,isStreaming:s=!1,isLastAssistant:a=!1,aggregatedSearchSources:i,wrapperRef:l,wrapperClassName:c,wrapperScrollMarginTop:u,messageDomId:d,highlighted:f=!1}){const{settings:m}=ro(),p=e.role||"assistant",g=Le(e),b=cn(e),h=oa(e),w=p==="user",y=on(e),x=zt(),M=$s(S=>S.openInEditor),C=o.useMemo(()=>la(g),[g]),[K,E]=o.useState({}),F=o.useMemo(()=>ca(g),[g]);o.useEffect(()=>{let S=!1;async function I(){const R={};await Promise.all(C.map(async T=>{try{const U=await fetch(`/api/files/info?path=${encodeURIComponent(T.path)}`);if(!U.ok){R[T.path]=null;return}const L=await U.json();R[T.path]=typeof L.size=="number"?L.size:null}catch{R[T.path]=null}})),S||E(R)}return C.length>0?I():E({}),()=>{S=!0}},[C]);const q=async S=>{M(S),await x({to:"/files"})},D=p==="assistant"?Qe(e):[],V=D.length>0,_=a&&!s&&m.showSearchSources&&i?i:[];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:A("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",w?"items-end":"items-start"),children:[b&&m.showReasoningBlocks&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(Zi,{content:b})}),h.length>0&&n.jsx("div",{className:A("flex flex-wrap gap-2 mb-2",w?"justify-end":"justify-start"),children:h.map((S,I)=>n.jsx("img",{src:`data:${S.source.media_type};base64,${S.source.data}`,alt:`Attachment ${I+1}`,loading:"lazy",decoding:"async",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},I))}),C.length>0&&n.jsx("div",{className:A("mb-2 flex w-full flex-col gap-2",w?"items-end":"items-start"),children:C.map(S=>n.jsxs("button",{type:"button",onClick:()=>{q(S.path)},className:"flex max-w-full items-center gap-3 rounded-xl border border-primary-200 bg-primary-50 px-3 py-2 text-left hover:bg-primary-100",children:[n.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-primary-100",children:n.jsx(X,{icon:ir,size:18,className:"text-primary-600"})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"truncate text-sm font-medium text-primary-900",children:S.filename}),n.jsx("p",{className:"text-xs text-primary-600",children:ia(K[S.path]??null)})]})]},S.path))}),n.jsx(Mr,{className:A("min-w-0 max-w-full",w?"flex-row-reverse":""),children:n.jsx(Ji,{markdown:!w,className:A("text-primary-900 opencami-text-size min-w-0 max-w-full",w?"opencami-message-user bg-primary-100 px-4 py-[var(--opencami-user-bubble-py)] max-w-[85%]":"opencami-message-assistant bg-transparent w-full",!w&&s&&"stream-fade-in"),children:F})}),V&&m.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:D.map(S=>{const I=S.id?t?.get(S.id):void 0,R=na(S,I);return n.jsx(ea,{toolPart:R,defaultOpen:!1},S.id||S.name)})}),_.length>0&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(ta,{sources:_})}),!V&&n.jsx(Vi,{text:g,timestamp:y,align:w?"end":"start",forceVisible:r})]})}function da(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")||Le(e.message)!==Le(t.message)||cn(e.message)!==cn(t.message)||Fn(e.message)!==Fn(t.message)||Hn(e.message,e.toolResultsByCallId)!==Hn(t.message,t.toolResultsByCallId)||Wn(e.message)!==Wn(t.message))}const Zt=o.memo(ua,da),fa=[/```[\s\S]*?```/g,/`[^`]+`/g,/\b(function|const|let|var|class|import|export|return|async|await)\b/g];function ma(e){const t=[],r=e.match(/"([^"]+)"|'([^']+)'/g);r&&t.push(...r.map(i=>i.replace(/['"]/g,"")));const s=e.match(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g);s&&t.push(...s.filter(i=>!["I","The","A","An","This"].includes(i)));const a=e.match(/`([^`]+)`/g);return a&&t.push(...a.map(i=>i.replace(/`/g,""))),[...new Set(t)].slice(0,5)}function pa(e){return fa.some(t=>t.test(e))}function ha(e){return/^[\s]*[-*•\d]+[.)\s]/m.test(e)||/\b(first|second|third|1\.|2\.|3\.)/i.test(e)}function ga(e){return/\b(alternatively|another|other option|could also|you might|consider)\b/i.test(e)}function xa(e){return/\b(because|since|due to|reason|why|how|what|when|where)\b/i.test(e)}function ya(e){return/\b(however|but|note|warning|caution|careful|important|keep in mind|be aware)\b/i.test(e)}function wa(e){const t=[],r=ma(e);if(pa(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"})),ha(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"})),ga(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"})),xa(e)&&t.length<3&&t.push({text:"Can you give me a practical example?",type:"example"}),ya(e)&&t.length<3&&t.push({text:"What potential issues should I watch out for?",type:"clarify"}),r.length>0&&t.length<3){const i=r[0];t.push({text:`Tell me more about ${i}`,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"}],a=new Set(t.map(i=>i.type));for(const i of s){if(t.length>=3)break;a.has(i.type)||(t.push(i),a.add(i.type))}for(const i of s){if(t.length>=3)break;t.some(l=>l.text===i.text)||t.push(i)}return t.slice(0,3)}function Xn(e){return wa(e).map(t=>t.text)}const ba={openai:{baseUrl:"https://api.openai.com/v1",model:"gpt-4.1-nano"},openrouter:{baseUrl:"https://openrouter.ai/api/v1",model:"openai/gpt-oss-120b"},kilocode:{baseUrl:"https://api.kilo.ai/api/gateway",model:"google/gemini-2.5-flash"},ollama:{baseUrl:"http://localhost:11434/v1",model:"llama3.2"},custom:{baseUrl:"",model:""}},Rt={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function Ar(e){return ba[e]}function Sa(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():Ar(e.llmProvider).baseUrl}function va(e){return e.llmModel.trim()?e.llmModel.trim():Ar(e.llmProvider).model}function Yn(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||!!(e.llmBaseUrl.trim()&&e.llmModel.trim()):t||!!e.llmApiKey.trim()}function ja(e){if(!e||typeof e!="object")return{settings:Rt};const{settings:t}=e;if(!t)return{settings:Rt};const{openaiApiKey:r,...s}=t,a=s.llmApiKey??r??"";return{settings:{...Rt,...s,llmApiKey:a}}}const Ze=pr()(mr(e=>({settings:{...Rt},updateSettings:t=>e(r=>({settings:{...r.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>ja(e)}));function rc(){const e=Ze(l=>l.settings),t=Ze(l=>l.updateSettings),r=Ze(l=>l.clearApiKey),[s,a]=o.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasKilocodeKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:Yn(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,m=e.llmProvider==="openrouter"?!!d.hasOpenRouterKey:e.llmProvider==="kilocode"?!!d.hasKilocodeKey:d.hasEnvKey;a({hasEnvKey:d.hasEnvKey,hasOpenRouterKey:!!d.hasOpenRouterKey,hasKilocodeKey:!!d.hasKilocodeKey,hasUserKey:f,isAvailable:Yn(e,m),isLoading:!1,error:null})}catch(u){if(l)return;a(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 i=o.useCallback(async l=>{try{const c=Ir({...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:i}}function Ir(e){const t=e.llmApiKey,r=Sa(e),s=va(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 Dr(){const e=Ze.getState().settings;return Ir(e)}async function Na(e,t){const r={"Content-Type":"application/json",...Dr()},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 a=await s.json();return a.ok&&Array.isArray(a.suggestions)&&a.suggestions.length>0?a.suggestions:[]}function ka(e,t,r){const s=Ze(M=>M.settings),a=s.useLlmFollowUps,{minResponseLength:i=50,timeoutMs:l=8e3,heuristicsOnly:c}=r??{},u=c??!a,[d,f]=o.useState([]),[m,p]=o.useState(!1),[g,b]=o.useState(null),[h,w]=o.useState(null),y=o.useRef(""),x=o.useRef(null);return o.useEffect(()=>{if(!e||e.trim().length<i){f([]),w(null),p(!1),b(null);return}const M=e.slice(0,200)+e.length;if(M===y.current)return;if(y.current=M,x.current&&x.current.abort(),u){const F=Xn(e);f(F),w("heuristic"),p(!1),b(null);return}const C=new AbortController;x.current=C,p(!0),b(null);const K=Xn(e);f(K),w("heuristic");const E=t?`Context: ${t}
|
|
15
|
+
|
|
16
|
+
Assistant's response:
|
|
17
|
+
${e.slice(0,2e3)}`:`Assistant's response:
|
|
18
|
+
${e.slice(0,2e3)}`;return Na(E,C.signal).then(F=>{C.signal.aborted||(F.length>0&&(f(F),w("llm")),p(!1))}).catch(F=>{C.signal.aborted||(b(F instanceof Error?F.message:String(F)),p(!1))}),()=>{}},[e,t,i,l,u,s.llmApiKey,s.llmBaseUrl,s.llmModel,s.llmProvider]),{suggestions:d,isLoading:m,error:g,source:h}}function Ca({responseText:e,contextSummary:t,onSuggestionClick:r,disabled:s=!1,className:a}){const{suggestions:i,isLoading:l,source:c}=ka(e,t,{minResponseLength:50,timeoutMs:8e3});return i.length===0&&!l?null:n.jsxs("div",{className:A("flex flex-col gap-2 mt-3",a),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(X,{icon:or,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:i.map((u,d)=>n.jsxs("button",{type:"button",disabled:s,onClick:()=>r(u),className:A("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(X,{icon:mn,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 Bn=o.memo(Ca);function Ea({className:e,variant:t="outline",scrollRef:r,...s}){const[a,i]=o.useState(!0),[l,c]=o.useState(!1),u=o.useRef(0),d=o.useCallback(()=>{const f=r.current;if(!f)return;const m=Math.abs(f.scrollHeight-f.scrollTop-f.clientHeight)<100;i(m)},[r]);return o.useLayoutEffect(()=>{const f=r.current;if(!f)return;const m=()=>{u.current=f.scrollTop,d()},p=new MutationObserver(()=>{f&&(f.scrollTop!==u.current&&(u.current=f.scrollTop),d())});return d(),f.addEventListener("scroll",m),p.observe(f,{childList:!0,subtree:!0}),()=>{f.removeEventListener("scroll",m),p.disconnect()}},[d,r]),o.useLayoutEffect(()=>{if(a){c(!1);return}const f=window.setTimeout(()=>{c(!0)},200);return()=>window.clearTimeout(f)},[a]),n.jsx(xe,{variant:"secondary",size:"icon-sm",className:A("pointer-events-auto rounded-full shadow-md","transition-all duration-100 ease-in-out",!a&&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,i(!0))},...s,children:n.jsx(X,{icon:hn,size:18,strokeWidth:1.8})})}function Ta({className:e,viewportRef:t,scrollRef:r,viewportProps:s}){return n.jsxs(Nr,{className:A("relative flex flex-1 min-h-0 flex-col",e),children:[n.jsx(kr,{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(Ea,{scrollRef:r})})}),n.jsx(Cr,{orientation:"vertical",children:n.jsx(Er,{})}),n.jsx(yi,{})]})}function Ra(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 a of r)if(e[a]!==t[a])return!1;return!0}function Ma(e,t){return!(e.className!==t.className||e.viewportRef!==t.viewportRef||e.scrollRef!==t.scrollRef||!Ra(e.viewportProps,t.viewportProps))}const Aa=o.memo(Ta,Ma);function Ia({viewportNode:e,children:t}){return e?ts.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 Da({children:e,className:t,onUserScroll:r,...s}){const a=o.useRef(null),[i,l]=o.useState(null),c=o.useCallback(function(d){a.current=d,l(d)},[]);return o.useLayoutEffect(()=>{const u=a.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(Aa,{className:t,viewportRef:c,scrollRef:a,viewportProps:s}),n.jsx(Ia,{viewportNode:i,children:e})]})}const Oa=o.memo(Da);function La({children:e,className:t,...r}){return n.jsx("div",{className:A("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 Pa({...e}){return n.jsx("div",{className:"h-px w-full shrink-0 scroll-mt-4 pt-6","aria-hidden":"true",...e})}function _a({as:e="span",className:t,duration:r=4,spread:s=20,children:a,...i}){const l=Math.min(Math.max(s,5),45),c=e;return n.jsx(c,{className:A("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`},...i,children:a})}function Ka({className:e}){return n.jsxs("div",{className:A("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(_a,{className:"text-sm",duration:2,children:"Generating..."})]})}function za({messages:e,loading:t,empty:r,emptyState:s,notice:a,noticePosition:i="start",waitingForResponse:l,isStreaming:c=!1,sessionKey:u,pinToTop:d,pinGroupMinHeight:f,headerHeight:m,contentStyle:p,onFollowUpClick:g,jumpToMessageId:b}){const h=o.useRef(null),w=o.useRef(null),y=o.useRef(!1),x=o.useRef(d),M=o.useRef(void 0),[C,K]=o.useState(null),E=o.useMemo(()=>e.filter(N=>N.role!=="toolResult"),[e]),F=o.useMemo(()=>{const N=new Map;for(const j of e){if(j.role!=="toolResult")continue;const k=j.toolCallId;typeof k=="string"&&k.trim().length>0&&N.set(k,j)}return N},[e]),q=o.useMemo(()=>{const N=H=>H?H.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,`
|
|
19
|
+
`).trim():"",j=(H,G,J)=>{try{const ee=JSON.parse(H),Q=Array.isArray(ee)?ee:ee?.results??ee?.web?.results??[];if(!Array.isArray(Q))return!1;let re=!1;for(const Z of Q)Z?.url&&Z?.title&&!J.has(Z.url)&&(J.add(Z.url),G.push({title:N(Z.title),url:Z.url,snippet:N(Z.description||Z.snippet||Z.content||"")}),re=!0);return re}catch{return!1}},k=[],z=new Set;for(const H of E){if(H.role!=="assistant")continue;const G=Qe(H);for(const J of G){if(!J.id)continue;const ee=J.name==="web_search",Q=J.name==="web_fetch",re=J.name==="exec";if(!ee&&!Q&&!re)continue;const Z=F.get(J.id);if(!Z)continue;const te=Z.content?.map(Y=>Y.type==="text"?String(Y.text??""):"").join("").trim();if(te){if(ee||re){if(re&&(!te.includes('"results"')||!te.includes('"url"')))continue;let Y=te;const ye=te.indexOf("{");ye>0&&(Y=te.slice(ye));const ve=Y.lastIndexOf("}");ve>0&&(Y=Y.slice(0,ve+1)),j(Y,k,z)}else if(Q){const Y=J.arguments?.url;if(Y&&!z.has(Y)){z.add(Y);let ye;try{ye=new URL(Y).hostname}catch{ye=Y}k.push({title:ye,url:Y})}}}}}return k},[E,F]),D=E.map((N,j)=>({message:N,index:j})).filter(({message:N})=>N.role!=="user").map(({index:N})=>N).pop(),V=E.map((N,j)=>({message:N,index:j})).filter(({message:N})=>N.role==="assistant").map(({index:N})=>N).pop(),_=E.map((N,j)=>({message:N,index:j})).filter(({message:N})=>N.role==="user").map(({index:N})=>N).pop(),S=l&&(typeof _!="number"||typeof D!="number"||D<_),I=typeof _=="number"?_:-1,R=d&&I>=0,T=typeof V=="number"?E[V]:void 0,U=T?Le(T):"",L=!l&&!c&&U.length>0&&g!==void 0&&(typeof _!="number"||typeof V!="number"||V>_);return o.useLayoutEffect(()=>{if(!t){if(d){const N=!x.current||M.current!==_;x.current=!0,M.current=_,N&&w.current&&(y.current=!0,w.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{y.current=!1},0));return}x.current=!1,M.current=_,h.current&&(y.current=!0,h.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{y.current=!1},0))}},[t,E.length,u,d,_]),o.useEffect(()=>{if(!b||t)return;const N=document.getElementById(`message-${b}`);if(!N)return;N.scrollIntoView({behavior:"smooth",block:"center"}),K(b);const j=window.setTimeout(()=>{K(k=>k===b?null:k)},1800);return()=>window.clearTimeout(j)},[b,t,E]),n.jsx(Oa,{className:"flex-1 min-h-0 -mb-4",children:n.jsxs(La,{className:"pt-6",style:p,children:[a&&i==="start"?a:null,r&&!a?s??n.jsx("div",{"aria-hidden":!0}):R?n.jsxs(n.Fragment,{children:[E.slice(0,I).map((N,j)=>{const k=typeof N.id=="string"?N.id:void 0,z=k||j,H=typeof D=="number"&&j===D,G=typeof D=="number"&&j===D,J=N.role==="assistant"&&Qe(N).length>0;return n.jsx(Zt,{message:N,toolResultsByCallId:J?F:void 0,forceActionsVisible:H,isStreaming:G&&c,isLastAssistant:G,aggregatedSearchSources:G?q:void 0,messageDomId:k?`message-${k}`:void 0,highlighted:C===k},z)}),n.jsxs("div",{className:"flex flex-col gap-[var(--opencami-msg-gap)]",style:{minHeight:`${Math.max(0,f)}px`},children:[E.slice(I).map((N,j)=>{const k=I+j,z=typeof N.id=="string"?N.id:void 0,H=z||k,G=typeof D=="number"&&k===D,J=typeof D=="number"&&k===D,ee=k===_?w:void 0,Q=k===_?"scroll-mt-0":void 0,re=k===_?m:void 0,Z=N.role==="assistant"&&Qe(N).length>0;return n.jsx(Zt,{message:N,toolResultsByCallId:Z?F:void 0,forceActionsVisible:G,isStreaming:J&&c,isLastAssistant:J,aggregatedSearchSources:J?q:void 0,wrapperRef:ee,wrapperClassName:Q,wrapperScrollMarginTop:re,messageDomId:z?`message-${z}`:void 0,highlighted:C===z},H)}),S?n.jsx("div",{className:"py-2",children:n.jsx(Ka,{})}):null,L&&g?n.jsx(Bn,{responseText:U,onSuggestionClick:g,disabled:l}):null]})]}):n.jsxs(n.Fragment,{children:[E.map((N,j)=>{const k=typeof N.id=="string"?N.id:void 0,z=k||j,H=typeof D=="number"&&j===D,G=typeof D=="number"&&j===D,J=N.role==="assistant"&&Qe(N).length>0;return n.jsx(Zt,{message:N,toolResultsByCallId:J?F:void 0,forceActionsVisible:H,isStreaming:G&&c,isLastAssistant:G,aggregatedSearchSources:G?q:void 0,messageDomId:k?`message-${k}`:void 0,highlighted:C===k},z)}),L&&g?n.jsx(Bn,{responseText:U,onSuggestionClick:g,disabled:l}):null]}),a&&i==="end"?a:null,n.jsx(Pa,{ref:h})]})})}function Ua(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 $a=o.memo(za,Ua),Or=o.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:ns.createRef()});let ct=null,Gn=!1;function Fa(){Gn||typeof window>"u"||(Gn=!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,a=e.key==="Backspace";!s&&!a||!ct||ct.disabled||ct.focus()}))}function Lr(){return o.useContext(Or)}function Ha({className:e,isLoading:t=!1,maxHeight:r=240,value:s,onValueChange:a,onSubmit:i,children:l,disabled:c=!1,onClick:u,...d}){const[f,m]=o.useState(s||""),p=o.useRef(null);Fa();function g(h){m(h),a?.(h)}function b(h){c||p.current?.focus(),u?.(h)}return n.jsx(Me,{children:n.jsx(Or.Provider,{value:{isLoading:t,value:s??f,setValue:a??g,maxHeight:r,onSubmit:i,disabled:c,textareaRef:p},children:n.jsx("div",{onClick:b,className:A("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 Wa({className:e,onKeyDown:t,disableAutosize:r=!1,inputRef:s,...a}){const{value:i,setValue:l,maxHeight:c,onSubmit:u,disabled:d,textareaRef:f}=Lr();function m(h){!h||r||(h.style.height="auto",typeof c=="number"?h.style.height=`${Math.min(h.scrollHeight,c)}px`:h.style.height=`min(${h.scrollHeight}px, ${c})`)}function p(h){f.current=h,typeof s=="function"?s(h):s&&"current"in s&&(s.current=h),h?ct=h:ct===h&&(ct=null),m(h)}o.useLayoutEffect(()=>{if(!f.current||r)return;const h=f.current;h.style.height="auto",typeof c=="number"?h.style.height=`${Math.min(h.scrollHeight,c)}px`:h.style.height=`min(${h.scrollHeight}px, ${c})`},[i,c,r]);function g(h){m(h.target),l(h.target.value)}function b(h){h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),u?.()),t?.(h)}return n.jsx("textarea",{ref:p,value:i,onChange:g,onKeyDown:b,className:A("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,...a})}function Xa({children:e,className:t,...r}){return n.jsx("div",{className:A("flex items-center gap-2",t),...r,children:e})}function qn({tooltip:e,children:t,className:r,side:s="top",...a}){const{disabled:i}=Lr();return n.jsxs(Ae,{...a,children:[n.jsx(Ie,{disabled:i,onClick:l=>l.stopPropagation(),children:t}),n.jsx(De,{side:s,className:r,children:e})]})}const Pr="opencami-selected-model";function Ya(){if(typeof window>"u")return null;try{return localStorage.getItem(Pr)}catch{return null}}function Ba(e){if(!(typeof window>"u"))try{localStorage.setItem(Pr,e)}catch{}}function Ga({className:e,onModelChange:t}){const[r,s]=o.useState([]),[a,i]=o.useState(""),[l,c]=o.useState(!0),[u,d]=o.useState(null),f=o.useRef(null);o.useEffect(()=>{let h=!0;async function w(){f.current?.abort();const y=new AbortController;f.current=y;try{c(!0),d(null);const x=await fetch("/api/models",{signal:y.signal});if(!x.ok)throw new Error("Failed to fetch models");const M=await x.json();if(!h)return;if(M.ok&&M.models.length>0){s(M.models);const C=Ya(),K=C&&M.models.some(E=>E.id===C)?C:M.defaultModel;i(K),t?.(K)}else throw new Error("No models available")}catch(x){if(x instanceof Error&&x.name==="AbortError"||!h)return;console.error("[model-selector] Error fetching models:",x),d(x instanceof Error?x.message:"Failed to load models"),s([{id:"default",name:"Default Model"}]),i("default")}finally{h&&c(!1)}}return w(),()=>{h=!1,f.current?.abort()}},[t]);function m(h){i(h),Ba(h),t?.(h)}if(l)return n.jsxs("div",{className:A("flex items-center gap-2 text-xs text-primary-500",e),children:[n.jsx(X,{icon:Yt,size:14}),n.jsx("span",{children:"Loading..."})]});if(u||r.length===0)return null;const p=r.find(h=>h.id===a),g=p?.name||"Select Model",b=(()=>{if(!p?.name)return g;const w=p.name.replace(/\s*\([^)]*\)\s*$/,"").trim(),y=w.split(/\s+/);return y.length>3?y.slice(0,3).join(" "):w})();return r.length===1?n.jsxs("div",{className:A("flex items-center gap-2 text-xs text-primary-500",e),children:[n.jsx(X,{icon:Yt,size:14}),n.jsx("span",{className:"font-[450] md:hidden",children:b}),n.jsx("span",{className:"font-[450] hidden md:inline",children:g})]}):n.jsxs($t,{children:[n.jsxs(Ft,{className:A("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(X,{icon:Yt,size:14}),n.jsx("span",{className:"md:hidden",children:b}),n.jsx("span",{className:"hidden md:inline",children:g})]}),n.jsx(Ht,{side:"top",align:"start",children:r.map(h=>n.jsxs(Ye,{onClick:()=>m(h.id),className:"justify-between min-w-[180px]",children:[n.jsx("span",{children:h.name}),a===h.id&&n.jsx(X,{icon:pn,size:14,className:"text-primary-600"})]},h.id))})]})}const _r="opencami-personas-enabled",un="opencami-active-persona";function qa(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(_r);return e===null?!0:e==="true"}catch{return!0}}function Va(){if(typeof window>"u")return null;try{const e=localStorage.getItem(un);return e?JSON.parse(e):null}catch{return null}}function Vn(e){if(!(typeof window>"u"))try{e?localStorage.setItem(un,JSON.stringify(e)):localStorage.removeItem(un)}catch{}}const Ja={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function Qa({className:e,onSelect:t}){const[r,s]=o.useState({}),[a,i]=o.useState(null),[l,c]=o.useState(!0),[u,d]=o.useState(!1),[f,m]=o.useState(qa),p=o.useRef(null);o.useEffect(()=>{const w=y=>{y.key===_r&&m(y.newValue===null?!0:y.newValue==="true")};return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[]),o.useEffect(()=>{let w=!0;async function y(){p.current?.abort();const x=new AbortController;p.current=x;try{c(!0);const M=await fetch("/api/personas",{signal:x.signal});if(!M.ok){d(!1);return}const C=await M.json();if(!w)return;C.ok&&C.available?(s(C.personas),d(!0),i(Va())):d(!1)}catch(M){if(M instanceof Error&&M.name==="AbortError"||!w)return;d(!1)}finally{w&&c(!1)}}return y(),()=>{w=!1,p.current?.abort()}},[]);const g=o.useCallback(w=>{i(w),Vn(w),t(`/persona ${w.id}`)},[t]),b=o.useCallback(()=>{i(null),Vn(null),t("/persona exit")},[t]);if(l||!u||!f)return null;const h=Object.entries(r);return h.length===0?null:n.jsxs($t,{children:[n.jsxs(Ft,{className:A("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:"🎭"}),a?n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{children:a.emoji}),n.jsx("span",{children:a.name})]}):n.jsx("span",{children:"Persona"})]}),n.jsxs(Ht,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[a&&n.jsxs(n.Fragment,{children:[n.jsxs(Ye,{onClick:b,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:[a.emoji," ",a.name]})]}),n.jsx("div",{className:"my-1 h-px bg-primary-200"})]}),h.map(([w,y])=>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:Ja[w]??w}),y.map(x=>n.jsxs(Ye,{onClick:()=>g(x),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:x.emoji}),n.jsx("span",{className:"truncate",children:x.name})]}),n.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:x.description})]},x.id))]},w))]})]})}const Za=[{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 el({className:e,onCommandSelect:t}){const[r,s]=o.useState(!1);function a(i){t?.(i),s(!1)}return n.jsxs(n.Fragment,{children:[n.jsx(xe,{variant:"ghost",size:"sm",onClick:()=>s(!0),className:A("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:n.jsx(X,{icon:Tn,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(X,{icon:Tn,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(xe,{variant:"ghost",size:"sm",onClick:()=>s(!1),className:"h-7 w-7 p-0",children:n.jsx(X,{icon:Ut,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"}),Za.map(i=>n.jsxs("button",{onClick:()=>a(i.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:i.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:i.description}),i.usage&&i.usage!==i.command&&n.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-500 font-mono mt-0.5",children:i.usage})]})]},i.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 tl=10*1024*1024,at=1280,nl=.75,rl=300*1024,sl=["image/png","image/jpeg","image/gif","image/webp"],Kr=["pdf","txt","md","csv","json","xml","yaml","yml","log","py","js","ts","html","css"],ol=[".png",".jpg",".jpeg",".gif",".webp",...Kr.map(e=>`.${e}`)].join(",");function il(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function al(e){if(!il())throw new Error("Image compression not available in this browser");return new Promise((t,r)=>{const s=new Image,a=URL.createObjectURL(e),i=()=>{URL.revokeObjectURL(a)};s.onload=()=>{try{let l=s.width,c=s.height;(l>at||c>at)&&(l>c?(c=Math.round(c*at/l),l=at):(l=Math.round(l*at/c),c=at));const u=document.createElement("canvas");u.width=l,u.height=c;const d=u.getContext("2d");if(!d){i(),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 m=nl,p=u.toDataURL(f,m);if(f==="image/jpeg"){const b=rl*1.37;for(;p.length>b&&m>.3;)m-=.1,p=u.toDataURL(f,m)}const g=p.split(",")[1];if(!g){i(),r(new Error("Failed to encode image"));return}i(),t(g)}catch(l){i(),r(l instanceof Error?l:new Error("Image compression failed"))}},s.onerror=()=>{i(),r(new Error("Failed to load image"))},s.src=a})}function zr(e){return sl.includes(e.type)}function ll(e){const t=e.name.includes(".")?e.name.split(".").pop()?.toLowerCase():"";return!!(t&&Kr.includes(t))}async function cl(e){const t=crypto.randomUUID();if(!zr(e))return{id:t,file:e,preview:null,type:"file",base64:null,error:"Unsupported image type. Please use PNG, JPG, GIF, or WebP images."};if(e.size>tl)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const r=await al(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 ul({onFilesSelect:e,disabled:t=!1,className:r}){const s=o.useRef(null),a=o.useCallback(()=>{s.current?.click()},[]),i=o.useCallback(async l=>{const c=Array.from(l.target.files??[]);c.length!==0&&(l.target.value="",e(c))},[e]);return n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:s,type:"file",accept:ol,multiple:!0,onChange:i,className:"hidden","aria-hidden":"true"}),n.jsx(xe,{variant:"ghost",size:"icon-sm",onClick:a,disabled:t,className:r,"aria-label":"Attach file",type:"button",children:n.jsx(X,{icon:Ns,size:18,strokeWidth:1.8})})]})}function Jn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function dl(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function fl({attachment:e,onRemove:t,className:r}){o.useEffect(()=>()=>{e.preview&&URL.revokeObjectURL(e.preview)},[e.preview]);const s=!!e.error;return e.type==="file"&&!s?n.jsxs("div",{className:A("inline-flex max-w-full items-center gap-2 rounded-full border border-primary-200 bg-primary-50 px-3 py-1.5 text-xs text-primary-800",r),children:[n.jsxs("span",{className:"truncate",children:["📄 ",e.file.name," (",Jn(e.file.size),")"]}),n.jsx("button",{onClick:()=>t(e.id),className:"shrink-0 text-primary-500 hover:text-primary-800","aria-label":"Remove attachment",type:"button",children:"✕"})]}):n.jsxs("div",{className:A("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(X,{icon:ir,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:[dl(e.file.name)," •"," ",Jn(e.file.size)]})]}),n.jsx(xe,{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(X,{icon:Ut,size:14})})]})}function ml({attachments:e,onRemove:t,className:r}){return e.length===0?null:n.jsx("div",{className:A("flex flex-wrap gap-2 px-4",r),children:e.map(s=>n.jsx(fl,{attachment:s,onRemove:t},s.id))})}function pl({commands:e,selectedIndex:t,onSelect:r,className:s}){return e.length===0?null:n.jsx("div",{className:A("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((a,i)=>{const l=i===t;return n.jsx("button",{type:"button",role:"option","aria-selected":l,onMouseDown:c=>{c.preventDefault(),r(a)},className:A("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:a.command}),n.jsx("span",{className:"text-xs text-neutral-300",children:a.description})]})},a.command)})})})}const hl=o.memo(pl),dn=pr()(mr(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function gl(){const e=dn(r=>r.level),t=dn(r=>r.setLevel);return{level:e,setLevel:t}}const en=[{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 xl({className:e}){const{level:t,setLevel:r}=gl(),s=en.find(a=>a.value===t)??en[1];return n.jsxs($t,{children:[n.jsxs(Ft,{className:A("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(X,{icon:rn,size:20,strokeWidth:1.5,className:A(t==="off"?"text-primary-400":"text-primary-700")}),n.jsx("span",{className:"text-pretty",children:s.shortLabel})]}),n.jsx(Ht,{side:"top",align:"start",className:"min-w-[190px]",children:en.map(a=>n.jsxs(Ye,{onClick:()=>r(a.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:a.label}),n.jsx("span",{className:"text-xs text-primary-500",children:a.description})]}),t===a.value&&n.jsx(X,{icon:pn,size:20,strokeWidth:1.5,className:"text-primary-600"})]},a.value))})]})}const Qn=[{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 yl({onSubmit:e,isLoading:t,disabled:r,wrapperRef:s,inputRef:a}){const[i,l]=o.useState(""),[c,u]=o.useState(""),[d,f]=o.useState([]),[m,p]=o.useState(0),[g,b]=o.useState(!1),[h,w]=o.useState(!1),[y,x]=o.useState(!1),[M,C]=o.useState(0),[K,E]=o.useState(!1),F=o.useRef(null),q=o.useRef([]),D=o.useRef(null),V=o.useRef(null),_=o.useRef(null),S=o.useRef(null),I=o.useMemo(()=>/^\/\S*$/.test(i)&&!g,[i,g]),R=o.useMemo(()=>I?i.slice(1).toLowerCase():"",[I,i]),T=o.useMemo(()=>I?R?Qn.filter(O=>O.command.slice(1).toLowerCase().startsWith(R)):Qn:[],[I,R]),U=o.useCallback(O=>{S.current=O,a&&(typeof a=="function"?a(O):a.current=O)},[a]),L=o.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{S.current?.focus()})},[]),N=o.useCallback(()=>{l(""),f([]),p(0),b(!1),L()},[L]),j=o.useCallback(O=>{l(B=>{const W=`📎 Uploaded file: ${O}
|
|
20
|
+
|
|
21
|
+
Please analyze this file.`;return B.trim()?`${B.trim()}
|
|
22
|
+
|
|
23
|
+
${W}`:W})},[]),k=o.useCallback(async()=>{await fetch("/api/files/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:"/uploads"})})},[]),z=o.useCallback(async O=>{const B=crypto.randomUUID();if(!ll(O))return{id:B,file:O,preview:null,type:"file",base64:null,error:"Unsupported file type for upload."};try{await k();const W=new FormData;W.append("path","/uploads"),W.append("file",O);const se=await fetch("/api/files/upload",{method:"POST",body:W});if(!se.ok){const je=await se.text();throw new Error(je||"File upload failed")}const ne=(await se.json()).files?.[0]?.path;if(!ne)throw new Error("Upload succeeded but no path was returned");return j(ne),{id:B,file:O,preview:null,type:"file",base64:null,uploadedPath:ne}}catch(W){return{id:B,file:O,preview:null,type:"file",base64:null,error:W instanceof Error?W.message:"File upload failed"}}},[j,k]),H=o.useCallback(async O=>{if(O.length===0)return;const B=await Promise.all(O.map(W=>zr(W)?cl(W):z(W)));f(W=>[...W,...B]),L()},[L,z]),G=o.useCallback(O=>{f(B=>B.filter(W=>W.id!==O))},[]),J=o.useCallback(O=>{Array.from(O.dataTransfer.types).includes("Files")&&(O.preventDefault(),O.dataTransfer.dropEffect="copy",w(!0))},[]),ee=o.useCallback(O=>{O.preventDefault();const B=O.relatedTarget;B&&O.currentTarget.contains(B)||w(!1)},[]),Q=o.useCallback(async O=>{O.preventDefault(),w(!1);const B=Array.from(O.dataTransfer.files??[]);B.length!==0&&await H(B)},[H]),re=o.useCallback(O=>{l(O),p(0),b(!1),L()},[L]),Z=o.useCallback(O=>{l(O),p(0),b(!1)},[]),te=o.useCallback(O=>{l(`${O.command} `),p(0),b(!1),L()},[L]),Y=o.useCallback(()=>{if(r)return;if(I&&T.length>0){const W=Math.min(m,T.length-1);te(T[W]);return}const O=i.trim(),B=d.filter(W=>!W.error&&W.base64);O.length===0&&B.length===0||(e(O,{reset:N,setValue:re,model:c||void 0,attachments:B}),L())},[r,I,T,m,te,i,d,e,N,re,c,L]),ye=o.useCallback(O=>{e(O,{reset:N,setValue:re,model:c||void 0,attachments:[]}),L()},[L,e,N,re,c]),ve=o.useCallback(O=>{if(I){if(O.key==="Escape"){O.preventDefault(),b(!0),p(0);return}if(T.length!==0){if(O.key==="ArrowDown"){O.preventDefault(),p(B=>(B+1)%T.length);return}if(O.key==="ArrowUp"){O.preventDefault(),p(B=>(B-1+T.length)%T.length);return}if(O.key==="Tab"){O.preventDefault();const B=Math.min(m,T.length-1);te(T[B])}}}},[I,T,m,te]);o.useEffect(()=>()=>{V.current?.abort(),D.current&&clearInterval(D.current),F.current&&F.current.state!=="inactive"&&F.current.stop(),_.current&&_.current.abort()},[]);const de=o.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),ae=o.useCallback(()=>{F.current&&F.current.state!=="inactive"&&F.current.stop(),_.current&&_.current.stop(),D.current&&(clearInterval(D.current),D.current=null),x(!1),C(0)},[]),ge=o.useCallback(async()=>{const O=de();if(O==="browser"){const B=window.SpeechRecognition||window.webkitSpeechRecognition;if(!B){alert("Web Speech API is not supported in this browser.");return}const W=new B;W.continuous=!0,W.interimResults=!1,W.lang=navigator.language||"en-US",_.current=W,x(!0),C(0),D.current=setInterval(()=>{C(oe=>oe>=119?(ae(),0):oe+1)},1e3);let se="";W.onresult=oe=>{for(let ne=oe.resultIndex;ne<oe.results.length;ne++)oe.results[ne].isFinal&&(se+=oe.results[ne][0].transcript)},W.onend=()=>{x(!1),C(0),D.current&&clearInterval(D.current),se.trim()&&(l(oe=>oe+(oe?" ":"")+se.trim()),L())},W.onerror=()=>{x(!1),C(0),D.current&&clearInterval(D.current)},W.start();return}try{const B=await navigator.mediaDevices.getUserMedia({audio:!0}),W=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",se=new MediaRecorder(B,{mimeType:W});F.current=se,q.current=[],se.ondataavailable=oe=>{oe.data.size>0&&q.current.push(oe.data)},se.onstop=async()=>{B.getTracks().forEach(ne=>ne.stop());const oe=new Blob(q.current,{type:W});if(oe.size!==0){E(!0);try{const ne=new FormData;ne.append("audio",oe,`recording.${W==="audio/webm"?"webm":"mp4"}`),O!=="auto"&&ne.append("provider",O),V.current?.abort();const je=new AbortController;V.current=je;const pe=await(await fetch("/api/stt",{method:"POST",body:ne,signal:je.signal})).json();pe.ok&&pe.text?(l(Te=>Te+(Te?" ":"")+pe.text),L()):pe.ok||(console.warn("STT failed:",pe.error),alert(pe.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(ne){if(ne instanceof Error&&ne.name==="AbortError")return;console.warn("STT request failed:",ne),alert("Could not reach speech-to-text service.")}finally{E(!1)}}},x(!0),C(0),D.current=setInterval(()=>{C(oe=>oe>=119?(ae(),0):oe+1)},1e3),se.start()}catch(B){const W=B instanceof Error?B.message:String(B);if(W.includes("NotAllowedError")||W.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: "+W)}},[de,ae,L]),fe=o.useCallback(()=>{y?ae():ge()},[y,ae,ge]),P=d.filter(O=>!O.error&&O.base64),me=r||i.trim().length===0&&P.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:J,onDragLeave:ee,onDrop:Q,children:[h&&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 files here"}),n.jsxs(Ha,{value:i,onValueChange:Z,onSubmit:Y,isLoading:t,disabled:r,children:[n.jsx(ml,{attachments:d,onRemove:G}),I&&T.length>0&&n.jsx(hl,{commands:T,selectedIndex:Math.min(m,T.length-1),onSelect:te}),n.jsx(Wa,{placeholder:"Type a message…",inputRef:U,onKeyDown:ve}),n.jsxs(Xa,{className:"justify-between px-3",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(Ga,{onModelChange:u}),n.jsx(xl,{}),n.jsx(Qa,{onSelect:ye}),n.jsx(el,{onCommandSelect:O=>Z(O+" ")})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(ul,{onFilesSelect:H,disabled:r}),n.jsx(qn,{tooltip:y?"Stop recording":"Voice input",children:n.jsx(xe,{onClick:fe,disabled:r||K,size:"icon-sm",variant:y?"destructive":"ghost",className:`rounded-full ${y?"animate-pulse":""}`,"aria-label":y?"Stop recording":"Voice input",children:K?n.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):y?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(M/60),":",String(M%60).padStart(2,"0")]}),n.jsx(X,{icon:sr,size:14,strokeWidth:2})]}):n.jsx(X,{icon:ks,size:18,strokeWidth:2})})}),n.jsx(qn,{tooltip:"Send message",children:n.jsx(xe,{onClick:Y,disabled:me,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:n.jsx(X,{icon:Cs,size:18,strokeWidth:2})})})]})]})]})]})}const wl=o.memo(yl);function bl({title:e,description:t,detail:r,actionLabel:s,onAction:a,className:i}){return n.jsx("div",{className:A("w-full max-w-[var(--opencami-chat-width)]",i),children:n.jsx(Mr,{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&&a?n.jsx("div",{className:"mt-3",children:n.jsx(xe,{size:"sm",variant:"outline",onClick:a,children:s})}):null]})})})}function Sl({state:e,error:t,onRetry:r,className:s}){const a=e==="checking",i=a?"Checking gateway connection...":"OpenClaw gateway is unreachable",l=a?"This dashboard needs access to the OpenClaw gateway configured by your server environment variables.":"";return n.jsx(bl,{title:i,description:a?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:a?null:t,actionLabel:a?void 0:"Retry",onAction:a?void 0:r,className:s})}function vl(){const e=o.useRef(null),t=o.useRef(null),r=o.useRef(null),[s,a]=o.useState(0),[i,l]=o.useState(0);return o.useLayoutEffect(()=>{const c=e.current,u=t.current,d=r.current;if(!d)return;const f=()=>{const p=c?.offsetHeight??0,g=u?.offsetHeight??0,b=d.clientHeight;d.style.setProperty("--chat-header-height",`${Math.max(0,p)}px`),d.style.setProperty("--chat-composer-height",`${Math.max(0,g)}px`),l(p),a(Math.max(0,b-p-g))};f();const m=new ResizeObserver(()=>f());return c&&m.observe(c),u&&m.observe(u),()=>m.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:r,pinGroupMinHeight:s,headerHeight:i}}function jl({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:r,isNewChat:s,isRedirecting:a,activeExists:i,sessionsReady:l,queryClient:c}){const u=r||t||e,d=ue.history(e,u),f=Mt({queryKey:d,queryFn:async function(){const x=c.getQueryData(d),M=Array.isArray(x?.messages)?x.messages.filter(E=>E.status==="sending"||E.__optimisticId?!0:!!E.clientId):[],C=await mo({sessionKey:u,friendlyId:e});if(!M.length)return C;const K=Nl(C.messages,M);return{...C,messages:K}},enabled:!s&&!!e&&!a&&(!l||i),placeholderData:function(){return c.getQueryData(d)},gcTime:1e3*60*10}),m=o.useRef(""),p=o.useRef([]),g=o.useMemo(()=>{const y=Array.isArray(f.data?.messages)?f.data.messages:[],x=y[y.length-1],M=x&&typeof x.id=="string"?x.id:"",C=`${y.length}:${x?.role??""}:${M}:${Le(x??{content:[]}).slice(-32)}`;return C===m.current?p.current:(m.current=C,p.current=y,y)},[f.data?.messages]),b=f.error instanceof Error?f.error.message:null,h=o.useMemo(()=>{if(r)return r;const y=f.data?.sessionKey;return typeof y=="string"&&y.trim().length>0?y.trim():t},[t,r,f.data?.sessionKey]);return{historyQuery:f,historyMessages:g,displayMessages:g,historyError:b,resolvedSessionKey:h,activeCanonicalKey:s?"new":h||e,sessionKeyForHistory:u}}function Nl(e,t){if(!t.length)return e;const r=[...e];for(const s of t)e.some(i=>{if(s.clientId&&i.clientId&&s.clientId===i.clientId||s.__optimisticId&&i.__optimisticId&&s.__optimisticId===i.__optimisticId)return!0;if(s.role&&i.role&&s.role!==i.role)return!1;const l=Le(s);if(!l||l!==Le(i))return!1;const c=on(s),u=on(i);return Math.abs(c-u)<=1e4})||r.push(s);return r}function kl(e){const[t,r]=o.useState(!1);return o.useLayoutEffect(()=>{const s=window.matchMedia("(max-width: 768px)"),a=()=>r(s.matches);return a(),s.addEventListener("change",a),()=>s.removeEventListener("change",a)},[]),o.useLayoutEffect(()=>{t&&We(e,function(a){return{...a,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function Cl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}){const s=Mt({queryKey:ue.sessions,queryFn:fo,refetchInterval:3e4}),a=o.useMemo(()=>{const m=s.data??[];return Ro(m)},[s.data]),i=o.useMemo(()=>a.find(m=>m.friendlyId===e),[a,e]),l=o.useMemo(()=>t||r||gr(e)?!0:a.some(m=>m.friendlyId===e),[e,r,t,a]),c=i?.key??"",u=o.useMemo(()=>i?i.label||i.title||i.derivedTitle||i.friendlyId:e,[e,i]),d=s.error instanceof Error?s.error.message:null,f=o.useMemo(()=>({totalTokens:i?.totalTokens,contextTokens:i?.contextTokens}),[i?.totalTokens,i?.contextTokens]);return{sessionsQuery:s,sessions:a,activeSession:i,activeExists:l,activeSessionKey:c,activeTitle:u,activeTokens:f,sessionsError:d}}function El(){const e=Ze(d=>d.settings),[t,r]=o.useState(!1),[s,a]=o.useState(null),[i,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 m={"Content-Type":"application/json",...Dr()},p=await fetch("/api/llm-features",{method:"POST",headers:m,body:JSON.stringify({action:"title",message:d}),signal:f.signal});if(!p.ok)throw new Error(`API error: ${p.status}`);const g=await p.json();if(f.signal.aborted)throw new Error("Aborted");const b=g.title||d.slice(0,50),h=b.length>64?b.slice(0,61)+"...":b,w=g.source||"heuristic";return a(h),l(w),{title:h,source:w,error:g.error}}catch(m){if(m instanceof Error&&m.name==="AbortError")throw m;const p=Tl(d);return a(p),l("heuristic"),{title:p,source:"heuristic",error:m instanceof Error?m.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:i}}function Tl(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 a=t.split(/\s+/).filter(i=>{if(i.length<=2){const l=i.toUpperCase();return["AI","ML","UI","UX","API","CSS","JS"].includes(l)}return!0}).slice(0,6).join(" ");return a=a.replace(/[.,!?]+$/,""),a.length>60&&(a=a.slice(0,57)+"..."),a||e.slice(0,50)}function Rl(){return Ze(e=>e.settings.useLlmTitles)}const tn={active:!1,text:"",tools:[],sessionKey:null};function Ml(e){const[t,r]=o.useState(tn),s=o.useRef(null),a=o.useRef(null),i=o.useRef(null),l=o.useRef(null),c=o.useRef(!1),u=o.useRef(e.onDone),d=o.useRef(e.onError),f=o.useRef(e.onAssistantDelta);u.current=e.onDone,d.current=e.onError,f.current=e.onAssistantDelta;function m(){i.current&&(window.clearTimeout(i.current),i.current=null),a.current&&(window.clearInterval(a.current),a.current=null)}function p(h,w){a.current||(a.current=window.setInterval(async()=>{try{const y=await fetch(`/api/history?sessionKey=${encodeURIComponent(h)}`);if(!y.ok)return;const x=await y.json();if(!(Array.isArray(x.messages)?x.messages:[]).some(K=>!K||K.role!=="assistant"||typeof K.timestamp!="number"?!1:K.timestamp>w-3e3))return;s.current&&(s.current.close(),s.current=null),m(),r(K=>({...K,active:!1})),u.current(h)}catch{}},2e3))}const g=o.useCallback(h=>{if(c.current=!0,m(),s.current&&(s.current.close(),s.current=null),h?.preserveState){r(w=>({...w,active:!1}));return}r(tn)},[]),b=o.useCallback(function(w){c.current=!1,m(),l.current=Date.now(),s.current&&(s.current.close(),s.current=null),r({active:!0,text:"",tools:[],sessionKey:w});const y=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(w)}`);s.current=y,y.addEventListener("delta",x=>{try{const M=JSON.parse(x.data);r(C=>({...C,text:C.text+M.text})),f.current?.({text:M.text,sessionKey:M.sessionKey})}catch{}}),y.addEventListener("tool",x=>{try{const M=JSON.parse(x.data);r(C=>{const K=C.tools.findIndex(F=>F.id===M.id),E=[...C.tools];return K>=0?E[K]={name:M.name,status:M.status,id:M.id}:E.push({name:M.name,status:M.status,id:M.id}),{...C,tools:E}})}catch{}}),y.addEventListener("done",x=>{try{const M=JSON.parse(x.data);c.current=!0,m(),y.close(),s.current=null,r(C=>({...C,active:!1})),u.current(M.sessionKey)}catch{}}),y.onerror=()=>{y.readyState===EventSource.CLOSED&&(y.close(),s.current=null,r(tn),d.current?.("Stream connection lost"))},i.current=window.setTimeout(()=>{if(c.current)return;const x=l.current??Date.now();p(w,x)},3e3)},[]);return{streaming:t,startStream:b,stopStream:g}}function Al(e){const t=o.useCallback(r=>{const s=r.target,a=s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable;if(r.key==="Escape"){e.onEscape?.();return}if(r.key==="?"&&!a&&!r.metaKey&&!r.ctrlKey){r.preventDefault(),e.onShowHelp?.();return}if(a)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 Zn(e){const{threshold:t=50,edgeWidth:r,onMove:s,onSwipe:a,onCancel:i,direction:l,enabled:c=!0}=e,u=o.useRef({startX:0,startY:0,tracking:!1,directionLocked:!1}),d=o.useCallback(p=>{if(!c)return;const g=p.touches[0];g&&(r!==void 0&&g.clientX>r||(u.current={startX:g.clientX,startY:g.clientY,tracking:!0,directionLocked:!1}))},[c,r]),f=o.useCallback(p=>{const g=u.current;if(!g.tracking)return;const b=p.touches[0];if(!b)return;const h=b.clientX-g.startX,w=b.clientY-g.startY,y=Math.abs(h),x=Math.abs(w);if(!g.directionLocked){if(y<5&&x<5)return;if(x>y){g.tracking=!1,i?.();return}g.directionLocked=!0}l==="left"&&h>0||l==="right"&&h<0||(p.preventDefault(),s?.(h))},[l,s,i]),m=o.useCallback(p=>{const g=u.current;if(!g.tracking)return;g.tracking=!1;const b=p.changedTouches[0];if(!b){i?.();return}const h=b.clientX-g.startX,w=Math.abs(h);if(!g.directionLocked||w<t){i?.();return}const y=h>0?"right":"left";if(l&&y!==l){i?.();return}a(y)},[l,i,a,t]);return{onTouchStart:d,onTouchMove:f,onTouchEnd:m}}const Ur="opencami-browser-notifications-enabled",nn="opencami-browser-notifications-permission-asked",Il=5e3;function kt(){return typeof window<"u"&&"Notification"in window}function er(){if(typeof window>"u")return!1;try{return localStorage.getItem(Ur)==="true"}catch{return!1}}function Dl(){const e=zt(),t=o.useRef(0),[r,s]=o.useState(()=>er()),a=o.useCallback(async()=>{if(!kt())return"denied";try{return await Notification.requestPermission()}catch{return"denied"}},[]),i=o.useCallback(async c=>{s(c);try{localStorage.setItem(Ur,String(c))}catch{}if(c&&kt()&&Notification.permission==="default"){await a();try{localStorage.setItem(nn,"true")}catch{}}},[a]),l=o.useCallback(c=>{if(!r||!kt()||document.hidden!==!0||Notification.permission!=="granted")return;const u=Date.now();if(u-t.current<Il)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(nn)==="true"}catch{d=!1}d||a().finally(()=>{try{localStorage.setItem(nn,"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)}},[a]),o.useEffect(()=>{const c=()=>s(er());return window.addEventListener("storage",c),()=>window.removeEventListener("storage",c)},[]),{notificationsEnabled:r,setNotificationsEnabled:i,requestNotificationPermission:a,maybeNotifyAssistantMessage:l}}const Ol=o.lazy(()=>Kt(()=>import("./keyboard-shortcuts-dialog-BZwd-iyV.js"),__vite__mapDeps([26,1,4,3,5,6,7,8,9,2])).then(e=>({default:e.KeyboardShortcutsDialog}))),Ll=o.lazy(()=>Kt(()=>import("./search-dialog-DW91SK30.js"),__vite__mapDeps([27,1,3,4,5,6,7,8,9,2,17,18,14,19,11,15,20,13,21,22,23,16,24])).then(e=>({default:e.SearchDialog}))),Ct="opencami-search-jump-target";function Pl({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:r,forcedSessionKey:s}){const a=zt(),i=ut(),[l,c]=o.useState(!1),[u,d]=o.useState(!1),[f,m]=o.useState(null),[p,g]=o.useState(!1),{headerRef:b,composerRef:h,mainRef:w,pinGroupMinHeight:y,headerHeight:x}=vl(),[M,C]=o.useState(()=>Gt()||qt()),[K,E]=o.useState(()=>Gt()||qt()),[F,q]=o.useState(!1),[D,V]=o.useState(!1),[_,S]=o.useState("global"),[I,R]=o.useState(null),[T,U]=o.useState(!1),L=dn(v=>v.level),{maybeNotifyAssistantMessage:N}=Dl(),j=o.useRef(null),k=o.useRef(null),z=o.useRef(null),H=o.useRef(""),G=o.useRef(()=>{}),J=o.useRef(!1),ee=o.useRef(""),{isMobile:Q}=kl(i),{sessionsQuery:re,sessions:Z,activeExists:te,activeSessionKey:Y,activeTitle:ye,activeTokens:ve,sessionsError:de}=Cl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:s}),{historyQuery:ae,historyMessages:ge,displayMessages:fe,historyError:P,resolvedSessionKey:me,activeCanonicalKey:O,sessionKeyForHistory:B}=jl({activeFriendlyId:e,activeSessionKey:Y,forcedSessionKey:s,isNewChat:t,isRedirecting:p,activeExists:te,sessionsReady:re.isSuccess,queryClient:i}),W=Mt({queryKey:ss,queryFn:function(){return En(i)},initialData:function(){return En(i)},staleTime:1/0}),se=Mt({queryKey:["gateway","status"],queryFn:po,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:"always"}),oe=o.useRef(Date.now()),ne=se.error instanceof Error?se.error.message:se.data&&!se.data.ok?se.data.error||"Gateway unavailable":null,je=ne??de??P,Pe=o.useCallback(()=>{se.refetch()},[se]),pe=W.data?.isSidebarCollapsed??!1,Te=Zn({enabled:Q&&pe,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{We(i,v=>({...v,isSidebarCollapsed:!1}))}}),dt=Zn({enabled:Q&&!pe,threshold:50,direction:"left",onSwipe:()=>{We(i,v=>({...v,isSidebarCollapsed:!0}))}}),xt=o.useCallback(()=>{m(null),g(!0),a({to:"/new",replace:!0})},[a]),qe=o.useCallback(()=>{k.current&&(window.clearInterval(k.current),k.current=null),z.current&&(window.clearTimeout(z.current),z.current=null)},[]),et=o.useCallback(()=>{qe(),ht(!1),C(!1),U(!1)},[qe]),yt=Rl(),{generateTitle:tt}=El(),nt=o.useRef(new Set),ft=150,wt=600,bt=o.useCallback(()=>{!e||t||(k.current&&window.clearInterval(k.current),U(!0),k.current=window.setInterval(()=>{G.current()},ft))},[e,t]),mt=o.useRef(()=>{}),St=o.useRef(()=>{}),{streaming:Ne,startStream:ie,stopStream:Se}=Ml({onDone:v=>mt.current(v),onError:v=>St.current(v),onAssistantDelta:({text:v})=>{ee.current+=v,N({text:ee.current,sessionFriendlyId:e})}});mt.current=o.useCallback(async v=>{await ae.refetch(),Se({preserveState:!0}),et(),i.invalidateQueries({queryKey:ue.sessions})},[ae,i,Se,et]),St.current=o.useCallback(v=>{console.warn("[stream] SSE error, falling back to polling")},[]);const ze=o.useMemo(()=>{if(!Ne.text)return null;const v=[];for(const $ of Ne.tools)v.push({type:"toolCall",name:$.name,id:$.id});return v.push({type:"text",text:Ne.text}),{role:"assistant",content:v,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[Ne.text,Ne.tools]),pt=o.useMemo(()=>{if(!ze)return fe;const v=[...fe].map((le,he)=>({message:le,index:he})).filter(({message:le})=>le.role==="assistant").map(({index:le})=>le).pop(),$=[...fe].map((le,he)=>({message:le,index:he})).filter(({message:le})=>le.role==="user").map(({index:le})=>le).pop();if(typeof v=="number"&&(typeof $!="number"||v>$)&&typeof v=="number"){const le=fe[v];if(Le(le).length>=Ne.text.length)return fe;const _e=[...fe];return _e[v]=ze,_e}return[...fe,ze]},[fe,ze,Ne.text]),$r=o.useMemo(()=>({}),[]);G.current=function(){ae.refetch()},o.useEffect(()=>{if(p){f&&m(null);return}if(rt){f&&m(null);return}if(re.isSuccess&&!te){f&&m(null);return}const v=de??P??ne;if(!v){f?.startsWith("Failed to load")&&m(null);return}In(v)&&a({to:"/connect",replace:!0});const $=de?`Failed to load sessions. ${de}`:P?`Failed to load history. ${P}`:ne?`Gateway unavailable. ${ne}`:null;$&&m($)},[f,ne,P,p,a,de]);const rt=!t&&!s&&!gr(e)&&re.isSuccess&&Z.length>0&&!Z.some(v=>v.friendlyId===e)&&!ae.isFetching&&!ae.isSuccess;o.useEffect(()=>{if(p){if(t){g(!1);return}!rt&&re.isSuccess&&g(!1)}},[t,p,re.isSuccess,rt]),o.useEffect(()=>{t||re.isSuccess&&Z.length!==0&&rt&&(It(),ln(i,e,B),a({to:"/new",replace:!0}))},[e,ae.isFetching,ae.isSuccess,t,a,i,B,Z,re.isSuccess,rt]);const wn=rt||p,vt=o.useRef("fast");o.useEffect(()=>{const v=[...ge].reverse().find(ce=>ce.role==="assistant");if(!v)return;const $=`${ge.length}:${Le(v).slice(-64)}`;$!==H.current&&(H.current=$,vt.current!=="fast"&&k.current&&(window.clearInterval(k.current),k.current=window.setInterval(()=>{G.current()},ft),vt.current="fast"),z.current&&window.clearTimeout(z.current),z.current=window.setTimeout(()=>{k.current&&(window.clearInterval(k.current),k.current=window.setInterval(()=>{G.current()},wt),vt.current="slow"),z.current=window.setTimeout(()=>{et(),vt.current="fast"},3e3)},1500))},[ge,et]),o.useEffect(()=>{if(!yt||t||p)return;const v=s||me||Y;if(!v||nt.current.has(v))return;const $=ge.filter(he=>he.role==="user"),ce=ge.filter(he=>he.role==="assistant");if($.length===0||ce.length===0||$.length!==1)return;const le=Le($[0]);!le||le.length<5||(nt.current.add(v),(async()=>{try{const he=await tt(le);he.title&&await bo(i,v,e,he.title)}catch(he){console.error("[smart-title] Error generating title:",he)}})())},[yt,t,p,s,me,Y,e,ge,tt,i]),o.useEffect(()=>{if(t||e){if(qe(),Se(),H.current="",U(!1),J.current){J.current=!1;return}if(Gt()||qt()){C(!0),E(!0);return}C(!1),E(!1)}},[e,t,qe,Se]),o.useEffect(()=>{if(!(typeof window>"u"))try{const v=sessionStorage.getItem(Ct);if(!v){R(null);return}const $=JSON.parse(v);if(typeof $.at=="number"&&Date.now()-$.at>300*1e3){sessionStorage.removeItem(Ct),R(null);return}if($.friendlyId===e&&typeof $.messageId=="string"&&$.messageId.length>0){R($.messageId),sessionStorage.removeItem(Ct);return}R(null)}catch{R(null)}},[e]),o.useLayoutEffect(()=>{if(t)return;const v=ko(s||me||Y,e);if(!v)return;J.current=!0;const $=ue.history(v.friendlyId,v.sessionKey),ce=i.getQueryData($);(Array.isArray(ce?.messages)?ce.messages:[]).some(_e=>!!(v.optimisticMessage.clientId&&(_e.clientId===v.optimisticMessage.clientId||_e.__optimisticId===v.optimisticMessage.clientId)||v.optimisticMessage.__optimisticId&&_e.__optimisticId===v.optimisticMessage.__optimisticId))||Bt(i,v.friendlyId,v.sessionKey,v.optimisticMessage),C(!0),E(!0),Xt(v.sessionKey,v.friendlyId,v.message,!0,v.attachments)},[e,Y,s,t,i,me]);function Xt(v,$,ce,le=!1,he,_e){let st="";if(!le){const{clientId:we,optimisticMessage:ot}=Dn(ce,he);st=we,Bt(i,$,v,ot),yo(i,v,$,ot)}ht(!0),c(!0),m(null),C(!0),E(!0);const $e=he?.map(we=>({mimeType:we.file.type,content:we.base64}));ee.current="",bt(),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:v,friendlyId:$,message:ce,thinking:L,idempotencyKey:crypto.randomUUID(),attachments:$e,model:_e||void 0})}).then(async we=>{if(!we.ok)throw new Error(await Ke(we));const Cn=(await we.json()).sessionKey||v||$;ie(Cn)}).catch(we=>{const ot=we instanceof Error?we.message:String(we);if(In(ot)){a({to:"/connect",replace:!0});return}st&&ho(i,$,v,st,function(es){return{...es,status:"error"}}),m(`Failed to send message. ${ot}`),ht(!1),C(!1),E(!1)}).finally(()=>{c(!1)})}const bn=o.useCallback(async()=>{d(!0);try{const v=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!v.ok)throw new Error(await Ke(v));const $=await v.json(),ce=typeof $.sessionKey=="string"?$.sessionKey:"",le=typeof $.friendlyId=="string"&&$.friendlyId.trim().length>0?$.friendlyId.trim():sn(ce);if(!ce||!le)throw new Error("Invalid session response");return i.invalidateQueries({queryKey:ue.sessions}),{sessionKey:ce,friendlyId:le}}finally{d(!1)}},[i]),Fr=o.useCallback((v,$)=>{const ce=$.attachments;if(v.length===0&&(!ce||ce.length===0))return;if($.reset(),t){const{clientId:he,optimisticId:_e,optimisticMessage:st}=Dn(v,ce);Bt(i,"new","new",st),ht(!0),c(!0),C(!0),E(!0),bn().then(({sessionKey:$e,friendlyId:we})=>{if(No(we),vo({sessionKey:$e,friendlyId:we,message:v,optimisticMessage:st,attachments:ce}),r){r({sessionKey:$e,friendlyId:we});return}a({to:"/chat/$sessionKey",params:{sessionKey:we},replace:!0})}).catch($e=>{go(i,"new","new",he,_e),$.setValue(v),m(`Failed to create session. ${$e instanceof Error?$e.message:String($e)}`),ht(!1),C(!1),E(!1),c(!1)});return}Xt(s||me||Y,e,v,!1,ce,$.model)},[e,Y,bn,s,t,a,r,i,me]),Sn=o.useCallback(()=>{C(!1),E(!1),ln(i,"new","new"),a({to:"/new"}),Q&&We(i,function($){return{...$,isSidebarCollapsed:!0}})},[Q,a,i]),Hr=o.useCallback(()=>{We(i,function($){return{...$,isSidebarCollapsed:!$.isSidebarCollapsed}})},[i]),Wr=o.useCallback(()=>{Q&&We(i,function($){return{...$,isSidebarCollapsed:!0}})},[Q,i]),Xr=o.useCallback(()=>{We(i,function($){return{...$,isSidebarCollapsed:!1}})},[i]),Yr=o.useCallback(v=>{if(t||!v.trim())return;const $=s||me||Y;$&&Xt($,e,v.trim())},[e,Y,s,t,me]),Br=o.useCallback(()=>{j.current?.focus()},[]),Gr=o.useCallback(()=>{if(F){q(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[F]),qr=o.useCallback(()=>{const v=[...fe].reverse().find(ce=>ce.role==="assistant");if(!v)return;const $=Le(v);$&&navigator.clipboard.writeText($).catch(()=>{})},[fe]),Vr=o.useCallback(()=>{q(!0)},[]),Jr=o.useCallback(()=>{S(t?"global":"current"),V(!0)},[t]),vn=o.useCallback(()=>{S("global"),V(!0)},[]);Al({onNewChat:Sn,onFocusInput:Br,onEscape:Gr,onCopyLastResponse:qr,onShowHelp:Vr,onSearch:Jr,onSearchGlobal:vn});const jn=ae.isLoading&&!ae.data||p,Nn=!!ne&&se.errorUpdatedAt>oe.current,Qr=!jn&&fe.length===0,Zr=o.useMemo(()=>!Nn||!je?null:n.jsx(Sl,{state:"error",error:je,onRetry:Pe}),[je,Pe,Nn]),kn=n.jsx($i,{sessions:Z,activeFriendlyId:e,activeSessionKey:B,creatingSession:u,onCreateSession:Sn,isCollapsed:Q?!1:pe,onToggleCollapse:Hr,onSelectSession:Wr,onActiveSessionDelete:xt,onOpenSearch:vn});return n.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[n.jsxs("div",{className:A("h-full overflow-hidden",Q?"relative":"grid grid-cols-[auto_minmax(0,1fr)]"),children:[wn?null:Q?n.jsxs(n.Fragment,{children:[!pe&&n.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>We(i,v=>({...v,isSidebarCollapsed:!0})),...dt}),n.jsx("div",{className:A("fixed inset-y-0 left-0 z-50 w-[var(--opencami-sidebar-width)] transition-transform duration-150 safe-area-top",pe?"-translate-x-full":"translate-x-0"),...dt,children:kn})]}):kn,n.jsxs("main",{className:"flex flex-col h-full min-h-0 min-w-0 overflow-x-hidden",ref:w,...Te,children:[n.jsx(Xi,{activeTitle:ye,wrapperRef:b,showSidebarButton:Q,onOpenSidebar:Xr,totalTokens:ve.totalTokens,contextTokens:ve.contextTokens}),wn?null:n.jsxs(n.Fragment,{children:[n.jsx($a,{messages:pt,loading:jn,empty:Qr,notice:Zr,noticePosition:"end",waitingForResponse:M,isStreaming:T,sessionKey:O,pinToTop:K,pinGroupMinHeight:y,headerHeight:x,contentStyle:$r,onFollowUpClick:Yr,jumpToMessageId:I}),n.jsx(wl,{onSubmit:Fr,isLoading:l,disabled:l,wrapperRef:h,inputRef:j})]})]})]}),F&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Ol,{open:F,onOpenChange:q})}),D&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Ll,{open:D,onOpenChange:V,sessions:Z,currentFriendlyId:e,currentSessionKey:Y,mode:_,onJumpToMessage:v=>{if(V(!1),!!v.friendlyId){if(v.messageId&&v.friendlyId===e){R(v.messageId);return}if(v.messageId&&typeof window<"u")try{sessionStorage.setItem(Ct,JSON.stringify({friendlyId:v.friendlyId,messageId:v.messageId,at:Date.now()}))}catch{}a({to:"/chat/$sessionKey",params:{sessionKey:v.friendlyId}})}}})})]})}function _l(){const e=ut(),t=zt(),[r,s]=o.useState(null),a=rs.useParams(),i=typeof a.sessionKey=="string"?a.sessionKey:"main",l=i==="new",c=r?.friendlyId===i?r.sessionKey:void 0,u=o.useCallback(function(f){xo(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(Pl,{activeFriendlyId:i,isNewChat:l,forcedSessionKey:c,onSessionResolved:l?u:void 0})}const sc=Object.freeze(Object.defineProperty({__proto__:null,component:_l},Symbol.toStringTag,{value:"Module"}));export{sc as $,ue as c,Ar as g,rc as u};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/agents-screen-BNQGEqcW.js","assets/main-CgwdHc9W.js","assets/useQuery-CmAJuY2W.js","assets/button-D9Plv7hu.js","assets/switch-DbgQPO6i.js","assets/useControlled-B5pEEz2V.js","assets/useBaseUiId-KQTzRPLp.js","assets/visuallyHidden-COI6QeQH.js","assets/tooltip-DLmutB5C.js","assets/popupStateMapping-D0ZbJR_o.js","assets/event-DD8Cz4O9.js","assets/DirectionContext-CxhRpXkm.js","assets/opencami-logo-Bmge6-FB.js","assets/proxy-CYZeDXoy.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e,r as t,_ as r}from"./main-CgwdHc9W.js";const n=t.lazy(()=>r(()=>import("./agents-screen-BNQGEqcW.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13])).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-CgwdHc9W.js";import{u as q}from"./useQuery-CmAJuY2W.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-D9Plv7hu.js";import{S as _}from"./switch-DbgQPO6i.js";import{s as X,T as Y,a as Z,b as $,c as ee,d as se,g as P}from"./tooltip-DLmutB5C.js";import{O as re,a as ae}from"./opencami-logo-Bmge6-FB.js";import{m as S,A as W}from"./proxy-CYZeDXoy.js";import"./useControlled-B5pEEz2V.js";import"./useBaseUiId-KQTzRPLp.js";import"./visuallyHidden-COI6QeQH.js";import"./popupStateMapping-D0ZbJR_o.js";import"./event-DD8Cz4O9.js";import"./DirectionContext-CxhRpXkm.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 ge(){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{ge as AgentsScreen};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/bots-screen-Be3cfGgq.js","assets/main-CgwdHc9W.js","assets/button-D9Plv7hu.js","assets/switch-DbgQPO6i.js","assets/useControlled-B5pEEz2V.js","assets/useBaseUiId-KQTzRPLp.js","assets/visuallyHidden-COI6QeQH.js","assets/useQuery-CmAJuY2W.js","assets/useMutation-BsQD6FKe.js","assets/proxy-CYZeDXoy.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e,r as t,_ as r}from"./main-CgwdHc9W.js";const n=t.lazy(()=>r(()=>import("./bots-screen-Be3cfGgq.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).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-CgwdHc9W.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-D9Plv7hu.js";import{S}from"./switch-DbgQPO6i.js";import{u as j}from"./useQuery-CmAJuY2W.js";import{u as N}from"./useMutation-BsQD6FKe.js";import{m as M,A}from"./proxy-CYZeDXoy.js";import"./useControlled-B5pEEz2V.js";import"./useBaseUiId-KQTzRPLp.js";import"./visuallyHidden-COI6QeQH.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 te(){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{te as BotsScreen};
|