@runfusion/fusion 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/bin.js +2058 -1709
  2. package/dist/client/assets/{AgentDetailView-Du65-jDo.js → AgentDetailView-DyzuiJas.js} +1 -1
  3. package/dist/client/assets/AgentsView-C2f7esMv.css +1 -0
  4. package/dist/client/assets/{AgentsView-BkgNEbNs.js → AgentsView-CgweOTe6.js} +46 -46
  5. package/dist/client/assets/{ChatView-LDte0TdV.js → ChatView-DrY8FMIt.js} +1 -1
  6. package/dist/client/assets/{DevServerView-AXznq3jv.js → DevServerView-fvjo36sF.js} +1 -1
  7. package/dist/client/assets/{DirectoryPicker-CSp3G115.js → DirectoryPicker-D5KQ-im_.js} +1 -1
  8. package/dist/client/assets/{DocumentsView-DOe0E1WQ.js → DocumentsView-D2wK7FYJ.js} +1 -1
  9. package/dist/client/assets/{InsightsView-DWZbS6z-.js → InsightsView-DfY3sa1j.js} +1 -1
  10. package/dist/client/assets/{MemoryView-BxnlhBoa.js → MemoryView-CyAQgXwO.js} +1 -1
  11. package/dist/client/assets/{NodesView-DO9jxhM4.js → NodesView-g26-j7rg.js} +4 -4
  12. package/dist/client/assets/{PiExtensionsManager-CfXZaWl7.js → PiExtensionsManager-DfMr3Gls.js} +3 -3
  13. package/dist/client/assets/{PluginManager-r6CWD9u-.js → PluginManager-DiMOD-Kj.js} +1 -1
  14. package/dist/client/assets/{RoadmapsView-CgAM3YfN.js → RoadmapsView-DJC4F4CD.js} +1 -1
  15. package/dist/client/assets/SettingsModal-BnekMOV2.css +1 -0
  16. package/dist/client/assets/{SettingsModal-fmRtzH8z.js → SettingsModal-Cx3iMWDs.js} +1 -1
  17. package/dist/client/assets/SettingsModal-DjVE27r5.js +31 -0
  18. package/dist/client/assets/{SetupWizardModal-oRNpImWR.js → SetupWizardModal-Cow6woq6.js} +1 -1
  19. package/dist/client/assets/{SkillsView-BhwtL-0_.js → SkillsView-DTB2cmXQ.js} +1 -1
  20. package/dist/client/assets/{TodoView-CmhUBFNV.js → TodoView-CyxdHUdz.js} +1 -1
  21. package/dist/client/assets/{folder-open-CrTagHrr.js → folder-open-C3zB1vmh.js} +1 -1
  22. package/dist/client/assets/{index-S9oR77v2.css → index-Belw0PQt.css} +1 -1
  23. package/dist/client/assets/{index-BTeSa6vk.js → index-DJDWSrju.js} +14 -14
  24. package/dist/client/assets/{list-checks-DR26h_Io.js → list-checks-CK3_6p5e.js} +1 -1
  25. package/dist/client/assets/{star-CO_D42zy.js → star-BQhDgM9V.js} +1 -1
  26. package/dist/client/assets/{upload-BcrgS-iu.js → upload-DDdZveEJ.js} +1 -1
  27. package/dist/client/assets/{users-4d8al5Sp.js → users-DWWgd19M.js} +1 -1
  28. package/dist/client/brands/hermes-logo.svg +1 -1
  29. package/dist/client/index.html +2 -2
  30. package/dist/client/version.json +1 -1
  31. package/dist/extension.js +1340 -1126
  32. package/dist/pi-claude-cli/package.json +1 -1
  33. package/package.json +7 -6
  34. package/dist/client/assets/AgentsView-D12CuIFc.css +0 -1
  35. package/dist/client/assets/SettingsModal-DPDQyWim.css +0 -1
  36. package/dist/client/assets/SettingsModal-GZdRt8fX.js +0 -31
