@runfusion/fusion 0.17.0 → 0.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/bin.js +1729 -789
  2. package/dist/client/assets/{AgentDetailView-DGqT1oDt.js → AgentDetailView-17J-F0Rl.js} +3 -3
  3. package/dist/client/assets/{AgentsView-BmemrfrO.js → AgentsView-sbBkb7Wd.js} +45 -45
  4. package/dist/client/assets/ChatView-BR5cvK_B.js +1 -0
  5. package/dist/client/assets/{DevServerView-C3Q0XqDA.js → DevServerView-GFFVXHVP.js} +1 -1
  6. package/dist/client/assets/{DirectoryPicker-BZWVA9ND.js → DirectoryPicker-WPDSBdT6.js} +1 -1
  7. package/dist/client/assets/{DocumentsView-DO48ivSq.js → DocumentsView-BHpDsIIt.js} +1 -1
  8. package/dist/client/assets/{InsightsView-CAngTfMf.js → InsightsView-Bxu0TJkt.js} +1 -1
  9. package/dist/client/assets/{MemoryView-B3rNcAOW.js → MemoryView-CmnzZorw.js} +2 -2
  10. package/dist/client/assets/{NodesView-BnV1LWa8.js → NodesView-CO9_4hCr.js} +4 -4
  11. package/dist/client/assets/{PiExtensionsManager-C3_Lw4sa.js → PiExtensionsManager-4e3MlD62.js} +3 -3
  12. package/dist/client/assets/{PluginManager-Vv3nzrJ1.js → PluginManager-DGN2rvOY.js} +1 -1
  13. package/dist/client/assets/ResearchView-Dsa6Gykl.js +1 -0
  14. package/dist/client/assets/{RoadmapsView-BiIpE-b8.js → RoadmapsView-jHTOK0RQ.js} +2 -2
  15. package/dist/client/assets/{SettingsModal-CK4w8Ztb.js → SettingsModal-4Z8ZJMzD.js} +1 -1
  16. package/dist/client/assets/SettingsModal-D0kuJpBA.js +31 -0
  17. package/dist/client/assets/{SetupWizardModal-Dw6N4UvY.js → SetupWizardModal-Bhumd4Rf.js} +1 -1
  18. package/dist/client/assets/{SkillsView-C1196wgA.js → SkillsView-MHweJTz4.js} +1 -1
  19. package/dist/client/assets/{folder-open-WVtgE4k3.js → folder-open-BNQW9dE9.js} +1 -1
  20. package/dist/client/assets/{index-BIJgrHEn.css → index-DEVBHvyW.css} +1 -1
  21. package/dist/client/assets/index-k_85J1DS.js +682 -0
  22. package/dist/client/assets/{star-MSImEC8V.js → star-7L86NZrT.js} +1 -1
  23. package/dist/client/assets/{upload-Dmvy3xXd.js → upload-DsAS6tno.js} +1 -1
  24. package/dist/client/assets/{users-CncYvHNf.js → users-D3u6f2Rz.js} +1 -1
  25. package/dist/client/index.html +2 -2
  26. package/dist/client/version.json +1 -1
  27. package/dist/extension.js +1239 -527
  28. package/dist/pi-claude-cli/package.json +1 -1
  29. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  30. package/package.json +1 -1
  31. package/dist/client/assets/ChatView-CZQUBFlV.js +0 -1
  32. package/dist/client/assets/ResearchView-Dfdsuc21.js +0 -1
  33. package/dist/client/assets/SettingsModal-BN00HYJ2.js +0 -31
  34. package/dist/client/assets/index-Bv0TGzDH.js +0 -682
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion/pi-claude-cli",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "Fusion vendored fork: pi coding-agent extension that routes LLM calls through the Claude Code CLI. Forked from rchern/pi-claude-cli (MIT). See UPSTREAM.md.",
5
5
  "license": "MIT",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/dependency-graph",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Dependency graph dashboard view plugin for Fusion",
6
6
  "private": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runfusion/fusion",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "license": "MIT",
5
5
  "description": "Fusion CLI: HTTP API server, daemon, dashboard launcher, and task tooling for the Fusion AI coding agent.",
6
6
  "homepage": "https://github.com/Runfusion/Fusion#readme",
