@runfusion/fusion 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin.js +34069 -34842
  3. package/dist/client/assets/{AgentDetailView-DJwWfkpv.js → AgentDetailView-dhJd4os0.js} +6 -11
  4. package/dist/client/assets/{AgentsView-DegK8aw-.js → AgentsView-CYVTv2_l.js} +3 -3
  5. package/dist/client/assets/{ChatView-CYpEShLS.js → ChatView-ByPhfQZ6.js} +1 -1
  6. package/dist/client/assets/{DevServerView-DfCTA9fx.js → DevServerView-CD7mgC11.js} +1 -1
  7. package/dist/client/assets/{DirectoryPicker-B0qNpfLW.js → DirectoryPicker-Cm0FCC9M.js} +1 -1
  8. package/dist/client/assets/{DocumentsView-CsQxuyz3.js → DocumentsView-oB319uCj.js} +1 -1
  9. package/dist/client/assets/{InsightsView-Bzs7A2jv.js → InsightsView-BHdMNnOa.js} +1 -1
  10. package/dist/client/assets/{MemoryView-Cl5ASqjW.js → MemoryView-BDJMlzlM.js} +1 -1
  11. package/dist/client/assets/{NodesView-BpiqRlvc.js → NodesView-BfOlOj-Q.js} +1 -1
  12. package/dist/client/assets/{PiExtensionsManager-Cr6EoC7S.js → PiExtensionsManager-D-IznnkU.js} +2 -2
  13. package/dist/client/assets/{PluginManager-DXtQdfns.js → PluginManager-D40uAE-p.js} +1 -1
  14. package/dist/client/assets/{RoadmapsView-CYPLTTB0.js → RoadmapsView-DtgL8yl3.js} +1 -1
  15. package/dist/client/assets/{SettingsModal-CNdVTVqD.js → SettingsModal-0IyoaKEv.js} +1 -1
  16. package/dist/client/assets/SettingsModal-D1vZdAS4.js +31 -0
  17. package/dist/client/assets/{SetupWizardModal-BLiljNn7.js → SetupWizardModal-BaQ8VkZm.js} +1 -1
  18. package/dist/client/assets/{SkillsView-Dlpw5LKI.js → SkillsView-DAvaRl37.js} +1 -1
  19. package/dist/client/assets/TodoView-BXRQSmSw.js +1 -0
  20. package/dist/client/assets/TodoView-DNi8blBB.css +1 -0
  21. package/dist/client/assets/{folder-open-B_38R5AA.js → folder-open-BJ4SvamV.js} +1 -1
  22. package/dist/client/assets/index-B7TDbn3p.css +1 -0
  23. package/dist/client/assets/index-CGW6tOaX.js +631 -0
  24. package/dist/client/assets/list-checks-CpGwz9gV.js +6 -0
  25. package/dist/client/assets/{upload-DNQF7XCK.js → upload-DJYyvab0.js} +1 -1
  26. package/dist/client/assets/{users-CG2_rCdk.js → users-ndAFpylb.js} +1 -1
  27. package/dist/client/index.html +2 -2
  28. package/dist/client/version.json +1 -1
  29. package/dist/extension.js +3311 -592
  30. package/dist/pi-claude-cli/src/__tests__/process-manager.test.ts +50 -17
  31. package/dist/pi-claude-cli/src/__tests__/setup-test-isolation.test.ts +30 -0
  32. package/dist/pi-claude-cli/src/__tests__/setup-test-isolation.ts +6 -0
  33. package/package.json +17 -17
  34. package/skill/fusion/references/extension-tools.md +5 -5
  35. package/skill/fusion/references/fusion-capabilities.md +5 -5
  36. package/dist/client/assets/SettingsModal-CyCC7MzL.js +0 -31
  37. package/dist/client/assets/index-DQKtk17v.js +0 -616
  38. package/dist/client/assets/index-DjOxzdj3.css +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-DJwWfkpv.js","assets/vendor-react-K0fH_qHe.js","assets/index-DQKtk17v.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-DjOxzdj3.css","assets/upload-DNQF7XCK.js","assets/folder-open-B_38R5AA.js","assets/AgentDetailView-C1b9PC5l.css"])))=>i.map(i=>d[i]);