@@ -1 +1 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{i as ze,ay as gt,g as ft,az as pt,a as xt,aA as St,aB as bt,aC as vt,aD as wt,aE as kt,aF as Nt,s as Ct,aG as Mt,aH as jt,aI as yt,f as Tt,a7 as At,a8 as $t,y as Le,S as Et,K as Ke,ak as Pt,aJ as Dt,B as je,a4 as Ue,a5 as qe,aK as Rt,aL as Lt,aM as _t,aN as zt,aO as It,aP as Ft,h as Ot,k as Ht}from"./index-BTeSa6vk.js";import"./vendor-xterm-DzcZoU0P.js";const _e="kb-chat-active-session";function Vt(n){const i=n?.toolCalls;if(!Array.isArray(i))return;const c=i.map(l=>{if(!l||typeof l!="object")return null;const r=l,f=typeof r.toolName=="string"?r.toolName:"";if(!f)return null;const v=r.args;return{toolName:f,...v&&typeof v=="object"?{args:v}:{},isError:!!r.isError,result:r.result,status:"completed"}}).filter(l=>l!==null);return c.length>0?c:void 0}function Je(n){return{id:n.id,sessionId:n.sessionId,role:n.role,content:n.content,thinkingOutput:n.thinkingOutput,toolCalls:Vt(n.metadata),createdAt:n.createdAt}}function Bt(n){const[i,c]=s.useState([]),[l,r]=s.useState(null),[f,v]=s.useState(!0),[j,w]=s.useState([]),[X,I]=s.useState(!1),[F,L]=s.useState(!1),[oe,E]=s.useState(""),[O,T]=s.useState(""),[pe,P]=s.useState([]),[p,D]=s.useState(""),[Z,K]=s.useState(""),[A,H]=s.useState(!0),[U,ne]=s.useState(new Map),N=s.useRef(null),q=s.useRef(!1),J=s.useRef(""),xe=s.useRef(i),V=s.useRef(l),ke=s.useRef(F);xe.current=i,V.current=l,ke.current=F,s.useEffect(()=>{J.current=p},[p]);const ae=s.useRef(new Set),ee=s.useRef(0),Ne=s.useRef(n);Ne.current!==n&&(Ne.current=n,ee.current++),s.useEffect(()=>{const u=ee.current;ze(void 0,n).then(m=>{if(ee.current!==u)return;const h=new Map;for(const k of m)h.set(k.id,k);ne(h)}).catch(()=>{})},[n]);const te=s.useCallback(async()=>{v(!0);try{const m=[...(await gt(n)).sessions].sort((h,k)=>new Date(k.updatedAt).getTime()-new Date(h.updatedAt).getTime());c(m)}catch{}finally{v(!1)}},[n]);s.useEffect(()=>{te()},[te]);const Q=s.useRef(()=>{});s.useEffect(()=>{if(f)return;const u=ft(_e,n);u&&i.find(h=>h.id===u)&&Q.current(u)},[f,i,n]);const _=s.useCallback(async(u,m)=>{I(!0);try{const h=await pt(u,{limit:50,...m},n),k=h.messages.map(Je);m?.offset&&m.offset>0?w(W=>[...k,...W]):w(k),H(h.messages.length>=50)}catch{}finally{I(!1)}},[n]),de=s.useCallback(u=>{N.current&&(N.current.close(),N.current=null);const m=i.find(h=>h.id===u);r(m||null),E(""),T(""),P([]),L(!1),H(!0),u?_(u):w([]),u?xt(_e,u,n):St(_e,n)},[i,_,n]);Q.current=de;const ue=s.useCallback(async u=>{const m=await bt(u,n),h={id:m.session.id,title:m.session.title,agentId:m.session.agentId,status:m.session.status,modelProvider:m.session.modelProvider,modelId:m.session.modelId,createdAt:m.session.createdAt,updatedAt:m.session.updatedAt};return c(k=>[h,...k]),r(h),w([]),E(""),T(""),P([]),L(!1),H(!0),h},[n]),he=s.useCallback(async u=>{await vt(u,{status:"archived"},n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),ie=s.useCallback(async u=>{l?.id===u&&N.current&&(N.current.close(),N.current=null),await wt(u,n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),me=s.useCallback(async()=>{!l||!A||await _(l.id,{offset:j.length})},[l,A,_,j.length]),se=s.useCallback(()=>{l&&(q.current=!0,N.current?.close(),N.current=null,kt(l.id,n).catch(()=>{}),L(!1),E(""),T(""),P([]))},[l,n]),B=s.useCallback(()=>{J.current="",D("")},[]),G=s.useCallback(u=>{if(!l)return;if(F){J.current=u,D(u);return}q.current=!1,N.current&&(N.current.close(),N.current=null);const m=`temp-${Date.now()}`,h={id:m,sessionId:l.id,role:"user",content:u,createdAt:new Date().toISOString()};w(x=>[...x,h]),E(""),T(""),P([]),L(!0);let k="",W="",M=[];const be={onThinking:x=>{W+=x,T(W)},onText:x=>{k+=x,E(k)},onToolStart:x=>{M=[...M,{toolName:x.toolName,args:x.args,isError:!1,status:"running"}],P(M)},onToolEnd:x=>{const d=[...M];for(let S=d.length-1;S>=0;S--){const b=d[S];if(b?.toolName===x.toolName&&b.status==="running"){d[S]={...b,status:"completed",isError:x.isError,result:x.result},M=d,P(d);return}}M=[...d,{toolName:x.toolName,isError:x.isError,result:x.result,status:"completed"}],P(M)},onDone:x=>{const d={id:x.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:k,thinkingOutput:W,toolCalls:M.length>0?M:void 0,createdAt:new Date().toISOString()};ae.current.add(d.id),w(b=>[...b,d]),E(""),T(""),P([]),L(!1),N.current=null,setTimeout(()=>{ae.current.delete(d.id)},1e3),te();const S=J.current.trim();S&&(J.current="",D(""),G(S))},onError:x=>{if(w(d=>d.filter(S=>S.id!==m)),E(""),T(""),P([]),L(!1),N.current=null,console.error("[useChat] Stream error:",x),!q.current){const d=J.current.trim();d&&(J.current="",D(""),G(d))}}};N.current=Nt(l.id,u,be,n)},[l,F,n,te]),Se=Z?i.filter(u=>u.title?.toLowerCase().includes(Z.toLowerCase())||u.agentId.toLowerCase().includes(Z.toLowerCase())):i;return s.useEffect(()=>{const u=ee.current,m=n?`?projectId=${encodeURIComponent(n)}`:"",h=()=>ee.current!==u,k=S=>{if(h())return;const b=JSON.parse(S.data);c(g=>g.some(R=>R.id===b.id)?g:[b,...g])},W=S=>{if(h())return;const b=JSON.parse(S.data);c(g=>[...g.map(C=>C.id===b.id?b:C)]),V.current?.id===b.id&&r(b)},M=S=>{if(h())return;const{id:b}=JSON.parse(S.data);c(g=>g.filter(R=>R.id!==b)),V.current?.id===b&&(r(null),w([]))},be=S=>{if(h())return;const b=JSON.parse(S.data),g=Je(b);ae.current.has(g.id)||V.current?.id===g.sessionId&&!ke.current&&w(R=>R.some(C=>C.id===g.id)?R:[...R,g])},x=S=>{if(h())return;const{id:b}=JSON.parse(S.data);w(g=>g.filter(R=>R.id!==b))};return Ct(`/api/events${m}`,{events:{"chat:session:created":k,"chat:session:updated":W,"chat:session:deleted":M,"chat:message:added":be,"chat:message:deleted":x}})},[n]),s.useEffect(()=>()=>{N.current&&(N.current.close(),N.current=null)},[]),{sessions:i,activeSession:l,sessionsLoading:f,messages:j,messagesLoading:X,isStreaming:F,streamingText:oe,streamingThinking:O,streamingToolCalls:pe,pendingMessage:p,selectSession:de,createSession:ue,archiveSession:he,deleteSession:ie,sendMessage:G,stopStreaming:se,clearPendingMessage:B,loadMoreMessages:me,hasMoreMessages:A,searchQuery:Z,setSearchQuery:K,filteredSessions:Se,refreshSessions:te,agentsMap:U}}function Qe(n){const i=new Date(n),l=new Date().getTime()-i.getTime(),r=Math.floor(l/1e3),f=Math.floor(r/60),v=Math.floor(f/60),j=Math.floor(v/24);return r<60?"just now":f<60?`${f}m ago`:v<24?`${v}h ago`:j<7?`${j}d ago`:i.toLocaleDateString()}function We(n,i){if(!n||!i)return null;const c=i.toLowerCase();if(c.includes("claude")){let r=i.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return r=r.replace(/\s+/g," "),r.length>30?r.slice(0,30)+"…":r}if(c.includes("gpt")||c.includes("openai")){const r=i.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return r.length>30?r.slice(0,30)+"…":r}if(c.includes("gemini")){const r=i.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return r.length>30?r.slice(0,30)+"…":r}const l=i.replace(/-/g," ").replace(/^\w/,r=>r.toUpperCase()).replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}function ye(n,i){return n.length>i?`${n.slice(0,i)}…`:n}function Gt(n){if(!n)return null;const i=Object.entries(n);return i.length===0?null:i.map(([c,l])=>{let r="";if(typeof l=="string")r=l;else try{r=JSON.stringify(l)}catch{r=String(l)}return`${c}=${ye(r,50)}`}).join(", ")}function Kt(n){if(n===void 0)return null;if(typeof n=="string")return ye(n,200);try{return ye(JSON.stringify(n),200)}catch{return ye(String(n),200)}}function Ye(n){return!n||n.length===0?null:e.jsxs("div",{className:"chat-tool-calls","data-testid":"chat-tool-calls",children:[e.jsxs("div",{className:"chat-tool-calls-header",children:[e.jsx(Ft,{size:12,"aria-hidden":"true"}),e.jsx("span",{children:"Tool calls"})]}),n.map((i,c)=>{const l=i.status==="running",r=i.status==="completed"&&i.isError,f=Gt(i.args),v=Kt(i.result),j=l?f:v?`result: ${v}`:f?`args: ${f}`:null,w=l?"running":r?"error":"completed";return e.jsxs("details",{className:`chat-tool-call${l?" chat-tool-call--running":""}${r?" chat-tool-call--error":""}`,open:l,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),e.jsx("span",{className:"chat-tool-call-name",children:i.toolName}),j&&e.jsx("span",{className:"chat-tool-call-preview",title:j,children:j}),e.jsx("span",{className:"chat-tool-call-status-text",children:w})]}),e.jsxs("div",{className:"chat-tool-call-content",children:[f&&e.jsxs("div",{className:"chat-tool-call-row",children:[e.jsx("span",{className:"chat-tool-call-label",children:"args"}),e.jsx("span",{className:"chat-tool-call-value",children:f})]}),v&&e.jsxs("div",{className:`chat-tool-call-row${r?" chat-tool-call-row--error":""}`,children:[e.jsx("span",{className:"chat-tool-call-label",children:"result"}),e.jsx("span",{className:"chat-tool-call-value",children:v})]})]})]},`${i.toolName}-${c}`)})]})}const Ut={pre:({children:n,...i})=>e.jsx("pre",{...i,className:"chat-markdown-pre",children:n}),table:({children:n,...i})=>e.jsx("table",{...i,className:"chat-markdown-table",children:n})},Te="__fn_agent__";function Xe(n){const i=/(^|[\s])\/([^\s]*)$/.exec(n);if(!i)return null;const c=i[1]??"",l=i[2]??"",r=i.index+c.length;return{filter:l,start:r,end:n.length}}function qt(n,i){const c=n.slice(0,i),l=/(^|[\s\n])@([\w-]*)$/.exec(c);if(!l)return null;const r=l[2]??"",f=c.length-r.length-1;return{filter:r,start:f,end:i}}function Jt({projectId:n,onClose:i,onCreate:c}){const[l,r]=s.useState("agent"),[f,v]=s.useState([]),[j,w]=s.useState(!0),[X,I]=s.useState(""),[F,L]=s.useState([]),[oe,E]=s.useState(!0),[O,T]=s.useState("");s.useEffect(()=>{let p=!1;return w(!0),ze(void 0,n).then(D=>{p||v(D)}).catch(()=>{p||v([])}).finally(()=>{p||w(!1)}),()=>{p=!0}},[n]),s.useEffect(()=>{E(!0),Ot().then(p=>{L(p.models)}).catch(()=>{L([])}).finally(()=>{E(!1)})},[]);const pe=p=>{if(p.preventDefault(),l==="agent"){if(!X)return;c({agentId:X});return}if(!O)return;const D=O.indexOf("/");if(D<=0)return;const Z=O.slice(0,D),K=O.slice(D+1);c({agentId:Te,modelProvider:Z,modelId:K})},P=l==="agent"?!X:!O;return e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"chat-new-dialog",onClick:p=>p.stopPropagation(),children:[e.jsx("h3",{children:"New Chat"}),e.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[e.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{r("agent"),T("")},children:"Agent"}),e.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{r("model"),I("")},children:"Model"})]}),e.jsxs("form",{onSubmit:pe,children:[l==="agent"&&e.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",j?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):f.length===0?e.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):e.jsx("div",{className:"chat-new-dialog-agent-list",children:f.map(p=>e.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${X===p.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>I(p.id),"data-testid":`agent-option-${p.id}`,children:[e.jsx(je,{size:16}),e.jsx("span",{className:"chat-new-dialog-agent-name",children:p.name}),e.jsx("span",{className:"chat-new-dialog-agent-role",children:p.role})]},p.id))})]}),l==="model"&&e.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:oe?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):e.jsx(Ht,{models:F,value:O,onChange:T,label:"Model",placeholder:"Select a model"})}),e.jsxs("div",{className:"chat-new-dialog-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:P,children:"Create"})]})]})]})})}function Zt({projectId:n,addToast:i}){const{activeSession:c,sessionsLoading:l,messages:r,messagesLoading:f,isStreaming:v,streamingText:j,streamingThinking:w,streamingToolCalls:X,selectSession:I,createSession:F,archiveSession:L,deleteSession:oe,sendMessage:E,stopStreaming:O,pendingMessage:T,clearPendingMessage:pe,searchQuery:P,setSearchQuery:p,filteredSessions:D}=Bt(n),[Z,K]=s.useState(!1),[A,H]=s.useState(""),[U,ne]=s.useState(null),[N,q]=s.useState(null),[J,xe]=s.useState(!0),[V,ke]=s.useState(new Map),[ae,ee]=s.useState([]),[Ne,te]=s.useState(!0),[Q,_]=s.useState(!1),[de,ue]=s.useState(""),[he,ie]=s.useState(0),[me,se]=s.useState(""),[B,G]=s.useState(!1),[Se,u]=s.useState(0),[m,h]=s.useState(-1),[k,W]=s.useState(()=>new Set),[,M]=s.useState(!1),[be,x]=s.useState({top:0,left:0}),d=Mt({projectId:n}),S=s.useCallback(t=>{if(!t||!d.mentionActive)return;const a=t.getBoundingClientRect();x({top:a.top-260,left:a.left+8})},[d.mentionActive]),b=s.useRef(null),g=s.useRef(null),R=s.useRef(null),C=s.useRef(null),ve=s.useRef(0),le=jt()==="mobile",{keyboardOverlap:Ce,viewportHeight:Ie}=yt({enabled:le&&!!c}),Ze=Ce>0?{"--keyboard-overlap":`${Ce}px`,...Ie!==null?{"--vv-height":`${Ie}px`}:{}}:{},z=s.useMemo(()=>{const t=de.trim().toLowerCase();return(t?ae.filter(o=>o.name.toLowerCase().includes(t)):ae).slice(0,10)},[ae,de]),ge=s.useMemo(()=>Array.from(V.values()),[V]),re=s.useMemo(()=>{const t=me.trim().toLowerCase();return t?ge.filter(a=>a.name.toLowerCase().includes(t)):ge},[ge,me]),Fe=s.useMemo(()=>{const t=new Map;for(const a of ge)t.set(a.name.toLowerCase(),a);return t},[ge]);s.useEffect(()=>{ie(0)},[z]),s.useEffect(()=>{u(0)},[me,B]),s.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current)},[]),s.useEffect(()=>{b.current?.scrollIntoView({behavior:"smooth"})},[r,j]),s.useEffect(()=>{if(Ce<=0)return;const t=R.current;t&&(t.scrollTop=t.scrollHeight)},[Ce]),s.useEffect(()=>{const t=()=>ne(null);if(U)return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[U]),s.useEffect(()=>{let t=!1;const a=n;return ze(void 0,n).then(o=>{if(t||a!==n)return;const y=new Map;for(const $ of o)y.set($.id,$);ke(y)}).catch(()=>{}),()=>{t=!0}},[n]),s.useEffect(()=>{let t=!1;return te(!0),Tt(n).then(a=>{t||ee(a)}).catch(()=>{t||ee([])}).finally(()=>{t||te(!1)}),()=>{t=!0}},[n]);const et=s.useCallback(async t=>{try{await F(t),K(!1),le&&xe(!1)}catch{i("Failed to create chat session","error")}},[F,i,le]),Ae=s.useCallback(()=>{const t=A.trim();!t||!c||(H(""),_(!1),ue(""),G(!1),se(""),h(-1),E(t))},[A,c,E]),$e=s.useCallback(t=>{H(a=>{const o=Xe(a);if(!o)return a;const y=`/skill:${t.name} `,$=a.slice(0,o.start)+y+a.slice(o.end);return window.requestAnimationFrame(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,120)}px`,C.current.focus())}),$}),_(!1),ue(""),ie(0)},[]),Ee=s.useCallback(t=>{const a=C.current;if(!a||m<0)return;const o=a.selectionStart??ve.current,y=a.selectionEnd??o,$=Math.max(o,y),we=Math.min(m,$),ce=`${`@${t.name.replace(/\s+/g,"_")}`} `,Re=A.slice(0,we)+ce+A.slice($),fe=we+ce.length;H(Re),G(!1),se(""),u(0),h(-1),window.requestAnimationFrame(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,120)}px`,C.current.focus(),C.current.setSelectionRange(fe,fe))})},[m,A]),tt=s.useCallback(t=>{const a=/@([\w-]+)/g,o=[];let y=0,$=a.exec(t);for(;$;){const[we,Ge=""]=$,ce=$.index;ce>y&&o.push(t.slice(y,ce));const Re=Ge.replace(/_/g," ").toLowerCase(),fe=Fe.get(Re);fe?o.push(e.jsxs("span",{className:"chat-mention-chip",children:["@",fe.name.replace(/\s+/g,"_")]},`${fe.id}-${ce}`)):o.push(we),y=ce+we.length,$=a.exec(t)}return y<t.length&&o.push(t.slice(y)),o.length===0?t:o},[Fe]),st=s.useCallback(t=>{if(ve.current=t.currentTarget.selectionStart??ve.current,d.mentionActive&&d.files.length>0){if(d.handleKeyDown(t,A),t.key==="Enter"||t.key==="Tab"){const a=d.files[d.selectedIndex];if(a){const o=d.selectFile(a,A);H(o),d.dismissMention(),M(!1)}}return}if(B&&t.key==="ArrowDown"){t.preventDefault(),re.length>0&&u(a=>(a+1)%re.length);return}if(B&&t.key==="ArrowUp"){t.preventDefault(),re.length>0&&u(a=>a===0?re.length-1:a-1);return}if(B&&t.key==="Enter"){t.preventDefault();const a=re[Se]??re[0];a&&Ee(a);return}if(B&&t.key==="Escape"){t.preventDefault(),G(!1),se(""),h(-1);return}if(Q&&t.key==="ArrowDown"){t.preventDefault(),z.length>0&&ie(a=>(a+1)%z.length);return}if(Q&&t.key==="ArrowUp"){t.preventDefault(),z.length>0&&ie(a=>a===0?z.length-1:a-1);return}if(Q&&(t.key==="Enter"||t.key==="Tab")&&z.length>0){t.preventDefault();const a=z[he]??z[0];a&&$e(a);return}if(Q&&t.key==="Escape"){t.preventDefault(),_(!1);return}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Ae())},[B,re,Se,Ee,Q,z,he,$e,Ae,d,A]),Me=s.useCallback((t,a)=>{const o=qt(t,a);if(o){G(!0),se(o.filter),h(o.start);return}G(!1),se(""),h(-1)},[]),nt=s.useCallback(t=>{const a=t.target,o=a.value,y=a.selectionStart??o.length;ve.current=y,H(o);const $=Xe(o);$?(_(!0),ue($.filter)):(_(!1),ue("")),Me(o,y),d.detectMention(o,y),M(d.mentionActive),d.mentionActive&&S(a),a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},[Me]),Pe=s.useCallback(t=>{const a=t.currentTarget,o=a.selectionStart??a.value.length;ve.current=o,Me(a.value,o),d.detectMention(a.value,o),M(d.mentionActive),d.mentionActive&&S(a)},[Me,d,S]),at=s.useCallback(t=>{t.key!=="Escape"&&Pe(t)},[Pe]),it=s.useCallback(()=>{g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{_(!1),G(!1),se(""),h(-1),M(!1),d.dismissMention(),g.current=null},120)},[d]),lt=s.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),rt=s.useCallback(async t=>{ne(null);try{await L(t),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[L,i]),ct=s.useCallback(async t=>{q(null),ne(null);try{await oe(t),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[oe,i]),ot=s.useCallback(t=>{I(t),le&&xe(!1)},[I,le]),dt=s.useCallback(()=>{I(""),xe(!0)},[I]),ut=()=>e.jsxs("div",{className:"chat-empty-state",children:[e.jsx(It,{size:48,strokeWidth:1.5}),e.jsx("h2",{children:"Start a new conversation"}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>K(!0),children:[e.jsx(Le,{size:16}),"New Chat"]})]}),Y=We(c?.modelProvider,c?.modelId),Oe=c?.agentId===Te?Y??"Fusion":c?.title||V.get(c?.agentId??"")?.name||c?.agentId||"Chat",ht=!!(Y&&Y!==Oe),De=V.get(c?.agentId??"")?.name||(c?.agentId===Te?Y??"Fusion":c?.agentId?.slice(0,30)??"Fusion"),He=!!(Y&&Y!==De),mt=T.length>50?`${T.slice(0,50)}…`:T,Ve=s.useCallback(t=>{W(a=>{const o=new Set(a);return o.has(t)?o.delete(t):o.add(t),o})},[]),Be=s.useCallback((t,a=!1)=>a?e.jsx("div",{className:"chat-message-content chat-message-content--plain",children:t}):e.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:e.jsx(At,{remarkPlugins:[$t],components:Ut,children:t})}),[]);return e.jsxs("div",{className:"chat-view",children:[e.jsxs("div",{className:`chat-sidebar${J?"":" chat-sidebar--hidden"}`,children:[e.jsx("div",{className:"chat-sidebar-header",children:e.jsxs("button",{className:"btn btn-sm btn-primary",onClick:()=>K(!0),"data-testid":"chat-new-btn",children:[e.jsx(Le,{size:14}),"New Chat"]})}),e.jsx("div",{className:"chat-sidebar-search",children:e.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[e.jsx(Et,{size:14,className:"chat-sidebar-search-icon"}),e.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:P,onChange:t=>p(t.target.value),"data-testid":"chat-search-input"})]})}),e.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?e.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):D.length===0?e.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):D.map(t=>e.jsxs("div",{className:`chat-session-item${c?.id===t.id?" chat-session-item--active":""}`,onClick:()=>ot(t.id),onContextMenu:a=>{a.preventDefault(),ne({sessionId:t.id,x:a.clientX,y:a.clientY})},"data-testid":`chat-session-${t.id}`,children:[e.jsx("button",{className:"chat-session-delete-btn",onClick:a=>{a.stopPropagation(),q(t.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:e.jsx(Ke,{size:14})}),e.jsx("div",{className:"chat-session-title",children:t.title||"Untitled"}),e.jsx("div",{className:"chat-session-preview",children:t.lastMessagePreview||"No messages"}),e.jsxs("div",{className:"chat-session-meta",children:[e.jsx("span",{children:V.get(t.agentId)?.name||(t.agentId===Te?We(t.modelProvider,t.modelId)??"Fusion":t.agentId.slice(0,30))}),e.jsx("span",{children:t.updatedAt?Qe(t.updatedAt):""})]})]},t.id))}),e.jsx("div",{className:"chat-sidebar-footer",children:e.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>K(!0),"data-testid":"chat-new-btn-mobile",children:[e.jsx(Le,{size:14}),"New Chat"]})})]}),U&&e.jsxs("div",{className:"chat-session-context-menu",style:{top:U.y,left:U.x},onClick:t=>t.stopPropagation(),children:[e.jsxs("button",{onClick:()=>rt(U.sessionId),"data-testid":"chat-context-archive",children:[e.jsx(Pt,{size:14}),"Archive"]}),e.jsxs("button",{onClick:()=>{ne(null),q(U.sessionId)},"data-testid":"chat-context-delete",children:[e.jsx(Ke,{size:14}),"Delete"]})]}),N&&e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>q(null),children:e.jsxs("div",{className:"chat-new-dialog",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{children:"Delete Conversation?"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),e.jsxs("div",{className:"chat-new-dialog-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>q(null),children:"Cancel"}),e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void ct(N),children:"Delete"})]})]})}),e.jsxs("div",{className:"chat-thread",style:Ze,children:[(c||!le)&&e.jsxs("div",{className:"chat-thread-header",children:[le&&c&&e.jsx("button",{className:"btn-icon",onClick:dt,"data-testid":"chat-back-btn",children:e.jsx(Dt,{size:16})}),e.jsx(je,{size:16}),e.jsx("span",{className:"chat-thread-header-title",children:Oe}),ht&&e.jsx("span",{className:"chat-model-tag",children:Y})]}),e.jsxs("div",{className:"chat-messages",ref:R,children:[f?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):r.length===0&&!c?ut():r.length===0&&c?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):e.jsxs(e.Fragment,{children:[r.map(t=>{const a=t.role==="assistant",o=k.has(t.id);return e.jsxs("div",{className:`chat-message chat-message--${t.role}`,"data-testid":`chat-message-${t.id}`,children:[a&&e.jsxs("div",{className:"chat-message-avatar",children:[e.jsx(je,{size:14}),e.jsx("span",{children:De}),He&&e.jsx("span",{className:"chat-model-tag",children:Y}),e.jsx("button",{type:"button",className:`btn btn-icon chat-message-render-toggle${o?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":o?"Show rendered markdown":"Show plain text",onClick:()=>Ve(t.id),children:o?e.jsx(Ue,{size:14}):e.jsx(qe,{size:14})})]}),a?Be(t.content,o):e.jsx("div",{className:"chat-message-content",children:tt(t.content)}),Ye(t.toolCalls),t.thinkingOutput&&e.jsxs("details",{className:"chat-message-thinking",children:[e.jsx("summary",{children:"Thinking"}),e.jsx("pre",{className:"chat-message-thinking-content",children:t.thinkingOutput})]}),e.jsx("div",{className:"chat-message-time",children:Qe(t.createdAt)})]},t.id)}),v&&e.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[e.jsxs("div",{className:"chat-message-avatar",children:[e.jsx(je,{size:14}),e.jsx("span",{children:De}),He&&e.jsx("span",{className:"chat-model-tag",children:Y}),e.jsx("button",{type:"button",className:`btn btn-icon chat-message-render-toggle${k.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":k.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Ve("__streaming__"),children:k.has("__streaming__")?e.jsx(Ue,{size:14}):e.jsx(qe,{size:14})})]}),j?Be(j,k.has("__streaming__")):e.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:w?"Thinking…":"Connecting…"}),Ye(X),w&&e.jsxs("details",{className:"chat-message-thinking",children:[e.jsx("summary",{children:"Thinking"}),e.jsx("pre",{className:"chat-message-thinking-content",children:w})]}),e.jsxs("div",{className:"chat-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})]})]}),e.jsx("div",{ref:b})]}),c&&e.jsxs("div",{className:"chat-input-area",children:[Q&&e.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:Ne?e.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):z.length===0?e.jsx("div",{className:"chat-skill-menu-empty",children:de?"No skills found":"No skills available"}):z.map((t,a)=>e.jsxs("button",{type:"button",role:"option","aria-selected":a===he,className:`chat-skill-menu-item${a===he?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>ie(a),onClick:()=>$e(t),children:[e.jsx("span",{className:"chat-skill-menu-item-name",children:t.name}),e.jsx("span",{className:"chat-skill-menu-item-description",title:t.relativePath,children:t.relativePath})]},t.id))}),e.jsxs("div",{className:"chat-input-wrapper",children:[e.jsx("textarea",{ref:C,className:"chat-input-textarea",placeholder:"Type a message...",value:A,onChange:nt,onKeyDown:st,onKeyUp:at,onClick:Pe,onBlur:it,onFocus:lt,rows:1,"data-testid":"chat-input"}),e.jsx(Rt,{agents:ge,filter:me,highlightedIndex:Se,visible:B,onSelect:Ee,position:"below"}),e.jsx(Lt,{visible:d.mentionActive&&!B,position:be,files:d.files,selectedIndex:d.selectedIndex,onSelect:t=>{const a=d.selectFile(t,A);H(a),d.dismissMention(),M(!1),C.current?.focus()},loading:d.loading}),T&&e.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[e.jsx("span",{children:`Queued: ${mt}`}),e.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:pe,children:"×"})]})]}),v?e.jsx("button",{className:"chat-input-stop",onClick:O,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:e.jsx(_t,{size:14})}):e.jsx("button",{className:"chat-input-send",onClick:()=>void Ae(),disabled:!A.trim(),"data-testid":"chat-send-btn",children:e.jsx(zt,{size:16})})]})]}),Z&&e.jsx(Jt,{projectId:n,onClose:()=>K(!1),onCreate:et})]})}export{Zt as ChatView};
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{i as ze,ay as gt,g as ft,az as pt,a as xt,aA as St,aB as bt,aC as vt,aD as wt,aE as kt,aF as Nt,s as Ct,aG as Mt,aH as jt,aI as yt,f as Tt,a7 as At,a8 as $t,y as Le,S as Et,M as Ke,ak as Pt,aJ as Dt,B as je,a4 as Ue,a5 as qe,aK as Rt,aL as Lt,aM as _t,aN as zt,aO as It,aP as Ft,h as Ot,k as Ht}from"./index-DJDWSrju.js";import"./vendor-xterm-DzcZoU0P.js";const _e="kb-chat-active-session";function Vt(n){const i=n?.toolCalls;if(!Array.isArray(i))return;const c=i.map(l=>{if(!l||typeof l!="object")return null;const r=l,f=typeof r.toolName=="string"?r.toolName:"";if(!f)return null;const v=r.args;return{toolName:f,...v&&typeof v=="object"?{args:v}:{},isError:!!r.isError,result:r.result,status:"completed"}}).filter(l=>l!==null);return c.length>0?c:void 0}function Je(n){return{id:n.id,sessionId:n.sessionId,role:n.role,content:n.content,thinkingOutput:n.thinkingOutput,toolCalls:Vt(n.metadata),createdAt:n.createdAt}}function Bt(n){const[i,c]=s.useState([]),[l,r]=s.useState(null),[f,v]=s.useState(!0),[j,w]=s.useState([]),[X,I]=s.useState(!1),[F,L]=s.useState(!1),[oe,E]=s.useState(""),[O,T]=s.useState(""),[pe,P]=s.useState([]),[p,D]=s.useState(""),[Z,K]=s.useState(""),[A,H]=s.useState(!0),[U,ne]=s.useState(new Map),N=s.useRef(null),q=s.useRef(!1),J=s.useRef(""),xe=s.useRef(i),V=s.useRef(l),ke=s.useRef(F);xe.current=i,V.current=l,ke.current=F,s.useEffect(()=>{J.current=p},[p]);const ae=s.useRef(new Set),ee=s.useRef(0),Ne=s.useRef(n);Ne.current!==n&&(Ne.current=n,ee.current++),s.useEffect(()=>{const u=ee.current;ze(void 0,n).then(m=>{if(ee.current!==u)return;const h=new Map;for(const k of m)h.set(k.id,k);ne(h)}).catch(()=>{})},[n]);const te=s.useCallback(async()=>{v(!0);try{const m=[...(await gt(n)).sessions].sort((h,k)=>new Date(k.updatedAt).getTime()-new Date(h.updatedAt).getTime());c(m)}catch{}finally{v(!1)}},[n]);s.useEffect(()=>{te()},[te]);const Q=s.useRef(()=>{});s.useEffect(()=>{if(f)return;const u=ft(_e,n);u&&i.find(h=>h.id===u)&&Q.current(u)},[f,i,n]);const _=s.useCallback(async(u,m)=>{I(!0);try{const h=await pt(u,{limit:50,...m},n),k=h.messages.map(Je);m?.offset&&m.offset>0?w(W=>[...k,...W]):w(k),H(h.messages.length>=50)}catch{}finally{I(!1)}},[n]),de=s.useCallback(u=>{N.current&&(N.current.close(),N.current=null);const m=i.find(h=>h.id===u);r(m||null),E(""),T(""),P([]),L(!1),H(!0),u?_(u):w([]),u?xt(_e,u,n):St(_e,n)},[i,_,n]);Q.current=de;const ue=s.useCallback(async u=>{const m=await bt(u,n),h={id:m.session.id,title:m.session.title,agentId:m.session.agentId,status:m.session.status,modelProvider:m.session.modelProvider,modelId:m.session.modelId,createdAt:m.session.createdAt,updatedAt:m.session.updatedAt};return c(k=>[h,...k]),r(h),w([]),E(""),T(""),P([]),L(!1),H(!0),h},[n]),he=s.useCallback(async u=>{await vt(u,{status:"archived"},n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),ie=s.useCallback(async u=>{l?.id===u&&N.current&&(N.current.close(),N.current=null),await wt(u,n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),me=s.useCallback(async()=>{!l||!A||await _(l.id,{offset:j.length})},[l,A,_,j.length]),se=s.useCallback(()=>{l&&(q.current=!0,N.current?.close(),N.current=null,kt(l.id,n).catch(()=>{}),L(!1),E(""),T(""),P([]))},[l,n]),B=s.useCallback(()=>{J.current="",D("")},[]),G=s.useCallback(u=>{if(!l)return;if(F){J.current=u,D(u);return}q.current=!1,N.current&&(N.current.close(),N.current=null);const m=`temp-${Date.now()}`,h={id:m,sessionId:l.id,role:"user",content:u,createdAt:new Date().toISOString()};w(x=>[...x,h]),E(""),T(""),P([]),L(!0);let k="",W="",M=[];const be={onThinking:x=>{W+=x,T(W)},onText:x=>{k+=x,E(k)},onToolStart:x=>{M=[...M,{toolName:x.toolName,args:x.args,isError:!1,status:"running"}],P(M)},onToolEnd:x=>{const d=[...M];for(let S=d.length-1;S>=0;S--){const b=d[S];if(b?.toolName===x.toolName&&b.status==="running"){d[S]={...b,status:"completed",isError:x.isError,result:x.result},M=d,P(d);return}}M=[...d,{toolName:x.toolName,isError:x.isError,result:x.result,status:"completed"}],P(M)},onDone:x=>{const d={id:x.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:k,thinkingOutput:W,toolCalls:M.length>0?M:void 0,createdAt:new Date().toISOString()};ae.current.add(d.id),w(b=>[...b,d]),E(""),T(""),P([]),L(!1),N.current=null,setTimeout(()=>{ae.current.delete(d.id)},1e3),te();const S=J.current.trim();S&&(J.current="",D(""),G(S))},onError:x=>{if(w(d=>d.filter(S=>S.id!==m)),E(""),T(""),P([]),L(!1),N.current=null,console.error("[useChat] Stream error:",x),!q.current){const d=J.current.trim();d&&(J.current="",D(""),G(d))}}};N.current=Nt(l.id,u,be,n)},[l,F,n,te]),Se=Z?i.filter(u=>u.title?.toLowerCase().includes(Z.toLowerCase())||u.agentId.toLowerCase().includes(Z.toLowerCase())):i;return s.useEffect(()=>{const u=ee.current,m=n?`?projectId=${encodeURIComponent(n)}`:"",h=()=>ee.current!==u,k=S=>{if(h())return;const b=JSON.parse(S.data);c(g=>g.some(R=>R.id===b.id)?g:[b,...g])},W=S=>{if(h())return;const b=JSON.parse(S.data);c(g=>[...g.map(C=>C.id===b.id?b:C)]),V.current?.id===b.id&&r(b)},M=S=>{if(h())return;const{id:b}=JSON.parse(S.data);c(g=>g.filter(R=>R.id!==b)),V.current?.id===b&&(r(null),w([]))},be=S=>{if(h())return;const b=JSON.parse(S.data),g=Je(b);ae.current.has(g.id)||V.current?.id===g.sessionId&&!ke.current&&w(R=>R.some(C=>C.id===g.id)?R:[...R,g])},x=S=>{if(h())return;const{id:b}=JSON.parse(S.data);w(g=>g.filter(R=>R.id!==b))};return Ct(`/api/events${m}`,{events:{"chat:session:created":k,"chat:session:updated":W,"chat:session:deleted":M,"chat:message:added":be,"chat:message:deleted":x}})},[n]),s.useEffect(()=>()=>{N.current&&(N.current.close(),N.current=null)},[]),{sessions:i,activeSession:l,sessionsLoading:f,messages:j,messagesLoading:X,isStreaming:F,streamingText:oe,streamingThinking:O,streamingToolCalls:pe,pendingMessage:p,selectSession:de,createSession:ue,archiveSession:he,deleteSession:ie,sendMessage:G,stopStreaming:se,clearPendingMessage:B,loadMoreMessages:me,hasMoreMessages:A,searchQuery:Z,setSearchQuery:K,filteredSessions:Se,refreshSessions:te,agentsMap:U}}function Qe(n){const i=new Date(n),l=new Date().getTime()-i.getTime(),r=Math.floor(l/1e3),f=Math.floor(r/60),v=Math.floor(f/60),j=Math.floor(v/24);return r<60?"just now":f<60?`${f}m ago`:v<24?`${v}h ago`:j<7?`${j}d ago`:i.toLocaleDateString()}function We(n,i){if(!n||!i)return null;const c=i.toLowerCase();if(c.includes("claude")){let r=i.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return r=r.replace(/\s+/g," "),r.length>30?r.slice(0,30)+"…":r}if(c.includes("gpt")||c.includes("openai")){const r=i.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return r.length>30?r.slice(0,30)+"…":r}if(c.includes("gemini")){const r=i.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return r.length>30?r.slice(0,30)+"…":r}const l=i.replace(/-/g," ").replace(/^\w/,r=>r.toUpperCase()).replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}function ye(n,i){return n.length>i?`${n.slice(0,i)}…`:n}function Gt(n){if(!n)return null;const i=Object.entries(n);return i.length===0?null:i.map(([c,l])=>{let r="";if(typeof l=="string")r=l;else try{r=JSON.stringify(l)}catch{r=String(l)}return`${c}=${ye(r,50)}`}).join(", ")}function Kt(n){if(n===void 0)return null;if(typeof n=="string")return ye(n,200);try{return ye(JSON.stringify(n),200)}catch{return ye(String(n),200)}}function Ye(n){return!n||n.length===0?null:e.jsxs("div",{className:"chat-tool-calls","data-testid":"chat-tool-calls",children:[e.jsxs("div",{className:"chat-tool-calls-header",children:[e.jsx(Ft,{size:12,"aria-hidden":"true"}),e.jsx("span",{children:"Tool calls"})]}),n.map((i,c)=>{const l=i.status==="running",r=i.status==="completed"&&i.isError,f=Gt(i.args),v=Kt(i.result),j=l?f:v?`result: ${v}`:f?`args: ${f}`:null,w=l?"running":r?"error":"completed";return e.jsxs("details",{className:`chat-tool-call${l?" chat-tool-call--running":""}${r?" chat-tool-call--error":""}`,open:l,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),e.jsx("span",{className:"chat-tool-call-name",children:i.toolName}),j&&e.jsx("span",{className:"chat-tool-call-preview",title:j,children:j}),e.jsx("span",{className:"chat-tool-call-status-text",children:w})]}),e.jsxs("div",{className:"chat-tool-call-content",children:[f&&e.jsxs("div",{className:"chat-tool-call-row",children:[e.jsx("span",{className:"chat-tool-call-label",children:"args"}),e.jsx("span",{className:"chat-tool-call-value",children:f})]}),v&&e.jsxs("div",{className:`chat-tool-call-row${r?" chat-tool-call-row--error":""}`,children:[e.jsx("span",{className:"chat-tool-call-label",children:"result"}),e.jsx("span",{className:"chat-tool-call-value",children:v})]})]})]},`${i.toolName}-${c}`)})]})}const Ut={pre:({children:n,...i})=>e.jsx("pre",{...i,className:"chat-markdown-pre",children:n}),table:({children:n,...i})=>e.jsx("table",{...i,className:"chat-markdown-table",children:n})},Te="__fn_agent__";function Xe(n){const i=/(^|[\s])\/([^\s]*)$/.exec(n);if(!i)return null;const c=i[1]??"",l=i[2]??"",r=i.index+c.length;return{filter:l,start:r,end:n.length}}function qt(n,i){const c=n.slice(0,i),l=/(^|[\s\n])@([\w-]*)$/.exec(c);if(!l)return null;const r=l[2]??"",f=c.length-r.length-1;return{filter:r,start:f,end:i}}function Jt({projectId:n,onClose:i,onCreate:c}){const[l,r]=s.useState("agent"),[f,v]=s.useState([]),[j,w]=s.useState(!0),[X,I]=s.useState(""),[F,L]=s.useState([]),[oe,E]=s.useState(!0),[O,T]=s.useState("");s.useEffect(()=>{let p=!1;return w(!0),ze(void 0,n).then(D=>{p||v(D)}).catch(()=>{p||v([])}).finally(()=>{p||w(!1)}),()=>{p=!0}},[n]),s.useEffect(()=>{E(!0),Ot().then(p=>{L(p.models)}).catch(()=>{L([])}).finally(()=>{E(!1)})},[]);const pe=p=>{if(p.preventDefault(),l==="agent"){if(!X)return;c({agentId:X});return}if(!O)return;const D=O.indexOf("/");if(D<=0)return;const Z=O.slice(0,D),K=O.slice(D+1);c({agentId:Te,modelProvider:Z,modelId:K})},P=l==="agent"?!X:!O;return e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"chat-new-dialog",onClick:p=>p.stopPropagation(),children:[e.jsx("h3",{children:"New Chat"}),e.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[e.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{r("agent"),T("")},children:"Agent"}),e.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{r("model"),I("")},children:"Model"})]}),e.jsxs("form",{onSubmit:pe,children:[l==="agent"&&e.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",j?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):f.length===0?e.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):e.jsx("div",{className:"chat-new-dialog-agent-list",children:f.map(p=>e.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${X===p.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>I(p.id),"data-testid":`agent-option-${p.id}`,children:[e.jsx(je,{size:16}),e.jsx("span",{className:"chat-new-dialog-agent-name",children:p.name}),e.jsx("span",{className:"chat-new-dialog-agent-role",children:p.role})]},p.id))})]}),l==="model"&&e.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:oe?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):e.jsx(Ht,{models:F,value:O,onChange:T,label:"Model",placeholder:"Select a model"})}),e.jsxs("div",{className:"chat-new-dialog-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:P,children:"Create"})]})]})]})})}function Zt({projectId:n,addToast:i}){const{activeSession:c,sessionsLoading:l,messages:r,messagesLoading:f,isStreaming:v,streamingText:j,streamingThinking:w,streamingToolCalls:X,selectSession:I,createSession:F,archiveSession:L,deleteSession:oe,sendMessage:E,stopStreaming:O,pendingMessage:T,clearPendingMessage:pe,searchQuery:P,setSearchQuery:p,filteredSessions:D}=Bt(n),[Z,K]=s.useState(!1),[A,H]=s.useState(""),[U,ne]=s.useState(null),[N,q]=s.useState(null),[J,xe]=s.useState(!0),[V,ke]=s.useState(new Map),[ae,ee]=s.useState([]),[Ne,te]=s.useState(!0),[Q,_]=s.useState(!1),[de,ue]=s.useState(""),[he,ie]=s.useState(0),[me,se]=s.useState(""),[B,G]=s.useState(!1),[Se,u]=s.useState(0),[m,h]=s.useState(-1),[k,W]=s.useState(()=>new Set),[,M]=s.useState(!1),[be,x]=s.useState({top:0,left:0}),d=Mt({projectId:n}),S=s.useCallback(t=>{if(!t||!d.mentionActive)return;const a=t.getBoundingClientRect();x({top:a.top-260,left:a.left+8})},[d.mentionActive]),b=s.useRef(null),g=s.useRef(null),R=s.useRef(null),C=s.useRef(null),ve=s.useRef(0),le=jt()==="mobile",{keyboardOverlap:Ce,viewportHeight:Ie}=yt({enabled:le&&!!c}),Ze=Ce>0?{"--keyboard-overlap":`${Ce}px`,...Ie!==null?{"--vv-height":`${Ie}px`}:{}}:{},z=s.useMemo(()=>{const t=de.trim().toLowerCase();return(t?ae.filter(o=>o.name.toLowerCase().includes(t)):ae).slice(0,10)},[ae,de]),ge=s.useMemo(()=>Array.from(V.values()),[V]),re=s.useMemo(()=>{const t=me.trim().toLowerCase();return t?ge.filter(a=>a.name.toLowerCase().includes(t)):ge},[ge,me]),Fe=s.useMemo(()=>{const t=new Map;for(const a of ge)t.set(a.name.toLowerCase(),a);return t},[ge]);s.useEffect(()=>{ie(0)},[z]),s.useEffect(()=>{u(0)},[me,B]),s.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current)},[]),s.useEffect(()=>{b.current?.scrollIntoView({behavior:"smooth"})},[r,j]),s.useEffect(()=>{if(Ce<=0)return;const t=R.current;t&&(t.scrollTop=t.scrollHeight)},[Ce]),s.useEffect(()=>{const t=()=>ne(null);if(U)return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[U]),s.useEffect(()=>{let t=!1;const a=n;return ze(void 0,n).then(o=>{if(t||a!==n)return;const y=new Map;for(const $ of o)y.set($.id,$);ke(y)}).catch(()=>{}),()=>{t=!0}},[n]),s.useEffect(()=>{let t=!1;return te(!0),Tt(n).then(a=>{t||ee(a)}).catch(()=>{t||ee([])}).finally(()=>{t||te(!1)}),()=>{t=!0}},[n]);const et=s.useCallback(async t=>{try{await F(t),K(!1),le&&xe(!1)}catch{i("Failed to create chat session","error")}},[F,i,le]),Ae=s.useCallback(()=>{const t=A.trim();!t||!c||(H(""),_(!1),ue(""),G(!1),se(""),h(-1),E(t))},[A,c,E]),$e=s.useCallback(t=>{H(a=>{const o=Xe(a);if(!o)return a;const y=`/skill:${t.name} `,$=a.slice(0,o.start)+y+a.slice(o.end);return window.requestAnimationFrame(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,120)}px`,C.current.focus())}),$}),_(!1),ue(""),ie(0)},[]),Ee=s.useCallback(t=>{const a=C.current;if(!a||m<0)return;const o=a.selectionStart??ve.current,y=a.selectionEnd??o,$=Math.max(o,y),we=Math.min(m,$),ce=`${`@${t.name.replace(/\s+/g,"_")}`} `,Re=A.slice(0,we)+ce+A.slice($),fe=we+ce.length;H(Re),G(!1),se(""),u(0),h(-1),window.requestAnimationFrame(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,120)}px`,C.current.focus(),C.current.setSelectionRange(fe,fe))})},[m,A]),tt=s.useCallback(t=>{const a=/@([\w-]+)/g,o=[];let y=0,$=a.exec(t);for(;$;){const[we,Ge=""]=$,ce=$.index;ce>y&&o.push(t.slice(y,ce));const Re=Ge.replace(/_/g," ").toLowerCase(),fe=Fe.get(Re);fe?o.push(e.jsxs("span",{className:"chat-mention-chip",children:["@",fe.name.replace(/\s+/g,"_")]},`${fe.id}-${ce}`)):o.push(we),y=ce+we.length,$=a.exec(t)}return y<t.length&&o.push(t.slice(y)),o.length===0?t:o},[Fe]),st=s.useCallback(t=>{if(ve.current=t.currentTarget.selectionStart??ve.current,d.mentionActive&&d.files.length>0){if(d.handleKeyDown(t,A),t.key==="Enter"||t.key==="Tab"){const a=d.files[d.selectedIndex];if(a){const o=d.selectFile(a,A);H(o),d.dismissMention(),M(!1)}}return}if(B&&t.key==="ArrowDown"){t.preventDefault(),re.length>0&&u(a=>(a+1)%re.length);return}if(B&&t.key==="ArrowUp"){t.preventDefault(),re.length>0&&u(a=>a===0?re.length-1:a-1);return}if(B&&t.key==="Enter"){t.preventDefault();const a=re[Se]??re[0];a&&Ee(a);return}if(B&&t.key==="Escape"){t.preventDefault(),G(!1),se(""),h(-1);return}if(Q&&t.key==="ArrowDown"){t.preventDefault(),z.length>0&&ie(a=>(a+1)%z.length);return}if(Q&&t.key==="ArrowUp"){t.preventDefault(),z.length>0&&ie(a=>a===0?z.length-1:a-1);return}if(Q&&(t.key==="Enter"||t.key==="Tab")&&z.length>0){t.preventDefault();const a=z[he]??z[0];a&&$e(a);return}if(Q&&t.key==="Escape"){t.preventDefault(),_(!1);return}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Ae())},[B,re,Se,Ee,Q,z,he,$e,Ae,d,A]),Me=s.useCallback((t,a)=>{const o=qt(t,a);if(o){G(!0),se(o.filter),h(o.start);return}G(!1),se(""),h(-1)},[]),nt=s.useCallback(t=>{const a=t.target,o=a.value,y=a.selectionStart??o.length;ve.current=y,H(o);const $=Xe(o);$?(_(!0),ue($.filter)):(_(!1),ue("")),Me(o,y),d.detectMention(o,y),M(d.mentionActive),d.mentionActive&&S(a),a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},[Me]),Pe=s.useCallback(t=>{const a=t.currentTarget,o=a.selectionStart??a.value.length;ve.current=o,Me(a.value,o),d.detectMention(a.value,o),M(d.mentionActive),d.mentionActive&&S(a)},[Me,d,S]),at=s.useCallback(t=>{t.key!=="Escape"&&Pe(t)},[Pe]),it=s.useCallback(()=>{g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{_(!1),G(!1),se(""),h(-1),M(!1),d.dismissMention(),g.current=null},120)},[d]),lt=s.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),rt=s.useCallback(async t=>{ne(null);try{await L(t),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[L,i]),ct=s.useCallback(async t=>{q(null),ne(null);try{await oe(t),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[oe,i]),ot=s.useCallback(t=>{I(t),le&&xe(!1)},[I,le]),dt=s.useCallback(()=>{I(""),xe(!0)},[I]),ut=()=>e.jsxs("div",{className:"chat-empty-state",children:[e.jsx(It,{size:48,strokeWidth:1.5}),e.jsx("h2",{children:"Start a new conversation"}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>K(!0),children:[e.jsx(Le,{size:16}),"New Chat"]})]}),Y=We(c?.modelProvider,c?.modelId),Oe=c?.agentId===Te?Y??"Fusion":c?.title||V.get(c?.agentId??"")?.name||c?.agentId||"Chat",ht=!!(Y&&Y!==Oe),De=V.get(c?.agentId??"")?.name||(c?.agentId===Te?Y??"Fusion":c?.agentId?.slice(0,30)??"Fusion"),He=!!(Y&&Y!==De),mt=T.length>50?`${T.slice(0,50)}…`:T,Ve=s.useCallback(t=>{W(a=>{const o=new Set(a);return o.has(t)?o.delete(t):o.add(t),o})},[]),Be=s.useCallback((t,a=!1)=>a?e.jsx("div",{className:"chat-message-content chat-message-content--plain",children:t}):e.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:e.jsx(At,{remarkPlugins:[$t],components:Ut,children:t})}),[]);return e.jsxs("div",{className:"chat-view",children:[e.jsxs("div",{className:`chat-sidebar${J?"":" chat-sidebar--hidden"}`,children:[e.jsx("div",{className:"chat-sidebar-header",children:e.jsxs("button",{className:"btn btn-sm btn-primary",onClick:()=>K(!0),"data-testid":"chat-new-btn",children:[e.jsx(Le,{size:14}),"New Chat"]})}),e.jsx("div",{className:"chat-sidebar-search",children:e.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[e.jsx(Et,{size:14,className:"chat-sidebar-search-icon"}),e.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:P,onChange:t=>p(t.target.value),"data-testid":"chat-search-input"})]})}),e.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?e.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):D.length===0?e.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):D.map(t=>e.jsxs("div",{className:`chat-session-item${c?.id===t.id?" chat-session-item--active":""}`,onClick:()=>ot(t.id),onContextMenu:a=>{a.preventDefault(),ne({sessionId:t.id,x:a.clientX,y:a.clientY})},"data-testid":`chat-session-${t.id}`,children:[e.jsx("button",{className:"chat-session-delete-btn",onClick:a=>{a.stopPropagation(),q(t.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:e.jsx(Ke,{size:14})}),e.jsx("div",{className:"chat-session-title",children:t.title||"Untitled"}),e.jsx("div",{className:"chat-session-preview",children:t.lastMessagePreview||"No messages"}),e.jsxs("div",{className:"chat-session-meta",children:[e.jsx("span",{children:V.get(t.agentId)?.name||(t.agentId===Te?We(t.modelProvider,t.modelId)??"Fusion":t.agentId.slice(0,30))}),e.jsx("span",{children:t.updatedAt?Qe(t.updatedAt):""})]})]},t.id))}),e.jsx("div",{className:"chat-sidebar-footer",children:e.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>K(!0),"data-testid":"chat-new-btn-mobile",children:[e.jsx(Le,{size:14}),"New Chat"]})})]}),U&&e.jsxs("div",{className:"chat-session-context-menu",style:{top:U.y,left:U.x},onClick:t=>t.stopPropagation(),children:[e.jsxs("button",{onClick:()=>rt(U.sessionId),"data-testid":"chat-context-archive",children:[e.jsx(Pt,{size:14}),"Archive"]}),e.jsxs("button",{onClick:()=>{ne(null),q(U.sessionId)},"data-testid":"chat-context-delete",children:[e.jsx(Ke,{size:14}),"Delete"]})]}),N&&e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>q(null),children:e.jsxs("div",{className:"chat-new-dialog",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{children:"Delete Conversation?"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),e.jsxs("div",{className:"chat-new-dialog-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>q(null),children:"Cancel"}),e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void ct(N),children:"Delete"})]})]})}),e.jsxs("div",{className:"chat-thread",style:Ze,children:[(c||!le)&&e.jsxs("div",{className:"chat-thread-header",children:[le&&c&&e.jsx("button",{className:"btn-icon",onClick:dt,"data-testid":"chat-back-btn",children:e.jsx(Dt,{size:16})}),e.jsx(je,{size:16}),e.jsx("span",{className:"chat-thread-header-title",children:Oe}),ht&&e.jsx("span",{className:"chat-model-tag",children:Y})]}),e.jsxs("div",{className:"chat-messages",ref:R,children:[f?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):r.length===0&&!c?ut():r.length===0&&c?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):e.jsxs(e.Fragment,{children:[r.map(t=>{const a=t.role==="assistant",o=k.has(t.id);return e.jsxs("div",{className:`chat-message chat-message--${t.role}`,"data-testid":`chat-message-${t.id}`,children:[a&&e.jsxs("div",{className:"chat-message-avatar",children:[e.jsx(je,{size:14}),e.jsx("span",{children:De}),He&&e.jsx("span",{className:"chat-model-tag",children:Y}),e.jsx("button",{type:"button",className:`btn btn-icon chat-message-render-toggle${o?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":o?"Show rendered markdown":"Show plain text",onClick:()=>Ve(t.id),children:o?e.jsx(Ue,{size:14}):e.jsx(qe,{size:14})})]}),a?Be(t.content,o):e.jsx("div",{className:"chat-message-content",children:tt(t.content)}),Ye(t.toolCalls),t.thinkingOutput&&e.jsxs("details",{className:"chat-message-thinking",children:[e.jsx("summary",{children:"Thinking"}),e.jsx("pre",{className:"chat-message-thinking-content",children:t.thinkingOutput})]}),e.jsx("div",{className:"chat-message-time",children:Qe(t.createdAt)})]},t.id)}),v&&e.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[e.jsxs("div",{className:"chat-message-avatar",children:[e.jsx(je,{size:14}),e.jsx("span",{children:De}),He&&e.jsx("span",{className:"chat-model-tag",children:Y}),e.jsx("button",{type:"button",className:`btn btn-icon chat-message-render-toggle${k.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":k.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Ve("__streaming__"),children:k.has("__streaming__")?e.jsx(Ue,{size:14}):e.jsx(qe,{size:14})})]}),j?Be(j,k.has("__streaming__")):e.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:w?"Thinking…":"Connecting…"}),Ye(X),w&&e.jsxs("details",{className:"chat-message-thinking",children:[e.jsx("summary",{children:"Thinking"}),e.jsx("pre",{className:"chat-message-thinking-content",children:w})]}),e.jsxs("div",{className:"chat-typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})]})]}),e.jsx("div",{ref:b})]}),c&&e.jsxs("div",{className:"chat-input-area",children:[Q&&e.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:Ne?e.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):z.length===0?e.jsx("div",{className:"chat-skill-menu-empty",children:de?"No skills found":"No skills available"}):z.map((t,a)=>e.jsxs("button",{type:"button",role:"option","aria-selected":a===he,className:`chat-skill-menu-item${a===he?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>ie(a),onClick:()=>$e(t),children:[e.jsx("span",{className:"chat-skill-menu-item-name",children:t.name}),e.jsx("span",{className:"chat-skill-menu-item-description",title:t.relativePath,children:t.relativePath})]},t.id))}),e.jsxs("div",{className:"chat-input-wrapper",children:[e.jsx("textarea",{ref:C,className:"chat-input-textarea",placeholder:"Type a message...",value:A,onChange:nt,onKeyDown:st,onKeyUp:at,onClick:Pe,onBlur:it,onFocus:lt,rows:1,"data-testid":"chat-input"}),e.jsx(Rt,{agents:ge,filter:me,highlightedIndex:Se,visible:B,onSelect:Ee,position:"below"}),e.jsx(Lt,{visible:d.mentionActive&&!B,position:be,files:d.files,selectedIndex:d.selectedIndex,onSelect:t=>{const a=d.selectFile(t,A);H(a),d.dismissMention(),M(!1),C.current?.focus()},loading:d.loading}),T&&e.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[e.jsx("span",{children:`Queued: ${mt}`}),e.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:pe,children:"×"})]})]}),v?e.jsx("button",{className:"chat-input-stop",onClick:O,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:e.jsx(_t,{size:14})}):e.jsx("button",{className:"chat-input-send",onClick:()=>void Ae(),disabled:!A.trim(),"data-testid":"chat-send-btn",children:e.jsx(zt,{size:16})})]})]}),Z&&e.jsx(Jt,{projectId:n,onClose:()=>K(!1),onCreate:et})]})}export{Zt as ChatView};
@@ -1,4 +1,4 @@
1
- import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as Ze,bp as De,bq as de,br as et,bs as ue,s as Me,bt as ge,bu as we,bv as xe,bw as ye,bx as tt,by as ae,bz as rt,bA as st,bB as nt,bC as at,bD as it,bE as ie,L as ee,S as lt,bF as ct,bG as ot,N as dt,bH as Ue,T as Ae,bI as ut,J as vt,aM as mt,a5 as ft,aj as pt,R as ht}from"./index-BTeSa6vk.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as Ze,bp as De,bq as de,br as et,bs as ue,s as Me,bt as ge,bu as we,bv as xe,bw as ye,bx as tt,by as ae,bz as rt,bA as st,bB as nt,bC as at,bD as it,bE as ie,L as ee,S as lt,bF as ct,bG as ot,N as dt,bH as Ue,T as Ae,bI as ut,J as vt,aM as mt,a5 as ft,aj as pt,R as ht}from"./index-DJDWSrju.js";import"./vendor-xterm-DzcZoU0P.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{dl as f,cv as m,H as y,a9 as g,a4 as P,a5 as H,L as C,ag as O}from"./index-BTeSa6vk.js";import{F as v}from"./folder-open-CrTagHrr.js";function B({value:d,onChange:l,placeholder:x,onInputKeyDown:j,nodeId:h,localNodeId:p}){const[e,n]=i.useState({isOpen:!1,loading:!1,error:null,currentPath:"",parentPath:null,entries:[],showHidden:!1}),a=i.useCallback(async(s,c=!1)=>{n(t=>({...t,loading:!0,error:null}));try{const t=await f(s,c,h,p);n(b=>({...b,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(b=>({...b,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[h,p]),k=i.useCallback(()=>{n(s=>s.isOpen?{...s,isOpen:!1}:{...s,isOpen:!0})},[]);i.useEffect(()=>{e.isOpen&&!e.loading&&e.entries.length===0&&!e.error&&a(d||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,d,e.showHidden,a,h,p]);const o=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),w=i.useCallback(()=>{l(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,l]),N=i.useCallback(()=>{n(s=>{const c=!s.showHidden;return{...s,showHidden:c}})},[]);i.useEffect(()=>{e.isOpen&&e.currentPath&&a(e.currentPath,e.showHidden)},[e.showHidden]);const u=e.currentPath?e.currentPath.split("/").filter(Boolean):[];return r.jsxs("div",{className:"directory-picker",children:[r.jsxs("div",{className:"directory-picker-input-row",children:[r.jsx("input",{type:"text",className:"input directory-picker-input",value:d,onChange:s=>l(s.target.value),onKeyDown:j,placeholder:x||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:k,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(v,{size:16}):r.jsx(m,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsxs("div",{className:"directory-picker-breadcrumbs",children:[r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o("/"),title:"Root",children:"/"}),u.map((s,c)=>{const t="/"+u.slice(0,c+1).join("/");return r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o(t),title:t,children:s})]},t)})]}),r.jsxs("div",{className:"directory-picker-toolbar",children:[e.parentPath&&r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-up-btn",onClick:()=>o(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(g,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:N,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(P,{size:14}):r.jsx(H,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(C,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(O,{size:16}),r.jsx("span",{children:e.error})]}):r.jsx("div",{className:"directory-picker-entries",children:e.entries.length===0?r.jsx("div",{className:"directory-picker-empty",children:"No subdirectories"}):e.entries.map(s=>r.jsxs("button",{type:"button",className:"directory-picker-entry",onClick:()=>o(s.path),role:"treeitem",title:s.path,children:[r.jsx(m,{size:16,className:"directory-picker-entry-icon"}),r.jsx("span",{className:"directory-picker-entry-name",children:s.name}),s.hasChildren&&r.jsx(y,{size:14,className:"directory-picker-entry-arrow"})]},s.path))}),r.jsxs("div",{className:"directory-picker-actions",children:[r.jsx("span",{className:"directory-picker-selected-path",title:e.currentPath,children:e.currentPath}),r.jsx("button",{type:"button",className:"btn btn-primary directory-picker-select-btn",onClick:w,children:"Select"})]})]})]})}export{B as D};
1
+ import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{dp as f,cy as m,H as y,a9 as g,a4 as P,a5 as H,L as C,ag as O}from"./index-DJDWSrju.js";import{F as v}from"./folder-open-C3zB1vmh.js";function B({value:d,onChange:l,placeholder:x,onInputKeyDown:j,nodeId:h,localNodeId:p}){const[e,n]=i.useState({isOpen:!1,loading:!1,error:null,currentPath:"",parentPath:null,entries:[],showHidden:!1}),a=i.useCallback(async(s,c=!1)=>{n(t=>({...t,loading:!0,error:null}));try{const t=await f(s,c,h,p);n(b=>({...b,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(b=>({...b,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[h,p]),k=i.useCallback(()=>{n(s=>s.isOpen?{...s,isOpen:!1}:{...s,isOpen:!0})},[]);i.useEffect(()=>{e.isOpen&&!e.loading&&e.entries.length===0&&!e.error&&a(d||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,d,e.showHidden,a,h,p]);const o=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),w=i.useCallback(()=>{l(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,l]),N=i.useCallback(()=>{n(s=>{const c=!s.showHidden;return{...s,showHidden:c}})},[]);i.useEffect(()=>{e.isOpen&&e.currentPath&&a(e.currentPath,e.showHidden)},[e.showHidden]);const u=e.currentPath?e.currentPath.split("/").filter(Boolean):[];return r.jsxs("div",{className:"directory-picker",children:[r.jsxs("div",{className:"directory-picker-input-row",children:[r.jsx("input",{type:"text",className:"input directory-picker-input",value:d,onChange:s=>l(s.target.value),onKeyDown:j,placeholder:x||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:k,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(v,{size:16}):r.jsx(m,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsxs("div",{className:"directory-picker-breadcrumbs",children:[r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o("/"),title:"Root",children:"/"}),u.map((s,c)=>{const t="/"+u.slice(0,c+1).join("/");return r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o(t),title:t,children:s})]},t)})]}),r.jsxs("div",{className:"directory-picker-toolbar",children:[e.parentPath&&r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-up-btn",onClick:()=>o(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(g,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:N,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(P,{size:14}):r.jsx(H,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(C,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(O,{size:16}),r.jsx("span",{children:e.error})]}):r.jsx("div",{className:"directory-picker-entries",children:e.entries.length===0?r.jsx("div",{className:"directory-picker-empty",children:"No subdirectories"}):e.entries.map(s=>r.jsxs("button",{type:"button",className:"directory-picker-entry",onClick:()=>o(s.path),role:"treeitem",title:s.path,children:[r.jsx(m,{size:16,className:"directory-picker-entry-icon"}),r.jsx("span",{className:"directory-picker-entry-name",children:s.name}),s.hasChildren&&r.jsx(y,{size:14,className:"directory-picker-entry-arrow"})]},s.path))}),r.jsxs("div",{className:"directory-picker-actions",children:[r.jsx("span",{className:"directory-picker-selected-path",title:e.currentPath,children:e.currentPath}),r.jsx("button",{type:"button",className:"btn btn-primary directory-picker-select-btn",onClick:w,children:"Select"})]})]})]})}export{B as D};
@@ -1 +1 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a0 as oe,a1 as K,a2 as le,a3 as ie,F as z,a4 as de,a5 as ue,S as me,X as he,R as pe,a6 as fe,a7 as W,a8 as V,N as X,H as je,a9 as xe}from"./index-BTeSa6vk.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?K(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await K(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function _(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:_(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:J,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:Y,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?Y:J,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,G=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:G,value:l,onChange:Z,"aria-label":G}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",_(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a0 as oe,a1 as K,a2 as le,a3 as ie,F as z,a4 as de,a5 as ue,S as me,X as he,R as pe,a6 as fe,a7 as W,a8 as V,N as X,H as je,a9 as xe}from"./index-DJDWSrju.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?K(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await K(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function _(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:_(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:J,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:Y,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?Y:J,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,G=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:G,value:l,onChange:Z,"aria-label":G}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",_(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
@@ -1,4 +1,4 @@
1
- import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,aa as Q,ab as V,ac as W,ad as X,ae as J,af as x,X as T,R as j,C as q,ag as F,ah as G,ai as K,y as B,aj as Z,ak as ss,al as P}from"./index-BTeSa6vk.js";import{U as _}from"./users-4d8al5Sp.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,aa as Q,ab as V,ac as W,ad as X,ae as J,af as x,X as T,R as j,C as q,ag as F,ah as G,ai as K,y as B,aj as Z,ak as ss,al as P}from"./index-DJDWSrju.js";import{U as _}from"./users-DWWgd19M.js";import"./vendor-xterm-DzcZoU0P.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,2 +1,2 @@
1
- import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Ae}from"./SettingsModal-fmRtzH8z.js";import{bb as Se,bc as Ne,bd as Fe,q as De,be as ze,bf as Ie,bg as Le,bh as Ce,bi as ke,bj as Re,bk as qe,bl as Ee,bm as Pe,p as Te,bn as We,L as A,bo as Me}from"./index-BTeSa6vk.js";import"./vendor-xterm-DzcZoU0P.js";const U=".fusion/memory/MEMORY.md",_e=5e4,Oe="0 3 * * *",Ue="0 4 * * *";function me(l){return{memoryEnabled:l.memoryEnabled!==!1,memoryAutoSummarizeEnabled:l.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:l.memoryAutoSummarizeThresholdChars??_e,memoryAutoSummarizeSchedule:l.memoryAutoSummarizeSchedule??Oe,memoryDreamsEnabled:l.memoryDreamsEnabled??!1,memoryDreamsSchedule:l.memoryDreamsSchedule??Ue}}function we(l,t){return l.some(c=>c.path===t)?t:l.find(c=>c.path===U)?.path??l[0]?.path??U}function Qe(l={}){const{projectId:t}=l,[c,p]=a.useState(""),[F,k]=a.useState(!0),[S,N]=a.useState(!1),[y,g]=a.useState(!1),[i,b]=a.useState(null),[Q,J]=a.useState(!0),[X,D]=a.useState(!1),[f,q]=a.useState(()=>me({})),[E,ee]=a.useState(!0),[ce,H]=a.useState(!1),[o,j]=a.useState([]),[se,z]=a.useState(!0),[m,C]=a.useState(U),[P,u]=a.useState(""),[d,te]=a.useState(!1),[$,x]=a.useState(!1),[ae,Y]=a.useState(!1),[ne,B]=a.useState(!1),[G,T]=a.useState(null),[M,W]=a.useState(!0),[oe,I]=a.useState(!1),[de,V]=a.useState(!1),[ie,Z]=a.useState(null),{status:K,loading:v,refresh:re}=Ae({projectId:t}),L=a.useCallback(n=>{u(n),x(!0)},[]),_=a.useCallback(async n=>{te(!0);try{const{content:s}=await Se(n,t);C(n),u(s),x(!1)}finally{te(!1)}},[t]),w=a.useCallback(async()=>{z(!0);try{const{files:n}=await Ne(t);if(j(n),n.length===0){C(U),u(""),x(!1);return}const s=we(n,m);s!==m&&await _(s)}finally{z(!1)}},[t,m,_]);a.useEffect(()=>{let n=!1;async function s(){try{const r=await Pe(t);n||(p(r.content),k(!1))}catch{n||(p(""),k(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await ke(t);n||(b(r.content),D(r.exists),J(!1))}catch{n||(b(null),D(!1),J(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){ee(!0);try{const r=await Te(t);n||q(me(r))}catch{n||q(me({}))}finally{n||ee(!1)}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){z(!0);try{const{files:r}=await Ne(t);if(n)return;if(j(r),r.length===0){C(U),u(""),x(!1);return}const h=we(r,m),{content:ve}=await Se(h,t);if(n)return;C(h),u(ve),x(!1)}catch{n||(j([]),C(U),u(""),x(!1))}finally{n||z(!1)}}return s(),()=>{n=!0}},[t,m]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await Ce(t);n||(T(r),W(!1))}catch{n||(T(null),W(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await We(t);n||Z(r)}catch{n||Z(null)}}return s(),()=>{n=!0}},[t]);const le=a.useCallback(n=>{p(n),N(!0)},[]),he=a.useCallback(async()=>{if(S){g(!0);try{await Fe(c,t),N(!1)}finally{g(!1)}}},[c,S,t]),ue=a.useCallback(async n=>{H(!0);try{const s=await De(n,t);q(me(s))}finally{H(!1)}},[t]),ye=a.useCallback(async n=>{await _(n)},[_]),ge=a.useCallback(async()=>{if($){Y(!0);try{await ze(m,P,t),x(!1),await w()}finally{Y(!1)}}},[P,$,m,t,w]),be=a.useCallback(async()=>{V(!0);try{const n=await Ie(t);return await re(),n}finally{V(!1)}},[t,re]),xe=a.useCallback(async n=>Le(n,t),[t]),O=a.useCallback(async()=>{try{const n=await Ce(t);T(n)}catch{T(null)}},[t]),R=a.useCallback(async()=>{try{const n=await ke(t);b(n.content),D(n.exists)}catch{b(null),D(!1)}},[t]),pe=a.useCallback(async n=>{await Re(n,t),await R()},[t,R]),fe=a.useCallback(async()=>{B(!0);try{const n=await qe(t);return await Promise.all([R(),O()]),{success:n.success,summary:n.summary}}finally{B(!1)}},[t,R,O]),je=a.useCallback(async n=>{I(!0);try{const s=n?await Ee(n,t):await Ee(t);if(n){const r=s.path??n;C(r),u(s.content),x(!1),await w();return}p(s.content),N(!0)}finally{I(!1)}},[t,w]);return{workingMemory:c,workingMemoryLoading:F,workingMemoryDirty:S,setWorkingMemory:le,saveWorkingMemory:he,savingWorkingMemory:y,insightsContent:i,insightsLoading:Q,insightsExists:X,refreshInsights:R,saveInsights:pe,memorySettings:f,settingsLoading:E,savingMemorySettings:ce,saveMemorySettings:ue,memoryFiles:o,memoryFilesLoading:se,selectedFilePath:m,selectedFileContent:P,selectedFileLoading:d,selectedFileDirty:$,setSelectedFileContent:L,selectFile:ye,saveSelectedFile:ge,savingSelectedFile:ae,reloadMemoryFiles:w,backendStatus:K,backendLoading:v,extractInsights:fe,extracting:ne,auditReport:G,auditLoading:M,refreshAudit:O,compactMemory:je,compacting:oe,installQmdAction:be,installingQmd:de,testRetrieval:xe,stats:ie}}const He={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},$e={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Ye={"long-term":"Curated durable decisions, conventions, constraints, and pitfalls promoted from dreams.",daily:"Raw daily observations, open loops, and running context for dream processing.",dreams:"Synthesized patterns and open loops promoted from daily memory."};function Be(l){if(!l)return[];const t=[],c=l.split(/(?=^## )/m);for(const p of c){const F=p.trim();if(!F)continue;const k=F.match(/^##\s+(.+?)(\n|$)/);if(k){const S=k[1].trim(),N=He[S]??S.toLowerCase(),y=F.slice(k[0].length).trim(),g=y.split(`
1
+ import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Ae}from"./SettingsModal-Cx3iMWDs.js";import{bb as Se,bc as Ne,bd as Fe,q as De,be as ze,bf as Ie,bg as Le,bh as Ce,bi as ke,bj as Re,bk as qe,bl as Ee,bm as Pe,p as Te,bn as We,L as A,bo as Me}from"./index-DJDWSrju.js";import"./vendor-xterm-DzcZoU0P.js";const U=".fusion/memory/MEMORY.md",_e=5e4,Oe="0 3 * * *",Ue="0 4 * * *";function me(l){return{memoryEnabled:l.memoryEnabled!==!1,memoryAutoSummarizeEnabled:l.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:l.memoryAutoSummarizeThresholdChars??_e,memoryAutoSummarizeSchedule:l.memoryAutoSummarizeSchedule??Oe,memoryDreamsEnabled:l.memoryDreamsEnabled??!1,memoryDreamsSchedule:l.memoryDreamsSchedule??Ue}}function we(l,t){return l.some(c=>c.path===t)?t:l.find(c=>c.path===U)?.path??l[0]?.path??U}function Qe(l={}){const{projectId:t}=l,[c,p]=a.useState(""),[F,k]=a.useState(!0),[S,N]=a.useState(!1),[y,g]=a.useState(!1),[i,b]=a.useState(null),[Q,J]=a.useState(!0),[X,D]=a.useState(!1),[f,q]=a.useState(()=>me({})),[E,ee]=a.useState(!0),[ce,H]=a.useState(!1),[o,j]=a.useState([]),[se,z]=a.useState(!0),[m,C]=a.useState(U),[P,u]=a.useState(""),[d,te]=a.useState(!1),[$,x]=a.useState(!1),[ae,Y]=a.useState(!1),[ne,B]=a.useState(!1),[G,T]=a.useState(null),[M,W]=a.useState(!0),[oe,I]=a.useState(!1),[de,V]=a.useState(!1),[ie,Z]=a.useState(null),{status:K,loading:v,refresh:re}=Ae({projectId:t}),L=a.useCallback(n=>{u(n),x(!0)},[]),_=a.useCallback(async n=>{te(!0);try{const{content:s}=await Se(n,t);C(n),u(s),x(!1)}finally{te(!1)}},[t]),w=a.useCallback(async()=>{z(!0);try{const{files:n}=await Ne(t);if(j(n),n.length===0){C(U),u(""),x(!1);return}const s=we(n,m);s!==m&&await _(s)}finally{z(!1)}},[t,m,_]);a.useEffect(()=>{let n=!1;async function s(){try{const r=await Pe(t);n||(p(r.content),k(!1))}catch{n||(p(""),k(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await ke(t);n||(b(r.content),D(r.exists),J(!1))}catch{n||(b(null),D(!1),J(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){ee(!0);try{const r=await Te(t);n||q(me(r))}catch{n||q(me({}))}finally{n||ee(!1)}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){z(!0);try{const{files:r}=await Ne(t);if(n)return;if(j(r),r.length===0){C(U),u(""),x(!1);return}const h=we(r,m),{content:ve}=await Se(h,t);if(n)return;C(h),u(ve),x(!1)}catch{n||(j([]),C(U),u(""),x(!1))}finally{n||z(!1)}}return s(),()=>{n=!0}},[t,m]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await Ce(t);n||(T(r),W(!1))}catch{n||(T(null),W(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const r=await We(t);n||Z(r)}catch{n||Z(null)}}return s(),()=>{n=!0}},[t]);const le=a.useCallback(n=>{p(n),N(!0)},[]),he=a.useCallback(async()=>{if(S){g(!0);try{await Fe(c,t),N(!1)}finally{g(!1)}}},[c,S,t]),ue=a.useCallback(async n=>{H(!0);try{const s=await De(n,t);q(me(s))}finally{H(!1)}},[t]),ye=a.useCallback(async n=>{await _(n)},[_]),ge=a.useCallback(async()=>{if($){Y(!0);try{await ze(m,P,t),x(!1),await w()}finally{Y(!1)}}},[P,$,m,t,w]),be=a.useCallback(async()=>{V(!0);try{const n=await Ie(t);return await re(),n}finally{V(!1)}},[t,re]),xe=a.useCallback(async n=>Le(n,t),[t]),O=a.useCallback(async()=>{try{const n=await Ce(t);T(n)}catch{T(null)}},[t]),R=a.useCallback(async()=>{try{const n=await ke(t);b(n.content),D(n.exists)}catch{b(null),D(!1)}},[t]),pe=a.useCallback(async n=>{await Re(n,t),await R()},[t,R]),fe=a.useCallback(async()=>{B(!0);try{const n=await qe(t);return await Promise.all([R(),O()]),{success:n.success,summary:n.summary}}finally{B(!1)}},[t,R,O]),je=a.useCallback(async n=>{I(!0);try{const s=n?await Ee(n,t):await Ee(t);if(n){const r=s.path??n;C(r),u(s.content),x(!1),await w();return}p(s.content),N(!0)}finally{I(!1)}},[t,w]);return{workingMemory:c,workingMemoryLoading:F,workingMemoryDirty:S,setWorkingMemory:le,saveWorkingMemory:he,savingWorkingMemory:y,insightsContent:i,insightsLoading:Q,insightsExists:X,refreshInsights:R,saveInsights:pe,memorySettings:f,settingsLoading:E,savingMemorySettings:ce,saveMemorySettings:ue,memoryFiles:o,memoryFilesLoading:se,selectedFilePath:m,selectedFileContent:P,selectedFileLoading:d,selectedFileDirty:$,setSelectedFileContent:L,selectFile:ye,saveSelectedFile:ge,savingSelectedFile:ae,reloadMemoryFiles:w,backendStatus:K,backendLoading:v,extractInsights:fe,extracting:ne,auditReport:G,auditLoading:M,refreshAudit:O,compactMemory:je,compacting:oe,installQmdAction:be,installingQmd:de,testRetrieval:xe,stats:ie}}const He={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},$e={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Ye={"long-term":"Curated durable decisions, conventions, constraints, and pitfalls promoted from dreams.",daily:"Raw daily observations, open loops, and running context for dream processing.",dreams:"Synthesized patterns and open loops promoted from daily memory."};function Be(l){if(!l)return[];const t=[],c=l.split(/(?=^## )/m);for(const p of c){const F=p.trim();if(!F)continue;const k=F.match(/^##\s+(.+?)(\n|$)/);if(k){const S=k[1].trim(),N=He[S]??S.toLowerCase(),y=F.slice(k[0].length).trim(),g=y.split(`
2
2
  `).map(i=>i.replace(/^-\s+/,"").trim()).filter(i=>i.length>0&&(i.startsWith("- ")||i.startsWith("* ")));(g.length>0||y.length>0)&&t.push({name:S,key:N,items:g.length>0?g:y.length>0?[y]:[],expanded:!0})}}return t}function Ge(l){if(!l)return null;const t=l.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function Ve(l){return l.reduce((t,c)=>t+c.items.length,0)}function Ze(l){switch(l){case"file":return"File (.fusion/memory/)";case"readonly":return"Read-Only";case"qmd":return"QMD (Quantized Memory Distillation)";default:return l}}function Ke(l){switch(l){case"healthy":return"Healthy";case"warning":return"Warning";case"issues":return"Issues Found"}}function ts({projectId:l,addToast:t}){const[c,p]=a.useState("working"),[F,k]=a.useState(new Set),[S,N]=a.useState(!1),[y,g]=a.useState(null),[i,b]=a.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[Q,J]=a.useState(""),[X,D]=a.useState(!1),[f,q]=a.useState(null),{insightsContent:E,insightsLoading:ee,insightsExists:ce,saveInsights:H,memorySettings:o,settingsLoading:j,saveMemorySettings:se,savingMemorySettings:z,backendStatus:m,backendLoading:C,extractInsights:P,extracting:u,auditReport:d,auditLoading:te,refreshAudit:$,compactMemory:x,compacting:ae,installQmdAction:Y,installingQmd:ne,testRetrieval:B,memoryFiles:G,memoryFilesLoading:T,selectedFilePath:M,selectedFileContent:W,selectedFileLoading:oe,selectedFileDirty:I,setSelectedFileContent:de,selectFile:V,saveSelectedFile:ie,savingSelectedFile:Z}=Qe({projectId:l});a.useEffect(()=>{b(o)},[o]);const K=a.useMemo(()=>i.memoryEnabled!==o.memoryEnabled||i.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled||i.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars||i.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule||i.memoryDreamsEnabled!==o.memoryDreamsEnabled||i.memoryDreamsSchedule!==o.memoryDreamsSchedule,[i,o]),v=a.useMemo(()=>G.find(s=>s.path===M),[G,M]),re=v?Ye[v.layer]:"Edits the selected memory file.",L=a.useMemo(()=>Be(E),[E]),_=a.useMemo(()=>Ve(L),[L]),w=a.useMemo(()=>Ge(E),[E]),le=a.useCallback(s=>{k(r=>{const h=new Set(r);return h.has(s)?h.delete(s):h.add(s),h})},[]),he=a.useCallback(async s=>{try{await V(s)}catch{t("Failed to load memory file","error")}},[V,t]),ue=a.useCallback(async()=>{try{await ie(),t("Memory saved","success")}catch{t("Failed to save memory","error")}},[ie,t]),ye=a.useCallback(async()=>{if(!K)return;const s={};i.memoryEnabled!==o.memoryEnabled&&(s.memoryEnabled=i.memoryEnabled),i.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled&&(s.memoryAutoSummarizeEnabled=i.memoryAutoSummarizeEnabled),i.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars&&(s.memoryAutoSummarizeThresholdChars=i.memoryAutoSummarizeThresholdChars),i.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule&&(s.memoryAutoSummarizeSchedule=i.memoryAutoSummarizeSchedule),i.memoryDreamsEnabled!==o.memoryDreamsEnabled&&(s.memoryDreamsEnabled=i.memoryDreamsEnabled),i.memoryDreamsSchedule!==o.memoryDreamsSchedule&&(s.memoryDreamsSchedule=i.memoryDreamsSchedule);try{await se(s),t("Memory settings saved","success")}catch{t("Failed to save memory settings","error")}},[K,i,o,se,t]),ge=a.useCallback(async()=>{try{const s=await Y();t(s.qmdAvailable?"qmd installed successfully":"qmd install finished, but qmd is still unavailable",s.qmdAvailable?"success":"info")}catch{t("Failed to install qmd","error")}},[Y,t]),be=a.useCallback(async()=>{D(!0),q(null);try{const s=await B(Q);q(s),t(s.qmdAvailable?"Memory retrieval test complete":"qmd is not installed; local fallback was used",s.qmdAvailable?"success":"info")}catch{t("Failed to test memory retrieval","error")}finally{D(!1)}},[Q,B,t]),xe=a.useCallback(async()=>{try{await x(M),t("Memory file compacted","success")}catch{t("Failed to compact memory","error")}},[x,M,t]),O=a.useCallback(async()=>{try{const s=await P();t(s.summary,"success")}catch(s){t(s instanceof Error?s.message:"Failed to extract insights","error")}},[P,t]),R=a.useCallback(async()=>{if(y!==null)try{await H(y),N(!1),g(null),t("Insights saved","success")}catch{t("Failed to save insights","error")}},[y,H,t]),pe=a.useCallback(()=>{g(E??""),N(!0)},[E]),fe=a.useCallback(()=>{N(!1),g(null)},[]),je=!C&&m!==null,n=m?.capabilities?.writable??!1;return e.jsxs("div",{className:"memory-view",children:[e.jsx("div",{className:"memory-view-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Memory"}),e.jsx("p",{className:"memory-view-description",children:"Working memory, long-term insights, and engine status"})]})}),e.jsxs("div",{className:"memory-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":c==="working",className:`memory-view-tab${c==="working"?" memory-view-tab--active":""}`,onClick:()=>p("working"),"data-testid":"memory-tab-working",children:"Working Memory"}),e.jsx("button",{type:"button",role:"tab","aria-selected":c==="insights",className:`memory-view-tab${c==="insights"?" memory-view-tab--active":""}`,onClick:()=>p("insights"),"data-testid":"memory-tab-insights",children:"Insights"}),e.jsx("button",{type:"button",role:"tab","aria-selected":c==="engines",className:`memory-view-tab${c==="engines"?" memory-view-tab--active":""}`,onClick:()=>p("engines"),"data-testid":"memory-tab-engines",children:"Engines"})]}),e.jsxs("div",{className:"memory-view-content",children:[c==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[je&&!n&&e.jsx("div",{className:"memory-readonly-banner",children:"This memory backend is read-only. Changes cannot be saved."}),T||oe?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading memory file…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-editor-section",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryViewFilePath",children:"Memory File"}),e.jsx("select",{id:"memoryViewFilePath",className:"select",value:M,onChange:s=>{he(s.target.value)},disabled:I,children:G.map(s=>e.jsxs("option",{value:s.path,children:[s.label," - ",s.path]},s.path))}),e.jsx("small",{children:I?"Save or discard the current edits before switching files.":"Choose any project memory file to view or edit."})]}),v&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:$e[v.layer]}),e.jsx("strong",{children:v.path}),e.jsxs("small",{children:[v.size.toLocaleString()," bytes · updated ",new Date(v.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:v?.label||"Memory Editor"}),e.jsx("small",{children:re}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Me,{content:W,onChange:de,readOnly:!n,filePath:M})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsxs("span",{className:"memory-char-count",children:[W.length," characters"]}),e.jsx("div",{className:"memory-flex-spacer"}),n&&W.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:xe,disabled:ae||I,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Compacting…"]}):"Compact Selected File"}),I&&n&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ue,disabled:Z,children:Z?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Saving…"]}):"Save"})]}),e.jsxs("div",{className:"memory-config-section",children:[e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:"memoryDreamsEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryDreamsEnabled",type:"checkbox",checked:i.memoryDreamsEnabled,onChange:s=>{b(r=>({...r,memoryDreamsEnabled:s.target.checked}))},disabled:!i.memoryEnabled||j}),"Process dreams from daily memory"]}),e.jsx("small",{children:"Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md."})]}),i.memoryEnabled&&i.memoryDreamsEnabled&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryDreamsSchedule",children:"Dream Schedule"}),e.jsx("input",{id:"memoryDreamsSchedule",type:"text",className:"input",value:i.memoryDreamsSchedule,onChange:s=>{b(r=>({...r,memoryDreamsSchedule:s.target.value}))},placeholder:"0 4 * * *",disabled:j}),e.jsx("small",{children:"Cron expression for dream processing."})]})]}),e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:"memoryAutoSummarizeEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryAutoSummarizeEnabled",type:"checkbox",checked:i.memoryAutoSummarizeEnabled,onChange:s=>{b(r=>({...r,memoryAutoSummarizeEnabled:s.target.checked}))},disabled:!i.memoryEnabled||j}),"Auto-Summarize Memory"]}),e.jsx("small",{children:"Automatically compact memory when it exceeds the threshold on a schedule"})]}),i.memoryEnabled&&i.memoryAutoSummarizeEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeThresholdChars",children:"Compaction Threshold (chars)"}),e.jsx("input",{id:"memoryAutoSummarizeThresholdChars",type:"number",className:"input",value:i.memoryAutoSummarizeThresholdChars,onChange:s=>{b(r=>({...r,memoryAutoSummarizeThresholdChars:parseInt(s.target.value,10)||5e4}))},min:1e3,disabled:j}),e.jsx("small",{children:"Memory will be compacted when it exceeds this character count"})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeSchedule",children:"Schedule (cron)"}),e.jsx("input",{id:"memoryAutoSummarizeSchedule",type:"text",className:"input",value:i.memoryAutoSummarizeSchedule,onChange:s=>{b(r=>({...r,memoryAutoSummarizeSchedule:s.target.value}))},placeholder:"0 3 * * *",disabled:j}),e.jsx("small",{children:"Cron expression for auto-summarize schedule (default: daily at 3 AM)"})]})]})]}),!i.memoryEnabled&&e.jsx("div",{className:"settings-empty-state memory-status-message",children:"Memory is currently disabled. Enable memory tools in Settings to edit these automations."}),K&&e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ye,disabled:z||j,children:z?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Settings"})})]})]})]}),c==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:ee?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading insights…"})]}):S?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Me,{content:y??"",onChange:g,readOnly:!1,filePath:".fusion/memory/INSIGHTS.md"})}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:fe,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:R,children:"Save Insights"})]})]}):!ce||L.length===0?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx("p",{children:"No insights extracted yet."}),e.jsx("p",{children:'Insights are automatically extracted from working memory. Click "Extract Now" to trigger extraction manually.'}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm memory-empty-extract-button",onClick:O,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-stats-row",children:[e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:_}),e.jsx("div",{className:"memory-stat-label",children:"Total Insights"})]}),e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:L.length}),e.jsx("div",{className:"memory-stat-label",children:"Categories"})]}),w&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:w}),e.jsx("div",{className:"memory-stat-label",children:"Last Updated"})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:O,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:pe,children:"Edit Raw"})]}),e.jsx("div",{className:"memory-categories-list",children:L.map(s=>{const r=!F.has(s.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>le(s.key),role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),le(s.key))},children:[e.jsx("h4",{children:s.name}),e.jsx("span",{className:"memory-category-count",children:s.items.length})]}),r&&e.jsx("div",{className:"memory-category-items",children:s.items.map((h,ve)=>e.jsx("div",{className:"memory-insight-item",children:h.replace(/^-\s+/,"").replace(/^\*\s+/,"")},ve))})]},s.key)})})]})}),c==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:C||te?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading engine status…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-engine-card memory-qmd-card",children:[e.jsx("h3",{children:"QMD Integration"}),m?.qmdAvailable===!0?e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge memory-health-badge--healthy",children:"Installed"}),e.jsx("span",{className:"memory-char-count",children:"qmd is available on PATH."})]}):m?.qmdAvailable===!1?e.jsxs("div",{className:"settings-empty-state memory-status-message",children:[e.jsxs("span",{children:["qmd is not installed. Search will use local files. Install indexed retrieval: ",e.jsx("code",{children:m.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ge,disabled:ne,children:ne?"Installing…":"Install qmd"})]}):e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge",children:"Checking"}),e.jsx("span",{className:"memory-char-count",children:"Checking qmd availability…"})]}),e.jsxs("div",{className:"memory-capability-row",children:[m?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),m?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),m?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),m?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:"Persistent"})]})]}),e.jsxs("div",{className:"memory-engine-card memory-retrieval-card",children:[e.jsx("h3",{children:"Test Memory Search"}),e.jsxs("div",{className:"memory-retrieval-input-row",children:[e.jsx("input",{type:"text",className:"input",value:Q,onChange:s=>J(s.target.value),placeholder:"Search memory with qmd"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:be,disabled:X,children:X?"Testing…":"Test Retrieval"})]}),e.jsx("small",{className:"settings-muted",children:"Runs the same qmd-backed memory_search path agents use."}),f&&e.jsxs("div",{className:"memory-test-result",children:[e.jsxs("strong",{children:[f.results.length," result",f.results.length===1?"":"s"," ",'for "',f.query,'"']}),e.jsxs("small",{children:["qmd ",f.qmdAvailable?"available":"missing"," · ",f.usedFallback?"local fallback used":"qmd path used"]}),f.results.length>0?e.jsx("ul",{children:f.results.map((s,r)=>e.jsxs("li",{children:[e.jsxs("span",{children:[s.path,":",s.lineStart]}),e.jsx("p",{children:s.snippet})]},`${s.path}-${s.lineStart}-${r}`))}):e.jsx("small",{children:"No matching memory found."})]})]}),e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:"Current Backend"}),e.jsx("div",{className:"memory-engine-status",children:e.jsx("span",{className:"memory-emphasis-text",children:Ze(m?.currentBackend??"unknown")})}),e.jsxs("div",{className:"memory-capability-row",children:[m?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),m?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),m?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),m?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:"Persistent"})]})]}),d&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsxs("div",{className:"memory-health-header",children:[e.jsx("h3",{children:"Health Status"}),e.jsx("span",{className:`memory-health-badge memory-health-badge--${d.health}`,children:Ke(d.health)})]}),e.jsxs("div",{className:"memory-health-grid",children:[e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:"Working Memory"}),e.jsxs("div",{className:"memory-emphasis-text",children:[d.workingMemory.size," chars"]}),e.jsxs("div",{className:"memory-health-detail",children:[d.workingMemory.sectionCount," sections"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"memory-health-label",children:"Insights Memory"}),e.jsxs("div",{className:"memory-emphasis-text",children:[d.insightsMemory.size," chars"]}),e.jsxs("div",{className:"memory-health-detail",children:[d.insightsMemory.insightCount," insights"]})]})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:"Last Extraction"}),e.jsx("div",{className:"memory-emphasis-text",children:d.extraction.success?e.jsx("span",{className:"memory-status-text memory-status-text--success",children:"Success"}):e.jsx("span",{className:"memory-status-text memory-status-text--error",children:"Failed"})}),e.jsx("div",{className:"memory-health-detail",children:d.extraction.summary||`${d.extraction.insightCount} insights extracted`})]}),e.jsxs("div",{className:"memory-health-section",children:[e.jsx("div",{className:"memory-health-label",children:"Pruning"}),e.jsx("div",{className:"memory-emphasis-text",children:d.pruning.applied?e.jsx("span",{className:"memory-status-text memory-status-text--warning",children:"Applied"}):e.jsx("span",{className:"memory-status-text memory-status-text--muted",children:"Not needed"})}),d.pruning.applied&&e.jsx("div",{className:"memory-health-detail",children:d.pruning.reason})]})]}),d&&d.checks.length>0&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:"Audit Checks"}),e.jsx("div",{children:d.checks.map(s=>e.jsxs("div",{className:"memory-audit-check",children:[e.jsx("span",{className:s.passed?"memory-audit-check-passed":"memory-audit-check-failed",children:s.passed?"✓":"✗"}),e.jsxs("div",{className:"memory-audit-check-content",children:[e.jsx("div",{className:"memory-emphasis-text",children:s.name}),e.jsx("div",{className:"memory-health-detail",children:s.details})]})]},s.id))})]}),e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>$(),children:"Run Audit"})}),e.jsxs("div",{className:"memory-settings-note",children:[e.jsx("span",{children:"Note: Change backend type in"}),e.jsx("button",{type:"button",className:"memory-settings-note-button",onClick:()=>{t("Open Settings → Memory to change backend type","info")},children:"Settings → Memory"})]})]})})]})]})}export{ts as MemoryView};