opencami 1.8.13 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +4 -2
  2. package/dist/client/assets/{CSPContext-DATmz4sz.js → CSPContext-B3PAVjBL.js} +1 -1
  3. package/dist/client/assets/{DirectionContext-FHFKdJq_.js → DirectionContext-CR5CCisG.js} +1 -1
  4. package/dist/client/assets/_sessionKey-Bg_9uype.js +23 -0
  5. package/dist/client/assets/agents-BiTHBb6Z.js +2 -0
  6. package/dist/client/assets/{agents-screen-C58VLjES.js → agents-screen--ZMzN5cB.js} +1 -1
  7. package/dist/client/assets/bots-DxhRnQp5.js +2 -0
  8. package/dist/client/assets/{bots-screen-B8h4Y1VL.js → bots-screen-C_uJBNwI.js} +1 -1
  9. package/dist/client/assets/{button-BcUmP7JL.js → button-BciDmec0.js} +1 -1
  10. package/dist/client/assets/{composite--BBbKdxm.js → composite-DArWbFHm.js} +1 -1
  11. package/dist/client/assets/{connect-BmwKnEFP.js → connect-B48HecjN.js} +1 -1
  12. package/dist/client/assets/{dashboard-BWQl_-2-.js → dashboard-BVKx9FMy.js} +1 -1
  13. package/dist/client/assets/{event-BxzjTPjG.js → event-BCwqPPkP.js} +1 -1
  14. package/dist/client/assets/{file-explorer-screen-BAbbb_R4.js → file-explorer-screen-DPs-FWeA.js} +1 -1
  15. package/dist/client/assets/files-SEycwYCa.js +2 -0
  16. package/dist/client/assets/{follow-up-suggestions-Bq-xR5GV.js → follow-up-suggestions-BPjWBpiy.js} +1 -1
  17. package/dist/client/assets/{index-rOr2i8gW.js → index-0gdwm1_H.js} +1 -1
  18. package/dist/client/assets/{index-BTtT4Vbb.js → index-CGeJcqZ3.js} +1 -1
  19. package/dist/client/assets/{keyboard-shortcuts-dialog-BA8cBwWm.js → keyboard-shortcuts-dialog-CK_XTzLr.js} +1 -1
  20. package/dist/client/assets/{main-_1IghVZn.js → main-B2CrcRuC.js} +3 -3
  21. package/dist/client/assets/{markdown-CqIcraPO.js → markdown-CdkuX06F.js} +1 -1
  22. package/dist/client/assets/memory-C7lKdkmc.js +2 -0
  23. package/dist/client/assets/{memory-screen-GBzowsnE.js → memory-screen-C1RfLy-d.js} +1 -1
  24. package/dist/client/assets/{menu--FXN_JCl.js → menu-CIwnliij.js} +1 -1
  25. package/dist/client/assets/{opencami-logo-BFo87CeM.js → opencami-logo-SVuYD55V.js} +1 -1
  26. package/dist/client/assets/{proxy-CJ6-TEKD.js → proxy-BijR8W1L.js} +1 -1
  27. package/dist/client/assets/{react-BRYbnjMp.js → react-DWx7OvUo.js} +1 -1
  28. package/dist/client/assets/{search-dialog-CJS2GUnE.js → search-dialog-CB4KE8ec.js} +1 -1
  29. package/dist/client/assets/{search-sources-badge-D0YArqfp.js → search-sources-badge-B8Z-8sSf.js} +1 -1
  30. package/dist/client/assets/{session-export-dialog-Bc9YEPLs.js → session-export-dialog-tDiFuv3a.js} +1 -1
  31. package/dist/client/assets/{settings-dialog-SDzqDXsx.js → settings-dialog-aL-AH4Rt.js} +1 -1
  32. package/dist/client/assets/skills-D1T6uemU.js +2 -0
  33. package/dist/client/assets/{skills-panel-DIalYvpW.js → skills-panel-fjJQVMog.js} +1 -1
  34. package/dist/client/assets/styles-D0L88B64.css +1 -0
  35. package/dist/client/assets/{switch-BwmDNR0d.js → switch-Bn5uei2k.js} +1 -1
  36. package/dist/client/assets/{tabs-T1fJbUsm.js → tabs-DOBNAUVE.js} +1 -1
  37. package/dist/client/assets/{thinking-DUdE6Iej.js → thinking-dfGrFAMV.js} +1 -1
  38. package/dist/client/assets/{tooltip-DexBPu8g.js → tooltip-DOKkNFvu.js} +1 -1
  39. package/dist/client/assets/{use-file-explorer-state-eXs92yKN.js → use-file-explorer-state-BAa6Cxyr.js} +1 -1
  40. package/dist/client/assets/{useBaseUiId-DN9cOflS.js → useBaseUiId-DFpBD0sg.js} +1 -1
  41. package/dist/client/assets/{useCompositeItem-B_J-cnZX.js → useCompositeItem-B-Axq9-D.js} +1 -1
  42. package/dist/client/assets/{useControlled-DeDLOsPR.js → useControlled-CQHE0ITz.js} +1 -1
  43. package/dist/client/assets/{useMutation-TzgejsE_.js → useMutation-BFl-7GnD.js} +1 -1
  44. package/dist/client/assets/{useOnFirstRender-S4-xcV93.js → useOnFirstRender-DlXHIIGk.js} +1 -1
  45. package/dist/client/assets/{useQuery-BdjM5kzn.js → useQuery-D-sF8Tld.js} +1 -1
  46. package/dist/server/assets/{_sessionKey-DBzlGMo3.js → _sessionKey-D8TGrDRM.js} +429 -131
  47. package/dist/server/assets/{_tanstack-start-manifest_v-CX4xb59U.js → _tanstack-start-manifest_v-DalBo2bY.js} +1 -1
  48. package/dist/server/assets/{follow-up-suggestions-BmSFSY87.js → follow-up-suggestions-C65ptDij.js} +2 -2
  49. package/dist/server/assets/{index-C1dylvu-.js → index-gRco4Ina.js} +1 -1
  50. package/dist/server/assets/{router-CL6A11qi.js → router-DaKDqc9w.js} +72 -251
  51. package/dist/server/assets/{search-dialog-D8DvpPZw.js → search-dialog-DSSK93kq.js} +2 -2
  52. package/dist/server/assets/{settings-dialog-CeP-J_NJ.js → settings-dialog-DyWNblva.js} +2 -2
  53. package/dist/server/assets/{thinking-ClIWjSbx.js → thinking-CU0FRlzT.js} +2 -2
  54. package/dist/server/server.js +2 -2
  55. package/package.json +1 -1
  56. package/dist/client/assets/_sessionKey-D2ZMdqJ0.js +0 -23
  57. package/dist/client/assets/agents-9A0buuwT.js +0 -2
  58. package/dist/client/assets/bots-Lqt92ma0.js +0 -2
  59. package/dist/client/assets/files-DvIFms9G.js +0 -2
  60. package/dist/client/assets/memory-B3LyVZwO.js +0 -2
  61. package/dist/client/assets/skills-BVLjvrPU.js +0 -2
  62. package/dist/client/assets/styles-b2XYKZYx.css +0 -1
package/README.md CHANGED
@@ -297,9 +297,11 @@ Requires a display/GUI environment.
297
297
 
