@runfusion/fusion 0.8.4 → 0.9.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 +6447 -1234
- package/dist/client/assets/{AgentDetailView-C_DD03d6.js → AgentDetailView-Ca1euvPo.js} +1 -1
- package/dist/client/assets/AgentsView-Cq-SEhLc.css +1 -0
- package/dist/client/assets/AgentsView-pile-9ZM.js +522 -0
- package/dist/client/assets/ChatView-C4SCF_Hj.js +1 -0
- package/dist/client/assets/{DevServerView-CNItMoga.js → DevServerView-1HvWligZ.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-BqcVbDZX.js → DirectoryPicker-B1eztZna.js} +1 -1
- package/dist/client/assets/DocumentsView-D4m9s6Ye.js +1 -0
- package/dist/client/assets/{InsightsView-CgguV1au.js → InsightsView-u535o96R.js} +2 -2
- package/dist/client/assets/{MemoryView-BWXP8uGT.js → MemoryView-DEmn8fA2.js} +1 -1
- package/dist/client/assets/{NodesView-DP_O4ae0.js → NodesView-Blg8NHiu.js} +4 -4
- package/dist/client/assets/{PiExtensionsManager-DGEPbF0y.js → PiExtensionsManager-DkXenPK0.js} +3 -3
- package/dist/client/assets/{PluginManager-4TehPpcf.js → PluginManager-Czso7ZUF.js} +1 -1
- package/dist/client/assets/{RoadmapsView-DNaToPqN.js → RoadmapsView-DATopkaE.js} +1 -1
- package/dist/client/assets/SettingsModal-Cs5qO84M.js +31 -0
- package/dist/client/assets/{SettingsModal-C-RjolQ5.js → SettingsModal-D_mcRJO2.js} +1 -1
- package/dist/client/assets/SettingsModal-xVaD-0tP.css +1 -0
- package/dist/client/assets/{SetupWizardModal-BQoo_AvX.js → SetupWizardModal-JBNr-XIW.js} +1 -1
- package/dist/client/assets/{SkillsView-AS8Cr_Md.js → SkillsView-CkT6-elZ.js} +1 -1
- package/dist/client/assets/{TodoView-nWOpOg3R.js → TodoView-CstzLvjw.js} +2 -2
- package/dist/client/assets/{folder-open-D0LfE0ZP.js → folder-open-BEDPztlF.js} +1 -1
- package/dist/client/assets/index-CPStj9Az.css +1 -0
- package/dist/client/assets/index-DZB5f-Bl.js +656 -0
- package/dist/client/assets/{list-checks-D1faMe1o.js → list-checks-DgZgg3rh.js} +1 -1
- package/dist/client/assets/{star-B_uA5YGG.js → star-DXieIAlP.js} +1 -1
- package/dist/client/assets/{upload-DPQ3hWf0.js → upload-Cbvs_TSB.js} +1 -1
- package/dist/client/assets/{users-CEcYlrZO.js → users-DAMIrlue.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/extension.js +5918 -962
- package/dist/pi-claude-cli/package.json +1 -1
- package/package.json +1 -1
- package/dist/client/assets/AgentsView-C2f7esMv.css +0 -1
- package/dist/client/assets/AgentsView-CsEX_Fsi.js +0 -522
- package/dist/client/assets/ChatView-DhudD-jT.js +0 -1
- package/dist/client/assets/DocumentsView-zpHkjZdf.js +0 -1
- package/dist/client/assets/SettingsModal-BluRnKGd.js +0 -31
- package/dist/client/assets/SettingsModal-C7gPLBaR.css +0 -1
- package/dist/client/assets/index-D6xr8Oa2.css +0 -1
- package/dist/client/assets/index-heCcln3Z.js +0 -656
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as s,j as t}from"./vendor-react-K0fH_qHe.js";import{i as Ie,ay as Nt,g as yt,az as jt,a as Tt,aA as At,aB as Pt,aC as Dt,aD as Rt,aE as $t,aF as Et,s as Ft,aG as Lt,aH as _t,aI as It,f as zt,aJ as Ut,a7 as Ot,a8 as Ht,S as Bt,M as Ye,y as Xe,ak as Gt,aK as Vt,B as Ae,a4 as Ze,a5 as et,aL as Kt,aM as qt,aN as Jt,aO as Qt,aP as Wt,aQ as Yt,aR as Xt,h as Zt,u as tt,k as es}from"./index-heCcln3Z.js";import"./vendor-xterm-DzcZoU0P.js";const _e="kb-chat-active-session";function ts(a){const l=a?.toolCalls;if(!Array.isArray(l))return;const r=l.map(c=>{if(!c||typeof c!="object")return null;const o=c,N=typeof o.toolName=="string"?o.toolName:"";if(!N)return null;const T=o.args;return{toolName:N,...T&&typeof T=="object"?{args:T}:{},isError:!!o.isError,result:o.result,status:"completed"}}).filter(c=>c!==null);return r.length>0?r:void 0}function st(a){return{id:a.id,sessionId:a.sessionId,role:a.role,content:a.content,thinkingOutput:a.thinkingOutput,toolCalls:ts(a.metadata),attachments:a.attachments,createdAt:a.createdAt}}function ss(a){const[l,r]=s.useState([]),[c,o]=s.useState(null),[N,T]=s.useState(!0),[F,M]=s.useState([]),[ee,B]=s.useState(!1),[G,I]=s.useState(!1),[ge,L]=s.useState(""),[V,D]=s.useState(""),[Q,A]=s.useState([]),[z,_]=s.useState(""),[te,se]=s.useState(""),[y,U]=s.useState(!0),[u,S]=s.useState(new Map),p=s.useRef(null),j=s.useRef(!1),$=s.useRef(""),be=s.useRef(l),K=s.useRef(c),Me=s.useRef(G);be.current=l,K.current=c,Me.current=G,s.useEffect(()=>{$.current=z},[z]);const ce=s.useRef(new Set),ne=s.useRef(0),Ne=s.useRef(a);Ne.current!==a&&(Ne.current=a,ne.current++),s.useEffect(()=>{const d=ne.current;Ie(void 0,a).then(m=>{if(ne.current!==d)return;const h=new Map;for(const k of m)h.set(k.id,k);S(h)}).catch(()=>{})},[a]);const ae=s.useCallback(async()=>{T(!0);try{const m=[...(await Nt(a)).sessions].sort((h,k)=>new Date(k.updatedAt).getTime()-new Date(h.updatedAt).getTime());r(m)}catch{}finally{T(!1)}},[a]);s.useEffect(()=>{ae()},[ae]);const W=s.useRef(()=>{});s.useEffect(()=>{if(N)return;const d=yt(_e,a);d&&l.find(h=>h.id===d)&&W.current(d)},[N,l,a]);const O=s.useCallback(async(d,m)=>{B(!0);try{const h=await jt(d,{limit:50,...m},a),k=h.messages.map(st);m?.offset&&m.offset>0?M(Y=>[...k,...Y]):M(k),U(h.messages.length>=50)}catch{}finally{B(!1)}},[a]),ie=s.useCallback((d,m)=>{p.current&&(p.current.close(),p.current=null);const h=m??l.find(k=>k.id===d);o(h||null),L(""),D(""),A([]),I(!1),U(!0),d?O(d):M([]),d?Tt(_e,d,a):At(_e,a)},[l,O,a]);W.current=ie;const me=s.useCallback(async d=>{const m=await Pt(d,a);p.current&&(p.current.close(),p.current=null);const h={id:m.session.id,title:m.session.title,agentId:m.session.agentId,status:m.session.status,modelProvider:m.session.modelProvider,modelId:m.session.modelId,createdAt:m.session.createdAt,updatedAt:m.session.updatedAt};return r(k=>[h,...k]),ie(h.id,h),M([]),h},[a,ie]),fe=s.useCallback(async d=>{await Dt(d,{status:"archived"},a),r(m=>m.filter(h=>h.id!==d)),c?.id===d&&(o(null),M([]))},[c,a]),oe=s.useCallback(async d=>{c?.id===d&&p.current&&(p.current.close(),p.current=null),await Rt(d,a),r(m=>m.filter(h=>h.id!==d)),c?.id===d&&(o(null),M([]))},[c,a]),pe=s.useCallback(async()=>{!c||!y||await O(c.id,{offset:F.length})},[c,y,O,F.length]),le=s.useCallback(()=>{c&&(j.current=!0,p.current?.close(),p.current=null,$t(c.id,a).catch(()=>{}),I(!1),L(""),D(""),A([]))},[c,a]),q=s.useCallback(()=>{$.current="",_("")},[]),J=s.useCallback((d,m)=>{if(!c)return;if(G){$.current=d,_(d);return}j.current=!1,p.current&&(p.current.close(),p.current=null);const h=`temp-${Date.now()}`,k={id:h,sessionId:c.id,role:"user",content:d,createdAt:new Date().toISOString()};M(b=>[...b,k]),L(""),D(""),A([]),I(!0);let Y="",E="",P=[];const we={onThinking:b=>{E+=b,D(E)},onText:b=>{Y+=b,L(Y)},onToolStart:b=>{P=[...P,{toolName:b.toolName,args:b.args,isError:!1,status:"running"}],A(P)},onToolEnd:b=>{const f=[...P];for(let v=f.length-1;v>=0;v--){const w=f[v];if(w?.toolName===b.toolName&&w.status==="running"){f[v]={...w,status:"completed",isError:b.isError,result:b.result},P=f,A(f);return}}P=[...f,{toolName:b.toolName,isError:b.isError,result:b.result,status:"completed"}],A(P)},onDone:b=>{const f={id:b.messageId||`msg-${Date.now()}`,sessionId:c.id,role:"assistant",content:Y,thinkingOutput:E,toolCalls:P.length>0?P:void 0,createdAt:new Date().toISOString()};ce.current.add(f.id),M(w=>[...w,f]),L(""),D(""),A([]),I(!1),p.current=null,setTimeout(()=>{ce.current.delete(f.id)},1e3),ae();const v=$.current.trim();v&&($.current="",_(""),J(v))},onError:b=>{if(M(f=>f.filter(v=>v.id!==h)),L(""),D(""),A([]),I(!1),p.current=null,console.error("[useChat] Stream error:",b),!j.current){const f=$.current.trim();f&&($.current="",_(""),J(f))}}};p.current=Et(c.id,d,we,m,a)},[c,G,a,ae]),Se=te?l.filter(d=>d.title?.toLowerCase().includes(te.toLowerCase())||d.agentId.toLowerCase().includes(te.toLowerCase())):l;return s.useEffect(()=>{const d=ne.current,m=a?`?projectId=${encodeURIComponent(a)}`:"",h=()=>ne.current!==d,k=f=>{if(h())return;const v=JSON.parse(f.data);r(w=>w.some(g=>g.id===v.id)?w:[v,...w])},Y=f=>{if(h())return;const v=JSON.parse(f.data);r(w=>[...w.map(re=>re.id===v.id?v:re)]),K.current?.id===v.id&&o(v)},E=f=>{if(h())return;const{id:v}=JSON.parse(f.data);r(w=>w.filter(g=>g.id!==v)),K.current?.id===v&&(o(null),M([]))},P=f=>{if(h())return;const v=JSON.parse(f.data),w=st(v);ce.current.has(w.id)||K.current?.id===w.sessionId&&!Me.current&&M(g=>g.some(re=>re.id===w.id)?g:[...g,w])},we=f=>{if(h())return;const{id:v}=JSON.parse(f.data);M(w=>w.filter(g=>g.id!==v))};return Ft(`/api/events${m}`,{events:{"chat:session:created":k,"chat:session:updated":Y,"chat:session:deleted":E,"chat:message:added":P,"chat:message:deleted":we}})},[a]),s.useEffect(()=>()=>{p.current&&(p.current.close(),p.current=null)},[]),{sessions:l,activeSession:c,sessionsLoading:N,messages:F,messagesLoading:ee,isStreaming:G,streamingText:ge,streamingThinking:V,streamingToolCalls:Q,pendingMessage:z,selectSession:ie,createSession:me,archiveSession:fe,deleteSession:oe,sendMessage:J,stopStreaming:le,clearPendingMessage:q,loadMoreMessages:pe,hasMoreMessages:y,searchQuery:te,setSearchQuery:se,filteredSessions:Se,refreshSessions:ae,agentsMap:u}}function nt(a){const l=new Date(a),c=new Date().getTime()-l.getTime(),o=Math.floor(c/1e3),N=Math.floor(o/60),T=Math.floor(N/60),F=Math.floor(T/24);return o<60?"just now":N<60?`${N}m ago`:T<24?`${T}h ago`:F<7?`${F}d ago`:l.toLocaleDateString()}function at(a,l){if(!a||!l)return null;const r=l.toLowerCase();if(r.includes("claude")){let o=l.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 o=o.replace(/\s+/g," "),o.length>30?o.slice(0,30)+"…":o}if(r.includes("gpt")||r.includes("openai")){const o=l.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 o.length>30?o.slice(0,30)+"…":o}if(r.includes("gemini")){const o=l.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 o.length>30?o.slice(0,30)+"…":o}const c=l.replace(/-/g," ").replace(/^\w/,o=>o.toUpperCase()).replace(/\s+/g," ").trim();return c.length>30?c.slice(0,30)+"…":c}function it(a){return t.jsx(Xt,{toolCalls:a})}const ns={pre:({children:a,...l})=>t.jsx("pre",{...l,className:"chat-markdown-pre",children:a}),table:({children:a,...l})=>t.jsx("table",{...l,className:"chat-markdown-table",children:a})},Pe="__fn_agent__",as=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function lt(a){const l=/(^|[\s])\/([^\s]*)$/.exec(a);if(!l)return null;const r=l[1]??"",c=l[2]??"",o=l.index+r.length;return{filter:c,start:o,end:a.length}}function is(a,l){const r=a.slice(0,l),c=/(^|[\s\n])@([\w-]*)$/.exec(r);if(!c)return null;const o=c[2]??"",N=r.length-o.length-1;return{filter:o,start:N,end:l}}function ls({projectId:a,onClose:l,onCreate:r}){const[c,o]=s.useState("agent"),[N,T]=s.useState([]),[F,M]=s.useState(!0),[ee,B]=s.useState(""),[G,I]=s.useState([]),[ge,L]=s.useState(!0),[V,D]=s.useState(""),[Q,A]=s.useState([]),[z,_]=s.useState([]);s.useEffect(()=>{let u=!1;return M(!0),Ie(void 0,a).then(S=>{u||T(S)}).catch(()=>{u||T([])}).finally(()=>{u||M(!1)}),()=>{u=!0}},[a]),s.useEffect(()=>{L(!0),Zt().then(u=>{I(u.models),A(u.favoriteProviders),_(u.favoriteModels)}).catch(()=>{I([]),A([]),_([])}).finally(()=>{L(!1)})},[]);const te=s.useCallback(async u=>{const S=Q,j=S.includes(u)?S.filter($=>$!==u):[u,...S];A(j);try{await tt({favoriteProviders:j,favoriteModels:z})}catch{A(S)}},[Q,z]),se=s.useCallback(async u=>{const S=z,j=S.includes(u)?S.filter($=>$!==u):[u,...S];_(j);try{await tt({favoriteProviders:Q,favoriteModels:j})}catch{_(S)}},[z,Q]),y=u=>{if(u.preventDefault(),c==="agent"){if(!ee)return;r({agentId:ee});return}if(!V)return;const S=V.indexOf("/");if(S<=0)return;const p=V.slice(0,S),j=V.slice(S+1);r({agentId:Pe,modelProvider:p,modelId:j})},U=c==="agent"?!ee:!V;return t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:l,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog",onClick:u=>u.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${c==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{o("agent"),D("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${c==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{o("model"),B("")},children:"Model"})]}),t.jsxs("form",{onSubmit:y,children:[c==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",F?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):N.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:N.map(u=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${ee===u.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>B(u.id),"data-testid":`agent-option-${u.id}`,children:[t.jsx(Ae,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:u.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:u.role})]},u.id))})]}),c==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:ge?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(es,{models:G,value:V,onChange:D,label:"Model",placeholder:"Select a model",favoriteProviders:Q,onToggleFavorite:te,favoriteModels:z,onToggleModelFavorite:se})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:l,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:U,children:"Create"})]})]})]})})}function us({projectId:a,addToast:l}){const{activeSession:r,sessionsLoading:c,messages:o,messagesLoading:N,isStreaming:T,streamingText:F,streamingThinking:M,streamingToolCalls:ee,selectSession:B,createSession:G,archiveSession:I,deleteSession:ge,sendMessage:L,stopStreaming:V,pendingMessage:D,clearPendingMessage:Q,searchQuery:A,setSearchQuery:z,filteredSessions:_}=ss(a),[te,se]=s.useState(!1),[y,U]=s.useState(""),[u,S]=s.useState(null),[p,j]=s.useState(null),[$,be]=s.useState(!0),[K,Me]=s.useState(new Map),[ce,ne]=s.useState([]),[Ne,ae]=s.useState(!0),[W,O]=s.useState(!1),[ie,me]=s.useState(""),[fe,oe]=s.useState(0),[pe,le]=s.useState(""),[q,J]=s.useState(!1),[Se,d]=s.useState(0),[m,h]=s.useState(-1),[k,Y]=s.useState(()=>new Set),[E,P]=s.useState([]),[we,b]=s.useState(!1),[,f]=s.useState(!1),[v,w]=s.useState({top:0,left:0}),g=Lt({projectId:a}),re=s.useCallback(e=>{if(!e||!g.mentionActive)return;const n=e.getBoundingClientRect();w({top:n.top-260,left:n.left+8})},[g.mentionActive]),ze=s.useRef(null),X=s.useRef(null),Ue=s.useRef(null),R=s.useRef(null),Oe=s.useRef(null),He=s.useRef([]),ke=s.useRef(0),de=_t()==="mobile",{keyboardOverlap:ye,viewportHeight:Be}=It({enabled:de&&!!r}),rt=ye>0?{"--keyboard-overlap":`${ye}px`,...Be!==null?{"--vv-height":`${Be}px`}:{}}:{},H=s.useMemo(()=>{const e=ie.trim().toLowerCase();return(e?ce.filter(i=>i.name.toLowerCase().includes(e)):ce).slice(0,10)},[ce,ie]),xe=s.useMemo(()=>Array.from(K.values()),[K]),ue=s.useMemo(()=>{const e=pe.trim().toLowerCase();return e?xe.filter(n=>n.name.toLowerCase().includes(e)):xe},[xe,pe]),Ge=s.useMemo(()=>{const e=new Map;for(const n of xe)e.set(n.name.toLowerCase(),n);return e},[xe]);s.useEffect(()=>{oe(0)},[H]),s.useEffect(()=>{d(0)},[pe,q]),s.useEffect(()=>()=>{X.current!==null&&window.clearTimeout(X.current)},[]),s.useEffect(()=>{ze.current?.scrollIntoView({behavior:"smooth"})},[o,F]),s.useEffect(()=>{if(ye<=0)return;const e=Ue.current;e&&(e.scrollTop=e.scrollHeight)},[ye]),s.useEffect(()=>{const e=()=>S(null);if(u)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[u]),s.useEffect(()=>{let e=!1;const n=a;return Ie(void 0,a).then(i=>{if(e||n!==a)return;const x=new Map;for(const C of i)x.set(C.id,C);Me(x)}).catch(()=>{}),()=>{e=!0}},[a]),s.useEffect(()=>{let e=!1;return ae(!0),zt(a).then(n=>{e||ne(n)}).catch(()=>{e||ne([])}).finally(()=>{e||ae(!1)}),()=>{e=!0}},[a]),s.useEffect(()=>{He.current=E},[E]),s.useEffect(()=>()=>{for(const e of He.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl)},[]);const je=s.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const i of Array.from(e)){if(!as.includes(i.type))continue;const x=i.type.startsWith("image/");n.push({file:i,previewUrl:x?URL.createObjectURL(i):""})}n.length>0&&P(i=>[...i,...n])},[]),ct=s.useCallback(e=>{P(n=>{const i=n[e];return i?.previewUrl&&URL.revokeObjectURL(i.previewUrl),n.filter((x,C)=>C!==e)})},[]),ot=s.useCallback(e=>{const n=e.clipboardData?.files;if(!n||n.length===0)return;const i=Array.from(n).filter(x=>x.type.startsWith("image/"));i.length!==0&&je(i)},[je]),dt=s.useCallback(async e=>{try{await G(e),se(!1),de&&be(!1)}catch{l("Failed to create chat session","error")}},[G,l,de]),De=s.useCallback(()=>{const e=y.trim(),n=E.map(i=>i.file);!e&&n.length===0||!r||(U(""),O(!1),me(""),J(!1),le(""),h(-1),L(e,n),P(i=>{for(const x of i)x.previewUrl&&URL.revokeObjectURL(x.previewUrl);return[]}))},[y,E,r,L]),Re=s.useCallback(e=>{U(n=>{const i=lt(n);if(!i)return n;const x=`/skill:${e.name} `,C=n.slice(0,i.start)+x+n.slice(i.end);return window.requestAnimationFrame(()=>{R.current&&(R.current.style.height="auto",R.current.style.height=`${Math.min(R.current.scrollHeight,120)}px`,R.current.focus())}),C}),O(!1),me(""),oe(0)},[]),$e=s.useCallback(e=>{const n=R.current;if(!n||m<0)return;const i=n.selectionStart??ke.current,x=n.selectionEnd??i,C=Math.max(i,x),Ce=Math.min(m,C),he=`${`@${e.name.replace(/\s+/g,"_")}`} `,Le=y.slice(0,Ce)+he+y.slice(C),ve=Ce+he.length;U(Le),J(!1),le(""),d(0),h(-1),window.requestAnimationFrame(()=>{R.current&&(R.current.style.height="auto",R.current.style.height=`${Math.min(R.current.scrollHeight,120)}px`,R.current.focus(),R.current.setSelectionRange(ve,ve))})},[m,y]),ut=s.useCallback(e=>{const n=/@([\w-]+)/g,i=[];let x=0,C=n.exec(e);for(;C;){const[Ce,We=""]=C,he=C.index;he>x&&i.push(e.slice(x,he));const Le=We.replace(/_/g," ").toLowerCase(),ve=Ge.get(Le);ve?i.push(t.jsxs("span",{className:"chat-mention-chip",children:["@",ve.name.replace(/\s+/g,"_")]},`${ve.id}-${he}`)):i.push(Ce),x=he+Ce.length,C=n.exec(e)}return x<e.length&&i.push(e.slice(x)),i.length===0?e:i},[Ge]),Ve=s.useCallback(e=>r?`/api/chat/sessions/${encodeURIComponent(r.id)}/attachments/${encodeURIComponent(e)}`:"",[r]),ht=s.useCallback(e=>!e||e.length===0?null:t.jsx("div",{className:"chat-message-attachments",children:e.map(n=>{const i=n.mimeType.startsWith("image/"),x=n.id||n.filename,C=Ve(n.filename);return i?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:C,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:C,alt:n.originalName})},x):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:C,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(Ut,{size:14}),t.jsx("span",{children:n.originalName})]},x)})}),[Ve]),gt=s.useCallback(e=>{if(ke.current=e.currentTarget.selectionStart??ke.current,g.mentionActive&&g.files.length>0){if(g.handleKeyDown(e,y),e.key==="Enter"||e.key==="Tab"){const n=g.files[g.selectedIndex];if(n){const i=g.selectFile(n,y);U(i),g.dismissMention(),f(!1)}}return}if(q&&e.key==="ArrowDown"){e.preventDefault(),ue.length>0&&d(n=>(n+1)%ue.length);return}if(q&&e.key==="ArrowUp"){e.preventDefault(),ue.length>0&&d(n=>n===0?ue.length-1:n-1);return}if(q&&e.key==="Enter"){e.preventDefault();const n=ue[Se]??ue[0];n&&$e(n);return}if(q&&e.key==="Escape"){e.preventDefault(),J(!1),le(""),h(-1);return}if(W&&e.key==="ArrowDown"){e.preventDefault(),H.length>0&&oe(n=>(n+1)%H.length);return}if(W&&e.key==="ArrowUp"){e.preventDefault(),H.length>0&&oe(n=>n===0?H.length-1:n-1);return}if(W&&(e.key==="Enter"||e.key==="Tab")&&H.length>0){e.preventDefault();const n=H[fe]??H[0];n&&Re(n);return}if(W&&e.key==="Escape"){e.preventDefault(),O(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),De())},[q,ue,Se,$e,W,H,fe,Re,De,g,y]),Te=s.useCallback((e,n)=>{const i=is(e,n);if(i){J(!0),le(i.filter),h(i.start);return}J(!1),le(""),h(-1)},[]),mt=s.useCallback(e=>{const n=e.target,i=n.value,x=n.selectionStart??i.length;ke.current=x,U(i);const C=lt(i);C?(O(!0),me(C.filter)):(O(!1),me("")),Te(i,x),g.detectMention(i,x),f(g.mentionActive),g.mentionActive&&re(n),n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight,120)}px`},[Te]),Ee=s.useCallback(e=>{const n=e.currentTarget,i=n.selectionStart??n.value.length;ke.current=i,Te(n.value,i),g.detectMention(n.value,i),f(g.mentionActive),g.mentionActive&&re(n)},[Te,g,re]),ft=s.useCallback(e=>{e.key!=="Escape"&&Ee(e)},[Ee]),pt=s.useCallback(()=>{X.current!==null&&window.clearTimeout(X.current),X.current=window.setTimeout(()=>{O(!1),J(!1),le(""),h(-1),f(!1),g.dismissMention(),X.current=null},120)},[g]),xt=s.useCallback(()=>{X.current!==null&&(window.clearTimeout(X.current),X.current=null)},[]),vt=s.useCallback(async e=>{S(null);try{await I(e),l("Conversation archived","success")}catch{l("Failed to archive conversation","error")}},[I,l]),bt=s.useCallback(async e=>{j(null),S(null);try{await ge(e),l("Conversation deleted","success")}catch{l("Failed to delete conversation","error")}},[ge,l]),St=s.useCallback(e=>{B(e),de&&be(!1)},[B,de]),wt=s.useCallback(()=>{B(""),be(!0)},[B]),kt=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(Yt,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>se(!0),children:[t.jsx(Xe,{size:16}),"New Chat"]})]}),Z=at(r?.modelProvider,r?.modelId),Ke=r?.agentId===Pe?Z??"Fusion":r?.title||K.get(r?.agentId??"")?.name||r?.agentId||"Chat",Ct=!!(Z&&Z!==Ke),Fe=K.get(r?.agentId??"")?.name||(r?.agentId===Pe?Z??"Fusion":r?.agentId?.slice(0,30)??"Fusion"),qe=!!(Z&&Z!==Fe),Mt=D.length>50?`${D.slice(0,50)}…`:D,Je=s.useCallback(e=>{Y(n=>{const i=new Set(n);return i.has(e)?i.delete(e):i.add(e),i})},[]),Qe=s.useCallback((e,n=!1)=>n?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:e}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(Ot,{remarkPlugins:[Ht],components:ns,children:e})}),[]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${$?"":" chat-sidebar--hidden"}`,children:[t.jsx("div",{className:"chat-sidebar-search",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(Bt,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:A,onChange:e=>z(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:c?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):_.length===0?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):_.map(e=>t.jsxs("div",{className:`chat-session-item${r?.id===e.id?" chat-session-item--active":""}`,onClick:()=>St(e.id),onContextMenu:n=>{n.preventDefault(),S({sessionId:e.id,x:n.clientX,y:n.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:n=>{n.stopPropagation(),j(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Ye,{size:14})}),t.jsx("div",{className:"chat-session-title",children:e.title||"Untitled"}),t.jsx("div",{className:"chat-session-preview",children:e.lastMessagePreview||"No messages"}),t.jsxs("div",{className:"chat-session-meta",children:[t.jsx("span",{children:K.get(e.agentId)?.name||(e.agentId===Pe?at(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))}),t.jsx("span",{children:e.updatedAt?nt(e.updatedAt):""})]})]},e.id))}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>se(!0),"data-testid":"chat-new-btn",children:[t.jsx(Xe,{size:14}),"New Chat"]})})]}),u&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:u.y,left:u.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>vt(u.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Gt,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{S(null),j(u.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Ye,{size:14}),"Delete"]})]}),p&&t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>j(null),children:t.jsxs("div",{className:"chat-new-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>j(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void bt(p),children:"Delete"})]})]})}),t.jsxs("div",{className:"chat-thread",style:rt,children:[(r||!de)&&t.jsxs("div",{className:"chat-thread-header",children:[de&&r&&t.jsx("button",{className:"btn-icon",onClick:wt,"data-testid":"chat-back-btn",children:t.jsx(Vt,{size:16})}),t.jsx(Ae,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Ke}),Ct&&t.jsx("span",{className:"chat-model-tag",children:Z})]}),t.jsxs("div",{className:"chat-messages",ref:Ue,children:[N?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):o.length===0&&!r?kt():o.length===0&&r?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):t.jsxs(t.Fragment,{children:[o.map(e=>{const n=e.role==="assistant",i=k.has(e.id);return t.jsxs("div",{className:`chat-message chat-message--${e.role}`,"data-testid":`chat-message-${e.id}`,children:[n&&t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Ae,{size:14}),t.jsx("span",{children:Fe}),qe&&t.jsx("span",{className:"chat-model-tag",children:Z}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${i?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":i?"Show rendered markdown":"Show plain text",onClick:()=>Je(e.id),children:i?t.jsx(Ze,{size:14}):t.jsx(et,{size:14})})]}),n?Qe(e.content,i):t.jsx("div",{className:"chat-message-content",children:ut(e.content)}),it(e.toolCalls),e.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:e.thinkingOutput})]}),ht(e.attachments),t.jsx("div",{className:"chat-message-time",children:nt(e.createdAt)})]},e.id)}),T&&t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Ae,{size:14}),t.jsx("span",{children:Fe}),qe&&t.jsx("span",{className:"chat-model-tag",children:Z}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${k.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":k.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Je("__streaming__"),children:k.has("__streaming__")?t.jsx(Ze,{size:14}):t.jsx(et,{size:14})})]}),F?Qe(F,k.has("__streaming__")):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:M?"Thinking…":"Connecting…"}),it(ee),M&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:M})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}),t.jsx("div",{ref:ze})]}),r&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Oe,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{je(e.target.files),e.target.value=""}}),W&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:Ne?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):H.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:ie?"No skills found":"No skills available"}):H.map((e,n)=>t.jsxs("button",{type:"button",role:"option","aria-selected":n===fe,className:`chat-skill-menu-item${n===fe?" chat-skill-menu-item--highlighted":""}`,onMouseDown:i=>i.preventDefault(),onMouseEnter:()=>oe(n),onClick:()=>Re(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))}),E.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:E.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>ct(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":"Attach files",onClick:()=>Oe.current?.click(),children:t.jsx(Kt,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${we?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:e=>{e.preventDefault(),b(!1),je(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:R,className:"chat-input-textarea",placeholder:"Type a message...",value:y,onChange:mt,onKeyDown:gt,onKeyUp:ft,onClick:Ee,onBlur:pt,onFocus:xt,onPaste:ot,rows:1,"data-testid":"chat-input"}),t.jsx(qt,{agents:xe,filter:pe,highlightedIndex:Se,visible:q,onSelect:$e,position:"below"}),t.jsx(Jt,{visible:g.mentionActive&&!q,position:v,files:g.files,selectedIndex:g.selectedIndex,onSelect:e=>{const n=g.selectFile(e,y);U(n),g.dismissMention(),f(!1),R.current?.focus()},loading:g.loading}),D&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${Mt}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:Q,children:"×"})]})]}),T?t.jsx("button",{className:"chat-input-stop",onClick:V,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(Qt,{size:14})}):t.jsx("button",{className:"chat-input-send",onClick:()=>void De(),disabled:!y.trim()&&E.length===0,"data-testid":"chat-send-btn",children:t.jsx(Wt,{size:16})})]})]})]}),te&&t.jsx(ls,{projectId:a,onClose:()=>se(!1),onCreate:dt})]})}export{us as ChatView};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a0 as oe,a1 as K,a2 as le,a3 as ie,F as z,a4 as de,a5 as ue,S as me,X as he,R as pe,a6 as fe,a7 as W,a8 as V,N as X,H as je,a9 as xe}from"./index-heCcln3Z.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};
|