opencami 1.8.6 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/{CSPContext-6t3O1emU.js → CSPContext-KDlbpvjX.js} +1 -1
- package/dist/client/assets/{DirectionContext-C6goXEY_.js → DirectionContext-DZNUWW6F.js} +1 -1
- package/dist/client/assets/_sessionKey-CPRycepq.js +19 -0
- package/dist/client/assets/agents-Bp6Cn1BH.js +2 -0
- package/dist/client/assets/{agents-screen-pHUzJxX5.js → agents-screen-Du8b4SRW.js} +1 -1
- package/dist/client/assets/bots-Dl65yZDx.js +2 -0
- package/dist/client/assets/bots-screen-CvbAVMk0.js +1 -0
- package/dist/client/assets/{button-CK8tKQ-Z.js → button-BxDVif49.js} +1 -1
- package/dist/client/assets/{composite-feK0c-xF.js → composite-t7Eu0qB0.js} +1 -1
- package/dist/client/assets/{connect-02tmQV_v.js → connect-Btonx7l6.js} +1 -1
- package/dist/client/assets/{dashboard-DQ0zDQKd.js → dashboard-Dz6Uyyke.js} +1 -1
- package/dist/client/assets/{event-BsD1rqGT.js → event-DeooaZzN.js} +1 -1
- package/dist/client/assets/{file-explorer-screen-Ds7LeJTd.js → file-explorer-screen-BnOINWSL.js} +1 -1
- package/dist/client/assets/files-Cf87gXsq.js +2 -0
- package/dist/client/assets/follow-up-suggestions-DP_84nA2.js +5 -0
- package/dist/client/assets/index-nheqha2z.js +3 -0
- package/dist/client/assets/{index-lK3yGoTI.js → index-yPOt98v7.js} +1 -1
- package/dist/client/assets/{keyboard-shortcuts-dialog-Bb_GOr9L.js → keyboard-shortcuts-dialog-BzL7ZJUb.js} +1 -1
- package/dist/client/assets/{main-Dq6jpr6-.js → main-DJgQwVqD.js} +3 -3
- package/dist/client/assets/{markdown-C7_Aipwd.js → markdown-CFbW7h0Q.js} +14 -14
- package/dist/client/assets/memory-kYdhgbRR.js +2 -0
- package/dist/client/assets/{memory-screen-CUFBWsq5.js → memory-screen-BKYBnY-V.js} +1 -1
- package/dist/client/assets/{menu-n6L--M9R.js → menu-CnihCZ4y.js} +1 -1
- package/dist/client/assets/{opencami-logo-zuSBm5Br.js → opencami-logo-CoCA2JIf.js} +1 -1
- package/dist/client/assets/{proxy-BU8Bw1Vt.js → proxy-C2vtPufK.js} +1 -1
- package/dist/client/assets/{react-BLyCEWpN.js → react-DzPMbcP8.js} +1 -1
- package/dist/client/assets/{search-dialog-yB4w5ajo.js → search-dialog-CDAdFAQI.js} +1 -1
- package/dist/client/assets/search-sources-badge-DOd5AI-i.js +1 -0
- package/dist/client/assets/{session-export-dialog-qbZgd2Zo.js → session-export-dialog-Cf8eisLM.js} +1 -1
- package/dist/client/assets/{settings-dialog-CHJbvpgk.js → settings-dialog-CB1OiRWU.js} +1 -1
- package/dist/client/assets/skills-D6MaebJh.js +2 -0
- package/dist/client/assets/{skills-panel-BH27r3nC.js → skills-panel-_M5k5dty.js} +1 -1
- package/dist/client/assets/styles-BNkOWk4R.css +1 -0
- package/dist/client/assets/{switch-BD3a0LRm.js → switch-LzFh8co4.js} +1 -1
- package/dist/client/assets/{tabs-DI1e-kzz.js → tabs-D9o7Irvl.js} +1 -1
- package/dist/client/assets/thinking-BqZoM6BP.js +1 -0
- package/dist/client/assets/{tooltip-BbH3QWvK.js → tooltip-D64CzFXa.js} +1 -1
- package/dist/client/assets/{use-file-explorer-state-DBfLeAyz.js → use-file-explorer-state-Tzex8EEL.js} +2 -2
- package/dist/client/assets/{useBaseUiId-MgM4ouhx.js → useBaseUiId-CMJ8I9al.js} +1 -1
- package/dist/client/assets/useCompositeItem-CSriPK0T.js +1 -0
- package/dist/client/assets/{useControlled-BQxTgsOd.js → useControlled-KFa25CcD.js} +1 -1
- package/dist/client/assets/{useMutation-12DyB3Ox.js → useMutation-Bd89JWif.js} +1 -1
- package/dist/client/assets/{useOnFirstRender-7qoaK5sI.js → useOnFirstRender-DqnUCnnL.js} +1 -1
- package/dist/client/assets/{useQuery-Ctiljcrr.js → useQuery-DhR_UXNX.js} +1 -1
- package/dist/server/assets/{_sessionKey-DzsJfprr.js → _sessionKey-BzM-igv7.js} +405 -703
- package/dist/server/assets/{_tanstack-start-manifest_v-C5HBDfQB.js → _tanstack-start-manifest_v-Bfnqdswf.js} +1 -1
- package/dist/server/assets/{connect-CbgijWz4.js → connect-BNabuqpW.js} +1 -1
- package/dist/server/assets/follow-up-suggestions-DhBZIszK.js +336 -0
- package/dist/server/assets/{index-Dl2BOKP7.js → index-BEWnDAH6.js} +24 -5
- package/dist/server/assets/{index-BFHEmXpN.js → index-DCMpnyEo.js} +1 -1
- package/dist/server/assets/{markdown-BFE5y9YH.js → markdown-DoX5Q7qh.js} +50 -26
- package/dist/server/assets/{memory-BqZOoD7Q.js → memory-Cxu7i8ej.js} +1 -1
- package/dist/server/assets/{memory-screen-BK5phS8K.js → memory-screen-B5l1NZRY.js} +2 -2
- package/dist/server/assets/{router-BZPatFG9.js → router-BqPDQeCx.js} +5 -5
- package/dist/server/assets/{search-dialog-DQRkARXw.js → search-dialog-DtYc9e4N.js} +4 -4
- package/dist/server/assets/search-sources-badge-B0rAEDs_.js +106 -0
- package/dist/server/assets/{settings-dialog-Bc1ta26X.js → settings-dialog-BQzn6fyF.js} +4 -4
- package/dist/server/assets/thinking-D6q1tJkk.js +92 -0
- package/dist/server/server.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/_sessionKey-B5Viv43f.js +0 -23
- package/dist/client/assets/agents-BmE6QOwl.js +0 -2
- package/dist/client/assets/bots-BeOkwrXr.js +0 -2
- package/dist/client/assets/bots-screen-B79bAYvf.js +0 -1
- package/dist/client/assets/files-e40B1zFy.js +0 -2
- package/dist/client/assets/index-rljDU_1M.js +0 -3
- package/dist/client/assets/memory-C7UG-1le.js +0 -2
- package/dist/client/assets/skills-DoKPPhNY.js +0 -2
- package/dist/client/assets/styles-CXV5jZiD.css +0 -1
- package/dist/client/assets/useCompositeItem-OhltNFdZ.js +0 -1
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-dialog-CHJbvpgk.js","assets/main-Dq6jpr6-.js","assets/react-BLyCEWpN.js","assets/button-CK8tKQ-Z.js","assets/use-file-explorer-state-DBfLeAyz.js","assets/useOnFirstRender-7qoaK5sI.js","assets/useBaseUiId-MgM4ouhx.js","assets/event-BsD1rqGT.js","assets/visuallyHidden-COI6QeQH.js","assets/composite-feK0c-xF.js","assets/switch-BD3a0LRm.js","assets/useControlled-BQxTgsOd.js","assets/tabs-DI1e-kzz.js","assets/useCompositeItem-OhltNFdZ.js","assets/DirectionContext-C6goXEY_.js","assets/CSPContext-6t3O1emU.js","assets/index-rljDU_1M.js","assets/useQuery-Ctiljcrr.js","assets/tooltip-BbH3QWvK.js","assets/useMutation-12DyB3Ox.js","assets/menu-n6L--M9R.js","assets/opencami-logo-zuSBm5Br.js","assets/proxy-BU8Bw1Vt.js","assets/markdown-C7_Aipwd.js","assets/index-T4TOjvD0.js","assets/session-export-dialog-qbZgd2Zo.js","assets/keyboard-shortcuts-dialog-Bb_GOr9L.js","assets/search-dialog-yB4w5ajo.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as o,u as ct,j as n,L as He,_ as _t,d as Kt,w as rs,a as ss,z as os}from"./main-Dq6jpr6-.js";import{u as Rt}from"./useQuery-Ctiljcrr.js";import{T as Te,a as Re,b as Me,c as Ae,s as We,d as is,g as Cn}from"./tooltip-BbH3QWvK.js";import{u as as,c as I,B as ye,ac as dn,ag as Ge,t as ls,H as Y,J as nr,V as zt,aj as cs,ak as us,al as ds,a as rr,am as fs,C as ms,an as ps,M as fn,b as Je,I as hs,ao as gs,a3 as xs,s as nn,ap as ys,G as ws,aq as bs,e as sr,L as Ss,O as vs,X as mn,x as js,h as Ns,ar as or,as as ks,Y as pn,p as ir,n as ar,at as Xt,au as En,av as Cs,aw as Es,ax as Ts}from"./button-CK8tKQ-Z.js";import{u as lr}from"./useMutation-12DyB3Ox.js";import{j as Rs,k as Ms,l as As,m as Is,n as Ds,o as Os,p as Ls,q as Ps,r as _s,s as cr,D as Ks,a as zs,b as Us,c as $s,d as Fs,u as Hs}from"./use-file-explorer-state-DBfLeAyz.js";import{e as ur,a as Xe,g as dr,t as Ws,u as Ie,f as Xs,n as Ys}from"./useBaseUiId-MgM4ouhx.js";import{u as Bs}from"./useControlled-BQxTgsOd.js";import{a2 as Gs,a3 as qs,a4 as Tn,t as fr,u as Vs,J as ke,e as Js,a as Mt}from"./useOnFirstRender-7qoaK5sI.js";import{u as Qs,e as Zs,p as eo}from"./event-BsD1rqGT.js";import{u as to}from"./CSPContext-6t3O1emU.js";import{u as mr}from"./DirectionContext-C6goXEY_.js";import{M as Ut,a as $t,b as Ft,c as Ye}from"./menu-n6L--M9R.js";import{O as no,a as ro}from"./opencami-logo-zuSBm5Br.js";import{m as ve,A as Ee}from"./proxy-BU8Bw1Vt.js";import{M as so}from"./markdown-C7_Aipwd.js";import{u as oo,p as pr}from"./index-rljDU_1M.js";import{c as hr}from"./react-BLyCEWpN.js";function rn(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 Rn=/^Conversation info \(untrusted metadata\):\s*```(?:json)?\s*[\s\S]*?```\s*/,Mn=/^Conversation info \(untrusted metadata\):\s*\{[\s\S]*?\}\s*/,io=/^\[(?:[A-Za-z]{3}\s+)?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s+GMT[+-]?\d+\]\s*/;function gr(e){let t=e;const r=Rn.test(t),s=!r&&Mn.test(t);return r?t=t.replace(Rn,""):s&&(t=t.replace(Mn,"")),(r||s)&&(t=t.replace(io,"")),t.trim()}function De(e){const r=(Array.isArray(e.content)?e.content:[]).map(s=>s.type==="text"?String(s.text??""):"").join("").trim();return gr(r)}function Ze(e){return(Array.isArray(e.content)?e.content:[]).filter(r=>r.type==="toolCall")}function ao(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 sn(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=ao(r);if(s)return s}return Date.now()}const lo=["agent:main:main","main"];function on(e){return lo.includes(e)}const co=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function uo(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 co.test(t)?"webchat":"chat"}return"other"}function fo(e){return Array.isArray(e)?e.map(t=>{const r=typeof t.key=="string"&&t.key.trim().length>0?t.key.trim():rn(t.friendlyId??t.key),s=typeof t.friendlyId=="string"&&t.friendlyId.trim().length>0?t.friendlyId.trim():rn(r),a=uo(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 _e(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 mo="Missing gateway auth. Set CLAWDBOT_GATEWAY_TOKEN (recommended) or CLAWDBOT_GATEWAY_PASSWORD in the server environment.";function An(e){return e.includes(mo)}function In(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 de={sessions:["chat","sessions"],history:function(t,r){return["chat","history",t,r]}};async function po(){const e=await fetch("/api/sessions");if(!e.ok)throw new Error(await _e(e));const t=await e.json();return fo(t.sessions)}async function ho(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 _e(r));return await r.json()}async function go(){const e=new AbortController,t=window.setTimeout(()=>e.abort(),2500);try{const r=await fetch("/api/ping",{signal:e.signal});if(!r.ok)throw new Error(await _e(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=de.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 Yt(e,t,r,s){hn(e,t,r,function(i){return[...i,s]})}function xo(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 yo(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 an(e,t,r){const s=de.history(t,r);e.setQueryData(s,{sessionKey:r,messages:[]})}function wo(e,t,r,s,a){const i=de.history(t,r),l=de.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 bo(e,t,r,s){e.setQueryData(de.sessions,function(i){return Array.isArray(i)?i.map(l=>l.key!==t&&l.friendlyId!==r?l:{...l,lastMessage:s}):i})}function So(e,t,r){e.setQueryData(de.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 vo(e,t,r,s){e.setQueryData(de.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 _e(a);console.error("[updateSessionLabel] Failed to persist:",i)}}catch(a){console.error("[updateSessionLabel] Network error:",a)}}function jo(){const[e,t]=o.useState(!1),[r,s]=o.useState(!1),[a,i]=o.useState(null),[l,c]=o.useState(null),u=o.useCallback(async()=>{if(t(!0),i(null),!(r||l)){s(!0);try{const g=await fetch("/api/paths");if(!g.ok)throw new Error(await _e(g));const b=await g.json();c({agentId:String(b.agentId??"main"),stateDir:String(b.stateDir??""),sessionsDir:String(b.sessionsDir??""),storePath:String(b.storePath??"")})}catch(g){i(g instanceof Error?g.message:String(g))}finally{s(!1)}}},[l,r]),d=o.useCallback(()=>{u()},[u]),f=o.useCallback(()=>{t(!1)},[]),m=o.useCallback(()=>{if(l?.sessionsDir)try{navigator.clipboard.writeText(l.sessionsDir)}catch{}},[l]),p=o.useCallback(()=>{if(l?.storePath)try{navigator.clipboard.writeText(l.storePath)}catch{}},[l]);return{settingsOpen:e,setSettingsOpen:t,pathsLoading:r,pathsError:a,paths:l,handleOpenSettings:d,closeSettings:f,copySessionsDir:m,copyStorePath:p}}let je=null,gn=!1,Ct=null;function No(e){je=e}function Bt(){return je!==null}function ht(e){gn=e}function Gt(){return gn}function At(){je=null,gn=!1}function ko(e,t){if(je){if(e&&je.sessionKey===e){At();return}t&&je.friendlyId===t&&At()}}function Co(e){Ct={friendlyId:e,at:Date.now()}}function xr(e,t=15e3){return!(!Ct||Ct.friendlyId!==e||Date.now()-Ct.at>t)}function Eo(e,t){if(!je)return null;if(e&&je.sessionKey===e){const r=je;return je=null,r}if(t&&je.friendlyId===t){const r=je;return je=null,r}return null}const To=8e3,Qe=new Map;function Ro(e){e&&Qe.set(e,{id:e,expiresAt:Date.now()+To})}function Mo(e){e&&Qe.delete(e)}function Ao(e){if(Qe.size===0)return e;const t=Date.now();let r=!1;const s=e.filter(a=>{const i=Qe.get(a.key),l=Qe.get(a.friendlyId);return i&&i.expiresAt<=t||l&&l.expiresAt<=t?(i&&i.expiresAt<=t&&Qe.delete(a.key),l&&l.expiresAt<=t&&Qe.delete(a.friendlyId),!0):i||l?(r=!0,!1):!0});return r?s:e}function Io(){const e=ct(),[t,r]=o.useState(!1),[s,a]=o.useState(null),i=lr({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 _e(f));return u},onMutate:async function(u){a(null),Ro(u.sessionKey||u.friendlyId),ko(u.sessionKey,u.friendlyId),await e.cancelQueries({queryKey:de.sessions});const d=e.getQueryData(de.sessions);return So(e,u.sessionKey,u.friendlyId),u.isActive&&(u.sessionKey||u.friendlyId)&&an(e,u.friendlyId||u.sessionKey,u.sessionKey||u.friendlyId),{previousSessions:d,isActive:u.isActive}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(de.sessions,f.previousSessions),Mo(d.sessionKey||d.friendlyId),a(u instanceof Error?u.message:String(u))},onSuccess:function(u){u.isActive&&At(),e.invalidateQueries({queryKey:de.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 Do(){const e=ct(),[t,r]=o.useState(!1),[s,a]=o.useState(null),i=lr({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 _e(d));return u},onMutate:async function(u){a(null),await e.cancelQueries({queryKey:de.sessions});const d=e.getQueryData(de.sessions);return e.setQueryData(de.sessions,function(m){return Array.isArray(m)?m.map(p=>p.key!==u.sessionKey?p:{...p,label:u.newTitle,title:u.newTitle}):m}),{previousSessions:d}},onError:function(u,d,f){f?.previousSessions&&e.setQueryData(de.sessions,f.previousSessions),a(u instanceof Error?u.message:String(u))},onSuccess:function(){e.invalidateQueries({queryKey:de.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 yr(e){return!e.content||!Array.isArray(e.content)?"":e.content.filter(t=>t.type==="text").map(t=>t.text||"").join(`
|
|
3
|
-
`)}function Oo(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=yr(a);if(l){const c=i==="user"?"User":"Assistant";s.push(`## ${c}`),s.push(""),s.push(l),s.push("")}}return s.join(`
|
|
4
|
-
`)}function Lo(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 Po(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=yr(a);if(l){const c=i==="user"?"User":"Assistant";s.push(`${c}:`),s.push(l),s.push("")}}return s.join(`
|
|
5
|
-
`)}function _o(e,t,r){const s=new Date;let a,i,l;switch(r){case"markdown":a=Oo(e,t,s),i=`${qt(e)}.md`,l="text/markdown";break;case"json":a=Lo(e,t,s),i=`${qt(e)}.json`,l="application/json";break;case"txt":a=Po(e,t,s),i=`${qt(e)}.txt`,l="text/plain";break;default:throw new Error(`Unsupported format: ${r}`)}Ko(a,i,l)}function qt(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function Ko(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 zo(e){const{children:t,open:r,defaultOpen:s=!1,onOpenChange:a,onOpenChangeComplete:i,actionsRef:l,handle:c,triggerId:u,defaultTriggerId:d=null}=e,f=Rs(),m=!!f,p=as(()=>c?.store??new Ms({open:s,openProp:r,activeTriggerId:d,triggerIdProp:u,modal:!0,disablePointerDismissal:!0,nested:m,role:"alertdialog"})).current;p.useControlledProp("openProp",r),p.useControlledProp("triggerIdProp",u),p.useSyncedValue("nested",m),p.useContextCallback("onOpenChange",a),p.useContextCallback("onOpenChangeComplete",i);const g=p.useState("payload");As({store:p,actionsRef:l,parentContext:f?.store.context});const b=o.useMemo(()=>({store:p}),[p]);return n.jsx(Is.Provider,{value:b,children:typeof t=="function"?t({payload:g}):t})}function Uo({children:e,...t}){return n.jsx(zo,{...t,children:e})}function $o({className:e,children:t}){return n.jsxs(Ds,{children:[n.jsx(Os,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),n.jsx(Ls,{className:I("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 Fo({className:e,...t}){return n.jsx(Ps,{className:I("text-lg font-medium text-primary-900",e),...t})}function Ho({className:e,...t}){return n.jsx(_s,{className:I("text-sm text-primary-600",e),...t})}function Wo({className:e,...t}){return n.jsx(cr,{render:n.jsx(ye,{variant:"outline",className:I(e)}),...t})}function Xo({className:e,...t}){return n.jsx(cr,{render:n.jsx(ye,{variant:"destructive",className:I(e)}),...t})}function Yo({open:e,onOpenChange:t,sessionTitle:r,onConfirm:s,onCancel:a}){return n.jsx(Uo,{open:e,onOpenChange:t,children:n.jsx($o,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(Fo,{className:"mb-1",children:"Delete Session"}),n.jsxs(Ho,{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(Wo,{onClick:a,children:"Cancel"}),n.jsx(Xo,{onClick:s,children:"Delete"})]})]})})})}function Bo({open:e,onOpenChange:t,sessionTitle:r,onSave:s,onCancel:a}){return n.jsx(Ks,{open:e,onOpenChange:t,children:n.jsx(zs,{children:n.jsxs("div",{className:"p-4",children:[n.jsx(Us,{className:"mb-1",children:"Rename"}),n.jsx($s,{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(Fs,{onClick:a,children:"Cancel"}),n.jsx(ye,{onClick:i=>{const l=i.currentTarget.parentElement?.previousElementSibling;s(l.value)},children:"Save"})]})]})})})}function Go(e){const{open:t,defaultOpen:r,onOpenChange:s,disabled:a}=e,i=t!==void 0,[l,c]=Bs({controlled:t,default:r,name:"Collapsible",state:"open"}),{mounted:u,setMounted:d,transitionStatus:f}=Gs(l,!0,!0),[m,p]=o.useState(l),[{height:g,width:b},h]=o.useState({height:void 0,width:void 0}),w=ur(),[y,x]=o.useState(),A=y??w,[k,_]=o.useState(!1),[R,F]=o.useState(!1),G=o.useRef(null),D=o.useRef(null),q=o.useRef(null),H=o.useRef(null),j=qs(H,!1),E=Xe(T=>{const M=!l,K=dr(Ws,T.nativeEvent);if(s(M,K),K.isCanceled)return;const $=H.current;D.current==="css-animation"&&$!=null&&$.style.removeProperty("animation-name"),!k&&!R&&(D.current!=null&&D.current!=="css-animation"&&!u&&M&&d(!0),D.current==="css-animation"&&(!m&&M&&p(!0),!u&&M&&d(!0))),c(M),D.current==="none"&&u&&!M&&d(!1)});return Ie(()=>{i&&D.current==="none"&&!R&&!l&&d(!1)},[i,R,l,t,d]),o.useMemo(()=>({abortControllerRef:G,animationTypeRef:D,disabled:a,handleTrigger:E,height:g,mounted:u,open:l,panelId:A,panelRef:H,runOnceAnimationsFinish:j,setDimensions:h,setHiddenUntilFound:_,setKeepMounted:F,setMounted:d,setOpen:c,setPanelIdState:x,setVisible:p,transitionDimensionRef:q,transitionStatus:f,visible:m,width:b}),[G,D,a,E,g,u,l,A,H,j,h,_,F,d,c,p,q,f,m,b])}const wr=o.createContext(void 0);function br(){const e=o.useContext(wr);if(e===void 0)throw new Error(dn(15));return e}let gt=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Tn.startingStyle]="startingStyle",e[e.endingStyle=Tn.endingStyle]="endingStyle",e})({}),qo=(function(e){return e.panelOpen="data-panel-open",e})({});const Vo={[gt.open]:""},Jo={[gt.closed]:""},Qo={open(e){return e?{[qo.panelOpen]:""}:null}},Zo={open(e){return e?Vo:Jo}},Sr={...Zo,...fr},ei=o.forwardRef(function(t,r){const{render:s,className:a,defaultOpen:i=!1,disabled:l=!1,onOpenChange:c,open:u,...d}=t,f=Xe(c),m=Go({open:u,defaultOpen:i,onOpenChange:f,disabled:l}),p=o.useMemo(()=>({open:m.open,disabled:m.disabled,transitionStatus:m.transitionStatus}),[m.open,m.disabled,m.transitionStatus]),g=o.useMemo(()=>({...m,onOpenChange:f,state:p}),[m,f,p]),b=Ge("div",t,{state:p,ref:r,props:d,stateAttributesMapping:Sr});return n.jsx(wr.Provider,{value:g,children:b})}),ti={...Qo,...fr},ni=o.forwardRef(function(t,r){const{panelId:s,open:a,handleTrigger:i,state:l,disabled:c}=br(),{className:u,disabled:d=c,id:f,render:m,nativeButton:p=!0,...g}=t,{getButtonProps:b,buttonRef:h}=Xs({disabled:d,focusableWhenDisabled:!0,native:p}),w=o.useMemo(()=>({"aria-controls":a?s:void 0,"aria-expanded":a,onClick:i}),[s,a,i]);return Ge("button",t,{state:l,ref:[r,h],props:[w,g,b],stateAttributesMapping:ti})});let ri=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function si(e){const{abortControllerRef:t,animationTypeRef:r,externalRef:s,height:a,hiddenUntilFound:i,keepMounted:l,id:c,mounted:u,onOpenChange:d,open:f,panelRef:m,runOnceAnimationsFinish:p,setDimensions:g,setMounted:b,setOpen:h,setVisible:w,transitionDimensionRef:y,visible:x,width:A}=e,k=o.useRef(!1),_=o.useRef(null),R=o.useRef(f),F=o.useRef(f),G=Vs(),D=o.useMemo(()=>r.current==="css-animation"?!x:!f&&!u,[f,u,x,r]),q=Xe(j=>{if(!j)return;if(r.current==null||y.current==null){const M=getComputedStyle(j),K=M.animationName!=="none"&&M.animationName!=="",$=M.transitionDuration!=="0s"&&M.transitionDuration!=="";K&&$||(M.animationName==="none"&&M.transitionDuration!=="0s"?r.current="css-transition":M.animationName!=="none"&&M.transitionDuration==="0s"?r.current="css-animation":r.current="none"),j.getAttribute(ri.orientation)==="horizontal"||M.transitionProperty.indexOf("width")>-1?y.current="width":y.current="height"}if(r.current!=="css-transition")return;(a===void 0||A===void 0)&&(g({height:j.scrollHeight,width:j.scrollWidth}),F.current&&j.style.setProperty("transition-duration","0s"));let E=-1,T=-1;return E=ke.request(()=>{F.current=!1,T=ke.request(()=>{setTimeout(()=>{j.style.removeProperty("transition-duration")})})}),()=>{ke.cancel(E),ke.cancel(T)}}),H=ls(s,m,q);return Ie(()=>{if(r.current!=="css-transition")return;const j=m.current;if(!j)return;let E=-1;if(t.current!=null&&(t.current.abort(),t.current=null),f){const T={"justify-content":j.style.justifyContent,"align-items":j.style.alignItems,"align-content":j.style.alignContent,"justify-items":j.style.justifyItems};Object.keys(T).forEach(M=>{j.style.setProperty(M,"initial","important")}),!F.current&&!l&&j.setAttribute(gt.startingStyle,""),g({height:j.scrollHeight,width:j.scrollWidth}),E=ke.request(()=>{Object.entries(T).forEach(([M,K])=>{K===""?j.style.removeProperty(M):j.style.setProperty(M,K)})})}else{if(j.scrollHeight===0&&j.scrollWidth===0)return;g({height:j.scrollHeight,width:j.scrollWidth});const T=new AbortController;t.current=T;const M=T.signal;let K=null;const $=gt.endingStyle;return K=new MutationObserver(C=>{C.some(N=>N.type==="attributes"&&N.attributeName===$)&&(K?.disconnect(),K=null,p(()=>{g({height:0,width:0}),j.style.removeProperty("content-visibility"),b(!1),t.current===T&&(t.current=null)},M))}),K.observe(j,{attributes:!0,attributeFilter:[$]}),()=>{K?.disconnect(),G.cancel(),t.current===T&&(T.abort(),t.current=null)}}return()=>{ke.cancel(E)}},[t,r,G,i,l,u,f,m,p,g,b]),Ie(()=>{if(r.current!=="css-animation")return;const j=m.current;j&&(_.current=j.style.animationName||_.current,j.style.setProperty("animation-name","none"),g({height:j.scrollHeight,width:j.scrollWidth}),!R.current&&!k.current&&j.style.removeProperty("animation-name"),f?(t.current!=null&&(t.current.abort(),t.current=null),b(!0),w(!0)):(t.current=new AbortController,p(()=>{b(!1),w(!1),t.current=null},t.current.signal)))},[t,r,f,m,p,g,b,w,x]),Qs(()=>{const j=ke.request(()=>{R.current=!1});return()=>ke.cancel(j)}),Ie(()=>{if(!i)return;const j=m.current;if(!j)return;let E=-1,T=-1;return f&&k.current&&(j.style.transitionDuration="0s",g({height:j.scrollHeight,width:j.scrollWidth}),E=ke.request(()=>{k.current=!1,T=ke.request(()=>{setTimeout(()=>{j.style.removeProperty("transition-duration")})})})),()=>{ke.cancel(E),ke.cancel(T)}},[i,f,m,g]),Ie(()=>{const j=m.current;j&&i&&D&&(j.setAttribute("hidden","until-found"),r.current==="css-transition"&&j.setAttribute(gt.startingStyle,""))},[i,D,r,m]),o.useEffect(function(){const E=m.current;if(!E)return;function T(M){k.current=!0,h(!0),d(!0,dr(Ys,M))}return E.addEventListener("beforematch",T),()=>{E.removeEventListener("beforematch",T)}},[d,m,h]),o.useMemo(()=>({props:{hidden:D,id:c,ref:H}}),[D,c,H])}let Dn=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const oi=o.forwardRef(function(t,r){const{className:s,hiddenUntilFound:a,keepMounted:i,render:l,id:c,...u}=t,{abortControllerRef:d,animationTypeRef:f,height:m,mounted:p,onOpenChange:g,open:b,panelId:h,panelRef:w,runOnceAnimationsFinish:y,setDimensions:x,setHiddenUntilFound:A,setKeepMounted:k,setMounted:_,setPanelIdState:R,setOpen:F,setVisible:G,state:D,transitionDimensionRef:q,visible:H,width:j,transitionStatus:E}=br(),T=a??!1,M=i??!1;Ie(()=>{if(c)return R(c),()=>{R(void 0)}},[c,R]),Ie(()=>{A(T)},[A,T]),Ie(()=>{k(M)},[k,M]);const{props:K}=si({abortControllerRef:d,animationTypeRef:f,externalRef:r,height:m,hiddenUntilFound:T,id:h,keepMounted:M,mounted:p,onOpenChange:g,open:b,panelRef:w,runOnceAnimationsFinish:y,setDimensions:x,setMounted:_,setOpen:F,setVisible:G,transitionDimensionRef:q,visible:H,width:j});Js({open:b&&E==="idle",ref:w,onComplete(){b&&x({height:void 0,width:void 0})}});const $=o.useMemo(()=>({...D,transitionStatus:E}),[D,E]),C=Ge("div",t,{state:$,ref:[r,w],props:[K,{style:{[Dn.collapsiblePanelHeight]:m===void 0?"auto":`${m}px`,[Dn.collapsiblePanelWidth]:j===void 0?"auto":`${j}px`}},u],stateAttributesMapping:Sr});return M||T||!M&&p?C:null});function It(e){return n.jsx(ei,{...e})}function Dt({className:e,...t}){return n.jsx(ni,{className:I("group inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-left text-xs font-medium text-primary-500 transition-colors hover:bg-primary-100 hover:text-primary-700 data-panel-open:text-primary-700",e),...t})}function Ot({className:e,contentClassName:t,children:r,...s}){return n.jsx(oi,{className:I('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:I("pt-1",t),children:r})})}const vr=o.createContext(void 0);function Ht(){const e=o.useContext(vr);if(e===void 0)throw new Error(dn(53));return e}let Lt=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const vt=500,On=16;function Ce(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 ii=(function(e){return e.orientation="data-orientation",e.hovering="data-hovering",e.scrolling="data-scrolling",e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const jt="base-ui-disable-scrollbar",jr={className:jt,getElement(e){return n.jsx("style",{nonce:e,href:jt,precedence:"base-ui:low",children:`.${jt}{scrollbar-width:none}.${jt}::-webkit-scrollbar{display:none}`})}};let st=(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 xn={hasOverflowX:e=>e?{[st.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[st.hasOverflowY]:""}:null,overflowXStart:e=>e?{[st.overflowXStart]:""}:null,overflowXEnd:e=>e?{[st.overflowXEnd]:""}:null,overflowYStart:e=>e?{[st.overflowYStart]:""}:null,overflowYEnd:e=>e?{[st.overflowYEnd]:""}:null,cornerHidden:()=>null},ai={x:0,y:0},Ln={width:0,height:0},li={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},ci={x:!1,y:!1,corner:!1},ui=o.forwardRef(function(t,r){const{render:s,className:a,overflowEdgeThreshold:i,...l}=t,c=di(i),u=ur(),d=Mt(),f=Mt(),{nonce:m,disableStyleElements:p}=to(),[g,b]=o.useState(!1),[h,w]=o.useState(!1),[y,x]=o.useState(!1),[A,k]=o.useState(!1),[_,R]=o.useState(Ln),[F,G]=o.useState(Ln),[D,q]=o.useState(li),[H,j]=o.useState(ci),E=o.useRef(null),T=o.useRef(null),M=o.useRef(null),K=o.useRef(null),$=o.useRef(null),C=o.useRef(null),S=o.useRef(null),N=o.useRef(!1),P=o.useRef(0),z=o.useRef(0),B=o.useRef(0),re=o.useRef(0),ne=o.useRef("vertical"),Z=o.useRef(ai),ee=Xe(O=>{const fe=O.x-Z.current.x,L=O.y-Z.current.y;Z.current=O,L!==0&&(x(!0),d.start(vt,()=>{x(!1)})),fe!==0&&(w(!0),f.start(vt,()=>{w(!1)}))}),Q=Xe(O=>{O.button===0&&(N.current=!0,P.current=O.clientY,z.current=O.clientX,ne.current=O.currentTarget.getAttribute(ii.orientation),T.current&&(B.current=T.current.scrollTop,re.current=T.current.scrollLeft),$.current&&ne.current==="vertical"&&$.current.setPointerCapture(O.pointerId),C.current&&ne.current==="horizontal"&&C.current.setPointerCapture(O.pointerId))}),le=Xe(O=>{if(!N.current)return;const fe=O.clientY-P.current,L=O.clientX-z.current;if(T.current){const W=T.current.scrollHeight,X=T.current.clientHeight,oe=T.current.scrollWidth,ie=T.current.clientWidth;if($.current&&M.current&&ne.current==="vertical"){const te=Ce(M.current,"padding","y"),Se=Ce($.current,"margin","y"),Oe=$.current.offsetHeight,xe=M.current.offsetHeight-Oe-te-Se,Le=fe/xe;T.current.scrollTop=B.current+Le*(W-X),O.preventDefault(),x(!0),d.start(vt,()=>{x(!1)})}if(C.current&&K.current&&ne.current==="horizontal"){const te=Ce(K.current,"padding","x"),Se=Ce(C.current,"margin","x"),Oe=C.current.offsetWidth,xe=K.current.offsetWidth-Oe-te-Se,Le=L/xe;T.current.scrollLeft=re.current+Le*(oe-ie),O.preventDefault(),w(!0),f.start(vt,()=>{w(!1)})}}}),V=Xe(O=>{N.current=!1,$.current&&ne.current==="vertical"&&$.current.releasePointerCapture(O.pointerId),C.current&&ne.current==="horizontal"&&C.current.releasePointerCapture(O.pointerId)});function se(O){k(O.pointerType==="touch")}function ce(O){if(se(O),O.pointerType!=="touch"){const fe=Zs(E.current,O.target);b(fe)}}const be=o.useMemo(()=>({scrolling:h||y,hasOverflowX:!H.x,hasOverflowY:!H.y,overflowXStart:D.xStart,overflowXEnd:D.xEnd,overflowYStart:D.yStart,overflowYEnd:D.yEnd,cornerHidden:H.corner}),[h,y,H.x,H.y,H.corner,D]),me={role:"presentation",onPointerEnter:ce,onPointerMove:ce,onPointerDown:se,onPointerLeave(){b(!1)},style:{position:"relative",[Lt.scrollAreaCornerHeight]:`${_.height}px`,[Lt.scrollAreaCornerWidth]:`${_.width}px`}},ge=Ge("div",t,{state:be,ref:[r,E],props:[me,l],stateAttributesMapping:xn}),pe=o.useMemo(()=>({handlePointerDown:Q,handlePointerMove:le,handlePointerUp:V,handleScroll:ee,cornerSize:_,setCornerSize:R,thumbSize:F,setThumbSize:G,touchModality:A,cornerRef:S,scrollingX:h,setScrollingX:w,scrollingY:y,setScrollingY:x,hovering:g,setHovering:b,viewportRef:T,rootRef:E,scrollbarYRef:M,scrollbarXRef:K,thumbYRef:$,thumbXRef:C,rootId:u,hiddenState:H,setHiddenState:j,overflowEdges:D,setOverflowEdges:q,viewportState:be,overflowEdgeThreshold:c}),[Q,le,V,ee,_,F,A,h,w,y,x,g,b,u,H,D,be,c]);return n.jsxs(vr.Provider,{value:pe,children:[!p&&jr.getElement(m),ge]})});function di(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 fi=o.createContext(void 0);function it(e,t=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,r))}function mi(e,t){if(typeof IntersectionObserver>"u")return()=>{};const r=new IntersectionObserver(s=>{s.forEach(a=>{a.intersectionRatio>0&&(t(),r.disconnect())})});return r.observe(e),()=>{r.disconnect()}}let Be=(function(e){return e.scrollAreaOverflowXStart="--scroll-area-overflow-x-start",e.scrollAreaOverflowXEnd="--scroll-area-overflow-x-end",e.scrollAreaOverflowYStart="--scroll-area-overflow-y-start",e.scrollAreaOverflowYEnd="--scroll-area-overflow-y-end",e})({});const Pn=1;function _n(e,t){if(t<=0)return 0;const r=it(e,0,t),s=r,a=t-r,i=s<=Pn,l=a<=Pn;return i&&l?s<=a?0:t:i?0:l?t:r}let Kn=!1;function pi(){Kn||eo||(typeof CSS<"u"&&"registerProperty"in CSS&&[Be.scrollAreaOverflowXStart,Be.scrollAreaOverflowXEnd,Be.scrollAreaOverflowYStart,Be.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),Kn=!0)}const hi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{viewportRef:l,scrollbarYRef:c,scrollbarXRef:u,thumbYRef:d,thumbXRef:f,cornerRef:m,cornerSize:p,setCornerSize:g,setThumbSize:b,rootId:h,setHiddenState:w,hiddenState:y,handleScroll:x,setHovering:A,setOverflowEdges:k,overflowEdges:_,overflowEdgeThreshold:R,scrollingX:F,scrollingY:G}=Ht(),D=mr(),q=o.useRef(!0),H=Mt(),j=Mt(),E=Xe(()=>{const S=l.current,N=c.current,P=u.current,z=d.current,B=f.current,re=m.current;if(!S)return;const ne=S.scrollHeight,Z=S.scrollWidth,ee=S.clientHeight,Q=S.clientWidth,le=S.scrollTop,V=S.scrollLeft;if(ne===0||Z===0)return;const se=ee>=ne,ce=Q>=Z,be=Q/Z,me=ee/ne,ge=Math.max(0,Z-Q),pe=Math.max(0,ne-ee);let O=0,fe=0;if(!ce){let J=0;D==="rtl"?J=it(-V,0,ge):J=it(V,0,ge),O=_n(J,ge),fe=ge-O}const L=se?0:it(le,0,pe),W=se?0:_n(L,pe),X=se?0:pe-W,oe=ce?0:Q,ie=se?0:ee;let te=0,Se=0;!ce&&!se&&(te=N?.offsetWidth||0,Se=P?.offsetHeight||0);const Oe=p.width===0&&p.height===0,xe=Oe?te:0,Le=Oe?Se:0,ut=Ce(P,"padding","x"),xt=Ce(N,"padding","y"),qe=Ce(B,"margin","x"),Ve=Ce(z,"margin","y"),dt=oe-ut-qe,ft=ie-xt-Ve,yt=P?Math.min(P.offsetWidth-xe,dt):dt,wt=N?Math.min(N.offsetHeight-Le,ft):ft,mt=Math.max(On,yt*be),pt=Math.max(On,wt*me);if(b(J=>J.height===pt&&J.width===mt?J:{width:mt,height:pt}),N&&z){const J=N.offsetHeight-pt-xt-Ve,Ne=ne-ee,Ke=Ne===0?0:le/Ne,Ue=Math.min(J,Math.max(0,Ke*J));z.style.transform=`translate3d(0,${Ue}px,0)`}if(P&&B){const J=P.offsetWidth-mt-ut-qe,Ne=Z-Q,Ke=Ne===0?0:V/Ne,Ue=D==="rtl"?it(Ke*J,-J,0):it(Ke*J,0,J);B.style.transform=`translate3d(${Ue}px,0,0)`}const bt=[[Be.scrollAreaOverflowXStart,O],[Be.scrollAreaOverflowXEnd,fe],[Be.scrollAreaOverflowYStart,W],[Be.scrollAreaOverflowYEnd,X]];for(const[J,Ne]of bt)S.style.setProperty(J,`${Ne}px`);re&&(ce||se?g({width:0,height:0}):!ce&&!se&&g({width:te,height:Se})),w(J=>{const Ne=se||ce;return J.y===se&&J.x===ce&&J.corner===Ne?J:{y:se,x:ce,corner:Ne}});const ze={xStart:!ce&&O>R.xStart,xEnd:!ce&&fe>R.xEnd,yStart:!se&&W>R.yStart,yEnd:!se&&X>R.yEnd};k(J=>J.xStart===ze.xStart&&J.xEnd===ze.xEnd&&J.yStart===ze.yStart&&J.yEnd===ze.yEnd?J:ze)});Ie(()=>{if(!l.current)return;pi();let S=!1;return mi(l.current,()=>{if(!S){S=!0;return}E()})},[E,l]),Ie(()=>{queueMicrotask(E)},[E,y,D]),Ie(()=>{l.current?.matches(":hover")&&A(!0)},[l,A]),o.useEffect(()=>{const S=l.current;if(typeof ResizeObserver>"u"||!S)return;let N=!1;const P=new ResizeObserver(()=>{if(!N){N=!0;return}E()});return P.observe(S),j.start(0,()=>{const z=S.getAnimations({subtree:!0});z.length!==0&&Promise.allSettled(z.map(B=>B.finished)).then(E).catch(()=>{})}),()=>{P.disconnect(),j.clear()}},[E,l,j]);function T(){q.current=!1}const M={role:"presentation",...h&&{"data-id":`${h}-viewport`},...(!y.x||!y.y)&&{tabIndex:0},className:jr.className,style:{overflow:"scroll"},onScroll(){l.current&&(E(),q.current||x({x:l.current.scrollLeft,y:l.current.scrollTop}),H.start(100,()=>{q.current=!0}))},onWheel:T,onTouchMove:T,onPointerMove:T,onPointerEnter:T,onKeyDown:T},K=o.useMemo(()=>({scrolling:F||G,hasOverflowX:!y.x,hasOverflowY:!y.y,overflowXStart:_.xStart,overflowXEnd:_.xEnd,overflowYStart:_.yStart,overflowYEnd:_.yEnd,cornerHidden:y.corner}),[F,G,y.x,y.y,y.corner,_]),$=Ge("div",t,{ref:[r,l],state:K,props:[M,i],stateAttributesMapping:xn}),C=o.useMemo(()=>({computeThumbPosition:E}),[E]);return n.jsx(fi.Provider,{value:C,children:$})}),Nr=o.createContext(void 0);function gi(){const e=o.useContext(Nr);if(e===void 0)throw new Error(dn(54));return e}let Pt=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const xi=o.forwardRef(function(t,r){const{render:s,className:a,orientation:i="vertical",keepMounted:l=!1,...c}=t,{hovering:u,scrollingX:d,scrollingY:f,hiddenState:m,overflowEdges:p,scrollbarYRef:g,scrollbarXRef:b,viewportRef:h,thumbYRef:w,thumbXRef:y,handlePointerDown:x,handlePointerUp:A,rootId:k,thumbSize:_}=Ht(),R={hovering:u,scrolling:{horizontal:d,vertical:f}[i],orientation:i,hasOverflowX:!m.x,hasOverflowY:!m.y,overflowXStart:p.xStart,overflowXEnd:p.xEnd,overflowYStart:p.yStart,overflowYEnd:p.yEnd,cornerHidden:m.corner},F=mr();o.useEffect(()=>{const E=h.current,T=i==="vertical"?g.current:b.current;if(!T)return;function M(K){if(!(!E||!T||K.ctrlKey)){if(K.preventDefault(),i==="vertical"){if(E.scrollTop===0&&K.deltaY<0)return}else if(E.scrollLeft===0&&K.deltaX<0)return;if(i==="vertical"){if(E.scrollTop===E.scrollHeight-E.clientHeight&&K.deltaY>0)return}else if(E.scrollLeft===E.scrollWidth-E.clientWidth&&K.deltaX>0)return;i==="vertical"?E.scrollTop+=K.deltaY:E.scrollLeft+=K.deltaX}}return T.addEventListener("wheel",M,{passive:!1}),()=>{T.removeEventListener("wheel",M)}},[i,b,g,h]);const G={...k&&{"data-id":`${k}-scrollbar`},onPointerDown(E){if(E.button===0&&E.currentTarget===E.target&&h.current){if(w.current&&g.current&&i==="vertical"){const T=Ce(w.current,"margin","y"),M=Ce(g.current,"padding","y"),K=w.current.offsetHeight,$=g.current.getBoundingClientRect(),C=E.clientY-$.top-K/2-M+T/2,S=h.current.scrollHeight,N=h.current.clientHeight,P=g.current.offsetHeight-K-M-T,B=C/P*(S-N);h.current.scrollTop=B}if(y.current&&b.current&&i==="horizontal"){const T=Ce(y.current,"margin","x"),M=Ce(b.current,"padding","x"),K=y.current.offsetWidth,$=b.current.getBoundingClientRect(),C=E.clientX-$.left-K/2-M+T/2,S=h.current.scrollWidth,N=h.current.clientWidth,P=b.current.offsetWidth-K-M-T,z=C/P;let B;F==="rtl"?(B=(1-z)*(S-N),h.current.scrollLeft<=0&&(B=-B)):B=z*(S-N),h.current.scrollLeft=B}x(E)}},onPointerUp:A,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...i==="vertical"&&{top:0,bottom:`var(${Lt.scrollAreaCornerHeight})`,insetInlineEnd:0,[Pt.scrollAreaThumbHeight]:`${_.height}px`},...i==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${Lt.scrollAreaCornerWidth})`,bottom:0,[Pt.scrollAreaThumbWidth]:`${_.width}px`}}},D=Ge("div",t,{ref:[r,i==="vertical"?g:b],state:R,props:[G,c],stateAttributesMapping:xn}),q=o.useMemo(()=>({orientation:i}),[i]),H=i==="vertical"?m.y:m.x;return l||!H?n.jsx(Nr.Provider,{value:q,children:D}):null}),yi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{thumbYRef:l,thumbXRef:c,handlePointerDown:u,handlePointerMove:d,handlePointerUp:f,setScrollingX:m,setScrollingY:p}=Ht(),{orientation:g}=gi();return Ge("div",t,{ref:[r,g==="vertical"?l:c],state:{orientation:g},props:[{onPointerDown:u,onPointerMove:d,onPointerUp(w){g==="vertical"&&p(!1),g==="horizontal"&&m(!1),f(w)},style:{...g==="vertical"&&{height:`var(${Pt.scrollAreaThumbHeight})`},...g==="horizontal"&&{width:`var(${Pt.scrollAreaThumbWidth})`}}},i]})}),wi=o.forwardRef(function(t,r){const{render:s,className:a,...i}=t,{cornerRef:l,cornerSize:c,hiddenState:u}=Ht(),d=Ge("div",t,{ref:[r,l],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:c.width,height:c.height}},i]});return u.corner?null:d});function kr({className:e,...t}){return n.jsx(ui,{className:I("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function Cr({className:e,...t}){return n.jsx(hi,{className:I("h-full w-full outline-none focus-visible:outline-none",e),...t})}function Er({className:e,...t}){return n.jsx(xi,{className:I("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 Tr({className:e,...t}){return n.jsx(yi,{className:I("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function bi({className:e,...t}){return n.jsx(wi,{className:I("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function Si(e){return e==="subagent"?fs:e==="cron"?ms:ps}function vi(e){if(!e||!Array.isArray(e.content))return"";const t=e.content.map(s=>s.type==="text"?String(s.text??""):"").join(" ");return gr(t).replace(/\s+/g," ").trim()}function ji(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function Ni(e){if(!e)return null;const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=ji(r);if(s)return s}return null}function ki(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 Ci(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function Ei({session:e,active:t,isGenerating:r=!1,isPinned:s,selectionMode:a=!1,selected:i=!1,onToggleSelect:l,onSelect:c,onTogglePin:u,onRename:d,onDelete:f,onExport:m}){const p=e.label||e.title||e.derivedTitle||e.friendlyId,g=Si(e.kind),b=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?vi(e.lastMessage):"",h=b.length>50?`${b.slice(0,50).trimEnd()}…`:b,w=e.kind==="subagent"?Ci(e.status):null,y=e.kind==="cron"?Ni(e.lastMessage):null;return n.jsxs(He,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:x=>{if(a){x.preventDefault(),x.stopPropagation(),l?.(e);return}c?.()},className:I("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:I("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(Y,{icon:g,size:12,strokeWidth:1.75,className:"text-primary-500/70 shrink-0"}),n.jsxs("div",{className:"min-w-0 truncate text-sm font-[450]",title:p,children:[s?n.jsx("span",{className:"mr-1 text-xs text-primary-700","aria-hidden":"true",children:"📌"}):null,p]}),e.kind==="subagent"?r?n.jsx("span",{"aria-label":"Session active",className:"size-1.5 rounded-full bg-green-500 shrink-0"}):w==="success"?n.jsx(Y,{icon:nr,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):w==="error"?n.jsx(Y,{icon:zt,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),h?n.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:h}):null,e.kind==="cron"&&y?n.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:ki(y)}):null]})]}),a?null:n.jsxs(Ut,{children:[n.jsx($t,{type:"button",onClick:x=>{x.preventDefault(),x.stopPropagation()},className:I("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(Y,{icon:cs,size:20,strokeWidth:1.5})}),n.jsxs(Ft,{side:"bottom",align:"end",children:[n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),u(e)},className:"gap-2",children:[n.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",s?"Unpin Session":"Pin Session"]}),n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),d(e)},className:"gap-2",children:[n.jsx(Y,{icon:us,size:20,strokeWidth:1.5})," ","Rename"]}),n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),m(e)},className:"gap-2",children:[n.jsx(Y,{icon:ds,size:20,strokeWidth:1.5})," ","Export"]}),on(e.key)?null:n.jsxs(Ye,{onClick:x=>{x.preventDefault(),x.stopPropagation(),f(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[n.jsx(Y,{icon:rr,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function Ti(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 Vt=o.memo(Ei,Ti),Rr="opencami-pinned-sessions",Mr="opencami-sidebar-folders",Fe={webchat:!1,subagent:!1,cron:!1,other:!1};async function Ri(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 _e(r))}async function Mi(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 Ai(){if(typeof window>"u")return[];try{const e=localStorage.getItem(Rr);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}catch{return[]}}function Ii(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(Rr,JSON.stringify(t))}catch{}}function Di(){if(typeof window>"u")return{...Fe};try{const e=localStorage.getItem(Mr);if(!e)return{...Fe};const t=JSON.parse(e);return!t||typeof t!="object"?{...Fe}:{webchat:typeof t.webchat=="boolean"?t.webchat:Fe.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:Fe.subagent,cron:typeof t.cron=="boolean"?t.cron:Fe.cron,other:typeof t.other=="boolean"?t.other:Fe.other}}catch{return{...Fe}}}function Oi(e){if(!(typeof window>"u"))try{localStorage.setItem(Mr,JSON.stringify(e))}catch{}}function Et(e,t,r){return r&&e.key?e.key===r:e.friendlyId===t}function Li(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function Jt(e,t,r,s){return Et(e,t,r)&&s?!0:Li(e.status)}const Pi=o.memo(function({sessions:t,activeFriendlyId:r,activeSessionKey:s,isStreaming:a=!1,defaultOpen:i=!0,onSelect:l,onRename:c,onDelete:u,onExport:d}){const f=o.useDeferredValue(t),m=ct(),[p,g]=o.useState(()=>Ai()),[b,h]=o.useState(()=>Di()),[w,y]=o.useState(!1),[x,A]=o.useState(()=>new Set),k=o.useMemo(()=>new Set(p),[p]),_=f.filter(S=>k.has(S.key)),R=f.filter(S=>!k.has(S.key)),F=_.length>0&&R.length>0,G=o.useMemo(()=>{const S={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const N of R){const P=N.kind??"other";S[P].push(N)}return S},[R]),D=o.useMemo(()=>f.filter(S=>x.has(S.key)),[x,f]),q=D.length,H=o.useCallback(()=>{y(S=>(S&&A(new Set),!S))},[]),j=o.useCallback(S=>{on(S.key)||A(N=>{const P=new Set(N);return P.has(S.key)?P.delete(S.key):P.add(S.key),P})},[]),E=o.useCallback(()=>{A(new Set(f.filter(S=>!on(S.key)).map(S=>S.key)))},[f]),T=o.useCallback(()=>{y(!1),A(new Set)},[]),M=o.useCallback(async()=>{if(D.length===0||!window.confirm(`Delete ${D.length} sessions? This will archive them.`))return;const N=[];await Mi(D,10,async P=>{try{await Ri(P.key)}catch(z){throw N.push(P.label||P.title||P.derivedTitle||P.friendlyId),z}}),N.length>0&&(console.error("[sidebar] Bulk delete failed for some sessions",N),window.alert(`Could not delete ${N.length} session${N.length!==1?"s":""}:
|
|
6
|
-
|
|
7
|
-
${N.join(`
|
|
8
|
-
`)}`)),y(!1),A(new Set),m.invalidateQueries({queryKey:de.sessions})},[m,D]),K=o.useCallback(S=>{g(N=>{const z=N.includes(S.key)?N.filter(B=>B!==S.key):[...N,S.key];return Ii(z),z})},[]),$=o.useCallback((S,N)=>{h(P=>{const z={...P,[S]:N};return Oi(z),z})},[]);function C(S,N,P){return P.length===0?null:n.jsxs(It,{className:"flex flex-col",open:b[S],onOpenChange:z=>$(S,z),children:[n.jsxs(Dt,{className:I("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:N}),n.jsx("span",{className:I("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:P.length})]}),n.jsx(Ot,{contentClassName:"flex flex-col gap-px",children:P.map(z=>n.jsx(Vt,{session:z,active:Et(z,r,s),isGenerating:Jt(z,r,s,a),isPinned:!1,selectionMode:w,selected:x.has(z.key),onToggleSelect:j,onSelect:l,onTogglePin:K,onRename:c,onDelete:u,onExport:d},z.key))})]})}return n.jsxs(It,{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(Dt,{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(Y,{icon:fn,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),n.jsx("button",{type:"button",onClick:H,className:I("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",w?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:w?"Done":"Select"})]}),n.jsx(Ot,{className:"w-full flex-1 min-h-0 h-auto data-starting-style:h-0 data-ending-style:h-0",contentClassName:"flex flex-1 min-h-0 flex-col overflow-y-auto",children:n.jsxs(kr,{className:"flex-1 min-h-0",children:[n.jsx(Cr,{className:"min-h-0",children:n.jsxs("div",{className:"flex flex-col gap-2 pl-2 pr-2",children:[_.length>0?n.jsx("div",{className:"flex flex-col gap-px",children:_.map(S=>n.jsx(Vt,{session:S,active:Et(S,r,s),isGenerating:Jt(S,r,s,a),isPinned:!0,selectionMode:w,selected:x.has(S.key),onToggleSelect:j,onSelect:l,onTogglePin:K,onRename:c,onDelete:u,onExport:d},S.key))}):null,F?n.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,G.chat.length>0?n.jsxs("div",{className:"flex flex-col gap-px",children:[n.jsx("div",{className:I("border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:"💬 Chats"}),n.jsx("div",{className:"flex flex-col gap-px",children:G.chat.map(S=>n.jsx(Vt,{session:S,active:Et(S,r,s),isGenerating:Jt(S,r,s,a),isPinned:!1,selectionMode:w,selected:x.has(S.key),onToggleSelect:j,onSelect:l,onTogglePin:K,onRename:c,onDelete:u,onExport:d},S.key))})]}):null,C("webchat","🦎 OpenCami",G.webchat),C("subagent","🤖 Sub-agents",G.subagent),C("cron","⏰ Cron / Isolated",G.cron),C("other","📁 Other",G.other)]})}),n.jsx(Er,{orientation:"vertical",children:n.jsx(Tr,{})})]})}),w?n.jsxs("div",{className:"shrink-0 border-t border-primary-200 bg-surface px-2 py-2 flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-xs text-primary-600 font-medium",children:[q," selected"]}),n.jsx("button",{type:"button",onClick:E,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:q===0,className:I("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",q>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[n.jsx(Y,{icon:rr,size:14,strokeWidth:1.5}),"Delete"]}),n.jsx("button",{type:"button",onClick:T,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]})},_i);function _i(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 Ki=o.lazy(()=>_t(()=>import("./settings-dialog-CHJbvpgk.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}))),zi=o.lazy(()=>_t(()=>import("./session-export-dialog-qbZgd2Zo.js"),__vite__mapDeps([25,1,4,3,5,6,7,8,9,2])).then(e=>({default:e.SessionExportDialog})));function Ui({sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s=!1,creatingSession:a,onCreateSession:i,isCollapsed:l,onToggleCollapse:c,onSelectSession:u,onActiveSessionDelete:d,onOpenSearch:f}){const{settingsOpen:m,setSettingsOpen:p,pathsLoading:g,pathsError:b,paths:h,handleOpenSettings:w,closeSettings:y,copySessionsDir:x,copyStorePath:A}=jo(),{deleteSession:k}=Io(),{renameSession:_}=Do(),R={duration:.15,ease:l?"easeIn":"easeOut"},[F,G]=o.useState(!1),[D,q]=o.useState(null),[H,j]=o.useState(""),[E,T]=o.useState(!1),[M,K]=o.useState(null),[$,C]=o.useState(null),[S,N]=o.useState(""),[P,z]=o.useState(!1),[B,re]=o.useState(null),[ne,Z]=o.useState(null),[ee,Q]=o.useState(""),le=ct();function V(O){q(O.key),j(O.label||O.title||O.derivedTitle||""),G(!0)}function se(O){D&&_(D,O),G(!1),q(null)}function ce(O){K(O.key),C(O.friendlyId),N(O.label||O.title||O.derivedTitle||O.friendlyId),T(!0)}function be(){if(M&&$){const O=$===t;O&&d&&d(),k(M,$,O)}T(!1),K(null),C(null)}function me(O){re(O.key),Z(O.friendlyId),Q(O.label||O.title||O.derivedTitle||O.friendlyId),z(!0)}function ge(O){if(B&&ne){const fe=de.history(ne,B),L=le.getQueryData(fe);L?.messages&&_o(ee,L.messages,O)}z(!1),re(null),Z(null)}const pe={className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col"};return n.jsxs(ve.aside,{initial:!1,animate:{width:l?48:"var(--opencami-sidebar-width)"},transition:R,className:pe.className,children:[n.jsxs(ve.div,{layout:!0,transition:{layout:R},className:I("flex items-center h-12 px-2 justify-between"),children:[n.jsx(Ee,{initial:!1,children:l?null:n.jsx(ve.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,children:n.jsxs(He,{to:"/new",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[n.jsx(no,{className:"size-5"}),n.jsx(ro,{})]})})}),n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{onClick:c,render:n.jsx(ye,{size:"icon-sm",variant:"ghost",children:n.jsx(Y,{icon:hs,size:20,strokeWidth:1.5})})}),n.jsx(Ae,{side:"right",children:l?"Open Sidebar":"Close Sidebar"})]})})]}),n.jsxs("div",{className:"px-2 mb-4 flex flex-col gap-1",children:[n.jsxs(ve.div,{layout:!0,transition:{layout:R},className:"w-full space-y-2",children:[n.jsxs(ye,{disabled:a,variant:"ghost",size:"sm",onClick:i,onMouseUp:u,className:"w-full pl-1.5 justify-start",children:[n.jsx(Y,{icon:gs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),(()=>{try{const O=localStorage.getItem("opencami-file-explorer");return O===null?!0:O==="true"}catch{return!0}})()&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{asChild:!0,children:n.jsxs(He,{to:"/files",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(Y,{icon:xs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),l&&n.jsx(Ae,{side:"right",children:"Files"})]})}),(()=>{try{const O=localStorage.getItem("opencami-memory-viewer");return O===null?!0:O==="true"}catch{return!0}})()&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{asChild:!0,children:n.jsxs(He,{to:"/memory",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(Y,{icon:nn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Memory"})})]})}),l&&n.jsx(Ae,{side:"right",children:"Memory"})]})}),(()=>{try{return localStorage.getItem("opencami-skills-browser")==="true"}catch{return!1}})()&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{asChild:!0,children:n.jsxs(He,{to:"/skills",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(Y,{icon:ys,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Skills"})})]})}),l&&n.jsx(Ae,{side:"right",children:"Skills"})]})}),(()=>{try{return localStorage.getItem("opencami-agent-manager")==="true"}catch{return!1}})()&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{asChild:!0,children:n.jsxs(He,{to:"/agents",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(Y,{icon:nn,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Agents"})})]})}),l&&n.jsx(Ae,{side:"right",children:"Agents"})]})}),(()=>{try{return localStorage.getItem("opencami-cron-manager")==="true"}catch{return!1}})()&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{asChild:!0,children:n.jsxs(He,{to:"/bots",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(Y,{icon:ws,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Cron Jobs"})})]})}),l&&n.jsx(Ae,{side:"right",children:"Cron Jobs"})]})}),(()=>{try{return localStorage.getItem("feature_dashboard")==="true"}catch{return!1}})()&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{asChild:!0,children:n.jsxs(He,{to:"/dashboard",className:I(Je({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:u,children:[n.jsx(Y,{icon:bs,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Dashboard"})})]})}),l&&n.jsx(Ae,{side:"right",children:"Dashboard"})]})})]}),n.jsx(ve.div,{layout:!0,transition:{layout:R},className:"w-full",children:n.jsxs(ye,{variant:"ghost",size:"sm",onClick:f,className:"w-full pl-1.5 justify-start",children:[n.jsx(Y,{icon:sr,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(Ee,{initial:!1,children:!l&&n.jsx(ve.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,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(Pi,{sessions:e,activeFriendlyId:t,activeSessionKey:r,isStreaming:s,onSelect:u,onRename:V,onDelete:ce,onExport:me})})},"content")})}),n.jsx("div",{className:"px-2 py-3 border-t border-primary-200 bg-primary-100",children:n.jsx(ve.div,{layout:!0,transition:{layout:R},className:"w-full",children:n.jsxs(ye,{variant:"ghost",size:"sm",onClick:w,title:l?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[n.jsx(Y,{icon:Ss,size:20,strokeWidth:1.5,className:"min-w-5"}),n.jsx(Ee,{initial:!1,mode:"wait",children:!l&&n.jsx(ve.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:R,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),m&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Ki,{open:m,onOpenChange:p,pathsLoading:g,pathsError:b,paths:h,onClose:y,onCopySessionsDir:x,onCopyStorePath:A})}),n.jsx(Bo,{open:F,onOpenChange:G,sessionTitle:H,onSave:se,onCancel:()=>G(!1)}),n.jsx(Yo,{open:E,onOpenChange:T,sessionTitle:S,onConfirm:be,onCancel:()=>T(!1)}),P&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(zi,{open:P,onOpenChange:z,sessionTitle:ee,onExport:ge,onCancel:()=>z(!1)})})]})}function $i(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 Fi(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!$i(e.sessions,t.sessions))}const Hi=o.memo(Ui,Fi);function zn(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 Un(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 Wi({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:Un(0),hasData:!1,isNearlyFull:!1};const m=typeof e=="number"&&e>0?e:0,p=Math.min(100,Math.round(m/t*100));return{percentage:p,usedStr:zn(m),maxStr:zn(t),colors:Un(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:I("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:I("h-full rounded-full transition-all duration-500 ease-out",l.bar,u&&"animate-pulse"),style:{width:`${s}%`}})}),n.jsx("span",{className:I("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:I("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:I("rounded-md border border-primary-200 dark:border-primary-700","bg-surface shadow-lg px-3 py-2","text-xs whitespace-nowrap"),children:[n.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[n.jsx("span",{className:"text-primary-500 dark:text-primary-400",children:"Context window"}),n.jsxs("span",{className:I("font-semibold",l.text),children:[s,"%"]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-primary-700 dark:text-primary-300",children:[n.jsx("span",{className:"font-medium",children:a}),n.jsx("span",{className:"text-primary-400",children:"/"}),n.jsx("span",{children:i}),n.jsx("span",{className:"text-primary-400",children:"tokens"})]}),n.jsx("div",{className:"w-full h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden mt-1.5",children:n.jsx("div",{className:I("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 Xi=o.memo(Wi);function Yi({activeTitle:e,wrapperRef:t,showSidebarButton:r=!1,onOpenSidebar:s,totalTokens:a,contextTokens:i}){return n.jsxs("div",{ref:t,"data-tauri-drag-region":!0,className:"border-b border-primary-200 px-4 h-12 flex min-w-0 items-center overflow-x-hidden bg-surface tauri-drag-header",children:[r?n.jsx(ye,{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(Y,{icon:vs,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(Xi,{totalTokens:a,contextTokens:i,className:"ml-3 hidden sm:flex"})]})}const Bi=o.memo(Yi);function Gi(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function qi(e){const t=new Date(e);return Gi(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 Vi(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 Ji({timestamp:e}){const t=qi(e),r=Vi(e);return n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{className:"inline-flex items-center text-xs text-primary-600",children:t}),n.jsx(Ae,{side:"top",children:r})]})})}function Qi({text:e,align:t,timestamp:r,forceVisible:s=!1}){const[a,i]=o.useState(!1),[l,c]=o.useState("idle"),u=o.useRef(null),d=o.useRef(null),f=o.useRef(null),[m,p]=o.useState(()=>{if(typeof window>"u")return!0;try{const y=localStorage.getItem("opencami-tts-enabled");return y===null?!0:y==="true"}catch{return!0}});o.useEffect(()=>{function y(x){x.key==="opencami-tts-enabled"&&p(x.newValue===null?!0:x.newValue==="true")}return window.addEventListener("storage",y),()=>window.removeEventListener("storage",y)},[]),o.useEffect(()=>()=>{f.current?.abort(),u.current&&(u.current.pause(),u.current=null),d.current&&(URL.revokeObjectURL(d.current),d.current=null)},[]);const g=async()=>{try{await navigator.clipboard.writeText(e),i(!0),window.setTimeout(()=>i(!1),1400)}catch{i(!1)}},b=async()=>{if(l==="playing"){f.current?.abort(),u.current&&(u.current.pause(),u.current=null),d.current&&(URL.revokeObjectURL(d.current),d.current=null),c("idle");return}f.current?.abort();const y=new AbortController;f.current=y,c("loading");try{const x=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e}),signal:y.signal});if(!x.ok)throw new Error("TTS failed");const A=await x.blob(),k=URL.createObjectURL(A);d.current=k;const _=new Audio(k);u.current=_,_.onended=()=>{c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null},_.onerror=()=>{c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null},await _.play(),c("playing")}catch(x){if(x instanceof Error&&x.name==="AbortError"){c("idle");return}c("idle"),d.current&&(URL.revokeObjectURL(d.current),d.current=null),u.current=null}},h=t==="end"?"justify-end":"justify-start",w=t==="start"&&m&&e.trim().length>0;return n.jsxs("div",{className:I("flex items-center gap-2 text-xs text-primary-600 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 duration-100 ease-out",s?"opacity-100":"opacity-0",h),children:[n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{type:"button",onClick:()=>{g().catch(()=>{})},className:"inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",children:n.jsx(Y,{icon:a?mn:js,size:16,strokeWidth:1.6})}),n.jsx(Ae,{side:"top",children:"Copy"})]})}),w&&n.jsx(Te,{children:n.jsxs(Re,{children:[n.jsx(Me,{type:"button",onClick:()=>{b().catch(()=>{})},disabled:l==="loading",className:I("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(Y,{icon:l==="loading"?Ns:l==="playing"?or:ks,size:16,strokeWidth:1.6,className:I(l==="loading"&&"animate-spin")})}),n.jsx(Ae,{side:"top",children:l==="loading"?"Generating speech…":l==="playing"?"Stop":"Listen"})]})}),n.jsx(Ji,{timestamp:r})]})}function Ar({children:e,className:t,...r}){return n.jsx("div",{className:I("flex gap-3 w-full",t),...r,children:e})}function Zi({children:e,markdown:t=!1,className:r,...s}){const a=I("rounded-[12px] break-words whitespace-normal min-w-0 max-w-full overflow-x-hidden",r);return t?n.jsx(so,{className:a,...s,children:e}):n.jsx("div",{className:a,...s,children:e})}function ea(){const[e,t]=o.useState(()=>typeof window<"u"?window.innerWidth<768:!1);return o.useEffect(()=>{if(typeof window>"u")return;const r=window.matchMedia("(max-width: 767px)"),s=a=>t(a.matches);return r.addEventListener("change",s),t(r.matches),()=>r.removeEventListener("change",s)},[]),e}function ta({content:e}){const t=ea();return n.jsx("div",{className:"inline-flex flex-col",children:n.jsxs(It,{defaultOpen:!t,children:[n.jsxs(Dt,{render:n.jsx(ye,{variant:"ghost",className:"h-auto gap-1.5 px-1.5 py-0.5 -mx-2"}),children:[n.jsx("span",{className:"text-sm font-medium text-primary-900",children:"Thinking"}),n.jsx(Y,{icon:pn,size:14,strokeWidth:1.5,className:"text-primary-900 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),n.jsx(Ot,{children:n.jsx("div",{className:"pt-1 mb-3",children:n.jsx("p",{className:"text-sm text-primary-700 whitespace-pre-wrap",children:e})})})]})})}function na({toolPart:e,defaultOpen:t=!1}){const{state:r,input:s,output:a,toolCallId:i}=e,l=(d,f=3200)=>{const m=d===void 0?"undefined":d;let p;if(typeof m=="string")try{p=JSON.stringify(JSON.parse(m),null,2)}catch{p=m}else p=JSON.stringify(m,null,2);return p.length<=f?p:`${p.slice(0,f).trimEnd()}
|
|
9
|
-
…[truncated]`},c=r==="output-error"?zt:r==="output-available"?nr:ir,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(It,{defaultOpen:t,children:[n.jsxs(Dt,{render:n.jsx(ye,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[n.jsx(Y,{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(Y,{icon:pn,size:14,strokeWidth:1.5,className:"ml-auto text-primary-700/80 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),n.jsx(Ot,{className:"mt-1",children:n.jsxs("div",{className:"space-y-2 rounded-md border border-primary-200 bg-primary-100/70 p-2",children:[n.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[n.jsx("div",{className:"text-[11px] font-medium text-primary-600",children:"Tool"}),n.jsx("div",{className:"font-mono text-xs text-primary-800 break-all",children:e.type})]}),s&&Object.keys(s).length>0&&n.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[n.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Input"}),n.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:l(s)})]}),a!=null&&n.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[n.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Output"}),n.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:l(a)})]}),r==="output-error"&&e.errorText&&n.jsxs("div",{className:"rounded border border-red-200 bg-red-50 px-2 py-1.5",children:[n.jsx("h4",{className:"mb-1 text-[11px] font-medium text-red-600",children:"Error"}),n.jsx("div",{className:"text-xs text-red-700",children:e.errorText})]}),i&&n.jsxs("div",{className:"text-[11px] text-primary-500/80 font-mono tabular-nums",children:["ID: ",i.slice(0,16),"..."]})]})})]})})}function $n(e){try{return new URL(e).hostname.replace("www.","")}catch{return e}}function Fn({domain:e}){return n.jsx("div",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-white dark:bg-zinc-800 border border-cyan-500/20 overflow-hidden",title:e,children:n.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${e}&sz=32`,alt:"",className:"w-4 h-4 object-contain",loading:"lazy",onError:t=>{const r=t.target;r.style.display="none";const s=r.parentElement;s&&(s.textContent=e.charAt(0).toUpperCase(),s.classList.add("text-[10px]","font-medium","text-cyan-400"))}})})}function ra({sources:e}){const[t,r]=o.useState(!1);if(!e.length)return null;const s=[...new Set(e.map(a=>$n(a.url)))];return n.jsxs("div",{className:"mt-2 w-full",children:[n.jsxs("button",{onClick:()=>r(!t),className:I("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs","bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-500/30","text-cyan-300 transition-colors"),children:[n.jsx(Y,{icon:sr,size:14}),n.jsx("span",{className:"font-medium",children:"Sources"}),n.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-cyan-500/20 text-cyan-400 font-semibold",children:e.length}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-1",children:[s.slice(0,3).map(a=>n.jsx(Fn,{domain:a},a)),s.length>3&&n.jsxs("span",{className:"text-cyan-500/70 text-[10px] ml-0.5",children:["+",s.length-3]})]}),n.jsx(Y,{icon:fn,size:12,className:I("transition-transform",t&&"rotate-90")})]}),t&&n.jsx("div",{className:"mt-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 max-h-80 overflow-y-auto",children:e.map((a,i)=>{const l=$n(a.url);return n.jsxs("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-start gap-2 p-2.5 border-b border-cyan-500/10 last:border-b-0 hover:bg-cyan-500/5 transition-colors",children:[n.jsx(Fn,{domain:l}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-primary-900 hover:underline line-clamp-1",children:a.title||l}),n.jsx("div",{className:"text-xs text-muted-foreground",children:l}),a.snippet&&n.jsx("p",{className:"text-xs text-muted-foreground/80 line-clamp-2 mt-0.5",children:a.snippet})]})]},`${a.url}-${i}`)})})]})}function sa(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 Hn(e){return Ze(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 oa(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 Wn(e,t){if(!t)return"";const r=Ze(e);return r.length===0?"":r.map(s=>s.id?oa(t.get(s.id)):"missing").join("||")}function ia(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 Xn(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const r of t){const s=ia(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 aa(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 at=/^📎 Uploaded file:\s*(\/uploads\/\S+)\s*$/;function la(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 ca(e){if(!e)return[];const t=e.trimStart();if(t.startsWith(">")||t.startsWith("```"))return[];const r=e.split(`
|
|
10
|
-
`),s=[];for(const i of r){if(at.test(i)){s.push(i);continue}if(s.length>0&&i.trim()===""){s.push(i);continue}break}const a=r[0]??"";return at.test(a)?s.filter(i=>at.test(i)):[]}function ua(e){const t=[],r=new Set;for(const s of ca(e)){const i=s.match(at)?.[1];!i||r.has(i)||(r.add(i),t.push({path:i,filename:i.split("/").pop()||i}))}return t}function da(e){const t=e.split(`
|
|
11
|
-
`);if(!at.test(t[0]??""))return e.trim();let r=0;for(;r<t.length&&at.test(t[r]);)r++;for(;r<t.length&&t[r].trim()==="";)r++;return t.slice(r).join(`
|
|
12
|
-
`).replace(/\n{3,}/g,`
|
|
13
|
-
|
|
14
|
-
`).trim()}function fa({message:e,toolResultsByCallId:t,forceActionsVisible:r=!1,isStreaming:s=!1,isLastAssistant:a=!1,aggregatedSearchSources:i,wrapperRef:l,wrapperClassName:c,wrapperScrollMarginTop:u,messageDomId:d,highlighted:f=!1}){const{settings:m}=oo(),p=e.role||"assistant",g=De(e),b=ln(e),h=aa(e),w=p==="user",y=sn(e),x=Kt(),A=Hs(j=>j.openInEditor),k=o.useMemo(()=>ua(g),[g]),[_,R]=o.useState({}),F=o.useMemo(()=>da(g),[g]);o.useEffect(()=>{let j=!1;async function E(){const T={};await Promise.all(k.map(async M=>{try{const K=await fetch(`/api/files/info?path=${encodeURIComponent(M.path)}`);if(!K.ok){T[M.path]=null;return}const $=await K.json();T[M.path]=typeof $.size=="number"?$.size:null}catch{T[M.path]=null}})),j||R(T)}return k.length>0?E():R({}),()=>{j=!0}},[k]);const G=async j=>{A(j),await x({to:"/files"})},D=p==="assistant"?Ze(e):[],q=D.length>0,H=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:I("opencami-message-item group mx-auto flex w-full max-w-[var(--opencami-chat-width)] flex-col gap-1 py-[var(--opencami-msg-padding-y)]",c,f&&"opencami-message-highlight",w?"items-end":"items-start"),children:[b&&m.showReasoningBlocks&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(ta,{content:b})}),h.length>0&&n.jsx("div",{className:I("flex flex-wrap gap-2 mb-2",w?"justify-end":"justify-start"),children:h.map((j,E)=>n.jsx("img",{src:`data:${j.source.media_type};base64,${j.source.data}`,alt:`Attachment ${E+1}`,loading:"lazy",decoding:"async",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},E))}),k.length>0&&n.jsx("div",{className:I("mb-2 flex w-full flex-col gap-2",w?"items-end":"items-start"),children:k.map(j=>n.jsxs("button",{type:"button",onClick:()=>{G(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(Y,{icon:ar,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:la(_[j.path]??null)})]})]},j.path))}),n.jsx(Ar,{className:I("min-w-0 max-w-full",w?"flex-row-reverse":""),children:n.jsx(Zi,{markdown:!w,className:I("text-primary-900 opencami-text-size min-w-0 max-w-full",w?"opencami-message-user bg-primary-100 px-4 py-[var(--opencami-user-bubble-py)] max-w-[85%]":"opencami-message-assistant bg-transparent w-full",!w&&s&&"stream-fade-in"),children:F})}),q&&m.showToolMessages&&n.jsx("div",{className:"mt-2 flex w-full min-w-0 max-w-[var(--opencami-chat-width)] flex-col gap-3 overflow-x-hidden",children:D.map(j=>{const E=j.id?t?.get(j.id):void 0,T=sa(j,E);return n.jsx(na,{toolPart:T,defaultOpen:!1},j.id||j.name)})}),H.length>0&&n.jsx("div",{className:"w-full max-w-[var(--opencami-chat-width)]",children:n.jsx(ra,{sources:H})}),!q&&n.jsx(Qi,{text:g,timestamp:y,align:w?"end":"start",forceVisible:r})]})}function ma(e,t){return!(e.forceActionsVisible!==t.forceActionsVisible||e.isStreaming!==t.isStreaming||e.isLastAssistant!==t.isLastAssistant||e.aggregatedSearchSources!==t.aggregatedSearchSources||e.wrapperClassName!==t.wrapperClassName||e.wrapperRef!==t.wrapperRef||e.wrapperScrollMarginTop!==t.wrapperScrollMarginTop||e.messageDomId!==t.messageDomId||e.highlighted!==t.highlighted||(e.message.role||"assistant")!==(t.message.role||"assistant")||De(e.message)!==De(t.message)||ln(e.message)!==ln(t.message)||Hn(e.message)!==Hn(t.message)||Wn(e.message,e.toolResultsByCallId)!==Wn(t.message,t.toolResultsByCallId)||Xn(e.message)!==Xn(t.message))}const Qt=o.memo(fa,ma),pa=[/```[\s\S]*?```/g,/`[^`]+`/g,/\b(function|const|let|var|class|import|export|return|async|await)\b/g];function ha(e){const t=[],r=e.match(/"([^"]+)"|'([^']+)'/g);r&&t.push(...r.map(i=>i.replace(/['"]/g,"")));const s=e.match(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g);s&&t.push(...s.filter(i=>!["I","The","A","An","This"].includes(i)));const a=e.match(/`([^`]+)`/g);return a&&t.push(...a.map(i=>i.replace(/`/g,""))),[...new Set(t)].slice(0,5)}function ga(e){return pa.some(t=>t.test(e))}function xa(e){return/^[\s]*[-*•\d]+[.)\s]/m.test(e)||/\b(first|second|third|1\.|2\.|3\.)/i.test(e)}function ya(e){return/\b(alternatively|another|other option|could also|you might|consider)\b/i.test(e)}function wa(e){return/\b(because|since|due to|reason|why|how|what|when|where)\b/i.test(e)}function ba(e){return/\b(however|but|note|warning|caution|careful|important|keep in mind|be aware)\b/i.test(e)}function Sa(e){const t=[],r=ha(e);if(ga(e)&&(t.push({text:"Can you explain this code step by step?",type:"clarify"}),t.push({text:"How would I modify this for my use case?",type:"actionable"})),xa(e)&&(t.push({text:"Can you elaborate on the first point?",type:"expand"}),t.push({text:"Which of these is most important to start with?",type:"actionable"})),ya(e)&&(t.push({text:"What are the pros and cons of each approach?",type:"alternative"}),t.push({text:"Which option would you recommend and why?",type:"clarify"})),wa(e)&&t.length<3&&t.push({text:"Can you give me a practical example?",type:"example"}),ba(e)&&t.length<3&&t.push({text:"What potential issues should I watch out for?",type:"clarify"}),r.length>0&&t.length<3){const i=r[0];t.push({text:`Tell me more about ${i}`,type:"expand"})}const s=[{text:"Can you give me a concrete example?",type:"example"},{text:"What would be the next steps?",type:"actionable"},{text:"How does this work in practice?",type:"expand"},{text:"Are there any common mistakes to avoid?",type:"clarify"},{text:"Can you simplify this explanation?",type:"clarify"}],a=new Set(t.map(i=>i.type));for(const i of s){if(t.length>=3)break;a.has(i.type)||(t.push(i),a.add(i.type))}for(const i of s){if(t.length>=3)break;t.some(l=>l.text===i.text)||t.push(i)}return t.slice(0,3)}function Yn(e){return Sa(e).map(t=>t.text)}const va={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:""}},Tt={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function Ir(e){return va[e]}function ja(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():Ir(e.llmProvider).baseUrl}function Na(e){return e.llmModel.trim()?e.llmModel.trim():Ir(e.llmProvider).model}function Bn(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||!!(e.llmBaseUrl.trim()&&e.llmModel.trim()):t||!!e.llmApiKey.trim()}function ka(e){if(!e||typeof e!="object")return{settings:Tt};const{settings:t}=e;if(!t)return{settings:Tt};const{openaiApiKey:r,...s}=t,a=s.llmApiKey??r??"";return{settings:{...Tt,...s,llmApiKey:a}}}const et=hr()(pr(e=>({settings:{...Tt},updateSettings:t=>e(r=>({settings:{...r.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>ka(e)}));function oc(){const e=et(l=>l.settings),t=et(l=>l.updateSettings),r=et(l=>l.clearApiKey),[s,a]=o.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasKilocodeKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:Bn(e,!1),isLoading:!0,error:null});o.useEffect(()=>{let l=!1;async function c(){try{const u=await fetch("/api/llm-features");if(!u.ok)throw new Error("Failed to check LLM status");const d=await u.json();if(l)return;const f=!!e.llmApiKey,m=e.llmProvider==="openrouter"?!!d.hasOpenRouterKey:e.llmProvider==="kilocode"?!!d.hasKilocodeKey:d.hasEnvKey;a({hasEnvKey:d.hasEnvKey,hasOpenRouterKey:!!d.hasOpenRouterKey,hasKilocodeKey:!!d.hasKilocodeKey,hasUserKey:f,isAvailable:Bn(e,m),isLoading:!1,error:null})}catch(u){if(l)return;a(d=>({...d,isLoading:!1,error:u instanceof Error?u.message:"Failed to check status"}))}}return c(),()=>{l=!0}},[e.llmApiKey,e.llmProvider,e.llmBaseUrl,e.llmModel]);const i=o.useCallback(async l=>{try{const c=Dr({...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 Dr(e){const t=e.llmApiKey,r=ja(e),s=Na(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 Or(){const e=et.getState().settings;return Dr(e)}async function Ca(e,t){const r={"Content-Type":"application/json",...Or()},s=await fetch("/api/llm-features",{method:"POST",headers:r,body:JSON.stringify({action:"followups",conversationContext:e}),signal:t});if(!s.ok)throw new Error(`API error: ${s.status}`);const a=await s.json();return a.ok&&Array.isArray(a.suggestions)&&a.suggestions.length>0?a.suggestions:[]}function Ea(e,t,r){const s=et(A=>A.settings),a=s.useLlmFollowUps,{minResponseLength:i=50,timeoutMs:l=8e3,heuristicsOnly:c}=r??{},u=c??!a,[d,f]=o.useState([]),[m,p]=o.useState(!1),[g,b]=o.useState(null),[h,w]=o.useState(null),y=o.useRef(""),x=o.useRef(null);return o.useEffect(()=>{if(!e||e.trim().length<i){f([]),w(null),p(!1),b(null);return}const A=e.slice(0,200)+e.length;if(A===y.current)return;if(y.current=A,x.current&&x.current.abort(),u){const F=Yn(e);f(F),w("heuristic"),p(!1),b(null);return}const k=new AbortController;x.current=k,p(!0),b(null);const _=Yn(e);f(_),w("heuristic");const R=t?`Context: ${t}
|
|
15
|
-
|
|
16
|
-
Assistant's response:
|
|
17
|
-
${e.slice(0,2e3)}`:`Assistant's response:
|
|
18
|
-
${e.slice(0,2e3)}`;return Ca(R,k.signal).then(F=>{k.signal.aborted||(F.length>0&&(f(F),w("llm")),p(!1))}).catch(F=>{k.signal.aborted||(b(F instanceof Error?F.message:String(F)),p(!1))}),()=>{}},[e,t,i,l,u,s.llmApiKey,s.llmBaseUrl,s.llmModel,s.llmProvider]),{suggestions:d,isLoading:m,error:g,source:h}}function Ta({responseText:e,contextSummary:t,onSuggestionClick:r,disabled:s=!1,className:a}){const{suggestions:i,isLoading:l,source:c}=Ea(e,t,{minResponseLength:50,timeoutMs:8e3});return i.length===0&&!l?null:n.jsxs("div",{className:I("flex flex-col gap-2 mt-3",a),children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-primary-500",children:[n.jsx("span",{className:"text-primary-400",children:"✨"}),n.jsx("span",{children:l?n.jsxs("span",{className:"flex items-center gap-1",children:["Thinking of follow-ups",n.jsx(Y,{icon:ir,size:12,strokeWidth:2,className:"animate-spin text-primary-400"})]}):c==="llm"?"AI suggestions":"Follow-up suggestions"})]}),n.jsx("div",{className:"flex flex-wrap gap-2",children:i.map((u,d)=>n.jsxs("button",{type:"button",disabled:s,onClick:()=>r(u),className:I("group inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full","text-sm text-primary-700 bg-primary-50 border border-primary-200","hover:bg-primary-100 hover:border-primary-300 hover:text-primary-900","focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:ring-offset-1","transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-primary-50 disabled:hover:border-primary-200",l&&"opacity-75"),children:[n.jsx("span",{children:u}),n.jsx(Y,{icon:fn,size:14,strokeWidth:2,className:"text-primary-400 group-hover:text-primary-600 group-hover:translate-x-0.5 transition-all duration-150"})]},`${d}-${u.slice(0,20)}`))})]})}const Gn=o.memo(Ta);function Ra({className:e,variant:t="outline",scrollRef:r,...s}){const[a,i]=o.useState(!0),[l,c]=o.useState(!1),u=o.useRef(0),d=o.useCallback(()=>{const f=r.current;if(!f)return;const m=Math.abs(f.scrollHeight-f.scrollTop-f.clientHeight)<100;i(m)},[r]);return o.useLayoutEffect(()=>{const f=r.current;if(!f)return;const m=()=>{u.current=f.scrollTop,d()},p=new MutationObserver(()=>{f&&(f.scrollTop!==u.current&&(u.current=f.scrollTop),d())});return d(),f.addEventListener("scroll",m),p.observe(f,{childList:!0,subtree:!0}),()=>{f.removeEventListener("scroll",m),p.disconnect()}},[d,r]),o.useLayoutEffect(()=>{if(a){c(!1);return}const f=window.setTimeout(()=>{c(!0)},200);return()=>window.clearTimeout(f)},[a]),n.jsx(ye,{variant:"secondary",size:"icon-sm",className:I("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(Y,{icon:pn,size:18,strokeWidth:1.8})})}function Ma({className:e,viewportRef:t,scrollRef:r,viewportProps:s}){return n.jsxs(kr,{className:I("relative flex flex-1 min-h-0 flex-col",e),children:[n.jsx(Cr,{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(Ra,{scrollRef:r})})}),n.jsx(Er,{orientation:"vertical",children:n.jsx(Tr,{})}),n.jsx(bi,{})]})}function Aa(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 Ia(e,t){return!(e.className!==t.className||e.viewportRef!==t.viewportRef||e.scrollRef!==t.scrollRef||!Aa(e.viewportProps,t.viewportProps))}const Da=o.memo(Ma,Ia);function Oa({viewportNode:e,children:t}){return e?rs.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 La({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(Da,{className:t,viewportRef:c,scrollRef:a,viewportProps:s}),n.jsx(Oa,{viewportNode:i,children:e})]})}const Pa=o.memo(La);function _a({children:e,className:t,...r}){return n.jsx("div",{className:I("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 Ka({...e}){return n.jsx("div",{className:"h-px w-full shrink-0 scroll-mt-4 pt-6","aria-hidden":"true",...e})}function za({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:I("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 Ua({className:e}){return n.jsxs("div",{className:I("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(za,{className:"text-sm",duration:2,children:"Generating..."})]})}function $a({messages:e,loading:t,empty:r,emptyState:s,notice:a,noticePosition:i="start",waitingForResponse:l,isStreaming:c=!1,sessionKey:u,pinToTop:d,pinGroupMinHeight:f,headerHeight:m,contentStyle:p,onFollowUpClick:g,jumpToMessageId:b}){const h=o.useRef(null),w=o.useRef(null),y=o.useRef(!1),x=o.useRef(d),A=o.useRef(void 0),[k,_]=o.useState(null),R=o.useMemo(()=>e.filter(C=>C.role!=="toolResult"),[e]),F=o.useMemo(()=>{const C=new Map;for(const S of e){if(S.role!=="toolResult")continue;const N=S.toolCallId;typeof N=="string"&&N.trim().length>0&&C.set(N,S)}return C},[e]),G=o.useMemo(()=>{const C=z=>z?z.replace(/SECURITY NOTICE:[\s\S]*?<<<EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?END_EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/Source: Web (?:Search|Fetch)\n---/g,"").replace(/\n{2,}/g,`
|
|
19
|
-
`).trim():"",S=(z,B,re)=>{try{const ne=JSON.parse(z),Z=Array.isArray(ne)?ne:ne?.results??ne?.web?.results??[];if(!Array.isArray(Z))return!1;let ee=!1;for(const Q of Z)Q?.url&&Q?.title&&!re.has(Q.url)&&(re.add(Q.url),B.push({title:C(Q.title),url:Q.url,snippet:C(Q.description||Q.snippet||Q.content||"")}),ee=!0);return ee}catch{return!1}},N=[],P=new Set;for(const z of R){if(z.role!=="assistant")continue;const B=Ze(z);for(const re of B){if(!re.id)continue;const ne=re.name==="web_search",Z=re.name==="web_fetch",ee=re.name==="exec";if(!ne&&!Z&&!ee)continue;const Q=F.get(re.id);if(!Q)continue;const le=Q.content?.map(V=>V.type==="text"?String(V.text??""):"").join("").trim();if(le){if(ne||ee){if(ee&&(!le.includes('"results"')||!le.includes('"url"')))continue;let V=le;const se=le.indexOf("{");se>0&&(V=le.slice(se));const ce=V.lastIndexOf("}");ce>0&&(V=V.slice(0,ce+1)),S(V,N,P)}else if(Z){const V=re.arguments?.url;if(V&&!P.has(V)){P.add(V);let se;try{se=new URL(V).hostname}catch{se=V}N.push({title:se,url:V})}}}}}return N},[R,F]),D=R.map((C,S)=>({message:C,index:S})).filter(({message:C})=>C.role!=="user").map(({index:C})=>C).pop(),q=R.map((C,S)=>({message:C,index:S})).filter(({message:C})=>C.role==="assistant").map(({index:C})=>C).pop(),H=R.map((C,S)=>({message:C,index:S})).filter(({message:C})=>C.role==="user").map(({index:C})=>C).pop(),j=l&&(typeof H!="number"||typeof D!="number"||D<H),E=typeof H=="number"?H:-1,T=d&&E>=0,M=typeof q=="number"?R[q]:void 0,K=M?De(M):"",$=!l&&!c&&K.length>0&&g!==void 0&&(typeof H!="number"||typeof q!="number"||q>H);return o.useLayoutEffect(()=>{if(!t){if(d){const C=!x.current||A.current!==H;x.current=!0,A.current=H,C&&w.current&&(y.current=!0,w.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{y.current=!1},0));return}x.current=!1,A.current=H,h.current&&(y.current=!0,h.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{y.current=!1},0))}},[t,R.length,u,d,H]),o.useEffect(()=>{if(!b||t)return;const C=document.getElementById(`message-${b}`);if(!C)return;C.scrollIntoView({behavior:"smooth",block:"center"}),_(b);const S=window.setTimeout(()=>{_(N=>N===b?null:N)},1800);return()=>window.clearTimeout(S)},[b,t,R]),n.jsx(Pa,{className:"flex-1 min-h-0 -mb-4",children:n.jsxs(_a,{className:"pt-6",style:p,children:[a&&i==="start"?a:null,r&&!a?s??n.jsx("div",{"aria-hidden":!0}):T?n.jsxs(n.Fragment,{children:[R.slice(0,E).map((C,S)=>{const N=typeof C.id=="string"?C.id:void 0,P=N||S,z=typeof D=="number"&&S===D,B=typeof D=="number"&&S===D,re=C.role==="assistant"&&Ze(C).length>0;return n.jsx(Qt,{message:C,toolResultsByCallId:re?F:void 0,forceActionsVisible:z,isStreaming:B&&c,isLastAssistant:B,aggregatedSearchSources:B?G:void 0,messageDomId:N?`message-${N}`:void 0,highlighted:k===N},P)}),n.jsxs("div",{className:"flex flex-col gap-[var(--opencami-msg-gap)]",style:{minHeight:`${Math.max(0,f)}px`},children:[R.slice(E).map((C,S)=>{const N=E+S,P=typeof C.id=="string"?C.id:void 0,z=P||N,B=typeof D=="number"&&N===D,re=typeof D=="number"&&N===D,ne=N===H?w:void 0,Z=N===H?"scroll-mt-0":void 0,ee=N===H?m:void 0,Q=C.role==="assistant"&&Ze(C).length>0;return n.jsx(Qt,{message:C,toolResultsByCallId:Q?F:void 0,forceActionsVisible:B,isStreaming:re&&c,isLastAssistant:re,aggregatedSearchSources:re?G:void 0,wrapperRef:ne,wrapperClassName:Z,wrapperScrollMarginTop:ee,messageDomId:P?`message-${P}`:void 0,highlighted:k===P},z)}),j?n.jsx("div",{className:"py-2",children:n.jsx(Ua,{})}):null,$&&g?n.jsx(Gn,{responseText:K,onSuggestionClick:g,disabled:l}):null]})]}):n.jsxs(n.Fragment,{children:[R.map((C,S)=>{const N=typeof C.id=="string"?C.id:void 0,P=N||S,z=typeof D=="number"&&S===D,B=typeof D=="number"&&S===D,re=C.role==="assistant"&&Ze(C).length>0;return n.jsx(Qt,{message:C,toolResultsByCallId:re?F:void 0,forceActionsVisible:z,isStreaming:B&&c,isLastAssistant:B,aggregatedSearchSources:B?G:void 0,messageDomId:N?`message-${N}`:void 0,highlighted:k===N},P)}),$&&g?n.jsx(Gn,{responseText:K,onSuggestionClick:g,disabled:l}):null]}),a&&i==="end"?a:null,n.jsx(Ka,{ref:h})]})})}function Fa(e,t){return e.messages===t.messages&&e.loading===t.loading&&e.empty===t.empty&&e.emptyState===t.emptyState&&e.notice===t.notice&&e.noticePosition===t.noticePosition&&e.waitingForResponse===t.waitingForResponse&&e.isStreaming===t.isStreaming&&e.sessionKey===t.sessionKey&&e.pinToTop===t.pinToTop&&e.pinGroupMinHeight===t.pinGroupMinHeight&&e.headerHeight===t.headerHeight&&e.contentStyle===t.contentStyle&&e.onFollowUpClick===t.onFollowUpClick&&e.jumpToMessageId===t.jumpToMessageId}const Ha=o.memo($a,Fa),Lr=o.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:ss.createRef()});let lt=null,qn=!1;function Wa(){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||!lt||lt.disabled||lt.focus()}))}function Pr(){return o.useContext(Lr)}function Xa({className:e,isLoading:t=!1,maxHeight:r=240,value:s,onValueChange:a,onSubmit:i,children:l,disabled:c=!1,onClick:u,...d}){const[f,m]=o.useState(s||""),p=o.useRef(null);Wa();function g(h){m(h),a?.(h)}function b(h){c||p.current?.focus(),u?.(h)}return n.jsx(Te,{children:n.jsx(Lr.Provider,{value:{isLoading:t,value:s??f,setValue:a??g,maxHeight:r,onSubmit:i,disabled:c,textareaRef:p},children:n.jsx("div",{onClick:b,className:I("bg-surface cursor-text rounded-[22px] outline outline-ink/10 shadow-[0px_12px_32px_0px_rgba(0,0,0,0.05)] py-3 gap-3 flex flex-col",c&&"cursor-not-allowed opacity-60",e),...d,children:l})})})}function Ya({className:e,onKeyDown:t,disableAutosize:r=!1,inputRef:s,...a}){const{value:i,setValue:l,maxHeight:c,onSubmit:u,disabled:d,textareaRef:f}=Pr();function m(h){!h||r||(h.style.height="auto",typeof c=="number"?h.style.height=`${Math.min(h.scrollHeight,c)}px`:h.style.height=`min(${h.scrollHeight}px, ${c})`)}function p(h){f.current=h,typeof s=="function"?s(h):s&&"current"in s&&(s.current=h),h?lt=h:lt===h&&(lt=null),m(h)}o.useLayoutEffect(()=>{if(!f.current||r)return;const h=f.current;h.style.height="auto",typeof c=="number"?h.style.height=`${Math.min(h.scrollHeight,c)}px`:h.style.height=`min(${h.scrollHeight}px, ${c})`},[i,c,r]);function g(h){m(h.target),l(h.target.value)}function b(h){h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),u?.()),t?.(h)}return n.jsx("textarea",{ref:p,value:i,onChange:g,onKeyDown:b,className:I("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 Ba({children:e,className:t,...r}){return n.jsx("div",{className:I("flex items-center gap-2",t),...r,children:e})}function Vn({tooltip:e,children:t,className:r,side:s="top",...a}){const{disabled:i}=Pr();return n.jsxs(Re,{...a,children:[n.jsx(Me,{disabled:i,onClick:l=>l.stopPropagation(),children:t}),n.jsx(Ae,{side:s,className:r,children:e})]})}const _r="opencami-selected-model";function Ga(){if(typeof window>"u")return null;try{return localStorage.getItem(_r)}catch{return null}}function qa(e){if(!(typeof window>"u"))try{localStorage.setItem(_r,e)}catch{}}function Va({className:e,onModelChange:t}){const[r,s]=o.useState([]),[a,i]=o.useState(""),[l,c]=o.useState(!0),[u,d]=o.useState(null),f=o.useRef(null);o.useEffect(()=>{let h=!0;async function w(){f.current?.abort();const y=new AbortController;f.current=y;try{c(!0),d(null);const x=await fetch("/api/models",{signal:y.signal});if(!x.ok)throw new Error("Failed to fetch models");const A=await x.json();if(!h)return;if(A.ok&&A.models.length>0){s(A.models);const k=Ga(),_=k&&A.models.some(R=>R.id===k)?k:A.defaultModel;i(_),t?.(_)}else throw new Error("No models available")}catch(x){if(x instanceof Error&&x.name==="AbortError"||!h)return;console.error("[model-selector] Error fetching models:",x),d(x instanceof Error?x.message:"Failed to load models"),s([{id:"default",name:"Default Model"}]),i("default")}finally{h&&c(!1)}}return w(),()=>{h=!1,f.current?.abort()}},[t]);function m(h){i(h),qa(h),t?.(h)}if(l)return n.jsxs("div",{className:I("flex items-center gap-2 text-xs text-primary-500",e),children:[n.jsx(Y,{icon:Xt,size:14}),n.jsx("span",{children:"Loading..."})]});if(u||r.length===0)return null;const p=r.find(h=>h.id===a),g=p?.name||"Select Model",b=(()=>{if(!p?.name)return g;const w=p.name.replace(/\s*\([^)]*\)\s*$/,"").trim(),y=w.split(/\s+/);return y.length>3?y.slice(0,3).join(" "):w})();return r.length===1?n.jsxs("div",{className:I("flex items-center gap-2 text-xs text-primary-500",e),children:[n.jsx(Y,{icon:Xt,size:14}),n.jsx("span",{className:"font-[450] md:hidden",children:b}),n.jsx("span",{className:"font-[450] hidden md:inline",children:g})]}):n.jsxs(Ut,{children:[n.jsxs($t,{className:I("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(Y,{icon:Xt,size:14}),n.jsx("span",{className:"md:hidden",children:b}),n.jsx("span",{className:"hidden md:inline",children:g})]}),n.jsx(Ft,{side:"top",align:"start",children:r.map(h=>n.jsxs(Ye,{onClick:()=>m(h.id),className:"justify-between min-w-[180px]",children:[n.jsx("span",{children:h.name}),a===h.id&&n.jsx(Y,{icon:mn,size:14,className:"text-primary-600"})]},h.id))})]})}const Kr="opencami-personas-enabled",cn="opencami-active-persona";function Ja(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(Kr);return e===null?!0:e==="true"}catch{return!0}}function Qa(){if(typeof window>"u")return null;try{const e=localStorage.getItem(cn);return e?JSON.parse(e):null}catch{return null}}function Jn(e){if(!(typeof window>"u"))try{e?localStorage.setItem(cn,JSON.stringify(e)):localStorage.removeItem(cn)}catch{}}const Za={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function el({className:e,onSelect:t}){const[r,s]=o.useState({}),[a,i]=o.useState(null),[l,c]=o.useState(!0),[u,d]=o.useState(!1),[f,m]=o.useState(Ja),p=o.useRef(null);o.useEffect(()=>{const w=y=>{y.key===Kr&&m(y.newValue===null?!0:y.newValue==="true")};return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[]),o.useEffect(()=>{let w=!0;async function y(){p.current?.abort();const x=new AbortController;p.current=x;try{c(!0);const A=await fetch("/api/personas",{signal:x.signal});if(!A.ok){d(!1);return}const k=await A.json();if(!w)return;k.ok&&k.available?(s(k.personas),d(!0),i(Qa())):d(!1)}catch(A){if(A instanceof Error&&A.name==="AbortError"||!w)return;d(!1)}finally{w&&c(!1)}}return y(),()=>{w=!1,p.current?.abort()}},[]);const g=o.useCallback(w=>{i(w),Jn(w),t(`/persona ${w.id}`)},[t]),b=o.useCallback(()=>{i(null),Jn(null),t("/persona exit")},[t]);if(l||!u||!f)return null;const h=Object.entries(r);return h.length===0?null:n.jsxs(Ut,{children:[n.jsxs($t,{className:I("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(Ft,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[a&&n.jsxs(n.Fragment,{children:[n.jsxs(Ye,{onClick:b,className:"text-red-600 hover:bg-red-50",children:[n.jsx("span",{className:"text-sm",children:"✕"}),n.jsx("span",{children:"Exit Persona"}),n.jsxs("span",{className:"ml-auto text-[10px] text-primary-400",children:[a.emoji," ",a.name]})]}),n.jsx("div",{className:"my-1 h-px bg-primary-200"})]}),h.map(([w,y])=>n.jsxs("div",{children:[n.jsx("div",{className:"px-2 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-primary-400",children:Za[w]??w}),y.map(x=>n.jsxs(Ye,{onClick:()=>g(x),className:"justify-between",children:[n.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:"text-sm flex-shrink-0",children:x.emoji}),n.jsx("span",{className:"truncate",children:x.name})]}),n.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:x.description})]},x.id))]},w))]})]})}const tl=[{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 nl({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(ye,{variant:"ghost",size:"sm",onClick:()=>s(!0),className:I("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:n.jsx(Y,{icon:En,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(Y,{icon:En,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(ye,{variant:"ghost",size:"sm",onClick:()=>s(!1),className:"h-7 w-7 p-0",children:n.jsx(Y,{icon:zt,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"}),tl.map(i=>n.jsxs("button",{onClick:()=>a(i.command),className:"w-full flex items-start gap-3 px-3 py-2 rounded-lg hover:bg-primary-100 dark:hover:bg-neutral-800 transition-colors text-left",children:[n.jsx("code",{className:"text-sm font-mono font-medium text-primary-700 dark:text-primary-300 bg-primary-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded min-w-[80px]",children:i.command}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm text-primary-900 dark:text-neutral-100",children:i.description}),i.usage&&i.usage!==i.command&&n.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-500 font-mono mt-0.5",children:i.usage})]})]},i.command))]}),n.jsx("div",{className:"px-4 py-2 border-t border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:n.jsxs("div",{className:"text-xs text-primary-500 dark:text-neutral-400",children:["Press ",n.jsx("kbd",{className:"px-1 py-0.5 bg-primary-200 dark:bg-neutral-700 rounded text-primary-700 dark:text-neutral-300",children:"Esc"})," to close"]})})]})})]})}const rl=10*1024*1024,ot=1280,sl=.75,ol=300*1024,il=["image/png","image/jpeg","image/gif","image/webp"],zr=["pdf","txt","md","csv","json","xml","yaml","yml","log","py","js","ts","html","css"],al=[".png",".jpg",".jpeg",".gif",".webp",...zr.map(e=>`.${e}`)].join(",");function ll(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function cl(e){if(!ll())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>ot||c>ot)&&(l>c?(c=Math.round(c*ot/l),l=ot):(l=Math.round(l*ot/c),c=ot));const u=document.createElement("canvas");u.width=l,u.height=c;const d=u.getContext("2d");if(!d){i(),r(new Error("Failed to get canvas context"));return}d.drawImage(s,0,0,l,c);const f=e.type==="image/png"?"image/png":"image/jpeg";let m=sl,p=u.toDataURL(f,m);if(f==="image/jpeg"){const b=ol*1.37;for(;p.length>b&&m>.3;)m-=.1,p=u.toDataURL(f,m)}const g=p.split(",")[1];if(!g){i(),r(new Error("Failed to encode image"));return}i(),t(g)}catch(l){i(),r(l instanceof Error?l:new Error("Image compression failed"))}},s.onerror=()=>{i(),r(new Error("Failed to load image"))},s.src=a})}function Ur(e){return il.includes(e.type)}function ul(e){const t=e.name.includes(".")?e.name.split(".").pop()?.toLowerCase():"";return!!(t&&zr.includes(t))}async function dl(e){const t=crypto.randomUUID();if(!Ur(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>rl)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const r=await cl(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 fl({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:al,multiple:!0,onChange:i,className:"hidden","aria-hidden":"true"}),n.jsx(ye,{variant:"ghost",size:"icon-sm",onClick:a,disabled:t,className:r,"aria-label":"Attach file",type:"button",children:n.jsx(Y,{icon:Cs,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 ml(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function pl({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:I("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:I("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(Y,{icon:ar,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:[ml(e.file.name)," •"," ",Qn(e.file.size)]})]}),n.jsx(ye,{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(Y,{icon:zt,size:14})})]})}function hl({attachments:e,onRemove:t,className:r}){return e.length===0?null:n.jsx("div",{className:I("flex flex-wrap gap-2 px-4",r),children:e.map(s=>n.jsx(pl,{attachment:s,onRemove:t},s.id))})}function gl({commands:e,selectedIndex:t,onSelect:r,className:s}){return e.length===0?null:n.jsx("div",{className:I("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:I("w-full rounded-md px-3 py-2 text-left transition-colors",l?"bg-neutral-800":"hover:bg-neutral-800/80"),children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("code",{className:"min-w-[90px] font-mono text-xs text-primary-300",children:a.command}),n.jsx("span",{className:"text-xs text-neutral-300",children:a.description})]})},a.command)})})})}const xl=o.memo(gl),un=hr()(pr(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function yl(){const e=un(r=>r.level),t=un(r=>r.setLevel);return{level:e,setLevel:t}}const Zt=[{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 wl({className:e}){const{level:t,setLevel:r}=yl(),s=Zt.find(a=>a.value===t)??Zt[1];return n.jsxs(Ut,{children:[n.jsxs($t,{className:I("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(Y,{icon:nn,size:20,strokeWidth:1.5,className:I(t==="off"?"text-primary-400":"text-primary-700")}),n.jsx("span",{className:"text-pretty",children:s.shortLabel})]}),n.jsx(Ft,{side:"top",align:"start",className:"min-w-[190px]",children:Zt.map(a=>n.jsxs(Ye,{onClick:()=>r(a.value),className:"justify-between",children:[n.jsxs("span",{className:"flex flex-col text-pretty",children:[n.jsx("span",{className:"text-sm text-primary-900",children:a.label}),n.jsx("span",{className:"text-xs text-primary-500",children:a.description})]}),t===a.value&&n.jsx(Y,{icon:mn,size:20,strokeWidth:1.5,className:"text-primary-600"})]},a.value))})]})}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 bl({onSubmit:e,isLoading:t,disabled:r,wrapperRef:s,inputRef:a}){const[i,l]=o.useState(""),[c,u]=o.useState(""),[d,f]=o.useState([]),[m,p]=o.useState(0),[g,b]=o.useState(!1),[h,w]=o.useState(!1),[y,x]=o.useState(!1),[A,k]=o.useState(0),[_,R]=o.useState(!1),F=o.useRef(null),G=o.useRef([]),D=o.useRef(null),q=o.useRef(null),H=o.useRef(null),j=o.useRef(null),E=o.useMemo(()=>/^\/\S*$/.test(i)&&!g,[i,g]),T=o.useMemo(()=>E?i.slice(1).toLowerCase():"",[E,i]),M=o.useMemo(()=>E?T?Zn.filter(L=>L.command.slice(1).toLowerCase().startsWith(T)):Zn:[],[E,T]),K=o.useCallback(L=>{j.current=L,a&&(typeof a=="function"?a(L):a.current=L)},[a]),$=o.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{j.current?.focus()})},[]),C=o.useCallback(()=>{l(""),f([]),p(0),b(!1),$()},[$]),S=o.useCallback(L=>{l(W=>{const X=`📎 Uploaded file: ${L}
|
|
20
|
-
|
|
21
|
-
Please analyze this file.`;return W.trim()?`${W.trim()}
|
|
22
|
-
|
|
23
|
-
${X}`:X})},[]),N=o.useCallback(async()=>{await fetch("/api/files/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:"/uploads"})})},[]),P=o.useCallback(async L=>{const W=crypto.randomUUID();if(!ul(L))return{id:W,file:L,preview:null,type:"file",base64:null,error:"Unsupported file type for upload."};try{await N();const X=new FormData;X.append("path","/uploads"),X.append("file",L);const oe=await fetch("/api/files/upload",{method:"POST",body:X});if(!oe.ok){const Se=await oe.text();throw new Error(Se||"File upload failed")}const te=(await oe.json()).files?.[0]?.path;if(!te)throw new Error("Upload succeeded but no path was returned");return S(te),{id:W,file:L,preview:null,type:"file",base64:null,uploadedPath:te}}catch(X){return{id:W,file:L,preview:null,type:"file",base64:null,error:X instanceof Error?X.message:"File upload failed"}}},[S,N]),z=o.useCallback(async L=>{if(L.length===0)return;const W=await Promise.all(L.map(X=>Ur(X)?dl(X):P(X)));f(X=>[...X,...W]),$()},[$,P]),B=o.useCallback(L=>{f(W=>W.filter(X=>X.id!==L))},[]),re=o.useCallback(L=>{Array.from(L.dataTransfer.types).includes("Files")&&(L.preventDefault(),L.dataTransfer.dropEffect="copy",w(!0))},[]),ne=o.useCallback(L=>{L.preventDefault();const W=L.relatedTarget;W&&L.currentTarget.contains(W)||w(!1)},[]),Z=o.useCallback(async L=>{L.preventDefault(),w(!1);const W=Array.from(L.dataTransfer.files??[]);W.length!==0&&await z(W)},[z]),ee=o.useCallback(L=>{l(L),p(0),b(!1),$()},[$]),Q=o.useCallback(L=>{l(L),p(0),b(!1)},[]),le=o.useCallback(L=>{l(`${L.command} `),p(0),b(!1),$()},[$]),V=o.useCallback(()=>{if(r)return;if(E&&M.length>0){const X=Math.min(m,M.length-1);le(M[X]);return}const L=i.trim(),W=d.filter(X=>!X.error&&X.base64);L.length===0&&W.length===0||(e(L,{reset:C,setValue:ee,model:c||void 0,attachments:W}),$())},[r,E,M,m,le,i,d,e,C,ee,c,$]),se=o.useCallback(L=>{e(L,{reset:C,setValue:ee,model:c||void 0,attachments:[]}),$()},[$,e,C,ee,c]),ce=o.useCallback(L=>{if(E){if(L.key==="Escape"){L.preventDefault(),b(!0),p(0);return}if(M.length!==0){if(L.key==="ArrowDown"){L.preventDefault(),p(W=>(W+1)%M.length);return}if(L.key==="ArrowUp"){L.preventDefault(),p(W=>(W-1+M.length)%M.length);return}if(L.key==="Tab"){L.preventDefault();const W=Math.min(m,M.length-1);le(M[W])}}}},[E,M,m,le]);o.useEffect(()=>()=>{q.current?.abort(),D.current&&clearInterval(D.current),F.current&&F.current.state!=="inactive"&&F.current.stop(),H.current&&H.current.abort()},[]);const be=o.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),me=o.useCallback(()=>{F.current&&F.current.state!=="inactive"&&F.current.stop(),H.current&&H.current.stop(),D.current&&(clearInterval(D.current),D.current=null),x(!1),k(0)},[]),ge=o.useCallback(async()=>{const L=be();if(L==="browser"){const W=window.SpeechRecognition||window.webkitSpeechRecognition;if(!W){alert("Web Speech API is not supported in this browser.");return}const X=new W;X.continuous=!0,X.interimResults=!1,X.lang=navigator.language||"en-US",H.current=X,x(!0),k(0),D.current=setInterval(()=>{k(ie=>ie>=119?(me(),0):ie+1)},1e3);let oe="";X.onresult=ie=>{for(let te=ie.resultIndex;te<ie.results.length;te++)ie.results[te].isFinal&&(oe+=ie.results[te][0].transcript)},X.onend=()=>{x(!1),k(0),D.current&&clearInterval(D.current),oe.trim()&&(l(ie=>ie+(ie?" ":"")+oe.trim()),$())},X.onerror=()=>{x(!1),k(0),D.current&&clearInterval(D.current)},X.start();return}try{const W=await navigator.mediaDevices.getUserMedia({audio:!0}),X=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",oe=new MediaRecorder(W,{mimeType:X});F.current=oe,G.current=[],oe.ondataavailable=ie=>{ie.data.size>0&&G.current.push(ie.data)},oe.onstop=async()=>{W.getTracks().forEach(te=>te.stop());const ie=new Blob(G.current,{type:X});if(ie.size!==0){R(!0);try{const te=new FormData;te.append("audio",ie,`recording.${X==="audio/webm"?"webm":"mp4"}`),L!=="auto"&&te.append("provider",L),q.current?.abort();const Se=new AbortController;q.current=Se;const xe=await(await fetch("/api/stt",{method:"POST",body:te,signal:Se.signal})).json();xe.ok&&xe.text?(l(Le=>Le+(Le?" ":"")+xe.text),$()):xe.ok||(console.warn("STT failed:",xe.error),alert(xe.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(te){if(te instanceof Error&&te.name==="AbortError")return;console.warn("STT request failed:",te),alert("Could not reach speech-to-text service.")}finally{R(!1)}}},x(!0),k(0),D.current=setInterval(()=>{k(ie=>ie>=119?(me(),0):ie+1)},1e3),oe.start()}catch(W){const X=W instanceof Error?W.message:String(W);if(X.includes("NotAllowedError")||X.includes("Permission"))try{(await navigator.permissions.query({name:"microphone"})).state==="denied"?alert("Microphone access is blocked. Please enable it in your browser/app settings."):alert("Microphone permission was not granted. Please try again and allow access when prompted.")}catch{alert("Could not access microphone. Please check your browser settings and allow microphone access for this site.")}else alert("Could not access microphone: "+X)}},[be,me,$]),pe=o.useCallback(()=>{y?me():ge()},[y,me,ge]),O=d.filter(L=>!L.error&&L.base64),fe=r||i.trim().length===0&&O.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:re,onDragLeave:ne,onDrop:Z,children:[h&&n.jsx("div",{className:"pointer-events-none absolute inset-2 z-20 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary-400 bg-primary-50/90 text-sm font-medium text-primary-700",children:"Drop files here"}),n.jsxs(Xa,{value:i,onValueChange:Q,onSubmit:V,isLoading:t,disabled:r,children:[n.jsx(hl,{attachments:d,onRemove:B}),E&&M.length>0&&n.jsx(xl,{commands:M,selectedIndex:Math.min(m,M.length-1),onSelect:le}),n.jsx(Ya,{placeholder:"Type a message…",inputRef:K,onKeyDown:ce}),n.jsxs(Ba,{className:"justify-between px-3",children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(Va,{onModelChange:u}),n.jsx(wl,{}),n.jsx(el,{onSelect:se}),n.jsx(nl,{onCommandSelect:L=>Q(L+" ")})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(fl,{onFilesSelect:z,disabled:r}),n.jsx(Vn,{tooltip:y?"Stop recording":"Voice input",children:n.jsx(ye,{onClick:pe,disabled:r||_,size:"icon-sm",variant:y?"destructive":"ghost",className:`rounded-full ${y?"animate-pulse":""}`,"aria-label":y?"Stop recording":"Voice input",children:_?n.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):y?n.jsxs("span",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"size-2 rounded-full bg-red-500"}),n.jsxs("span",{className:"text-xs tabular-nums",children:[Math.floor(A/60),":",String(A%60).padStart(2,"0")]}),n.jsx(Y,{icon:or,size:14,strokeWidth:2})]}):n.jsx(Y,{icon:Es,size:18,strokeWidth:2})})}),n.jsx(Vn,{tooltip:"Send message",children:n.jsx(ye,{onClick:V,disabled:fe,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:n.jsx(Y,{icon:Ts,size:18,strokeWidth:2})})})]})]})]})]})}const Sl=o.memo(bl);function vl({title:e,description:t,detail:r,actionLabel:s,onAction:a,className:i}){return n.jsx("div",{className:I("w-full max-w-[var(--opencami-chat-width)]",i),children:n.jsx(Ar,{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(ye,{size:"sm",variant:"outline",onClick:a,children:s})}):null]})})})}function jl({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(vl,{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 Nl(){const e=o.useRef(null),t=o.useRef(null),r=o.useRef(null),[s,a]=o.useState(0),[i,l]=o.useState(0);return o.useLayoutEffect(()=>{const c=e.current,u=t.current,d=r.current;if(!d)return;const f=()=>{const p=c?.offsetHeight??0,g=u?.offsetHeight??0,b=d.clientHeight;d.style.setProperty("--chat-header-height",`${Math.max(0,p)}px`),d.style.setProperty("--chat-composer-height",`${Math.max(0,g)}px`),l(p),a(Math.max(0,b-p-g))};f();const m=new ResizeObserver(()=>f());return c&&m.observe(c),u&&m.observe(u),()=>m.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:r,pinGroupMinHeight:s,headerHeight:i}}function kl({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:r,isNewChat:s,isRedirecting:a,activeExists:i,sessionsReady:l,queryClient:c}){const u=r||t||e,d=de.history(e,u),f=Rt({queryKey:d,queryFn:async function(){const x=c.getQueryData(d),A=Array.isArray(x?.messages)?x.messages.filter(R=>R.status==="sending"||R.__optimisticId?!0:!!R.clientId):[],k=await ho({sessionKey:u,friendlyId:e});if(!A.length)return k;const _=Cl(k.messages,A);return{...k,messages:_}},enabled:!s&&!!e&&!a&&(!l||i),placeholderData:function(){return c.getQueryData(d)},gcTime:1e3*60*10}),m=o.useRef(""),p=o.useRef([]),g=o.useMemo(()=>{const y=Array.isArray(f.data?.messages)?f.data.messages:[],x=y[y.length-1],A=x&&typeof x.id=="string"?x.id:"",k=`${y.length}:${x?.role??""}:${A}:${De(x??{content:[]}).slice(-32)}`;return k===m.current?p.current:(m.current=k,p.current=y,y)},[f.data?.messages]),b=f.error instanceof Error?f.error.message:null,h=o.useMemo(()=>{if(r)return r;const y=f.data?.sessionKey;return typeof y=="string"&&y.trim().length>0?y.trim():t},[t,r,f.data?.sessionKey]);return{historyQuery:f,historyMessages:g,displayMessages:g,historyError:b,resolvedSessionKey:h,activeCanonicalKey:s?"new":h||e,sessionKeyForHistory:u}}function Cl(e,t){if(!t.length)return e;const r=[...e];for(const s of t)e.some(i=>{if(s.clientId&&i.clientId&&s.clientId===i.clientId||s.__optimisticId&&i.__optimisticId&&s.__optimisticId===i.__optimisticId)return!0;if(s.role&&i.role&&s.role!==i.role)return!1;const l=De(s);if(!l||l!==De(i))return!1;const c=sn(s),u=sn(i);return Math.abs(c-u)<=1e4})||r.push(s);return r}function El(e){const[t,r]=o.useState(!1);return o.useLayoutEffect(()=>{const s=window.matchMedia("(max-width: 768px)"),a=()=>r(s.matches);return a(),s.addEventListener("change",a),()=>s.removeEventListener("change",a)},[]),o.useLayoutEffect(()=>{t&&We(e,function(a){return{...a,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function Tl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}){const s=Rt({queryKey:de.sessions,queryFn:po,refetchInterval:3e4}),a=o.useMemo(()=>{const m=s.data??[];return Ao(m)},[s.data]),i=o.useMemo(()=>a.find(m=>m.friendlyId===e),[a,e]),l=o.useMemo(()=>t||r||xr(e)?!0:a.some(m=>m.friendlyId===e),[e,r,t,a]),c=i?.key??"",u=o.useMemo(()=>i?i.label||i.title||i.derivedTitle||i.friendlyId:e,[e,i]),d=s.error instanceof Error?s.error.message:null,f=o.useMemo(()=>({totalTokens:i?.totalTokens,contextTokens:i?.contextTokens}),[i?.totalTokens,i?.contextTokens]);return{sessionsQuery:s,sessions:a,activeSession:i,activeExists:l,activeSessionKey:c,activeTitle:u,activeTokens:f,sessionsError:d}}function Rl(){const e=et(d=>d.settings),[t,r]=o.useState(!1),[s,a]=o.useState(null),[i,l]=o.useState(null),c=o.useRef(null);return{generateTitle:o.useCallback(async d=>{c.current&&c.current.abort();const f=new AbortController;c.current=f,r(!0);try{const m={"Content-Type":"application/json",...Or()},p=await fetch("/api/llm-features",{method:"POST",headers:m,body:JSON.stringify({action:"title",message:d}),signal:f.signal});if(!p.ok)throw new Error(`API error: ${p.status}`);const g=await p.json();if(f.signal.aborted)throw new Error("Aborted");const b=g.title||d.slice(0,50),h=b.length>64?b.slice(0,61)+"...":b,w=g.source||"heuristic";return a(h),l(w),{title:h,source:w,error:g.error}}catch(m){if(m instanceof Error&&m.name==="AbortError")throw m;const p=Ml(d);return a(p),l("heuristic"),{title:p,source:"heuristic",error:m instanceof Error?m.message:"Unknown error"}}finally{r(!1),c.current===f&&(c.current=null)}},[e.llmApiKey,e.llmBaseUrl,e.llmModel,e.llmProvider]),isGenerating:t,lastTitle:s,lastSource:i}}function Ml(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 Al(){return et(e=>e.settings.useLlmTitles)}const en={active:!1,text:"",tools:[],sessionKey:null};function Il(e){const[t,r]=o.useState(en),s=o.useRef(null),a=o.useRef(null),i=o.useRef(null),l=o.useRef(null),c=o.useRef(!1),u=o.useRef(e.onDone),d=o.useRef(e.onError),f=o.useRef(e.onAssistantDelta);u.current=e.onDone,d.current=e.onError,f.current=e.onAssistantDelta;function m(){i.current&&(window.clearTimeout(i.current),i.current=null),a.current&&(window.clearInterval(a.current),a.current=null)}function p(h,w){a.current||(a.current=window.setInterval(async()=>{try{const y=await fetch(`/api/history?sessionKey=${encodeURIComponent(h)}`);if(!y.ok)return;const x=await y.json();if(!(Array.isArray(x.messages)?x.messages:[]).some(_=>!_||_.role!=="assistant"||typeof _.timestamp!="number"?!1:_.timestamp>w-3e3))return;s.current&&(s.current.close(),s.current=null),m(),r(_=>({..._,active:!1})),u.current(h)}catch{}},2e3))}const g=o.useCallback(h=>{if(c.current=!0,m(),s.current&&(s.current.close(),s.current=null),h?.preserveState){r(w=>({...w,active:!1}));return}r(en)},[]),b=o.useCallback(function(w){c.current=!1,m(),l.current=Date.now(),s.current&&(s.current.close(),s.current=null),r({active:!0,text:"",tools:[],sessionKey:w});const y=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(w)}`);s.current=y,y.addEventListener("delta",x=>{try{const A=JSON.parse(x.data);r(k=>({...k,text:k.text+A.text})),f.current?.({text:A.text,sessionKey:A.sessionKey})}catch{}}),y.addEventListener("tool",x=>{try{const A=JSON.parse(x.data);r(k=>{const _=k.tools.findIndex(F=>F.id===A.id),R=[...k.tools];return _>=0?R[_]={name:A.name,status:A.status,id:A.id}:R.push({name:A.name,status:A.status,id:A.id}),{...k,tools:R}})}catch{}}),y.addEventListener("done",x=>{try{const A=JSON.parse(x.data);c.current=!0,m(),y.close(),s.current=null,r(k=>({...k,active:!1})),u.current(A.sessionKey)}catch{}}),y.onerror=()=>{y.readyState===EventSource.CLOSED&&(y.close(),s.current=null,r(en),d.current?.("Stream connection lost"))},i.current=window.setTimeout(()=>{if(c.current)return;const x=l.current??Date.now();p(w,x)},3e3)},[]);return{streaming:t,startStream:b,stopStream:g}}function Dl(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 er(e){const{threshold:t=50,edgeWidth:r,onMove:s,onSwipe:a,onCancel:i,direction:l,enabled:c=!0}=e,u=o.useRef({startX:0,startY:0,tracking:!1,directionLocked:!1}),d=o.useCallback(p=>{if(!c)return;const g=p.touches[0];g&&(r!==void 0&&g.clientX>r||(u.current={startX:g.clientX,startY:g.clientY,tracking:!0,directionLocked:!1}))},[c,r]),f=o.useCallback(p=>{const g=u.current;if(!g.tracking)return;const b=p.touches[0];if(!b)return;const h=b.clientX-g.startX,w=b.clientY-g.startY,y=Math.abs(h),x=Math.abs(w);if(!g.directionLocked){if(y<5&&x<5)return;if(x>y){g.tracking=!1,i?.();return}g.directionLocked=!0}l==="left"&&h>0||l==="right"&&h<0||(p.preventDefault(),s?.(h))},[l,s,i]),m=o.useCallback(p=>{const g=u.current;if(!g.tracking)return;g.tracking=!1;const b=p.changedTouches[0];if(!b){i?.();return}const h=b.clientX-g.startX,w=Math.abs(h);if(!g.directionLocked||w<t){i?.();return}const y=h>0?"right":"left";if(l&&y!==l){i?.();return}a(y)},[l,i,a,t]);return{onTouchStart:d,onTouchMove:f,onTouchEnd:m}}const $r="opencami-browser-notifications-enabled",tn="opencami-browser-notifications-permission-asked",Ol=5e3;function Nt(){return typeof window<"u"&&"Notification"in window}function tr(){if(typeof window>"u")return!1;try{return localStorage.getItem($r)==="true"}catch{return!1}}function Ll(){const e=Kt(),t=o.useRef(0),[r,s]=o.useState(()=>tr()),a=o.useCallback(async()=>{if(!Nt())return"denied";try{return await Notification.requestPermission()}catch{return"denied"}},[]),i=o.useCallback(async c=>{s(c);try{localStorage.setItem($r,String(c))}catch{}if(c&&Nt()&&Notification.permission==="default"){await a();try{localStorage.setItem(tn,"true")}catch{}}},[a]),l=o.useCallback(c=>{if(!r||!Nt()||document.hidden!==!0||Notification.permission!=="granted")return;const u=Date.now();if(u-t.current<Ol)return;t.current=u;const d=c.text.slice(0,100),f=new Notification("OpenCami",{body:d,icon:"/pwa-192x192.png"});f.onclick=()=>{window.focus(),e({to:"/chat/$sessionKey",params:{sessionKey:c.sessionFriendlyId}}),f.close()}},[r,e]);return o.useEffect(()=>{if(!Nt())return;const c=()=>{if(Notification.permission!=="default")return;let d=!1;try{d=localStorage.getItem(tn)==="true"}catch{d=!1}d||a().finally(()=>{try{localStorage.setItem(tn,"true")}catch{}})},u={once:!0,passive:!0};return window.addEventListener("pointerdown",c,u),window.addEventListener("keydown",c,{once:!0}),()=>{window.removeEventListener("pointerdown",c),window.removeEventListener("keydown",c)}},[a]),o.useEffect(()=>{const c=()=>s(tr());return window.addEventListener("storage",c),()=>window.removeEventListener("storage",c)},[]),{notificationsEnabled:r,setNotificationsEnabled:i,requestNotificationPermission:a,maybeNotifyAssistantMessage:l}}const Pl=o.lazy(()=>_t(()=>import("./keyboard-shortcuts-dialog-Bb_GOr9L.js"),__vite__mapDeps([26,1,4,3,5,6,7,8,9,2])).then(e=>({default:e.KeyboardShortcutsDialog}))),_l=o.lazy(()=>_t(()=>import("./search-dialog-yB4w5ajo.js"),__vite__mapDeps([27,1,3,4,5,6,7,8,9,2,17,18,14,19,11,15,20,13,21,22,23,16,24])).then(e=>({default:e.SearchDialog}))),kt="opencami-search-jump-target";function Kl({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:r,forcedSessionKey:s}){const a=Kt(),i=ct(),[l,c]=o.useState(!1),[u,d]=o.useState(!1),[f,m]=o.useState(null),[p,g]=o.useState(!1),{headerRef:b,composerRef:h,mainRef:w,pinGroupMinHeight:y,headerHeight:x}=Nl(),[A,k]=o.useState(()=>Bt()||Gt()),[_,R]=o.useState(()=>Bt()||Gt()),[F,G]=o.useState(!1),[D,q]=o.useState(!1),[H,j]=o.useState("global"),[E,T]=o.useState(null),[M,K]=o.useState(!1),$=un(v=>v.level),{maybeNotifyAssistantMessage:C}=Ll(),S=o.useRef(null),N=o.useRef(null),P=o.useRef(null),z=o.useRef(""),B=o.useRef(()=>{}),re=o.useRef(!1),ne=o.useRef(""),{isMobile:Z}=El(i),{sessionsQuery:ee,sessions:Q,activeExists:le,activeSessionKey:V,activeTitle:se,activeTokens:ce,sessionsError:be}=Tl({activeFriendlyId:e,isNewChat:t,forcedSessionKey:s}),{historyQuery:me,historyMessages:ge,displayMessages:pe,historyError:O,resolvedSessionKey:fe,activeCanonicalKey:L,sessionKeyForHistory:W}=kl({activeFriendlyId:e,activeSessionKey:V,forcedSessionKey:s,isNewChat:t,isRedirecting:p,activeExists:le,sessionsReady:ee.isSuccess,queryClient:i}),X=Rt({queryKey:is,queryFn:function(){return Cn(i)},initialData:function(){return Cn(i)},staleTime:1/0}),oe=Rt({queryKey:["gateway","status"],queryFn:go,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:"always"}),ie=o.useRef(Date.now()),te=oe.error instanceof Error?oe.error.message:oe.data&&!oe.data.ok?oe.data.error||"Gateway unavailable":null,Se=te??be??O,Oe=o.useCallback(()=>{oe.refetch()},[oe]),xe=X.data?.isSidebarCollapsed??!1,Le=er({enabled:Z&&xe,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{We(i,v=>({...v,isSidebarCollapsed:!1}))}}),ut=er({enabled:Z&&!xe,threshold:50,direction:"left",onSwipe:()=>{We(i,v=>({...v,isSidebarCollapsed:!0}))}}),xt=o.useCallback(()=>{m(null),g(!0),a({to:"/new",replace:!0})},[a]),qe=o.useCallback(()=>{N.current&&(window.clearInterval(N.current),N.current=null),P.current&&(window.clearTimeout(P.current),P.current=null)},[]),Ve=o.useCallback(()=>{qe(),ht(!1),k(!1),K(!1)},[qe]),dt=Al(),{generateTitle:ft}=Rl(),yt=o.useRef(new Set),wt=150,mt=600,pt=o.useCallback(()=>{!e||t||(N.current&&window.clearInterval(N.current),K(!0),N.current=window.setInterval(()=>{B.current()},wt))},[e,t]),bt=o.useRef(()=>{}),ze=o.useRef(()=>{}),{streaming:J,startStream:Ne,stopStream:Ke}=Il({onDone:v=>bt.current(v),onError:v=>ze.current(v),onAssistantDelta:({text:v})=>{ne.current+=v,C({text:ne.current,sessionFriendlyId:e})}});bt.current=o.useCallback(async v=>{await me.refetch(),Ke({preserveState:!0}),Ve(),i.invalidateQueries({queryKey:de.sessions})},[me,i,Ke,Ve]),ze.current=o.useCallback(v=>{console.warn("[stream] SSE error, falling back to polling")},[]);const Ue=o.useMemo(()=>{if(!J.text)return null;const v=[];for(const U of J.tools)v.push({type:"toolCall",name:U.name,id:U.id});return v.push({type:"text",text:J.text}),{role:"assistant",content:v,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[J.text,J.tools]),Fr=o.useMemo(()=>{if(!Ue)return pe;const v=[...pe].map((ae,he)=>({message:ae,index:he})).filter(({message:ae})=>ae.role==="assistant").map(({index:ae})=>ae).pop(),U=[...pe].map((ae,he)=>({message:ae,index:he})).filter(({message:ae})=>ae.role==="user").map(({index:ae})=>ae).pop();if(typeof v=="number"&&(typeof U!="number"||v>U)&&typeof v=="number"){const ae=pe[v];if(De(ae).length>=J.text.length)return pe;const Pe=[...pe];return Pe[v]=Ue,Pe}return[...pe,Ue]},[pe,Ue,J.text]),Hr=o.useMemo(()=>({}),[]);B.current=function(){me.refetch()},o.useEffect(()=>{if(p){f&&m(null);return}if(tt){f&&m(null);return}if(ee.isSuccess&&!le){f&&m(null);return}const v=be??O??te;if(!v){f?.startsWith("Failed to load")&&m(null);return}An(v)&&a({to:"/connect",replace:!0});const U=be?`Failed to load sessions. ${be}`:O?`Failed to load history. ${O}`:te?`Gateway unavailable. ${te}`:null;U&&m(U)},[f,te,O,p,a,be]);const tt=!t&&!s&&!xr(e)&&ee.isSuccess&&Q.length>0&&!Q.some(v=>v.friendlyId===e)&&!me.isFetching&&!me.isSuccess;o.useEffect(()=>{if(p){if(t){g(!1);return}!tt&&ee.isSuccess&&g(!1)}},[t,p,ee.isSuccess,tt]),o.useEffect(()=>{t||ee.isSuccess&&Q.length!==0&&tt&&(At(),an(i,e,W),a({to:"/new",replace:!0}))},[e,me.isFetching,me.isSuccess,t,a,i,W,Q,ee.isSuccess,tt]);const yn=tt||p,St=o.useRef("fast");o.useEffect(()=>{const v=[...ge].reverse().find(ue=>ue.role==="assistant");if(!v)return;const U=`${ge.length}:${De(v).slice(-64)}`;U!==z.current&&(z.current=U,St.current!=="fast"&&N.current&&(window.clearInterval(N.current),N.current=window.setInterval(()=>{B.current()},wt),St.current="fast"),P.current&&window.clearTimeout(P.current),P.current=window.setTimeout(()=>{N.current&&(window.clearInterval(N.current),N.current=window.setInterval(()=>{B.current()},mt),St.current="slow"),P.current=window.setTimeout(()=>{Ve(),St.current="fast"},3e3)},1500))},[ge,Ve]),o.useEffect(()=>{if(!dt||t||p)return;const v=s||fe||V;if(!v||yt.current.has(v))return;const U=ge.filter(he=>he.role==="user"),ue=ge.filter(he=>he.role==="assistant");if(U.length===0||ue.length===0||U.length!==1)return;const ae=De(U[0]);!ae||ae.length<5||(yt.current.add(v),(async()=>{try{const he=await ft(ae);he.title&&await vo(i,v,e,he.title)}catch(he){console.error("[smart-title] Error generating title:",he)}})())},[dt,t,p,s,fe,V,e,ge,ft,i]),o.useEffect(()=>{if(t||e){if(qe(),Ke(),z.current="",K(!1),re.current){re.current=!1;return}if(Bt()||Gt()){k(!0),R(!0);return}k(!1),R(!1)}},[e,t,qe,Ke]),o.useEffect(()=>{if(!(typeof window>"u"))try{const v=sessionStorage.getItem(kt);if(!v){T(null);return}const U=JSON.parse(v);if(typeof U.at=="number"&&Date.now()-U.at>300*1e3){sessionStorage.removeItem(kt),T(null);return}if(U.friendlyId===e&&typeof U.messageId=="string"&&U.messageId.length>0){T(U.messageId),sessionStorage.removeItem(kt);return}T(null)}catch{T(null)}},[e]),o.useLayoutEffect(()=>{if(t)return;const v=Eo(s||fe||V,e);if(!v)return;re.current=!0;const U=de.history(v.friendlyId,v.sessionKey),ue=i.getQueryData(U);(Array.isArray(ue?.messages)?ue.messages:[]).some(Pe=>!!(v.optimisticMessage.clientId&&(Pe.clientId===v.optimisticMessage.clientId||Pe.__optimisticId===v.optimisticMessage.clientId)||v.optimisticMessage.__optimisticId&&Pe.__optimisticId===v.optimisticMessage.__optimisticId))||Yt(i,v.friendlyId,v.sessionKey,v.optimisticMessage),k(!0),R(!0),Wt(v.sessionKey,v.friendlyId,v.message,!0,v.attachments)},[e,V,s,t,i,fe]);function Wt(v,U,ue,ae=!1,he,Pe){let nt="";if(!ae){const{clientId:we,optimisticMessage:rt}=In(ue,he);nt=we,Yt(i,U,v,rt),bo(i,v,U,rt)}ht(!0),c(!0),m(null),k(!0),R(!0);const $e=he?.map(we=>({mimeType:we.file.type,content:we.base64}));ne.current="",pt(),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:v,friendlyId:U,message:ue,thinking:$,idempotencyKey:crypto.randomUUID(),attachments:$e,model:Pe||void 0})}).then(async we=>{if(!we.ok)throw new Error(await _e(we));const kn=(await we.json()).sessionKey||v||U;Ne(kn)}).catch(we=>{const rt=we instanceof Error?we.message:String(we);if(An(rt)){a({to:"/connect",replace:!0});return}nt&&xo(i,U,v,nt,function(ns){return{...ns,status:"error"}}),m(`Failed to send message. ${rt}`),ht(!1),k(!1),R(!1)}).finally(()=>{c(!1)})}const wn=o.useCallback(async()=>{d(!0);try{const v=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!v.ok)throw new Error(await _e(v));const U=await v.json(),ue=typeof U.sessionKey=="string"?U.sessionKey:"",ae=typeof U.friendlyId=="string"&&U.friendlyId.trim().length>0?U.friendlyId.trim():rn(ue);if(!ue||!ae)throw new Error("Invalid session response");return i.invalidateQueries({queryKey:de.sessions}),{sessionKey:ue,friendlyId:ae}}finally{d(!1)}},[i]),Wr=o.useCallback((v,U)=>{const ue=U.attachments;if(v.length===0&&(!ue||ue.length===0))return;if(U.reset(),t){const{clientId:he,optimisticId:Pe,optimisticMessage:nt}=In(v,ue);Yt(i,"new","new",nt),ht(!0),c(!0),k(!0),R(!0),wn().then(({sessionKey:$e,friendlyId:we})=>{if(Co(we),No({sessionKey:$e,friendlyId:we,message:v,optimisticMessage:nt,attachments:ue}),r){r({sessionKey:$e,friendlyId:we});return}a({to:"/chat/$sessionKey",params:{sessionKey:we},replace:!0})}).catch($e=>{yo(i,"new","new",he,Pe),U.setValue(v),m(`Failed to create session. ${$e instanceof Error?$e.message:String($e)}`),ht(!1),k(!1),R(!1),c(!1)});return}Wt(s||fe||V,e,v,!1,ue,U.model)},[e,V,wn,s,t,a,r,i,fe]),bn=o.useCallback(()=>{k(!1),R(!1),an(i,"new","new"),a({to:"/new"}),Z&&We(i,function(U){return{...U,isSidebarCollapsed:!0}})},[Z,a,i]),Xr=o.useCallback(()=>{We(i,function(U){return{...U,isSidebarCollapsed:!U.isSidebarCollapsed}})},[i]),Yr=o.useCallback(()=>{Z&&We(i,function(U){return{...U,isSidebarCollapsed:!0}})},[Z,i]),Br=o.useCallback(()=>{We(i,function(U){return{...U,isSidebarCollapsed:!1}})},[i]),Gr=o.useCallback(v=>{if(t||!v.trim())return;const U=s||fe||V;U&&Wt(U,e,v.trim())},[e,V,s,t,fe]),qr=o.useCallback(()=>{S.current?.focus()},[]),Vr=o.useCallback(()=>{if(F){G(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[F]),Jr=o.useCallback(()=>{const v=[...pe].reverse().find(ue=>ue.role==="assistant");if(!v)return;const U=De(v);U&&navigator.clipboard.writeText(U).catch(()=>{})},[pe]),Qr=o.useCallback(()=>{G(!0)},[]),Zr=o.useCallback(()=>{j(t?"global":"current"),q(!0)},[t]),Sn=o.useCallback(()=>{j("global"),q(!0)},[]);Dl({onNewChat:bn,onFocusInput:qr,onEscape:Vr,onCopyLastResponse:Jr,onShowHelp:Qr,onSearch:Zr,onSearchGlobal:Sn});const vn=me.isLoading&&!me.data||p,jn=!!te&&oe.errorUpdatedAt>ie.current,es=!vn&&pe.length===0,ts=o.useMemo(()=>!jn||!Se?null:n.jsx(jl,{state:"error",error:Se,onRetry:Oe}),[Se,Oe,jn]),Nn=n.jsx(Hi,{sessions:Q,activeFriendlyId:e,activeSessionKey:W,creatingSession:u,onCreateSession:bn,isCollapsed:Z?!1:xe,onToggleCollapse:Xr,onSelectSession:Yr,onActiveSessionDelete:xt,onOpenSearch:Sn});return n.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[n.jsxs("div",{className:I("h-full overflow-hidden",Z?"relative":"grid grid-cols-[auto_minmax(0,1fr)]"),children:[yn?null:Z?n.jsxs(n.Fragment,{children:[!xe&&n.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>We(i,v=>({...v,isSidebarCollapsed:!0})),...ut}),n.jsx("div",{className:I("fixed inset-y-0 left-0 z-50 w-[var(--opencami-sidebar-width)] transition-transform duration-150 safe-area-top",xe?"-translate-x-full":"translate-x-0"),...ut,children:Nn})]}):Nn,n.jsxs("main",{className:"flex flex-col h-full min-h-0 min-w-0 overflow-x-hidden",ref:w,...Le,children:[n.jsx(Bi,{activeTitle:se,wrapperRef:b,showSidebarButton:Z,onOpenSidebar:Br,totalTokens:ce.totalTokens,contextTokens:ce.contextTokens}),yn?null:n.jsxs(n.Fragment,{children:[n.jsx(Ha,{messages:Fr,loading:vn,empty:es,notice:ts,noticePosition:"end",waitingForResponse:A,isStreaming:M,sessionKey:L,pinToTop:_,pinGroupMinHeight:y,headerHeight:x,contentStyle:Hr,onFollowUpClick:Gr,jumpToMessageId:E}),n.jsx(Sl,{onSubmit:Wr,isLoading:l,disabled:l,wrapperRef:h,inputRef:S})]})]})]}),F&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(Pl,{open:F,onOpenChange:G})}),D&&n.jsx(o.Suspense,{fallback:null,children:n.jsx(_l,{open:D,onOpenChange:q,sessions:Q,currentFriendlyId:e,currentSessionKey:V,mode:H,onJumpToMessage:v=>{if(q(!1),!!v.friendlyId){if(v.messageId&&v.friendlyId===e){T(v.messageId);return}if(v.messageId&&typeof window<"u")try{sessionStorage.setItem(kt,JSON.stringify({friendlyId:v.friendlyId,messageId:v.messageId,at:Date.now()}))}catch{}a({to:"/chat/$sessionKey",params:{sessionKey:v.friendlyId}})}}})})]})}function zl(){const e=ct(),t=Kt(),[r,s]=o.useState(null),a=os.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){wo(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:zl},Symbol.toStringTag,{value:"Module"}));export{ic as $,de as c,Ir as g,oc as u};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/agents-screen-pHUzJxX5.js","assets/main-Dq6jpr6-.js","assets/useQuery-Ctiljcrr.js","assets/button-CK8tKQ-Z.js","assets/switch-BD3a0LRm.js","assets/useControlled-BQxTgsOd.js","assets/useBaseUiId-MgM4ouhx.js","assets/visuallyHidden-COI6QeQH.js","assets/tooltip-BbH3QWvK.js","assets/useOnFirstRender-7qoaK5sI.js","assets/event-BsD1rqGT.js","assets/DirectionContext-C6goXEY_.js","assets/opencami-logo-zuSBm5Br.js","assets/proxy-BU8Bw1Vt.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,r as t,_ as r}from"./main-Dq6jpr6-.js";const n=t.lazy(()=>r(()=>import("./agents-screen-pHUzJxX5.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,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/bots-screen-B79bAYvf.js","assets/main-Dq6jpr6-.js","assets/button-CK8tKQ-Z.js","assets/switch-BD3a0LRm.js","assets/useControlled-BQxTgsOd.js","assets/useBaseUiId-MgM4ouhx.js","assets/visuallyHidden-COI6QeQH.js","assets/useQuery-Ctiljcrr.js","assets/useMutation-12DyB3Ox.js","assets/proxy-BU8Bw1Vt.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,r as t,_ as r}from"./main-Dq6jpr6-.js";const n=t.lazy(()=>r(()=>import("./bots-screen-B79bAYvf.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};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as g,j as e,r as f,L as v}from"./main-Dq6jpr6-.js";import{H as o,h,c as d,C as x,A as w,B as k,E as C,G as b,r as E}from"./button-CK8tKQ-Z.js";import{S}from"./switch-BD3a0LRm.js";import{u as j}from"./useQuery-Ctiljcrr.js";import{u as N}from"./useMutation-12DyB3Ox.js";import{m as M,A}from"./proxy-BU8Bw1Vt.js";import"./useControlled-BQxTgsOd.js";import"./useBaseUiId-MgM4ouhx.js";import"./visuallyHidden-COI6QeQH.js";const y=["cron-jobs"];function $(){return j({queryKey:y,queryFn:async({signal:r})=>{const t=new AbortController,n=()=>t.abort();r.addEventListener("abort",n);try{const s=await fetch("/api/cron",{signal:t.signal});if(!s.ok)throw new Error("Failed to fetch cron jobs");const i=await s.json();return Array.isArray(i.jobs)?i.jobs:[]}finally{r.removeEventListener("abort",n)}},refetchInterval:3e4})}function D(r){return j({queryKey:["cron-job-runs",r],queryFn:async({signal:t})=>{if(!r)return[];const n=new AbortController,s=()=>n.abort();t.addEventListener("abort",s);try{const i=await fetch(`/api/cron?jobId=${encodeURIComponent(r)}`,{signal:n.signal});if(!i.ok)throw new Error("Failed to fetch cron job runs");const l=await i.json();return Array.isArray(l.runs)?l.runs:[]}finally{t.removeEventListener("abort",s)}},enabled:!!r})}function R(){const r=g();return N({mutationFn:async t=>{const n=new AbortController,s=await fetch("/api/cron",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jobId:t}),signal:n.signal});if(!s.ok)throw new Error("Failed to run cron job");return s.json()},onSuccess:()=>{r.invalidateQueries({queryKey:y})}})}function L(){const r=g();return N({mutationFn:async({jobId:t,enabled:n})=>{const s=new AbortController,i=await fetch("/api/cron",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({jobId:t,patch:{enabled:n}}),signal:s.signal});if(!i.ok)throw new Error("Failed to update cron job");return i.json()},onSuccess:()=>{r.invalidateQueries({queryKey:y})}})}function J(r){return!r||r<=0?"—":r<1e3?`${r}ms`:r<6e4?`${(r/1e3).toFixed(1)}s`:`${(r/6e4).toFixed(1)}m`}function z(r){return r?new Date(r).toLocaleString():"—"}function F({job:r}){const t=D(r.id),n=t.data??[];return e.jsx(M.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsxs("div",{className:"space-y-4 border-t border-primary-100 bg-primary-50/50 px-4 py-4",children:[(r.payload.message||r.payload.prompt)&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Prompt / Message"}),e.jsx("p",{className:"whitespace-pre-wrap break-words rounded-lg bg-surface border border-primary-100 p-3 text-sm text-primary-700 leading-relaxed",children:r.payload.message??r.payload.prompt})]}),r.delivery&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Delivery"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.delivery.mode&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-surface text-primary-600 border border-primary-100",children:["Mode: ",r.delivery.mode]}),r.delivery.channel&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-surface text-primary-600 border border-primary-100",children:["Channel: ",r.delivery.channel]}),r.delivery.to&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-surface text-primary-600 border border-primary-100",children:["To: ",r.delivery.to]})]})]}),r.payload.model&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Model"}),e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-mono rounded-full bg-surface text-primary-600 border border-primary-100",children:r.payload.model})]}),r.state?.lastError&&e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-red-500 uppercase tracking-wider mb-2",children:"Last Error"}),e.jsx("p",{className:"rounded-lg bg-red-50 border border-red-100 p-3 font-mono text-xs text-red-600 leading-relaxed",children:r.state.lastError})]}),e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-2",children:"Recent Runs"}),t.isLoading?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-primary-500",children:[e.jsx(o,{icon:h,size:12,className:"animate-spin"}),"Loading..."]}):n.length===0?e.jsx("p",{className:"text-xs text-primary-400",children:"No run history available"}):e.jsx("div",{className:"space-y-1.5",children:n.slice(0,5).map(s=>e.jsxs("div",{className:"flex items-center gap-3 py-1.5 px-2 rounded-md bg-surface border border-primary-50",children:[e.jsx("span",{className:d("inline-block h-2 w-2 shrink-0 rounded-full",s.status==="ok"?"bg-emerald-500":"bg-red-500")}),e.jsx(o,{icon:x,size:11,strokeWidth:1.5,className:"text-primary-400"}),e.jsx("span",{className:"tabular-nums text-[11px] text-primary-600",children:z(s.ranAt)}),e.jsx("span",{className:"tabular-nums text-[11px] text-primary-400",children:J(s.durationMs)}),s.error&&e.jsx("span",{className:"truncate text-[11px] text-red-500 ml-auto",children:s.error})]},s.id))})]})]})})}function T(r){const t=r.trim().split(/\s+/);if(t.length<5)return r;const[n,s,i,l,c]=t,a=`${s.padStart(2,"0")}:${n.padStart(2,"0")}`;if(i==="*"&&l==="*"&&c==="*")return`Daily at ${a}`;if(i==="*"&&l==="*"&&c!=="*"){const m={0:"Sun",1:"Mon",2:"Tue",3:"Wed",4:"Thu",5:"Fri",6:"Sat",7:"Sun"};return`${c.split(",").map(u=>m[u]??u).join(", ")} at ${a}`}return r}function B(r){const t=r.schedule;return t.kind==="every"&&t.expr?`Every ${t.expr}`:t.kind==="at"&&t.expr?`Once at ${t.expr}`:t.kind==="cron"&&t.expr?T(t.expr):t.expr??"Unknown"}function W(r){if(!r)return"—";const t=Date.now()-r;return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(r).toLocaleDateString()}function q(r){if(!r)return"—";const t=r-Date.now();return t<0?"overdue":t<6e4?"in <1m":t<36e5?`in ${Math.floor(t/6e4)}m`:t<864e5?`in ${Math.floor(t/36e5)}h`:new Date(r).toLocaleDateString()}function K({status:r}){return r==="ok"?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-emerald-50 text-emerald-600 border border-emerald-100",children:"ok"}):r==="error"?e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-red-50 text-red-600 border border-red-100",children:"error"}):e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-primary-50 text-primary-400 border border-primary-100",children:"—"})}function O({jobs:r}){const[t,n]=f.useState(null),s=R(),i=L(),l=f.useCallback(a=>{i.mutate({jobId:a.id,enabled:!a.enabled})},[i]),c=f.useCallback(a=>{s.mutate(a)},[s]);return r.length===0?null:e.jsx("div",{className:"space-y-2",children:r.map(a=>{const m=t===a.id,p=s.isPending&&s.variables===a.id;return e.jsxs("div",{className:d("group rounded-lg border border-primary-100 bg-surface transition-all duration-150 ease-out",m?"border-primary-200 shadow-sm":"hover:border-primary-200 hover:shadow-sm"),children:[e.jsxs("button",{type:"button",onClick:()=>n(m?null:a.id),className:d("w-full p-4 text-left","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-300 focus-visible:rounded-lg"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsx("h4",{className:d("text-[13px] font-semibold leading-tight truncate",a.enabled?"text-primary-900":"text-primary-400"),children:a.name??a.id}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[!a.enabled&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-primary-50 text-primary-400 border border-primary-100",children:"Disabled"}),e.jsx(K,{status:a.state?.lastStatus})]})]}),e.jsx("p",{className:"text-xs text-primary-500 leading-relaxed mb-3",children:B(a)}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-primary-50",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-[11px] text-primary-400 flex items-center gap-1",children:[e.jsx(o,{icon:x,size:11,strokeWidth:1.5}),"Last: ",W(a.state?.lastRunAtMs)]}),e.jsxs("span",{className:"text-[11px] text-primary-400 flex items-center gap-1",children:[e.jsx(o,{icon:w,size:11,strokeWidth:1.5}),"Next: ",q(a.state?.nextRunAtMs)]})]}),e.jsxs("div",{className:"flex items-center gap-2",onClick:u=>u.stopPropagation(),children:[e.jsx(S,{checked:a.enabled,onCheckedChange:()=>l(a),"aria-label":`${a.enabled?"Disable":"Enable"} ${a.name??a.id}`,disabled:i.isPending}),e.jsx(k,{variant:"ghost",size:"icon-sm",onClick:()=>c(a.id),disabled:p,"aria-label":`Run ${a.name??a.id} now`,className:"text-primary-500 hover:text-primary-700",children:e.jsx(o,{icon:p?h:C,size:16,strokeWidth:1.5,className:d(p&&"animate-spin")})})]})]})]}),e.jsx(A,{children:m&&e.jsx(F,{job:a})})]},a.id)})})}function P(r){if(!r)return"never";const t=Date.now()-r;return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:new Date(r).toLocaleDateString()}function Q(r){for(const t of[" - "," | ",": "," / "]){const n=r.indexOf(t);if(n>0)return r.substring(0,n).trim()}return r}function I(r){const t=new Map;for(const n of r){const s=Q(n.name??n.id),i=t.get(s);i?i.push(n):t.set(s,[n])}return Array.from(t.entries()).map(([n,s])=>({name:n,jobs:s})).sort((n,s)=>n.name.localeCompare(s.name))}function H({bot:r}){const t=r.jobs.reduce((i,l)=>Math.max(i,l.state?.lastRunAtMs??0),0),n=r.jobs.some(i=>i.state?.lastStatus==="error"),s=r.jobs.filter(i=>i.enabled).length;return e.jsxs("div",{className:"group rounded-lg border border-primary-100 bg-surface p-4 transition-all duration-150 ease-out hover:border-primary-200 hover:shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:d("flex items-center justify-center w-10 h-10 rounded-lg",n?"bg-red-50":"bg-primary-50"),children:e.jsx(o,{icon:b,size:20,strokeWidth:1.5,className:n?"text-red-500":"text-primary-500"})}),e.jsx("h4",{className:"text-[13px] font-semibold text-primary-900 leading-tight truncate",children:r.name})]}),n&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 text-[11px] font-medium rounded-full bg-red-50 text-red-600 border border-red-100 shrink-0",children:"Error"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-primary-50",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{className:"text-[11px] text-primary-400 flex items-center gap-1",children:[e.jsx(o,{icon:x,size:11,strokeWidth:1.5}),P(t||void 0)]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full bg-primary-50 text-primary-500 border border-primary-100",children:[r.jobs.length," job",r.jobs.length!==1?"s":""]}),s<r.jobs.length&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full bg-amber-50 text-amber-600 border border-amber-100",children:[r.jobs.length-s," disabled"]})]})]})]})}function te(){const r=$(),t=r.data??[],n=f.useMemo(()=>I(t),[t]);return e.jsxs("div",{className:"flex h-screen flex-col bg-surface text-primary-900",children:[e.jsxs("div",{className:"px-4 pt-4 pb-3 border-b border-primary-100",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(v,{to:"/chat/$sessionKey",params:{sessionKey:"main"},className:"p-1.5 -ml-1.5 rounded-md text-primary-500 hover:text-primary-700 hover:bg-primary-50 transition-colors duration-150","aria-label":"Back to Chat",children:e.jsx(o,{icon:E,size:18,strokeWidth:2})}),e.jsx("h2",{className:"text-base font-semibold text-primary-900",children:"Cron Jobs"})]}),e.jsxs("p",{className:"text-xs text-primary-500",children:[t.length," job",t.length!==1?"s":""," configured"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-4 pb-4 pt-4",children:r.isLoading?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(o,{icon:h,size:18,className:"animate-spin text-primary-300"})}):r.isError?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("p",{className:"text-sm text-red-500",children:r.error instanceof Error?r.error.message:"Failed to load cron jobs"}),e.jsx("button",{onClick:()=>{r.refetch()},className:"mt-2 text-xs font-medium text-primary-500 hover:text-primary-700 transition-colors duration-150",children:"Retry"})]}):t.length===0?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-lg bg-primary-50 mb-3",children:e.jsx(o,{icon:x,size:24,className:"text-primary-400"})}),e.jsx("p",{className:"text-sm text-primary-500",children:"No cron jobs configured"}),e.jsx("p",{className:"text-xs text-primary-400 mt-1",children:"Jobs will appear here once created"})]}):e.jsxs("div",{className:"space-y-6",children:[n.length>0&&e.jsxs("section",{children:[e.jsxs("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3 flex items-center gap-2",children:[e.jsx(o,{icon:b,size:14,strokeWidth:1.5}),"Bots (",n.length,")"]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:n.map(s=>e.jsx(H,{bot:s},s.name))})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:"text-xs font-medium text-primary-400 uppercase tracking-wider mb-3 flex items-center gap-2",children:[e.jsx(o,{icon:x,size:14,strokeWidth:1.5}),"All Jobs (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:e.jsx(O,{jobs:t})})]})]})})]})}export{te as BotsScreen};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/file-explorer-screen-Ds7LeJTd.js","assets/main-Dq6jpr6-.js","assets/useQuery-Ctiljcrr.js","assets/button-CK8tKQ-Z.js","assets/tooltip-BbH3QWvK.js","assets/useOnFirstRender-7qoaK5sI.js","assets/useBaseUiId-MgM4ouhx.js","assets/event-BsD1rqGT.js","assets/visuallyHidden-COI6QeQH.js","assets/DirectionContext-C6goXEY_.js","assets/use-file-explorer-state-DBfLeAyz.js","assets/composite-feK0c-xF.js","assets/react-BLyCEWpN.js","assets/proxy-BU8Bw1Vt.js","assets/menu-n6L--M9R.js","assets/useCompositeItem-OhltNFdZ.js","assets/useMutation-12DyB3Ox.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,r,_ as s}from"./main-Dq6jpr6-.js";const n=r.lazy(()=>s(()=>import("./file-explorer-screen-Ds7LeJTd.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])).then(t=>({default:t.FileExplorerScreen})));function o(){return e.jsx(r.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,3 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/cpp-B-lmv-kZ.js","assets/regexp-CDVJQ6XC.js","assets/c-BIGW1oBm.js","assets/sql-BLtJtn59.js","assets/graphql-ChdNCCLP.js","assets/javascript-wDzz0qaB.js","assets/typescript-BPQ3VLAy.js","assets/jsx-g9-lgVsj.js","assets/tsx-COt5Ahok.js","assets/html-GMplVEZG.js","assets/css-DPfMkruS.js","assets/php-Dhbhpdrm.js","assets/xml-sdJ4AIDG.js","assets/java-CylS5w8V.js","assets/json-Cp-IABpG.js","assets/ruby-NiQIzKut.js","assets/shell-DfDnw5Jg.js","assets/yaml-Buea-lGh.js","assets/core-BrHBc0Zp.js","assets/index-T4TOjvD0.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as _,j as u,_ as r}from"./main-Dq6jpr6-.js";import{H as k,n as J,B as C,F as q,X as z,x as U,c as T}from"./button-CK8tKQ-Z.js";import{c as G}from"./react-BLyCEWpN.js";function X(e,s){let t;try{t=e()}catch{return}return{getItem:i=>{var a;const p=f=>f===null?null:JSON.parse(f,void 0),c=(a=t.getItem(i))!=null?a:null;return c instanceof Promise?c.then(p):p(c)},setItem:(i,a)=>t.setItem(i,JSON.stringify(a,void 0)),removeItem:i=>t.removeItem(i)}}const D=e=>s=>{try{const t=e(s);return t instanceof Promise?t:{then(n){return D(n)(t)},catch(n){return this}}}catch(t){return{then(n){return this},catch(n){return D(n)(t)}}}},$=(e,s)=>(t,n,i)=>{let a={storage:X(()=>window.localStorage),partialize:o=>o,version:0,merge:(o,g)=>({...g,...o}),...s},p=!1,c=0;const f=new Set,E=new Set;let m=a.storage;if(!m)return e((...o)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),t(...o)},n,i);const L=()=>{const o=a.partialize({...n()});return m.setItem(a.name,{state:o,version:a.version})},P=i.setState;i.setState=(o,g)=>(P(o,g),L());const x=e((...o)=>(t(...o),L()),n,i);i.getInitialState=()=>x;let d;const b=()=>{var o,g;if(!m)return;const w=++c;p=!1,f.forEach(l=>{var h;return l((h=n())!=null?h:x)});const y=((g=a.onRehydrateStorage)==null?void 0:g.call(a,(o=n())!=null?o:x))||void 0;return D(m.getItem.bind(m))(a.name).then(l=>{if(l)if(typeof l.version=="number"&&l.version!==a.version){if(a.migrate){const h=a.migrate(l.state,l.version);return h instanceof Promise?h.then(I=>[!0,I]):[!0,h]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,l.state];return[!1,void 0]}).then(l=>{var h;if(w!==c)return;const[I,R]=l;if(d=a.merge(R,(h=n())!=null?h:x),t(d,!0),I)return L()}).then(()=>{w===c&&(y?.(d,void 0),d=n(),p=!0,E.forEach(l=>l(d)))}).catch(l=>{w===c&&y?.(void 0,l)})};return i.persist={setOptions:o=>{a={...a,...o},o.storage&&(m=o.storage)},clearStorage:()=>{m?.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>b(),hasHydrated:()=>p,onHydrate:o=>(f.add(o),()=>{f.delete(o)}),onFinishHydration:o=>(E.add(o),()=>{E.delete(o)})},a.skipHydration||b(),d||x},Q=$,O=G()(Q(e=>({settings:{showToolMessages:!0,showReasoningBlocks:!0,showSearchSources:!0,inlineFilePreview:!1,theme:"system",fontFamily:"system",density:"comfortable",accentColor:"green",chatWidth:"wide",sidebarWidth:"normal",bubbleStyle:"default"},updateSettings:s=>e(t=>({settings:{...t.settings,...s}}))}),{name:"chat-settings",merge:(e,s)=>{const t=e;return{...s,...t,settings:{...s.settings,...t?.settings??{}}}}}));function ue(){const e=O(t=>t.settings),s=O(t=>t.updateSettings);return{settings:e,updateSettings:s}}function Y(){const e=O(n=>n.settings.theme),[s,t]=_.useState(!1);return _.useEffect(()=>{if(typeof window>"u")return;const n=window.matchMedia("(prefers-color-scheme: dark)");t(n.matches);function i(a){t(a.matches)}return n.addEventListener("change",i),()=>n.removeEventListener("change",i)},[]),_.useMemo(()=>e==="dark"?"dark":e==="light"||e==="frost-light"?"light":e==="frost-dark"||s?"dark":"light",[e,s])}const K=new Set(["bash","c","cpp","csharp","css","diff","dockerfile","go","graphql","html","java","javascript","json","jsx","kotlin","markdown","php","python","regexp","ruby","rust","shell","sql","swift","toml","typescript","tsx","xml","yaml"]),Z={js:"javascript",ts:"typescript",tsx:"tsx",jsx:"jsx",typescriptreact:"tsx",javascriptreact:"jsx",react:"jsx",sh:"bash",shell:"bash",yml:"yaml",md:"markdown",txt:"text"};function H(e){const t=e.trim().toLowerCase().replace(/^language-/,"").replace(/^\[|\]$/g,"").split(/[\s,]+/)[0]||"text";return Z[t]??t}function ee(e){const s=H(e);return K.has(s)?s:"text"}function te(e){return{bash:"Bash",python:"Python",javascript:"JavaScript",typescript:"TypeScript",tsx:"TSX",jsx:"JSX",json:"JSON",html:"HTML",css:"CSS",sql:"SQL",yaml:"YAML",markdown:"Markdown",text:"Plain Text"}[e]||e.charAt(0).toUpperCase()+e.slice(1)}const re={bash:()=>r(()=>import("./shell-DfDnw5Jg.js").then(e=>e.b),[]).then(e=>e.default),c:()=>r(()=>import("./c-BIGW1oBm.js"),[]).then(e=>e.default),cpp:()=>r(()=>import("./cpp-B-lmv-kZ.js"),__vite__mapDeps([0,1,2,3])).then(e=>e.default),csharp:()=>r(()=>import("./csharp-COcwbKMJ.js"),[]).then(e=>e.default),css:()=>r(()=>import("./css-DPfMkruS.js"),[]).then(e=>e.default),diff:()=>r(()=>import("./diff-D97Zzqfu.js"),[]).then(e=>e.default),dockerfile:()=>r(()=>import("./dockerfile-BcOcwvcX.js"),[]).then(e=>e.default),go:()=>r(()=>import("./go-CxLEBnE3.js"),[]).then(e=>e.default),graphql:()=>r(()=>import("./graphql-ChdNCCLP.js"),__vite__mapDeps([4,5,6,7,8])).then(e=>e.default),html:()=>r(()=>import("./html-GMplVEZG.js"),__vite__mapDeps([9,5,10])).then(e=>e.default),java:()=>r(()=>import("./java-CylS5w8V.js"),[]).then(e=>e.default),javascript:()=>r(()=>import("./javascript-wDzz0qaB.js"),[]).then(e=>e.default),json:()=>r(()=>import("./json-Cp-IABpG.js"),[]).then(e=>e.default),jsx:()=>r(()=>import("./jsx-g9-lgVsj.js"),[]).then(e=>e.default),kotlin:()=>r(()=>import("./kotlin-BdnUsdx6.js"),[]).then(e=>e.default),markdown:()=>r(()=>import("./markdown-Cvjx9yec.js"),[]).then(e=>e.default),php:()=>r(()=>import("./php-Dhbhpdrm.js"),__vite__mapDeps([11,9,5,10,12,13,3,14])).then(e=>e.default),python:()=>r(()=>import("./python-B6aJPvgy.js"),[]).then(e=>e.default),regexp:()=>r(()=>import("./regexp-CDVJQ6XC.js"),[]).then(e=>e.default),ruby:()=>r(()=>import("./ruby-NiQIzKut.js"),__vite__mapDeps([15,9,5,10,12,13,3,4,6,7,8,0,1,2,16,17])).then(e=>e.default),rust:()=>r(()=>import("./rust-B1yitclQ.js"),[]).then(e=>e.default),shell:()=>r(()=>import("./shell-DfDnw5Jg.js").then(e=>e.a),[]).then(e=>e.default),sql:()=>r(()=>import("./sql-BLtJtn59.js"),[]).then(e=>e.default),swift:()=>r(()=>import("./swift-D82vCrfD.js"),[]).then(e=>e.default),toml:()=>r(()=>import("./toml-vGWfd6FD.js"),[]).then(e=>e.default),typescript:()=>r(()=>import("./typescript-BPQ3VLAy.js"),[]).then(e=>e.default),tsx:()=>r(()=>import("./tsx-COt5Ahok.js"),[]).then(e=>e.default),xml:()=>r(()=>import("./xml-sdJ4AIDG.js"),__vite__mapDeps([12,13])).then(e=>e.default),yaml:()=>r(()=>import("./yaml-Buea-lGh.js"),[]).then(e=>e.default)},ne={sh:"bash",zsh:"bash",js:"javascript",ts:"typescript",py:"python",rb:"ruby",rs:"rust",cs:"csharp","c++":"cpp",yml:"yaml",md:"markdown",docker:"dockerfile"};let j=null;const N=new Set;async function se(){if(!j){const[{createHighlighterCore:e},{createJavaScriptRegexEngine:s},t,n]=await Promise.all([r(()=>import("./core-BrHBc0Zp.js"),__vite__mapDeps([18,19])),r(()=>import("./engine-javascript-PwbX1GN8.js"),[]),r(()=>import("./vitesse-dark-D0r3Knsf.js"),[]).then(i=>i.default),r(()=>import("./vitesse-light-CVO1_9PV.js"),[]).then(i=>i.default)]);j=e({themes:[t,n],langs:[],engine:s()})}return j}async function ae(e,s){const t=ne[s]||s;if(N.has(t))return t;const n=re[t];if(!n)return"text";try{const i=await n();return await e.loadLanguage(i),N.add(t),t}catch{return"text"}}function ce({content:e,ariaLabel:s,language:t="text",filename:n,className:i}){const a=Y(),[p,c]=_.useState(!1),[f,E]=_.useState(null),[m,L]=_.useState("text"),[P,x]=_.useState(),[d,b]=_.useState(!1),o=_.useMemo(()=>e,[e]),g=H(t||"text"),w=a==="dark"?"vitesse-dark":"vitesse-light";_.useEffect(()=>{let v=!0;async function S(){try{const A=await se();if(!v)return;const F=ee(g),V=await ae(A,F);if(!v)return;const W=A.codeToHtml(e,{lang:V,theme:w});if(v){L(V),E(W);const B=A.getTheme(w);x(B.bg)}}catch{v&&E(null)}}return S(),()=>{v=!1}},[e,g,w]),_.useEffect(()=>{if(typeof window>"u")return;const v=window.localStorage.getItem("opencami-code-wrap");b(v==="1")},[]);function y(){b(v=>{const S=!v;return typeof window<"u"&&window.localStorage.setItem("opencami-code-wrap",S?"1":"0"),S})}async function l(){try{await navigator.clipboard.writeText(e),c(!0),window.setTimeout(()=>c(!1),1600)}catch{c(!1)}}const R=!(e.replace(/\n$/,"").split(`
|
|
3
|
-
`).length<=1),M=te(m);return u.jsxs("div",{className:T("code-block group relative w-full min-w-0 max-w-full overflow-hidden rounded-lg border border-primary-200",i),children:[u.jsxs("div",{className:T("flex items-center justify-between px-3 pt-2"),style:{backgroundColor:P},children:[u.jsx("span",{className:"text-xs font-medium text-primary-500 flex items-center gap-1.5 min-w-0",children:n?u.jsxs(u.Fragment,{children:[u.jsx(k,{icon:J,size:14,strokeWidth:1.8}),u.jsx("span",{className:"truncate",children:n})]}):M}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs(C,{variant:"ghost","aria-label":d?"Disable wrap":"Enable wrap",className:"h-auto px-0 text-xs font-medium text-primary-500 hover:text-primary-800 hover:bg-transparent",onClick:y,children:[u.jsx(k,{icon:q,size:14,strokeWidth:1.8}),d?"No wrap":"Wrap"]}),u.jsxs(C,{variant:"ghost","aria-label":s??"Copy code",className:"h-auto px-0 text-xs font-medium text-primary-500 hover:text-primary-800 hover:bg-transparent",onClick:()=>{l().catch(()=>{})},children:[u.jsx(k,{icon:p?z:U,size:14,strokeWidth:1.8}),p?"Copied":"Copy"]})]})]}),f?u.jsx("div",{className:T("w-full min-w-0 max-w-full text-sm text-primary-900 overflow-x-hidden [&>pre]:w-full [&>pre]:min-w-0 [&>pre]:max-w-full [&>pre]:px-3 [&>pre]:py-3",d?"[&>pre]:whitespace-pre-wrap [&>pre]:break-words [&_.line]:whitespace-pre-wrap [&_.line]:break-words":"overflow-x-auto [&>pre]:whitespace-pre [&>pre]:overflow-x-auto",R&&"[&>pre]:[counter-reset:line] [&_.line]:before:content-[counter(line)] [&_.line]:before:[counter-increment:line] [&_.line]:before:inline-block [&_.line]:before:w-8 [&_.line]:before:mr-4 [&_.line]:before:text-right [&_.line]:before:select-none [&_.line]:before:text-primary-500/60"),dangerouslySetInnerHTML:{__html:f}}):u.jsx("pre",{className:T("w-full min-w-0 max-w-full text-sm px-3 py-3 overflow-x-auto",d?"whitespace-pre-wrap break-words":"whitespace-pre overflow-x-auto"),children:u.jsx("code",{className:"block",children:o})})]})}export{ce as C,Q as p,ee as r,ue as u};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/memory-screen-CUFBWsq5.js","assets/main-Dq6jpr6-.js","assets/useQuery-Ctiljcrr.js","assets/useMutation-12DyB3Ox.js","assets/button-CK8tKQ-Z.js","assets/markdown-C7_Aipwd.js","assets/index-rljDU_1M.js","assets/react-BLyCEWpN.js","assets/use-file-explorer-state-DBfLeAyz.js","assets/useOnFirstRender-7qoaK5sI.js","assets/useBaseUiId-MgM4ouhx.js","assets/event-BsD1rqGT.js","assets/visuallyHidden-COI6QeQH.js","assets/composite-feK0c-xF.js","assets/index-T4TOjvD0.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,r,_ as s}from"./main-Dq6jpr6-.js";const n=r.lazy(()=>s(()=>import("./memory-screen-CUFBWsq5.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(t=>({default:t.MemoryScreen})));function a(){return e.jsx(r.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{a as component};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/skills-panel-BH27r3nC.js","assets/main-Dq6jpr6-.js","assets/button-CK8tKQ-Z.js","assets/tabs-DI1e-kzz.js","assets/useControlled-BQxTgsOd.js","assets/useBaseUiId-MgM4ouhx.js","assets/useCompositeItem-OhltNFdZ.js","assets/DirectionContext-C6goXEY_.js","assets/event-BsD1rqGT.js","assets/composite-feK0c-xF.js","assets/CSPContext-6t3O1emU.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{j as e,r as t,_ as r}from"./main-Dq6jpr6-.js";const l=t.lazy(()=>r(()=>import("./skills-panel-BH27r3nC.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.SkillsPanel})));function a(){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(l,{})})}export{a as component};
|