298
298
  Built on top of [WebClaw](https://github.com/ibelick/webclaw) by [@ibelick](https://github.com/ibelick).
299
299
 
300
- File Explorer by [@balin-ar](https://github.com/balin-ar) ([PR #2](https://github.com/ibelick/webclaw/pull/2)).
300
+ ### Contributors
301
301
 
302
- Dockerfile by [@deblanco](https://github.com/deblanco) ([PR #7](https://github.com/ibelick/webclaw/pull/7)).
302
+ - [@maciejlis](https://github.com/maciejlis) Dark mode palette, dark mode visibility fixes, metadata stripping improvements
303
+ - [@balin-ar](https://github.com/balin-ar) — File Explorer ([upstream PR #2](https://github.com/ibelick/webclaw/pull/2))
304
+ - [@deblanco](https://github.com/deblanco) — Dockerfile ([upstream PR #7](https://github.com/ibelick/webclaw/pull/7))
303
305
 
304
306
  Powered by [OpenClaw](https://github.com/openclaw/openclaw).
305
307
 
@@ -1 +1 @@
1
- import{r as t}from"./main-_1IghVZn.js";const e=t.createContext(void 0),o={disableStyleElements:!1};function s(){return t.useContext(e)??o}export{s as u};
1
+ import{r as t}from"./main-B2CrcRuC.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-_1IghVZn.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};
1
+ import{r as l}from"./main-B2CrcRuC.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-aL-AH4Rt.js","assets/main-B2CrcRuC.js","assets/react-DWx7OvUo.js","assets/button-BciDmec0.js","assets/use-file-explorer-state-BAa6Cxyr.js","assets/useOnFirstRender-DlXHIIGk.js","assets/useBaseUiId-DFpBD0sg.js","assets/event-BCwqPPkP.js","assets/visuallyHidden-COI6QeQH.js","assets/composite-DArWbFHm.js","assets/switch-Bn5uei2k.js","assets/useControlled-CQHE0ITz.js","assets/tabs-DOBNAUVE.js","assets/useCompositeItem-B-Axq9-D.js","assets/DirectionContext-CR5CCisG.js","assets/CSPContext-B3PAVjBL.js","assets/index-CGeJcqZ3.js","assets/useQuery-D-sF8Tld.js","assets/tooltip-DOKkNFvu.js","assets/useMutation-BFl-7GnD.js","assets/menu-CIwnliij.js","assets/opencami-logo-SVuYD55V.js","assets/proxy-BijR8W1L.js","assets/markdown-CdkuX06F.js","assets/index-T4TOjvD0.js","assets/session-export-dialog-tDiFuv3a.js","assets/thinking-dfGrFAMV.js","assets/search-sources-badge-B8Z-8sSf.js","assets/follow-up-suggestions-BPjWBpiy.js","assets/keyboard-shortcuts-dialog-CK_XTzLr.js","assets/search-dialog-CB4KE8ec.js"])))=>i.map(i=>d[i]);
2
+ import{r as o,u as ht,j as n,L as Be,_ as nt,d as zt,w as os,a as is,z as as}from"./main-B2CrcRuC.js";import{u as Lt}from"./useQuery-D-sF8Tld.js";import{T as De,a as Oe,b as Le,c as _e,s as Xe,d as ls,g as Nn}from"./tooltip-DOKkNFvu.js";import{C as cs,c as L,B as we,ac as dn,ag as Ve,E as us,H as te,J as sr,V as $t,aj as ds,ak as fs,al as ms,a as or,am as ps,G as hs,an as gs,l as ys,b as Ze,I as xs,ao as ws,a3 as bs,s as en,ap as Ss,L as vs,aq as js,A as ks,N as Es,Q as Cs,X as ir,x as Ns,h as Ts,ar,as as Rs,p as Is,T as lr,u as cr,at as Tn,au as As,av as Ms,aw as Ds}from"./button-BciDmec0.js";import{u as ur}from"./useMutation-BFl-7GnD.js";import{j as Os,k as Ls,l as _s,m as Ps,n as Ks,o as Us,p as zs,q as $s,r as Fs,s as dr,D as Hs,a as Ws,b as Bs,c as Xs,d as Ys,u as Gs}from"./use-file-explorer-state-BAa6Cxyr.js";import{e as fr,a as Ge,g as mr,t as qs,u as Pe,f as Vs,n as Js}from"./useBaseUiId-DFpBD0sg.js";import{u as Qs}from"./useControlled-CQHE0ITz.js";import{a2 as Zs,a3 as eo,a4 as Rn,t as pr,u as to,J as Te,e as no,a as _t}from"./useOnFirstRender-DlXHIIGk.js";import{u as ro,e as so,p as oo}from"./event-BCwqPPkP.js";import{u as io}from"./CSPContext-B3PAVjBL.js";import{u as hr}from"./DirectionContext-CR5CCisG.js";import{M as fn,a as mn,b as pn,c as tt}from"./menu-CIwnliij.js";import{O as ao,a as lo}from"./opencami-logo-SVuYD55V.js";import{m as be,A as Me}from"./proxy-BijR8W1L.js";import{M as co}from"./markdown-CdkuX06F.js";import{u as uo,p as gr}from"./index-CGeJcqZ3.js";import{c as yr}from"./react-DWx7OvUo.js";function tn(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 In=/^Conversation info \(untrusted metadata\):\s*```(?:json)?\s*[\s\S]*?```\s*/,An=/^Conversation info \(untrusted metadata\):\s*\{[\s\S]*?\}\s*/,Mn=/^Sender \(untrusted metadata\):\s*```(?:[a-zA-Z0-9_-]+)?\s*[\s\S]*?```\s*/gm,fo=/^Sender \(untrusted metadata\):\s*\{[^\n]*\}\s*$/gm,Dn=/<supermemory-context\b[^>]*>[\s\S]*?<\/supermemory-context>/gi,On=/<supermemory-containers\b[^>]*>[\s\S]*?<\/supermemory-containers>/gi,mo=/<workspace-critical-rules\b[^>]*>[\s\S]*?<\/workspace-critical-rules>/gi,po=/^\[(?:[A-Za-z]{3}\s+)?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s+GMT[+-]?\d+\]\s*/gm,ho=/\n{3,}/g;function xr(e){let t=e;t=t.replace(Dn,"").replace(On,"").replace(mo,"").replace(Mn,"");const r=In.test(t),s=!r&&An.test(t);return r?t=t.replace(In,""):s&&(t=t.replace(An,"")),t=t.replace(Dn,"").replace(On,"").replace(Mn,"").replace(fo,"").replace(po,"").replace(ho,`
3
+
4
+ `),t.trim()}function ve(e){const r=(Array.isArray(e.content)?e.content:[]).map(s=>s.type==="text"?String(s.text??""):"").join("").trim();return xr(r)}function Ye(e){return(Array.isArray(e.content)?e.content:[]).filter(r=>r.type==="toolCall")}function go(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 jt(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=go(r);if(s)return s}return Date.now()}const yo=["agent:main:main","main"];function nn(e){return yo.includes(e)}const xo=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function wo(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 xo.test(t)?"webchat":"chat"}return"other"}function bo(e){return Array.isArray(e)?e.map(t=>{const r=typeof t.key=="string"&&t.key.trim().length>0?t.key.trim():tn(t.friendlyId??t.key),s=typeof t.friendlyId=="string"&&t.friendlyId.trim().length>0?t.friendlyId.trim():tn(r),a=wo(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 ze(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 So="Missing gateway auth. Set CLAWDBOT_GATEWAY_TOKEN (recommended) or CLAWDBOT_GATEWAY_PASSWORD in the server environment.";function Ln(e){return e.includes(So)}function _n(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 ge={sessions:["chat","sessions"],history:function(t,r){return["chat","history",t,r]}};async function vo(){const e=await fetch("/api/sessions");if(!e.ok)throw new Error(await ze(e));const t=await e.json();return bo(t.sessions)}async function jo(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 ze(r));return await r.json()}async function ko(){const e=new AbortController,t=window.setTimeout(()=>e.abort(),8e3);try{const r=await fetch("/api/ping",{signal:e.signal});if(!r.ok)throw new Error(await ze(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 hn(e,t,r,s){const a=ge.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 Wt(e,t,r,s){hn(e,t,r,function(i){return[...i,s]})}function Eo(e,t,r,s,a){const i=`opt-${s}`;hn(e,t,r,function(c){return c.map(u=>u.clientId===s||u.__optimisticId===s||u.__optimisticId===i?a(u):u)})}function Bt(e,t,r,s,a){hn(e,t,r,function(l){return l.filter(c=>!(c.clientId===s||c.__optimisticId===s||a&&c.__optimisticId===a))})}function rn(e,t,r){const s=ge.history(t,r);e.setQueryData(s,{sessionKey:r,messages:[]})}function Co(e,t,r,s,a){const i=ge.history(t,r),l=ge.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 No(e,t,r,s){e.setQueryData(ge.sessions,function(i){return Array.isArray(i)?i.map(l=>l.key!==t&&l.friendlyId!==r?l:{...l,lastMessage:s}):i})}function To(e,t,r){e.setQueryData(ge.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 Ro(e,t,r,s){e.setQueryData(ge.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 ze(a);console.error("[updateSessionLabel] Failed to persist:",i)}}catch(a){console.error("[updateSessionLabel] Network error:",a)}}function Io(){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 m=await fetch("/api/paths");if(!m.ok)throw new Error(await ze(m));const b=await m.json();c({agentId:String(b.agentId??"main"),stateDir:String(b.stateDir??""),sessionsDir:String(b.sessionsDir??""),storePath:String(b.storePath??"")})}catch(m){i(m instanceof Error?m.message:String(m))}finally{s(!1)}}},[l,r]),d=o.useCallback(()=>{u()},[u]),f=o.useCallback(()=>{t(!1)},[]),h=o.useCallback(()=>{if(l?.sessionsDir)try{navigator.clipboard.writeText(l.sessionsDir)}catch{}},[l]),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:h,copyStorePath:p}}let Ee=null,gn=!1,Mt=null;function Ao(e){Ee=e}function Xt(){return Ee!==null}function bt(e){gn=e}function Yt(){return gn}function Pt(){Ee=null,gn=!1}function Mo(e,t){if(Ee){if(e&&Ee.sessionKey===e){Pt();return}t&&Ee.friendlyId===t&&Pt()}}function Do(e){Mt={friendlyId:e,at:Date.now()}}function wr(e,t=15e3){return!(!Mt||Mt.friendlyId!==e||Date.now()-Mt.at>t)}function Oo(e,t){if(!Ee)return null;if(e&&Ee.sessionKey===e){const r=Ee;return Ee=null,r}if(t&&Ee.friendlyId===t){const r=Ee;return Ee=null,r}return null}const Lo=8e3,et=new Map;function _o(e){e&&et.set(e,{id:e,expiresAt:Date.now()+Lo})}function Po(e){e&&et.delete(e)}function Ko(e){if(et.size===0)return e;const t=Date.now();let r=!1;const s=e.filter(a=>{const i=et.get(a.key),l=et.get(a.friendlyId);return i&&i.expiresAt<=t||l&&l.expiresAt<=t?(i&&i.expiresAt<=t&&et.delete(a.key),l&&l.expiresAt<=t&&et.delete(a.friendlyId),!0):i||l?(r=!0,!1):!0});return r?s:e}function Uo(){const e=ht(),[t,r]=o.useState(!1),[s,a]=o.useState(null),i=ur({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 ze(f));return u},onMutate:async function(u){a(null),_o(u.sessionKey||u.friendlyId),Mo(u.sessionKey,u.friendlyId),await e.cancelQueries({queryKey:ge.sessions});const d=e.getQueryData(ge.sessions);return To(e,u.sessionKey,u.friendlyId),u.isActive&&(u.sessionKey||u.friendlyId)&&rn(e,u.friendlyId||u.sessionKey,u.sessionKey||u.friendlyId),{previousSessions:d,isActive:u.isActive}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(ge.sessions,f.previousSessions),Po(d.sessionKey||d.friendlyId),a(u instanceof Error?u.message:String(u))},onSuccess:function(u){u.isActive&&Pt(),e.invalidateQueries({queryKey:ge.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 zo(){const e=ht(),[t,r]=o.useState(!1),[s,a]=o.useState(null),i=ur({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 ze(d));return u},onMutate:async function(u){a(null),await e.cancelQueries({queryKey:ge.sessions});const d=e.getQueryData(ge.sessions);return e.setQueryData(ge.sessions,function(h){return Array.isArray(h)?h.map(p=>p.key!==u.sessionKey?p:{...p,label:u.newTitle,title:u.newTitle}):h}),{previousSessions:d}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(ge.sessions,f.previousSessions),a(u instanceof Error?u.message:String(u))},onSuccess:function(){e.invalidateQueries({queryKey:ge.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 br(e){return!e.content||!Array.isArray(e.content)?"":e.content.filter(t=>t.type==="text").map(t=>t.text||"").join(`
5
+ `)}function $o(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=br(a);if(l){const c=i==="user"?"User":"Assistant";s.push(`## ${c}`),s.push(""),s.push(l),s.push("")}}return s.join(`
6
+ `)}function Fo(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 Ho(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=br(a);if(l){const c=i==="user"?"User":"Assistant";s.push(`${c}:`),s.push(l),s.push("")}}return s.join(`
7
+ `)}function Wo(e,t,r){const s=new Date;let a,i,l;switch(r){case"markdown":a=$o(e,t,s),i=`${Gt(e)}.md`,l="text/markdown";break;case"json":a=Fo(e,t,s),i=`${Gt(e)}.json`,l="application/json";break;case"txt":a=Ho(e,t,s),i=`${Gt(e)}.txt`,l="text/plain";break;default:throw new Error(`Unsupported format: ${r}`)}Bo(a,i,l)}function Gt(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function Bo(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 Xo(e){const{children:t,open:r,defaultOpen:s=!1,onOpenChange:a,onOpenChangeComplete:i,actionsRef:l,handle:c,triggerId:u,defaultTriggerId:d=null}=e,f=Os(),h=!!f,p=cs(()=>c?.store??new Ls({open:s,openProp:r,activeTriggerId:d,triggerIdProp:u,modal:!0,disablePointerDismissal:!0,nested:h,role:"alertdialog"})).current;p.useControlledProp("openProp",r),p.useControlledProp("triggerIdProp",u),p.useSyncedValue("nested",h),p.useContextCallback("onOpenChange",a),p.useContextCallback("onOpenChangeComplete",i);const m=p.useState("payload");_s({store:p,actionsRef:l,parentContext:f?.store.context});const b=o.useMemo(()=>({store:p}),[p]);return n.jsx(Ps.Provider,{value:b,children:typeof t=="function"?t({payload:m}):t})}function Yo({children:e,...t}){return n.jsx(Xo,{...t,children:e})}function Go({className:e,children:t}){return n.jsxs(Ks,{children:[n.jsx(Us,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),n.jsx(zs,{className:L("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 qo({className:e,...t}){return n.jsx($s,{className:L("text-lg font-medium text-primary-900",e),...t})}function Vo({className:e,...t}){return n.jsx(Fs,{className:L("text-sm text-primary-600",e),...t})}function Jo({className:e,...t}){return n.jsx(dr,{render:n.jsx(we,{variant:"outline",className:L(e)}),...t})}function Qo({className:e,...t}){return n.jsx(dr,{render:n.jsx(we,{variant:"destructive",className:L(e)}),...t})}function Zo({open:e,onOpenChange:t,sessionTitle:r,onConfirm:s,onCancel:a}){return n.jsx(Yo,{open:e,onOpenChange:t,children:n.jsx(Go,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(qo,{className:"mb-1",children:"Delete Session"}),n.jsxs(Vo,{className:"mb-4",children:['Are you sure you want to delete "',r,'"? This action cannot be undone.']}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx(Jo,{onClick:a,children:"Cancel"}),n.jsx(Qo,{onClick:s,children:"Delete"})]})]})})})}function ei({open:e,onOpenChange:t,sessionTitle:r,onSave:s,onCancel:a}){return n.jsx(Hs,{open:e,onOpenChange:t,children:n.jsx(Ws,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(Bs,{className:"mb-1",children:"Rename"}),n.jsx(Xs,{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(Ys,{onClick:a,children:"Cancel"}),n.jsx(we,{onClick:i=>{const l=i.currentTarget.parentElement?.previousElementSibling;s(l.value)},children:"Save"})]})]})})})}function ti(e){const{open:t,defaultOpen:r,onOpenChange:s,disabled:a}=e,i=t!==void 0,[l,c]=Qs({controlled:t,default:r,name:"Collapsible",state:"open"}),{mounted:u,setMounted:d,transitionStatus:f}=Zs(l,!0,!0),[h,p]=o.useState(l),[{height:m,width:b},g]=o.useState({height:void 0,width:void 0}),k=fr(),[w,y]=o.useState(),U=w??k,[I,F]=o.useState(!1),[O,ee]=o.useState(!1),_=o.useRef(null),P=o.useRef(null),Z=o.useRef(null),B=o.useRef(null),C=eo(B,!1),A=Ge(v=>{const M=!l,j=mr(qs,v.nativeEvent);if(s(M,j),j.isCanceled)return;const z=B.current;P.current==="css-animation"&&z!=null&&z.style.removeProperty("animation-name"),!I&&!O&&(P.current!=null&&P.current!=="css-animation"&&!u&&M&&d(!0),P.current==="css-animation"&&(!h&&M&&p(!0),!u&&M&&d(!0))),c(M),P.current==="none"&&u&&!M&&d(!1)});return Pe(()=>{i&&P.current==="none"&&!O&&!l&&d(!1)},[i,O,l,t,d]),o.useMemo(()=>({abortControllerRef:_,animationTypeRef:P,disabled:a,handleTrigger:A,height:m,mounted:u,open:l,panelId:U,panelRef:B,runOnceAnimationsFinish:C,setDimensions:g,setHiddenUntilFound:F,setKeepMounted:ee,setMounted:d,setOpen:c,setPanelIdState:y,setVisible:p,transitionDimensionRef:Z,transitionStatus:f,visible:h,width:b}),[_,P,a,A,m,u,l,U,B,C,g,F,ee,d,c,p,Z,f,h,b])}const Sr=o.createContext(void 0);function vr(){const e=o.useContext(Sr);if(e===void 0)throw new Error(dn(15));return e}let St=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Rn.startingStyle]="startingStyle",e[e.endingStyle=Rn.endingStyle]="endingStyle",e})({}),ni=(function(e){return e.panelOpen="data-panel-open",e})({});const ri={[St.open]:""},si={[St.closed]:""},oi={open(e){return e?{[ni.panelOpen]:""}:null}},ii={open(e){return e?ri:si}},jr={...ii,...pr},ai=o.forwardRef(function(t,r){const{render:s,className:a,defaultOpen:i=!1,disabled:l=!1,onOpenChange:c,open:u,...d}=t,f=Ge(c),h=ti({open:u,defaultOpen:i,onOpenChange:f,disabled:l}),p=o.useMemo(()=>({open:h.open,disabled:h.disabled,transitionStatus:h.transitionStatus}),[h.open,h.disabled,h.transitionStatus]),m=o.useMemo(()=>({...h,onOpenChange:f,state:p}),[h,f,p]),b=Ve("div",t,{state:p,ref:r,props:d,stateAttributesMapping:jr});return n.jsx(Sr.Provider,{value:m,children:b})}),li={...oi,...pr},ci=o.forwardRef(function(t,r){const{panelId:s,open:a,handleTrigger:i,state:l,disabled:c}=vr(),{className:u,disabled:d=c,id:f,render:h,nativeButton:p=!0,...m}=t,{getButtonProps:b,buttonRef:g}=Vs({disabled:d,focusableWhenDisabled:!0,native:p}),k=o.useMemo(()=>({"aria-controls":a?s:void 0,"aria-expanded":a,onClick:i}),[s,a,i]);return Ve("button",t,{state:l,ref:[r,g],props:[k,m,b],stateAttributesMapping:li})});let ui=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function di(e){const{abortControllerRef:t,animationTypeRef:r,externalRef:s,height:a,hiddenUntilFound:i,keepMounted:l,id:c,mounted:u,onOpenChange:d,open:f,panelRef:h,runOnceAnimationsFinish:p,setDimensions:m,setMounted:b,setOpen:g,setVisible:k,transitionDimensionRef:w,visible:y,width:U}=e,I=o.useRef(!1),F=o.useRef(null),O=o.useRef(f),ee=o.useRef(f),_=to(),P=o.useMemo(()=>r.current==="css-animation"?!y:!f&&!u,[f,u,y,r]),Z=Ge(C=>{if(!C)return;if(r.current==null||w.current==null){const M=getComputedStyle(C),j=M.animationName!=="none"&&M.animationName!=="",z=M.transitionDuration!=="0s"&&M.transitionDuration!=="";j&&z||(M.animationName==="none"&&M.transitionDuration!=="0s"?r.current="css-transition":M.animationName!=="none"&&M.transitionDuration==="0s"?r.current="css-animation":r.current="none"),C.getAttribute(ui.orientation)==="horizontal"||M.transitionProperty.indexOf("width")>-1?w.current="width":w.current="height"}if(r.current!=="css-transition")return;(a===void 0||U===void 0)&&(m({height:C.scrollHeight,width:C.scrollWidth}),ee.current&&C.style.setProperty("transition-duration","0s"));let A=-1,v=-1;return A=Te.request(()=>{ee.current=!1,v=Te.request(()=>{setTimeout(()=>{C.style.removeProperty("transition-duration")})})}),()=>{Te.cancel(A),Te.cancel(v)}}),B=us(s,h,Z);return Pe(()=>{if(r.current!=="css-transition")return;const C=h.current;if(!C)return;let A=-1;if(t.current!=null&&(t.current.abort(),t.current=null),f){const v={"justify-content":C.style.justifyContent,"align-items":C.style.alignItems,"align-content":C.style.alignContent,"justify-items":C.style.justifyItems};Object.keys(v).forEach(M=>{C.style.setProperty(M,"initial","important")}),!ee.current&&!l&&C.setAttribute(St.startingStyle,""),m({height:C.scrollHeight,width:C.scrollWidth}),A=Te.request(()=>{Object.entries(v).forEach(([M,j])=>{j===""?C.style.removeProperty(M):C.style.setProperty(M,j)})})}else{if(C.scrollHeight===0&&C.scrollWidth===0)return;m({height:C.scrollHeight,width:C.scrollWidth});const v=new AbortController;t.current=v;const M=v.signal;let j=null;const z=St.endingStyle;return j=new MutationObserver(G=>{G.some(D=>D.type==="attributes"&&D.attributeName===z)&&(j?.disconnect(),j=null,p(()=>{m({height:0,width:0}),C.style.removeProperty("content-visibility"),b(!1),t.current===v&&(t.current=null)},M))}),j.observe(C,{attributes:!0,attributeFilter:[z]}),()=>{j?.disconnect(),_.cancel(),t.current===v&&(v.abort(),t.current=null)}}return()=>{Te.cancel(A)}},[t,r,_,i,l,u,f,h,p,m,b]),Pe(()=>{if(r.current!=="css-animation")return;const C=h.current;C&&(F.current=C.style.animationName||F.current,C.style.setProperty("animation-name","none"),m({height:C.scrollHeight,width:C.scrollWidth}),!O.current&&!I.current&&C.style.removeProperty("animation-name"),f?(t.current!=null&&(t.current.abort(),t.current=null),b(!0),k(!0)):(t.current=new AbortController,p(()=>{b(!1),k(!1),t.current=null},t.current.signal)))},[t,r,f,h,p,m,b,k,y]),ro(()=>{const C=Te.request(()=>{O.current=!1});return()=>Te.cancel(C)}),Pe(()=>{if(!i)return;const C=h.current;if(!C)return;let A=-1,v=-1;return f&&I.current&&(C.style.transitionDuration="0s",m({height:C.scrollHeight,width:C.scrollWidth}),A=Te.request(()=>{I.current=!1,v=Te.request(()=>{setTimeout(()=>{C.style.removeProperty("transition-duration")})})})),()=>{Te.cancel(A),Te.cancel(v)}},[i,f,h,m]),Pe(()=>{const C=h.current;C&&i&&P&&(C.setAttribute("hidden","until-found"),r.current==="css-transition"&&C.setAttribute(St.startingStyle,""))},[i,P,r,h]),o.useEffect(function(){const A=h.current;if(!A)return;function v(M){I.current=!0,g(!0),d(!0,mr(Js,M))}return A.addEventListener("beforematch",v),()=>{A.removeEventListener("beforematch",v)}},[d,h,g]),o.useMemo(()=>({props:{hidden:P,id:c,ref:B}}),[P,c,B])}let Pn=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const fi=o.forwardRef(function(t,r){const{className:s,hiddenUntilFound:a,keepMounted:i,render:l,id:c,...u}=t,{abortControllerRef:d,animationTypeRef:f,height:h,mounted:p,onOpenChange:m,open:b,panelId:g,panelRef:k,runOnceAnimationsFinish:w,setDimensions:y,setHiddenUntilFound:U,setKeepMounted:I,setMounted:F,setPanelIdState:O,setOpen:ee,setVisible:_,state:P,transitionDimensionRef:Z,visible:B,width:C,transitionStatus:A}=vr(),v=a??!1,M=i??!1;Pe(()=>{if(c)return O(c),()=>{O(void 0)}},[c,O]),Pe(()=>{U(v)},[U,v]),Pe(()=>{I(M)},[I,M]);const{props:j}=di({abortControllerRef:d,animationTypeRef:f,externalRef:r,height:h,hiddenUntilFound:v,id:g,keepMounted:M,mounted:p,onOpenChange:m,open:b,panelRef:k,runOnceAnimationsFinish:w,setDimensions:y,setMounted:F,setOpen:ee,setVisible:_,transitionDimensionRef:Z,visible:B,width:C});no({open:b&&A==="idle",ref:k,onComplete(){b&&y({height:void 0,width:void 0})}});const z=o.useMemo(()=>({...P,transitionStatus:A}),[P,A]),G=Ve("div",t,{state:z,ref:[r,k],props:[j,{style:{[Pn.collapsiblePanelHeight]:h===void 0?"auto":`${h}px`,[Pn.collapsiblePanelWidth]:C===void 0?"auto":`${C}px`}},u],stateAttributesMapping:jr});return M||v||!M&&p?G:null});function sn(e){return n.jsx(ai,{...e})}function on({className:e,...t}){return n.jsx(ci,{className:L("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 an({className:e,contentClassName:t,children:r,...s}){return n.jsx(fi,{className:L('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:L("pt-1",t),children:r})})}const kr=o.createContext(void 0);function Ft(){const e=o.useContext(kr);if(e===void 0)throw new Error(dn(53));return e}let Kt=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const Rt=500,Kn=16;function Re(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 mi=(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 It="base-ui-disable-scrollbar",Er={className:It,getElement(e){return n.jsx("style",{nonce:e,href:It,precedence:"base-ui:low",children:`.${It}{scrollbar-width:none}.${It}::-webkit-scrollbar{display:none}`})}};let lt=(function(e){return 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 yn={hasOverflowX:e=>e?{[lt.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[lt.hasOverflowY]:""}:null,overflowXStart:e=>e?{[lt.overflowXStart]:""}:null,overflowXEnd:e=>e?{[lt.overflowXEnd]:""}:null,overflowYStart:e=>e?{[lt.overflowYStart]:""}:null,overflowYEnd:e=>e?{[lt.overflowYEnd]:""}:null,cornerHidden:()=>null},pi={x:0,y:0},Un={width:0,height:0},hi={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},gi={x:!1,y:!1,corner:!1},yi=o.forwardRef(function(t,r){const{render:s,className:a,overflowEdgeThreshold:i,...l}=t,c=xi(i),u=fr(),d=_t(),f=_t(),{nonce:h,disableStyleElements:p}=io(),[m,b]=o.useState(!1),[g,k]=o.useState(!1),[w,y]=o.useState(!1),[U,I]=o.useState(!1),[F,O]=o.useState(Un),[ee,_]=o.useState(Un),[P,Z]=o.useState(hi),[B,C]=o.useState(gi),A=o.useRef(null),v=o.useRef(null),M=o.useRef(null),j=o.useRef(null),z=o.useRef(null),G=o.useRef(null),S=o.useRef(null),D=o.useRef(!1),K=o.useRef(0),X=o.useRef(0),E=o.useRef(0),q=o.useRef(0),H=o.useRef("vertical"),W=o.useRef(pi),J=Ge(T=>{const pe=T.x-W.current.x,Ce=T.y-W.current.y;W.current=T,Ce!==0&&(y(!0),d.start(Rt,()=>{y(!1)})),pe!==0&&(k(!0),f.start(Rt,()=>{k(!1)}))}),re=Ge(T=>{T.button===0&&(D.current=!0,K.current=T.clientY,X.current=T.clientX,H.current=T.currentTarget.getAttribute(mi.orientation),v.current&&(E.current=v.current.scrollTop,q.current=v.current.scrollLeft),z.current&&H.current==="vertical"&&z.current.setPointerCapture(T.pointerId),G.current&&H.current==="horizontal"&&G.current.setPointerCapture(T.pointerId))}),ie=Ge(T=>{if(!D.current)return;const pe=T.clientY-K.current,Ce=T.clientX-X.current;if(v.current){const Ie=v.current.scrollHeight,$e=v.current.clientHeight,N=v.current.scrollWidth,Y=v.current.clientWidth;if(z.current&&M.current&&H.current==="vertical"){const $=Re(M.current,"padding","y"),me=Re(z.current,"margin","y"),se=z.current.offsetHeight,fe=M.current.offsetHeight-se-$-me,Ne=pe/fe;v.current.scrollTop=E.current+Ne*(Ie-$e),T.preventDefault(),y(!0),d.start(Rt,()=>{y(!1)})}if(G.current&&j.current&&H.current==="horizontal"){const $=Re(j.current,"padding","x"),me=Re(G.current,"margin","x"),se=G.current.offsetWidth,fe=j.current.offsetWidth-se-$-me,Ne=Ce/fe;v.current.scrollLeft=q.current+Ne*(N-Y),T.preventDefault(),k(!0),f.start(Rt,()=>{k(!1)})}}}),V=Ge(T=>{D.current=!1,z.current&&H.current==="vertical"&&z.current.releasePointerCapture(T.pointerId),G.current&&H.current==="horizontal"&&G.current.releasePointerCapture(T.pointerId)});function ae(T){I(T.pointerType==="touch")}function ne(T){if(ae(T),T.pointerType!=="touch"){const pe=so(A.current,T.target);b(pe)}}const ce=o.useMemo(()=>({scrolling:g||w,hasOverflowX:!B.x,hasOverflowY:!B.y,overflowXStart:P.xStart,overflowXEnd:P.xEnd,overflowYStart:P.yStart,overflowYEnd:P.yEnd,cornerHidden:B.corner}),[g,w,B.x,B.y,B.corner,P]),he={role:"presentation",onPointerEnter:ne,onPointerMove:ne,onPointerDown:ae,onPointerLeave(){b(!1)},style:{position:"relative",[Kt.scrollAreaCornerHeight]:`${F.height}px`,[Kt.scrollAreaCornerWidth]:`${F.width}px`}},oe=Ve("div",t,{state:ce,ref:[r,A],props:[he,l],stateAttributesMapping:yn}),de=o.useMemo(()=>({handlePointerDown:re,handlePointerMove:ie,handlePointerUp:V,handleScroll:J,cornerSize:F,setCornerSize:O,thumbSize:ee,setThumbSize:_,touchModality:U,cornerRef:S,scrollingX:g,setScrollingX:k,scrollingY:w,setScrollingY:y,hovering:m,setHovering:b,viewportRef:v,rootRef:A,scrollbarYRef:M,scrollbarXRef:j,thumbYRef:z,thumbXRef:G,rootId:u,hiddenState:B,setHiddenState:C,overflowEdges:P,setOverflowEdges:Z,viewportState:ce,overflowEdgeThreshold:c}),[re,ie,V,J,F,ee,U,g,k,w,y,m,b,u,B,P,ce,c]);return n.jsxs(kr.Provider,{value:de,children:[!p&&Er.getElement(h),oe]})});function xi(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 wi=o.createContext(void 0);function ut(e,t=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,r))}function bi(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 qe=(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})({});const zn=1;function $n(e,t){if(t<=0)return 0;const r=ut(e,0,t),s=r,a=t-r,i=s<=zn,l=a<=zn;return i&&l?s<=a?0:t:i?0:l?t:r}let Fn=!1;function Si(){Fn||oo||(typeof CSS<"u"&&"registerProperty"in CSS&&[qe.scrollAreaOverflowXStart,qe.scrollAreaOverflowXEnd,qe.scrollAreaOverflowYStart,qe.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),Fn=!0)}const vi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{viewportRef:l,scrollbarYRef:c,scrollbarXRef:u,thumbYRef:d,thumbXRef:f,cornerRef:h,cornerSize:p,setCornerSize:m,setThumbSize:b,rootId:g,setHiddenState:k,hiddenState:w,handleScroll:y,setHovering:U,setOverflowEdges:I,overflowEdges:F,overflowEdgeThreshold:O,scrollingX:ee,scrollingY:_}=Ft(),P=hr(),Z=o.useRef(!0),B=_t(),C=_t(),A=Ge(()=>{const S=l.current,D=c.current,K=u.current,X=d.current,E=f.current,q=h.current;if(!S)return;const H=S.scrollHeight,W=S.scrollWidth,J=S.clientHeight,re=S.clientWidth,ie=S.scrollTop,V=S.scrollLeft;if(H===0||W===0)return;const ae=J>=H,ne=re>=W,ce=re/W,he=J/H,oe=Math.max(0,W-re),de=Math.max(0,H-J);let T=0,pe=0;if(!ne){let Q=0;P==="rtl"?Q=ut(-V,0,oe):Q=ut(V,0,oe),T=$n(Q,oe),pe=oe-T}const Ce=ae?0:ut(ie,0,de),Ie=ae?0:$n(Ce,de),$e=ae?0:de-Ie,N=ne?0:re,Y=ae?0:J;let $=0,me=0;!ne&&!ae&&($=D?.offsetWidth||0,me=K?.offsetHeight||0);const se=p.width===0&&p.height===0,fe=se?$:0,Ne=se?me:0,rt=Re(K,"padding","x"),Ae=Re(D,"padding","y"),Ke=Re(E,"margin","x"),Je=Re(X,"margin","y"),gt=N-rt-Ke,yt=Y-Ae-Je,kt=K?Math.min(K.offsetWidth-fe,gt):gt,Et=D?Math.min(D.offsetHeight-Ne,yt):yt,xt=Math.max(Kn,kt*ce),wt=Math.max(Kn,Et*he);if(b(Q=>Q.height===wt&&Q.width===xt?Q:{width:xt,height:wt}),D&&X){const Q=D.offsetHeight-wt-Ae-Je,je=H-J,Qe=je===0?0:ie/je,He=Math.min(Q,Math.max(0,Qe*Q));X.style.transform=`translate3d(0,${He}px,0)`}if(K&&E){const Q=K.offsetWidth-xt-rt-Ke,je=W-re,Qe=je===0?0:V/je,He=P==="rtl"?ut(Qe*Q,-Q,0):ut(Qe*Q,0,Q);E.style.transform=`translate3d(${He}px,0,0)`}const Ct=[[qe.scrollAreaOverflowXStart,T],[qe.scrollAreaOverflowXEnd,pe],[qe.scrollAreaOverflowYStart,Ie],[qe.scrollAreaOverflowYEnd,$e]];for(const[Q,je]of Ct)S.style.setProperty(Q,`${je}px`);q&&(ne||ae?m({width:0,height:0}):!ne&&!ae&&m({width:$,height:me})),k(Q=>{const je=ae||ne;return Q.y===ae&&Q.x===ne&&Q.corner===je?Q:{y:ae,x:ne,corner:je}});const Fe={xStart:!ne&&T>O.xStart,xEnd:!ne&&pe>O.xEnd,yStart:!ae&&Ie>O.yStart,yEnd:!ae&&$e>O.yEnd};I(Q=>Q.xStart===Fe.xStart&&Q.xEnd===Fe.xEnd&&Q.yStart===Fe.yStart&&Q.yEnd===Fe.yEnd?Q:Fe)});Pe(()=>{if(!l.current)return;Si();let S=!1;return bi(l.current,()=>{if(!S){S=!0;return}A()})},[A,l]),Pe(()=>{queueMicrotask(A)},[A,w,P]),Pe(()=>{l.current?.matches(":hover")&&U(!0)},[l,U]),o.useEffect(()=>{const S=l.current;if(typeof ResizeObserver>"u"||!S)return;let D=!1;const K=new ResizeObserver(()=>{if(!D){D=!0;return}A()});return K.observe(S),C.start(0,()=>{const X=S.getAnimations({subtree:!0});X.length!==0&&Promise.allSettled(X.map(E=>E.finished)).then(A).catch(()=>{})}),()=>{K.disconnect(),C.clear()}},[A,l,C]);function v(){Z.current=!1}const M={role:"presentation",...g&&{"data-id":`${g}-viewport`},...(!w.x||!w.y)&&{tabIndex:0},className:Er.className,style:{overflow:"scroll"},onScroll(){l.current&&(A(),Z.current||y({x:l.current.scrollLeft,y:l.current.scrollTop}),B.start(100,()=>{Z.current=!0}))},onWheel:v,onTouchMove:v,onPointerMove:v,onPointerEnter:v,onKeyDown:v},j=o.useMemo(()=>({scrolling:ee||_,hasOverflowX:!w.x,hasOverflowY:!w.y,overflowXStart:F.xStart,overflowXEnd:F.xEnd,overflowYStart:F.yStart,overflowYEnd:F.yEnd,cornerHidden:w.corner}),[ee,_,w.x,w.y,w.corner,F]),z=Ve("div",t,{ref:[r,l],state:j,props:[M,i],stateAttributesMapping:yn}),G=o.useMemo(()=>({computeThumbPosition:A}),[A]);return n.jsx(wi.Provider,{value:G,children:z})}),Cr=o.createContext(void 0);function ji(){const e=o.useContext(Cr);if(e===void 0)throw new Error(dn(54));return e}let Ut=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const ki=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:h,overflowEdges:p,scrollbarYRef:m,scrollbarXRef:b,viewportRef:g,thumbYRef:k,thumbXRef:w,handlePointerDown:y,handlePointerUp:U,rootId:I,thumbSize:F}=Ft(),O={hovering:u,scrolling:{horizontal:d,vertical:f}[i],orientation:i,hasOverflowX:!h.x,hasOverflowY:!h.y,overflowXStart:p.xStart,overflowXEnd:p.xEnd,overflowYStart:p.yStart,overflowYEnd:p.yEnd,cornerHidden:h.corner},ee=hr();o.useEffect(()=>{const A=g.current,v=i==="vertical"?m.current:b.current;if(!v)return;function M(j){if(!(!A||!v||j.ctrlKey)){if(j.preventDefault(),i==="vertical"){if(A.scrollTop===0&&j.deltaY<0)return}else if(A.scrollLeft===0&&j.deltaX<0)return;if(i==="vertical"){if(A.scrollTop===A.scrollHeight-A.clientHeight&&j.deltaY>0)return}else if(A.scrollLeft===A.scrollWidth-A.clientWidth&&j.deltaX>0)return;i==="vertical"?A.scrollTop+=j.deltaY:A.scrollLeft+=j.deltaX}}return v.addEventListener("wheel",M,{passive:!1}),()=>{v.removeEventListener("wheel",M)}},[i,b,m,g]);const _={...I&&{"data-id":`${I}-scrollbar`},onPointerDown(A){if(A.button===0&&A.currentTarget===A.target&&g.current){if(k.current&&m.current&&i==="vertical"){const v=Re(k.current,"margin","y"),M=Re(m.current,"padding","y"),j=k.current.offsetHeight,z=m.current.getBoundingClientRect(),G=A.clientY-z.top-j/2-M+v/2,S=g.current.scrollHeight,D=g.current.clientHeight,K=m.current.offsetHeight-j-M-v,E=G/K*(S-D);g.current.scrollTop=E}if(w.current&&b.current&&i==="horizontal"){const v=Re(w.current,"margin","x"),M=Re(b.current,"padding","x"),j=w.current.offsetWidth,z=b.current.getBoundingClientRect(),G=A.clientX-z.left-j/2-M+v/2,S=g.current.scrollWidth,D=g.current.clientWidth,K=b.current.offsetWidth-j-M-v,X=G/K;let E;ee==="rtl"?(E=(1-X)*(S-D),g.current.scrollLeft<=0&&(E=-E)):E=X*(S-D),g.current.scrollLeft=E}y(A)}},onPointerUp:U,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...i==="vertical"&&{top:0,bottom:`var(${Kt.scrollAreaCornerHeight})`,insetInlineEnd:0,[Ut.scrollAreaThumbHeight]:`${F.height}px`},...i==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${Kt.scrollAreaCornerWidth})`,bottom:0,[Ut.scrollAreaThumbWidth]:`${F.width}px`}}},P=Ve("div",t,{ref:[r,i==="vertical"?m:b],state:O,props:[_,c],stateAttributesMapping:yn}),Z=o.useMemo(()=>({orientation:i}),[i]),B=i==="vertical"?h.y:h.x;return l||!B?n.jsx(Cr.Provider,{value:Z,children:P}):null}),Ei=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{thumbYRef:l,thumbXRef:c,handlePointerDown:u,handlePointerMove:d,handlePointerUp:f,setScrollingX:h,setScrollingY:p}=Ft(),{orientation:m}=ji();return Ve("div",t,{ref:[r,m==="vertical"?l:c],state:{orientation:m},props:[{onPointerDown:u,onPointerMove:d,onPointerUp(k){m==="vertical"&&p(!1),m==="horizontal"&&h(!1),f(k)},style:{...m==="vertical"&&{height:`var(${Ut.scrollAreaThumbHeight})`},...m==="horizontal"&&{width:`var(${Ut.scrollAreaThumbWidth})`}}},i]})}),Ci=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{cornerRef:l,cornerSize:c,hiddenState:u}=Ft(),d=Ve("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(yi,{className:L("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function Tr({className:e,...t}){return n.jsx(vi,{className:L("h-full w-full outline-none focus-visible:outline-none",e),...t})}function Rr({className:e,...t}){return n.jsx(ki,{className:L("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 Ir({className:e,...t}){return n.jsx(Ei,{className:L("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function Ni({className:e,...t}){return n.jsx(Ci,{className:L("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function Ti(e){return e==="subagent"?ps:e==="cron"?hs:gs}function Ri(e){if(!e||!Array.isArray(e.content))return"";const t=e.content.map(s=>s.type==="text"?String(s.text??""):"").join(" ");return xr(t).replace(/\s+/g," ").trim()}function Ii(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 Ai(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=Ii(r);if(s)return s}return null}function Mi(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 Di(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function Oi({session:e,active:t,isGenerating:r=!1,isPinned:s,selectionMode:a=!1,selected:i=!1,onToggleSelect:l,onSelect:c,onTogglePin:u,onRename:d,onDelete:f,onExport:h}){const p=e.label||e.title||e.derivedTitle||e.friendlyId,m=Ti(e.kind),b=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?Ri(e.lastMessage):"",g=b.length>50?`${b.slice(0,50).trimEnd()}…`:b,k=e.kind==="subagent"?Di(e.status):null,w=e.kind==="cron"?Ai(e.lastMessage):null;return n.jsxs(Be,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:y=>{if(a){y.preventDefault(),y.stopPropagation(),l?.(e);return}c?.()},className:L("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:L("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(te,{icon:m,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"}):k==="success"?n.jsx(te,{icon:sr,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):k==="error"?n.jsx(te,{icon:$t,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),g?n.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:g}):null,e.kind==="cron"&&w?n.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:Mi(w)}):null]})]}),a?null:n.jsxs(fn,{children:[n.jsx(mn,{type:"button",onClick:y=>{y.preventDefault(),y.stopPropagation()},className:L("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(te,{icon:ds,size:20,strokeWidth:1.5})}),n.jsxs(pn,{side:"bottom",align:"end",children:[n.jsxs(tt,{onClick:y=>{y.preventDefault(),y.stopPropagation(),u(e)},className:"gap-2",children:[n.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",s?"Unpin Session":"Pin Session"]}),n.jsxs(tt,{onClick:y=>{y.preventDefault(),y.stopPropagation(),d(e)},className:"gap-2",children:[n.jsx(te,{icon:fs,size:20,strokeWidth:1.5})," ","Rename"]}),n.jsxs(tt,{onClick:y=>{y.preventDefault(),y.stopPropagation(),h(e)},className:"gap-2",children:[n.jsx(te,{icon:ms,size:20,strokeWidth:1.5})," ","Export"]}),nn(e.key)?null:n.jsxs(tt,{onClick:y=>{y.preventDefault(),y.stopPropagation(),f(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[n.jsx(te,{icon:or,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function Li(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 qt=o.memo(Oi,Li),Ar="opencami-pinned-sessions",Mr="opencami-sidebar-folders",We={webchat:!1,subagent:!1,cron:!1,other:!1};async function _i(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 ze(r))}async function Pi(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 Ki(){if(typeof window>"u")return[];try{const e=localStorage.getItem(Ar);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}catch{return[]}}function Ui(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(Ar,JSON.stringify(t))}catch{}}function zi(){if(typeof window>"u")return{...We};try{const e=localStorage.getItem(Mr);if(!e)return{...We};const t=JSON.parse(e);return!t||typeof t!="object"?{...We}:{webchat:typeof t.webchat=="boolean"?t.webchat:We.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:We.subagent,cron:typeof t.cron=="boolean"?t.cron:We.cron,other:typeof t.other=="boolean"?t.other:We.other}}catch{return{...We}}}function $i(e){if(!(typeof window>"u"))try{localStorage.setItem(Mr,JSON.stringify(e))}catch{}}function Dt(e,t,r){return r&&e.key?e.key===r:e.friendlyId===t}function Fi(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function Vt(e,t,r,s){return Dt(e,t,r)&&s?!0:Fi(e.status)}const Hi=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),h=ht(),[p,m]=o.useState(()=>Ki()),[b,g]=o.useState(()=>zi()),[k,w]=o.useState(!1),[y,U]=o.useState(()=>new Set),I=o.useMemo(()=>new Set(p),[p]),F=f.filter(S=>I.has(S.key)),O=f.filter(S=>!I.has(S.key)),ee=F.length>0&&O.length>0,_=o.useMemo(()=>{const S={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const D of O){const K=D.kind??"other";S[K].push(D)}return S},[O]),P=o.useMemo(()=>f.filter(S=>y.has(S.key)),[y,f]),Z=P.length,B=o.useCallback(()=>{w(S=>(S&&U(new Set),!S))},[]),C=o.useCallback(S=>{nn(S.key)||U(D=>{const K=new Set(D);return K.has(S.key)?K.delete(S.key):K.add(S.key),K})},[]),A=o.useCallback(()=>{U(new Set(f.filter(S=>!nn(S.key)).map(S=>S.key)))},[f]),v=o.useCallback(()=>{w(!1),U(new Set)},[]),M=o.useCallback(async()=>{if(P.length===0||!window.confirm(`Delete ${P.length} sessions? This will archive them.`))return;const D=[];await Pi(P,10,async K=>{try{await _i(K.key)}catch(X){throw D.push(K.label||K.title||K.derivedTitle||K.friendlyId),X}}),D.length>0&&(console.error("[sidebar] Bulk delete failed for some sessions",D),window.alert(`Could not delete ${D.length} session${D.length!==1?"s":""}:
8
+
9
+ ${D.join(`
10
+ `)}`)),w(!1),U(new Set),h.invalidateQueries({queryKey:ge.sessions})},[h,P]),j=o.useCallback(S=>{m(D=>{const X=D.includes(S.key)?D.filter(E=>E!==S.key):[...D,S.key];return Ui(X),X})},[]),z=o.useCallback((S,D)=>{g(K=>{const X={...K,[S]:D};return $i(X),X})},[]);function G(S,D,K){return K.length===0?null:n.jsxs(sn,{className:"flex flex-col",open:b[S],onOpenChange:X=>z(S,X),children:[n.jsxs(on,{className:L("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:D}),n.jsx("span",{className:L("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:K.length})]}),n.jsx(an,{contentClassName:"flex flex-col gap-px",children:K.map(X=>n.jsx(qt,{session:X,active:Dt(X,r,s),isGenerating:Vt(X,r,s,a),isPinned:!1,selectionMode:k,selected:y.has(X.key),onToggleSelect:C,onSelect:l,onTogglePin:j,onRename:c,onDelete:u,onExport:d},X.key))})]})}return n.jsxs(sn,{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(on,{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(te,{icon:ys,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),n.jsx("button",{type:"button",onClick:B,className:L("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",k?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:k?"Done":"Select"})]}),n.jsx(an,{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(Tr,{className:"min-h-0",children:n.jsxs("div",{className:"flex flex-col gap-2 pl-2 pr-2",children:[F.length>0?n.jsx("div",{className:"flex flex-col gap-px",children:F.map(S=>n.jsx(qt,{session:S,active:Dt(S,r,s),isGenerating:Vt(S,r,s,a),isPinned:!0,selectionMode:k,selected:y.has(S.key),onToggleSelect:C,onSelect:l,onTogglePin:j,onRename:c,onDelete:u,onExport:d},S.key))}):null,ee?n.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,_.chat.length>0?n.jsxs("div",{className:"flex flex-col gap-px",children:[n.jsx("div",{className:L("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:_.chat.map(S=>n.jsx(qt,{session:S,active:Dt(S,r,s),isGenerating:Vt(S,r,s,a),isPinned:!1,selectionMode:k,selected:y.has(S.key),onToggleSelect:C,onSelect:l,onTogglePin:j,onRename:c,onDelete:u,onExport:d},S.key))})]}):null,G("webchat","🦎 OpenCami",_.webchat),G("subagent","🤖 Sub-agents",_.subagent),G("cron","⏰ Cron / Isolated",_.cron),G("other","📁 Other",_.other)]})}),n.jsx(Rr,{orientation:"vertical",children:n.jsx(Ir,{})})]})}),k?n.jsxs("div",{className:"shrink-0 border-t border-primary-200 bg-surface px-2 py-2 flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-xs text-primary-600 font-medium",children:[Z," selected"]}),n.jsx("button",{type:"button",onClick:A,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:M,disabled:Z===0,className:L("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",Z>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[n.jsx(te,{icon:or,size:14,strokeWidth:1.5}),"Delete"]}),n.jsx("button",{type:"button",onClick:v,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]})},Wi);function Wi(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 Bi=o.lazy(()=>nt(()=>import("./settings-dialog-aL-AH4Rt.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}))),Xi=o.lazy(()=>nt(()=>import("./session-export-dialog-tDiFuv3a.js"),__vite__mapDeps([25,1,4,3,5,6,7,8,9,2])).then(e=>({default:e.SessionExportDialog})));function Yi({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:h,setSettingsOpen:p,pathsLoading:m,pathsError:b,paths:g,handleOpenSettings:k,closeSettings:w,copySessionsDir:y,copyStorePath:U}=Io(),{deleteSession:I}=Uo(),{renameSession:F}=zo(),O={duration:.15,ease:l?"easeIn":"easeOut"},[ee,_]=o.useState(!1),[P,Z]=o.useState(null),[B,C]=o.useState(""),[A,v]=o.useState(!1),[M,j]=o.useState(null),[z,G]=o.useState(null),[S,D]=o.useState(""),[K,X]=o.useState(!1),[E,q]=o.useState(null),[H,W]=o.useState(null),[J,re]=o.useState(""),ie=ht();function V(T){Z(T.key),C(T.label||T.title||T.derivedTitle||""),_(!0)}function ae(T){P&&F(P,T),_(!1),Z(null)}function ne(T){j(T.key),G(T.friendlyId),D(T.label||T.title||T.derivedTitle||T.friendlyId),v(!0)}function ce(){if(M&&z){const T=z===t;T&&d&&d(),I(M,z,T)}v(!1),j(null),G(null)}function he(T){q(T.key),W(T.friendlyId),re(T.label||T.title||T.derivedTitle||T.friendlyId),X(!0)}function oe(T){if(E&&H){const pe=ge.history(H,E),Ce=ie.getQueryData(pe);Ce?.messages&&Wo(J,Ce.messages,T)}X(!1),q(null),W(null)}const de={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:O,className:de.className,children:[n.jsxs(be.div,{layout:!0,transition:{layout:O},className:L("flex items-center h-12 px-2 justify-between"),children:[n.jsx(Me,{initial:!1,children:l?null:n.jsx(be.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,children:n.jsxs(Be,{to:"/new",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[n.jsx(ao,{className:"size-5"}),n.jsx(lo,{})]})})}),n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{onClick:c,render:n.jsx(we,{size:"icon-sm",variant:"ghost",children:n.jsx(te,{icon:xs,size:20,strokeWidth:1.5})})}),n.jsx(_e,{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:O},className:"w-full space-y-2",children:[n.jsxs(we,{disabled:a,variant:"ghost",size:"sm",onClick:i,onMouseUp:u,className:"w-full pl-1.5 justify-start",children:[n.jsx(te,{icon:ws,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),(()=>{try{const T=localStorage.getItem("opencami-file-explorer");return T===null?!0:T==="true"}catch{return!0}})()&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{asChild:!0,children:n.jsxs(Be,{to:"/files",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(te,{icon:bs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),l&&n.jsx(_e,{side:"right",children:"Files"})]})}),(()=>{try{const T=localStorage.getItem("opencami-memory-viewer");return T===null?!0:T==="true"}catch{return!0}})()&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{asChild:!0,children:n.jsxs(Be,{to:"/memory",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(te,{icon:en,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Memory"})})]})}),l&&n.jsx(_e,{side:"right",children:"Memory"})]})}),(()=>{try{return localStorage.getItem("opencami-skills-browser")==="true"}catch{return!1}})()&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{asChild:!0,children:n.jsxs(Be,{to:"/skills",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(te,{icon:Ss,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Skills"})})]})}),l&&n.jsx(_e,{side:"right",children:"Skills"})]})}),(()=>{try{return localStorage.getItem("opencami-agent-manager")==="true"}catch{return!1}})()&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{asChild:!0,children:n.jsxs(Be,{to:"/agents",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(te,{icon:en,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Agents"})})]})}),l&&n.jsx(_e,{side:"right",children:"Agents"})]})}),(()=>{try{return localStorage.getItem("opencami-cron-manager")==="true"}catch{return!1}})()&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{asChild:!0,children:n.jsxs(Be,{to:"/bots",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(te,{icon:vs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Cron Jobs"})})]})}),l&&n.jsx(_e,{side:"right",children:"Cron Jobs"})]})}),(()=>{try{return localStorage.getItem("feature_dashboard")==="true"}catch{return!1}})()&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{asChild:!0,children:n.jsxs(Be,{to:"/dashboard",className:L(Ze({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(te,{icon:js,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Dashboard"})})]})}),l&&n.jsx(_e,{side:"right",children:"Dashboard"})]})})]}),n.jsx(be.div,{layout:!0,transition:{layout:O},className:"w-full",children:n.jsxs(we,{variant:"ghost",size:"sm",onClick:f,className:"w-full pl-1.5 justify-start",children:[n.jsx(te,{icon:ks,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(Me,{initial:!1,children:!l&&n.jsx(be.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"pt-0 flex flex-col w-full min-h-0 h-full",children:n.jsx("div",{className:"flex-1 min-h-0",children:n.jsx(Hi,{sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s,onSelect:u,onRename:V,onDelete:ne,onExport:he})})},"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:O},className:"w-full",children:n.jsxs(we,{variant:"ghost",size:"sm",onClick:k,title:l?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[n.jsx(te,{icon:Es,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Me,{initial:!1,mode:"wait",children:!l&&n.jsx(be.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:O,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),h&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Bi,{open:h,onOpenChange:p,pathsLoading:m,pathsError:b,paths:g,onClose:w,onCopySessionsDir:y,onCopyStorePath:U})}),n.jsx(ei,{open:ee,onOpenChange:_,sessionTitle:B,onSave:ae,onCancel:()=>_(!1)}),n.jsx(Zo,{open:A,onOpenChange:v,sessionTitle:S,onConfirm:ce,onCancel:()=>v(!1)}),K&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Xi,{open:K,onOpenChange:X,sessionTitle:J,onExport:oe,onCancel:()=>X(!1)})})]})}function Gi(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 qi(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!Gi(e.sessions,t.sessions))}const Vi=o.memo(Yi,qi);function Hn(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 Wn(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 Ji({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:Wn(0),hasData:!1,isNearlyFull:!1};const h=typeof e=="number"&&e>0?e:0,p=Math.min(100,Math.round(h/t*100));return{percentage:p,usedStr:Hn(h),maxStr:Hn(t),colors:Wn(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:L("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:L("h-full rounded-full transition-all duration-500 ease-out",l.bar,u&&"animate-pulse"),style:{width:`${s}%`}})}),n.jsx("span",{className:L("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:L("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:L("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-500",children:"Context window"}),n.jsxs("span",{className:L("font-semibold",l.text),children:[s,"%"]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-primary-700 dark:text-primary-700",children:[n.jsx("span",{className:"font-medium",children:a}),n.jsx("span",{className:"text-primary-400 dark:text-primary-500",children:"/"}),n.jsx("span",{children:i}),n.jsx("span",{className:"text-primary-400 dark:text-primary-500",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:L("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 Qi=o.memo(Ji);function Zi({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 pr-4 h-12 flex shrink-0 min-w-0 items-center bg-surface tauri-drag-header",children:[r?n.jsx(we,{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(te,{icon:Cs,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(Qi,{totalTokens:a,contextTokens:i,className:"ml-3 hidden sm:flex"})]})}const ea=o.memo(Zi);function ta(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function na(e){const t=new Date(e);return ta(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 ra(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 sa({timestamp:e}){const t=na(e),r=ra(e);return n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{className:"inline-flex items-center text-xs text-primary-600",children:t}),n.jsx(_e,{side:"top",children:r})]})})}function oa({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),[h,p]=o.useState(()=>{if(typeof window>"u")return!0;try{const w=localStorage.getItem("opencami-tts-enabled");return w===null?!0:w==="true"}catch{return!0}});o.useEffect(()=>{function w(y){y.key==="opencami-tts-enabled"&&p(y.newValue===null?!0:y.newValue==="true")}return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[]),o.useEffect(()=>()=>{f.current?.abort(),u.current&&(u.current.pause(),u.current=null),d.current&&(URL.revokeObjectURL(d.current),d.current=null)},[]);const m=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 w=new AbortController;f.current=w,c("loading");try{const y=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e}),signal:w.signal});if(!y.ok)throw new Error("TTS failed");const U=await y.blob(),I=URL.createObjectURL(U);d.current=I;const F=new Audio(I);u.current=F,F.onended=()=>{c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null},F.onerror=()=>{c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null},await F.play(),c("playing")}catch(y){if(y instanceof Error&&y.name==="AbortError"){c("idle");return}c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null}},g=t==="end"?"justify-end":"justify-start",k=t==="start"&&h&&e.trim().length>0;return n.jsxs("div",{className:L("flex items-center gap-2 text-xs text-primary-600 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 duration-100 ease-out",s?"opacity-100":"opacity-0",g),children:[n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{type:"button",onClick:()=>{m().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(te,{icon:a?ir:Ns,size:16,strokeWidth:1.6})}),n.jsx(_e,{side:"top",children:"Copy"})]})}),k&&n.jsx(De,{children:n.jsxs(Oe,{children:[n.jsx(Le,{type:"button",onClick:()=>{b().catch(()=>{})},disabled:l==="loading",className:L("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(te,{icon:l==="loading"?Ts:l==="playing"?ar:Rs,size:16,strokeWidth:1.6,className:L(l==="loading"&&"animate-spin")})}),n.jsx(_e,{side:"top",children:l==="loading"?"Generating speech…":l==="playing"?"Stop":"Listen"})]})}),n.jsx(sa,{timestamp:r})]})}function Dr({children:e,className:t,...r}){return n.jsx("div",{className:L("flex gap-3 w-full",t),...r,children:e})}function ia({children:e,markdown:t=!1,className:r,...s}){const a=L("rounded-[12px] break-words whitespace-normal min-w-0 max-w-full overflow-x-hidden",r);return t?n.jsx(co,{className:a,...s,children:e}):n.jsx("div",{className:a,...s,children:e})}function aa({toolPart:e,defaultOpen:t=!1}){const{state:r,input:s,output:a,toolCallId:i}=e,l=(d,f=3200)=>{const h=d===void 0?"undefined":d;let p;if(typeof h=="string")try{p=JSON.stringify(JSON.parse(h),null,2)}catch{p=h}else p=JSON.stringify(h,null,2);return p.length<=f?p:`${p.slice(0,f).trimEnd()}
11
+ …[truncated]`},c=r==="output-error"?$t:r==="output-available"?sr:Is,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(sn,{defaultOpen:t,children:[n.jsxs(on,{render:n.jsx(we,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[n.jsx(te,{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(te,{icon:lr,size:14,strokeWidth:1.5,className:"ml-auto text-primary-700/80 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),n.jsx(an,{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),"..."]})]})})]})})}const la=o.lazy(()=>nt(()=>import("./thinking-dfGrFAMV.js"),__vite__mapDeps([26,1,3,17,18,5,6,7,8,14,19,4,9,2,11,15,20,13,21,22,23,16,24])).then(e=>({default:e.Thinking}))),ca=o.lazy(()=>nt(()=>import("./search-sources-badge-B8Z-8sSf.js"),__vite__mapDeps([27,1,3])).then(e=>({default:e.SearchSourcesBadge})));function ua(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 Bn(e){return Ye(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 da(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 Xn(e,t){if(!t)return"";const r=Ye(e);return r.length===0?"":r.map(s=>s.id?da(t.get(s.id)):"missing").join("||")}function fa(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 Yn(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=fa(r);if(s)return s}return null}function ln(e){const r=(Array.isArray(e.content)?e.content:[]).find(s=>s.type==="thinking");return r&&"thinking"in r?String(r.thinking??""):null}function ma(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 ft=/^📎 Uploaded file:\s*(\/uploads\/\S+)\s*$/;function pa(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 ha(e){if(!e)return[];const t=e.trimStart();if(t.startsWith(">")||t.startsWith("```"))return[];const r=e.split(`
12
+ `),s=[];for(const i of r){if(ft.test(i)){s.push(i);continue}if(s.length>0&&i.trim()===""){s.push(i);continue}break}const a=r[0]??"";return ft.test(a)?s.filter(i=>ft.test(i)):[]}function ga(e){const t=[],r=new Set;for(const s of ha(e)){const i=s.match(ft)?.[1];!i||r.has(i)||(r.add(i),t.push({path:i,filename:i.split("/").pop()||i}))}return t}function ya(e){const t=e.split(`
13
+ `);if(!ft.test(t[0]??""))return e.trim();let r=0;for(;r<t.length&&ft.test(t[r]);)r++;for(;r<t.length&&t[r].trim()==="";)r++;return t.slice(r).join(`
14
+ `).replace(/\n{3,}/g,`
15
+
16
+ `).trim()}function xa({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,onRetry:h,onDismiss:p}){const{settings:m}=uo(),b=e.role||"assistant",g=ve(e),k=ln(e),w=ma(e),y=b==="user",U=y&&e.status==="error",I=o.useMemo(()=>w.map(j=>`data:${j.source.media_type};base64,${j.source.data}`),[w]),F=jt(e),O=zt(),ee=Gs(j=>j.openInEditor),_=o.useMemo(()=>ga(g),[g]),[P,Z]=o.useState({}),B=o.useMemo(()=>ya(g),[g]);o.useEffect(()=>{let j=!1;async function z(){const G={};await Promise.all(_.map(async S=>{try{const D=await fetch(`/api/files/info?path=${encodeURIComponent(S.path)}`);if(!D.ok){G[S.path]=null;return}const K=await D.json();G[S.path]=typeof K.size=="number"?K.size:null}catch{G[S.path]=null}})),j||Z(G)}return _.length>0?z():Z({}),()=>{j=!0}},[_]);const C=async j=>{ee(j),await O({to:"/files"})},A=b==="assistant"?Ye(e):[],v=A.length>0,M=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:L("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",y?"items-end":"items-start"),children:[k&&m.showReasoningBlocks&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(o.Suspense,{fallback:null,children:n.jsx(la,{content:k})})}),w.length>0&&n.jsx("div",{className:L("flex flex-wrap gap-2 mb-2",y?"justify-end":"justify-start"),children:w.map((j,z)=>n.jsx("img",{src:I[z],alt:`Attachment ${z+1}`,loading:"lazy",decoding:"async",fetchPriority:"low",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},z))}),_.length>0&&n.jsx("div",{className:L("mb-2 flex w-full flex-col gap-2",y?"items-end":"items-start"),children:_.map(j=>n.jsxs("button",{type:"button",onClick:()=>{C(j.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(te,{icon:cr,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:j.filename}),n.jsx("p",{className:"text-xs text-primary-600",children:pa(P[j.path]??null)})]})]},j.path))}),n.jsx(Dr,{className:L("min-w-0 max-w-full",y?"flex-row-reverse":""),children:n.jsx(ia,{markdown:!y,isStreaming:!y&&s,className:L("text-primary-900 opencami-text-size min-w-0 max-w-full",y?"opencami-message-user bg-primary-100 px-4 py-[var(--opencami-user-bubble-py)] max-w-[85%]":"opencami-message-assistant bg-transparent w-full",!y&&s&&"stream-fade-in",U&&"opacity-60"),children:B})}),U&&n.jsxs("div",{className:"flex items-center gap-2 text-xs text-red-500 dark:text-red-400",children:[n.jsx("span",{children:"Failed to send"}),h&&n.jsx("button",{type:"button",className:"underline hover:text-red-700 dark:hover:text-red-300",onClick:()=>h(e),children:"Retry"}),p&&n.jsx("button",{type:"button",className:"underline hover:text-red-700 dark:hover:text-red-300",onClick:()=>p(e),children:"Dismiss"})]}),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:A.map(j=>{const z=j.id?t?.get(j.id):void 0,G=ua(j,z);return n.jsx(aa,{toolPart:G,defaultOpen:!1},j.id||j.name)})}),M.length>0&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(o.Suspense,{fallback:null,children:n.jsx(ca,{sources:M})})}),!v&&n.jsx(oa,{text:g,timestamp:F,align:y?"end":"start",forceVisible:r})]})}function wa(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.onRetry!==t.onRetry||e.onDismiss!==t.onDismiss||e.message.status!==t.message.status||(e.message.role||"assistant")!==(t.message.role||"assistant")||ve(e.message)!==ve(t.message)||ln(e.message)!==ln(t.message)||Bn(e.message)!==Bn(t.message)||Xn(e.message,e.toolResultsByCallId)!==Xn(t.message,t.toolResultsByCallId)||Yn(e.message)!==Yn(t.message))}const Jt=o.memo(xa,wa);function ba({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 h=Math.abs(f.scrollHeight-f.scrollTop-f.clientHeight)<100;i(h)},[r]);return o.useLayoutEffect(()=>{const f=r.current;if(!f)return;const h=()=>{u.current=f.scrollTop,d()},p=new MutationObserver(()=>{f&&(f.scrollTop!==u.current&&(u.current=f.scrollTop),d())});return d(),f.addEventListener("scroll",h),p.observe(f,{childList:!0,subtree:!0}),()=>{f.removeEventListener("scroll",h),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(we,{variant:"secondary",size:"icon-sm",className:L("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(te,{icon:lr,size:18,strokeWidth:1.8})})}function Sa({className:e,viewportRef:t,scrollRef:r,viewportProps:s}){return n.jsxs(Nr,{className:L("relative flex flex-1 min-h-0 flex-col",e),children:[n.jsx(Tr,{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(ba,{scrollRef:r})})}),n.jsx(Rr,{orientation:"vertical",children:n.jsx(Ir,{})}),n.jsx(Ni,{})]})}function va(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 ja(e,t){return!(e.className!==t.className||e.viewportRef!==t.viewportRef||e.scrollRef!==t.scrollRef||!va(e.viewportProps,t.viewportProps))}const ka=o.memo(Sa,ja);function Ea({viewportNode:e,children:t}){return e?os.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 Ca({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(ka,{className:t,viewportRef:c,scrollRef:a,viewportProps:s}),n.jsx(Ea,{viewportNode:i,children:e})]})}const Na=o.memo(Ca);function Ta({children:e,className:t,...r}){return n.jsx("div",{className:L("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 Ra({...e}){return n.jsx("div",{className:"h-px w-full shrink-0 scroll-mt-4 pt-6","aria-hidden":"true",...e})}function Ia({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:L("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 Aa({className:e}){return n.jsxs("div",{className:L("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(Ia,{className:"text-sm",duration:2,children:"Generating..."})]})}const Gn=o.lazy(()=>nt(()=>import("./follow-up-suggestions-BPjWBpiy.js"),__vite__mapDeps([28,1,3,17,18,5,6,7,8,14,19,4,9,2,11,15,20,13,21,22,23,16,24])).then(e=>({default:e.FollowUpSuggestions})));function Ma({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:h,contentStyle:p,onFollowUpClick:m,jumpToMessageId:b,onRetryMessage:g,onDismissMessage:k}){const w=o.useRef(null),y=o.useRef(null),U=o.useRef(!1),I=o.useRef(d),F=o.useRef(void 0),[O,ee]=o.useState(null),_=o.useMemo(()=>e.filter(E=>E.role!=="toolResult"),[e]),P=o.useDeferredValue(_),Z=o.useMemo(()=>{const E=new Map;for(const q of e){if(q.role!=="toolResult")continue;const H=q.toolCallId;typeof H=="string"&&H.trim().length>0&&E.set(H,q)}return E},[e]),B=o.useDeferredValue(Z),C=o.useMemo(()=>{const E=[];for(const q of P){if(q.role!=="assistant")continue;const H=Ye(q);for(const W of H){if(!W.id)continue;const J=W.name==="web_search",re=W.name==="web_fetch",ie=W.name==="exec";if(!J&&!re&&!ie)continue;const V=B.get(W.id),ae=V?.content?.map(ne=>ne.type==="text"?String(ne.text??""):"").join("").trim()??"";E.push([W.id,W.name??"",typeof W.arguments?.url=="string"?W.arguments.url:"",V?.isError?"1":"0",ae].join("::"))}}return E.join("||")},[P,B]),A=o.useMemo(()=>{const E=J=>J?J.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,`
17
+ `).trim():"",q=(J,re,ie)=>{try{const V=JSON.parse(J),ae=Array.isArray(V)?V:V?.results??V?.web?.results??[];if(!Array.isArray(ae))return!1;let ne=!1;for(const ce of ae)ce?.url&&ce?.title&&!ie.has(ce.url)&&(ie.add(ce.url),re.push({title:E(ce.title),url:ce.url,snippet:E(ce.description||ce.snippet||ce.content||"")}),ne=!0);return ne}catch{return!1}},H=[],W=new Set;for(const J of P){if(J.role!=="assistant")continue;const re=Ye(J);for(const ie of re){if(!ie.id)continue;const V=ie.name==="web_search",ae=ie.name==="web_fetch",ne=ie.name==="exec";if(!V&&!ae&&!ne)continue;const ce=B.get(ie.id);if(!ce)continue;const he=ce.content?.map(oe=>oe.type==="text"?String(oe.text??""):"").join("").trim();if(he){if(V||ne){if(ne&&(!he.includes('"results"')||!he.includes('"url"')))continue;let oe=he;const de=he.indexOf("{");de>0&&(oe=he.slice(de));const T=oe.lastIndexOf("}");T>0&&(oe=oe.slice(0,T+1)),q(oe,H,W)}else if(ae){const oe=ie.arguments?.url;if(oe&&!W.has(oe)){W.add(oe);let de;try{de=new URL(oe).hostname}catch{de=oe}H.push({title:de,url:oe})}}}}}return H},[C,P,B]),v=_.map((E,q)=>({message:E,index:q})).filter(({message:E})=>E.role!=="user").map(({index:E})=>E).pop(),M=_.map((E,q)=>({message:E,index:q})).filter(({message:E})=>E.role==="assistant").map(({index:E})=>E).pop(),j=_.map((E,q)=>({message:E,index:q})).filter(({message:E})=>E.role==="user").map(({index:E})=>E).pop(),z=l&&(typeof j!="number"||typeof v!="number"||v<j),G=typeof j=="number"?j:-1,S=d&&G>=0,D=typeof M=="number"?_[M]:void 0,K=D?ve(D):"",X=!l&&!c&&K.length>0&&m!==void 0&&(typeof j!="number"||typeof M!="number"||M>j);return o.useLayoutEffect(()=>{if(!t){if(d){const E=!I.current||F.current!==j;I.current=!0,F.current=j,E&&y.current&&(U.current=!0,y.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{U.current=!1},0));return}I.current=!1,F.current=j,w.current&&(U.current=!0,w.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{U.current=!1},0))}},[t,_.length,u,d,j]),o.useEffect(()=>{if(!b||t)return;const E=document.getElementById(`message-${b}`);if(!E)return;E.scrollIntoView({behavior:"smooth",block:"center"}),ee(b);const q=window.setTimeout(()=>{ee(H=>H===b?null:H)},1800);return()=>window.clearTimeout(q)},[b,t,_]),n.jsx(Na,{className:"flex-1 min-h-0 -mb-4",children:n.jsxs(Ta,{className:"pt-6",style:p,children:[a&&i==="start"?a:null,r&&!a?s??n.jsx("div",{"aria-hidden":!0}):S?n.jsxs(n.Fragment,{children:[_.slice(0,G).map((E,q)=>{const H=typeof E.id=="string"?E.id:void 0,W=H||q,J=typeof v=="number"&&q===v,re=typeof v=="number"&&q===v,ie=E.role==="assistant"&&Ye(E).length>0;return n.jsx(Jt,{message:E,toolResultsByCallId:ie?Z:void 0,forceActionsVisible:J,isStreaming:re&&c,isLastAssistant:re,aggregatedSearchSources:re?A:void 0,messageDomId:H?`message-${H}`:void 0,highlighted:O===H,onRetry:g,onDismiss:k},W)}),n.jsxs("div",{className:"flex flex-col gap-[var(--opencami-msg-gap)]",style:{minHeight:`${Math.max(0,f)}px`},children:[_.slice(G).map((E,q)=>{const H=G+q,W=typeof E.id=="string"?E.id:void 0,J=W||H,re=typeof v=="number"&&H===v,ie=typeof v=="number"&&H===v,V=H===j?y:void 0,ae=H===j?"scroll-mt-0":void 0,ne=H===j?h:void 0,ce=E.role==="assistant"&&Ye(E).length>0;return n.jsx(Jt,{message:E,toolResultsByCallId:ce?Z:void 0,forceActionsVisible:re,isStreaming:ie&&c,isLastAssistant:ie,aggregatedSearchSources:ie?A:void 0,wrapperRef:V,wrapperClassName:ae,wrapperScrollMarginTop:ne,messageDomId:W?`message-${W}`:void 0,highlighted:O===W,onRetry:g,onDismiss:k},J)}),z?n.jsx("div",{className:"py-2",children:n.jsx(Aa,{})}):null,X&&m?n.jsx(o.Suspense,{fallback:null,children:n.jsx(Gn,{responseText:K,onSuggestionClick:m,disabled:l})}):null]})]}):n.jsxs(n.Fragment,{children:[_.map((E,q)=>{const H=typeof E.id=="string"?E.id:void 0,W=H||q,J=typeof v=="number"&&q===v,re=typeof v=="number"&&q===v,ie=E.role==="assistant"&&Ye(E).length>0;return n.jsx(Jt,{message:E,toolResultsByCallId:ie?Z:void 0,forceActionsVisible:J,isStreaming:re&&c,isLastAssistant:re,aggregatedSearchSources:re?A:void 0,messageDomId:H?`message-${H}`:void 0,highlighted:O===H,onRetry:g,onDismiss:k},W)}),X&&m?n.jsx(o.Suspense,{fallback:null,children:n.jsx(Gn,{responseText:K,onSuggestionClick:m,disabled:l})}):null]}),a&&i==="end"?a:null,n.jsx(Ra,{ref:w})]})})}function Da(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&&e.onRetryMessage===t.onRetryMessage&&e.onDismissMessage===t.onDismissMessage}const Oa=o.memo(Ma,Da),cn=yr()(gr(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function La(){const e=cn(r=>r.level),t=cn(r=>r.setLevel);return{level:e,setLevel:t}}const Qt=[{value:"off",label:"Off",description:"No reasoning",shortLabel:"Off"},{value:"low",label:"Low",description:"Think",shortLabel:"Low"},{value:"medium",label:"Medium",description:"Think harder",shortLabel:"Medium"},{value:"high",label:"High",description:"Ultrathink",shortLabel:"High"}];function _a({className:e}){const{level:t,setLevel:r}=La(),s=Qt.find(a=>a.value===t)??Qt[1];return n.jsxs(fn,{children:[n.jsxs(mn,{className:L("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(te,{icon:en,size:20,strokeWidth:1.5,className:L(t==="off"?"text-primary-400":"text-primary-700")}),n.jsx("span",{className:"text-pretty",children:s.shortLabel})]}),n.jsx(pn,{side:"top",align:"start",className:"min-w-[190px]",children:Qt.map(a=>n.jsxs(tt,{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(te,{icon:ir,size:20,strokeWidth:1.5,className:"text-primary-600"})]},a.value))})]})}function Pa({commands:e,selectedIndex:t,onSelect:r,className:s}){return e.length===0?null:n.jsx("div",{className:L("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:L("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-700 dark:text-primary-700",children:a.command}),n.jsx("span",{className:"text-xs text-primary-600 dark:text-primary-600",children:a.description})]})},a.command)})})})}const Ka=o.memo(Pa),Or=o.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:is.createRef()});let mt=null,qn=!1;function Ua(){qn||typeof window>"u"||(qn=!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||!mt||mt.disabled||mt.focus()}))}function Lr(){return o.useContext(Or)}function za({className:e,isLoading:t=!1,maxHeight:r=240,value:s,onValueChange:a,onSubmit:i,children:l,disabled:c=!1,onClick:u,...d}){const[f,h]=o.useState(s||""),p=o.useRef(null);Ua();function m(g){h(g),a?.(g)}function b(g){c||p.current?.focus(),u?.(g)}return n.jsx(De,{children:n.jsx(Or.Provider,{value:{isLoading:t,value:s??f,setValue:a??m,maxHeight:r,onSubmit:i,disabled:c,textareaRef:p},children:n.jsx("div",{onClick:b,className:L("bg-surface dark:bg-primary-200 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 $a({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 h(g){!g||r||(g.style.height="auto",typeof c=="number"?g.style.height=`${Math.min(g.scrollHeight,c)}px`:g.style.height=`min(${g.scrollHeight}px, ${c})`)}function p(g){f.current=g,typeof s=="function"?s(g):s&&"current"in s&&(s.current=g),g?mt=g:mt===g&&(mt=null),h(g)}o.useLayoutEffect(()=>{if(!f.current||r)return;const g=f.current;g.style.height="auto",typeof c=="number"?g.style.height=`${Math.min(g.scrollHeight,c)}px`:g.style.height=`min(${g.scrollHeight}px, ${c})`},[i,c,r]);function m(g){h(g.target),l(g.target.value)}function b(g){g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),u?.()),t?.(g)}return n.jsx("textarea",{ref:p,value:i,onChange:m,onKeyDown:b,className:L("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 Fa({children:e,className:t,...r}){return n.jsx("div",{className:L("flex items-center gap-2",t),...r,children:e})}function Vn({tooltip:e,children:t,className:r,side:s="top",...a}){const{disabled:i}=Lr();return n.jsxs(Oe,{...a,children:[n.jsx(Le,{disabled:i,onClick:l=>l.stopPropagation(),children:t}),n.jsx(_e,{side:s,className:r,children:e})]})}const _r="opencami-personas-enabled",un="opencami-active-persona";function Ha(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(_r);return e===null?!0:e==="true"}catch{return!0}}function Wa(){if(typeof window>"u")return null;try{const e=localStorage.getItem(un);return e?JSON.parse(e):null}catch{return null}}function Jn(e){if(!(typeof window>"u"))try{e?localStorage.setItem(un,JSON.stringify(e)):localStorage.removeItem(un)}catch{}}const Ba={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function Xa({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,h]=o.useState(Ha),p=o.useRef(null);o.useEffect(()=>{const k=w=>{w.key===_r&&h(w.newValue===null?!0:w.newValue==="true")};return window.addEventListener("storage",k),()=>window.removeEventListener("storage",k)},[]),o.useEffect(()=>{let k=!0;async function w(){p.current?.abort();const y=new AbortController;p.current=y;try{c(!0);const U=await fetch("/api/personas",{signal:y.signal});if(!U.ok){d(!1);return}const I=await U.json();if(!k)return;I.ok&&I.available?(s(I.personas),d(!0),i(Wa())):d(!1)}catch(U){if(U instanceof Error&&U.name==="AbortError"||!k)return;d(!1)}finally{k&&c(!1)}}return w(),()=>{k=!1,p.current?.abort()}},[]);const m=o.useCallback(k=>{i(k),Jn(k),t(`/persona ${k.id}`)},[t]),b=o.useCallback(()=>{i(null),Jn(null),t("/persona exit")},[t]);if(l||!u||!f)return null;const g=Object.entries(r);return g.length===0?null:n.jsxs(fn,{children:[n.jsxs(mn,{className:L("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(pn,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[a&&n.jsxs(n.Fragment,{children:[n.jsxs(tt,{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"})]}),g.map(([k,w])=>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:Ba[k]??k}),w.map(y=>n.jsxs(tt,{onClick:()=>m(y),className:"justify-between",children:[n.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-sm flex-shrink-0",children:y.emoji}),n.jsx("span",{className:"truncate",children:y.name})]}),n.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:y.description})]},y.id))]},k))]})]})}const Ya=[{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 Ga({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(we,{variant:"ghost",size:"sm",onClick:()=>s(!0),className:L("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:n.jsx(te,{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(te,{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(we,{variant:"ghost",size:"sm",onClick:()=>s(!1),className:"h-7 w-7 p-0",children:n.jsx(te,{icon:$t,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"}),Ya.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-700 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 qa=10*1024*1024,ct=1280,Va=.75,Ja=300*1024,Qa=["image/png","image/jpeg","image/gif","image/webp"],Pr=["pdf","txt","md","csv","json","xml","yaml","yml","log","py","js","ts","html","css"],Za=[".png",".jpg",".jpeg",".gif",".webp",...Pr.map(e=>`.${e}`)].join(",");function el(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function tl(e){if(!el())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>ct||c>ct)&&(l>c?(c=Math.round(c*ct/l),l=ct):(l=Math.round(l*ct/c),c=ct));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 h=Va,p=u.toDataURL(f,h);if(f==="image/jpeg"){const b=Ja*1.37;for(;p.length>b&&h>.3;)h-=.1,p=u.toDataURL(f,h)}const m=p.split(",")[1];if(!m){i(),r(new Error("Failed to encode image"));return}i(),t(m)}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 Kr(e){return Qa.includes(e.type)}function nl(e){const t=e.name.includes(".")?e.name.split(".").pop()?.toLowerCase():"";return!!(t&&Pr.includes(t))}async function rl(e){const t=crypto.randomUUID();if(!Kr(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>qa)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const r=await tl(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 sl({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:Za,multiple:!0,onChange:i,className:"hidden","aria-hidden":"true"}),n.jsx(we,{variant:"ghost",size:"icon-sm",onClick:a,disabled:t,className:r,"aria-label":"Attach file",type:"button",children:n.jsx(te,{icon:As,size:18,strokeWidth:1.8})})]})}function Qn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function ol(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function il({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:L("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," (",Qn(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:L("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(te,{icon:cr,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:[ol(e.file.name)," •"," ",Qn(e.file.size)]})]}),n.jsx(we,{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(te,{icon:$t,size:14})})]})}function al({attachments:e,onRemove:t,className:r}){return e.length===0?null:n.jsx("div",{className:L("flex flex-wrap gap-2 px-4",r),children:e.map(s=>n.jsx(il,{attachment:s,onRemove:t},s.id))})}const Zn=[{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 ll(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function cl(e,t){const r=ll(t),s=new RegExp(`(?:^|\\n\\n)📎 Uploaded file: ${r}\\n\\nPlease analyze this file\\.(?=\\n\\n|$)`);return e.replace(s,(a,i)=>i===0?"":`
18
+
19
+ `).trim()}function ul({onSubmit:e,isLoading:t,disabled:r,wrapperRef:s,inputRef:a}){const[i,l]=o.useState(""),[c,u]=o.useState(""),[d,f]=o.useState([]),[h,p]=o.useState(0),[m,b]=o.useState(!1),[g,k]=o.useState(!1),[w,y]=o.useState(!1),[U,I]=o.useState(0),[F,O]=o.useState(!1),[ee,_]=o.useState(null),P=o.useRef(null),Z=o.useRef([]),B=o.useRef(null),C=o.useRef(null),A=o.useRef(null),v=o.useRef(null),M=o.useMemo(()=>/^\/\S*$/.test(i)&&!m,[i,m]),j=o.useMemo(()=>M?i.slice(1).toLowerCase():"",[M,i]),z=o.useMemo(()=>M?j?Zn.filter(N=>N.command.slice(1).toLowerCase().startsWith(j)):Zn:[],[M,j]),G=o.useCallback(N=>{v.current=N,a&&(typeof a=="function"?a(N):a.current=N)},[a]),S=o.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{v.current?.focus()})},[]),D=o.useCallback(N=>{_(N)},[]),K=o.useCallback(()=>{l(""),f([]),p(0),b(!1),S()},[S]),X=o.useCallback(N=>{l(Y=>{const $=`📎 Uploaded file: ${N}
20
+
21
+ Please analyze this file.`;return Y.trim()?`${Y.trim()}
22
+
23
+ ${$}`:$})},[]),E=o.useCallback(async()=>{await fetch("/api/files/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:"/uploads"})})},[]),q=o.useCallback(async N=>{const Y=crypto.randomUUID();if(!nl(N))return{id:Y,file:N,preview:null,type:"file",base64:null,error:"Unsupported file type for upload."};try{await E();const $=new FormData;$.append("path","/uploads"),$.append("file",N);const me=await fetch("/api/files/upload",{method:"POST",body:$});if(!me.ok){const Ne=await me.text();throw new Error(Ne||"File upload failed")}const fe=(await me.json()).files?.[0]?.path;if(!fe)throw new Error("Upload succeeded but no path was returned");return X(fe),{id:Y,file:N,preview:null,type:"file",base64:null,uploadedPath:fe}}catch($){return{id:Y,file:N,preview:null,type:"file",base64:null,error:$ instanceof Error?$.message:"File upload failed"}}},[X,E]),H=o.useCallback(async N=>{if(N.length===0)return;const Y=await Promise.all(N.map($=>Kr($)?rl($):q($)));f($=>[...$,...Y]),S()},[S,q]),W=o.useCallback(N=>{let Y;f($=>{const me=$.find(se=>se.id===N);return me?.uploadedPath&&(Y=me.uploadedPath),$.filter(se=>se.id!==N)}),Y&&l($=>cl($,Y))},[]),J=o.useCallback(N=>{Array.from(N.dataTransfer.types).includes("Files")&&(N.preventDefault(),N.dataTransfer.dropEffect="copy",k(!0))},[]),re=o.useCallback(N=>{N.preventDefault();const Y=N.relatedTarget;Y&&N.currentTarget.contains(Y)||k(!1)},[]),ie=o.useCallback(async N=>{N.preventDefault(),k(!1);const Y=Array.from(N.dataTransfer.files);Y.length!==0&&await H(Y)},[H]),V=o.useCallback(N=>{l(N),p(0),b(!1),S()},[S]),ae=o.useCallback(N=>{l(N),p(0),b(!1)},[]),ne=o.useCallback(N=>{l(`${N.command} `),p(0),b(!1),S()},[S]),ce=o.useCallback(()=>{if(r)return;if(M&&z.length>0){const $=Math.min(h,z.length-1);ne(z[$]);return}const N=i.trim(),Y=d.filter($=>!$.error&&$.base64);N.length===0&&Y.length===0||(e(N,{reset:K,setValue:V,model:c||void 0,attachments:Y}),S())},[r,M,z,h,ne,i,d,e,K,V,c,S]),he=o.useCallback(N=>{e(N,{reset:K,setValue:V,model:c||void 0,attachments:[]}),S()},[S,e,K,V,c]),oe=o.useCallback(N=>{if(M){if(N.key==="Escape"){N.preventDefault(),b(!0),p(0);return}if(z.length!==0){if(N.key==="ArrowDown"){N.preventDefault(),p(Y=>(Y+1)%z.length);return}if(N.key==="ArrowUp"){N.preventDefault(),p(Y=>(Y-1+z.length)%z.length);return}if(N.key==="Tab"){N.preventDefault();const Y=Math.min(h,z.length-1);ne(z[Y])}}}},[M,z,h,ne]);o.useEffect(()=>()=>{C.current?.abort(),B.current&&clearInterval(B.current),P.current&&P.current.state!=="inactive"&&P.current.stop(),A.current&&A.current.abort()},[]);const de=o.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),T=o.useCallback(()=>{P.current&&P.current.state!=="inactive"&&P.current.stop(),A.current&&A.current.stop(),B.current&&(clearInterval(B.current),B.current=null),y(!1),I(0)},[]),pe=o.useCallback(async()=>{_(null);const N=de();if(N==="browser"){const Y=window.SpeechRecognition||window.webkitSpeechRecognition;if(!Y){D("Web Speech API is not supported in this browser.");return}const $=new Y;$.continuous=!0,$.interimResults=!1,$.lang=navigator.language||"en-US",A.current=$,y(!0),I(0),B.current=setInterval(()=>{I(se=>se>=119?(T(),0):se+1)},1e3);let me="";$.onresult=se=>{for(let fe=se.resultIndex;fe<se.results.length;fe++)se.results[fe].isFinal&&(me+=se.results[fe][0].transcript)},$.onend=()=>{y(!1),I(0),B.current&&clearInterval(B.current),me.trim()&&(_(null),l(se=>se+(se?" ":"")+me.trim()),S())},$.onerror=()=>{y(!1),I(0),B.current&&clearInterval(B.current),D("Speech recognition failed. Try the Browser provider again or switch providers in Settings.")},$.start();return}try{const Y=await navigator.mediaDevices.getUserMedia({audio:!0}),$=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",me=new MediaRecorder(Y,{mimeType:$});P.current=me,Z.current=[],me.ondataavailable=se=>{se.data.size>0&&Z.current.push(se.data)},me.onstop=async()=>{Y.getTracks().forEach(fe=>fe.stop());const se=new Blob(Z.current,{type:$});if(se.size!==0){O(!0);try{const fe=new FormData;fe.append("audio",se,`recording.${$==="audio/webm"?"webm":"mp4"}`),N!=="auto"&&fe.append("provider",N),C.current?.abort();const Ne=new AbortController;C.current=Ne;const Ae=await(await fetch("/api/stt",{method:"POST",body:fe,signal:Ne.signal})).json();Ae.ok&&Ae.text?(_(null),l(Ke=>Ke+(Ke?" ":"")+Ae.text),S()):Ae.ok||(console.warn("STT failed:",Ae.error),D(Ae.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(fe){if(fe instanceof Error&&fe.name==="AbortError")return;console.warn("STT request failed:",fe),D("Could not reach speech-to-text service.")}finally{O(!1)}}},y(!0),I(0),B.current=setInterval(()=>{I(se=>se>=119?(T(),0):se+1)},1e3),me.start()}catch(Y){const $=Y instanceof Error?Y.message:String(Y);if($.includes("NotAllowedError")||$.includes("Permission"))try{(await navigator.permissions.query({name:"microphone"})).state==="denied"?D("Microphone access is blocked. Please enable it in your browser/app settings."):D("Microphone permission was not granted. Please try again and allow access when prompted.")}catch{D("Could not access microphone. Please check your browser settings and allow microphone access for this site.")}else D("Could not access microphone: "+$)}},[de,T,S,D]),Ce=o.useCallback(()=>{w?T():pe()},[w,T,pe]),Ie=d.filter(N=>!N.error&&N.base64),$e=r||i.trim().length===0&&Ie.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:re,onDrop:ie,children:[g&&n.jsx("div",{className:"pointer-events-none absolute inset-2 z-20 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary-400 bg-primary-50/90 text-sm font-medium text-primary-700",children:"Drop files here"}),n.jsxs(za,{value:i,onValueChange:ae,onSubmit:ce,isLoading:t,disabled:r,children:[n.jsx(al,{attachments:d,onRemove:W}),ee&&n.jsx("div",{className:"mx-3 mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/40 dark:text-red-200",role:"alert","aria-live":"polite",children:ee}),M&&z.length>0&&n.jsx(Ka,{commands:z,selectedIndex:Math.min(h,z.length-1),onSelect:ne}),n.jsx($a,{placeholder:"Type a message…",inputRef:G,onKeyDown:oe}),n.jsxs(Fa,{className:"justify-between px-3",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(_a,{}),n.jsx(Xa,{onSelect:he}),n.jsx(Ga,{onCommandSelect:N=>ae(N+" ")})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(sl,{onFilesSelect:H,disabled:r}),n.jsx(Vn,{tooltip:w?"Stop recording":"Voice input",children:n.jsx(we,{onClick:Ce,disabled:r||F,size:"icon-sm",variant:w?"destructive":"ghost",className:`rounded-full ${w?"animate-pulse":""}`,"aria-label":w?"Stop recording":"Voice input",children:F?n.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):w?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(U/60),":",String(U%60).padStart(2,"0")]}),n.jsx(te,{icon:ar,size:14,strokeWidth:2})]}):n.jsx(te,{icon:Ms,size:18,strokeWidth:2})})}),n.jsx(Vn,{tooltip:"Send message",children:n.jsx(we,{onClick:ce,disabled:$e,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:n.jsx(te,{icon:Ds,size:18,strokeWidth:2})})})]})]})]})]})}const dl=o.memo(ul);function fl({title:e,description:t,detail:r,actionLabel:s,onAction:a,className:i}){return n.jsx("div",{className:L("w-full max-w-[var(--opencami-chat-width)]",i),children:n.jsx(Dr,{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(we,{size:"sm",variant:"outline",onClick:a,children:s})}):null]})})})}function ml({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(fl,{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 pl(){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,m=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,m)}px`),l(p),a(Math.max(0,b-p-m))};f();const h=new ResizeObserver(()=>f());return c&&h.observe(c),u&&h.observe(u),()=>h.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:r,pinGroupMinHeight:s,headerHeight:i}}function hl({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:r,isNewChat:s,isRedirecting:a,activeExists:i,sessionsReady:l,queryClient:c}){const u=r||t||e,d=ge.history(e,u),f=Lt({queryKey:d,queryFn:async function(){const y=c.getQueryData(d),U=Array.isArray(y?.messages)?y.messages.filter(_=>_.status==="sending"||_.__optimisticId?!0:!!_.clientId):[],I=Array.isArray(y?.messages)?y.messages:[],F=await jo({sessionKey:u,friendlyId:e}),O=yl(F.messages,I);if(!U.length)return{...F,messages:O};const ee=xl(O,U);return{...F,messages:ee}},enabled:!s&&!!e&&!a&&(!l||i),placeholderData:function(){return c.getQueryData(d)},gcTime:1e3*60*10}),h=o.useRef(""),p=o.useRef([]),m=o.useMemo(()=>{const w=Array.isArray(f.data?.messages)?f.data.messages:[],y=w[w.length-1],U=y&&typeof y.id=="string"?y.id:"",I=`${w.length}:${y?.role??""}:${U}:${ve(y??{content:[]}).slice(-32)}`;return I===h.current?p.current:(h.current=I,p.current=w,w)},[f.data?.messages]),b=f.error instanceof Error?f.error.message:null,g=o.useMemo(()=>{if(r)return r;const w=f.data?.sessionKey;return typeof w=="string"&&w.trim().length>0?w.trim():t},[t,r,f.data?.sessionKey]);return{historyQuery:f,historyMessages:m,displayMessages:m,historyError:b,resolvedSessionKey:g,activeCanonicalKey:s?"new":g||e,sessionKeyForHistory:u}}function gl(e,t){return e.findIndex(r=>{if(t.clientId&&r.clientId&&t.clientId===r.clientId||t.__optimisticId&&r.__optimisticId&&t.__optimisticId===r.__optimisticId)return!0;if(t.role&&r.role&&t.role!==r.role)return!1;const s=ve(t);if(!s||s!==ve(r))return!1;const a=jt(t),i=jt(r);return Math.abs(a-i)<=1e4})}function vt(e){return Array.isArray(e.content)?e.content.filter(t=>{if(typeof t!="object"||t===null)return!1;const r=t;if(r.type!=="image")return!1;const s=r.source;return typeof s?.data=="string"&&s.data.length>0}):[]}function yl(e,t){const r=t.filter(s=>vt(s).length>0);return r.length?e.map(s=>{if(vt(s).length>0)return s;const a=r.find(l=>{if(s.role!==l.role)return!1;if(s.id&&l.id&&s.id===l.id||s.clientId&&l.clientId&&s.clientId===l.clientId)return!0;const c=ve(s),u=ve(l);return!c||c!==u?!1:Math.abs(jt(s)-jt(l))<=3e4});if(!a)return s;const i=vt(a);return i.length?{...s,content:[...i,...Array.isArray(s.content)?s.content:[]]}:s}):e}function xl(e,t){if(!t.length)return e;const r=[...e];for(const s of t){const a=gl(r,s);if(a===-1){r.push(s);continue}const i=vt(s),l=r[a],c=vt(l),u=i.length>0&&c.length===0,d=!!(s.__optimisticId&&!l.__optimisticId),f=!!(s.clientId&&!l.clientId);!u&&!d&&!f||(r[a]={...l,...d?{__optimisticId:s.__optimisticId}:{},...f?{clientId:s.clientId}:{},...u?{content:[...i,...Array.isArray(l.content)?l.content:[]]}:{}})}return r}function wl(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&&Xe(e,function(a){return{...a,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function bl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}){const[s,a]=o.useState(()=>typeof document>"u"?!0:document.visibilityState==="visible");o.useEffect(()=>{if(typeof document>"u")return;const m=()=>{a(document.visibilityState==="visible")};return m(),document.addEventListener("visibilitychange",m),()=>{document.removeEventListener("visibilitychange",m)}},[]);const i=Lt({queryKey:ge.sessions,queryFn:vo,refetchInterval:s?3e4:!1}),l=o.useMemo(()=>{const m=i.data??[];return Ko(m)},[i.data]),c=o.useMemo(()=>l.find(m=>m.friendlyId===e),[l,e]),u=o.useMemo(()=>t||r||wr(e)?!0:l.some(m=>m.friendlyId===e),[e,r,t,l]),d=c?.key??"",f=o.useMemo(()=>c?c.label||c.title||c.derivedTitle||c.friendlyId:e,[e,c]),h=i.error instanceof Error?i.error.message:null,p=o.useMemo(()=>({totalTokens:c?.totalTokens,contextTokens:c?.contextTokens}),[c?.totalTokens,c?.contextTokens]);return{sessionsQuery:i,sessions:l,activeSession:c,activeExists:u,activeSessionKey:d,activeTitle:f,activeTokens:p,sessionsError:h}}const Sl={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:""}},Ot={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function Ur(e){return Sl[e]}function vl(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():Ur(e.llmProvider).baseUrl}function jl(e){return e.llmModel.trim()?e.llmModel.trim():Ur(e.llmProvider).model}function er(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||!!(e.llmBaseUrl.trim()&&e.llmModel.trim()):t||!!e.llmApiKey.trim()}function kl(e){if(!e||typeof e!="object")return{settings:Ot};const{settings:t}=e;if(!t)return{settings:Ot};const{openaiApiKey:r,...s}=t,a=s.llmApiKey??r??"";return{settings:{...Ot,...s,llmApiKey:a}}}const pt=yr()(gr(e=>({settings:{...Ot},updateSettings:t=>e(r=>({settings:{...r.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>kl(e)}));function oc(){const e=pt(l=>l.settings),t=pt(l=>l.updateSettings),r=pt(l=>l.clearApiKey),[s,a]=o.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasKilocodeKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:er(e,!1),isLoading:!0,error:null});o.useEffect(()=>{let l=!1;async function c(){try{const u=await fetch("/api/llm-features");if(!u.ok)throw new Error("Failed to check LLM status");const d=await u.json();if(l)return;const f=!!e.llmApiKey,h=e.llmProvider==="openrouter"?!!d.hasOpenRouterKey:e.llmProvider==="kilocode"?!!d.hasKilocodeKey:d.hasEnvKey;a({hasEnvKey:d.hasEnvKey,hasOpenRouterKey:!!d.hasOpenRouterKey,hasKilocodeKey:!!d.hasKilocodeKey,hasUserKey:f,isAvailable:er(e,h),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=zr({...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 zr(e){const t=e.llmApiKey,r=vl(e),s=jl(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 El(){const e=pt.getState().settings;return zr(e)}function Cl(){const e=pt(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 h={"Content-Type":"application/json",...El()},p=await fetch("/api/llm-features",{method:"POST",headers:h,body:JSON.stringify({action:"title",message:d}),signal:f.signal});if(!p.ok)throw new Error(`API error: ${p.status}`);const m=await p.json();if(f.signal.aborted)throw new Error("Aborted");const b=m.title||d.slice(0,50),g=b.length>64?b.slice(0,61)+"...":b,k=m.source||"heuristic";return a(g),l(k),{title:g,source:k,error:m.error}}catch(h){if(h instanceof Error&&h.name==="AbortError")throw h;const p=Nl(d);return a(p),l("heuristic"),{title:p,source:"heuristic",error:h instanceof Error?h.message:"Unknown error"}}finally{r(!1),c.current===f&&(c.current=null)}},[e.llmApiKey,e.llmBaseUrl,e.llmModel,e.llmProvider]),isGenerating:t,lastTitle:s,lastSource:i}}function Nl(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 Tl(){return pt(e=>e.settings.useLlmTitles)}function Rl(e,t,r){const s=dt(e),a=xe(s?.stream),i=xe(s?.runId),l=xe(s?.sessionKey)||t,c=dt(s?.data);if(i)if(r.anyRunSeen.current=!0,a==="lifecycle"){const m=xe(c?.phase);m==="end"||m==="error"||m==="abort"?r.activeRuns.delete(i):m&&r.activeRuns.add(i)}else r.activeRuns.add(i);if(a==="assistant"){const m=xe(c?.delta)||xe(c?.text);if(!m)return;r.setState(b=>{const g=[...b.contentBlocks],k=g[g.length-1];return k?.kind==="text"?g[g.length-1]={...k,text:k.text+m}:g.push({kind:"text",text:m}),{...b,sessionKey:l,text:b.text+m,contentBlocks:g}}),r.onAssistantDelta?.({text:m,sessionKey:l});return}if(!a.includes("tool"))return;const u=xe(c?.toolCallId)||xe(c?.id)||xe(c?.callId)||`${i||"tool"}:${xe(c?.toolName)||xe(c?.name)||"unknown"}`,d=xe(c?.toolName)||xe(c?.name)||"Tool",f=Il(a,c),h=dt(c?.arguments)||dt(c?.input)||dt(c?.params)||null,p=xe(c?.result)||xe(c?.output)||(a.includes("result")?xe(c?.text):"");r.setState(m=>{const b=[...m.tools],g=b.findIndex(F=>F.id===u),k={id:u,name:d,status:f};g>=0?b[g]=k:b.push(k);const w=[...m.contentBlocks],y=w.findIndex(F=>F.kind==="tool"&&F.id===u),U=y>=0?w[y]:null,I={kind:"tool",name:d,id:u,status:f,arguments:h??U?.arguments,output:p||U?.output||void 0};return y>=0?w[y]=I:w.push(I),{...m,sessionKey:l,tools:b,contentBlocks:w}})}function Il(e,t){const r=xe(t?.phase)||xe(t?.status)||xe(t?.state);return r||(e.includes("result")||e.includes("output")?"done":(e.includes("call"),"running"))}function dt(e){return e&&typeof e=="object"?e:null}function xe(e){return typeof e=="string"?e.trim():""}const tr={active:!1,text:"",tools:[],contentBlocks:[],sessionKey:null};function Al(e){const[t,r]=o.useState(tr),s=o.useRef(null),a=o.useRef(!1),i=o.useRef(!1),l=o.useRef(new Set),c=o.useRef(-1),u=o.useRef(""),d=o.useRef(!1),f=o.useRef(""),h=o.useRef(e.onDone),p=o.useRef(e.onError),m=o.useRef(e.onAssistantDelta);h.current=e.onDone,p.current=e.onError,m.current=e.onAssistantDelta;const b=o.useCallback(k=>{if(a.current=!0,i.current=!1,l.current.clear(),d.current=!1,c.current=-1,u.current="",s.current&&(s.current.close(),s.current=null),k?.preserveState){r(w=>({...w,active:!1}));return}r(tr)},[]),g=o.useCallback(function(w){if(f.current=w,s.current&&!a.current){r(U=>({...U,sessionKey:w,active:!0}));return}if(a.current=!1,i.current=!1,l.current.clear(),d.current=!1,c.current=-1,u.current="",r({active:!0,text:"",tools:[],contentBlocks:[],sessionKey:w}),s.current)return;const y=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(w)}`);s.current=y,y.addEventListener("message",U=>{try{const I=JSON.parse(U.data);if(typeof I.seq=="number"){if(I.seq<=c.current)return;c.current=I.seq}const F=f.current;if(I.event==="agent"){const O=JSON.stringify(I.payload);if(O===u.current)return;u.current=O,Rl(I.payload,F,{setState:r,onAssistantDelta:m.current,activeRuns:l.current,anyRunSeen:d});return}if(I.event==="chat"){const O=dt(I.payload),ee=xe(O?.sessionKey)||F,_=xe(O?.state);_==="final"&&(i.current=!0),!a.current&&i.current&&(_==="final"||d.current&&l.current.size===0)&&(a.current=!0,r(P=>({...P,active:!1})),h.current(ee));return}if(I.event==="error"){const O=typeof I.payload=="string"?I.payload:"Stream connection lost";p.current?.(O)}}catch{}}),y.onerror=()=>{a.current||y.readyState===EventSource.CLOSED&&(s.current=null,r(U=>({...U,active:!1})),p.current?.("Stream connection lost"))}},[]);return{streaming:t,startStream:g,stopStream:b}}function Ml(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 nr(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 m=p.touches[0];m&&(r!==void 0&&m.clientX>r||(u.current={startX:m.clientX,startY:m.clientY,tracking:!0,directionLocked:!1}))},[c,r]),f=o.useCallback(p=>{const m=u.current;if(!m.tracking)return;const b=p.touches[0];if(!b)return;const g=b.clientX-m.startX,k=b.clientY-m.startY,w=Math.abs(g),y=Math.abs(k);if(!m.directionLocked){if(w<5&&y<5)return;if(y>w){m.tracking=!1,i?.();return}m.directionLocked=!0}l==="left"&&g>0||l==="right"&&g<0||(p.preventDefault(),s?.(g))},[l,s,i]),h=o.useCallback(p=>{const m=u.current;if(!m.tracking)return;m.tracking=!1;const b=p.changedTouches[0];if(!b){i?.();return}const g=b.clientX-m.startX,k=Math.abs(g);if(!m.directionLocked||k<t){i?.();return}const w=g>0?"right":"left";if(l&&w!==l){i?.();return}a(w)},[l,i,a,t]);return{onTouchStart:d,onTouchMove:f,onTouchEnd:h}}const $r="opencami-browser-notifications-enabled",Dl=5e3;function Zt(){return typeof window<"u"&&"Notification"in window}function rr(){if(typeof window>"u")return!1;try{return localStorage.getItem($r)==="true"}catch{return!1}}function Ol(){const e=zt(),t=o.useRef(0),[r,s]=o.useState(()=>rr()),a=o.useCallback(async()=>{if(!Zt())return"denied";try{return await Notification.requestPermission()}catch{return"denied"}},[]),i=o.useCallback(async c=>{s(c);try{localStorage.setItem($r,String(c))}catch{}c&&Zt()&&Notification.permission==="default"&&await a()},[a]),l=o.useCallback(c=>{if(!r||!Zt()||document.hidden!==!0||Notification.permission!=="granted")return;const u=Date.now();if(u-t.current<Dl)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(()=>{const c=()=>s(rr());return window.addEventListener("storage",c),()=>window.removeEventListener("storage",c)},[]),{notificationsEnabled:r,setNotificationsEnabled:i,requestNotificationPermission:a,maybeNotifyAssistantMessage:l}}const Ll=o.lazy(()=>nt(()=>import("./keyboard-shortcuts-dialog-CK_XTzLr.js"),__vite__mapDeps([29,1,4,3,5,6,7,8,9,2])).then(e=>({default:e.KeyboardShortcutsDialog}))),_l=o.lazy(()=>nt(()=>import("./search-dialog-CB4KE8ec.js"),__vite__mapDeps([30,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}))),At="opencami-search-jump-target";function Pl(e){const t=Array.isArray(e.content)?e.content:[],r=[],s=[];for(const[a,i]of t.entries()){if(i.type!=="image"||!("source"in i)||typeof i.source?.data!="string"||i.source.data.length===0)continue;const l=typeof i.source?.media_type=="string"&&i.source.media_type.length>0?i.source.media_type:"image/jpeg",c=i.source.data;r.push({id:crypto.randomUUID(),file:new File([],`retry-attachment-${a+1}`,{type:l}),preview:null,type:"image",base64:c}),s.push({mimeType:l,content:c})}return{attachments:r,payload:s}}function Kl({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:r,forcedSessionKey:s}){const a=zt(),i=ht(),[l,c]=o.useState(!1),[u,d]=o.useState(!1),[f,h]=o.useState(null),[p,m]=o.useState(!1),{headerRef:b,composerRef:g,mainRef:k,pinGroupMinHeight:w,headerHeight:y}=pl(),[U,I]=o.useState(()=>Xt()||Yt()),[F,O]=o.useState(()=>Xt()||Yt()),[ee,_]=o.useState(!1),[P,Z]=o.useState(!1),[B,C]=o.useState("global"),[A,v]=o.useState(null),[M,j]=o.useState(!1),z=cn(x=>x.level),{maybeNotifyAssistantMessage:G}=Ol(),S=o.useRef(null),D=o.useRef(null),K=o.useRef(null),X=o.useRef(""),E=o.useRef(()=>{}),q=o.useRef(!1),H=o.useRef(""),{isMobile:W}=wl(i),{sessionsQuery:J,sessions:re,activeExists:ie,activeSessionKey:V,activeTitle:ae,activeTokens:ne,sessionsError:ce}=bl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:s}),{historyQuery:he,historyMessages:oe,displayMessages:de,historyError:T,resolvedSessionKey:pe,activeCanonicalKey:Ce,sessionKeyForHistory:Ie}=hl({activeFriendlyId:e,activeSessionKey:V,forcedSessionKey:s,isNewChat:t,isRedirecting:p,activeExists:ie,sessionsReady:J.isSuccess,queryClient:i}),$e=Lt({queryKey:ls,queryFn:function(){return Nn(i)},initialData:function(){return Nn(i)},staleTime:1/0}),N=Lt({queryKey:["gateway","status"],queryFn:ko,retry:2,retryDelay:x=>Math.min(2e3*2**x,8e3),refetchOnWindowFocus:!1,refetchOnReconnect:!0,refetchOnMount:"always"}),Y=o.useRef(Date.now()),$=N.error instanceof Error?N.error.message:N.data&&!N.data.ok?N.data.error||"Gateway unavailable":null,me=$??ce??T,se=o.useCallback(()=>{N.refetch()},[N]),fe=$e.data?.isSidebarCollapsed??!1;o.useEffect(()=>{J.isSuccess&&N.isError&&N.refetch()},[J.isSuccess,N.isError]);const Ne=nr({enabled:W&&fe,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{Xe(i,x=>({...x,isSidebarCollapsed:!1}))}}),rt=nr({enabled:W&&!fe,threshold:50,direction:"left",onSwipe:()=>{Xe(i,x=>({...x,isSidebarCollapsed:!0}))}}),Ae=o.useCallback(()=>{h(null),m(!0),a({to:"/new",replace:!0})},[a]),Ke=o.useCallback(()=>{D.current&&(window.clearInterval(D.current),D.current=null),K.current&&(window.clearTimeout(K.current),K.current=null)},[]),Je=o.useCallback(()=>{Ke(),bt(!1),I(!1),j(!1)},[Ke]),gt=Tl(),{generateTitle:yt}=Cl(),kt=o.useRef(new Set),Et=2e3,xt=2e3,wt=o.useCallback(()=>{!e||t||(D.current&&window.clearInterval(D.current),j(!0),D.current=window.setInterval(()=>{E.current()},Et))},[e,t]),Ct=o.useRef(()=>{}),Fe=o.useRef(()=>{}),{streaming:Q,startStream:je,stopStream:Qe}=Al({onDone:x=>Ct.current(x),onError:x=>Fe.current(x),onAssistantDelta:({text:x})=>{H.current+=x,G({text:H.current,sessionFriendlyId:e})}});Ct.current=o.useCallback(async x=>{await he.refetch(),Je(),i.invalidateQueries({queryKey:ge.sessions})},[he,i,Je]),Fe.current=o.useCallback(x=>{console.warn("[stream] SSE error, falling back to polling")},[]);const He=o.useMemo(()=>{if(Q.contentBlocks.length===0)return null;const x=[];for(const R of Q.contentBlocks)R.kind==="text"&&R.text?x.push({type:"text",text:R.text}):R.kind==="tool"&&x.push({type:"toolCall",name:R.name,id:R.id,arguments:R.arguments});return x.length===0?null:{role:"assistant",content:x,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[Q.contentBlocks]),Ht=o.useMemo(()=>{const x=[];for(const R of Q.contentBlocks)R.kind==="tool"&&R.status==="done"&&x.push({role:"toolResult",toolCallId:R.id,toolName:R.name,content:R.output?[{type:"text",text:R.output}]:[]});return x},[Q.contentBlocks]),Fr=o.useMemo(()=>{if(!He)return de;const x=[...de].map((le,Se)=>({message:le,index:Se})).filter(({message:le})=>le.role==="assistant").map(({index:le})=>le).pop(),R=[...de].map((le,Se)=>({message:le,index:Se})).filter(({message:le})=>le.role==="user").map(({index:le})=>le).pop(),ue=typeof x=="number"&&(typeof R!="number"||x>R);if(!Q.active&&ue)return de;let ye;if(ue&&typeof x=="number"){const le=de[x];if(ve(le).length>=Q.text.length&&Q.tools.length===0)return de;ye=[...de],ye[x]=He}else ye=[...de,He];return Ht.length>0&&(ye=[...ye,...Ht]),ye},[de,He,Ht,Q.active,Q.text,Q.tools]),Hr=o.useMemo(()=>({}),[]);E.current=function(){he.refetch()},o.useEffect(()=>{if(p){f&&h(null);return}if(st){f&&h(null);return}if(J.isSuccess&&!ie){f&&h(null);return}const x=ce??T??$;if(!x){f?.startsWith("Failed to load")&&h(null);return}Ln(x)&&a({to:"/connect",replace:!0});const R=ce?`Failed to load sessions. ${ce}`:T?`Failed to load history. ${T}`:$?`Gateway unavailable. ${$}`:null;R&&h(R)},[f,$,T,p,a,ce]);const st=!t&&!s&&!wr(e)&&J.isSuccess&&re.length>0&&!re.some(x=>x.friendlyId===e)&&!he.isFetching&&!he.isSuccess;o.useEffect(()=>{if(p){if(t){m(!1);return}!st&&J.isSuccess&&m(!1)}},[t,p,J.isSuccess,st]),o.useEffect(()=>{t||J.isSuccess&&re.length!==0&&st&&(Pt(),rn(i,e,Ie),a({to:"/new",replace:!0}))},[e,he.isFetching,he.isSuccess,t,a,i,Ie,re,J.isSuccess,st]);const xn=st||p,Nt=o.useRef("fast");o.useEffect(()=>{const x=[...oe].reverse().find(ue=>ue.role==="assistant");if(!x)return;const R=`${oe.length}:${ve(x).slice(-64)}`;R!==X.current&&(X.current=R,Nt.current!=="fast"&&D.current&&(window.clearInterval(D.current),D.current=window.setInterval(()=>{E.current()},Et),Nt.current="fast"),K.current&&window.clearTimeout(K.current),K.current=window.setTimeout(()=>{D.current&&(window.clearInterval(D.current),D.current=window.setInterval(()=>{E.current()},xt),Nt.current="slow"),K.current=window.setTimeout(()=>{Je(),Nt.current="fast"},3e3)},1500))},[oe,Je]),o.useEffect(()=>{if(!gt||t||p)return;const x=s||pe||V;if(!x||kt.current.has(x))return;const R=oe.filter(le=>le.role==="user"),ue=oe.filter(le=>le.role==="assistant");if(R.length===0||ue.length===0||R.length!==1)return;const ye=ve(R[0]);!ye||ye.length<5||(kt.current.add(x),(async()=>{try{const le=await yt(ye);le.title&&await Ro(i,x,e,le.title)}catch(le){console.error("[smart-title] Error generating title:",le)}})())},[gt,t,p,s,pe,V,e,oe,yt,i]),o.useEffect(()=>{if(t||e){if(Ke(),Qe(),X.current="",j(!1),q.current){q.current=!1;return}if(Xt()||Yt()){I(!0),O(!0);return}I(!1),O(!1)}},[e,t,Ke,Qe]),o.useEffect(()=>{if(!(typeof window>"u"))try{const x=sessionStorage.getItem(At);if(!x){v(null);return}const R=JSON.parse(x);if(typeof R.at=="number"&&Date.now()-R.at>300*1e3){sessionStorage.removeItem(At),v(null);return}if(R.friendlyId===e&&typeof R.messageId=="string"&&R.messageId.length>0){v(R.messageId),sessionStorage.removeItem(At);return}v(null)}catch{v(null)}},[e]),o.useLayoutEffect(()=>{if(t)return;const x=Oo(s||pe||V,e);if(!x)return;q.current=!0;const R=ge.history(x.friendlyId,x.sessionKey),ue=i.getQueryData(R);(Array.isArray(ue?.messages)?ue.messages:[]).some(Se=>!!(x.optimisticMessage.clientId&&(Se.clientId===x.optimisticMessage.clientId||Se.__optimisticId===x.optimisticMessage.clientId)||x.optimisticMessage.__optimisticId&&Se.__optimisticId===x.optimisticMessage.__optimisticId))||Wt(i,x.friendlyId,x.sessionKey,x.optimisticMessage),I(!0),O(!0),Tt(x.sessionKey,x.friendlyId,x.message,!0,x.attachments)},[e,V,s,t,i,pe]);function Tt(x,R,ue,ye=!1,le,Se,ot){let Ue="";if(!ye){const{clientId:ke,optimisticMessage:at}=_n(ue,le);Ue=ke,Wt(i,R,x,at),No(i,x,R,at)}bt(!0),c(!0),h(null),I(!0),O(!0);const it=ot??le?.flatMap(ke=>ke.base64?[{mimeType:ke.file.type,content:ke.base64}]:[]);H.current="",wt();const En=x||R;En&&je(En),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:x,friendlyId:R,message:ue,thinking:z,idempotencyKey:crypto.randomUUID(),attachments:it,model:Se||void 0})}).then(async ke=>{if(!ke.ok)throw new Error(await ze(ke));const Cn=(await ke.json()).sessionKey||x||R;je(Cn)}).catch(ke=>{const at=ke instanceof Error?ke.message:String(ke);if(Ln(at)){a({to:"/connect",replace:!0});return}Ue&&Eo(i,R,x,Ue,function(ss){return{...ss,status:"error"}}),h(`Failed to send message. ${at}`),bt(!1),I(!1),O(!1)}).finally(()=>{c(!1)})}const wn=o.useCallback(async()=>{d(!0);try{const x=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!x.ok)throw new Error(await ze(x));const R=await x.json(),ue=typeof R.sessionKey=="string"?R.sessionKey:"",ye=typeof R.friendlyId=="string"&&R.friendlyId.trim().length>0?R.friendlyId.trim():tn(ue);if(!ue||!ye)throw new Error("Invalid session response");return i.invalidateQueries({queryKey:ge.sessions}),{sessionKey:ue,friendlyId:ye}}finally{d(!1)}},[i]),Wr=o.useCallback((x,R)=>{const ue=R.attachments;if(x.length===0&&(!ue||ue.length===0))return;if(R.reset(),t){const{clientId:le,optimisticId:Se,optimisticMessage:ot}=_n(x,ue);Wt(i,"new","new",ot),bt(!0),c(!0),I(!0),O(!0),wn().then(({sessionKey:Ue,friendlyId:it})=>{if(Do(it),Ao({sessionKey:Ue,friendlyId:it,message:x,optimisticMessage:ot,attachments:ue}),r){r({sessionKey:Ue,friendlyId:it});return}a({to:"/chat/$sessionKey",params:{sessionKey:it},replace:!0})}).catch(Ue=>{Bt(i,"new","new",le,Se),R.setValue(x),h(`Failed to create session. ${Ue instanceof Error?Ue.message:String(Ue)}`),bt(!1),I(!1),O(!1),c(!1)});return}Tt(s||pe||V,e,x,!1,ue,R.model)},[e,V,wn,s,t,a,r,i,pe]),bn=o.useCallback(()=>{I(!1),O(!1),rn(i,"new","new"),a({to:"/new"}),W&&Xe(i,function(R){return{...R,isSidebarCollapsed:!0}})},[W,a,i]),Br=o.useCallback(()=>{Xe(i,function(R){return{...R,isSidebarCollapsed:!R.isSidebarCollapsed}})},[i]),Xr=o.useCallback(()=>{W&&Xe(i,function(R){return{...R,isSidebarCollapsed:!0}})},[W,i]),Yr=o.useCallback(()=>{Xe(i,function(R){return{...R,isSidebarCollapsed:!1}})},[i]),Gr=o.useCallback(x=>{const R=ve(x),{attachments:ue,payload:ye}=Pl(x);if(!R&&ue.length===0)return;const le=s||pe||V;if(!le)return;const Se=x.clientId,ot=x.__optimisticId;Se&&Bt(i,e,le,Se,ot),Tt(le,e,R,!1,ue,void 0,ye)},[e,V,s,i,pe]),qr=o.useCallback(x=>{const R=s||pe||V;if(!R)return;const ue=x.clientId,ye=x.__optimisticId;ue&&Bt(i,e,R,ue,ye),h(null)},[e,V,s,i,pe]),Vr=o.useCallback(x=>{if(t||!x.trim())return;const R=s||pe||V;R&&Tt(R,e,x.trim())},[e,V,s,t,pe]),Jr=o.useCallback(()=>{S.current?.focus()},[]),Qr=o.useCallback(()=>{if(ee){_(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[ee]),Zr=o.useCallback(()=>{const x=[...de].reverse().find(ue=>ue.role==="assistant");if(!x)return;const R=ve(x);R&&navigator.clipboard.writeText(R).catch(()=>{})},[de]),es=o.useCallback(()=>{_(!0)},[]),ts=o.useCallback(()=>{C(t?"global":"current"),Z(!0)},[t]),Sn=o.useCallback(()=>{C("global"),Z(!0)},[]);Ml({onNewChat:bn,onFocusInput:Jr,onEscape:Qr,onCopyLastResponse:Zr,onShowHelp:es,onSearch:ts,onSearchGlobal:Sn});const vn=he.isLoading&&!he.data||p,jn=!!$&&!J.isSuccess&&N.errorUpdatedAt>Y.current,ns=!vn&&de.length===0,rs=o.useMemo(()=>!jn||!me?null:n.jsx(ml,{state:"error",error:me,onRetry:se}),[me,se,jn]),kn=n.jsx(Vi,{sessions:re,activeFriendlyId:e,activeSessionKey:Ie,creatingSession:u,onCreateSession:bn,isCollapsed:W?!1:fe,onToggleCollapse:Br,onSelectSession:Xr,onActiveSessionDelete:Ae,onOpenSearch:Sn});return n.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[n.jsxs("div",{className:L("h-full overflow-hidden",W?"relative":"grid grid-cols-[auto_minmax(0,1fr)]"),children:[xn?null:W?n.jsxs(n.Fragment,{children:[!fe&&n.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>Xe(i,x=>({...x,isSidebarCollapsed:!0})),...rt}),n.jsx("div",{className:L("fixed inset-y-0 left-0 z-50 w-[var(--opencami-sidebar-width)] transition-transform duration-150 safe-area-top",fe?"-translate-x-full":"translate-x-0"),...rt,children:kn})]}):kn,n.jsxs("main",{className:"flex flex-col h-full min-h-0 min-w-0 overflow-x-hidden",ref:k,...Ne,children:[n.jsx(ea,{activeTitle:ae,wrapperRef:b,showSidebarButton:W,onOpenSidebar:Yr,totalTokens:ne.totalTokens,contextTokens:ne.contextTokens}),xn?null:n.jsxs(n.Fragment,{children:[n.jsx(Oa,{messages:Fr,loading:vn,empty:ns,notice:rs,noticePosition:"end",waitingForResponse:U,isStreaming:M,sessionKey:Ce,pinToTop:F,pinGroupMinHeight:w,headerHeight:y,contentStyle:Hr,onFollowUpClick:Vr,jumpToMessageId:A,onRetryMessage:Gr,onDismissMessage:qr}),n.jsx(dl,{onSubmit:Wr,isLoading:l,disabled:l,wrapperRef:g,inputRef:S})]})]})]}),ee&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Ll,{open:ee,onOpenChange:_})}),P&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(_l,{open:P,onOpenChange:Z,sessions:re,currentFriendlyId:e,currentSessionKey:V,mode:B,onJumpToMessage:x=>{if(Z(!1),!!x.friendlyId){if(x.messageId&&x.friendlyId===e){v(x.messageId);return}if(x.messageId&&typeof window<"u")try{sessionStorage.setItem(At,JSON.stringify({friendlyId:x.friendlyId,messageId:x.messageId,at:Date.now()}))}catch{}a({to:"/chat/$sessionKey",params:{sessionKey:x.friendlyId}})}}})})]})}function Ul(){const e=ht(),t=zt(),[r,s]=o.useState(null),a=as.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){Co(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(Kl,{activeFriendlyId:i,isNewChat:l,forcedSessionKey:c,onSessionResolved:l?u:void 0})}const ic=Object.freeze(Object.defineProperty({__proto__:null,component:Ul},Symbol.toStringTag,{value:"Module"}));export{ic as $,sn as C,on as a,an as b,ge as c,pt as d,El as e,Ur as g,oc as u};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/agents-screen--ZMzN5cB.js","assets/main-B2CrcRuC.js","assets/useQuery-D-sF8Tld.js","assets/button-BciDmec0.js","assets/switch-Bn5uei2k.js","assets/useControlled-CQHE0ITz.js","assets/useBaseUiId-DFpBD0sg.js","assets/visuallyHidden-COI6QeQH.js","assets/tooltip-DOKkNFvu.js","assets/useOnFirstRender-DlXHIIGk.js","assets/event-BCwqPPkP.js","assets/DirectionContext-CR5CCisG.js","assets/opencami-logo-SVuYD55V.js","assets/proxy-BijR8W1L.js"])))=>i.map(i=>d[i]);
2
+ import{j as e,r as t,_ as r}from"./main-B2CrcRuC.js";const n=t.lazy(()=>r(()=>import("./agents-screen--ZMzN5cB.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};
@@ -1 +1 @@
1
- import{u as L,r as t,j as e,L as M}from"./main-_1IghVZn.js";import{u as q}from"./useQuery-BdjM5kzn.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-BcUmP7JL.js";import{S as _}from"./switch-BwmDNR0d.js";import{s as X,T as Y,a as Z,b as $,c as ee,d as se,g as P}from"./tooltip-DexBPu8g.js";import{O as re,a as ae}from"./opencami-logo-BFo87CeM.js";import{m as S,A as W}from"./proxy-CJ6-TEKD.js";import"./useControlled-DeDLOsPR.js";import"./useBaseUiId-DN9cOflS.js";import"./visuallyHidden-COI6QeQH.js";import"./useOnFirstRender-S4-xcV93.js";import"./event-BxzjTPjG.js";import"./DirectionContext-FHFKdJq_.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};
1
+ import{u as L,r as t,j as e,L as M}from"./main-B2CrcRuC.js";import{u as q}from"./useQuery-D-sF8Tld.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-BciDmec0.js";import{S as _}from"./switch-Bn5uei2k.js";import{s as X,T as Y,a as Z,b as $,c as ee,d as se,g as P}from"./tooltip-DOKkNFvu.js";import{O as re,a as ae}from"./opencami-logo-SVuYD55V.js";import{m as S,A as W}from"./proxy-BijR8W1L.js";import"./useControlled-CQHE0ITz.js";import"./useBaseUiId-DFpBD0sg.js";import"./visuallyHidden-COI6QeQH.js";import"./useOnFirstRender-DlXHIIGk.js";import"./event-BCwqPPkP.js";import"./DirectionContext-CR5CCisG.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-C_uJBNwI.js","assets/main-B2CrcRuC.js","assets/button-BciDmec0.js","assets/switch-Bn5uei2k.js","assets/useControlled-CQHE0ITz.js","assets/useBaseUiId-DFpBD0sg.js","assets/visuallyHidden-COI6QeQH.js","assets/useQuery-D-sF8Tld.js","assets/useMutation-BFl-7GnD.js","assets/proxy-BijR8W1L.js"])))=>i.map(i=>d[i]);
2
+ import{j as e,r as t,_ as r}from"./main-B2CrcRuC.js";const n=t.lazy(()=>r(()=>import("./bots-screen-C_uJBNwI.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};