@@ -1 +0,0 @@
1
- import{r as s,j as t}from"./vendor-react-K0fH_qHe.js";import{i as tt,aS as Ht,x as Bt,aT as Gt,z as Vt,aU as qt,aV as Kt,aW as Xt,aX as Yt,aY as Jt,aZ as Qt,s as Zt,a_ as es,v as ts,a$ as ss,b0 as ns,ad as pt,ae as xt,S as as,Y as ot,M as Ze,aq as is,$ as rs,B as We,aa as vt,ab as wt,b1 as ls,b2 as os,b3 as cs,aJ as ds,b4 as us,b5 as hs,b6 as ct,b7 as ms,h as fs,u as dt,k as gs}from"./index-Bv0TGzDH.js";import"./vendor-xterm-DzcZoU0P.js";const et="kb-chat-active-session";function ps(a){const i=a?.toolCalls;if(!Array.isArray(i))return;const l=i.map(o=>{if(!o||typeof o!="object")return null;const c=o,j=typeof c.toolName=="string"?c.toolName:"";if(!j)return null;const y=c.args;return{toolName:j,...y&&typeof y=="object"?{args:y}:{},isError:!!c.isError,result:c.result,status:"completed"}}).filter(o=>o!==null);return l.length>0?l:void 0}function ut(a){return{id:a.id,sessionId:a.sessionId,role:a.role,content:a.content,thinkingOutput:a.thinkingOutput,toolCalls:ps(a.metadata),attachments:a.attachments,createdAt:a.createdAt}}function xs(a){const[i,l]=s.useState([]),[o,c]=s.useState(null),[j,y]=s.useState(!0),[$,b]=s.useState([]),[P,W]=s.useState(!1),[g,D]=s.useState(!1),[A,C]=s.useState(""),[f,v]=s.useState(""),[M,S]=s.useState([]),[q,F]=s.useState(""),[se,K]=s.useState(""),[_,Y]=s.useState(!0),[m,T]=s.useState(new Map),w=s.useRef(null),L=s.useRef(!1),H=s.useRef(""),le=s.useRef(null),he=s.useRef(i),oe=s.useRef(o),ce=s.useRef(g);he.current=i,oe.current=o,ce.current=g,s.useEffect(()=>{H.current=q},[q]);const Ne=s.useRef(new Set),de=s.useRef(0),je=s.useRef(a);je.current!==a&&(je.current=a,de.current++),s.useEffect(()=>{const u=de.current;tt(void 0,a).then(p=>{if(de.current!==u)return;const h=new Map;for(const k of p)h.set(k.id,k);T(h)}).catch(()=>{})},[a]);const ge=s.useCallback(async()=>{y(!0);try{const p=[...(await Ht(a)).sessions].sort((h,k)=>new Date(k.updatedAt).getTime()-new Date(h.updatedAt).getTime());l(p)}catch{}finally{y(!1)}},[a]);s.useEffect(()=>{ge()},[ge]);const Ce=s.useRef(()=>{});s.useEffect(()=>{if(j)return;const u=Bt(et,a);u&&i.find(h=>h.id===u)&&Ce.current(u)},[j,i,a]);const J=s.useCallback(async(u,p)=>{W(!0);try{const h=await Gt(u,{limit:50,...p},a),k=h.messages.map(ut);p?.offset&&p.offset>0?b(Z=>[...k,...Z]):b(k),Y(h.messages.length>=50)}catch{}finally{W(!1)}},[a]),Q=s.useCallback(()=>{le.current?.(),le.current=null,H.current="",F(""),C(""),v(""),S([]),D(!1)},[]),me=s.useCallback((u,p)=>{w.current&&(w.current.close(),w.current=null);const h=p??i.find(k=>k.id===u);c(h||null),Q(),Y(!0),u?J(u):b([]),h?.isGenerating&&(D(!0),C("")),u?Vt(et,u,a):qt(et,a)},[i,J,a,Q]);Ce.current=me;const ve=s.useCallback(async u=>{const p=await Kt(u,a);w.current&&(w.current.close(),w.current=null);const h={id:p.session.id,title:p.session.title,agentId:p.session.agentId,status:p.session.status,modelProvider:p.session.modelProvider,modelId:p.session.modelId,createdAt:p.session.createdAt,updatedAt:p.session.updatedAt};return l(k=>k.some(Z=>Z.id===h.id)?k:[h,...k]),Q(),me(h.id,h),b([]),h},[a,Q,me]),we=s.useCallback(async u=>{await Xt(u,{status:"archived"},a),l(p=>p.filter(h=>h.id!==u)),o?.id===u&&(c(null),b([]))},[o,a]),pe=s.useCallback(async u=>{o?.id===u&&w.current&&(w.current.close(),w.current=null),await Yt(u,a),l(p=>p.filter(h=>h.id!==u)),o?.id===u&&(c(null),b([]))},[o,a]),be=s.useCallback(async()=>{!o||!_||await J(o.id,{offset:$.length})},[o,_,J,$.length]),fe=s.useCallback(()=>{o&&(L.current=!0,le.current?.(),le.current=null,w.current?.close(),w.current=null,Jt(o.id,a).catch(()=>{}),D(!1),C(""),v(""),S([]))},[o,a]),ne=s.useCallback(()=>{H.current="",F("")},[]),ae=s.useCallback((u,p)=>{if(!o)return;if(g){H.current=u,F(u);return}L.current=!1,w.current&&(w.current.close(),w.current=null);const h=`temp-${Date.now()}`,k={id:h,sessionId:o.id,role:"user",content:u,createdAt:new Date().toISOString()};b(x=>[...x,k]),C(""),v(""),S([]),D(!0);let Z="",X="",B=[],ie=null,ee=null;const z=()=>{ie=null,C(Z)},I=()=>{ee=null,v(X)},N=()=>{ie!==null&&(cancelAnimationFrame(ie),ie=null),ee!==null&&(cancelAnimationFrame(ee),ee=null)};le.current=N;const d={onThinking:x=>{X+=x,ee===null&&(ee=requestAnimationFrame(I))},onText:x=>{Z+=x,ie===null&&(ie=requestAnimationFrame(z))},onToolStart:x=>{B=[...B,{toolName:x.toolName,args:x.args,isError:!1,status:"running"}],S(B)},onToolEnd:x=>{const O=[...B];for(let E=O.length-1;E>=0;E--){const ue=O[E];if(ue?.toolName===x.toolName&&ue.status==="running"){O[E]={...ue,status:"completed",isError:x.isError,result:x.result},B=O,S(O);return}}B=[...O,{toolName:x.toolName,isError:x.isError,result:x.result,status:"completed"}],S(B)},onDone:x=>{N();const O={id:x.messageId||`msg-${Date.now()}`,sessionId:o.id,role:"assistant",content:Z,thinkingOutput:X,toolCalls:B.length>0?B:void 0,createdAt:new Date().toISOString()};Ne.current.add(O.id),b(ue=>[...ue,O]),C(""),v(""),S([]),D(!1),w.current=null,setTimeout(()=>{Ne.current.delete(O.id)},1e3),ge();const E=H.current.trim();E&&(H.current="",F(""),ae(E))},onError:x=>{if(N(),b(O=>O.filter(E=>E.id!==h)),C(""),v(""),S([]),D(!1),w.current=null,console.error("[useChat] Stream error:",x),!L.current){const O=H.current.trim();O&&(H.current="",F(""),ae(O))}}};w.current=Qt(o.id,u,d,p,a)},[o,g,a,ge]),Me=se?i.filter(u=>u.title?.toLowerCase().includes(se.toLowerCase())||u.agentId.toLowerCase().includes(se.toLowerCase())):i;return s.useEffect(()=>{const u=de.current,p=a?`?projectId=${encodeURIComponent(a)}`:"",h=()=>de.current!==u,k=z=>{if(h())return;const I=JSON.parse(z.data);l(N=>N.some(d=>d.id===I.id)?N:[I,...N])},Z=z=>{if(h())return;const I=JSON.parse(z.data);l(N=>[...N.map(x=>x.id===I.id?I:x)]),oe.current?.id===I.id&&c(I)},X=z=>{if(h())return;const{id:I}=JSON.parse(z.data);l(N=>N.filter(d=>d.id!==I)),oe.current?.id===I&&(c(null),b([]))},B=z=>{if(h())return;const I=JSON.parse(z.data),N=ut(I);if(!Ne.current.has(N.id)){if(oe.current?.id===N.sessionId&&ce.current&&!w.current&&N.role==="assistant"){b(d=>d.some(x=>x.id===N.id)?d:[...d,N]),C(""),v(""),S([]),D(!1);return}oe.current?.id===N.sessionId&&!ce.current&&b(d=>d.some(x=>x.id===N.id)?d:[...d,N])}},ie=z=>{if(h())return;const{id:I}=JSON.parse(z.data);b(N=>N.filter(d=>d.id!==I))};return Zt(`/api/events${p}`,{events:{"chat:session:created":k,"chat:session:updated":Z,"chat:session:deleted":X,"chat:message:added":B,"chat:message:deleted":ie}})},[a]),s.useEffect(()=>()=>{w.current&&(w.current.close(),w.current=null)},[]),{sessions:i,activeSession:o,sessionsLoading:j,messages:$,messagesLoading:P,isStreaming:g,streamingText:A,streamingThinking:f,streamingToolCalls:M,pendingMessage:q,selectSession:me,createSession:ve,archiveSession:we,deleteSession:pe,sendMessage:ae,stopStreaming:fe,clearPendingMessage:ne,loadMoreMessages:be,hasMoreMessages:_,searchQuery:se,setSearchQuery:K,filteredSessions:Me,refreshSessions:ge,agentsMap:m}}function bt(a){const i=new Date(a),o=new Date().getTime()-i.getTime(),c=Math.floor(o/1e3),j=Math.floor(c/60),y=Math.floor(j/60),$=Math.floor(y/24);return c<60?"just now":j<60?`${j}m ago`:y<24?`${y}h ago`:$<7?`${$}d ago`:i.toLocaleDateString()}function ht(a,i){if(!a||!i)return null;const l=i.toLowerCase();if(l.includes("claude")){let c=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 c=c.replace(/\s+/g," "),c.length>30?c.slice(0,30)+"…":c}if(l.includes("gpt")||l.includes("openai")){const c=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 c.length>30?c.slice(0,30)+"…":c}if(l.includes("gemini")){const c=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 c.length>30?c.slice(0,30)+"…":c}const o=i.replace(/-/g," ").replace(/^\w/,c=>c.toUpperCase()).replace(/\s+/g," ").trim();return o.length>30?o.slice(0,30)+"…":o}function Oe(a,i){return a.length<=i?a:`${a.slice(0,i)}…`}function vs(a){if(!a)return null;const i=Object.entries(a);return i.length===0?null:i.map(([l,o])=>{const c=typeof o=="string"?o:(()=>{try{return JSON.stringify(o)}catch{return String(o)}})();return`${l}=${Oe(c,50)}`}).join(", ")}function ws(a){if(a===void 0)return null;if(typeof a=="string")return Oe(a,200);try{return Oe(JSON.stringify(a),200)}catch{return Oe(String(a),200)}}function St(a){if(!a||a.length===0)return null;const i=(g,D)=>{const A=g.status==="running",C=g.status==="completed"&&g.isError,f=vs(g.args),v=ws(g.result),M=A?f:v?`result: ${v}`:f?`args: ${f}`:null,S=A?"running":C?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${A?" chat-tool-call--running":""}${C?" chat-tool-call--error":""}`,open:A,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),t.jsx("span",{className:"chat-tool-call-name",children:g.toolName}),M&&t.jsx("span",{className:"chat-tool-call-preview",title:M,children:M}),t.jsx("span",{className:"chat-tool-call-status-text",children:S})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[f&&t.jsxs("div",{className:"chat-tool-call-row",children:[t.jsx("span",{className:"chat-tool-call-label",children:"args"}),t.jsx("span",{className:"chat-tool-call-value",children:f})]}),v&&t.jsxs("div",{className:`chat-tool-call-row${C?" chat-tool-call-row--error":""}`,children:[t.jsx("span",{className:"chat-tool-call-label",children:"result"}),t.jsx("span",{className:"chat-tool-call-value",children:v})]})]})]},`${g.toolName}-${D}`)},l="chat-tool-calls";if(a.length===1)return t.jsxs("div",{className:l,"data-testid":"chat-tool-calls",children:[t.jsxs("div",{className:"chat-tool-calls-header",children:[t.jsx(ct,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),i(a[0],0)]});const o=a.filter(g=>g.status==="running").length,c=a.filter(g=>g.status==="completed"&&g.isError).length,j=o>0,y=Array.from(new Set(a.map(g=>g.toolName))),$=y.slice(0,5),b=Math.max(0,y.length-$.length),P=b>0?`${$.join(", ")}, +${b} more`:$.join(", "),W=j?`(${o} running)`:c>0?`(${c} ${c===1?"error":"errors"})`:null;return t.jsx("div",{className:l,"data-testid":"chat-tool-calls",children:t.jsxs("details",{className:"chat-tool-calls-group","data-testid":"chat-tool-calls-group",open:j,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(ct,{size:12,"aria-hidden":"true"}),t.jsxs("span",{children:[a.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:P,children:P}),W&&t.jsx("span",{className:"chat-tool-calls-group-status",children:W})]}),a.map((g,D)=>i(g,D))]})})}const yt={pre:({children:a,...i})=>t.jsx("pre",{...i,className:"chat-markdown-pre",children:a}),table:({children:a,...i})=>t.jsx("table",{...i,className:"chat-markdown-table",children:a})},Ue="__fn_agent__",bs=280,Le=180,ze=500,mt="fusion:chat-sidebar-width",Ss=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function ft(a){const i=/(^|[\s])\/([^\s]*)$/.exec(a);if(!i)return null;const l=i[1]??"",o=i[2]??"",c=i.index+l.length;return{filter:o,start:c,end:a.length}}function ys(a,i){const l=a.slice(0,i),o=/(^|[\s\n])@([\w-]*)$/.exec(l);if(!o)return null;const c=o[2]??"",j=l.length-c.length-1;return{filter:c,start:j,end:i}}function ks({projectId:a,onClose:i,onCreate:l}){const[o,c]=s.useState("agent"),[j,y]=s.useState([]),[$,b]=s.useState(!0),[P,W]=s.useState(""),[g,D]=s.useState([]),[A,C]=s.useState(!0),[f,v]=s.useState(""),[M,S]=s.useState([]),[q,F]=s.useState([]);s.useEffect(()=>{let m=!1;return b(!0),tt(void 0,a).then(T=>{m||y(T)}).catch(()=>{m||y([])}).finally(()=>{m||b(!1)}),()=>{m=!0}},[a]),s.useEffect(()=>{C(!0),fs().then(m=>{D(m.models),S(m.favoriteProviders),F(m.favoriteModels)}).catch(()=>{D([]),S([]),F([])}).finally(()=>{C(!1)})},[]);const se=s.useCallback(async m=>{const T=M,L=T.includes(m)?T.filter(H=>H!==m):[m,...T];S(L);try{await dt({favoriteProviders:L,favoriteModels:q})}catch{S(T)}},[M,q]),K=s.useCallback(async m=>{const T=q,L=T.includes(m)?T.filter(H=>H!==m):[m,...T];F(L);try{await dt({favoriteProviders:M,favoriteModels:L})}catch{F(T)}},[q,M]),_=m=>{if(m.preventDefault(),o==="agent"){if(!P)return;l({agentId:P});return}if(!f)return;const T=f.indexOf("/");if(T<=0)return;const w=f.slice(0,T),L=f.slice(T+1);l({agentId:Ue,modelProvider:w,modelId:L})},Y=o==="agent"?!P:!f;return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:m=>m.stopPropagation(),children:[t.jsx("h3",{children:"New Chat"}),t.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${o==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{c("agent"),v("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${o==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{c("model"),W("")},children:"Model"})]}),t.jsxs("form",{onSubmit:_,children:[o==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",$?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):j.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:j.map(m=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${P===m.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>W(m.id),"data-testid":`agent-option-${m.id}`,children:[t.jsx(We,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:m.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:m.role})]},m.id))})]}),o==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:A?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(gs,{models:g,value:f,onChange:v,label:"Model",placeholder:"Select a model",favoriteProviders:M,onToggleFavorite:se,favoriteModels:q,onToggleModelFavorite:K})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:Y,children:"Create"})]})]})]})})}const gt=s.memo(function({message:i,forcePlain:l,agentName:o,showAssistantModelTag:c,activeModelTag:j,activeSessionId:y,mentionAgentsByName:$,onToggleRender:b}){const P=i.role==="assistant",W=s.useMemo(()=>{if(P)return null;const A=i.content,C=/@([\w-]+)/g,f=[];let v=0,M=C.exec(A);for(;M;){const[S,q=""]=M,F=M.index;F>v&&f.push(A.slice(v,F));const se=q.replace(/_/g," ").toLowerCase(),K=$.get(se);K?f.push(t.jsxs("span",{className:"chat-mention-chip",children:["@",K.name.replace(/\s+/g,"_")]},`${K.id}-${F}`)):f.push(S),v=F+S.length,M=C.exec(A)}return v<A.length&&f.push(A.slice(v)),f.length===0?A:f},[P,i.content,$]),g=s.useMemo(()=>{const A=i.attachments;if(!A||A.length===0||!y)return null;const C=`/api/chat/sessions/${encodeURIComponent(y)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:A.map(f=>{const v=f.mimeType.startsWith("image/"),M=f.id||f.filename,S=`${C}${encodeURIComponent(f.filename)}`;return v?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:S,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:S,alt:f.originalName})},M):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:S,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(hs,{size:14}),t.jsx("span",{children:f.originalName})]},M)})})},[i.attachments,y]),D=s.useMemo(()=>P?l?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:i.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(pt,{remarkPlugins:[xt],components:yt,children:i.content})}):null,[P,l,i.content]);return t.jsxs("div",{className:`chat-message chat-message--${i.role}`,"data-testid":`chat-message-${i.id}`,children:[P&&t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(We,{size:14}),t.jsx("span",{children:o}),c&&j&&t.jsx("span",{className:"chat-model-tag",children:j}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${l?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":l?"Show rendered markdown":"Show plain text",onClick:()=>b(i.id),children:l?t.jsx(vt,{size:14}):t.jsx(wt,{size:14})})]}),P?D:t.jsx("div",{className:"chat-message-content",children:W}),St(i.toolCalls),i.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:i.thinkingOutput})]}),g,t.jsx("div",{className:"chat-message-time",children:bt(i.createdAt)})]})});function Ts({projectId:a,addToast:i}){const{activeSession:l,sessionsLoading:o,messages:c,messagesLoading:j,isStreaming:y,streamingText:$,streamingThinking:b,streamingToolCalls:P,selectSession:W,createSession:g,archiveSession:D,deleteSession:A,sendMessage:C,stopStreaming:f,pendingMessage:v,clearPendingMessage:M,searchQuery:S,setSearchQuery:q,filteredSessions:F}=xs(a),[se,K]=s.useState(!1),[_,Y]=s.useState(""),[m,T]=s.useState(null),[w,L]=s.useState(null),[H,le]=s.useState(!0),[he,oe]=s.useState(bs),[ce,Ne]=s.useState(new Map),[de,je]=s.useState([]),[ge,Ce]=s.useState(!0),[J,Q]=s.useState(!1),[me,ve]=s.useState(""),[we,pe]=s.useState(0),[be,fe]=s.useState(""),[ne,ae]=s.useState(!1),[Me,u]=s.useState(0),[p,h]=s.useState(-1),[k,Z]=s.useState(()=>new Set),[X,B]=s.useState([]),[ie,ee]=s.useState(!1),[,z]=s.useState(!1),[I,N]=s.useState({top:0,left:0}),d=es({projectId:a}),x=s.useCallback(e=>{if(!e||!d.mentionActive)return;const n=e.getBoundingClientRect();N({top:n.top-260,left:n.left+8})},[d.mentionActive]),O=s.useRef(null),E=s.useRef(null),ue=s.useRef(null),G=s.useRef(null),De=s.useRef(!1),Ee=s.useRef(!1),st=s.useRef(null),nt=s.useRef([]),Te=s.useRef(0),U=ts()==="mobile";s.useEffect(()=>{try{const e=localStorage.getItem(mt);if(!e)return;const n=Number.parseInt(e,10);if(Number.isNaN(n))return;const r=Math.max(Le,Math.min(ze,n));oe(r)}catch{}},[]);const{keyboardOverlap:He,viewportHeight:at,viewportOffsetTop:kt,keyboardOpen:Be}=ss({enabled:U&&!!l}),Nt=Be?{"--keyboard-overlap":`${He}px`,"--vv-offset-top":`${kt}px`,...at!==null?{"--vv-height":`${at}px`}:{}}:{},te=s.useMemo(()=>{const e=me.trim().toLowerCase();return(e?de.filter(r=>r.name.toLowerCase().includes(e)):de).slice(0,10)},[de,me]),Se=s.useMemo(()=>Array.from(ce.values()),[ce]),xe=s.useMemo(()=>{const e=be.trim().toLowerCase();return e?Se.filter(n=>n.name.toLowerCase().includes(e)):Se},[Se,be]),it=s.useMemo(()=>{const e=new Map;for(const n of Se)e.set(n.name.toLowerCase(),n);return e},[Se]);s.useEffect(()=>{pe(0)},[te]),s.useEffect(()=>{u(0)},[be,ne]),s.useEffect(()=>()=>{E.current!==null&&window.clearTimeout(E.current)},[]),s.useEffect(()=>{const e=ue.current;e&&(e.scrollTop=e.scrollHeight)},[c,$,b,y]),s.useEffect(()=>{if(He<=0)return;const e=ue.current;e&&(e.scrollTop=e.scrollHeight)},[He]),s.useEffect(()=>{if(!U||!Be)return;const e=document.documentElement,n=document.body,r={htmlOverflow:e.style.overflow,bodyOverflow:n.style.overflow};return e.style.overflow="hidden",n.style.overflow="hidden",()=>{e.style.overflow=r.htmlOverflow,n.style.overflow=r.bodyOverflow}},[U,Be]),s.useEffect(()=>{const e=()=>T(null);if(m)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[m]),s.useEffect(()=>{let e=!1;const n=a;return tt(void 0,a).then(r=>{if(e||n!==a)return;const R=new Map;for(const V of r)R.set(V.id,V);Ne(R)}).catch(()=>{}),()=>{e=!0}},[a]),s.useEffect(()=>{let e=!1;return Ce(!0),ns(a).then(n=>{e||je(n)}).catch(()=>{e||je([])}).finally(()=>{e||Ce(!1)}),()=>{e=!0}},[a]),s.useEffect(()=>{nt.current=X},[X]),s.useEffect(()=>()=>{for(const e of nt.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl)},[]);const Pe=s.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const r of Array.from(e)){if(!Ss.includes(r.type))continue;const R=r.type.startsWith("image/");n.push({file:r,previewUrl:R?URL.createObjectURL(r):""})}n.length>0&&B(r=>[...r,...n])},[]),jt=s.useCallback(e=>{B(n=>{const r=n[e];return r?.previewUrl&&URL.revokeObjectURL(r.previewUrl),n.filter((R,V)=>V!==e)})},[]),Ct=s.useCallback(e=>{const n=e.clipboardData?.files;if(!n||n.length===0)return;const r=Array.from(n).filter(R=>R.type.startsWith("image/"));r.length!==0&&Pe(r)},[Pe]),Mt=s.useCallback(async e=>{try{await g(e),K(!1),U&&le(!1)}catch{i("Failed to create chat session","error")}},[g,i,U]),Ge=s.useCallback(()=>{Y(""),Q(!1),ve(""),ae(!1),fe(""),h(-1),B(e=>{for(const n of e)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);return[]})},[]),Ae=s.useCallback(()=>{const e=_.trim(),n=X.map(r=>r.file);if(!(!e&&n.length===0||!l)){if(e==="/clear"){Ge(),f(),M(),g({agentId:l.agentId,modelProvider:l.modelProvider??void 0,modelId:l.modelId??void 0}).catch(()=>{i("Failed to clear conversation","error")});return}Ge(),C(e,n)}},[_,X,l,Ge,f,M,g,i,C]),Fe=s.useCallback(()=>{if(typeof window>"u"||window.innerWidth>768)return;const e=G.current;if(!e||e.disabled)return;const n=window.scrollX,r=window.scrollY;e.focus({preventScroll:!0}),window.requestAnimationFrame(()=>{(window.scrollX!==n||window.scrollY!==r)&&window.scrollTo(n,r)})},[]),rt=s.useCallback(()=>{typeof window>"u"||window.innerWidth>768||(De.current=!0)},[]),Ve=s.useCallback(e=>{Y(n=>{const r=ft(n);if(!r)return n;const R=`/skill:${e.name} `,V=n.slice(0,r.start)+R+n.slice(r.end);return window.requestAnimationFrame(()=>{G.current&&(G.current.style.height="auto",G.current.style.height=`${Math.min(G.current.scrollHeight,120)}px`,G.current.focus())}),V}),Q(!1),ve(""),pe(0)},[]),qe=s.useCallback(e=>{const n=G.current;if(!n||p<0)return;const r=n.selectionStart??Te.current,R=n.selectionEnd??r,V=Math.max(r,R),$e=Math.min(p,V),ye=`${`@${e.name.replace(/\s+/g,"_")}`} `,Qe=_.slice(0,$e)+ye+_.slice(V),ke=$e+ye.length;Y(Qe),ae(!1),fe(""),u(0),h(-1),window.requestAnimationFrame(()=>{G.current&&(G.current.style.height="auto",G.current.style.height=`${Math.min(G.current.scrollHeight,120)}px`,G.current.focus(),G.current.setSelectionRange(ke,ke))})},[p,_]),Tt=s.useCallback(e=>{if(Te.current=e.currentTarget.selectionStart??Te.current,d.mentionActive&&d.files.length>0){if(d.handleKeyDown(e,_),e.key==="Enter"||e.key==="Tab"){const n=d.files[d.selectedIndex];if(n){const r=d.selectFile(n,_);Y(r),d.dismissMention(),z(!1)}}return}if(ne&&e.key==="ArrowDown"){e.preventDefault(),xe.length>0&&u(n=>(n+1)%xe.length);return}if(ne&&e.key==="ArrowUp"){e.preventDefault(),xe.length>0&&u(n=>n===0?xe.length-1:n-1);return}if(ne&&e.key==="Enter"){e.preventDefault();const n=xe[Me]??xe[0];n&&qe(n);return}if(ne&&e.key==="Escape"){e.preventDefault(),ae(!1),fe(""),h(-1);return}if(J&&e.key==="ArrowDown"){e.preventDefault(),te.length>0&&pe(n=>(n+1)%te.length);return}if(J&&e.key==="ArrowUp"){e.preventDefault(),te.length>0&&pe(n=>n===0?te.length-1:n-1);return}if(J&&(e.key==="Enter"||e.key==="Tab")&&te.length>0){e.preventDefault();const n=te[we]??te[0];n&&Ve(n);return}if(J&&e.key==="Escape"){e.preventDefault(),Q(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ae())},[ne,xe,Me,qe,J,te,we,Ve,Ae,d,_]),Ie=s.useCallback((e,n)=>{const r=ys(e,n);if(r){ae(!0),fe(r.filter),h(r.start);return}ae(!1),fe(""),h(-1)},[]),At=s.useCallback(e=>{const n=e.target,r=n.value,R=n.selectionStart??r.length;Te.current=R,Y(r);const V=ft(r);V?(Q(!0),ve(V.filter)):(Q(!1),ve("")),Ie(r,R),d.detectMention(r,R),z(d.mentionActive),d.mentionActive&&x(n),n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight,120)}px`},[Ie]),Ke=s.useCallback(e=>{const n=e.currentTarget,r=n.selectionStart??n.value.length;Te.current=r,Ie(n.value,r),d.detectMention(n.value,r),z(d.mentionActive),d.mentionActive&&x(n)},[Ie,d,x]),Rt=s.useCallback(e=>{e.key!=="Escape"&&Ke(e)},[Ke]),$t=s.useCallback(()=>{if(De.current){window.requestAnimationFrame(()=>{Fe()});return}E.current!==null&&window.clearTimeout(E.current),E.current=window.setTimeout(()=>{Q(!1),ae(!1),fe(""),h(-1),z(!1),d.dismissMention(),E.current=null},120)},[d,Fe]),Dt=s.useCallback(()=>{E.current!==null&&(window.clearTimeout(E.current),E.current=null)},[]),Et=s.useCallback(async e=>{T(null);try{await D(e),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[D,i]),Pt=s.useCallback(async e=>{L(null),T(null);try{await A(e),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[A,i]),Re=s.useCallback(e=>{try{localStorage.setItem(mt,String(e))}catch{}},[]),Ft=s.useCallback(e=>{if(U)return;e.preventDefault(),e.stopPropagation();const n=e.currentTarget;typeof n.setPointerCapture=="function"&&n.setPointerCapture(e.pointerId);const r=e.clientX,R=he;let V=R;document.body.style.userSelect="none";const $e=ye=>{const Qe=ye.clientX-r,ke=Math.max(Le,Math.min(ze,R+Qe));V=ke,oe(ke),Re(ke)},Je=ye=>{typeof n.releasePointerCapture=="function"&&n.releasePointerCapture(ye.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",$e),document.removeEventListener("pointerup",Je),Re(V)};document.addEventListener("pointermove",$e),document.addEventListener("pointerup",Je)},[U,Re,he]),It=s.useCallback(e=>{if(U||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const n=e.shiftKey?50:10,r=e.key==="ArrowLeft"?-n:n,R=Math.max(Le,Math.min(ze,he+r));oe(R),Re(R)},[U,Re,he]),_t=s.useCallback(e=>{W(e),U&&le(!1)},[W,U]),Lt=s.useCallback(()=>{W(""),le(!0)},[W]),zt=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(ms,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>K(!0),children:[t.jsx(Ze,{size:16}),"New Chat"]})]}),re=ht(l?.modelProvider,l?.modelId),lt=l?.agentId===Ue?re??"Fusion":l?.title||ce.get(l?.agentId??"")?.name||l?.agentId||"Chat",Ot=!!(re&&re!==lt),_e=ce.get(l?.agentId??"")?.name||(l?.agentId===Ue?re??"Fusion":l?.agentId?.slice(0,30)??"Fusion"),Xe=!!(re&&re!==_e),Ut=v.length>50?`${v.slice(0,50)}…`:v,Ye=s.useCallback(e=>{Z(n=>{const r=new Set(n);return r.has(e)?r.delete(e):r.add(e),r})},[]),Wt=s.useCallback((e,n=!1)=>n?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:e}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(pt,{remarkPlugins:[xt],components:yt,children:e})}),[]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${H?"":" chat-sidebar--hidden"}`,style:U?void 0:{width:`${he}px`},children:[t.jsx("div",{className:"chat-sidebar-search",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(as,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:S,onChange:e=>q(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:o?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):F.length===0?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):F.map(e=>t.jsxs("div",{className:`chat-session-item${l?.id===e.id?" chat-session-item--active":""}`,onClick:()=>_t(e.id),onContextMenu:n=>{n.preventDefault(),T({sessionId:e.id,x:n.clientX,y:n.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:n=>{n.stopPropagation(),L(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(ot,{size:14})}),t.jsx("div",{className:"chat-session-title",children:e.title||"Untitled"}),t.jsx("div",{className:"chat-session-preview",children:e.lastMessagePreview||"No messages"}),t.jsxs("div",{className:"chat-session-meta",children:[t.jsx("span",{children:ce.get(e.agentId)?.name||(e.agentId===Ue?ht(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))}),t.jsx("span",{children:e.updatedAt?bt(e.updatedAt):""})]})]},e.id))}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>K(!0),"data-testid":"chat-new-btn",children:[t.jsx(Ze,{size:14}),"New Chat"]})})]}),!U&&H&&t.jsx("div",{className:"chat-sidebar-resize-handle",role:"separator","aria-orientation":"vertical","aria-valuemin":Le,"aria-valuemax":ze,"aria-valuenow":he,"aria-label":"Resize chat sidebar",tabIndex:0,onPointerDown:Ft,onKeyDown:It}),m&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:m.y,left:m.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Et(m.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(is,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{T(null),L(m.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(ot,{size:14}),"Delete"]})]}),w&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>L(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>L(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Pt(w),children:"Delete"})]})]})}),t.jsxs("div",{className:"chat-thread",style:Nt,children:[(l||!U)&&t.jsxs("div",{className:"chat-thread-header",children:[U&&l&&t.jsx("button",{className:"btn-icon",onClick:Lt,"data-testid":"chat-back-btn",children:t.jsx(rs,{size:16})}),t.jsx(We,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:lt}),Ot&&t.jsx("span",{className:"chat-model-tag",children:re}),!U&&t.jsxs("button",{className:"btn btn-sm btn-primary chat-thread-header-new-chat",onClick:()=>K(!0),"data-testid":"chat-thread-new-chat-btn",children:[t.jsx(Ze,{size:14}),"New Chat"]})]}),t.jsxs("div",{className:"chat-messages",ref:ue,children:[y?t.jsxs(t.Fragment,{children:[c.map(e=>t.jsx(gt,{message:e,forcePlain:k.has(e.id),agentName:_e,showAssistantModelTag:Xe,activeModelTag:re,activeSessionId:l?.id??null,mentionAgentsByName:it,onToggleRender:Ye},e.id)),t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(We,{size:14}),t.jsx("span",{children:_e}),Xe&&t.jsx("span",{className:"chat-model-tag",children:re}),t.jsx("button",{type:"button",className:`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:()=>Ye("__streaming__"),children:k.has("__streaming__")?t.jsx(vt,{size:14}):t.jsx(wt,{size:14})})]}),$?Wt($,k.has("__streaming__")):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:b?"Thinking…":"Connecting…"}),St(P),b&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:b})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}):j?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):c.length===0&&!l?zt():c.length===0&&l?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):t.jsx(t.Fragment,{children:c.map(e=>t.jsx(gt,{message:e,forcePlain:k.has(e.id),agentName:_e,showAssistantModelTag:Xe,activeModelTag:re,activeSessionId:l?.id??null,mentionAgentsByName:it,onToggleRender:Ye},e.id))}),t.jsx("div",{ref:O})]}),l&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:st,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{Pe(e.target.files),e.target.value=""}}),J&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:ge?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):te.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:me?"No skills found":"No skills available"}):te.map((e,n)=>t.jsxs("button",{type:"button",role:"option","aria-selected":n===we,className:`chat-skill-menu-item${n===we?" chat-skill-menu-item--highlighted":""}`,onMouseDown:r=>r.preventDefault(),onMouseEnter:()=>pe(n),onClick:()=>Ve(e),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.name}),t.jsx("span",{className:"chat-skill-menu-item-description",title:e.relativePath,children:e.relativePath})]},e.id))}),X.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:X.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>jt(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":"Attach files",onClick:()=>st.current?.click(),children:t.jsx(ls,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${ie?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),ee(!0)},onDragLeave:()=>ee(!1),onDrop:e=>{e.preventDefault(),ee(!1),Pe(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:G,className:"chat-input-textarea",placeholder:"Type a message...",value:_,onChange:At,onKeyDown:Tt,onKeyUp:Rt,onClick:Ke,onBlur:$t,onFocus:Dt,onPaste:Ct,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(os,{agents:Se,filter:be,highlightedIndex:Me,visible:ne,onSelect:qe,position:"below"}),t.jsx(cs,{visible:d.mentionActive&&!ne,position:I,files:d.files,selectedIndex:d.selectedIndex,onSelect:e=>{const n=d.selectFile(e,_);Y(n),d.dismissMention(),z(!1),G.current?.focus()},loading:d.loading}),v&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${Ut}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:M,children:"×"})]})]}),y?t.jsx("button",{className:"chat-input-stop",onClick:f,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(ds,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),e.pointerType&&e.pointerType!=="mouse"&&(Ee.current=!0,rt(),Fe(),Ae(),window.setTimeout(()=>{De.current=!1},1500)))},onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),Ee.current=!0,rt(),Fe(),Ae(),window.setTimeout(()=>{De.current=!1},1500))},onMouseDown:e=>{typeof window>"u"||window.innerWidth>768||e.preventDefault()},onClick:()=>{if(Ee.current){Ee.current=!1;return}Ae()},disabled:!_.trim()&&X.length===0,"data-testid":"chat-send-btn",children:t.jsx(us,{size:16})})]})]})]}),se&&t.jsx(ks,{projectId:a,onClose:()=>K(!1),onCreate:Mt})]})}export{Ts as ChatView};
@@ -1 +0,0 @@
1
- import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{as as ie,at as ce,s as le,au as oe,av as de,aw as ue,ax as he,ay as me,az as ve,aA as be,D as xe,aB as fe,L as pe,S as je}from"./index-Bv0TGzDH.js";import"./vendor-xterm-DzcZoU0P.js";const F={webSearch:!0,pageFetch:!0,github:!1,localDocs:!0,llmSynthesis:!0};function W(d){const t=d?.researchGlobalDefaults,u=d?.researchSettings;return{enabled:u?.enabled??d?.researchEnabled??d?.researchGlobalEnabled??!0,searchProvider:u?.searchProvider??t?.searchProvider,synthesisProvider:u?.synthesisProvider??t?.synthesisProvider,synthesisModelId:u?.synthesisModelId??t?.synthesisModelId,enabledSources:{webSearch:u?.enabledSources?.webSearch??t?.enabledSources?.webSearch??F.webSearch,pageFetch:u?.enabledSources?.pageFetch??t?.enabledSources?.pageFetch??F.pageFetch,github:u?.enabledSources?.github??t?.enabledSources?.github??F.github,localDocs:u?.enabledSources?.localDocs??t?.enabledSources?.localDocs??F.localDocs,llmSynthesis:u?.enabledSources?.llmSynthesis??t?.enabledSources?.llmSynthesis??F.llmSynthesis},limits:{maxConcurrentRuns:u?.limits?.maxConcurrentRuns??d?.researchMaxConcurrentRuns??d?.researchGlobalMaxConcurrentRuns??3,maxSourcesPerRun:u?.limits?.maxSourcesPerRun??t?.maxSourcesPerRun??d?.researchMaxSourcesPerRun??d?.researchGlobalMaxSourcesPerRun??20,maxDurationMs:u?.limits?.maxDurationMs??d?.researchDefaultTimeout??d?.researchGlobalDefaultTimeout??3e5,requestTimeoutMs:u?.limits?.requestTimeoutMs??d?.researchFetchTimeoutMs??3e4},defaultExportFormat:t?.defaultExportFormat??"markdown"}}const ge=300,ye=4e3;function Se(d){const t=d?.projectId,[u,x]=a.useState([]),[m,r]=a.useState(null),[I,g]=a.useState(null),[f,S]=a.useState({available:!0}),[R,N]=a.useState(!0),[T,k]=a.useState(null),[y,C]=a.useState(""),_=a.useRef(0),E=a.useRef(0),M=a.useRef(t);a.useEffect(()=>{M.current!==t&&(M.current=t,E.current++)},[t]);const p=a.useCallback(async(c=y)=>{const l=++_.current,i=t;k(null);try{const n=await ie({q:c||void 0,limit:100},i);if(l!==_.current||i!==t)return;x(n.runs),S(n.availability),m&&!n.runs.some(b=>b.id===m)&&(r(null),g(null))}catch(n){if(l!==_.current||i!==t)return;k(n instanceof Error?n.message:"Failed to load research runs")}finally{l===_.current&&N(!1)}},[t,y,m]),j=a.useCallback(async c=>{const l=await ce(c,t);return g(l.run),S(l.availability),l.run},[t]);return a.useEffect(()=>{N(!0);const c=window.setTimeout(()=>{p(y)},ge);return()=>window.clearTimeout(c)},[p,y]),a.useEffect(()=>{if(!m){g(null);return}j(m)},[j,m]),a.useEffect(()=>{const c=E.current,l=()=>E.current!==c,i=t?`?projectId=${encodeURIComponent(t)}`:"";let n=!0;const b=()=>{!n||l()||(p(),m&&j(m))},A=le(`/api/events${i}`,{events:{"research:run:created":b,"research:run:updated":b,"research:run:completed":b,"research:run:failed":b,"research:run:cancelled":b},onReconnect:b}),q=window.setInterval(b,ye);return()=>{n=!1,A(),window.clearInterval(q)}},[t,p,m,j]),{runs:u,selectedRun:I,selectedRunId:m,setSelectedRunId:r,availability:f,loading:R,error:T,searchQuery:y,setSearchQuery:C,refresh:p,createRun:c=>ve(c,t),cancelRun:async c=>{const l=await me(c,t);return m===c&&g(l.run),await p(),l},retryRun:async c=>{const l=await he(c,t);return m===c&&g(l.run),await p(),l},exportRun:(c,l)=>ue(c,l,t),createTaskFromRun:(c,l,i,n,b,A)=>de(c,{title:l,findingId:i,description:n,priority:b,attachExport:A},t),attachRunToTask:(c,l,i,n)=>oe(c,{taskId:l,findingId:i,attachExport:n},t),statusCounts:u.reduce((c,l)=>(c[l.status]+=1,c),{queued:0,running:0,cancelling:0,retry_waiting:0,completed:0,failed:0,cancelled:0,timed_out:0,retry_exhausted:0})}}function _e({open:d,mode:t,run:u,finding:x,projectId:m,onClose:r,onConfirm:I}){const[g,f]=a.useState(!1),[S,R]=a.useState(""),[N,T]=a.useState(""),[k,y]=a.useState("normal"),[C,_]=a.useState(""),[E,M]=a.useState([]),[p,j]=a.useState(!1),[c,l]=a.useState(!1),i=a.useMemo(()=>{const n=(x.content??"").split(/(?<=[.!?])\s+/)[0]??"";return`${x.heading||"Research finding"} — ${n}`.trim()},[x.content,x.heading]);return a.useEffect(()=>{d&&(f(!1),R(`Research: ${x.heading||u.title}`),T(i),y("normal"),_(""),t==="enrich"&&(j(!0),be(50,0,m).then(n=>M(n.filter(b=>b.column!=="archived"))).finally(()=>j(!1))))},[d,t,m,x.heading,i,u.title]),d?e.jsx("div",{className:"modal-overlay open",role:"presentation",onClick:r,children:e.jsxs("div",{className:"modal modal-lg research-task-action-modal",role:"dialog","aria-modal":"true",onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:t==="create"?"Create task from finding":"Enrich existing task"}),e.jsx("button",{className:"modal-close",type:"button","aria-label":"Close",onClick:r,children:"×"})]}),e.jsxs("div",{className:"research-task-action-modal__body",children:[e.jsxs("div",{className:"card research-task-action-modal__preview",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Run:"})," ",u.id]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Finding:"})," ",x.id,x.heading?` — ${x.heading}`:""]}),e.jsx("p",{children:i||"No preview available."})]}),t==="create"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"research-task-action-modal__field",children:["Title",e.jsx("input",{className:"input",value:S,onChange:n=>R(n.target.value)})]}),e.jsxs("label",{className:"research-task-action-modal__field",children:["Description",e.jsx("textarea",{className:"input research-task-action-modal__textarea",value:N,onChange:n=>T(n.target.value)})]}),e.jsxs("label",{className:"research-task-action-modal__field",children:["Priority",e.jsxs("select",{className:"select",value:k,onChange:n=>y(n.target.value),children:[e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"normal",children:"Normal"}),e.jsx("option",{value:"high",children:"High"}),e.jsx("option",{value:"urgent",children:"Urgent"})]})]})]}):e.jsxs("label",{className:"research-task-action-modal__field",children:["Target task",e.jsx("input",{className:"input",list:"research-task-action-task-list",value:C,placeholder:p?"Loading tasks…":"Enter task ID",onChange:n=>_(n.target.value)}),e.jsx("datalist",{id:"research-task-action-task-list",children:E.map(n=>e.jsx("option",{value:n.id,children:n.title},n.id))})]}),e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:g,onChange:n=>f(n.target.checked)}),e.jsx("span",{children:"Attach markdown export artifact"})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:r,children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",type:"button",disabled:c||t==="enrich"&&!C,onClick:()=>{l(!0),I({taskId:t==="enrich"?C:void 0,title:t==="create"?S.trim():void 0,description:t==="create"?N.trim():void 0,priority:t==="create"?k:void 0,attachExport:g}).finally(()=>l(!1))},children:t==="create"?"Create Task":"Enrich Task"})]})]})}):null}const Re=["web-search","page-fetch","github","local-docs","llm-synthesis"],we={"web-search":"webSearch","page-fetch":"pageFetch",github:"github","local-docs":"localDocs","llm-synthesis":"llmSynthesis"},Ne={"web-search":"Web Search","page-fetch":"Page Fetch",github:"GitHub","local-docs":"Local Docs","llm-synthesis":"LLM Synthesis"};function Te({projectId:d,addToast:t,onOpenSettings:u,readinessVersion:x=0}){const{runs:m,selectedRun:r,selectedRunId:I,setSelectedRunId:g,availability:f,loading:S,error:R,searchQuery:N,setSearchQuery:T,createRun:k,cancelRun:y,retryRun:C,exportRun:_,createTaskFromRun:E,attachRunToTask:M,statusCounts:p,refresh:j}=Se({projectId:d}),[c,l]=a.useState(""),[i,n]=a.useState(()=>W(void 0)),[b,A]=a.useState([]),[q,Q]=a.useState(!1),[Y,X]=a.useState([]),[L,O]=a.useState(null),[P,$]=a.useState(null),B=f.supportedProviders??Re,U=s=>i.enabledSources[we[s]];a.useEffect(()=>{const s=B.filter(o=>U(o));X(o=>{const v=o.filter(h=>s.includes(h));return v.length>0?v:s})},[i.enabledSources,B]),a.useEffect(()=>{let s=!1;return Promise.all([xe(d),fe().catch(()=>({providers:[]}))]).then(([o,v])=>{s||(n(W(o)),A(v.providers.filter(h=>h.type==="api_key").map(h=>({id:h.id,authenticated:h.authenticated}))))}).catch(()=>{s||n(W(void 0))}),()=>{s=!0}},[d,x]);const re=a.useMemo(()=>r?r.status:"No run selected",[r]),ae=a.useMemo(()=>r?r.status==="queued"||r.status==="retry_waiting"?"status-dot status-dot--pending":r.status==="running"?"status-dot status-dot--connecting":r.status==="completed"?"status-dot status-dot--online":r.status==="failed"||r.status==="cancelled"?"status-dot status-dot--error":"status-dot":"status-dot",[r]),H=f.supportedExportFormats??["markdown","json","html"],V=i.searchProvider,Z=i.enabledSources.webSearch&&!V,ee=i.enabledSources.llmSynthesis&&(!i.synthesisProvider||!i.synthesisModelId),z=a.useMemo(()=>new Map(b.map(s=>[s.id,s.authenticated])),[b]),K=a.useMemo(()=>{const s=new Set;return i.enabledSources.webSearch&&V&&s.add(V),i.enabledSources.llmSynthesis&&i.synthesisProvider&&s.add(i.synthesisProvider),[...s].filter(o=>z.has(o))},[i.enabledSources.llmSynthesis,i.enabledSources.webSearch,i.synthesisProvider,V,z]).find(s=>z.get(s)!==!0),D=a.useMemo(()=>f.available?i.enabled?Z||ee?{reason:"Research defaults are incomplete.",details:"Select the required provider/model defaults in Research settings.",settingsSection:"research-global"}:K?{reason:`Missing API key for ${K}.`,details:"Add provider credentials in Authentication settings.",settingsSection:"authentication"}:null:{reason:"Research is disabled for this project.",details:"Enable project research settings to create runs.",settingsSection:"research-project"}:{reason:f.reason??"Research is unavailable for this project.",details:f.setupInstructions,settingsSection:"research-project"},[f.available,f.reason,f.setupInstructions,i.enabled,K,Z,ee]),G=async(s,o,v)=>{O(s);try{await o(),t?.(v,"success"),await j()}catch(h){t?.(h instanceof Error?h.message:"Action failed","error")}finally{O(null)}},J=async s=>{if(r){O(`export-${s}`);try{const o=await _(r.id,s),v=new Blob([o.content],{type:"text/plain;charset=utf-8"}),h=URL.createObjectURL(v),w=document.createElement("a");w.href=h,w.download=o.filename,document.body.appendChild(w),w.click(),w.remove(),URL.revokeObjectURL(h),t?.(`Exported ${o.filename}`,"success")}catch(o){t?.(o instanceof Error?o.message:"Export failed","error")}finally{O(null)}}},ne=async()=>{if(c.trim()){Q(!0);try{const s=Y.filter(v=>U(v));if(s.length===0){Q(!1),t?.("No enabled research sources are available for this project.","error");return}const o=await k({query:c.trim(),providers:s});g(o.run.id),l(""),t?.("Research run created","success"),await j()}catch(s){t?.(s instanceof Error?s.message:"Failed to create run","error")}finally{Q(!1)}}};return e.jsxs("section",{className:"research-view","aria-label":"Research view",children:[e.jsxs("header",{className:"research-view__header",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"research-view__title",children:"Research"}),e.jsx("p",{className:"research-view__subtitle",children:"Create and track research runs with cited findings."})]}),e.jsx("button",{className:"btn",type:"button",onClick:()=>void j(),children:"Refresh"})]}),D?e.jsxs("div",{className:"research-view__state research-view__state--error card","data-testid":"research-state-unavailable",children:[e.jsx("p",{children:D.reason}),D.details&&e.jsx("p",{children:D.details}),e.jsxs("p",{children:["Current defaults: provider ",i.searchProvider??"(not set)",", max sources ",i.limits.maxSourcesPerRun]}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:()=>void j(),children:"Refresh"}),e.jsx("button",{className:"btn btn-primary",type:"button",onClick:()=>u?.(D.settingsSection),children:"Open Settings"})]})]}):e.jsxs("div",{className:"research-view__layout",children:[e.jsxs("aside",{className:"research-view__sidebar card",children:[e.jsxs("div",{className:"research-view__form",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-query",children:"Query"}),e.jsx("textarea",{id:"research-query",className:"input research-view__textarea",value:c,onChange:s=>l(s.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:"Providers"}),e.jsx("div",{className:"research-view__providers",children:B.map(s=>e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:Y.includes(s),disabled:!U(s),onChange:()=>{U(s)&&X(o=>o.includes(s)?o.filter(v=>v!==s):[...o,s])}}),e.jsx("span",{children:Ne[s]??s})]},s))})]}),e.jsxs("button",{className:"btn btn-primary",type:"button",disabled:!c.trim()||q,onClick:()=>void ne(),children:[q?e.jsx(pe,{className:"animate-spin",size:14}):null,"Create Run"]})]}),e.jsxs("div",{className:"research-view__history-header form-group",children:[e.jsx("label",{htmlFor:"research-run-search",children:"Search"}),e.jsxs("div",{className:"research-view__history-search-row",children:[e.jsx(je,{size:14}),e.jsx("input",{id:"research-run-search",className:"input",placeholder:"Search runs",value:N,onChange:s=>T(s.target.value)})]})]}),e.jsx("div",{className:"research-view__history","data-testid":"research-state-running",children:m.map(s=>e.jsxs("button",{type:"button",className:`research-view__history-item card${I===s.id?" research-view__history-item--active":""}`,onClick:()=>g(s.id),children:[e.jsx("span",{className:"card-id",children:s.id}),e.jsx("span",{children:s.title})]},s.id))})]}),e.jsxs("div",{className:"research-view__reader card",children:[S&&e.jsx("p",{"data-testid":"research-state-loading",children:"Loading research runs…"}),!S&&R&&e.jsx("p",{"data-testid":"research-state-error",children:R}),!S&&!R&&m.length===0&&e.jsx("p",{"data-testid":"research-state-empty",children:"No research runs yet"}),r&&e.jsxs("div",{children:[e.jsxs("div",{className:"research-view__status-row",children:[e.jsx("span",{className:ae}),e.jsx("strong",{children:re})]}),e.jsx("h3",{className:"research-view__run-title",children:r.title}),e.jsx("p",{className:"research-view__run-query",children:r.query}),e.jsx("p",{className:"research-view__run-summary","data-testid":"research-state-results",children:r.results?.summary??"No summary yet."}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",disabled:L==="cancel",onClick:()=>void G("cancel",()=>y(r.id),"Run cancelled"),children:"Cancel"}),e.jsx("button",{className:"btn",type:"button",disabled:L==="retry",onClick:()=>void G("retry",()=>C(r.id),"Run retried"),children:"Retry"}),H.includes("markdown")&&e.jsx("button",{className:"btn",type:"button",disabled:L==="export-markdown",onClick:()=>void J("markdown"),children:"Export MD"}),H.includes("json")&&e.jsx("button",{className:"btn",type:"button",disabled:L==="export-json",onClick:()=>void J("json"),children:"Export JSON"}),H.includes("html")&&e.jsx("button",{className:"btn",type:"button",disabled:L==="export-html",onClick:()=>void J("html"),children:"Export HTML"})]}),r.error&&e.jsx("p",{className:"research-view__error",children:r.error}),Array.isArray(r.results?.findings)&&r.results.findings.length>0&&e.jsx("div",{className:"research-view__findings",children:r.results.findings.map((s,o)=>{const h=s.id?.trim()||`finding-${o+1}`;return e.jsxs("article",{className:"research-view__finding card",children:[e.jsx("h4",{children:s.heading}),e.jsx("p",{children:s.content}),e.jsxs("div",{className:"research-view__actions research-view__finding-actions",children:[e.jsx("button",{className:"btn btn-primary btn-sm",type:"button",onClick:()=>$({mode:"create",findingId:h}),children:"Create Task"}),e.jsx("button",{className:"btn btn-sm",type:"button",onClick:()=>$({mode:"enrich",findingId:h}),children:"Enrich Task"})]})]},h)})}),Array.isArray(r.results?.citations)&&r.results.citations.length>0&&e.jsx("ul",{className:"research-view__citations",children:r.results.citations.map(s=>e.jsx("li",{children:e.jsx("a",{href:s,target:"_blank",rel:"noreferrer",children:s})},s))}),r.events.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:"Run history"}),e.jsx("ul",{className:"research-view__events",children:r.events.map(s=>e.jsx("li",{children:s.message},s.id))})]})]}),!r&&m.length>0&&e.jsx("p",{children:"Select a run to view details."}),e.jsxs("div",{className:"research-view__stats",children:[e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Running"}),e.jsx("div",{className:"research-view__stat-value",children:p.running})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Completed"}),e.jsx("div",{className:"research-view__stat-value",children:p.completed})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Failed"}),e.jsx("div",{className:"research-view__stat-value",children:p.failed})]})]})]})]}),r&&P&&(()=>{const s=r.results?.findings?.findIndex((v,h)=>(v.id?.trim()||`finding-${h+1}`)===P.findingId)??-1,o=s>=0?r.results.findings[s]:null;return o?e.jsx(_e,{open:!0,mode:P.mode,run:r,finding:{id:P.findingId,heading:o.heading,content:o.content},projectId:d,onClose:()=>$(null),onConfirm:async({taskId:v,title:h,description:w,priority:se,attachExport:te})=>{P.mode==="create"?await G("create-task",()=>E(r.id,h,P.findingId,w,se,te),"Task created from research"):v&&await G("attach-task",()=>M(r.id,v,P.findingId,te),"Task enriched from research"),$(null)}}):null})()]})}export{Te as ResearchView};