2
- import{c as Fe,s as rt,A as xe,C as Se,Z as lt,B as De,g as Re,a as et,b as Ae,d as ot,e as ct,f as dt,h as ut,i as mt,u as ze,j as ht,P as gt,k as pt,l as Oe,G as ft,S as bt,L as Te,T as Me,R as $e,F as qe,X as He,m as vt,n as xt,o as yt,p as de,q as Ve,r as wt,t as jt,v as kt,w as Nt,x as It,y as We,z as Ct,D as tt,H as St,E as ke,I as Ke,J as Ue,K as Et,M as At,N as Ne,O as Tt,Q as Be,U as Mt,V as _t,W as Pt,_ as Rt}from"./index-DQKtk17v.js";import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{U as nt}from"./upload-DNQF7XCK.js";import{F as $t}from"./folder-open-B_38R5AA.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-dhJd4os0.js","assets/vendor-react-K0fH_qHe.js","assets/index-CGW6tOaX.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-B7TDbn3p.css","assets/list-checks-CpGwz9gV.js","assets/upload-DJYyvab0.js","assets/folder-open-BJ4SvamV.js","assets/AgentDetailView-C1b9PC5l.css"])))=>i.map(i=>d[i]);
2
+ import{c as Fe,s as rt,A as xe,C as Se,Z as lt,B as De,g as Re,a as et,b as Ae,d as ot,e as ct,f as dt,h as ut,i as mt,u as ze,j as ht,P as gt,k as pt,l as Oe,G as ft,S as bt,L as Te,T as Me,R as $e,F as qe,X as He,m as vt,n as xt,o as yt,p as de,q as Ve,r as wt,t as jt,v as kt,w as Nt,x as It,y as We,z as Ct,D as tt,H as St,E as ke,I as Ke,J as Ue,K as Et,M as At,N as Ne,O as Tt,Q as Be,U as Mt,V as _t,W as Pt,_ as Rt}from"./index-CGW6tOaX.js";import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{U as nt}from"./upload-DJYyvab0.js";import{F as $t}from"./folder-open-BJ4SvamV.js";/**
3
3
  * @license lucide-react v1.7.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -519,4 +519,4 @@ reportsTo: null
519
519
  skills:
520
520
  - review
521
521
  ---
522
- Agent instructions go here...`,value:o,onChange:n=>{u("paste"),N([]),g(n.target.value),M(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),_&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Me,{size:14}),_]})]}),c==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:x})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(qe,{size:14}),e.jsxs("span",{children:[p.length," agent",p.length!==1?"s":""," found"]})]}),p.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>j(p.map(n=>n.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>j([]),children:"Clear agents"})]}),p.length>0?e.jsx("div",{className:"agent-import-agent-list",children:p.map((n,t)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${n.name}`,checked:E.includes(n.name),onChange:()=>te(n.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:n.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:n.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[n.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[n.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:n.role}),n.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",n.reportsTo]}),n.skills&&n.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",n.skills.join(", ")]})]}),n.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[n.instructionsText.slice(0,100),n.instructionsText.length>100?"...":""]})]})]},t))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),C.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(qe,{size:14}),e.jsxs("span",{children:[C.length," skill",C.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>W(C.map(n=>n.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>W([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:C.map((n,t)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${n.name}`,checked:T.includes(n.name),onChange:()=>oe(n.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:n.name}),n.description&&e.jsx("span",{className:"agent-import-skill-description",children:n.description})]})]},`${n.name}-${t}`))})]}),Z&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Me,{size:14}),Z]})]}),c==="result"&&k&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Se,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:k.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[k.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[k.created.length," created"]})}),k.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[k.skipped.length," skipped (already exist)"]})}),k.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[k.errors.length," error",k.errors.length!==1?"s":""]})})]}),k.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:k.created.map((n,t)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:n.name})]},t))}),k.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:k.errors.map((n,t)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(He,{size:12}),e.jsxs("span",{children:[n.name,": ",n.error]})]},t))}),k.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[k.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[k.skills.imported.length," skill",k.skills.imported.length!==1?"s":""," imported"]})}),k.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[k.skills.skipped.length," skill",k.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),k.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[k.skills.errors.length," skill",k.skills.errors.length!==1?"s":""," error",k.skills.errors.length!==1?"s":""]})}),k.skills.imported.length===0&&k.skills.skipped.length===0&&k.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),k.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:k.skills.imported.map((n,t)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:n.name})]},t))}),k.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:k.skills.errors.map((n,t)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(He,{size:12}),e.jsxs("span",{children:[n.name,": ",n.error]})]},t))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>d("input"),disabled:L,children:"Back"}),e.jsx("button",{className:"btn",onClick:se,disabled:L,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn--primary",onClick:()=>void ye(),disabled:X||(r==="directory"?b.length===0:r==="browse"?!$:!o.trim()),children:X?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn--primary",onClick:()=>void we(),disabled:L||O===0&&D===0,children:L?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"spin"}),ge]}):`Import ${je}`})]})]})}):null}const Cn=s.lazy(()=>Rt(()=>import("./AgentDetailView-DJwWfkpv.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])).then(a=>({default:a.AgentDetailView}))),Ce=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Pe=[.1,.25,.5,1,2,3,5,10];function Ee(a){switch(a){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function Ye(a,l){switch(l){case"running":return`${a}--running`;case"active":return`${a}--active`;case"paused":return`${a}--paused`;case"error":return`${a}--error`;case"terminated":return`${a}--terminated`;case"idle":default:return`${a}--idle`}}function at({node:a,onSelect:l,onToggle:f,isExpanded:m,getChildCount:c,getHealthStatus:d,getRoleIcon:r,getSkillBadges:u}){const{agent:o,children:g,depth:b}=a,N=c(o.id),x=m(o.id),I=d(o),p=Ee(o.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`agent-tree__node${o.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(b,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${N===0?" agent-tree__toggle--leaf":""}`,onClick:()=>N>0&&f(o.id),title:N>0?x?"Collapse":"Expand":"No employees","aria-label":N>0?x?"Collapse":"Expand":"No employees",children:N>0?x?e.jsx(Et,{size:16}):e.jsx(tt,{size:16}):e.jsx(De,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:w=>w.key==="Enter"&&l(o.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(o.role)}),e.jsx("span",{className:"agent-tree__name",children:o.name}),e.jsx("span",{className:`agent-tree__badge ${p}`,children:o.state}),e.jsx("span",{className:"agent-tree__health",style:{color:I.color},title:I.label,children:I.icon}),N>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",N,")"]}),(()=>{const w=u(o);return w.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:w.join(", "),children:[w[0],w.length>1&&` +${w.length-1}`]})})()]})]}),x&&g.length>0&&e.jsx("div",{className:"agent-tree__children",children:g.map(w=>e.jsx(at,{node:w,onSelect:l,onToggle:f,isExpanded:m,getChildCount:c,getHealthStatus:d,getRoleIcon:r,getSkillBadges:u},w.agent.id))})]})}function it({node:a,onSelect:l,getHealthStatus:f,getRoleIcon:m,getSkillBadges:c}){const{agent:d,children:r}=a,u=f(d),o=Ee(d.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:"org-chart-node-card",onClick:()=>l(d.id),role:"button",tabIndex:0,onKeyDown:g=>g.key==="Enter"&&l(d.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:m(d.role)}),e.jsx("span",{className:"org-chart-node__name",children:d.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${o}`,children:d.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:u.color},title:u.label,children:[u.icon,!u.stateDerived&&e.jsx("span",{className:"text-secondary",children:u.label})]}),(()=>{const g=c(d);if(g.length===0)return null;const b=g.slice(0,2),N=g.length-2;return e.jsxs(e.Fragment,{children:[b.map(x=>e.jsx("span",{className:"org-chart-node__skill",children:x},x)),N>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",N]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${d.name} employees`,children:r.map(g=>e.jsx(it,{node:g,onSelect:l,getHealthStatus:f,getRoleIcon:m,getSkillBadges:c},g.agent.id))})]})}function Sn({addToast:a,projectId:l}){const[f,m]=s.useState(!1),[c,d]=s.useState("all"),{agents:r,activeAgents:u,stats:o,isLoading:g,loadAgents:b}=vt(l,{filterState:c,showSystemAgents:f}),[N,x]=s.useState(!1),[I,p]=s.useState(!1),[w,C]=s.useState(null),[A,E]=s.useState(()=>{if(typeof window>"u")return"list";const t=Re("fn-agent-view",l);return t==="list"||t==="board"||t==="tree"||t==="org"?t:"list"}),[j,T]=s.useState([]),[W,X]=s.useState(!1),[H,L]=s.useState(!1),ie=s.useRef(null),_=s.useRef(null),M=s.useId();s.useEffect(()=>{const t=Re("fn-agent-view",l);if(t==="list"||t==="board"||t==="tree"||t==="org"){E(t);return}E("list")},[l]),s.useEffect(()=>{et("fn-agent-view",A,l)},[A,l]);const[k,K]=s.useState(null),Z=s.useRef(null),[ue,z]=s.useState(null),[me,U]=s.useState(null),[Y,P]=s.useState({}),[B,$]=s.useState(1),[ee,re]=s.useState(!1),[F,G]=s.useState(new Set),R=s.useRef(!0);s.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]),s.useEffect(()=>{xt(l).then(t=>{R.current&&$(t.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const V=s.useCallback(async t=>{const i=Number.isFinite(t)&&t>0?t:1;$(i),re(!0);try{await yt({heartbeatMultiplier:i},l),a(`Heartbeat speed set to ×${i.toFixed(1)}`,"success")}catch(h){a(`Failed to save heartbeat multiplier: ${de(h)}`,"error")}finally{R.current&&re(!1)}},[l,a]),ne=Xt(r,l),Q=s.useMemo(()=>r.filter(t=>f||!Ve(t)),[r,f]),se=s.useMemo(()=>{if(f)return j;const t=i=>Ve(i.agent)?null:{...i,children:i.children.map(t).filter(h=>h!==null)};return j.map(t).filter(i=>i!==null)},[j,f]);s.useEffect(()=>{if(A!=="org")return;let t=!1;return X(!0),wt(l,{includeEphemeral:f}).then(i=>{t||T(i)}).catch(i=>{t||(a(`Failed to load org chart: ${de(i)}`,"error"),T([]))}).finally(()=>{t||X(!1)}),()=>{t=!0}},[A,l,f,a]),s.useEffect(()=>{const t=setInterval(()=>{b()},3e4);return()=>{clearInterval(t)}},[b]),s.useEffect(()=>{if(!H)return;const t=h=>{const v=h.target;v&&(ie.current?.contains(v)||_.current?.contains(v)||L(!1))},i=h=>{h.key==="Escape"&&(L(!1),_.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",i)}},[H]);const ae=async(t,i)=>{if(!F.has(t)){G(h=>new Set(h).add(t));try{await Mt(t,i,l),a(`Agent state updated to ${i}`,"success"),b()}catch(h){a(`Failed to update state: ${de(h)}`,"error")}finally{G(h=>{const v=new Set(h);return v.delete(t),v})}}},he=async(t,i)=>{if(confirm(`Delete agent "${i}"? This cannot be undone.`))try{await _t(t,l),a(`Agent "${i}" deleted`,"success"),b()}catch(h){a(`Failed to delete agent: ${de(h)}`,"error")}},J=async(t,i)=>{const h=r.find(v=>v.id===t);if(h){if(h.role===i){K(null);return}try{await Ne(t,{role:i},l),a(`Agent role updated to ${Ce.find(v=>v.value===i)?.label??i}`,"success"),K(null),b()}catch(v){a(`Failed to update role: ${de(v)}`,"error")}}},ye=(t,i)=>{t.key==="Escape"&&K(null)},we=async(t,i)=>{me===t.id&&(U(null),P(h=>{const v={...h};return delete v[t.id],v})),z(t.id);try{await Ne(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:i}},l),a(`Heartbeat interval updated to ${Be(i)} for ${t.name}`,"success"),b()}catch(h){a(`Failed to update heartbeat interval: ${de(h)}`,"error")}finally{z(null)}},O=async t=>{const i=Y[t.id]??"";if(i.trim()===""){a("Please enter a heartbeat interval in minutes","error");return}const h=Number(i);if(isNaN(h)){a("Heartbeat interval must be a valid number","error");return}if(h<=0){a("Heartbeat interval must be greater than 0","error");return}if(h>=1&&h<5){z(t.id);try{await Ne(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Tt}},l),a(`Heartbeat interval set to 5 minutes (minimum). ${h} minute${h!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),P(S=>{const ce={...S};return delete ce[t.id],ce}),b()}catch(S){a(`Failed to update heartbeat interval: ${de(S)}`,"error")}finally{z(null)}return}const v=Math.round(h*6e4);z(t.id);try{await Ne(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:v}},l),a(`Heartbeat interval updated to ${Be(v)} for ${t.name}`,"success"),U(null),P(S=>{const ce={...S};return delete ce[t.id],ce}),b()}catch(S){a(`Failed to update heartbeat interval: ${de(S)}`,"error")}finally{z(null)}},D=t=>{const i=We(t.runtimeConfig?.heartbeatIntervalMs),h=Math.round(i/6e4);U(t.id),P(v=>({...v,[t.id]:String(h)}))},be=s.useCallback(()=>{C(null)},[]),le=s.useCallback(t=>{C(t)},[]),je=async(t,i)=>{try{await Pt(t,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),a(`Heartbeat run started for ${i}`,"success"),b()}catch(h){a(`Failed to start heartbeat run: ${de(h)}`,"error")}},ge=t=>Ce.find(i=>i.value===t)?.label??t,te=t=>Ce.find(i=>i.value===t)?.icon??"◆",oe=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],n=t=>At(t);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(De,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${A==="list"?" active":""}`,onClick:()=>E("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(jt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>E("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(xe,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="tree"?" active":""}`,onClick:()=>E("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":A==="tree",children:e.jsx(kt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>E("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(zt,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:_,className:`btn-icon agent-controls-trigger${H?" agent-controls-trigger--active":""}`,onClick:()=>L(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":H,"aria-controls":M,children:e.jsx(qt,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx($e,{size:16,className:g?"spin":void 0})}),e.jsxs("button",{className:"btn btn--primary",onClick:()=>{x(!0),L(!1)},children:[e.jsx(Nt,{size:16}),"New Agent"]})]})]})]}),H&&e.jsxs("div",{ref:ie,id:M,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(It,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:c,onChange:t=>d(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:t=>m(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{p(!0),L(!1)},children:[e.jsx(nt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:B,onChange:t=>{const i=Number(t.target.value);V(Number.isFinite(i)&&i>0?i:1)},disabled:ee}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",B.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Pe.reduce((t,i)=>Math.abs(i-B)<Math.abs(t-B)?i:t,Pe[0])),onChange:t=>{const i=Number(t.target.value);V(Number.isFinite(i)&&i>0?i:1)},disabled:ee,"aria-label":"Heartbeat speed preset",children:Pe.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(Gt,{agents:Q})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(Bt,{stats:o}),e.jsx(kn,{isOpen:N,onClose:()=>x(!1),onCreated:()=>{x(!1),b()},projectId:l}),e.jsx(In,{isOpen:I,onClose:()=>p(!1),onImported:()=>void b(),projectId:l}),A==="tree"?e.jsx("div",{className:"agent-tree__view",children:Q.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):ne.rootNodes.map(t=>e.jsx(at,{node:t,onSelect:C,onToggle:ne.toggleExpand,isExpanded:ne.isExpanded,getChildCount:i=>ne.getChildren(i).length,getHealthStatus:n,getRoleIcon:te,getSkillBadges:oe},t.agent.id))}):A==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:W?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx($e,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):se.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):se.map(t=>e.jsx(it,{node:t,onSelect:C,getHealthStatus:n,getRoleIcon:te,getSkillBadges:oe},t.agent.id))}):A==="board"?e.jsx("div",{className:"agent-board",children:Q.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):Q.map(t=>{const i=n(t),h=Ee(t.state),v=Ye("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${v}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>C(t.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&C(t.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:te(t.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:ge(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${h}`,children:t.state})]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:i.color},title:i.label,children:[i.icon,!i.stateDerived&&` ${i.label}`]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:Q.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):Q.map(t=>{const i=n(t),h=Ee(t.state),v=Ye("agent-card",t.state),S=We(t.runtimeConfig?.heartbeatIntervalMs),ce=Ct(S),pe=ue===t.id;return e.jsxs("div",{className:`agent-card ${v}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>C(t.id),role:"button",tabIndex:0,onKeyDown:y=>y.key==="Enter"&&C(t.id),children:[k===t.id?e.jsx("select",{ref:Z,className:"select agent-role-select",value:t.role,onChange:y=>void J(t.id,y.target.value),onKeyDown:y=>ye(y,t.id),onBlur:()=>K(null),autoFocus:!0,children:Ce.map(y=>e.jsxs("option",{value:y.value,children:[y.icon," ",y.label]},y.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:y=>{y.stopPropagation(),K(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),K(t.id))},children:te(t.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(tt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${h}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:i.color},title:i.label,children:[i.icon,!i.stateDerived&&` ${i.label}`]}),e.jsx("span",{className:"badge text-secondary",children:ge(t.role)}),(()=>{const y=oe(t);if(y.length===0)return null;const q=y.slice(0,2),fe=y.length-2;return e.jsxs(e.Fragment,{children:[q.map(Le=>e.jsx("span",{className:"badge badge-skill",children:Le},Le)),fe>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",fe]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),me===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Y[t.id]??"",onChange:y=>P(q=>({...q,[t.id]:y.target.value})),onKeyDown:y=>{y.key==="Enter"?O(t):y.key==="Escape"&&(U(null),P(q=>{const fe={...q};return delete fe[t.id],fe}))},disabled:pe,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void O(t),disabled:pe,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),P(y=>{const q={...y};return delete q[t.id],q})},disabled:pe,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:S,onChange:y=>{const q=y.target.value;q==="__custom__"?D(t):we(t,Number(q))},disabled:pe,"aria-label":`Set heartbeat interval for ${t.name}`,children:[ce.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value)),St.some(y=>y.value===S)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),pe&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const y=new Date(t.lastHeartbeatAt),q=new Date(y.getTime()+S),fe=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:y.toLocaleString(),children:["Last: ",y.toLocaleTimeString()]}),fe&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:q.toLocaleString(),children:["Next: ",q.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[t.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Activate",children:[e.jsx(ke,{size:14})," Start"]}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void he(t.id,t.name),title:"Delete",children:[e.jsx(Ke,{size:14})," Delete"]})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void je(t.id,t.name),disabled:F.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(xe,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"paused"),disabled:F.has(t.id),title:"Pause",children:[e.jsx(Ue,{size:14})," Pause"]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Resume",children:[e.jsx(ke,{size:14})," Resume"]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${t.name}`,children:[e.jsx(xe,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"paused"),disabled:F.has(t.id),title:"Pause",children:[e.jsx(Ue,{size:14})," Pause"]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Retry",children:[e.jsx(ke,{size:14})," Retry"]}),t.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Start",children:[e.jsx(ke,{size:14})," Start"]}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void he(t.id,t.name),title:"Delete",children:[e.jsx(Ke,{size:14})," Delete"]})]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>C(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:"View Details"})]})]},t.id)})}),e.jsx(Kt,{agents:u,projectId:l,onAgentSelect:C})]}),w&&e.jsx(s.Suspense,{fallback:null,children:e.jsx(Cn,{agentId:w,projectId:l,onClose:be,addToast:a,onChildClick:le})})]})}const _n=Object.freeze(Object.defineProperty({__proto__:null,AgentsView:Sn},Symbol.toStringTag,{value:"Module"}));export{_n as A,wn as S};
522
+ Agent instructions go here...`,value:o,onChange:n=>{u("paste"),N([]),g(n.target.value),M(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),_&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Me,{size:14}),_]})]}),c==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:x})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(qe,{size:14}),e.jsxs("span",{children:[p.length," agent",p.length!==1?"s":""," found"]})]}),p.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>j(p.map(n=>n.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>j([]),children:"Clear agents"})]}),p.length>0?e.jsx("div",{className:"agent-import-agent-list",children:p.map((n,t)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${n.name}`,checked:E.includes(n.name),onChange:()=>te(n.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:n.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:n.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[n.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[n.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:n.role}),n.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",n.reportsTo]}),n.skills&&n.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",n.skills.join(", ")]})]}),n.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[n.instructionsText.slice(0,100),n.instructionsText.length>100?"...":""]})]})]},t))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),C.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(qe,{size:14}),e.jsxs("span",{children:[C.length," skill",C.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>W(C.map(n=>n.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>W([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:C.map((n,t)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${n.name}`,checked:T.includes(n.name),onChange:()=>oe(n.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:n.name}),n.description&&e.jsx("span",{className:"agent-import-skill-description",children:n.description})]})]},`${n.name}-${t}`))})]}),Z&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Me,{size:14}),Z]})]}),c==="result"&&k&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Se,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:k.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[k.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[k.created.length," created"]})}),k.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[k.skipped.length," skipped (already exist)"]})}),k.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[k.errors.length," error",k.errors.length!==1?"s":""]})})]}),k.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:k.created.map((n,t)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:n.name})]},t))}),k.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:k.errors.map((n,t)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(He,{size:12}),e.jsxs("span",{children:[n.name,": ",n.error]})]},t))}),k.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[k.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[k.skills.imported.length," skill",k.skills.imported.length!==1?"s":""," imported"]})}),k.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[k.skills.skipped.length," skill",k.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),k.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[k.skills.errors.length," skill",k.skills.errors.length!==1?"s":""," error",k.skills.errors.length!==1?"s":""]})}),k.skills.imported.length===0&&k.skills.skipped.length===0&&k.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),k.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:k.skills.imported.map((n,t)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Se,{size:12}),e.jsx("span",{children:n.name})]},t))}),k.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:k.skills.errors.map((n,t)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(He,{size:12}),e.jsxs("span",{children:[n.name,": ",n.error]})]},t))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>d("input"),disabled:L,children:"Back"}),e.jsx("button",{className:"btn",onClick:se,disabled:L,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn--primary",onClick:()=>void ye(),disabled:X||(r==="directory"?b.length===0:r==="browse"?!$:!o.trim()),children:X?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn--primary",onClick:()=>void we(),disabled:L||O===0&&D===0,children:L?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:14,className:"spin"}),ge]}):`Import ${je}`})]})]})}):null}const Cn=s.lazy(()=>Rt(()=>import("./AgentDetailView-dhJd4os0.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(a=>({default:a.AgentDetailView}))),Ce=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Pe=[.1,.25,.5,1,2,3,5,10];function Ee(a){switch(a){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function Ye(a,l){switch(l){case"running":return`${a}--running`;case"active":return`${a}--active`;case"paused":return`${a}--paused`;case"error":return`${a}--error`;case"terminated":return`${a}--terminated`;case"idle":default:return`${a}--idle`}}function at({node:a,onSelect:l,onToggle:f,isExpanded:m,getChildCount:c,getHealthStatus:d,getRoleIcon:r,getSkillBadges:u}){const{agent:o,children:g,depth:b}=a,N=c(o.id),x=m(o.id),I=d(o),p=Ee(o.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`agent-tree__node${o.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(b,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${N===0?" agent-tree__toggle--leaf":""}`,onClick:()=>N>0&&f(o.id),title:N>0?x?"Collapse":"Expand":"No employees","aria-label":N>0?x?"Collapse":"Expand":"No employees",children:N>0?x?e.jsx(Et,{size:16}):e.jsx(tt,{size:16}):e.jsx(De,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:w=>w.key==="Enter"&&l(o.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(o.role)}),e.jsx("span",{className:"agent-tree__name",children:o.name}),e.jsx("span",{className:`agent-tree__badge ${p}`,children:o.state}),e.jsx("span",{className:"agent-tree__health",style:{color:I.color},title:I.label,children:I.icon}),N>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",N,")"]}),(()=>{const w=u(o);return w.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:w.join(", "),children:[w[0],w.length>1&&` +${w.length-1}`]})})()]})]}),x&&g.length>0&&e.jsx("div",{className:"agent-tree__children",children:g.map(w=>e.jsx(at,{node:w,onSelect:l,onToggle:f,isExpanded:m,getChildCount:c,getHealthStatus:d,getRoleIcon:r,getSkillBadges:u},w.agent.id))})]})}function it({node:a,onSelect:l,getHealthStatus:f,getRoleIcon:m,getSkillBadges:c}){const{agent:d,children:r}=a,u=f(d),o=Ee(d.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:"org-chart-node-card",onClick:()=>l(d.id),role:"button",tabIndex:0,onKeyDown:g=>g.key==="Enter"&&l(d.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:m(d.role)}),e.jsx("span",{className:"org-chart-node__name",children:d.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${o}`,children:d.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:u.color},title:u.label,children:[u.icon,!u.stateDerived&&e.jsx("span",{className:"text-secondary",children:u.label})]}),(()=>{const g=c(d);if(g.length===0)return null;const b=g.slice(0,2),N=g.length-2;return e.jsxs(e.Fragment,{children:[b.map(x=>e.jsx("span",{className:"org-chart-node__skill",children:x},x)),N>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",N]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${d.name} employees`,children:r.map(g=>e.jsx(it,{node:g,onSelect:l,getHealthStatus:f,getRoleIcon:m,getSkillBadges:c},g.agent.id))})]})}function Sn({addToast:a,projectId:l}){const[f,m]=s.useState(!1),[c,d]=s.useState("all"),{agents:r,activeAgents:u,stats:o,isLoading:g,loadAgents:b}=vt(l,{filterState:c,showSystemAgents:f}),[N,x]=s.useState(!1),[I,p]=s.useState(!1),[w,C]=s.useState(null),[A,E]=s.useState(()=>{if(typeof window>"u")return"list";const t=Re("fn-agent-view",l);return t==="list"||t==="board"||t==="tree"||t==="org"?t:"list"}),[j,T]=s.useState([]),[W,X]=s.useState(!1),[H,L]=s.useState(!1),ie=s.useRef(null),_=s.useRef(null),M=s.useId();s.useEffect(()=>{const t=Re("fn-agent-view",l);if(t==="list"||t==="board"||t==="tree"||t==="org"){E(t);return}E("list")},[l]),s.useEffect(()=>{et("fn-agent-view",A,l)},[A,l]);const[k,K]=s.useState(null),Z=s.useRef(null),[ue,z]=s.useState(null),[me,U]=s.useState(null),[Y,P]=s.useState({}),[B,$]=s.useState(1),[ee,re]=s.useState(!1),[F,G]=s.useState(new Set),R=s.useRef(!0);s.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]),s.useEffect(()=>{xt(l).then(t=>{R.current&&$(t.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const V=s.useCallback(async t=>{const i=Number.isFinite(t)&&t>0?t:1;$(i),re(!0);try{await yt({heartbeatMultiplier:i},l),a(`Heartbeat speed set to ×${i.toFixed(1)}`,"success")}catch(h){a(`Failed to save heartbeat multiplier: ${de(h)}`,"error")}finally{R.current&&re(!1)}},[l,a]),ne=Xt(r,l),Q=s.useMemo(()=>r.filter(t=>f||!Ve(t)),[r,f]),se=s.useMemo(()=>{if(f)return j;const t=i=>Ve(i.agent)?null:{...i,children:i.children.map(t).filter(h=>h!==null)};return j.map(t).filter(i=>i!==null)},[j,f]);s.useEffect(()=>{if(A!=="org")return;let t=!1;return X(!0),wt(l,{includeEphemeral:f}).then(i=>{t||T(i)}).catch(i=>{t||(a(`Failed to load org chart: ${de(i)}`,"error"),T([]))}).finally(()=>{t||X(!1)}),()=>{t=!0}},[A,l,f,a]),s.useEffect(()=>{const t=setInterval(()=>{b()},3e4);return()=>{clearInterval(t)}},[b]),s.useEffect(()=>{if(!H)return;const t=h=>{const v=h.target;v&&(ie.current?.contains(v)||_.current?.contains(v)||L(!1))},i=h=>{h.key==="Escape"&&(L(!1),_.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",i)}},[H]);const ae=async(t,i)=>{if(!F.has(t)){G(h=>new Set(h).add(t));try{await Mt(t,i,l),a(`Agent state updated to ${i}`,"success"),b()}catch(h){a(`Failed to update state: ${de(h)}`,"error")}finally{G(h=>{const v=new Set(h);return v.delete(t),v})}}},he=async(t,i)=>{if(confirm(`Delete agent "${i}"? This cannot be undone.`))try{await _t(t,l),a(`Agent "${i}" deleted`,"success"),b()}catch(h){a(`Failed to delete agent: ${de(h)}`,"error")}},J=async(t,i)=>{const h=r.find(v=>v.id===t);if(h){if(h.role===i){K(null);return}try{await Ne(t,{role:i},l),a(`Agent role updated to ${Ce.find(v=>v.value===i)?.label??i}`,"success"),K(null),b()}catch(v){a(`Failed to update role: ${de(v)}`,"error")}}},ye=(t,i)=>{t.key==="Escape"&&K(null)},we=async(t,i)=>{me===t.id&&(U(null),P(h=>{const v={...h};return delete v[t.id],v})),z(t.id);try{await Ne(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:i}},l),a(`Heartbeat interval updated to ${Be(i)} for ${t.name}`,"success"),b()}catch(h){a(`Failed to update heartbeat interval: ${de(h)}`,"error")}finally{z(null)}},O=async t=>{const i=Y[t.id]??"";if(i.trim()===""){a("Please enter a heartbeat interval in minutes","error");return}const h=Number(i);if(isNaN(h)){a("Heartbeat interval must be a valid number","error");return}if(h<=0){a("Heartbeat interval must be greater than 0","error");return}if(h>=1&&h<5){z(t.id);try{await Ne(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Tt}},l),a(`Heartbeat interval set to 5 minutes (minimum). ${h} minute${h!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),P(S=>{const ce={...S};return delete ce[t.id],ce}),b()}catch(S){a(`Failed to update heartbeat interval: ${de(S)}`,"error")}finally{z(null)}return}const v=Math.round(h*6e4);z(t.id);try{await Ne(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:v}},l),a(`Heartbeat interval updated to ${Be(v)} for ${t.name}`,"success"),U(null),P(S=>{const ce={...S};return delete ce[t.id],ce}),b()}catch(S){a(`Failed to update heartbeat interval: ${de(S)}`,"error")}finally{z(null)}},D=t=>{const i=We(t.runtimeConfig?.heartbeatIntervalMs),h=Math.round(i/6e4);U(t.id),P(v=>({...v,[t.id]:String(h)}))},be=s.useCallback(()=>{C(null)},[]),le=s.useCallback(t=>{C(t)},[]),je=async(t,i)=>{try{await Pt(t,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),a(`Heartbeat run started for ${i}`,"success"),b()}catch(h){a(`Failed to start heartbeat run: ${de(h)}`,"error")}},ge=t=>Ce.find(i=>i.value===t)?.label??t,te=t=>Ce.find(i=>i.value===t)?.icon??"◆",oe=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],n=t=>At(t);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(De,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${A==="list"?" active":""}`,onClick:()=>E("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(jt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>E("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(xe,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="tree"?" active":""}`,onClick:()=>E("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":A==="tree",children:e.jsx(kt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>E("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(zt,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:_,className:`btn-icon agent-controls-trigger${H?" agent-controls-trigger--active":""}`,onClick:()=>L(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":H,"aria-controls":M,children:e.jsx(qt,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx($e,{size:16,className:g?"spin":void 0})}),e.jsxs("button",{className:"btn btn--primary",onClick:()=>{x(!0),L(!1)},children:[e.jsx(Nt,{size:16}),"New Agent"]})]})]})]}),H&&e.jsxs("div",{ref:ie,id:M,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(It,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:c,onChange:t=>d(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:t=>m(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{p(!0),L(!1)},children:[e.jsx(nt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:B,onChange:t=>{const i=Number(t.target.value);V(Number.isFinite(i)&&i>0?i:1)},disabled:ee}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",B.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Pe.reduce((t,i)=>Math.abs(i-B)<Math.abs(t-B)?i:t,Pe[0])),onChange:t=>{const i=Number(t.target.value);V(Number.isFinite(i)&&i>0?i:1)},disabled:ee,"aria-label":"Heartbeat speed preset",children:Pe.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(Gt,{agents:Q})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(Bt,{stats:o}),e.jsx(kn,{isOpen:N,onClose:()=>x(!1),onCreated:()=>{x(!1),b()},projectId:l}),e.jsx(In,{isOpen:I,onClose:()=>p(!1),onImported:()=>void b(),projectId:l}),A==="tree"?e.jsx("div",{className:"agent-tree__view",children:Q.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):ne.rootNodes.map(t=>e.jsx(at,{node:t,onSelect:C,onToggle:ne.toggleExpand,isExpanded:ne.isExpanded,getChildCount:i=>ne.getChildren(i).length,getHealthStatus:n,getRoleIcon:te,getSkillBadges:oe},t.agent.id))}):A==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:W?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx($e,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):se.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):se.map(t=>e.jsx(it,{node:t,onSelect:C,getHealthStatus:n,getRoleIcon:te,getSkillBadges:oe},t.agent.id))}):A==="board"?e.jsx("div",{className:"agent-board",children:Q.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):Q.map(t=>{const i=n(t),h=Ee(t.state),v=Ye("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${v}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>C(t.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&C(t.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:te(t.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:ge(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${h}`,children:t.state})]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:i.color},title:i.label,children:[i.icon,!i.stateDerived&&` ${i.label}`]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:Q.length===0?e.jsx(Ie,{onCtaClick:()=>x(!0)}):Q.map(t=>{const i=n(t),h=Ee(t.state),v=Ye("agent-card",t.state),S=We(t.runtimeConfig?.heartbeatIntervalMs),ce=Ct(S),pe=ue===t.id;return e.jsxs("div",{className:`agent-card ${v}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>C(t.id),role:"button",tabIndex:0,onKeyDown:y=>y.key==="Enter"&&C(t.id),children:[k===t.id?e.jsx("select",{ref:Z,className:"select agent-role-select",value:t.role,onChange:y=>void J(t.id,y.target.value),onKeyDown:y=>ye(y,t.id),onBlur:()=>K(null),autoFocus:!0,children:Ce.map(y=>e.jsxs("option",{value:y.value,children:[y.icon," ",y.label]},y.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:y=>{y.stopPropagation(),K(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),K(t.id))},children:te(t.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(tt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${h}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:i.color},title:i.label,children:[i.icon,!i.stateDerived&&` ${i.label}`]}),e.jsx("span",{className:"badge text-secondary",children:ge(t.role)}),(()=>{const y=oe(t);if(y.length===0)return null;const q=y.slice(0,2),fe=y.length-2;return e.jsxs(e.Fragment,{children:[q.map(Le=>e.jsx("span",{className:"badge badge-skill",children:Le},Le)),fe>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",fe]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),me===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Y[t.id]??"",onChange:y=>P(q=>({...q,[t.id]:y.target.value})),onKeyDown:y=>{y.key==="Enter"?O(t):y.key==="Escape"&&(U(null),P(q=>{const fe={...q};return delete fe[t.id],fe}))},disabled:pe,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void O(t),disabled:pe,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),P(y=>{const q={...y};return delete q[t.id],q})},disabled:pe,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:S,onChange:y=>{const q=y.target.value;q==="__custom__"?D(t):we(t,Number(q))},disabled:pe,"aria-label":`Set heartbeat interval for ${t.name}`,children:[ce.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value)),St.some(y=>y.value===S)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),pe&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const y=new Date(t.lastHeartbeatAt),q=new Date(y.getTime()+S),fe=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:y.toLocaleString(),children:["Last: ",y.toLocaleTimeString()]}),fe&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:q.toLocaleString(),children:["Next: ",q.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[t.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Activate",children:[e.jsx(ke,{size:14})," Start"]}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void he(t.id,t.name),title:"Delete",children:[e.jsx(Ke,{size:14})," Delete"]})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void je(t.id,t.name),disabled:F.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(xe,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"paused"),disabled:F.has(t.id),title:"Pause",children:[e.jsx(Ue,{size:14})," Pause"]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Resume",children:[e.jsx(ke,{size:14})," Resume"]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${t.name}`,children:[e.jsx(xe,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"paused"),disabled:F.has(t.id),title:"Pause",children:[e.jsx(Ue,{size:14})," Pause"]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Retry",children:[e.jsx(ke,{size:14})," Retry"]}),t.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void ae(t.id,"active"),disabled:F.has(t.id),title:"Start",children:[e.jsx(ke,{size:14})," Start"]}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void he(t.id,t.name),title:"Delete",children:[e.jsx(Ke,{size:14})," Delete"]})]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>C(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:"View Details"})]})]},t.id)})}),e.jsx(Kt,{agents:u,projectId:l,onAgentSelect:C})]}),w&&e.jsx(s.Suspense,{fallback:null,children:e.jsx(Cn,{agentId:w,projectId:l,onClose:be,addToast:a,onChildClick:le})})]})}const _n=Object.freeze(Object.defineProperty({__proto__:null,AgentsView:Sn},Symbol.toStringTag,{value:"Module"}));export{_n as A,wn as S};
@@ -1 +1 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{i as _e,aw as ut,g as ht,ax as mt,a as gt,ay as ft,az as pt,aA as xt,aB as St,aC as bt,aD as vt,s as wt,aE as kt,aF as Nt,f as Ct,a5 as jt,a6 as Mt,w as Re,S as yt,I as He,ai as Tt,aG as At,B as je,a2 as Ge,a3 as Ue,aH as $t,aI as Et,aJ as Pt,aK as Dt,aL as Rt,aM as Lt,h as _t,j as zt}from"./index-DQKtk17v.js";import"./vendor-xterm-DzcZoU0P.js";const Le="kb-chat-active-session";function It(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 qe(n){return{id:n.id,sessionId:n.sessionId,role:n.role,content:n.content,thinkingOutput:n.thinkingOutput,toolCalls:It(n.metadata),createdAt:n.createdAt}}function Ft(n){const[i,c]=s.useState([]),[l,r]=s.useState(null),[f,v]=s.useState(!0),[M,w]=s.useState([]),[X,I]=s.useState(!1),[F,R]=s.useState(!1),[ce,E]=s.useState(""),[O,T]=s.useState(""),[pe,P]=s.useState([]),[p,D]=s.useState(""),[Z,U]=s.useState(""),[A,V]=s.useState(!0),[q,ne]=s.useState(new Map),N=s.useRef(null),J=s.useRef(!1),K=s.useRef(""),xe=s.useRef(i),B=s.useRef(l),ke=s.useRef(F);xe.current=i,B.current=l,ke.current=F,s.useEffect(()=>{K.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;_e(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 ut(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=ht(Le,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 mt(u,{limit:50,...m},n),k=h.messages.map(qe);m?.offset&&m.offset>0?w(W=>[...k,...W]):w(k),V(h.messages.length>=50)}catch{}finally{I(!1)}},[n]),oe=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([]),R(!1),V(!0),u?_(u):w([]),u?gt(Le,u,n):ft(Le,n)},[i,_,n]);Q.current=oe;const de=s.useCallback(async u=>{const m=await pt(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([]),R(!1),V(!0),h},[n]),ue=s.useCallback(async u=>{await xt(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 St(u,n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),he=s.useCallback(async()=>{!l||!A||await _(l.id,{offset:M.length})},[l,A,_,M.length]),se=s.useCallback(()=>{l&&(J.current=!0,N.current?.close(),N.current=null,bt(l.id,n).catch(()=>{}),R(!1),E(""),T(""),P([]))},[l,n]),H=s.useCallback(()=>{K.current="",D("")},[]),G=s.useCallback(u=>{if(!l)return;if(F){K.current=u,D(u);return}J.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([]),R(!0);let k="",W="",j=[];const be={onThinking:x=>{W+=x,T(W)},onText:x=>{k+=x,E(k)},onToolStart:x=>{j=[...j,{toolName:x.toolName,args:x.args,isError:!1,status:"running"}],P(j)},onToolEnd:x=>{const d=[...j];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},j=d,P(d);return}}j=[...d,{toolName:x.toolName,isError:x.isError,result:x.result,status:"completed"}],P(j)},onDone:x=>{const d={id:x.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:k,thinkingOutput:W,toolCalls:j.length>0?j:void 0,createdAt:new Date().toISOString()};ae.current.add(d.id),w(b=>[...b,d]),E(""),T(""),P([]),R(!1),N.current=null,setTimeout(()=>{ae.current.delete(d.id)},1e3),te();const S=K.current.trim();S&&(K.current="",D(""),G(S))},onError:x=>{if(w(d=>d.filter(S=>S.id!==m)),E(""),T(""),P([]),R(!1),N.current=null,console.error("[useChat] Stream error:",x),!J.current){const d=K.current.trim();d&&(K.current="",D(""),G(d))}}};N.current=vt(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(L=>L.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)]),B.current?.id===b.id&&r(b)},j=S=>{if(h())return;const{id:b}=JSON.parse(S.data);c(g=>g.filter(L=>L.id!==b)),B.current?.id===b&&(r(null),w([]))},be=S=>{if(h())return;const b=JSON.parse(S.data),g=qe(b);ae.current.has(g.id)||B.current?.id===g.sessionId&&!ke.current&&w(L=>L.some(C=>C.id===g.id)?L:[...L,g])},x=S=>{if(h())return;const{id:b}=JSON.parse(S.data);w(g=>g.filter(L=>L.id!==b))};return wt(`/api/events${m}`,{events:{"chat:session:created":k,"chat:session:updated":W,"chat:session:deleted":j,"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:M,messagesLoading:X,isStreaming:F,streamingText:ce,streamingThinking:O,streamingToolCalls:pe,pendingMessage:p,selectSession:oe,createSession:de,archiveSession:ue,deleteSession:ie,sendMessage:G,stopStreaming:se,clearPendingMessage:H,loadMoreMessages:he,hasMoreMessages:A,searchQuery:Z,setSearchQuery:U,filteredSessions:Se,refreshSessions:te,agentsMap:q}}function Je(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),M=Math.floor(v/24);return r<60?"just now":f<60?`${f}m ago`:v<24?`${v}h ago`:M<7?`${M}d ago`:i.toLocaleDateString()}function Ke(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 Me(n,i){return n.length>i?`${n.slice(0,i)}…`:n}function Ot(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}=${Me(r,50)}`}).join(", ")}function Vt(n){if(n===void 0)return null;if(typeof n=="string")return Me(n,200);try{return Me(JSON.stringify(n),200)}catch{return Me(String(n),200)}}function Qe(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(Lt,{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=Ot(i.args),v=Vt(i.result),M=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}),M&&e.jsx("span",{className:"chat-tool-call-preview",title:M,children:M}),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 Bt={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})},ye="__fn_agent__";function We(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 Ht(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 Gt({projectId:n,onClose:i,onCreate:c}){const[l,r]=s.useState("agent"),[f,v]=s.useState([]),[M,w]=s.useState(!0),[X,I]=s.useState(""),[F,R]=s.useState([]),[ce,E]=s.useState(!0),[O,T]=s.useState("");s.useEffect(()=>{let p=!1;return w(!0),_e(void 0,n).then(D=>{p||v(D)}).catch(()=>{p||v([])}).finally(()=>{p||w(!1)}),()=>{p=!0}},[n]),s.useEffect(()=>{E(!0),_t().then(p=>{R(p.models)}).catch(()=>{R([])}).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),U=O.slice(D+1);c({agentId:ye,modelProvider:Z,modelId:U})},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",M?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:ce?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):e.jsx(zt,{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 Qt({projectId:n,addToast:i}){const{activeSession:c,sessionsLoading:l,messages:r,messagesLoading:f,isStreaming:v,streamingText:M,streamingThinking:w,streamingToolCalls:X,selectSession:I,createSession:F,archiveSession:R,deleteSession:ce,sendMessage:E,stopStreaming:O,pendingMessage:T,clearPendingMessage:pe,searchQuery:P,setSearchQuery:p,filteredSessions:D}=Ft(n),[Z,U]=s.useState(!1),[A,V]=s.useState(""),[q,ne]=s.useState(null),[N,J]=s.useState(null),[K,xe]=s.useState(!0),[B,ke]=s.useState(new Map),[ae,ee]=s.useState([]),[Ne,te]=s.useState(!0),[Q,_]=s.useState(!1),[oe,de]=s.useState(""),[ue,ie]=s.useState(0),[he,se]=s.useState(""),[H,G]=s.useState(!1),[Se,u]=s.useState(0),[m,h]=s.useState(-1),[k,W]=s.useState(()=>new Set),[,j]=s.useState(!1),[be,x]=s.useState({top:0,left:0}),d=kt({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),L=s.useRef(null),C=s.useRef(null),ve=s.useRef(0),me=Nt()==="mobile",z=s.useMemo(()=>{const t=oe.trim().toLowerCase();return(t?ae.filter(o=>o.name.toLowerCase().includes(t)):ae).slice(0,10)},[ae,oe]),ge=s.useMemo(()=>Array.from(B.values()),[B]),le=s.useMemo(()=>{const t=he.trim().toLowerCase();return t?ge.filter(a=>a.name.toLowerCase().includes(t)):ge},[ge,he]),ze=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)},[he,H]),s.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current)},[]),s.useEffect(()=>{b.current?.scrollIntoView({behavior:"smooth"})},[r,M]),s.useEffect(()=>{const t=()=>ne(null);if(q)return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[q]),s.useEffect(()=>{let t=!1;const a=n;return _e(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),Ct(n).then(a=>{t||ee(a)}).catch(()=>{t||ee([])}).finally(()=>{t||te(!1)}),()=>{t=!0}},[n]);const Ye=s.useCallback(async t=>{try{await F(t),U(!1),me&&xe(!1)}catch{i("Failed to create chat session","error")}},[F,i,me]),Te=s.useCallback(()=>{const t=A.trim();!t||!c||(V(""),_(!1),de(""),G(!1),se(""),h(-1),E(t))},[A,c,E]),Ae=s.useCallback(t=>{V(a=>{const o=We(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),de(""),ie(0)},[]),$e=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,$),re=`${`@${t.name.replace(/\s+/g,"_")}`} `,De=A.slice(0,we)+re+A.slice($),fe=we+re.length;V(De),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]),Xe=s.useCallback(t=>{const a=/@([\w-]+)/g,o=[];let y=0,$=a.exec(t);for(;$;){const[we,Be=""]=$,re=$.index;re>y&&o.push(t.slice(y,re));const De=Be.replace(/_/g," ").toLowerCase(),fe=ze.get(De);fe?o.push(e.jsxs("span",{className:"chat-mention-chip",children:["@",fe.name.replace(/\s+/g,"_")]},`${fe.id}-${re}`)):o.push(we),y=re+we.length,$=a.exec(t)}return y<t.length&&o.push(t.slice(y)),o.length===0?t:o},[ze]),Ze=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);V(o),d.dismissMention(),j(!1)}}return}if(H&&t.key==="ArrowDown"){t.preventDefault(),le.length>0&&u(a=>(a+1)%le.length);return}if(H&&t.key==="ArrowUp"){t.preventDefault(),le.length>0&&u(a=>a===0?le.length-1:a-1);return}if(H&&t.key==="Enter"){t.preventDefault();const a=le[Se]??le[0];a&&$e(a);return}if(H&&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[ue]??z[0];a&&Ae(a);return}if(Q&&t.key==="Escape"){t.preventDefault(),_(!1);return}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Te())},[H,le,Se,$e,Q,z,ue,Ae,Te,d,A]),Ce=s.useCallback((t,a)=>{const o=Ht(t,a);if(o){G(!0),se(o.filter),h(o.start);return}G(!1),se(""),h(-1)},[]),et=s.useCallback(t=>{const a=t.target,o=a.value,y=a.selectionStart??o.length;ve.current=y,V(o);const $=We(o);$?(_(!0),de($.filter)):(_(!1),de("")),Ce(o,y),d.detectMention(o,y),j(d.mentionActive),d.mentionActive&&S(a),a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},[Ce]),Ee=s.useCallback(t=>{const a=t.currentTarget,o=a.selectionStart??a.value.length;ve.current=o,Ce(a.value,o),d.detectMention(a.value,o),j(d.mentionActive),d.mentionActive&&S(a)},[Ce,d,S]),tt=s.useCallback(t=>{t.key!=="Escape"&&Ee(t)},[Ee]),st=s.useCallback(()=>{g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{_(!1),G(!1),se(""),h(-1),j(!1),d.dismissMention(),g.current=null},120)},[d]),nt=s.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),at=s.useCallback(async t=>{ne(null);try{await R(t),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[R,i]),it=s.useCallback(async t=>{J(null),ne(null);try{await ce(t),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[ce,i]),lt=s.useCallback(t=>{I(t),me&&xe(!1)},[I,me]),rt=s.useCallback(()=>{I(""),xe(!0)},[I]),ct=()=>e.jsxs("div",{className:"chat-empty-state",children:[e.jsx(Rt,{size:48,strokeWidth:1.5}),e.jsx("h2",{children:"Start a new conversation"}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>U(!0),children:[e.jsx(Re,{size:16}),"New Chat"]})]}),Y=Ke(c?.modelProvider,c?.modelId),Ie=c?.agentId===ye?Y??"Fusion":c?.title||B.get(c?.agentId??"")?.name||c?.agentId||"Chat",ot=!!(Y&&Y!==Ie),Pe=B.get(c?.agentId??"")?.name||(c?.agentId===ye?Y??"Fusion":c?.agentId?.slice(0,30)??"Fusion"),Fe=!!(Y&&Y!==Pe),dt=T.length>50?`${T.slice(0,50)}…`:T,Oe=s.useCallback(t=>{W(a=>{const o=new Set(a);return o.has(t)?o.delete(t):o.add(t),o})},[]),Ve=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(jt,{remarkPlugins:[Mt],components:Bt,children:t})}),[]);return e.jsxs("div",{className:"chat-view",children:[e.jsxs("div",{className:`chat-sidebar${K?"":" chat-sidebar--hidden"}`,children:[e.jsx("div",{className:"chat-sidebar-header",children:e.jsxs("button",{className:"btn btn-sm btn-primary",onClick:()=>U(!0),"data-testid":"chat-new-btn",children:[e.jsx(Re,{size:14}),"New Chat"]})}),e.jsx("div",{className:"chat-sidebar-search",children:e.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[e.jsx(yt,{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:()=>lt(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(),J(t.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:e.jsx(He,{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:B.get(t.agentId)?.name||(t.agentId===ye?Ke(t.modelProvider,t.modelId)??"Fusion":t.agentId.slice(0,30))}),e.jsx("span",{children:t.updatedAt?Je(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:()=>U(!0),"data-testid":"chat-new-btn-mobile",children:[e.jsx(Re,{size:14}),"New Chat"]})})]}),q&&e.jsxs("div",{className:"chat-session-context-menu",style:{top:q.y,left:q.x},onClick:t=>t.stopPropagation(),children:[e.jsxs("button",{onClick:()=>at(q.sessionId),"data-testid":"chat-context-archive",children:[e.jsx(Tt,{size:14}),"Archive"]}),e.jsxs("button",{onClick:()=>{ne(null),J(q.sessionId)},"data-testid":"chat-context-delete",children:[e.jsx(He,{size:14}),"Delete"]})]}),N&&e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>J(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:()=>J(null),children:"Cancel"}),e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void it(N),children:"Delete"})]})]})}),e.jsxs("div",{className:"chat-thread",children:[(c||!me)&&e.jsxs("div",{className:"chat-thread-header",children:[me&&c&&e.jsx("button",{className:"btn-icon",onClick:rt,"data-testid":"chat-back-btn",children:e.jsx(At,{size:16})}),e.jsx(je,{size:16}),e.jsx("span",{className:"chat-thread-header-title",children:Ie}),ot&&e.jsx("span",{className:"chat-model-tag",children:Y})]}),e.jsxs("div",{className:"chat-messages",ref:L,children:[f?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):r.length===0&&!c?ct():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:Pe}),Fe&&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:()=>Oe(t.id),children:o?e.jsx(Ge,{size:14}):e.jsx(Ue,{size:14})})]}),a?Ve(t.content,o):e.jsx("div",{className:"chat-message-content",children:Xe(t.content)}),Qe(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:Je(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:Pe}),Fe&&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:()=>Oe("__streaming__"),children:k.has("__streaming__")?e.jsx(Ge,{size:14}):e.jsx(Ue,{size:14})})]}),M?Ve(M,k.has("__streaming__")):e.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:w?"Thinking…":"Connecting…"}),Qe(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:oe?"No skills found":"No skills available"}):z.map((t,a)=>e.jsxs("button",{type:"button",role:"option","aria-selected":a===ue,className:`chat-skill-menu-item${a===ue?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>ie(a),onClick:()=>Ae(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:et,onKeyDown:Ze,onKeyUp:tt,onClick:Ee,onBlur:st,onFocus:nt,rows:1,"data-testid":"chat-input"}),e.jsx($t,{agents:ge,filter:he,highlightedIndex:Se,visible:H,onSelect:$e,position:"below"}),e.jsx(Et,{visible:d.mentionActive&&!H,position:be,files:d.files,selectedIndex:d.selectedIndex,onSelect:t=>{const a=d.selectFile(t,A);V(a),d.dismissMention(),j(!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: ${dt}`}),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(Pt,{size:14})}):e.jsx("button",{className:"chat-input-send",onClick:()=>void Te(),disabled:!A.trim(),"data-testid":"chat-send-btn",children:e.jsx(Dt,{size:16})})]})]}),Z&&e.jsx(Gt,{projectId:n,onClose:()=>U(!1),onCreate:Ye})]})}export{Qt as ChatView};
1
+ import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{i as _e,aw as ut,g as ht,ax as mt,a as gt,ay as ft,az as pt,aA as xt,aB as St,aC as bt,aD as vt,s as wt,aE as kt,aF as Nt,f as Ct,a5 as jt,a6 as Mt,w as Re,S as yt,I as He,ai as Tt,aG as At,B as je,a2 as Ge,a3 as Ue,aH as $t,aI as Et,aJ as Pt,aK as Dt,aL as Rt,aM as Lt,h as _t,j as zt}from"./index-CGW6tOaX.js";import"./vendor-xterm-DzcZoU0P.js";const Le="kb-chat-active-session";function It(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 qe(n){return{id:n.id,sessionId:n.sessionId,role:n.role,content:n.content,thinkingOutput:n.thinkingOutput,toolCalls:It(n.metadata),createdAt:n.createdAt}}function Ft(n){const[i,c]=s.useState([]),[l,r]=s.useState(null),[f,v]=s.useState(!0),[M,w]=s.useState([]),[X,I]=s.useState(!1),[F,R]=s.useState(!1),[ce,E]=s.useState(""),[O,T]=s.useState(""),[pe,P]=s.useState([]),[p,D]=s.useState(""),[Z,U]=s.useState(""),[A,V]=s.useState(!0),[q,ne]=s.useState(new Map),N=s.useRef(null),J=s.useRef(!1),K=s.useRef(""),xe=s.useRef(i),B=s.useRef(l),ke=s.useRef(F);xe.current=i,B.current=l,ke.current=F,s.useEffect(()=>{K.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;_e(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 ut(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=ht(Le,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 mt(u,{limit:50,...m},n),k=h.messages.map(qe);m?.offset&&m.offset>0?w(W=>[...k,...W]):w(k),V(h.messages.length>=50)}catch{}finally{I(!1)}},[n]),oe=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([]),R(!1),V(!0),u?_(u):w([]),u?gt(Le,u,n):ft(Le,n)},[i,_,n]);Q.current=oe;const de=s.useCallback(async u=>{const m=await pt(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([]),R(!1),V(!0),h},[n]),ue=s.useCallback(async u=>{await xt(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 St(u,n),c(m=>m.filter(h=>h.id!==u)),l?.id===u&&(r(null),w([]))},[l,n]),he=s.useCallback(async()=>{!l||!A||await _(l.id,{offset:M.length})},[l,A,_,M.length]),se=s.useCallback(()=>{l&&(J.current=!0,N.current?.close(),N.current=null,bt(l.id,n).catch(()=>{}),R(!1),E(""),T(""),P([]))},[l,n]),H=s.useCallback(()=>{K.current="",D("")},[]),G=s.useCallback(u=>{if(!l)return;if(F){K.current=u,D(u);return}J.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([]),R(!0);let k="",W="",j=[];const be={onThinking:x=>{W+=x,T(W)},onText:x=>{k+=x,E(k)},onToolStart:x=>{j=[...j,{toolName:x.toolName,args:x.args,isError:!1,status:"running"}],P(j)},onToolEnd:x=>{const d=[...j];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},j=d,P(d);return}}j=[...d,{toolName:x.toolName,isError:x.isError,result:x.result,status:"completed"}],P(j)},onDone:x=>{const d={id:x.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:k,thinkingOutput:W,toolCalls:j.length>0?j:void 0,createdAt:new Date().toISOString()};ae.current.add(d.id),w(b=>[...b,d]),E(""),T(""),P([]),R(!1),N.current=null,setTimeout(()=>{ae.current.delete(d.id)},1e3),te();const S=K.current.trim();S&&(K.current="",D(""),G(S))},onError:x=>{if(w(d=>d.filter(S=>S.id!==m)),E(""),T(""),P([]),R(!1),N.current=null,console.error("[useChat] Stream error:",x),!J.current){const d=K.current.trim();d&&(K.current="",D(""),G(d))}}};N.current=vt(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(L=>L.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)]),B.current?.id===b.id&&r(b)},j=S=>{if(h())return;const{id:b}=JSON.parse(S.data);c(g=>g.filter(L=>L.id!==b)),B.current?.id===b&&(r(null),w([]))},be=S=>{if(h())return;const b=JSON.parse(S.data),g=qe(b);ae.current.has(g.id)||B.current?.id===g.sessionId&&!ke.current&&w(L=>L.some(C=>C.id===g.id)?L:[...L,g])},x=S=>{if(h())return;const{id:b}=JSON.parse(S.data);w(g=>g.filter(L=>L.id!==b))};return wt(`/api/events${m}`,{events:{"chat:session:created":k,"chat:session:updated":W,"chat:session:deleted":j,"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:M,messagesLoading:X,isStreaming:F,streamingText:ce,streamingThinking:O,streamingToolCalls:pe,pendingMessage:p,selectSession:oe,createSession:de,archiveSession:ue,deleteSession:ie,sendMessage:G,stopStreaming:se,clearPendingMessage:H,loadMoreMessages:he,hasMoreMessages:A,searchQuery:Z,setSearchQuery:U,filteredSessions:Se,refreshSessions:te,agentsMap:q}}function Je(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),M=Math.floor(v/24);return r<60?"just now":f<60?`${f}m ago`:v<24?`${v}h ago`:M<7?`${M}d ago`:i.toLocaleDateString()}function Ke(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 Me(n,i){return n.length>i?`${n.slice(0,i)}…`:n}function Ot(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}=${Me(r,50)}`}).join(", ")}function Vt(n){if(n===void 0)return null;if(typeof n=="string")return Me(n,200);try{return Me(JSON.stringify(n),200)}catch{return Me(String(n),200)}}function Qe(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(Lt,{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=Ot(i.args),v=Vt(i.result),M=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}),M&&e.jsx("span",{className:"chat-tool-call-preview",title:M,children:M}),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 Bt={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})},ye="__fn_agent__";function We(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 Ht(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 Gt({projectId:n,onClose:i,onCreate:c}){const[l,r]=s.useState("agent"),[f,v]=s.useState([]),[M,w]=s.useState(!0),[X,I]=s.useState(""),[F,R]=s.useState([]),[ce,E]=s.useState(!0),[O,T]=s.useState("");s.useEffect(()=>{let p=!1;return w(!0),_e(void 0,n).then(D=>{p||v(D)}).catch(()=>{p||v([])}).finally(()=>{p||w(!1)}),()=>{p=!0}},[n]),s.useEffect(()=>{E(!0),_t().then(p=>{R(p.models)}).catch(()=>{R([])}).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),U=O.slice(D+1);c({agentId:ye,modelProvider:Z,modelId:U})},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",M?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:ce?e.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):e.jsx(zt,{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 Qt({projectId:n,addToast:i}){const{activeSession:c,sessionsLoading:l,messages:r,messagesLoading:f,isStreaming:v,streamingText:M,streamingThinking:w,streamingToolCalls:X,selectSession:I,createSession:F,archiveSession:R,deleteSession:ce,sendMessage:E,stopStreaming:O,pendingMessage:T,clearPendingMessage:pe,searchQuery:P,setSearchQuery:p,filteredSessions:D}=Ft(n),[Z,U]=s.useState(!1),[A,V]=s.useState(""),[q,ne]=s.useState(null),[N,J]=s.useState(null),[K,xe]=s.useState(!0),[B,ke]=s.useState(new Map),[ae,ee]=s.useState([]),[Ne,te]=s.useState(!0),[Q,_]=s.useState(!1),[oe,de]=s.useState(""),[ue,ie]=s.useState(0),[he,se]=s.useState(""),[H,G]=s.useState(!1),[Se,u]=s.useState(0),[m,h]=s.useState(-1),[k,W]=s.useState(()=>new Set),[,j]=s.useState(!1),[be,x]=s.useState({top:0,left:0}),d=kt({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),L=s.useRef(null),C=s.useRef(null),ve=s.useRef(0),me=Nt()==="mobile",z=s.useMemo(()=>{const t=oe.trim().toLowerCase();return(t?ae.filter(o=>o.name.toLowerCase().includes(t)):ae).slice(0,10)},[ae,oe]),ge=s.useMemo(()=>Array.from(B.values()),[B]),le=s.useMemo(()=>{const t=he.trim().toLowerCase();return t?ge.filter(a=>a.name.toLowerCase().includes(t)):ge},[ge,he]),ze=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)},[he,H]),s.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current)},[]),s.useEffect(()=>{b.current?.scrollIntoView({behavior:"smooth"})},[r,M]),s.useEffect(()=>{const t=()=>ne(null);if(q)return document.addEventListener("click",t),()=>document.removeEventListener("click",t)},[q]),s.useEffect(()=>{let t=!1;const a=n;return _e(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),Ct(n).then(a=>{t||ee(a)}).catch(()=>{t||ee([])}).finally(()=>{t||te(!1)}),()=>{t=!0}},[n]);const Ye=s.useCallback(async t=>{try{await F(t),U(!1),me&&xe(!1)}catch{i("Failed to create chat session","error")}},[F,i,me]),Te=s.useCallback(()=>{const t=A.trim();!t||!c||(V(""),_(!1),de(""),G(!1),se(""),h(-1),E(t))},[A,c,E]),Ae=s.useCallback(t=>{V(a=>{const o=We(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),de(""),ie(0)},[]),$e=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,$),re=`${`@${t.name.replace(/\s+/g,"_")}`} `,De=A.slice(0,we)+re+A.slice($),fe=we+re.length;V(De),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]),Xe=s.useCallback(t=>{const a=/@([\w-]+)/g,o=[];let y=0,$=a.exec(t);for(;$;){const[we,Be=""]=$,re=$.index;re>y&&o.push(t.slice(y,re));const De=Be.replace(/_/g," ").toLowerCase(),fe=ze.get(De);fe?o.push(e.jsxs("span",{className:"chat-mention-chip",children:["@",fe.name.replace(/\s+/g,"_")]},`${fe.id}-${re}`)):o.push(we),y=re+we.length,$=a.exec(t)}return y<t.length&&o.push(t.slice(y)),o.length===0?t:o},[ze]),Ze=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);V(o),d.dismissMention(),j(!1)}}return}if(H&&t.key==="ArrowDown"){t.preventDefault(),le.length>0&&u(a=>(a+1)%le.length);return}if(H&&t.key==="ArrowUp"){t.preventDefault(),le.length>0&&u(a=>a===0?le.length-1:a-1);return}if(H&&t.key==="Enter"){t.preventDefault();const a=le[Se]??le[0];a&&$e(a);return}if(H&&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[ue]??z[0];a&&Ae(a);return}if(Q&&t.key==="Escape"){t.preventDefault(),_(!1);return}t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),Te())},[H,le,Se,$e,Q,z,ue,Ae,Te,d,A]),Ce=s.useCallback((t,a)=>{const o=Ht(t,a);if(o){G(!0),se(o.filter),h(o.start);return}G(!1),se(""),h(-1)},[]),et=s.useCallback(t=>{const a=t.target,o=a.value,y=a.selectionStart??o.length;ve.current=y,V(o);const $=We(o);$?(_(!0),de($.filter)):(_(!1),de("")),Ce(o,y),d.detectMention(o,y),j(d.mentionActive),d.mentionActive&&S(a),a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},[Ce]),Ee=s.useCallback(t=>{const a=t.currentTarget,o=a.selectionStart??a.value.length;ve.current=o,Ce(a.value,o),d.detectMention(a.value,o),j(d.mentionActive),d.mentionActive&&S(a)},[Ce,d,S]),tt=s.useCallback(t=>{t.key!=="Escape"&&Ee(t)},[Ee]),st=s.useCallback(()=>{g.current!==null&&window.clearTimeout(g.current),g.current=window.setTimeout(()=>{_(!1),G(!1),se(""),h(-1),j(!1),d.dismissMention(),g.current=null},120)},[d]),nt=s.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),at=s.useCallback(async t=>{ne(null);try{await R(t),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[R,i]),it=s.useCallback(async t=>{J(null),ne(null);try{await ce(t),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[ce,i]),lt=s.useCallback(t=>{I(t),me&&xe(!1)},[I,me]),rt=s.useCallback(()=>{I(""),xe(!0)},[I]),ct=()=>e.jsxs("div",{className:"chat-empty-state",children:[e.jsx(Rt,{size:48,strokeWidth:1.5}),e.jsx("h2",{children:"Start a new conversation"}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>U(!0),children:[e.jsx(Re,{size:16}),"New Chat"]})]}),Y=Ke(c?.modelProvider,c?.modelId),Ie=c?.agentId===ye?Y??"Fusion":c?.title||B.get(c?.agentId??"")?.name||c?.agentId||"Chat",ot=!!(Y&&Y!==Ie),Pe=B.get(c?.agentId??"")?.name||(c?.agentId===ye?Y??"Fusion":c?.agentId?.slice(0,30)??"Fusion"),Fe=!!(Y&&Y!==Pe),dt=T.length>50?`${T.slice(0,50)}…`:T,Oe=s.useCallback(t=>{W(a=>{const o=new Set(a);return o.has(t)?o.delete(t):o.add(t),o})},[]),Ve=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(jt,{remarkPlugins:[Mt],components:Bt,children:t})}),[]);return e.jsxs("div",{className:"chat-view",children:[e.jsxs("div",{className:`chat-sidebar${K?"":" chat-sidebar--hidden"}`,children:[e.jsx("div",{className:"chat-sidebar-header",children:e.jsxs("button",{className:"btn btn-sm btn-primary",onClick:()=>U(!0),"data-testid":"chat-new-btn",children:[e.jsx(Re,{size:14}),"New Chat"]})}),e.jsx("div",{className:"chat-sidebar-search",children:e.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[e.jsx(yt,{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:()=>lt(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(),J(t.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:e.jsx(He,{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:B.get(t.agentId)?.name||(t.agentId===ye?Ke(t.modelProvider,t.modelId)??"Fusion":t.agentId.slice(0,30))}),e.jsx("span",{children:t.updatedAt?Je(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:()=>U(!0),"data-testid":"chat-new-btn-mobile",children:[e.jsx(Re,{size:14}),"New Chat"]})})]}),q&&e.jsxs("div",{className:"chat-session-context-menu",style:{top:q.y,left:q.x},onClick:t=>t.stopPropagation(),children:[e.jsxs("button",{onClick:()=>at(q.sessionId),"data-testid":"chat-context-archive",children:[e.jsx(Tt,{size:14}),"Archive"]}),e.jsxs("button",{onClick:()=>{ne(null),J(q.sessionId)},"data-testid":"chat-context-delete",children:[e.jsx(He,{size:14}),"Delete"]})]}),N&&e.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>J(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:()=>J(null),children:"Cancel"}),e.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void it(N),children:"Delete"})]})]})}),e.jsxs("div",{className:"chat-thread",children:[(c||!me)&&e.jsxs("div",{className:"chat-thread-header",children:[me&&c&&e.jsx("button",{className:"btn-icon",onClick:rt,"data-testid":"chat-back-btn",children:e.jsx(At,{size:16})}),e.jsx(je,{size:16}),e.jsx("span",{className:"chat-thread-header-title",children:Ie}),ot&&e.jsx("span",{className:"chat-model-tag",children:Y})]}),e.jsxs("div",{className:"chat-messages",ref:L,children:[f?e.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):r.length===0&&!c?ct():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:Pe}),Fe&&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:()=>Oe(t.id),children:o?e.jsx(Ge,{size:14}):e.jsx(Ue,{size:14})})]}),a?Ve(t.content,o):e.jsx("div",{className:"chat-message-content",children:Xe(t.content)}),Qe(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:Je(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:Pe}),Fe&&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:()=>Oe("__streaming__"),children:k.has("__streaming__")?e.jsx(Ge,{size:14}):e.jsx(Ue,{size:14})})]}),M?Ve(M,k.has("__streaming__")):e.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:w?"Thinking…":"Connecting…"}),Qe(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:oe?"No skills found":"No skills available"}):z.map((t,a)=>e.jsxs("button",{type:"button",role:"option","aria-selected":a===ue,className:`chat-skill-menu-item${a===ue?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>ie(a),onClick:()=>Ae(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:et,onKeyDown:Ze,onKeyUp:tt,onClick:Ee,onBlur:st,onFocus:nt,rows:1,"data-testid":"chat-input"}),e.jsx($t,{agents:ge,filter:he,highlightedIndex:Se,visible:H,onSelect:$e,position:"below"}),e.jsx(Et,{visible:d.mentionActive&&!H,position:be,files:d.files,selectedIndex:d.selectedIndex,onSelect:t=>{const a=d.selectFile(t,A);V(a),d.dismissMention(),j(!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: ${dt}`}),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(Pt,{size:14})}):e.jsx("button",{className:"chat-input-send",onClick:()=>void Te(),disabled:!A.trim(),"data-testid":"chat-send-btn",children:e.jsx(Dt,{size:16})})]})]}),Z&&e.jsx(Gt,{projectId:n,onClose:()=>U(!1),onCreate:Ye})]})}export{Qt as ChatView};
@@ -1,4 +1,4 @@
1
- import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bm as Me,bn as de,bo as et,bp as ue,s as Ue,bq as ge,br as we,bs as xe,bt as ye,bu as tt,bv as ae,bw as rt,bx as st,by as nt,bz as at,bA as it,bB as ie,L as ee,S as lt,bC as ct,bD as ot,K as dt,T as Ae,bE as ut,E as vt,aJ as mt,a3 as ft,ah as pt,R as ht}from"./index-DQKtk17v.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bm as Me,bn as de,bo as et,bp as ue,s as Ue,bq as ge,br as we,bs as xe,bt as ye,bu as tt,bv as ae,bw as rt,bx as st,by as nt,bz as at,bA as it,bB as ie,L as ee,S as lt,bC as ct,bD as ot,K as dt,T as Ae,bE as ut,E as vt,aJ as mt,a3 as ft,ah as pt,R as ht}from"./index-CGW6tOaX.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{cY as f,c4 as m,D as y,a7 as g,a2 as P,a3 as C,L as H,ae as O}from"./index-DQKtk17v.js";import{F as v}from"./folder-open-B_38R5AA.js";function S({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(C,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(H,{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{S as D};
1
+ import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{d4 as f,cc as m,D as y,a7 as g,a2 as P,a3 as C,L as H,ae as O}from"./index-CGW6tOaX.js";import{F as v}from"./folder-open-BJ4SvamV.js";function S({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(C,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(H,{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{S as D};
@@ -1 +1 @@
1
- import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{Y as oe,$ as G,a0 as le,a1 as ie,F as z,a2 as de,a3 as ue,S as me,X as he,R as pe,a4 as fe,a5 as W,a6 as V,K as X,D as je,a7 as xe}from"./index-DQKtk17v.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?G(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 G(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 Y(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:Y(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:_,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:J,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"?J:_,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,K=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-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:K,value:l,onChange:Z,"aria-label":K}),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)," · ",Y(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{Y as oe,$ as G,a0 as le,a1 as ie,F as z,a2 as de,a3 as ue,S as me,X as he,R as pe,a4 as fe,a5 as W,a6 as V,K as X,D as je,a7 as xe}from"./index-CGW6tOaX.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?G(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 G(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 Y(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:Y(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:_,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:J,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"?J:_,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,K=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-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:K,value:l,onChange:Z,"aria-label":K}),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)," · ",Y(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,a8 as Q,a9 as V,aa as W,ab as X,ac as J,ad as x,X as T,R as j,C as q,ae as F,af as G,ag as K,w as B,ah as Z,ai as ss,aj as P}from"./index-DQKtk17v.js";import{U as _}from"./users-CG2_rCdk.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 as V,aa as W,ab as X,ac as J,ad as x,X as T,R as j,C as q,ae as F,af as G,ag as K,w as B,ah as Z,ai as ss,aj as P}from"./index-CGW6tOaX.js";import{U as _}from"./users-ndAFpylb.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-CNdVTVqD.js";import{b8 as Se,b9 as Ne,ba as Fe,o as De,bb as ze,bc as Ie,bd as Le,be as Ce,bf as ke,bg as Re,bh as qe,bi as Ee,bj as Pe,n as Te,bk as We,L as A,bl as Me}from"./index-DQKtk17v.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-0IyoaKEv.js";import{b8 as Se,b9 as Ne,ba as Fe,o as De,bb as ze,bc as Ie,bd as Le,be as Ce,bf as ke,bg as Re,bh as qe,bi as Ee,bj as Pe,n as Te,bk as We,L as A,bl as Me}from"./index-CGW6tOaX.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};
@@ -1,4 +1,4 @@
1
- import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,ak as xe,al as ge,am as pe,an as je,ao as Z,ap as Q,A as T,aq as _e,I as Ne,K as be,ar as ee,as as ve,at as Ce,X as B,au as ke,av as Se,R as J,w as G,G as we}from"./index-DQKtk17v.js";import{U as se}from"./upload-DNQF7XCK.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,ak as xe,al as ge,am as pe,an as je,ao as Z,ap as Q,A as T,aq as _e,I as Ne,K as be,ar as ee,as as ve,at as Ce,X as B,au as ke,av as Se,R as J,w as G,G as we}from"./index-CGW6tOaX.js";import{U as se}from"./upload-DJYyvab0.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.