@runfusion/fusion 0.27.0 → 0.28.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.
- package/dist/bin.js +5059 -1216
- package/dist/client/assets/AgentDetailView-DSpIqBOs.css +1 -0
- package/dist/client/assets/{AgentDetailView-DwLmRXTY.js → AgentDetailView-V32TpEe1.js} +3 -3
- package/dist/client/assets/{AgentsView-CV3vm7Qk.css → AgentsView-B3ADnF0D.css} +1 -1
- package/dist/client/assets/{AgentsView-D-N6aA0P.js → AgentsView-CxITZE-U.js} +8 -8
- package/dist/client/assets/ChatView-7WPHyB_7.js +1 -0
- package/dist/client/assets/DevServerView-Diw4hjw0.js +1 -0
- package/dist/client/assets/{DirectoryPicker-DvBviDG6.js → DirectoryPicker-CWSApoLU.js} +1 -1
- package/dist/client/assets/{DocumentsView-BWXOxpuq.js → DocumentsView-1kr0dhsV.js} +1 -1
- package/dist/client/assets/{EvalsView-CJFbtL7i.js → EvalsView-cDfXYiK6.js} +1 -1
- package/dist/client/assets/{ExperimentalAgentOnboardingModal-DuGIPd0B.js → ExperimentalAgentOnboardingModal-lNSf6UtY.js} +1 -1
- package/dist/client/assets/{InsightsView-BBpRiolN.js → InsightsView-D2AjxOnu.js} +1 -1
- package/dist/client/assets/{MemoryView-48LuNkKk.js → MemoryView-Dq4yjIPI.js} +1 -1
- package/dist/client/assets/{NodesView-CGQWSNZM.js → NodesView-Cpmkze7n.js} +4 -4
- package/dist/client/assets/{PiExtensionsManager-i-7UL2oh.js → PiExtensionsManager-oi9FHT0y.js} +2 -2
- package/dist/client/assets/PluginManager-C4UoLv4U.css +1 -0
- package/dist/client/assets/PluginManager-o12KG4e8.js +1 -0
- package/dist/client/assets/ResearchView-C7uXon3o.css +1 -0
- package/dist/client/assets/ResearchView-C9bjVB7-.js +1 -0
- package/dist/client/assets/{SettingsModal-CmeF8CN4.js → SettingsModal-CT01a5Rh.js} +1 -1
- package/dist/client/assets/SettingsModal-Cu93Jjho.js +31 -0
- package/dist/client/assets/{SetupWizardModal-CgtvpMX9.js → SetupWizardModal-Agi3XNtZ.js} +1 -1
- package/dist/client/assets/{SkillsView-DErYRumF.js → SkillsView-DmZfbGLs.js} +1 -1
- package/dist/client/assets/{StashRecoveryView-QJrNS4Vg.js → StashRecoveryView-BwKJQaUW.js} +1 -1
- package/dist/client/assets/{TodoView-BD9NRwq0.js → TodoView-uJRg4Cnl.js} +2 -2
- package/dist/client/assets/dashboard-view-C7Snlgow.js +21 -0
- package/dist/client/assets/dashboard-view-DqWnXEbq.css +1 -0
- package/dist/client/assets/{folder-open-CHSlllzf.js → folder-open-DU-Ec_iC.js} +1 -1
- package/dist/client/assets/index-CD0_dkME.css +1 -0
- package/dist/client/assets/index-DiewofJh.js +692 -0
- package/dist/client/assets/{star-BgVwWAPz.js → star-Qi0GspVN.js} +1 -1
- package/dist/client/assets/{upload-CAzycxr9.js → upload-Dx_l9Vbu.js} +1 -1
- package/dist/client/assets/{users-CZnxCCCJ.js → users-3Qw_TMah.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/extension.js +4173 -929
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/registration.test.ts +2 -4
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/runtime-availability.test.ts +5 -2
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/workflow-integration.test.ts +7 -4
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/package.json +1 -1
- package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +1 -1
- package/skill/fusion/SKILL.md +1 -1
- package/skill/fusion/references/engine-tools.md +2 -1
- package/skill/fusion/references/extension-tools.md +4 -1
- package/skill/fusion/workflows/task-management.md +3 -1
- package/dist/client/assets/AgentDetailView-B7QRcHJH.css +0 -1
- package/dist/client/assets/ChatView-DnCdKu8Z.js +0 -1
- package/dist/client/assets/DevServerView-BiA1nYtt.js +0 -1
- package/dist/client/assets/PluginManager-DoSAykD6.js +0 -1
- package/dist/client/assets/PluginManager-DtRQXia5.css +0 -1
- package/dist/client/assets/ResearchView-BEI4ZSGs.css +0 -1
- package/dist/client/assets/ResearchView-XZuRtOxE.js +0 -1
- package/dist/client/assets/SettingsModal-DBcjf9Bu.js +0 -31
- package/dist/client/assets/dashboard-view-BoTzlP8b.css +0 -1
- package/dist/client/assets/dashboard-view-Ws9_ZnKu.js +0 -21
- package/dist/client/assets/index-DCovGm5b.css +0 -1
- package/dist/client/assets/index-bEwSVl7B.js +0 -692
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as n,a as Js,j as t,R as Ys}from"./vendor-react-K0fH_qHe.js";import{i as ft,b4 as us,t as Ms,b5 as Qs,b6 as ms,b7 as Zs,w as Ht,b8 as Oe,b9 as en,ba as tn,bb as sn,bc as nn,bd as an,be as rn,s as Rs,bf as on,bg as cn,bh as Pt,bi as ln,bj as dn,bk as un,bl as mn,k as As,bm as hn,bn as fn,p as gn,bo as pn,bp as bn,u as vn,bq as xn,ab as Es,ac as Ts,br as yn,bs as wn,S as Sn,W as Lt,P as Qe,I as lt,ao as Nn,bt as hs,bu as fs,bv as gs,B as Ze,a as ps,a8 as Cn,a9 as kn,aV as ht,bw as jn,bx as Mn,aS as Rn,by as bs,bz as An,T as En,bA as vs,bB as Tn,h as Dn,j as xs,m as In}from"./index-DiewofJh.js";import"./vendor-xterm-DzcZoU0P.js";const Ft="kb-chat-active-session";function ys(s){const r=typeof s=="string"?s.trim():"",l=r.indexOf("/");return!r||l<=0||l>=r.length-1?{}:{modelProvider:r.slice(0,l),modelId:r.slice(l+1)}}function $n(s){const r=s?.toolCalls;if(!Array.isArray(r))return;const l=r.map(i=>{if(!i||typeof i!="object")return null;const d=i,v=typeof d.toolName=="string"?d.toolName:"";if(!v)return null;const M=d.args;return{toolName:v,...M&&typeof M=="object"?{args:M}:{},isError:!!d.isError,result:d.result,status:"completed"}}).filter(i=>i!==null);return l.length>0?l:void 0}function Pn(s){const r=s?.fallback;if(!r||typeof r!="object")return;const l=r,i=typeof l.primaryModel=="string"?l.primaryModel:"",d=typeof l.fallbackModel=="string"?l.fallbackModel:"",v=l.triggerPoint;if(!(!i||!d||v!=="session-creation"&&v!=="prompt-time"))return{primaryModel:i,fallbackModel:d,triggerPoint:v}}function Ln(s){const r=s?.failureInfo;if(!r||typeof r!="object")return;const l=r,i=typeof l.summary=="string"?l.summary.trim():"";if(!i)return;const d=(()=>{const v=l.reference;if(!v||typeof v!="object")return;const M=v,T=typeof M.kind=="string"?M.kind.trim():"",D=typeof M.id=="string"?M.id.trim():"";if(!(!T||!D))return{kind:T,id:D,...typeof M.label=="string"&&M.label.trim()?{label:M.label.trim()}:{}}})();return{summary:i,...typeof l.errorClass=="string"&&l.errorClass.trim()?{errorClass:l.errorClass.trim()}:{},...typeof l.code=="string"&&l.code.trim()?{code:l.code.trim()}:{},...typeof l.detail=="string"&&l.detail.trim()?{detail:l.detail.trim()}:{},...d?{reference:d}:{}}}function ws(s){return typeof s=="string"?{summary:s.trim()||"Failed to get response"}:{summary:typeof s.summary=="string"&&s.summary.trim()?s.summary.trim():"Failed to get response",...typeof s.errorClass=="string"&&s.errorClass.trim()?{errorClass:s.errorClass.trim()}:{},...typeof s.code=="string"&&s.code.trim()?{code:s.code.trim()}:{},...typeof s.detail=="string"&&s.detail.trim()?{detail:s.detail.trim()}:{},...s.reference?{reference:s.reference}:{}}}function _t(s){return{id:s.id,sessionId:s.sessionId,role:s.role,content:s.content,thinkingOutput:s.thinkingOutput,toolCalls:$n(s.metadata),fallbackInfo:Pn(s.metadata),failureInfo:Ln(s.metadata),attachments:s.attachments,createdAt:s.createdAt}}function Fn(s,r){const[l,i]=n.useState([]),[d,v]=n.useState(null),[M,T]=n.useState(!0),[D,S]=n.useState([]),[Y,w]=n.useState(!1),[_,g]=n.useState(!1),[ee,R]=n.useState(""),[U,b]=n.useState(""),[j,I]=n.useState([]),[A,E]=n.useState(""),[V,q]=n.useState(""),[z,h]=n.useState(!0),[f,o]=n.useState(new Map),c=n.useRef(null),m=n.useRef(!1),x=n.useRef(""),k=n.useRef(null),Q=n.useRef(l),O=n.useRef(d),se=n.useRef(_);Q.current=l,O.current=d,se.current=_,n.useEffect(()=>{x.current=A},[A]);const xe=n.useRef(new Set),ue=n.useRef(0),me=n.useRef(s);me.current!==s&&(me.current=s,ue.current++),n.useEffect(()=>{const p=ue.current;ft(void 0,s).then(y=>{if(ue.current!==p)return;const C=new Map;for(const P of y)C.set(P.id,P);o(C)}).catch(()=>{})},[s]);const re=n.useCallback(async()=>{T(!0);try{const y=[...(await us(s)).sessions].sort((C,P)=>new Date(P.updatedAt).getTime()-new Date(C.updatedAt).getTime());i(y)}catch{}finally{T(!1)}},[s]);n.useEffect(()=>{re()},[re]);const $e=n.useRef(()=>{}),Te=n.useRef(!1);n.useEffect(()=>{Te.current=!1},[s]),n.useEffect(()=>{if(M||Te.current||O.current)return;const p=Ms(Ft,s);if(!p){Te.current=!0;return}const y=l.find(C=>C.id===p);if(y){Te.current=!0,$e.current(p,y);return}Te.current=!0},[M,l,s]);const ae=n.useCallback(async(p,y)=>{w(!0);try{const C=await Qs(p,{limit:50,...y},s),P=C.messages.map(_t);y?.offset&&y.offset>0?S(te=>[...P,...te]):S(P),h(C.messages.length>=50)}catch{}finally{w(!1)}},[s]),oe=n.useCallback(()=>{k.current?.(),k.current=null,x.current="",E(""),R(""),b(""),I([]),g(!1)},[]),he=n.useCallback((p,y)=>{if(c.current||!p)return!0;m.current=!1,y&&(R(y.streamingText),b(y.streamingThinking),I(y.toolCalls)),g(!0);const{handlers:C}=ms({sessionId:p,tempUserMessageId:"",setStreamingText:R,setStreamingThinking:b,setStreamingToolCalls:I,cancelStreamingFlushesRef:k,addToast:r,onFallbackSession:(te,G)=>{const Z=ys(te.fallbackModel);i(L=>L.map(X=>X.id===G?{...X,...Z}:X)),v(L=>L&&L.id===G?{...L,...Z}:L)},onDone:()=>{R(""),b(""),I([]),g(!1),se.current=!1,c.current=null,ae(p)},onError:te=>{R(""),b(""),I([]),g(!1),se.current=!1,c.current=null;const G=ws(te);r?.(G.summary,"error"),ae(p)}}),P=Zs(p,C,s,{...typeof y?.replayFromEventId=="number"?{lastEventId:y.replayFromEventId}:{}});return c.current=P,!0},[r,ae,s]),ye=n.useCallback((p,y)=>{const C=O.current?.id??null;if(p&&C===p&&!y)return;c.current&&(c.current.close(),c.current=null);const P=y??l.find(te=>te.id===p);v(P||null),oe(),h(!0),p?ae(p):S([]),P?.isGenerating&&he(P.id,P.inFlightGeneration),p?Ht(Ft,p,s):Oe(Ft,s)},[he,l,ae,s,oe]);$e.current=ye;const et=n.useCallback(async p=>{const y=await en(p,s);c.current&&(c.current.close(),c.current=null);const C={id:y.session.id,title:y.session.title,agentId:y.session.agentId,status:y.session.status,modelProvider:y.session.modelProvider,modelId:y.session.modelId,createdAt:y.session.createdAt,updatedAt:y.session.updatedAt};return i(P=>P.some(te=>te.id===C.id)?P:[C,...P]),oe(),ye(C.id,C),S([]),C},[s,oe,ye]),gt=n.useCallback(async p=>{await tn(p,{status:"archived"},s),i(y=>y.filter(C=>C.id!==p)),d?.id===p&&(v(null),S([]))},[d,s]),tt=n.useCallback(async p=>{d?.id===p&&c.current&&(c.current.close(),c.current=null),await sn(p,s),i(y=>y.filter(C=>C.id!==p)),d?.id===p&&(v(null),S([]))},[d,s]),we=n.useCallback(async()=>{!d||!z||await ae(d.id,{offset:D.length})},[d,z,ae,D.length]),Se=n.useCallback(()=>{d&&(m.current=!0,k.current?.(),k.current=null,c.current?.close(),c.current=null,nn(d.id,s).catch(()=>{}),g(!1),R(""),b(""),I([]))},[d,s]),Be=n.useCallback(()=>{x.current="",E("")},[]),Ne=n.useRef(()=>{}),Ce=an(),ke=n.useCallback((p,y)=>{if(!d)return;if(se.current){x.current=p,E(p);return}m.current=!1,c.current&&(c.current.close(),c.current=null);const C=`temp-${Date.now()}`,P={id:C,sessionId:d.id,role:"user",content:p,createdAt:new Date().toISOString()};S(G=>[...G,P]),R(""),b(""),I([]),g(!0);const{handlers:te}=ms({sessionId:d.id,tempUserMessageId:C,setStreamingText:R,setStreamingThinking:b,setStreamingToolCalls:I,cancelStreamingFlushesRef:k,addToast:r,onFallbackSession:(G,Z)=>{const L=ys(G.fallbackModel);i(X=>X.map(F=>F.id===Z?{...F,...L}:F)),v(X=>X&&X.id===Z?{...X,...L}:X)},onDone:({messageId:G,message:Z,accumulated:L})=>{const X=Z?_t(Z):{id:G||`msg-${Date.now()}`,sessionId:d.id,role:"assistant",content:L.text,thinkingOutput:L.thinking,toolCalls:L.toolCalls.length>0?L.toolCalls:void 0,fallbackInfo:L.fallbackInfo,createdAt:new Date().toISOString()};xe.current.add(X.id),S(H=>[...H,X]),R(""),b(""),I([]),g(!1),se.current=!1,c.current=null,setTimeout(()=>{xe.current.delete(X.id)},1e3),re();const F=x.current.trim();F&&(x.current="",E(""),Ne.current(F))},onError:(G,Z)=>{const L=ws(G),X=typeof G=="string"&&on(G)&&(Ce.isHiddenNow()||Ce.wasRecentlyHidden(5e3));if(S(F=>{const H=F.filter(B=>B.id!==Z);return X?H:[...H,{id:`error-${Date.now()}`,sessionId:d.id,role:"assistant",content:L.summary,failureInfo:L,createdAt:new Date().toISOString()}]}),R(""),b(""),I([]),g(!1),se.current=!1,c.current=null,console.error("[useChat] Stream error:",G),X?(console.info("[useChat] Suppressed tab-suspension stream error:",G),d?.id&&(d.isGenerating?he(d.id,d.inFlightGeneration):ae(d.id))):(r?.(L.summary,"error"),re()),!m.current){const F=x.current.trim();F&&(x.current="",E(""),Ne.current(F))}}});c.current=rn(d.id,p,te,y,s)},[d,s,re,r,ae,he,Ce]);Ne.current=ke;const je=V?l.filter(p=>p.title?.toLowerCase().includes(V.toLowerCase())||p.agentId.toLowerCase().includes(V.toLowerCase())):l;return n.useEffect(()=>{if(!O.current?.isGenerating||(c.current||he(O.current.id,O.current.inFlightGeneration),!se.current||c.current||!O.current))return;const p=setInterval(async()=>{if(!se.current||c.current||!O.current){clearInterval(p);return}try{(await us(s)).sessions.find(P=>P.id===O.current?.id)?.isGenerating||(clearInterval(p),await ae(O.current.id),R(""),b(""),I([]),g(!1))}catch{}},3e3);return()=>clearInterval(p)},[he,ae,s,d]),n.useEffect(()=>{const p=ue.current,y=s?`?projectId=${encodeURIComponent(s)}`:"",C=()=>ue.current!==p,P=F=>{if(C())return;const H=JSON.parse(F.data);i(B=>B.some(J=>J.id===H.id)?B:[H,...B])},te=F=>{if(C())return;const H=JSON.parse(F.data);i(B=>[...B.map(ce=>ce.id===H.id?H:ce)]),O.current?.id===H.id&&(v(H),H.isGenerating&&!c.current&&he(H.id,H.inFlightGeneration))},G=F=>{if(C())return;const{id:H}=JSON.parse(F.data);i(B=>B.filter(J=>J.id!==H)),O.current?.id===H&&(v(null),S([]))},Z=F=>{if(C())return;const H=JSON.parse(F.data),B=_t(H);if(!xe.current.has(B.id)){if(O.current?.id===B.sessionId&&se.current&&!c.current&&B.role==="assistant"){S(J=>J.some(ce=>ce.id===B.id)?J:[...J,B]),R(""),b(""),I([]),g(!1);return}O.current?.id===B.sessionId&&!se.current&&S(J=>{if(J.some(ce=>ce.id===B.id))return J;if(B.role==="user"){const ce=J.findIndex(fe=>fe.role==="user"&&fe.id.startsWith("temp-")&&fe.content.trim()===B.content.trim());if(ce>=0){const fe=[...J];return fe[ce]=B,fe}}return[...J,B]})}},L=F=>{if(C())return;const{id:H}=JSON.parse(F.data);S(B=>B.filter(J=>J.id!==H))};return Rs(`/api/events${y}`,{events:{"chat:session:created":P,"chat:session:updated":te,"chat:session:deleted":G,"chat:message:added":Z,"chat:message:deleted":L}})},[he,s]),n.useEffect(()=>()=>{c.current&&(c.current.close(),c.current=null)},[]),{sessions:l,activeSession:d,sessionsLoading:M,messages:D,messagesLoading:Y,isStreaming:_,streamingText:ee,streamingThinking:U,streamingToolCalls:j,pendingMessage:A,selectSession:ye,createSession:et,archiveSession:gt,deleteSession:tt,sendMessage:ke,stopStreaming:Se,clearPendingMessage:Be,loadMoreMessages:we,hasMoreMessages:z,searchQuery:V,setSearchQuery:q,filteredSessions:je,refreshSessions:re,agentsMap:f}}const Ae="fusion:chat-active-room";function Bt(s){return[...s].sort((r,l)=>new Date(l.updatedAt).getTime()-new Date(r.updatedAt).getTime())}function Ye(s,r){const l=s.findIndex(d=>d.id===r.id);if(l===-1)return Bt([r,...s]);const i=[...s];return i[l]=r,Bt(i)}function Ee(s){try{return JSON.parse(s.data)}catch{return null}}function _n(s,r){return{id:`temp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,roomId:s,role:"user",content:r,thinkingOutput:null,metadata:null,senderAgentId:null,mentions:[],createdAt:new Date().toISOString()}}function zn(s,r){const[l,i]=n.useState([]),[d,v]=n.useState(!0),[M,T]=n.useState(null),[D,S]=n.useState(null),[Y,w]=n.useState([]),[_,g]=n.useState([]),[ee,R]=n.useState(!1),U=n.useRef(l),b=n.useRef(D),j=n.useRef(0),I=n.useRef(s);U.current=l,b.current=D,I.current!==s&&(I.current=s,j.current+=1);const A=n.useCallback(async(f,o=!0)=>{if(!f){w([]),g([]),R(!1);return}o&&g([]),R(!0);try{const[c,m]=await Promise.all([cn(f.id,s),Pt(f.id,{limit:100},s)]);w(c.members),g(m.messages)}catch{w([]),g([])}finally{R(!1)}},[s]),E=n.useCallback(async()=>{v(!0);try{const f=await ln({},s),o=Bt(f.rooms);i(o),T(null);const c=Ms(Ae,s);if(c){const m=o.find(x=>x.id===c)??null;m?(S(m),A(m,!0)):Oe(Ae,s)}}catch(f){const o=f instanceof Error?f.message:"Failed to load chat rooms";T(o),r?.(o,"error")}finally{v(!1)}},[r,A,s]),V=n.useCallback(f=>{if(!f){S(null),Oe(Ae,s),A(null,!0);return}const o=U.current.find(c=>c.id===f)??null;S(o),o&&(Ht(Ae,o.id,s),A(o,!0))},[A,s]),q=n.useCallback(async f=>{const c=(await dn({name:f.name,memberAgentIds:f.memberAgentIds},s)).room;return i(m=>Ye(m,c)),S(c),Ht(Ae,c.id,s),await A(c,!0),c},[A,s]),z=n.useCallback(async f=>{await un(f,s),i(o=>o.filter(c=>c.id!==f)),b.current?.id===f&&(S(null),w([]),g([]),Oe(Ae,s))},[s]),h=n.useCallback(async(f,o)=>{const c=b.current,m=c?.id;if(!m)throw new Error("Select a room before sending a message");const x=_n(m,f);b.current?.id===m&&g(k=>[...k,x]);try{const k=await mn(m,{content:f,...o?.attachments?{attachments:o.attachments}:{}},s);k.message?.createdAt&&c&&i(O=>Ye(O,{...c,updatedAt:k.message.createdAt})),b.current?.id===m&&g(O=>O.map(se=>se.id===x.id?k.message:se));const Q=await Pt(m,{limit:100},s);if(b.current?.id!==m)return;g(Q.messages)}catch(k){try{const Q=await Pt(m,{limit:100},s);b.current?.id===m&&g(Q.messages)}catch{b.current?.id===m&&g(Q=>Q.filter(O=>O.id!==x.id))}throw k}},[s]);return n.useEffect(()=>{E()},[E]),n.useEffect(()=>{const f=j.current,o=s?`/api/events?projectId=${encodeURIComponent(s)}`:"/api/events";return Rs(o,{onReconnect:()=>{E()},events:{"chat:room:created":c=>{if(j.current!==f)return;const m=Ee(c);m&&i(x=>Ye(x,m))},"chat:room:updated":c=>{if(j.current!==f)return;const m=Ee(c);m&&(i(x=>Ye(x,m)),b.current?.id===m.id&&S(m))},"chat:room:deleted":c=>{if(j.current!==f)return;const m=Ee(c);m?.id&&(i(x=>x.filter(k=>k.id!==m.id)),b.current?.id===m.id&&(S(null),w([]),g([]),Oe(Ae,s)))},"chat:room:member:added":c=>{if(j.current!==f)return;const m=Ee(c);!m||b.current?.id!==m.roomId||w(x=>x.some(k=>k.agentId===m.agentId)?x:[...x,m])},"chat:room:member:removed":c=>{if(j.current!==f)return;const m=Ee(c);!m||b.current?.id!==m.roomId||w(x=>x.filter(k=>k.agentId!==m.agentId))},"chat:room:message:added":c=>{if(j.current!==f)return;const m=Ee(c);m&&(i(x=>{const k=x.find(Q=>Q.id===m.roomId);return k?Ye(x,{...k,updatedAt:m.createdAt}):x}),b.current?.id===m.roomId&&g(x=>{if(x.some(k=>k.id===m.id))return x;if(m.role==="user"){const k=x.findIndex(Q=>Q.role==="user"&&Q.id.startsWith("temp-")&&Q.content.trim()===m.content.trim());if(k>=0){const Q=[...x];return Q[k]=m,Q}}return[...x,m]}))},"chat:room:message:updated":c=>{if(j.current!==f)return;const m=Ee(c);!m||b.current?.id!==m.roomId||g(x=>x.map(k=>k.id===m.id?m:k))},"chat:room:message:deleted":c=>{if(j.current!==f)return;const m=Ee(c);m?.id&&g(x=>x.filter(k=>k.id!==m.id))}}})},[s,E]),n.useEffect(()=>{D&&(l.some(f=>f.id===D.id)||(S(null),w([]),g([]),Oe(Ae,s)))},[D,s,l]),{rooms:l,roomsLoading:d,roomsError:M,activeRoom:D,activeRoomMembers:Y,messages:_,messagesLoading:ee,selectRoom:V,createRoom:q,deleteRoom:z,sendRoomMessage:h,refreshRooms:E}}function Un(s,r=[]){const l=s.trim().replace(/^#/,"");if(!l)return{ok:!1,error:"Room name is required."};if(/[A-Z]/.test(l))return{ok:!1,error:"Use lowercase letters only."};const i=l.toLowerCase();return i.length>80?{ok:!1,error:"Room names can be at most 80 characters."}:/^[a-z0-9_-]+$/.test(i)?/^[-_]|[-_]$/.test(i)?{ok:!1,error:"Room names cannot start or end with a hyphen or underscore."}:r.some(d=>d.toLowerCase()===i)?{ok:!1,error:"A room with this name already exists."}:{ok:!0,name:i}:{ok:!1,error:"Use lowercase letters, numbers, hyphens, or underscores only."}}function On({isOpen:s,onClose:r,onCreate:l,projectId:i,existingRoomNames:d=[]}){const[v,M]=n.useState(""),[T,D]=n.useState([]),[S,Y]=n.useState(""),[w,_]=n.useState([]),[g,ee]=n.useState(!1),[R,U]=n.useState(null),[b,j]=n.useState(!1),I=n.useRef(null),A=n.useRef(null);n.useEffect(()=>{s&&(A.current=document.activeElement instanceof HTMLElement?document.activeElement:null,ee(!0),U(null),ft(void 0,i).then(o=>D(o)).catch(()=>{D([]),U("Failed to load agents.")}).finally(()=>ee(!1)))},[s,i]),n.useEffect(()=>{if(!s){M(""),Y(""),_([]),U(null),j(!1);return}const o=window.requestAnimationFrame(()=>I.current?.focus());return()=>window.cancelAnimationFrame(o)},[s]),n.useEffect(()=>{if(!s)return;const o=c=>{c.key==="Escape"&&r()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[s,r]),n.useEffect(()=>{s||A.current?.focus()},[s]);const E=n.useMemo(()=>Un(v,d),[v,d]),V=n.useMemo(()=>{const o=S.trim().toLowerCase();return o?T.filter(c=>c.name.toLowerCase().includes(o)):T},[T,S]),q=n.useMemo(()=>T.filter(o=>w.includes(o.id)),[T,w]),z=E.ok&&w.length>0&&!b&&!g;if(!s)return null;const h=o=>{b||_(c=>c.includes(o)?c.filter(m=>m!==o):[...c,o])},f=async()=>{if(!E.ok){U(E.error);return}if(w.length===0){U("Select at least one member.");return}U(null),j(!0);try{await l({name:E.name,displayName:`#${E.name}`,memberAgentIds:w}),r()}catch(o){U(o instanceof Error?o.message:"Failed to create room.")}finally{j(!1)}};return Js.createPortal(t.jsx("div",{className:"modal-overlay open",onClick:o=>o.target===o.currentTarget&&r(),children:t.jsxs("div",{className:"modal modal-lg create-room-modal",role:"dialog","aria-modal":"true","aria-label":"Create room",onClick:o=>o.stopPropagation(),children:[t.jsxs("div",{className:"modal-header",children:[t.jsx("h3",{children:"Create room"}),t.jsx("button",{type:"button",className:"modal-close","aria-label":"Close",onClick:r,children:"×"})]}),t.jsxs("div",{className:"form-group create-room-modal-name-group",children:[t.jsx("label",{htmlFor:"create-room-name",children:"Room name"}),t.jsxs("div",{className:"create-room-modal-name-field",children:[t.jsx("span",{"aria-hidden":"true",className:"create-room-modal-name-hash",children:"#"}),t.jsx("input",{ref:I,id:"create-room-name",className:"input",value:v,disabled:b,onChange:o=>{const c=o.target.value.replace(/^#/,"").replace(/\s+/g,"-").toLowerCase();M(c)}})]}),!E.ok&&t.jsx("div",{className:"form-error",children:E.error})]}),t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"create-room-member-search",children:"Members"}),t.jsx("input",{id:"create-room-member-search",className:"input",placeholder:"Search agents",value:S,disabled:b,onChange:o=>Y(o.target.value)})]}),q.length>0&&t.jsx("div",{className:"create-room-modal-selected","data-testid":"create-room-selected-chips",children:q.map(o=>t.jsxs("button",{type:"button",className:"btn btn-sm create-room-modal-chip",onClick:()=>h(o.id),disabled:b,children:[o.name," ×"]},o.id))}),t.jsx("div",{className:"create-room-modal-member-list","data-testid":"create-room-member-list",children:g?t.jsx("div",{className:"create-room-modal-empty",children:"Loading agents..."}):V.length===0?t.jsx("div",{className:"create-room-modal-empty",children:T.length===0?"No agents in this project yet.":"No agents match your search."}):V.map(o=>{const c=w.includes(o.id);return t.jsxs("button",{type:"button",className:`create-room-modal-member-row${c?" create-room-modal-member-row--selected":""}`,onClick:()=>h(o.id),disabled:b,children:[t.jsx(As,{agent:o,size:20}),t.jsx("span",{children:o.name}),t.jsx("span",{className:"create-room-modal-member-role",children:o.role})]},o.id)})}),R&&t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"form-error",children:R})}),t.jsxs("div",{className:"modal-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:r,disabled:b,children:"Cancel"}),t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void f(),disabled:!z,children:b?"Creating...":"Create room"})]})]})}),document.body)}const Hn=320;function zt(s){return Math.min(s,Hn)}function Ds(s){const r=new Date(s),i=new Date().getTime()-r.getTime(),d=Math.floor(i/1e3),v=Math.floor(d/60),M=Math.floor(v/60),T=Math.floor(M/24);return d<60?"just now":v<60?`${v}m ago`:M<24?`${M}h ago`:T<7?`${T}d ago`:r.toLocaleDateString()}function Ss(s,r){if(!s||!r)return null;const l=r.toLowerCase();if(l.includes("claude")){let d=r.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 d=d.replace(/\s+/g," "),d.length>30?d.slice(0,30)+"…":d}if(l.includes("gpt")||l.includes("openai")){const d=r.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 d.length>30?d.slice(0,30)+"…":d}if(l.includes("gemini")){const d=r.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 d.length>30?d.slice(0,30)+"…":d}const i=r.replace(/-/g," ").replace(/^\w/,d=>d.toUpperCase()).replace(/\s+/g," ").trim();return i.length>30?i.slice(0,30)+"…":i}function mt(s,r){return s.length<=r?s:`${s.slice(0,r)}…`}function Bn(s){if(!s)return null;const r=Object.entries(s);return r.length===0?null:r.map(([l,i])=>{const d=typeof i=="string"?i:(()=>{try{return JSON.stringify(i)}catch{return String(i)}})();return`${l}=${mt(d,50)}`}).join(", ")}function Kn(s){if(s===void 0)return null;if(typeof s=="string")return mt(s,200);try{return mt(JSON.stringify(s),200)}catch{return mt(String(s),200)}}function Wn(s){if(!s)return null;if(s.kind==="mailbox"||s.kind==="mailbox-message"){const r=typeof window>"u"?"/":window.location.pathname||"/",l=new URLSearchParams(typeof window>"u"?"":window.location.search);return l.set("view","mailbox"),l.set("mailbox-message",s.id),`${r}?${l.toString()}#message-${encodeURIComponent(s.id)}`}return null}function Gn(s){if(!s)return null;const r=s.label??`${s.kind} ${s.id}`,l=Wn(s),i=`chat-failure-reference-${s.kind}-${s.id}`.replace(/[^a-zA-Z0-9_-]+/g,"-").toLowerCase();return t.jsxs("div",{className:"chat-message-failure-reference",children:[t.jsx("span",{className:"chat-message-failure-reference-label",children:"Reference"}),t.jsx("span",{className:"chat-message-failure-reference-value",children:r}),l?t.jsx("a",{className:"btn btn-sm chat-message-failure-reference-link",href:l,children:"Open mailbox message"}):t.jsxs("details",{className:"chat-message-failure-reference-details",children:[t.jsx("summary",{className:"btn btn-sm chat-message-failure-reference-link",children:"View failure details"}),t.jsxs("dl",{className:"chat-message-failure-reference-meta",id:i,children:[t.jsxs("div",{children:[t.jsx("dt",{children:"Kind"}),t.jsx("dd",{children:s.kind})]}),t.jsxs("div",{children:[t.jsx("dt",{children:"ID"}),t.jsx("dd",{children:s.id})]}),s.label&&t.jsxs("div",{children:[t.jsx("dt",{children:"Label"}),t.jsx("dd",{children:s.label})]})]})]})]})}function Is(s){if(!s||s.length===0)return null;const r=(w,_)=>{const g=w.status==="running",ee=w.status==="completed"&&w.isError,R=Bn(w.args),U=Kn(w.result),b=g?R:U?`result: ${U}`:R?`args: ${R}`:null,j=g?"running":ee?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${g?" chat-tool-call--running":""}${ee?" chat-tool-call--error":""}`,open:g,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",title:w.toolName,children:w.toolName}),b&&t.jsx("span",{className:"chat-tool-call-preview",title:b,children:b}),t.jsx("span",{className:"chat-tool-call-status-text",children:j})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[R&&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:R})]}),U&&t.jsxs("div",{className:`chat-tool-call-row${ee?" 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:U})]})]})]},`${w.toolName}-${_}`)},l="chat-tool-calls";if(s.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(vs,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),r(s[0],0)]});const i=s.filter(w=>w.status==="running").length,d=s.filter(w=>w.status==="completed"&&w.isError).length,v=i>0,M=Array.from(new Set(s.map(w=>w.toolName))),T=M.slice(0,5),D=Math.max(0,M.length-T.length),S=D>0?`${T.join(", ")}, +${D} more`:T.join(", "),Y=v?`(${i} running)`:d>0?`(${d} ${d===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:v,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(vs,{size:12,"aria-hidden":"true"}),t.jsxs("span",{className:"chat-tool-calls-count",children:[s.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:S,children:S}),Y&&t.jsx("span",{className:"chat-tool-calls-group-status",children:Y})]}),s.map((w,_)=>r(w,_))]})})}const $s={p:({children:s,...r})=>t.jsx("p",{...r,children:bs(s)}),li:({children:s,...r})=>t.jsx("li",{...r,children:bs(s)}),pre:({children:s,...r})=>t.jsx("pre",{...r,className:"chat-markdown-pre",children:s}),code:({children:s,...r})=>{const l=typeof s=="string"?s:Ys.Children.toArray(s).join(""),i=ht(l);return i.length===1&&typeof i[0]=="string"?t.jsx("code",{...r,children:s}):t.jsx("code",{...r,children:i})},table:({children:s,...r})=>t.jsx("table",{...r,className:"chat-markdown-table",children:s})},He="__fn_agent__",Vn=280,dt=180,ut=500,Ns="fusion:chat-sidebar-width",Ut="fusion:chat-scope",qn="fusion:chat-draft:";function Cs(s,r){return r?`${qn}${s}:${r}`:null}function ks(s){if(!s)return"";try{return localStorage.getItem(s)??""}catch{return""}}const Xn=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function js(s){const r=/(^|[\s])\/([^\s]*)$/.exec(s);if(!r)return null;const l=r[1]??"",i=r[2]??"",d=r.index+l.length;return{filter:i,start:d,end:s.length}}function Jn(s,r){const l=s.slice(0,r),i=/(^|[\s\n])@([\w-]*)$/.exec(l);if(!i)return null;const d=i[2]??"",v=l.length-d.length-1;return{filter:d,start:v,end:r}}function Yn({projectId:s,onClose:r,onCreate:l}){const[i,d]=n.useState("agent"),[v,M]=n.useState([]),[T,D]=n.useState(!0),[S,Y]=n.useState(""),[w,_]=n.useState([]),[g,ee]=n.useState(!0),[R,U]=n.useState(""),[b,j]=n.useState([]),[I,A]=n.useState([]);n.useEffect(()=>{let h=!1;return D(!0),ft(void 0,s).then(f=>{h||M(f)}).catch(()=>{h||M([])}).finally(()=>{h||D(!1)}),()=>{h=!0}},[s]),n.useEffect(()=>{ee(!0),Dn().then(h=>{_(h.models),j(h.favoriteProviders),A(h.favoriteModels)}).catch(()=>{_([]),j([]),A([])}).finally(()=>{ee(!1)})},[]);const E=n.useCallback(async h=>{const f=b,c=f.includes(h)?f.filter(m=>m!==h):[h,...f];j(c);try{await xs({favoriteProviders:c,favoriteModels:I})}catch{j(f)}},[b,I]),V=n.useCallback(async h=>{const f=I,c=f.includes(h)?f.filter(m=>m!==h):[h,...f];A(c);try{await xs({favoriteProviders:b,favoriteModels:c})}catch{A(f)}},[I,b]),q=h=>{if(h.preventDefault(),i==="agent"){if(!S)return;l({agentId:S});return}if(!R)return;const f=R.indexOf("/");if(f<=0)return;const o=R.slice(0,f),c=R.slice(f+1);l({agentId:He,modelProvider:o,modelId:c})},z=i==="agent"?!S:!R;return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:r,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:h=>h.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${i==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{d("agent"),U("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${i==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{d("model"),Y("")},children:"Model"})]}),t.jsxs("form",{onSubmit:q,children:[i==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",T?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):v.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:v.map(h=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${S===h.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>Y(h.id),"data-testid":`agent-option-${h.id}`,children:[t.jsx(Ze,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:h.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:h.role})]},h.id))})]}),i==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:g?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(In,{models:w,value:R,onChange:U,label:"Model",placeholder:"Select a model",favoriteProviders:b,onToggleFavorite:E,favoriteModels:I,onToggleModelFavorite:V})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:r,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:z,children:"Create"})]})]})]})})}const Ot=n.memo(function({message:r,forcePlain:l,agentName:i,hideAssistantIdentity:d,showAssistantModelTag:v,activeModelTag:M,activeModelProvider:T,activeSessionId:D,mentionAgentsByName:S,roomContext:Y,copyAction:w}){const _=r.role==="assistant",g=_?r.failureInfo:void 0,ee=_&&(!d||!!g),R=n.useMemo(()=>{if(_)return null;const j=r.content,I=/@([\w-]+)/g,A=[];let E=0,V=I.exec(j);for(;V;){const[q,z=""]=V,h=V.index;h>E&&A.push(j.slice(E,h));const f=z.replace(/_/g," ").toLowerCase(),o=S.get(f);if(o){const c=!!(Y&&!Y.memberIds.has(o.id)),m=c?`Not a member of ${Y?.roomName}`:void 0;A.push(t.jsxs("span",{className:`chat-mention-chip${c?" chat-mention-chip--non-member":""}`,title:m,"aria-label":m,children:["@",o.name.replace(/\s+/g,"_")]},`${o.id}-${h}`))}else A.push(q);E=h+q.length,V=I.exec(j)}return E<j.length&&A.push(j.slice(E)),A.length===0?j:A},[_,r.content,S,Y]),U=n.useMemo(()=>{const j=r.attachments;if(!j||j.length===0||!D)return null;const I=`/api/chat/sessions/${encodeURIComponent(D)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:j.map(A=>{const E=A.mimeType.startsWith("image/"),V=A.id||A.filename,q=`${I}${encodeURIComponent(A.filename)}`;return E?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:q,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:q,alt:A.originalName})},V):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:q,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(An,{size:14}),t.jsx("span",{children:A.originalName})]},V)})})},[r.attachments,D]),b=n.useMemo(()=>_?g?t.jsxs("div",{className:"chat-message-content chat-message-content--failure",children:[t.jsxs("div",{className:"chat-message-failure-summary-row",children:[t.jsx("span",{className:"status-dot status-dot--error","aria-hidden":"true"}),t.jsx("span",{className:"chat-message-failure-label",children:"Response failed"})]}),t.jsx("div",{className:"chat-message-failure-summary",children:g.summary}),(g.errorClass||g.code)&&t.jsxs("div",{className:"chat-message-failure-badges",children:[g.errorClass&&t.jsx("span",{className:"chat-message-failure-badge",children:g.errorClass}),g.code&&t.jsx("span",{className:"chat-message-failure-badge",children:g.code})]}),(g.detail||g.reference)&&t.jsxs("details",{className:"chat-message-failure-details",children:[t.jsxs("summary",{children:[t.jsx(En,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:"Failure details"})]}),g.detail&&t.jsx("pre",{className:"chat-message-failure-detail",children:ht(g.detail)}),Gn(g.reference)]})]}):l?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:r.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(Es,{remarkPlugins:[Ts],components:$s,children:r.content})}):null,[g,l,_,r.content]);return t.jsxs("div",{className:`chat-message chat-message--${r.role}${g?" chat-message--failure":""}`,"data-testid":`chat-message-${r.id}`,children:[ee&&t.jsxs("div",{className:"chat-message-avatar",children:[T?t.jsx(Qe,{provider:T,size:"sm"}):t.jsx(Ze,{size:14}),t.jsx("span",{children:i}),v&&M&&t.jsx("span",{className:"chat-model-tag",children:M})]}),_?b:t.jsx("div",{className:"chat-message-content",children:R}),!g&&w,Is(r.toolCalls),r.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:ht(r.thinkingOutput)})]}),U,t.jsx("div",{className:"chat-message-time",children:Ds(r.createdAt)})]})});function sa({projectId:s,addToast:r,experimentalFeatures:l}){const{activeSession:i,sessionsLoading:d,messages:v,messagesLoading:M,isStreaming:T,streamingText:D,streamingThinking:S,streamingToolCalls:Y,selectSession:w,createSession:_,archiveSession:g,deleteSession:ee,sendMessage:R,stopStreaming:U,pendingMessage:b,clearPendingMessage:j,searchQuery:I,setSearchQuery:A,filteredSessions:E}=Fn(s,r),[V,q]=n.useState(!1),z=l?.chatRooms===!0,[h,f]=n.useState(()=>{try{if(localStorage.getItem(Ut)==="rooms"&&z)return"rooms"}catch{}return"direct"}),o=zn(s,r),[c,m]=n.useState(()=>{const e=Cs(h,h==="rooms"?o.activeRoom?.id:i?.id);return ks(e)}),[x,k]=n.useState(null),[Q,O]=n.useState(null),[se,xe]=n.useState(null),[ue,me]=n.useState(!0),[re,$e]=n.useState(Vn),[Te,ae]=n.useState(!1),[oe,he]=n.useState(new Map),[ye,et]=n.useState([]),[gt,tt]=n.useState(!0),[we,Se]=n.useState(!1),[Be,Ne]=n.useState(""),[Ce,ke]=n.useState(0),[je,p]=n.useState(""),[y,C]=n.useState(!1),[P,te]=n.useState(0),[G,Z]=n.useState(-1),[L,X]=n.useState(!1),[F,H]=n.useState([]),[B,J]=n.useState(!1),[ce,fe]=n.useState(!1),[Pe,Kt]=n.useState({}),[st,Le]=n.useState(!1),{pushNav:Wt}=hn(),[,Ke]=n.useState(!1),[Ps,Ls]=n.useState({top:0,left:0}),K=fn({projectId:s}),pt=n.useCallback(e=>{if(!e||!K.mentionActive)return;const a=e.getBoundingClientRect();Ls({top:a.top-260,left:a.left+8})},[K.mentionActive]),Gt=n.useRef(null),Vt=n.useRef(null),bt=n.useRef(!1),vt=n.useRef(null),ge=n.useRef(null),De=n.useRef(null),ne=n.useRef(null),qt=n.useRef(null),Xt=n.useRef([]),We=n.useRef(0),Ge=n.useRef(new Map),$=gn()==="mobile";n.useEffect(()=>{try{const e=localStorage.getItem(Ns);if(!e)return;const a=Number.parseInt(e,10);if(Number.isNaN(a))return;const u=Math.max(dt,Math.min(ut,a));$e(u)}catch{}},[]),n.useEffect(()=>{try{const e=localStorage.getItem(Ut);if(e==="direct"){f("direct");return}e==="rooms"&&z&&f("rooms")}catch{}},[z]),n.useEffect(()=>{if(!z&&h==="rooms"){f("direct");return}try{localStorage.setItem(Ut,h)}catch{}},[z,h]);const ie=Cs(h,h==="rooms"?o.activeRoom?.id:i?.id),xt=n.useRef(ie);n.useEffect(()=>{ie!==xt.current&&(xt.current=ie,m(ks(ie)))},[ie]),n.useEffect(()=>{if(!(!ie||xt.current!==ie))try{if(c){localStorage.setItem(ie,c);return}localStorage.removeItem(ie)}catch{}},[ie,c]);const pe=z&&h==="rooms"&&!!o.activeRoom,{keyboardOverlap:nt,viewportHeight:Jt,viewportOffsetTop:Yt,keyboardOpen:Ve}=pn({enabled:$&&(!!i||pe)}),Qt=nt>0||Yt>0,Zt=Ve&&Qt?{"--keyboard-overlap":`${nt}px`,"--vv-offset-top":`${Yt}px`,...Jt!==null?{"--vv-height":`${Jt}px`}:{}}:{},es=`chat-thread${Ve&&Qt?" chat-thread--keyboard-active":""}`,le=n.useMemo(()=>{const e=Be.trim().toLowerCase();return(e?ye.filter(u=>u.name.toLowerCase().includes(e)):ye).slice(0,10)},[ye,Be]),Fe=n.useMemo(()=>Array.from(oe.values()),[oe]),be=n.useMemo(()=>!z||h!=="rooms"||!o.activeRoom?null:{roomId:o.activeRoom.id,roomName:o.activeRoom.name,memberIds:new Set(o.activeRoomMembers.map(e=>e.agentId))},[z,h,o.activeRoom,o.activeRoomMembers]),Ie=n.useMemo(()=>{const e=Fe.filter(N=>bn(N.name,je));if(!be)return e;const a=e.filter(N=>be.memberIds.has(N.id));if(je.trim().length===0)return a;const u=e.filter(N=>!be.memberIds.has(N.id));return[...a,...u]},[Fe,je,be]),yt=n.useMemo(()=>{const e=new Map;for(const a of Fe)e.set(a.name.toLowerCase(),a);return e},[Fe]);n.useEffect(()=>{ke(0)},[le]),n.useEffect(()=>{te(0)},[je,y]),n.useEffect(()=>()=>{ge.current!==null&&window.clearTimeout(ge.current)},[]);const ts=n.useCallback(()=>{const e=De.current;if(!e)return;const u=e.scrollTop+e.clientHeight>=e.scrollHeight-50;fe(!u),bt.current=!u},[]),_e=n.useCallback(e=>{if(!e.isConnected)return;let a=0,u=0,N=-1;const W=6,de=()=>{if(e.isConnected){if(e.scrollTop=e.scrollHeight,e.scrollHeight===N?u+=1:(u=0,N=e.scrollHeight),a+=1,a>=W||u>=2){fe(!1),bt.current=!1;return}window.requestAnimationFrame(de)}};de()},[]),qe=n.useCallback(()=>{const e=De.current;e&&_e(e)},[_e]);n.useLayoutEffect(()=>{const e=pe?o.activeRoom?.id??null:i?.id??null;if(!e){vt.current=null;return}const a={threadId:e,loaded:pe?!o.messagesLoading:!M,hasMessages:pe?o.messages.length>0:v.length>0},u=vt.current,N=u?.threadId!==e,W=u?.threadId===e&&!u.loaded&&a.loaded,de=u?.threadId===e&&!u.hasMessages&&a.hasMessages;if(!(u===null||N||W||de))return;const ve=De.current;ve&&(_e(ve),vt.current=a)},[pe,o.activeRoom?.id,o.messages.length,o.messagesLoading,i?.id,v.length,M,_e]);const Fs=pe?o.messages:v;n.useEffect(()=>{bt.current||qe()},[Fs,D,S,T,qe]),n.useEffect(()=>{nt<=0||!De.current||qe()},[nt,qe]),vn($&&Ve),n.useEffect(()=>{const e=()=>k(null);if(x)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[x]),n.useEffect(()=>{if(!$||!Ve)return;const e=a=>{a.target?.closest(".chat-messages")||a.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>{document.removeEventListener("touchmove",e)}},[$,Ve]),n.useEffect(()=>{if(!$||!i)return;const e=()=>{const a=ne.current;a&&document.activeElement===a&&(a.blur(),window.setTimeout(()=>{a.focus({preventScroll:!0})},0))};return document.addEventListener("visibilitychange",e),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("pageshow",e)}},[$,i]),n.useEffect(()=>{if(!$||!i&&!pe)return;const e=()=>{const u=De.current;u&&_e(u)},a=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",a),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("pageshow",e)}},[$,i,pe,_e]),n.useEffect(()=>{let e=!1;const a=s;return ft(void 0,s).then(u=>{if(e||a!==s)return;const N=new Map;for(const W of u)N.set(W.id,W);he(N)}).catch(()=>{}),()=>{e=!0}},[s]),n.useEffect(()=>{let e=!1;return tt(!0),xn(s).then(a=>{e||et(a)}).catch(()=>{e||et([])}).finally(()=>{e||tt(!1)}),()=>{e=!0}},[s]),n.useEffect(()=>{Xt.current=F},[F]),n.useEffect(()=>()=>{for(const e of Xt.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);for(const e of Ge.current.values())window.clearTimeout(e);Ge.current.clear()},[]);const at=n.useCallback(e=>{if(!e||e.length===0)return;const a=[];for(const u of Array.from(e)){if(!Xn.includes(u.type))continue;const N=u.type.startsWith("image/");a.push({file:u,previewUrl:N?URL.createObjectURL(u):""})}a.length>0&&H(u=>[...u,...a])},[]),_s=n.useCallback(e=>{H(a=>{const u=a[e];return u?.previewUrl&&URL.revokeObjectURL(u.previewUrl),a.filter((N,W)=>W!==e)})},[]),zs=n.useCallback(e=>{const a=e.clipboardData?.files;if(!a||a.length===0)return;const u=Array.from(a).filter(N=>N.type.startsWith("image/"));u.length!==0&&at(u)},[at]),Us=n.useCallback(async e=>{try{await _(e),q(!1),$&&me(!1)}catch{r("Failed to create chat session","error")}},[_,r,$]),Xe=n.useCallback(()=>{if(m(""),ie)try{localStorage.removeItem(ie)}catch{}Se(!1),Ne(""),C(!1),p(""),Z(-1),H(e=>{for(const a of e)a.previewUrl&&URL.revokeObjectURL(a.previewUrl);return[]})},[ie]),wt=n.useCallback(()=>{const e=c.trim(),a=F.map(u=>u.file);if(!(!e&&a.length===0||!i)){if(e==="/clear"||e==="/new"){Xe(),U(),j(),_({agentId:i.agentId,modelProvider:i.modelProvider??void 0,modelId:i.modelId??void 0}).catch(()=>{r("Failed to clear conversation","error")});return}Xe(),R(e,a)}},[c,F,i,Xe,U,j,_,r,R]),St=n.useCallback(async()=>{const e=c.trim();if(e){if(z&&h==="rooms"){if(!o.activeRoom)return;const a=c;Xe();try{await o.sendRoomMessage(e)}catch(u){m(a);const N=u instanceof Error&&u.message.trim()?u.message:"Failed to send room message";r(N,"error")}return}wt()}},[c,z,h,o,Xe,r,wt]),Nt=n.useCallback(e=>{m(a=>{const u=js(a);if(!u)return a;const N=`/skill:${e.name} `,W=a.slice(0,u.start)+N+a.slice(u.end);return window.requestAnimationFrame(()=>{ne.current&&(ne.current.style.height="auto",ne.current.style.height=`${zt(ne.current.scrollHeight)}px`,ne.current.focus())}),W}),Se(!1),Ne(""),ke(0)},[]),rt=n.useCallback(e=>{const a=ne.current;if(!a||G<0)return;const u=a.selectionStart??We.current,N=a.selectionEnd??u,W=Math.max(u,N),de=Math.min(G,W),ve=`${`@${e.name.replace(/\s+/g,"_")}`} `,$t=c.slice(0,de)+ve+c.slice(W),Ue=de+ve.length;m($t),C(!1),p(""),te(0),Z(-1),window.requestAnimationFrame(()=>{ne.current&&(ne.current.style.height="auto",ne.current.style.height=`${zt(ne.current.scrollHeight)}px`,ne.current.focus(),ne.current.setSelectionRange(Ue,Ue))})},[G,c]),ss=n.useCallback(e=>{if(We.current=e.currentTarget.selectionStart??We.current,K.mentionActive&&K.files.length>0){if(K.handleKeyDown(e,c),e.key==="Enter"||e.key==="Tab"){const a=K.files[K.selectedIndex];if(a){const u=K.selectFile(a,c);m(u),K.dismissMention(),Ke(!1)}}return}if(y&&e.key==="ArrowDown"){e.preventDefault(),Ie.length>0&&te(a=>(a+1)%Ie.length);return}if(y&&e.key==="ArrowUp"){e.preventDefault(),Ie.length>0&&te(a=>a===0?Ie.length-1:a-1);return}if(y&&e.key==="Enter"){e.preventDefault();const a=Ie[P]??Ie[0];a&&rt(a);return}if(y&&e.key==="Escape"){e.preventDefault(),C(!1),p(""),Z(-1);return}if(we&&e.key==="ArrowDown"){e.preventDefault(),le.length>0&&ke(a=>(a+1)%le.length);return}if(we&&e.key==="ArrowUp"){e.preventDefault(),le.length>0&&ke(a=>a===0?le.length-1:a-1);return}if(we&&(e.key==="Enter"||e.key==="Tab")&&le.length>0){e.preventDefault();const a=le[Ce]??le[0];a&&Nt(a);return}if(we&&e.key==="Escape"){e.preventDefault(),Se(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),St())},[y,Ie,P,rt,we,le,Ce,Nt,St,K,c]),it=n.useCallback((e,a)=>{const u=Jn(e,a);if(u){C(!0),p(u.filter),Z(u.start);return}C(!1),p(""),Z(-1)},[]),ns=n.useCallback(e=>{const a=e.target,u=a.value,N=a.selectionStart??u.length;We.current=N,m(u);const W=js(u);W?(Se(!0),Ne(W.filter)):(Se(!1),Ne("")),it(u,N),K.detectMention(u,N),Ke(K.mentionActive),K.mentionActive&&pt(a),a.style.height="auto",a.style.height=`${zt(a.scrollHeight)}px`},[it]),ot=n.useCallback(e=>{const a=e.currentTarget,u=a.selectionStart??a.value.length;We.current=u,it(a.value,u),K.detectMention(a.value,u),Ke(K.mentionActive),K.mentionActive&&pt(a)},[it,K,pt]),as=n.useCallback(e=>{e.key!=="Escape"&&ot(e)},[ot]),rs=n.useCallback(()=>{ge.current!==null&&window.clearTimeout(ge.current),ge.current=window.setTimeout(()=>{Se(!1),C(!1),p(""),Z(-1),Ke(!1),K.dismissMention(),ge.current=null},120)},[K]),is=n.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),typeof window<"u"&&window.innerWidth<=768&&window.setTimeout(()=>{(window.scrollY!==0||window.scrollX!==0)&&window.scrollTo(0,0)},0)},[]),Os=n.useCallback(async e=>{k(null);try{await g(e),r("Conversation archived","success")}catch{r("Failed to archive conversation","error")}},[g,r]),Hs=n.useCallback(async e=>{O(null),k(null);try{await ee(e),r("Conversation deleted","success")}catch{r("Failed to delete conversation","error")}},[ee,r]),Je=n.useCallback(e=>{try{localStorage.setItem(Ns,String(e))}catch{}},[]),Bs=n.useCallback(e=>{if($)return;e.preventDefault(),e.stopPropagation();const a=e.currentTarget;typeof a.setPointerCapture=="function"&&a.setPointerCapture(e.pointerId);const u=e.clientX,N=re;let W=N;document.body.style.userSelect="none";const de=ve=>{const $t=ve.clientX-u,Ue=Math.max(dt,Math.min(ut,N+$t));W=Ue,$e(Ue),Je(Ue)},ze=ve=>{typeof a.releasePointerCapture=="function"&&a.releasePointerCapture(ve.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",de),document.removeEventListener("pointerup",ze),Je(W)};document.addEventListener("pointermove",de),document.addEventListener("pointerup",ze)},[$,Je,re]),Ks=n.useCallback(e=>{if($||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const a=e.shiftKey?50:10,u=e.key==="ArrowLeft"?-a:a,N=Math.max(dt,Math.min(ut,re+u));$e(N),Je(N)},[$,Je,re]),os=n.useCallback(e=>{w(e),Le(!1),$&&me(!1)},[w,$]),Ct=n.useCallback(()=>{w(""),me(!0),Le(!1)},[w]),kt=n.useCallback(()=>{o.selectRoom(null),me(!0),Le(!1)},[o]),Ws=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(Tn,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>q(!0),children:[t.jsx(lt,{size:16}),"New Chat"]})]}),Me=Ss(i?.modelProvider,i?.modelId),Re=i?.modelProvider??null,jt=!!(i||T||v.length>0),ct=h==="rooms"?pe:!!i,cs=n.useRef(ct);n.useEffect(()=>{const e=cs.current;cs.current=ct,$&&(e||!ct||Wt({type:"view",revert:h==="rooms"?kt:Ct}))},[h,Ct,kt,ct,$,Wt]);const Mt=i?.agentId===He?Me??"Fusion":i?.title||oe.get(i?.agentId??"")?.name||i?.agentId||"Chat",ls=!!(Me&&Me!==Mt),Gs=$&&h==="direct"&&!!i,Rt=oe.get(i?.agentId??"")?.name||(i?.agentId===He?Me??"Fusion":i?.agentId?.slice(0,30)??"Fusion"),At=!1,Et=i?.agentId===He,Vs=b.length>50?`${b.slice(0,50)}…`:b,qs=n.useCallback(()=>{X(e=>!e)},[]);n.useEffect(()=>{if(!st)return;const e=a=>{Vt.current?.contains(a.target)||Le(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[st]),n.useEffect(()=>{(!$||h!=="direct"||ue)&&Le(!1)},[$,h,ue]);const Tt=n.useCallback((e,a)=>{const u=Ge.current.get(e);u&&window.clearTimeout(u),Kt(W=>({...W,[e]:a}));const N=window.setTimeout(()=>{Kt(W=>{const{[e]:de,...ze}=W;return ze}),Ge.current.delete(e)},2e3);Ge.current.set(e,N)},[]),ds=n.useCallback(async(e,a)=>{try{if(!navigator.clipboard?.writeText)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(a),Tt(e,"success")}catch{Tt(e,"error")}},[Tt]),Xs=n.useCallback((e,a=!1)=>a?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(Es,{remarkPlugins:[Ts],components:$s,children:e})}),[]),Dt=i?.agentId===He,It=n.useCallback((e,a,u)=>t.jsx("button",{type:"button",className:`btn-icon chat-message-copy-action${Pe[e]==="success"?" chat-message-copy-action--success":""}${Pe[e]==="error"?" chat-message-copy-action--error":""}`,"data-testid":u??`chat-copy-response-${e}`,"aria-label":Pe[e]==="success"?"Response copied":Pe[e]==="error"?"Copy failed":"Copy response",onClick:()=>{ds(e,a)},children:Pe[e]==="success"?t.jsx(yn,{size:14}):t.jsx(wn,{size:14})}),[Pe,ds]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${ue?"":" chat-sidebar--hidden"}`,style:$?void 0:{width:`${re}px`},children:[z&&t.jsxs("div",{className:"chat-sidebar-scope-toggle",role:"tablist","data-testid":"chat-sidebar-scope-toggle",children:[t.jsx("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${h==="direct"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":h==="direct","data-testid":"chat-sidebar-scope-direct",onClick:()=>f("direct"),children:"Direct"}),t.jsx("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${h==="rooms"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":h==="rooms","data-testid":"chat-sidebar-scope-rooms",onClick:()=>f("rooms"),children:"Rooms"})]}),!z||h==="direct"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"chat-sidebar-search-container",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(Sn,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:I,onChange:e=>A(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:d?t.jsx("div",{className:"chat-status-copy chat-status-copy--padded",children:"Loading..."}):E.length===0?t.jsx("div",{className:"chat-status-copy chat-status-copy--padded",children:"No conversations yet"}):E.map(e=>t.jsxs("div",{className:`chat-session-item${i?.id===e.id?" chat-session-item--active":""}`,onClick:()=>os(e.id),onContextMenu:a=>{a.preventDefault(),k({sessionId:e.id,x:a.clientX,y:a.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:a=>{a.stopPropagation(),O(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Lt,{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.jsxs("span",{className:"chat-session-meta-model",children:[e.modelProvider&&t.jsx(Qe,{provider:e.modelProvider,size:"sm"}),t.jsx("span",{children:oe.get(e.agentId)?.name||(e.agentId===He?Ss(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))})]}),t.jsx("span",{children:e.updatedAt?Ds(e.updatedAt):""})]})]},e.id))})]}):t.jsxs("div",{className:"chat-sidebar-rooms","data-testid":"chat-sidebar-rooms",children:[t.jsx("div",{className:"chat-sidebar-rooms-header",children:t.jsxs("button",{type:"button",className:"btn btn-sm btn-primary","data-testid":"chat-create-room-btn",onClick:()=>ae(!0),children:[t.jsx(lt,{size:14}),"Create room"]})}),o.rooms.length===0?t.jsx("div",{className:"chat-sidebar-rooms-empty","data-testid":"chat-sidebar-rooms-empty",children:"No rooms yet."}):t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:o.rooms.map(e=>{const a=o.activeRoom?.id===e.id,u=a?o.activeRoomMembers.length:null;return t.jsxs("div",{role:"button",tabIndex:0,className:`chat-room-item${a?" chat-room-item--active":""}`,"data-testid":`chat-room-item-${e.slug}`,onClick:()=>{o.selectRoom(e.id),$&&me(!1)},onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),o.selectRoom(e.id),$&&me(!1))},children:[t.jsxs("span",{className:"chat-room-item-details",children:[t.jsxs("span",{className:"chat-room-item-name",children:["#",e.name]}),u!==null?t.jsxs("span",{className:"chat-room-item-meta",children:[u," ",u===1?"member":"members"]}):null]}),t.jsx("button",{type:"button",className:"btn-icon chat-room-item-delete","data-testid":`chat-room-delete-${e.slug}`,"aria-label":`Delete room ${e.name}`,onClick:N=>{N.stopPropagation(),xe(e.id)},children:t.jsx(Lt,{size:14})})]},e.id)})})]}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>q(!0),"data-testid":"chat-new-btn",children:[t.jsx(lt,{size:14}),"New Chat"]})})]}),!$&&ue&&t.jsx("div",{className:"chat-sidebar-resize-handle",role:"separator","aria-orientation":"vertical","aria-valuemin":dt,"aria-valuemax":ut,"aria-valuenow":re,"aria-label":"Resize chat sidebar",tabIndex:0,onPointerDown:Bs,onKeyDown:Ks}),x&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:x.y,left:x.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Os(x.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Nn,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{k(null),O(x.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Lt,{size:14}),"Delete"]})]}),Q&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>O(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:()=>O(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Hs(Q),children:"Delete"})]})]})}),z&&se&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>xe(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Room?"}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:"This action cannot be undone. This room and all its messages will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>xe(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>{(async()=>{try{await o.deleteRoom(se),xe(null)}catch{r("Failed to delete room","error")}})()},children:"Delete"})]})]})}),z&&h==="rooms"?t.jsxs("div",{className:es,style:Zt,children:[o.activeRoom?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-room-thread-header",children:[$&&t.jsx("button",{className:"btn-icon",onClick:kt,"data-testid":"chat-back-btn",children:t.jsx(hs,{size:16})}),t.jsxs("div",{className:"chat-thread-header-title",children:["#",o.activeRoom.name]}),t.jsx("div",{className:"chat-room-thread-members",children:o.activeRoomMembers.map(e=>t.jsx(As,{agent:oe.get(e.agentId)??{id:e.agentId,name:e.agentId.slice(0,30)}},e.agentId))})]}),t.jsxs("div",{className:"chat-messages",ref:De,onScroll:ts,children:[o.messagesLoading?t.jsx("div",{className:"chat-status-copy",children:"Loading messages..."}):o.messages.length===0?t.jsx("div",{className:"chat-status-copy",children:"No messages yet. Start the conversation!"}):o.messages.map(e=>{const a=e.senderAgentId?oe.get(e.senderAgentId)?.name??e.senderAgentId.slice(0,30):"You",u={id:e.id,sessionId:e.roomId,role:e.role,content:e.content,thinkingOutput:e.thinkingOutput??void 0,toolCalls:void 0,fallbackInfo:void 0,attachments:e.attachments,createdAt:e.createdAt};return t.jsx(Ot,{message:u,forcePlain:L,agentName:a,hideAssistantIdentity:!1,showAssistantModelTag:!1,activeModelTag:null,activeModelProvider:null,activeSessionId:o.activeRoom?.id??null,mentionAgentsByName:yt,roomContext:be},e.id)}),t.jsx("div",{ref:Gt})]})]}):t.jsx("div",{className:"chat-room-empty-pane","data-testid":"chat-rooms-empty-pane",children:"Select a room or create one"}),o.activeRoom&&t.jsx("div",{className:"chat-input-area",children:t.jsxs("div",{className:"chat-input-row",children:[t.jsxs("div",{className:"chat-input-wrapper",children:[t.jsx("textarea",{ref:ne,className:"chat-input-textarea",placeholder:"Type a message...",value:c,onChange:ns,onKeyDown:ss,onKeyUp:as,onClick:ot,onBlur:rs,onFocus:is,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(fs,{agents:Fe,filter:je,highlightedIndex:P,visible:y,onSelect:rt,position:"below",roomMemberIds:be?.memberIds,roomName:be?.roomName})]}),t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{e.pointerType&&e.pointerType!=="mouse"&&e.preventDefault()},onMouseDown:e=>{e.preventDefault()},onClick:()=>{St()},disabled:!c.trim(),"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(gs,{size:16})})]})})]}):t.jsxs("div",{className:es,style:Zt,children:[(jt||!$)&&t.jsxs("div",{className:"chat-thread-header",children:[$&&jt&&t.jsx("button",{className:"btn-icon",onClick:Ct,"data-testid":"chat-back-btn",children:t.jsx(hs,{size:16})}),t.jsx("div",{className:"chat-thread-header-identity","data-testid":"chat-thread-header-identity",children:Gs?t.jsxs("div",{className:"chat-mobile-session-menu",ref:Vt,children:[t.jsxs("button",{type:"button",className:"btn chat-mobile-session-trigger","data-testid":"chat-mobile-session-trigger","aria-haspopup":"menu","aria-expanded":st,onClick:()=>Le(e=>!e),children:[Re?t.jsx(Qe,{provider:Re,size:"md"}):t.jsx(Ze,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Mt}),ls&&t.jsx("span",{className:"chat-model-tag",children:Me}),t.jsx(ps,{size:16,"aria-hidden":"true"})]}),st&&t.jsx("div",{className:"chat-mobile-session-dropdown",role:"menu","data-testid":"chat-mobile-session-dropdown",children:E.map(e=>t.jsx("button",{type:"button",role:"menuitem",className:`chat-mobile-session-option${i?.id===e.id?" chat-mobile-session-option--active":""}`,"data-testid":`chat-mobile-session-option-${e.id}`,onClick:()=>os(e.id),children:t.jsx("span",{className:"chat-mobile-session-option-title",children:e.title||"Untitled"})},e.id))})]}):t.jsxs(t.Fragment,{children:[Re?t.jsx(Qe,{provider:Re,size:"md"}):t.jsx(Ze,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Mt}),ls&&t.jsx("span",{className:"chat-model-tag",children:Me})]})}),jt&&t.jsx("button",{type:"button",className:`chat-thread-header-render-toggle${L?" chat-thread-header-render-toggle--plain":""}`,"data-testid":"chat-thread-render-toggle","aria-label":L?"Show all messages as rendered Markdown":"Show all messages as plain text",onClick:qs,children:L?t.jsx(Cn,{size:14}):t.jsx(kn,{size:14})}),!$&&t.jsxs("button",{className:"btn btn-sm btn-primary chat-thread-header-new-chat",onClick:()=>q(!0),"data-testid":"chat-thread-new-chat-btn",children:[t.jsx(lt,{size:14}),"New Chat"]})]}),t.jsxs("div",{className:"chat-messages",ref:De,onScroll:ts,children:[T?t.jsxs(t.Fragment,{children:[v.map(e=>t.jsx(Ot,{message:e,forcePlain:L,agentName:Rt,hideAssistantIdentity:Et,showAssistantModelTag:At,activeModelTag:Me,activeModelProvider:Re,activeSessionId:i?.id??null,mentionAgentsByName:yt,roomContext:null,copyAction:Dt&&e.role==="assistant"?It(e.id,e.content):void 0},e.id)),t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[!Et&&t.jsxs("div",{className:"chat-message-avatar",children:[Re?t.jsx(Qe,{provider:Re,size:"sm"}):t.jsx(Ze,{size:14}),t.jsx("span",{children:Rt}),At]}),D?Xs(D,L):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:S?"Thinking…":"Connecting…"}),Dt&&D&&It("__streaming__",D,"chat-copy-response-streaming"),Is(Y),S&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:ht(S)})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}):M?t.jsx("div",{className:"chat-status-copy",children:"Loading messages..."}):v.length===0&&!i?Ws():v.length===0&&i?t.jsx("div",{className:"chat-status-copy",children:"No messages yet. Start the conversation!"}):t.jsx(t.Fragment,{children:v.map(e=>t.jsx(Ot,{message:e,forcePlain:L,agentName:Rt,hideAssistantIdentity:Et,showAssistantModelTag:At,activeModelTag:Me,activeModelProvider:Re,activeSessionId:i?.id??null,mentionAgentsByName:yt,roomContext:null,copyAction:Dt&&e.role==="assistant"?It(e.id,e.content):void 0},e.id))}),t.jsx("div",{ref:Gt})]}),ce&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:qe,children:[t.jsx(ps,{size:14}),"Latest"]}),i&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:qt,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{at(e.target.files),e.target.value=""}}),we&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:gt?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):le.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:Be?"No skills found":"No skills available"}):le.map((e,a)=>t.jsxs("button",{type:"button",role:"option","aria-selected":a===Ce,className:`chat-skill-menu-item${a===Ce?" chat-skill-menu-item--highlighted":""}`,onMouseDown:u=>u.preventDefault(),onMouseEnter:()=>ke(a),onClick:()=>Nt(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))}),F.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:F.map((e,a)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${a}`,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:()=>_s(a),"data-testid":`chat-attachment-remove-${a}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${a}`))}),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:()=>qt.current?.click(),children:t.jsx(jn,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${B?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),J(!0)},onDragLeave:()=>J(!1),onDrop:e=>{e.preventDefault(),J(!1),at(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:ne,className:"chat-input-textarea",placeholder:"Type a message...",value:c,onChange:ns,onKeyDown:ss,onKeyUp:as,onClick:ot,onBlur:rs,onFocus:is,onPaste:zs,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(fs,{agents:Fe,filter:je,highlightedIndex:P,visible:y,onSelect:rt,position:"below",roomMemberIds:be?.memberIds,roomName:be?.roomName}),t.jsx(Mn,{visible:K.mentionActive&&!y,position:Ps,files:K.files,selectedIndex:K.selectedIndex,onSelect:e=>{const a=K.selectFile(e,c);m(a),K.dismissMention(),Ke(!1),ne.current?.focus()},loading:K.loading}),b&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${Vs}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:j,children:"×"})]})]}),T?t.jsx("button",{className:"chat-input-stop",onClick:U,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(Rn,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{e.pointerType&&e.pointerType!=="mouse"&&e.preventDefault()},onMouseDown:e=>{e.preventDefault()},onClick:()=>{wt()},disabled:!c.trim()&&F.length===0,"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(gs,{size:16})})]})]})]}),z&&t.jsx(On,{isOpen:Te,onClose:()=>ae(!1),projectId:s,existingRoomNames:o.rooms.map(e=>e.name),onCreate:async e=>{await o.createRoom({name:e.name,memberAgentIds:e.memberAgentIds}),h!=="rooms"&&f("rooms"),ae(!1),$&&me(!1)}}),V&&t.jsx(Yn,{projectId:s,onClose:()=>q(!1),onCreate:Us})]})}export{sa as ChatView,zt as clampChatInputHeight};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{bU as De,bV as de,bW as Ze,bX as ue,s as Ue,bY as be,bZ as we,b_ as xe,b$ as ye,c0 as et,c1 as ae,c2 as tt,c3 as rt,c4 as st,c5 as nt,c6 as at,c7 as ie,L as ee,S as it,M as lt,c8 as ct,by as ot,a as dt,c9 as Me,T as Ae,ca as ut,U as vt,aS as mt,aT as ft,a9 as pt,at as ht,R as gt}from"./index-DiewofJh.js";import"./vendor-xterm-DzcZoU0P.js";const ve=500,bt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Te(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Te([...e,i])}function G(e){try{return JSON.parse(e)}catch{return null}}function Q(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function wt(e){return e?.previewUrl??null}async function Se(e){return tt(e)}async function Ne(e,i){return rt(e,i)}async function xt(e){return st(e)}async function yt(e){return nt(e)}async function je(e){return at(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>De)=="function"}function X(e){return{config:{id:e.id??"default",name:e.name??"Dev Server",command:e.command??"",cwd:e.cwd??"."},status:e.status,runtime:e.pid?{pid:e.pid,startedAt:e.startedAt??new Date().toISOString(),exitCode:e.exitCode??void 0,previewUrl:e.previewUrl}:void 0,previewUrl:e.previewUrl??e.detectedUrl??e.manualUrl??void 0,logHistory:(e.logs??[]).map(i=>({timestamp:new Date().toISOString(),stream:i.startsWith("[stderr]")?"stderr":"stdout",text:i.replace(/^\[stderr\]\s*/,"")}))}}function St(e){const[i,o]=r.useState(null),[g,y]=r.useState([]),[w,f]=r.useState([]),[k,U]=r.useState([]),[C,T]=r.useState(!0),[S,u]=r.useState(null),n=r.useRef(0),[d,M]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Q);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await De(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(M(s[0].config.id),R(s[0]))}else{const s=await Se(e);if(n.current!==a)return;const c=X(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),U([]),T(!0),u(null),M(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Se(e).then(N=>[X(N)]),typeof V(()=>ae)=="function"?ae(e):je(e).then(N=>N.map(b=>({name:b.name,command:b.command,cwd:b.cwd,scriptName:b.scriptName,packagePath:b.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const N=c.value;if(y(N),N.length>0){const b=N[0];ce()&&M(b.config.id),R(b)}}else v=B(c.reason);l.status==="fulfilled"&&U(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&T(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?Ze(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=G(l.data);if(v?.lines){const N=v.lines.map(Q);f(Te(N))}},log:l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:Q(v);f(b=>le(b,N))}},"dev-server:log":l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:Q(v);f(b=>le(b,N))}},"dev-server:output":l=>{if(n.current!==s)return;const v=G(l.data);v?.line&&f(N=>le(N,v.line))},status:l=>{if(n.current!==s)return;const v=G(l.data),N=v?.status;N&&o(b=>b&&{...b,status:N,runtime:v.pid?{...b.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:b.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=G(l.data);if(v?.status){const N=X(v);o(N),y([N])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},bt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>be)=="function")l=await be(d,e);else{const v=await Ne({command:a,cwd:s},e);l=X(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await xt(e);s=X(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),j=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>xe)=="function")s=await xe(d,e);else{const c=await yt(e);s=X(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),P=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>ye)=="function")c=await ye(d,a,e);else{const l=await et({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await je(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;U(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e]),p=r.useCallback(async(a,s)=>{if(typeof a!="string"&&!d)try{const v=a,N=await Ne({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),b=X(N);o(b),y([b]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await j()},[j]),z=r.useCallback(async a=>{await P(a)},[P]),F=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=wt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:g,logs:w,detectedCommands:k,previewUrl:H,isLoading:C,error:S,startServer:_,stopServer:D,restartServer:j,setPreviewUrl:P,detectCommands:h,refresh:A,candidates:k,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:F,refreshStatus:O}}const ke=500,Ce=100;function Pe(e){return e.length>ke?e.slice(-ke):e}function ze(e){return e==="stderr"?"stderr":"stdout"}function K(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:ze(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function Nt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],g=new Set(e.map(y=>y.id));for(const y of i)g.has(y.id)||(g.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),Pe(o)}function jt(e,i){const[o,g]=r.useState([]),[y,w]=r.useState(!1),[f,k]=r.useState(!1),[U,C]=r.useState(!1),[T,S]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),M=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,g([]),w(!1),k(!1),C(!1),S(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++M.current;n.current=!1,w(!0);const z=(x,a)=>{const s=Pe(x);g(s),S(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},F=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>Nt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:ze(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),g(v=>oe(v,[l])),S(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||M.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||M.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&M.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=K(a);s&&O(s)},log:a=>{const s=K(a);s&&O(s)},history:a=>{const s=K(a);F(s)},"dev-server:history":a=>{const s=K(a);F(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}g(c=>oe(c,s)),S(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const P=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;k(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const F=z.lines.map((O,H)=>Z(O,H+1));g(O=>oe(F,O)),C(z.totalLines>L+F.length),S(z.totalLines)}catch{}finally{k(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{g([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:U,total:T,loadMore:P,clear:h,logs:o,isStreaming:p,clearLogs:h}}const kt="This preview appears to block iframe embedding. Open it in a new tab instead.",Ct="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Et="Preview is taking longer than expected and may block iframe embedding.";function Lt(e){return e==="blocked"?kt:e==="error"?Ct:null}function Rt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:g=null}=i,y=r.useRef(null),w=r.useRef(null),[f,k]=r.useState("unknown"),[U,C]=r.useState(null),[T]=r.useState(g),S=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(j=>{k(j),C(Lt(j))},[]),n=r.useCallback(()=>{k("blocked"),C(Et)},[]);r.useEffect(()=>{if(S(),!e){k("unknown"),C(null);return}k("unknown"),C(null);let j=!1;return queueMicrotask(()=>{j||(k("loading"),C(null))}),()=>{j=!0,S()}},[S,e]),r.useEffect(()=>{if(f!=="loading"){S();return}const j=setTimeout(()=>{w.current=null,n()},o);return w.current=j,()=>{clearTimeout(j),w.current===j&&(w.current=null)}},[S,f,o,n]);const d=r.useCallback(()=>{const j=y.current;if(!j){u("embedded");return}try{if(j.contentWindow?.location?.href==="about:blank"&&j.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),M=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(S(),!e){k("unknown"),C(null);return}k("unknown"),C(null)},[S]);const R=r.useCallback(()=>{S(),k("unknown"),C(null)},[S]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:U,detectionMethod:T,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:U,handleIframeLoad:d,handleIframeError:M}}const _t=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(_t,"")}function Dt(e){if(!e)return"";const i=new Date(e);return Number.isNaN(i.getTime())?"":i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}function Ut(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Mt(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function At(e,i){if(!i)return e;const o=new RegExp(`(${Ut(i)})`,"ig"),g=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:g.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function Tt({entries:e,loading:i,loadingMore:o,hasMore:g,total:y,onLoadMore:w,isRunning:f}){const k=r.useRef(null),U=r.useRef(e.length),C=r.useRef(f),[T,S]=r.useState(!1),[u,n]=r.useState(!1),[d,M]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Mt(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),j=D.length,P=r.useCallback(()=>{const p=k.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=U.current,L=e.length>E;f&&(!p||!u&&L)&&P(),C.current=f,U.current=e.length},[e.length,f,u,P]);const h=r.useCallback(()=>{const p=k.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&P()},[e,f,u,i,P]),i&&e.length===0?t.jsx("section",{className:"devserver-log-viewer","data-testid":"devserver-log-viewer",children:t.jsxs("div",{className:"devserver-log-viewer__loading","data-testid":"devserver-log-loading",children:[t.jsx(ee,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${T?" devserver-log-viewer--fullscreen":""}`,"data-testid":"devserver-log-viewer",children:[t.jsxs("header",{className:"devserver-log-viewer__toolbar",children:[t.jsxs("div",{className:"devserver-log-viewer__toolbar-meta",children:[t.jsx("span",{className:"devserver-log-viewer__title",children:"Logs"}),t.jsxs("span",{className:"devserver-log-viewer__count","data-testid":"devserver-log-count",children:[y!==null?`${e.length}/${y}`:`${e.length}`," lines"]})]}),t.jsxs("div",{className:"devserver-log-viewer__toolbar-actions",children:[t.jsxs("label",{className:"devserver-log-viewer__severity",htmlFor:"devserver-log-severity-filter",children:[t.jsx("span",{className:"visually-hidden",children:"Filter logs by severity"}),t.jsxs("select",{id:"devserver-log-severity-filter",className:"select devserver-log-viewer__severity-select",value:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(it,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>M(p.target.value),placeholder:"Search logs","data-testid":"devserver-log-search-input","aria-label":"Search logs"})]}),d.trim().length>0&&t.jsxs("span",{className:"devserver-log-viewer__matches","data-testid":"devserver-log-match-count",children:[j," match",j===1?"":"es"]}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",onClick:()=>S(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":T?"Exit fullscreen logs":"Enter fullscreen logs",children:T?t.jsx(lt,{size:14}):t.jsx(ct,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[g&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:k,className:"devserver-log-viewer__content",onScroll:h,"data-testid":"devserver-log-content",children:[!i&&D.length===0&&t.jsx("p",{className:"devserver-log-viewer__empty","data-testid":"devserver-log-empty",children:e.length===0?"No logs yet. Start the dev server to see output.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=Dt(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:ot(At(E,d.trim()))})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:P,"data-testid":"devserver-log-jump-button",children:[t.jsx(dt,{size:14}),"New logs"]})]})]})}const Pt="devserver-preview-iframe";function zt({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:g,blockReason:y,onRetry:w,className:f=Pt,embedContext:k}){const U=y??k??null,[C,T]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(T(d=>d+1),o("loading"))},[i,o,e]);const S=r.useCallback(()=>{const d=g.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[g,o]),u=r.useCallback(d=>{d.stopPropagation(),o("error")},[o]),n=r.useCallback(()=>{e&&window.open(e,"_blank","noopener,noreferrer")},[e]);return e?t.jsxs("div",{className:"devserver-preview-iframe-shell",children:[t.jsx("iframe",{src:e,ref:g,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:S,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(Me,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Preview cannot be embedded"}),U&&t.jsx("p",{className:"devserver-preview-blocked-context",children:U})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),U&&t.jsx("p",{className:"devserver-preview-blocked-context",children:U})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function $e(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?$e(e.cwd)===o:!0}function $t(e){return e.cwd==="."?"root":e.cwd}function Ft(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Vt({addToast:e,projectId:i}){const{session:o,detectedCommands:g,previewUrl:y,isLoading:w,error:f,startServer:k,stopServer:U,restartServer:C,setPreviewUrl:T,detectCommands:S,refresh:u}=St(i),n=o?.status??"stopped",d=n==="running"||n==="starting",M=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:j,loadMore:P}=jt(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,F]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),N=l==="embedded"?h:null,{embedStatus:b,setEmbedStatus:Fe,resetEmbedStatus:I,iframeRef:q,isEmbedded:Oe,isBlocked:te,blockReason:re,retry:fe}=Rt(N),[pe,W]=r.useState(!1),he=r.useRef(b);r.useEffect(()=>{const m=he.current!==b;te&&m&&W(!0),b==="embedded"&&W(!1),he.current=b},[b,te]),r.useEffect(()=>{W(!1)},[h]);const J=r.useMemo(()=>{if(!x)return null;const m=Re(p);return g.find($=>!($.scriptName!==x||m&&$.cwd!==m||o?.config?.command&&$.command!==o.config.command))??g.find($=>_e($,x,p))??null},[g,o?.config?.command,x,p]);r.useEffect(()=>{typeof S=="function"&&S().catch(m=>{e(Le(m),"error")})},[e,S]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&F(o.config.command);return}if(J){F(J.command);return}g.length>0&&F(m=>m.trim().length>0?m:g[0]?.command??"")},[g,J,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),ge=r.useCallback(()=>{W(!1),fe()},[fe]),Be=r.useCallback(()=>{try{const m=q.current;if(m?.contentWindow){m.contentWindow.location.reload(),W(!1),I();return}}catch{}if(!(!h||!q.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),q.current.src=m.toString(),W(!1),I()}catch{q.current.src=h,W(!1),I()}},[h,q,I]),Y=r.useCallback(async(m,$,ne)=>{c(m);try{await $(),e(ne,"success")}catch(Ke){e(Le(Ke),"error")}finally{c(null)}},[e]),He=r.useCallback(m=>{a(m.scriptName),L(!1),F(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),Ve=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const $=Re(p)??".",ne=J?.cwd??$;Y("start",()=>k(m,ne),"Dev server started.")},Xe=()=>{Y("stop",U,"Dev server stopped.")},qe=()=>{Y("restart",C,"Dev server restarted.")},Ge=()=>{const m=O.trim(),$=m.length>0?m:null;Y("preview",()=>T($),$?"Preview URL updated.":"Preview URL override cleared.")},Ie=r.useCallback(()=>{f&&u()},[f,u]),Je=n==="starting"||n==="running"||s!==null,Ye=n==="stopped"||s!==null,Qe=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(ut,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${M.className}`,"data-testid":"dev-server-status-badge",children:M.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:We,disabled:Je,"data-testid":"dev-server-start-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Xe,disabled:Ye,"data-testid":"dev-server-stop-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:qe,disabled:Qe,"data-testid":"dev-server-restart-button",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&g.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Ie,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ve,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&g.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&g.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:g.map(m=>{const $=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${$?"dev-server-candidate--selected":""}`,onClick:()=>He(m),"data-testid":`dev-server-candidate-${m.scriptName}-${$e(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:Ft(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:$t(m)})]},`${m.cwd}::${m.scriptName}::${m.command}`)})})]}),t.jsxs("div",{className:"dev-server-field-group",children:[t.jsx("label",{htmlFor:"dev-server-command",className:"dev-server-label",children:"Command"}),t.jsx("input",{id:"dev-server-command",className:"input",value:z,onChange:m=>F(m.target.value),placeholder:"pnpm dev","data-testid":"dev-server-command-input",readOnly:n==="running"||n==="starting"})]}),(n==="running"||n==="starting")&&o&&t.jsxs("div",{className:"dev-server-current-command","data-testid":"dev-server-current-command",children:[t.jsx("span",{className:"dev-server-label",children:"Running command"}),t.jsx("code",{children:o.config?.command??z})]}),t.jsxs("div",{className:"dev-server-preview-override",children:[t.jsx("label",{htmlFor:"dev-server-preview-input",className:"dev-server-label",children:"Preview URL Override"}),t.jsx("input",{id:"dev-server-preview-input",className:"input",type:"url",value:O,onChange:m=>H(m.target.value),placeholder:"http://localhost:3000","data-testid":"dev-server-preview-input"}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ge,disabled:s==="preview","data-testid":"dev-server-set-preview",children:"Save"})]}),h&&t.jsxs("p",{className:"dev-server-preview-hint",children:["Auto-detected: ",h]})]}),t.jsx("div",{className:"dev-server-content",children:t.jsxs("section",{className:"dev-server-panel dev-server-logs-panel","data-testid":"dev-server-logs-panel","aria-label":"Dev server logs",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Logs"}),t.jsxs("span",{className:"dev-server-muted",children:[j??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(Tt,{entries:R,loading:A,loadingMore:_,hasMore:D,total:j,onLoadMore:P,isRunning:d})})]})}),t.jsxs("section",{className:"dev-server-panel devserver-preview-panel","data-testid":"devserver-preview-panel","aria-label":"Dev server preview",children:[t.jsxs("div",{className:"devserver-preview-header",children:[t.jsxs("div",{className:"devserver-preview-title",children:[t.jsx(pt,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(ht,{})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:Be,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(gt,{})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":b,"data-embedded":Oe?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:b==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[b==="error"?t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Me,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:b==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:ge,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx(zt,{url:h,embedStatus:b,onEmbedStatusChange:Fe,iframeRef:q,blockReason:re,onRetry:ge})]})]})]})}export{Vt as DevServerView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{
|
|
1
|
+
import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{ew as f,ex as g,dg as b,b as y,ad as P,a8 as H,a9 as C,L as O,aq as v}from"./index-DiewofJh.js";import{F as z}from"./folder-open-DU-Ec_iC.js";function D({value:o,onChange:d,placeholder:m,onInputKeyDown:x,nodeId:l,localNodeId:h}){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,l,h);n(u=>({...u,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(u=>({...u,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[l,h]),j=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(o||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,o,e.showHidden,a,l,h]);const p=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),k=i.useCallback(()=>{d(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,d]),w=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 N=e.currentPath?g(e.currentPath):[];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:o,onChange:s=>d(s.target.value),onKeyDown:x,placeholder:m||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:j,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(z,{size:16}):r.jsx(b,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsx("div",{className:"directory-picker-breadcrumbs",children:N.map((s,c)=>r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[c>0&&r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>p(s.path),title:s.path,children:s.label})]},s.path))}),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:()=>p(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(P,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:w,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(H,{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(O,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(v,{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:()=>p(s.path),role:"treeitem",title:s.path,children:[r.jsx(b,{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:k,children:"Select"})]})]})]})}export{D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a5 as oe,a6 as K,f as le,a7 as ie,F as z,a8 as de,a9 as ue,S as me,X as he,R as pe,aa as fe,ab as W,ac as V,a as X,b as je,ad as xe}from"./index-bEwSVl7B.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?K(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await K(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function _(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:_(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:J,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:Y,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?Y:J,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,G=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:G,value:l,onChange:Z,"aria-label":G}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",_(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
|
|
1
|
+
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a5 as oe,a6 as K,f as le,a7 as ie,F as z,a8 as de,a9 as ue,S as me,X as he,R as pe,aa as fe,ab as W,ac as V,a as X,b as je,ad as xe}from"./index-DiewofJh.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?K(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await K(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function _(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:_(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:J,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:Y,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?Y:J,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,G=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:G,value:l,onChange:Z,"aria-label":G}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",_(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{aG as z,aH as F,aI as O,x as U,ap as _,R as D,at as V}from"./index-
|
|
1
|
+
import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{aG as z,aH as F,aI as O,x as U,ap as _,R as D,at as V}from"./index-DiewofJh.js";import"./vendor-xterm-DzcZoU0P.js";const $=300,P=15e3;function T(a){if(!a.trim())return;const t=Number(a);return Number.isFinite(t)?t:void 0}function j(...a){for(const t of a)if(Array.isArray(t))return t;return[]}function v(a){return typeof a=="object"&&a!==null?a:{}}function q(a){const t=v(a),r=v(t.taskSnapshot);return{id:String(t.id??t.evalId??""),runId:String(t.runId??t.batchId??""),taskId:String(t.taskId??r.taskId??""),taskTitle:String(r.title??t.taskTitle??t.title??"Untitled task"),createdAt:String(t.createdAt??t.timestamp??t.updatedAt??new Date(0).toISOString()),overallScore:typeof t.overallScore=="number"?t.overallScore:null,maxScore:typeof t.maxScore=="number"?t.maxScore:null,categoryScores:j(t.categoryScores,v(t.scores).categories)}}function B(a){const t=v(a);return{...q(t),rationale:String(t.rationale??t.summary??""),evidence:j(t.evidence,v(t.details).evidence),followUps:j(t.followUps,v(t.recommendations).followUps)}}function G(a){const t=a?.projectId,[r,g]=l.useState({q:"",runId:"",scoreMin:"",scoreMax:""}),[S,h]=l.useState([]),[I,p]=l.useState([]),[i,f]=l.useState(null),[k,c]=l.useState(null),[E,w]=l.useState(0),[N,b]=l.useState(!0),[R,s]=l.useState(null),n=l.useRef(0),d=l.useCallback(async()=>{const u=++n.current;b(!0),s(null);try{const[o,y]=await Promise.all([z({q:r.q||void 0,runId:r.runId||void 0,scoreMin:T(r.scoreMin),scoreMax:T(r.scoreMax),limit:100,offset:0},t),F(t)]);if(u!==n.current)return;const M=j(o.results,o.evals,o.items).map(q);p(M),w(typeof o.count=="number"?o.count:M.length);const L=j(y.runs,y.items);h(L.map(C=>{const x=v(C),A=v(x.counts);return{id:String(x.id??""),createdAt:String(x.createdAt??""),completedAt:typeof x.completedAt=="string"?x.completedAt:void 0,status:String(x.status??"pending"),evaluatedTaskCount:typeof A.totalTasks=="number"?A.totalTasks:0}})),i&&!M.some(C=>C.id===i)&&(f(null),c(null))}catch(o){if(u!==n.current)return;s(o instanceof Error?o.message:"Failed to load evals")}finally{u===n.current&&b(!1)}},[r.q,r.runId,r.scoreMax,r.scoreMin,t,i]),m=l.useCallback(async u=>{const o=await O(u,t),y=o.result??o;c(B(y))},[t]);return l.useEffect(()=>{const u=window.setTimeout(()=>{d()},$);return()=>window.clearTimeout(u)},[d]),l.useEffect(()=>{if(!i){c(null);return}m(i)},[m,i]),l.useEffect(()=>{const u=window.setInterval(()=>{d(),i&&m(i)},P);return()=>window.clearInterval(u)},[m,d,i]),{loading:N,error:R,results:I,count:E,runs:S,filters:r,setFilters:g,refresh:d,selectedEvalId:i,setSelectedEvalId:f,selectedEval:k}}function W({projectId:a,onOpenSettings:t,onOpenTaskDetail:r}){const{loading:g,error:S,results:h,runs:I,filters:p,setFilters:i,selectedEvalId:f,setSelectedEvalId:k,selectedEval:c,refresh:E}=G({projectId:a}),[w,N]=l.useState(!0);l.useEffect(()=>{let s=!1;return U(a).then(n=>{if(s)return;const d=n.evalSettings?.enabled;N(d??!1)}).catch(()=>{s||N(!1)}),()=>{s=!0}},[a]);const b=h.length>0,R=l.useMemo(()=>h.find(s=>s.id===f)??null,[h,f]);return w?e.jsxs("section",{className:"evals-view","data-testid":"evals-view",children:[e.jsxs("div",{className:"evals-list card",children:[e.jsxs("div",{className:"evals-toolbar",children:[e.jsx("input",{className:"input",placeholder:"Search task or rationale",value:p.q,onChange:s=>i(n=>({...n,q:s.target.value}))}),e.jsxs("select",{className:"select",value:p.runId,onChange:s=>i(n=>({...n,runId:s.target.value})),children:[e.jsx("option",{value:"",children:"All runs"}),I.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}),e.jsx("input",{className:"input",placeholder:"Min score",value:p.scoreMin,onChange:s=>i(n=>({...n,scoreMin:s.target.value}))}),e.jsx("input",{className:"input",placeholder:"Max score",value:p.scoreMax,onChange:s=>i(n=>({...n,scoreMax:s.target.value}))}),e.jsx("button",{className:"btn btn-icon",type:"button",onClick:()=>void E(),"aria-label":"Refresh evals",children:e.jsx(D,{size:16})})]}),g&&e.jsx("p",{className:"evals-state","data-testid":"evals-loading",children:"Loading evals…"}),S&&e.jsx("p",{className:"evals-state evals-state--error",children:S}),!g&&!S&&!b&&e.jsx("p",{className:"evals-state",children:"No evals yet. Scheduled evals review tasks completed since the last run."}),e.jsx("ul",{className:"evals-results","data-testid":"evals-results",children:h.map(s=>e.jsx("li",{children:e.jsxs("button",{className:`evals-result ${s.id===f?"evals-result--active":""}`,type:"button",onClick:()=>k(s.id),children:[e.jsx("span",{className:"evals-result-title",children:s.taskTitle}),e.jsxs("span",{className:"evals-result-meta",children:[s.taskId," · ",s.runId," · ",s.overallScore??"n/a"]})]})},s.id))})]}),e.jsxs("div",{className:"evals-detail card","data-testid":"evals-detail",children:[!c&&e.jsx("p",{className:"evals-state",children:"Select an evaluation to inspect scores, rationale, and evidence."}),c&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"evals-detail-title",children:R?.taskTitle??c.taskTitle}),e.jsxs("p",{className:"evals-result-meta",children:[c.taskId," · ",c.runId]}),e.jsxs("p",{className:"evals-score",children:["Overall score: ",c.overallScore??"n/a"]}),e.jsx("ul",{className:"evals-categories",children:c.categoryScores.map(s=>e.jsxs("li",{children:[s.category,": ",s.finalScore]},s.category))}),e.jsx("p",{className:"evals-rationale",children:c.rationale||"No rationale recorded."}),e.jsxs("div",{children:[e.jsx("h4",{children:"Evidence"}),e.jsx("ul",{className:"evals-links",children:c.evidence.map((s,n)=>{const d=typeof s.metadata?.taskId=="string"?s.metadata.taskId:void 0,m=typeof s.metadata?.url=="string"?s.metadata.url:void 0;return e.jsx("li",{children:d?e.jsx("button",{type:"button",className:"btn",onClick:()=>r?.(d),children:s.ref}):m?e.jsxs("a",{href:m,target:"_blank",rel:"noreferrer",className:"evals-external-link",children:[s.ref,e.jsx(V,{size:14})]}):e.jsx("span",{children:s.ref})},`${s.ref}-${n}`)})})]}),e.jsxs("div",{children:[e.jsx("h4",{children:"Suggested follow-up tasks"}),e.jsxs("ul",{className:"evals-follow-ups",children:[c.followUps.length===0&&e.jsx("li",{children:"None"}),c.followUps.map(s=>e.jsxs("li",{children:[e.jsx("strong",{children:s.title}),e.jsx("p",{children:s.rationale})]},s.suggestionId))]})]})]})]})]}):e.jsxs("section",{className:"evals-view card","data-testid":"evals-disabled",children:[e.jsx("h2",{className:"evals-title",children:"Scheduled evals are disabled"}),e.jsx("p",{className:"evals-empty-copy",children:"Enable Scheduled Evals to review scored tasks, evidence, and follow-up recommendations."}),e.jsxs("button",{className:"btn btn-primary",type:"button",onClick:()=>t?.("scheduled-evals"),children:[e.jsx(_,{size:16}),"Open Scheduled Evals Settings"]})]})}export{W as EvalsView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{
|
|
1
|
+
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{bq as L,eg as F,eh as H,ei as V,ej as U,ek as K}from"./index-DiewofJh.js";function fe({value:o,onChange:u,projectId:h,disabled:m=!1,id:g,label:w="Skills"}){const[k,l]=s.useState([]),[c,f]=s.useState(!0);s.useEffect(()=>{let n=!1;return f(!0),L(h).then(p=>{n||l(p)}).catch(()=>{n||l([])}).finally(()=>{n||f(!1)}),()=>{n=!0}},[h]);const j=n=>{o.includes(n)||u([...o,n])},d=n=>{u(o.filter(p=>p!==n))},I=n=>k.find(S=>S.id===n)?.name??n,x=k.filter(n=>!o.includes(n.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[w&&e.jsx("label",{htmlFor:g?`${g}-select`:void 0,className:"skill-multiselect-label",children:w}),o.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:o.map(n=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${n}`,children:[e.jsx("span",{className:"skill-chip-name",children:I(n)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>d(n),disabled:m,"aria-label":`Remove ${I(n)}`,"data-testid":`remove-skill-${n}`,children:"×"})]},n))}),e.jsx("div",{className:"skill-multiselect-add",children:c?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):x.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:o.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:g?`${g}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:n=>{n.target.value&&(j(n.target.value),n.target.value="")},disabled:m,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),x.map(n=>e.jsx("option",{value:n.id,children:n.name},n.id))]})})]})}const B=/(?:^|\/)skills\/([^/]+)\/SKILL\.md$/i;function ye(o){const u=o.trim();if(!u)return o;const h=u.match(B);return h?.[1]?h[1]:u}const Q=`# Soul: Chief Executive Officer
|
|
2
2
|
|
|
3
3
|
I am a strategic leader who connects every decision to business outcomes.
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as ye,ae as $e,af as De,ag as Le,ah as Pe,ai as Ue,aj as Te,ak as _e,al as de,am as Ge,h as Oe,j as ue,an as w,X as ge,ao as ne,R as j,ap as qe,m as Be,C as pe,aq as X,ar as me,as as He,I as be,at as Ve,au as we,av as Ye}from"./index-
|
|
1
|
+
import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as ye,ae as $e,af as De,ag as Le,ah as Pe,ai as Ue,aj as Te,ak as _e,al as de,am as Ge,h as Oe,j as ue,an as w,X as ge,ao as ne,R as j,ap as qe,m as Be,C as pe,aq as X,ar as me,as as He,I as be,at as Ve,au as we,av as Ye}from"./index-DiewofJh.js";import{U as ve}from"./users-3Qw_TMah.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 Le}from"./SettingsModal-
|
|
1
|
+
import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Le}from"./SettingsModal-CT01a5Rh.js";import{bF as Ee,bG as Me,bH as Ie,y as Re,bI as qe,bJ as Pe,bK as _e,bL as ke,bM as we,bN as We,bO as Oe,bP as Te,bQ as Ae,bR as $e,x as Ue,bS as He,L as w,bT as Fe}from"./index-DiewofJh.js";import"./vendor-xterm-DzcZoU0P.js";const O=".fusion/memory/MEMORY.md",Qe=5e4,Ye="0 3 * * *",Be="0 4 * * *";function he(i){return{memoryEnabled:i.memoryEnabled!==!1,memoryAutoSummarizeEnabled:i.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:i.memoryAutoSummarizeThresholdChars??Qe,memoryAutoSummarizeSchedule:i.memoryAutoSummarizeSchedule??Ye,memoryDreamsEnabled:i.memoryDreamsEnabled??!1,memoryDreamsSchedule:i.memoryDreamsSchedule??Be}}function De(i,t){return i.some(m=>m.path===t)?t:i.find(m=>m.path===O)?.path??i[0]?.path??O}function Ge(i={}){const{projectId:t}=i,[m,u]=a.useState(""),[C,A]=a.useState(!0),[E,M]=a.useState(!1),[b,x]=a.useState(!1),[r,p]=a.useState(null),[T,J]=a.useState(!0),[X,L]=a.useState(!1),[S,_]=a.useState(()=>he({})),[F,ee]=a.useState(!0),[ue,$]=a.useState(!1),[o,v]=a.useState([]),[se,I]=a.useState(!0),[c,k]=a.useState(O),[W,y]=a.useState(""),[d,te]=a.useState(!1),[U,f]=a.useState(!1),[ae,H]=a.useState(!1),[ne,Q]=a.useState(!1),[Y,re]=a.useState(!1),[D,z]=a.useState(null),[ye,R]=a.useState(!0),[ge,B]=a.useState(!1),[ie,G]=a.useState(!1),[le,V]=a.useState(null),{status:me,loading:K,refresh:j}=Le({projectId:t}),be=a.useCallback(n=>{y(n),f(!0)},[]),N=a.useCallback(async n=>{te(!0);try{const{content:l}=await Ee(n,t);k(n),y(l),f(!1)}finally{te(!1)}},[t]),q=a.useCallback(async()=>{I(!0);try{const{files:n}=await Me(t);if(v(n),n.length===0){k(O),y(""),f(!1);return}const l=De(n,c);l!==c&&await N(l)}finally{I(!1)}},[t,c,N]);a.useEffect(()=>{let n=!1;async function l(){try{const s=await $e(t);n||(u(s.content),A(!1))}catch{n||(u(""),A(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await we(t);n||(p(s.content),L(s.exists),J(!1))}catch{n||(p(null),L(!1),J(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){ee(!0);try{const s=await Ue(t);n||_(he(s))}catch{n||_(he({}))}finally{n||ee(!1)}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){I(!0);try{const{files:s}=await Me(t);if(n)return;if(v(s),s.length===0){k(O),y(""),f(!1);return}const h=De(s,c),{content:g}=await Ee(h,t);if(n)return;k(h),y(g),f(!1)}catch{n||(v([]),k(O),y(""),f(!1))}finally{n||I(!1)}}return l(),()=>{n=!0}},[t,c]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await ke(t);n||(z(s),R(!1))}catch{n||(z(null),R(!1))}}return l(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function l(){try{const s=await He(t);n||V(s)}catch{n||V(null)}}return l(),()=>{n=!0}},[t]);const ce=a.useCallback(n=>{u(n),M(!0)},[]),oe=a.useCallback(async()=>{if(E){x(!0);try{await Ie(m,t),M(!1)}finally{x(!1)}}},[m,E,t]),xe=a.useCallback(async n=>{$(!0);try{const l=await Re(n,t);_(he(l))}finally{$(!1)}},[t]),pe=a.useCallback(async n=>{await N(n)},[N]),fe=a.useCallback(async()=>{if(U){H(!0);try{await qe(c,W,t),f(!1),await q()}finally{H(!1)}}},[W,U,c,t,q]),je=a.useCallback(async()=>{G(!0);try{const n=await Pe(t);return await j(),n}finally{G(!1)}},[t,j]),Se=a.useCallback(async n=>_e(n,t),[t]),Z=a.useCallback(async()=>{try{const n=await ke(t);z(n)}catch{z(null)}},[t]),P=a.useCallback(async()=>{try{const n=await we(t);p(n.content),L(n.exists)}catch{p(null),L(!1)}},[t]),de=a.useCallback(async n=>{await We(n,t),await P()},[t,P]),ve=a.useCallback(async()=>{Q(!0);try{const n=await Oe(t);return await Promise.all([P(),Z()]),{success:n.success,summary:n.summary}}finally{Q(!1)}},[t,P,Z]),Ne=a.useCallback(async()=>{re(!0);try{return await Te(t)}finally{re(!1)}},[t]),Ce=a.useCallback(async n=>{B(!0);try{const l=n?await Ae(n,t):await Ae(t);if(n){const s=l.path??n;k(s),y(l.content),f(!1),await q();return}u(l.content),M(!0)}finally{B(!1)}},[t,q]);return{workingMemory:m,workingMemoryLoading:C,workingMemoryDirty:E,setWorkingMemory:ce,saveWorkingMemory:oe,savingWorkingMemory:b,insightsContent:r,insightsLoading:T,insightsExists:X,refreshInsights:P,saveInsights:de,memorySettings:S,settingsLoading:F,savingMemorySettings:ue,saveMemorySettings:xe,memoryFiles:o,memoryFilesLoading:se,selectedFilePath:c,selectedFileContent:W,selectedFileLoading:d,selectedFileDirty:U,setSelectedFileContent:be,selectFile:pe,saveSelectedFile:fe,savingSelectedFile:ae,reloadMemoryFiles:q,backendStatus:me,backendLoading:K,extractInsights:ve,extracting:ne,triggerDreamNow:Ne,dreamRunning:Y,auditReport:D,auditLoading:ye,refreshAudit:Z,compactMemory:Ce,compacting:ge,installQmdAction:je,installingQmd:ie,testRetrieval:Se,stats:le}}const Ve={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},Ke={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Ze={"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."},Je=72;function Xe(i,t){if(i.length<=t)return i;const m=Math.max(1,t-1),u=Math.ceil(m/2),C=Math.floor(m/2);return`${i.slice(0,u)}…${i.slice(i.length-C)}`}function es(i){const t=`${i.label} — ${i.path}`;return Xe(t,Je)}function ss(i){if(!i)return[];const t=[],m=i.split(/(?=^## )/m);for(const u of m){const C=u.trim();if(!C)continue;const A=C.match(/^##\s+(.+?)(\n|$)/);if(A){const E=A[1].trim(),M=Ve[E]??E.toLowerCase(),b=C.slice(A[0].length).trim(),x=b.split(`
|
|
2
2
|
`).map(r=>r.replace(/^-\s+/,"").trim()).filter(r=>r.length>0&&(r.startsWith("- ")||r.startsWith("* ")));(x.length>0||b.length>0)&&t.push({name:E,key:M,items:x.length>0?x:b.length>0?[b]:[],expanded:!0})}}return t}function ts(i){if(!i)return null;const t=i.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function as(i){return i.reduce((t,m)=>t+m.items.length,0)}function ns(i){switch(i){case"file":return"File (.fusion/memory/, agent/<agent-name>/memory/)";case"readonly":return"Read-Only";case"qmd":return"QMD (Quantized Memory Distillation)";default:return i}}function rs(i){switch(i){case"healthy":return"Healthy";case"warning":return"Warning";case"issues":return"Issues Found"}}function os({projectId:i,addToast:t}){const[m,u]=a.useState("working"),[C,A]=a.useState(new Set),[E,M]=a.useState(!1),[b,x]=a.useState(null),[r,p]=a.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[T,J]=a.useState(""),[X,L]=a.useState(!1),[S,_]=a.useState(null),{insightsContent:F,insightsLoading:ee,insightsExists:ue,saveInsights:$,memorySettings:o,settingsLoading:v,saveMemorySettings:se,savingMemorySettings:I,backendStatus:c,backendLoading:k,extractInsights:W,extracting:y,auditReport:d,auditLoading:te,refreshAudit:U,compactMemory:f,compacting:ae,installQmdAction:H,installingQmd:ne,testRetrieval:Q,memoryFiles:Y,memoryFilesLoading:re,selectedFilePath:D,selectedFileContent:z,selectedFileLoading:ye,selectedFileDirty:R,setSelectedFileContent:ge,selectFile:B,saveSelectedFile:ie,savingSelectedFile:G,reloadMemoryFiles:le,triggerDreamNow:V,dreamRunning:me}=Ge({projectId:i});a.useEffect(()=>{p(o)},[o]);const K=a.useMemo(()=>r.memoryEnabled!==o.memoryEnabled||r.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled||r.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars||r.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule||r.memoryDreamsEnabled!==o.memoryDreamsEnabled||r.memoryDreamsSchedule!==o.memoryDreamsSchedule,[r,o]),j=a.useMemo(()=>Y.find(s=>s.path===D),[Y,D]),be=j?Ze[j.layer]:"Edits the selected memory file.",N=a.useMemo(()=>ss(F),[F]),q=a.useMemo(()=>as(N),[N]),ce=a.useMemo(()=>ts(F),[F]),oe=a.useCallback(s=>{A(h=>{const g=new Set(h);return g.has(s)?g.delete(s):g.add(s),g})},[]),xe=a.useCallback(async s=>{try{await B(s)}catch{t("Failed to load memory file","error")}},[B,t]),pe=a.useCallback(async()=>{try{await ie(),t("Memory saved","success")}catch{t("Failed to save memory","error")}},[ie,t]),fe=a.useCallback(async()=>{if(!K)return;const s={};r.memoryEnabled!==o.memoryEnabled&&(s.memoryEnabled=r.memoryEnabled),r.memoryAutoSummarizeEnabled!==o.memoryAutoSummarizeEnabled&&(s.memoryAutoSummarizeEnabled=r.memoryAutoSummarizeEnabled),r.memoryAutoSummarizeThresholdChars!==o.memoryAutoSummarizeThresholdChars&&(s.memoryAutoSummarizeThresholdChars=r.memoryAutoSummarizeThresholdChars),r.memoryAutoSummarizeSchedule!==o.memoryAutoSummarizeSchedule&&(s.memoryAutoSummarizeSchedule=r.memoryAutoSummarizeSchedule),r.memoryDreamsEnabled!==o.memoryDreamsEnabled&&(s.memoryDreamsEnabled=r.memoryDreamsEnabled),r.memoryDreamsSchedule!==o.memoryDreamsSchedule&&(s.memoryDreamsSchedule=r.memoryDreamsSchedule);try{await se(s),t("Memory settings saved","success")}catch{t("Failed to save memory settings","error")}},[K,r,o,se,t]),je=a.useCallback(async()=>{try{const s=await H();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")}},[H,t]),Se=a.useCallback(async()=>{L(!0),_(null);try{const s=await Q(T);_(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{L(!1)}},[T,Q,t]),Z=a.useCallback(async()=>{try{await V(),t("Dream processing completed","success"),await le()}catch(s){t(s instanceof Error?s.message:"Failed to run dream processing","error")}},[V,le,t]),P=a.useCallback(async()=>{try{await f(D),t("Memory file compacted","success")}catch{t("Failed to compact memory","error")}},[f,D,t]),de=a.useCallback(async()=>{try{const s=await W();t(s.summary,"success")}catch(s){t(s instanceof Error?s.message:"Failed to extract insights","error")}},[W,t]),ve=a.useCallback(async()=>{if(b!==null)try{await $(b),M(!1),x(null),t("Insights saved","success")}catch{t("Failed to save insights","error")}},[b,$,t]),Ne=a.useCallback(()=>{x(F??""),M(!0)},[F]),Ce=a.useCallback(()=>{M(!1),x(null)},[]),n=!k&&c!==null,l=c?.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":m==="working",className:`memory-view-tab${m==="working"?" memory-view-tab--active":""}`,onClick:()=>u("working"),"data-testid":"memory-tab-working",children:"Working Memory"}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="insights",className:`memory-view-tab${m==="insights"?" memory-view-tab--active":""}`,onClick:()=>u("insights"),"data-testid":"memory-tab-insights",children:"Insights"}),e.jsx("button",{type:"button",role:"tab","aria-selected":m==="engines",className:`memory-view-tab${m==="engines"?" memory-view-tab--active":""}`,onClick:()=>u("engines"),"data-testid":"memory-tab-engines",children:"Engines"})]}),e.jsxs("div",{className:"memory-view-content",children:[m==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[n&&!l&&e.jsx("div",{className:"memory-readonly-banner",children:"This memory backend is read-only. Changes cannot be saved."}),re||ye?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{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:D,onChange:s=>{xe(s.target.value)},disabled:R,children:Y.map(s=>e.jsx("option",{value:s.path,title:`${s.label} — ${s.path}`,children:es(s)},s.path))}),e.jsx("small",{children:R?"Save or discard the current edits before switching files.":"Choose any project memory file to view or edit."})]}),j&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:Ke[j.layer]}),e.jsx("strong",{children:j.path}),e.jsxs("small",{children:[j.size.toLocaleString()," bytes · updated ",new Date(j.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"form-group memory-editor-form-group",children:[e.jsx("label",{children:j?.label||"Memory Editor"}),e.jsx("small",{children:be}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Fe,{content:z,onChange:ge,readOnly:!l,filePath:D})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsxs("span",{className:"memory-char-count",children:[z.length," characters"]}),e.jsx("div",{className:"memory-flex-spacer"}),l&&z.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:P,disabled:ae||R,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Compacting…"]}):"Compact Selected File"}),R&&l&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:pe,disabled:G,children:G?e.jsxs(e.Fragment,{children:[e.jsx(w,{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:r.memoryDreamsEnabled,onChange:s=>{p(h=>({...h,memoryDreamsEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Process dreams from daily memory"]}),e.jsx("small",{children:"Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md."})]}),r.memoryEnabled&&r.memoryDreamsEnabled&&e.jsxs(e.Fragment,{children:[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:r.memoryDreamsSchedule,onChange:s=>{p(h=>({...h,memoryDreamsSchedule:s.target.value}))},placeholder:"0 4 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for dream processing."})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:Z,disabled:me||!r.memoryDreamsEnabled,children:me?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Dreaming…"]}):"Dream Now"}),e.jsx("small",{children:"Manually trigger dream processing now."})]})]})]}),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:r.memoryAutoSummarizeEnabled,onChange:s=>{p(h=>({...h,memoryAutoSummarizeEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Auto-Summarize Memory"]}),e.jsx("small",{children:"Automatically compact memory when it exceeds the threshold on a schedule"})]}),r.memoryEnabled&&r.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:r.memoryAutoSummarizeThresholdChars,onChange:s=>{p(h=>({...h,memoryAutoSummarizeThresholdChars:parseInt(s.target.value,10)||5e4}))},min:1e3,disabled:v}),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:r.memoryAutoSummarizeSchedule,onChange:s=>{p(h=>({...h,memoryAutoSummarizeSchedule:s.target.value}))},placeholder:"0 3 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for auto-summarize schedule (default: daily at 3 AM)"})]})]})]}),!r.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:fe,disabled:I||v,children:I?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Settings"})})]})]})]}),m==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:ee?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading insights…"})]}):E?e.jsxs("div",{className:"memory-insights-editor-layout",children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Fe,{content:b??"",onChange:x,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:Ce,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ve,children:"Save Insights"})]})]}):!ue||N.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:de,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(w,{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:q}),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:N.length}),e.jsx("div",{className:"memory-stat-label",children:"Categories"})]}),ce&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value memory-stat-value--updated",children:ce}),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:de,disabled:y,children:y?e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ne,children:"Edit Raw"})]}),e.jsx("div",{className:"memory-categories-list",children:N.map(s=>{const h=!C.has(s.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>oe(s.key),role:"button",tabIndex:0,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),oe(s.key))},children:[e.jsx("h4",{children:s.name}),e.jsx("span",{className:"memory-category-count",children:s.items.length})]}),h&&e.jsx("div",{className:"memory-category-items",children:s.items.map((g,ze)=>e.jsx("div",{className:"memory-insight-item",children:g.replace(/^-\s+/,"").replace(/^\*\s+/,"")},ze))})]},s.key)})})]})}),m==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:k||te?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(w,{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"}),c?.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."})]}):c?.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:c.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:je,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:[c?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),c?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),c?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),c?.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:T,onChange:s=>J(s.target.value),placeholder:"Search memory with qmd"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Se,disabled:X,children:X?"Testing…":"Test Retrieval"})]}),e.jsx("small",{className:"settings-muted",children:"Runs the same qmd-backed memory_search path agents use."}),S&&e.jsxs("div",{className:"memory-test-result",children:[e.jsxs("strong",{children:[S.results.length," result",S.results.length===1?"":"s"," ",'for "',S.query,'"']}),e.jsxs("small",{children:["qmd ",S.qmdAvailable?"available":"missing"," · ",S.usedFallback?"local fallback used":"qmd path used"]}),S.results.length>0?e.jsx("ul",{children:S.results.map((s,h)=>e.jsxs("li",{children:[e.jsxs("span",{children:[s.path,":",s.lineStart]}),e.jsx("p",{children:s.snippet})]},`${s.path}-${s.lineStart}-${h}`))}):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:ns(c?.currentBackend??"unknown")})}),e.jsxs("div",{className:"memory-capability-row",children:[c?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),c?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),c?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),c?.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:rs(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:()=>U(),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{os as MemoryView};
|