@runfusion/fusion 0.37.0 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +1510 -234
- package/dist/client/.vite/manifest.json +58 -58
- package/dist/client/assets/AgentDetailView-DuRYmHK3.js +18 -0
- package/dist/client/assets/{AgentPermissionPolicyEditor-niLSqGAE.js → AgentPermissionPolicyEditor-ClY32kYN.js} +1 -1
- package/dist/client/assets/AgentsView-UbCAHs_i.js +29 -0
- package/dist/client/assets/ChatView-DDDjYRKc.js +6 -0
- package/dist/client/assets/{DevServerView-0Gb44WOb.js → DevServerView-DY5GlJcD.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-BSQA0XM9.js → DirectoryPicker-B4VRL2BH.js} +1 -1
- package/dist/client/assets/{DocumentsView-XZbaqEFF.js → DocumentsView-tqpIZ9t9.js} +1 -1
- package/dist/client/assets/{EvalsView-CJNtXxX9.js → EvalsView-C_Br3ry8.js} +1 -1
- package/dist/client/assets/{ExperimentalAgentOnboardingModal-DR8E3i36.js → ExperimentalAgentOnboardingModal-lXM--LV-.js} +1 -1
- package/dist/client/assets/GoalsView-B65urz9k.css +1 -0
- package/dist/client/assets/{GoalsView-CN1zQ_Ax.js → GoalsView-CI3Bzs1b.js} +1 -1
- package/dist/client/assets/{InsightsView-D_jRaMyn.js → InsightsView-BYfsVobi.js} +2 -2
- package/dist/client/assets/{MemoryView-D90vdPnp.js → MemoryView-DT4vIhaW.js} +1 -1
- package/dist/client/assets/{NodesView-C1zuedAe.js → NodesView-Dx6HFqjI.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-DBJDDVfM.js → PiExtensionsManager-BcGBnNiC.js} +2 -2
- package/dist/client/assets/{PluginManager-Ceg64P2Z.js → PluginManager-T_XZ7iNI.js} +1 -1
- package/dist/client/assets/{ResearchView-XRwWdczc.js → ResearchView-Bv4igpnv.js} +1 -1
- package/dist/client/assets/{SecretsView-TCrKyCme.js → SecretsView-C4VX2ZTa.js} +1 -1
- package/dist/client/assets/SettingsModal-CLEkhLK_.js +31 -0
- package/dist/client/assets/{SettingsModal-C1TczsEr.js → SettingsModal-Cy42vswI.js} +1 -1
- package/dist/client/assets/SettingsModal-D_uIvf6n.css +1 -0
- package/dist/client/assets/{SetupWizardModal-D6moSTT3.js → SetupWizardModal-LqloAL4J.js} +1 -1
- package/dist/client/assets/{SkillsView-BDHLPVBi.js → SkillsView-I1SDKaRz.js} +1 -1
- package/dist/client/assets/{StashRecoveryView-DZGa591R.js → StashRecoveryView-DMUUR3cy.js} +1 -1
- package/dist/client/assets/{TodoView-nr_SnCJv.js → TodoView-PKvJKjtV.js} +2 -2
- package/dist/client/assets/{dashboard-view-0XeZ1FTR.js → dashboard-view-D4XVI1XP.js} +2 -2
- package/dist/client/assets/{folder-open-iURwQbEg.js → folder-open-Doam5g-y.js} +1 -1
- package/dist/client/assets/index-BS-jSWPW.js +742 -0
- package/dist/client/assets/index-ktpD_W3I.css +1 -0
- package/dist/client/assets/{upload-Beqg4S4L.js → upload-BUfrZl69.js} +1 -1
- package/dist/client/assets/{users-C2o86ZCR.js → users-XNGnYBJb.js} +1 -1
- package/dist/client/index.html +40 -3
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/extension.js +1326 -182
- 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-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/dist/client/assets/AgentDetailView-T_AHPxcG.js +0 -18
- package/dist/client/assets/AgentsView-CQhaLHz_.js +0 -29
- package/dist/client/assets/ChatView-B60kYfdk.js +0 -6
- package/dist/client/assets/GoalsView-CtWi0fxE.css +0 -1
- package/dist/client/assets/SettingsModal-0gevFhXV.css +0 -1
- package/dist/client/assets/SettingsModal-B8fRuWdQ.js +0 -31
- package/dist/client/assets/index-CjuQj4qe.js +0 -742
- package/dist/client/assets/index-DmrpDn7c.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c4 as Ue,c5 as ve,c6 as tt,c7 as me,s as Me,c8 as xe,c9 as ye,ca as Se,cb as Ne,cc as rt,cd as ie,ce as st,cf as nt,cg as at,ch as it,ci as lt,aF as J,cj as le,L as te,S as ct,M as ot,ck as dt,bJ as ut,a as vt,cl as Pe,T as Te,cm as mt,Q as ft,a_ as pt,a$ as ht,af as gt,aA as bt,R as wt}from"./index-CjuQj4qe.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const fe=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function ze(e){return e.length<=fe?e:e.slice(-fe)}function ce(e,i){return ze([...e,i])}function G(e){try{return JSON.parse(e)}catch{return null}}function I(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function ke(e){return st(e)}async function je(e,i){return nt(e,i)}async function St(e){return at(e)}async function Nt(e){return it(e)}async function Ce(e){return lt(e)}function V(e){try{return e()}catch{return null}}function oe(){return typeof V(()=>ve)=="function"&&typeof V(()=>Ue)=="function"}function q(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 kt(e){const[i,o]=r.useState(null),[g,y]=r.useState([]),[x,f]=r.useState([]),[j,A]=r.useState([]),[C,P]=r.useState(!0),[S,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),_=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-fe).map(I);f(s)}},[]),M=r.useCallback(async()=>{const a=n.current;try{if(oe())if(d){const s=await Ue(d,e);if(n.current!==a)return;_(s)}else{const s=await ve(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),_(s[0]))}else{const s=await ke(e);if(n.current!==a)return;const c=q(s);y([c]),_(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[_,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),A([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([oe()?ve(e):ke(e).then(N=>[q(N)]),typeof V(()=>ie)=="function"?ie(e):Ce(e).then(N=>N.map(w=>({name:w.name,command:w.command,cwd:w.cwd,scriptName:w.scriptName,packagePath:w.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const N=c.value;if(y(N),N.length>0){const w=N[0];oe()&&U(w.config.id),_(w)}}else v=B(c.reason);l.status==="fulfilled"&&A(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[_,e]),r.useEffect(()=>{const a=d?tt(d,e):typeof V(()=>me)=="function"?me(e):null;if(!a)return;const s=n.current,c=Me(a,{events:{history:l=>{if(n.current!==s)return;const v=G(l.data);if(v?.lines){const N=v.lines.map(I);f(ze(N))}},log:l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:I(v);f(w=>ce(w,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:I(v);f(w=>ce(w,N))}},"dev-server:output":l=>{if(n.current!==s)return;const v=G(l.data);v?.line&&f(N=>ce(N,v.line))},status:l=>{if(n.current!==s)return;const v=G(l.data),N=v?.status;N&&o(w=>w&&{...w,status:N,runtime:v.pid?{...w.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:w.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=G(l.data);if(v?.status){const N=q(v);o(N),y([N])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&M()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,M,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{M()},xt);return()=>{clearInterval(a)}},[M,i?.status]);const E=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>xe)=="function")l=await xe(d,e);else{const v=await je({command:a,cwd:s},e);l=q(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(()=>ye)=="function")s=await ye(d,e);else{const c=await St(e);s=q(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),k=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>Se)=="function")s=await Se(d,e);else{const c=await Nt(e);s=q(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),T=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>Ne)=="function")c=await Ne(d,a,e);else{const l=await rt({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 ie(e)}catch{s=(await Ce(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;A(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 je({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),w=q(N);o(w),y([w]),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 E(c,l)},[e,E,d]),L=r.useCallback(async()=>{await D()},[D]),R=r.useCallback(async()=>{await k()},[k]),z=r.useCallback(async a=>{await T(a)},[T]),$=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await M()},[M]),H=yt(i),b=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:g,logs:x,detectedCommands:j,previewUrl:H,isLoading:C,error:S,startServer:E,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:M,candidates:j,serverState:b,loading:C,start:p,stop:L,restart:R,setManualUrl:z,detect:$,refreshStatus:O}}const Ee=500,Le=100;function Fe(e){return e.length>Ee?e.slice(-Ee):e}function $e(e){return e==="stderr"?"stderr":"stdout"}function Z(e){try{return JSON.parse(e.data)}catch{return null}}function ee(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:$e(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function jt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function de(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,x)=>y.id-x.id),Fe(o)}function Ct(e,i){const[o,g]=r.useState([]),[y,x]=r.useState(!1),[f,j]=r.useState(!1),[A,C]=r.useState(!1),[P,S]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),_=r.useRef(e),M=r.useRef(i),E=r.useRef(0),D=r.useRef(1);(_.current!==e||M.current!==i)&&(_.current=e,M.current=i,d.current++,J({view:"useDevServerLogs",trigger:"project-context-change",projectId:e,replayAttempted:!1,reason:"context-version-bumped"}),n.current=!0,E.current=0,D.current=1,g([]),x(!1),j(!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 L=d.current,R=++U.current;n.current=!1,x(!0);const z=(b,a)=>{const s=Fe(b);g(s),S(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;E.current=c,D.current=c+1},$=b=>{if(n.current||d.current!==L||!b||typeof b!="object")return;const a=b.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)=>jt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>ee(c,l+1));z(s,s.length)},O=b=>{if(n.current||d.current!==L)return;const a=typeof b.text=="string"?b.text:typeof b.line=="string"?b.line:null;if(!a)return;const s=D.current,c=typeof b.id=="number"&&Number.isFinite(b.id)?b.id:s,l={id:c,text:a,stream:$e(b.stream),timestamp:typeof b.timestamp=="string"?b.timestamp:""};E.current=Math.max(E.current,c),D.current=Math.max(D.current,c+1),g(v=>de(v,[l])),S(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await le({maxLines:Le},e);if(n.current||d.current!==L||U.current!==R)return;const s=a.lines.map((c,l)=>ee(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==L||U.current!==R)return;z([],null)}finally{!n.current&&d.current===L&&U.current===R&&x(!1)}const b=me(e);u.current=Me(b,{events:{"dev-server:log":a=>{const s=Z(a);s&&O(s)},log:a=>{const s=Z(a);s&&O(s)},history:a=>{const s=Z(a);$(s)},"dev-server:history":a=>{const s=Z(a);$(s)}},onReconnect:()=>{J({view:"useDevServerLogs",trigger:"sse-reconnect",projectId:e,replayAttempted:!0,replayFromEventId:E.current??null,sseChannel:b,reason:"history-replay"}),!(n.current||d.current!==L)&&le({lastEventId:E.current,maxLines:50},e).then(a=>{if(n.current||d.current!==L)return;const s=a.lines.map((c,l)=>ee(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;E.current=Math.max(E.current,c),D.current=Math.max(D.current,c+1)}g(c=>de(c,s)),S(a.totalLines)}).catch(()=>{})}}),J({view:"useDevServerLogs",trigger:"sse-open",projectId:e,replayAttempted:!1,sseChannel:b})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const L=d.current,R=o.length;j(!0);try{const z=await le({maxLines:Le,offset:R},e);if(n.current||d.current!==L)return;const $=z.lines.map((O,H)=>ee(O,H+1));g(O=>de($,O)),C(z.totalLines>R+$.length),S(z.totalLines)}catch{}finally{j(!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:A,total:P,loadMore:T,clear:h,logs:o,isStreaming:p,clearLogs:h}}const Et="This preview appears to block iframe embedding. Open it in a new tab instead.",Lt="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Rt="Preview is taking longer than expected and may block iframe embedding.";function _t(e){return e==="blocked"?Et:e==="error"?Lt:null}function Dt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:g=null}=i,y=r.useRef(null),x=r.useRef(null),[f,j]=r.useState("unknown"),[A,C]=r.useState(null),[P]=r.useState(g),S=r.useCallback(()=>{x.current!==null&&(window.clearTimeout(x.current),x.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(S(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,S()}},[S,e]),r.useEffect(()=>{if(f!=="loading"){S();return}const k=setTimeout(()=>{x.current=null,n()},o);return x.current=k,()=>{clearTimeout(k),x.current===k&&(x.current=null)}},[S,f,o,n]);const d=r.useCallback(()=>{const k=y.current;if(!k){u("embedded");return}try{if(k.contentWindow?.location?.href==="about:blank"&&k.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),U=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(S(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[S]);const _=r.useCallback(()=>{S(),j("unknown"),C(null)},[S]),M=_,E=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:E,isBlocked:D,blockReason:A,detectionMethod:P,iframeRef:y,resetEmbedStatus:_,setEmbedStatus:u,retry:M,embedContext:A,handleIframeLoad:d,handleIframeError:U}}const At=/\x1b\[[0-9;]*m/g;function pe(e){return e.replace(At,"")}function Ut(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 Mt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=pe(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Tt(e,i){if(!i)return e;const o=new RegExp(`(${Mt(i)})`,"ig"),g=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:g.map((x,f)=>x.toLowerCase()===y?t.jsx("mark",{children:x},`${x}-${f}`):t.jsx("span",{children:x},`${x}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:g,total:y,onLoadMore:x,isRunning:f}){const j=r.useRef(null),A=r.useRef(e.length),C=r.useRef(f),[P,S]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[_,M]=r.useState("all"),E=r.useMemo(()=>_==="all"?e:e.filter(p=>Pt(p)===_),[e,_]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?E.filter(L=>pe(L.text).toLowerCase().includes(p)):E},[E,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,L=A.current,R=e.length>L;f&&(!p||!u&&R)&&T(),C.current=f,A.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const R=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!R)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&T()},[e,f,u,i,T]),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(te,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${P?" 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:_,onChange:p=>M(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(ct,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>U(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:[k," match",k===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":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ot,{size:14}):t.jsx(dt,{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:x,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(te,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:j,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.":E.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const L=pe(p.text),R=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[R&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:R}),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:ut(Tt(L,d.trim()))})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:T,"data-testid":"devserver-log-jump-button",children:[t.jsx(vt,{size:14}),"New logs"]})]})]})}const Ft="devserver-preview-iframe";function $t({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:g,blockReason:y,onRetry:x,className:f=Ft,embedContext:j}){const A=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(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(te,{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(Pe,{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"}),A&&t.jsx("p",{className:"devserver-preview-blocked-context",children:A})]}),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"}),x&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:x,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Te,{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"}),A&&t.jsx("p",{className:"devserver-preview-blocked-context",children:A})]}),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"}),x&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:x,children:"Retry"})]})]})]}):null}const Re={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"}};let ue=!1;function _e(e){return e instanceof Error?e.message:String(e)}function Oe(e){return e==="."?"root":e}function De(e){return e?e==="root"?".":e:null}function Ae(e,i,o){return!i||e.scriptName!==i?!1:o?Oe(e.cwd)===o:!0}function Ot(e){return e.cwd==="."?"root":e.cwd}function Bt(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Xt({addToast:e,projectId:i}){r.useEffect(()=>(J({view:"DevServerView",trigger:ue?"route-active":"remount",projectId:i,replayAttempted:!1}),ue=!1,()=>{ue=!0,J({view:"DevServerView",trigger:"route-inactive",projectId:i,replayAttempted:!1})}),[i]);const{session:o,detectedCommands:g,previewUrl:y,isLoading:x,error:f,startServer:j,stopServer:A,restartServer:C,setPreviewUrl:P,detectCommands:S,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Re[n]??Re.stopped,{entries:_,loading:M,loadingMore:E,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[L,R]=r.useState(!0),[z,$]=r.useState(""),[O,H]=r.useState(""),[b,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),N=l==="embedded"?h:null,{embedStatus:w,setEmbedStatus:Be,resetEmbedStatus:Q,iframeRef:X,isEmbedded:He,isBlocked:re,blockReason:se,retry:he}=Dt(N),[ge,W]=r.useState(!1),be=r.useRef(w);r.useEffect(()=>{const m=be.current!==w;re&&m&&W(!0),w==="embedded"&&W(!1),be.current=w},[w,re]),r.useEffect(()=>{W(!1)},[h]);const Y=r.useMemo(()=>{if(!b)return null;const m=De(p);return g.find(F=>!(F.scriptName!==b||m&&F.cwd!==m||o?.config?.command&&F.command!==o.config.command))??g.find(F=>Ae(F,b,p))??null},[g,o?.config?.command,b,p]);r.useEffect(()=>{typeof S=="function"&&S().catch(m=>{e(_e(m),"error")})},[e,S]),r.useEffect(()=>{if(b){R(!1);return}R(!0)},[b]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&$(o.config.command);return}if(Y){$(Y.command);return}g.length>0&&$(m=>m.trim().length>0?m:g[0]?.command??"")},[g,Y,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const ne=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),we=r.useCallback(()=>{W(!1),he()},[he]),Ve=r.useCallback(()=>{try{const m=X.current;if(m?.contentWindow){m.contentWindow.location.reload(),W(!1),Q();return}}catch{}if(!(!h||!X.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),X.current.src=m.toString(),W(!1),Q()}catch{X.current.src=h,W(!1),Q()}},[h,X,Q]),K=r.useCallback(async(m,F,ae)=>{c(m);try{await F(),e(ae,"success")}catch(et){e(_e(et),"error")}finally{c(null)}},[e]),We=r.useCallback(m=>{a(m.scriptName),R(!1),$(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),R(!0),e("Cleared selected dev server script.","success")},[e]),Xe=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const F=De(p)??".",ae=Y?.cwd??F;K("start",()=>j(m,ae),"Dev server started.")},Ge=()=>{K("stop",A,"Dev server stopped.")},Je=()=>{K("restart",C,"Dev server restarted.")},Qe=()=>{const m=O.trim(),F=m.length>0?m:null;K("preview",()=>P(F),F?"Preview URL updated.":"Preview URL override cleared.")},Ye=r.useCallback(()=>{f&&u()},[f,u]),Ke=n==="starting"||n==="running"||s!==null,Ie=n==="stopped"||s!==null,Ze=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(mt,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${U.className}`,"data-testid":"dev-server-status-badge",children:U.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Xe,disabled:Ke,"data-testid":"dev-server-start-button",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ge,disabled:Ie,"data-testid":"dev-server-stop-button",children:[t.jsx(pt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Je,disabled:Ze,"data-testid":"dev-server-restart-button",children:[t.jsx(ht,{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"}),x&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),x&&!o&&g.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(te,{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:Ye,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),b&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:b}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>R(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:qe,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),L&&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."]}),L&&g.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:g.map(m=>{const F=Ae(m,b,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${F?"dev-server-candidate--selected":""}`,onClick:()=>We(m),"data-testid":`dev-server-candidate-${m.scriptName}-${Oe(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:Bt(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:Ot(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=>$(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:Qe,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:[k??_.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:_,loading:M,loadingMore:E,hasMore:D,total:k,onLoadMore:T,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(gt,{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:ne,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(bt,{})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:Ve,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(wt,{})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":w,"data-embedded":He?"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:ne,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&ge&&re&&t.jsxs("div",{className:w==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[w==="error"?t.jsx(Te,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Pe,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:w==="error"?"Preview failed":"Preview blocked"}),se&&t.jsx("p",{className:"devserver-preview-blocked-context",children:se})]}),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:ne,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:we,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!ge&&t.jsx($t,{url:h,embedStatus:w,onEmbedStatusChange:Be,iframeRef:X,blockReason:se,onRetry:we})]})]})]})}export{Xt as DevServerView};
|
|
1
|
+
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c5 as Ue,c6 as ve,c7 as tt,c8 as me,s as Me,c9 as xe,ca as ye,cb as Se,cc as Ne,cd as rt,ce as ie,cf as st,cg as nt,ch as at,ci as it,cj as lt,aG as J,ck as le,L as te,S as ct,M as ot,cl as dt,bK as ut,a as vt,cm as Pe,T as Te,cn as mt,Q as ft,a$ as pt,b0 as ht,af as gt,aB as bt,R as wt}from"./index-BS-jSWPW.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const fe=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function ze(e){return e.length<=fe?e:e.slice(-fe)}function ce(e,i){return ze([...e,i])}function X(e){try{return JSON.parse(e)}catch{return null}}function I(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function ke(e){return st(e)}async function je(e,i){return nt(e,i)}async function St(e){return at(e)}async function Nt(e){return it(e)}async function Ce(e){return lt(e)}function V(e){try{return e()}catch{return null}}function oe(){return typeof V(()=>ve)=="function"&&typeof V(()=>Ue)=="function"}function q(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 kt(e){const[i,o]=r.useState(null),[g,y]=r.useState([]),[x,f]=r.useState([]),[j,A]=r.useState([]),[C,P]=r.useState(!0),[S,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),_=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-fe).map(I);f(s)}},[]),M=r.useCallback(async()=>{const a=n.current;try{if(oe())if(d){const s=await Ue(d,e);if(n.current!==a)return;_(s)}else{const s=await ve(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),_(s[0]))}else{const s=await ke(e);if(n.current!==a)return;const c=q(s);y([c]),_(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[_,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),A([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([oe()?ve(e):ke(e).then(N=>[q(N)]),typeof V(()=>ie)=="function"?ie(e):Ce(e).then(N=>N.map(w=>({name:w.name,command:w.command,cwd:w.cwd,scriptName:w.scriptName,packagePath:w.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const N=c.value;if(y(N),N.length>0){const w=N[0];oe()&&U(w.config.id),_(w)}}else v=B(c.reason);l.status==="fulfilled"&&A(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[_,e]),r.useEffect(()=>{const a=d?tt(d,e):typeof V(()=>me)=="function"?me(e):null;if(!a)return;const s=n.current,c=Me(a,{events:{history:l=>{if(n.current!==s)return;const v=X(l.data);if(v?.lines){const N=v.lines.map(I);f(ze(N))}},log:l=>{if(n.current!==s)return;const v=X(l.data);if(v){const N=typeof v.line=="string"?v.line:I(v);f(w=>ce(w,N))}},"dev-server:log":l=>{if(n.current!==s)return;const v=X(l.data);if(v){const N=typeof v.line=="string"?v.line:I(v);f(w=>ce(w,N))}},"dev-server:output":l=>{if(n.current!==s)return;const v=X(l.data);v?.line&&f(N=>ce(N,v.line))},status:l=>{if(n.current!==s)return;const v=X(l.data),N=v?.status;N&&o(w=>w&&{...w,status:N,runtime:v.pid?{...w.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:w.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=X(l.data);if(v?.status){const N=q(v);o(N),y([N])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&M()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,M,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{M()},xt);return()=>{clearInterval(a)}},[M,i?.status]);const E=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>xe)=="function")l=await xe(d,e);else{const v=await je({command:a,cwd:s},e);l=q(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(()=>ye)=="function")s=await ye(d,e);else{const c=await St(e);s=q(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),k=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>Se)=="function")s=await Se(d,e);else{const c=await Nt(e);s=q(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),T=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>Ne)=="function")c=await Ne(d,a,e);else{const l=await rt({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 ie(e)}catch{s=(await Ce(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;A(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 je({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),w=q(N);o(w),y([w]),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 E(c,l)},[e,E,d]),L=r.useCallback(async()=>{await D()},[D]),R=r.useCallback(async()=>{await k()},[k]),z=r.useCallback(async a=>{await T(a)},[T]),$=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await M()},[M]),H=yt(i),b=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:g,logs:x,detectedCommands:j,previewUrl:H,isLoading:C,error:S,startServer:E,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:M,candidates:j,serverState:b,loading:C,start:p,stop:L,restart:R,setManualUrl:z,detect:$,refreshStatus:O}}const Ee=500,Le=100;function Fe(e){return e.length>Ee?e.slice(-Ee):e}function $e(e){return e==="stderr"?"stderr":"stdout"}function Z(e){try{return JSON.parse(e.data)}catch{return null}}function ee(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:$e(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function jt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function de(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,x)=>y.id-x.id),Fe(o)}function Ct(e,i){const[o,g]=r.useState([]),[y,x]=r.useState(!1),[f,j]=r.useState(!1),[A,C]=r.useState(!1),[P,S]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),_=r.useRef(e),M=r.useRef(i),E=r.useRef(0),D=r.useRef(1);(_.current!==e||M.current!==i)&&(_.current=e,M.current=i,d.current++,J({view:"useDevServerLogs",trigger:"project-context-change",projectId:e,replayAttempted:!1,reason:"context-version-bumped"}),n.current=!0,E.current=0,D.current=1,g([]),x(!1),j(!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 L=d.current,R=++U.current;n.current=!1,x(!0);const z=(b,a)=>{const s=Fe(b);g(s),S(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;E.current=c,D.current=c+1},$=b=>{if(n.current||d.current!==L||!b||typeof b!="object")return;const a=b.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)=>jt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>ee(c,l+1));z(s,s.length)},O=b=>{if(n.current||d.current!==L)return;const a=typeof b.text=="string"?b.text:typeof b.line=="string"?b.line:null;if(!a)return;const s=D.current,c=typeof b.id=="number"&&Number.isFinite(b.id)?b.id:s,l={id:c,text:a,stream:$e(b.stream),timestamp:typeof b.timestamp=="string"?b.timestamp:""};E.current=Math.max(E.current,c),D.current=Math.max(D.current,c+1),g(v=>de(v,[l])),S(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await le({maxLines:Le},e);if(n.current||d.current!==L||U.current!==R)return;const s=a.lines.map((c,l)=>ee(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==L||U.current!==R)return;z([],null)}finally{!n.current&&d.current===L&&U.current===R&&x(!1)}const b=me(e);u.current=Me(b,{events:{"dev-server:log":a=>{const s=Z(a);s&&O(s)},log:a=>{const s=Z(a);s&&O(s)},history:a=>{const s=Z(a);$(s)},"dev-server:history":a=>{const s=Z(a);$(s)}},onReconnect:()=>{J({view:"useDevServerLogs",trigger:"sse-reconnect",projectId:e,replayAttempted:!0,replayFromEventId:E.current??null,sseChannel:b,reason:"history-replay"}),!(n.current||d.current!==L)&&le({lastEventId:E.current,maxLines:50},e).then(a=>{if(n.current||d.current!==L)return;const s=a.lines.map((c,l)=>ee(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;E.current=Math.max(E.current,c),D.current=Math.max(D.current,c+1)}g(c=>de(c,s)),S(a.totalLines)}).catch(()=>{})}}),J({view:"useDevServerLogs",trigger:"sse-open",projectId:e,replayAttempted:!1,sseChannel:b})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const L=d.current,R=o.length;j(!0);try{const z=await le({maxLines:Le,offset:R},e);if(n.current||d.current!==L)return;const $=z.lines.map((O,H)=>ee(O,H+1));g(O=>de($,O)),C(z.totalLines>R+$.length),S(z.totalLines)}catch{}finally{j(!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:A,total:P,loadMore:T,clear:h,logs:o,isStreaming:p,clearLogs:h}}const Et="This preview appears to block iframe embedding. Open it in a new tab instead.",Lt="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Rt="Preview is taking longer than expected and may block iframe embedding.";function _t(e){return e==="blocked"?Et:e==="error"?Lt:null}function Dt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:g=null}=i,y=r.useRef(null),x=r.useRef(null),[f,j]=r.useState("unknown"),[A,C]=r.useState(null),[P]=r.useState(g),S=r.useCallback(()=>{x.current!==null&&(window.clearTimeout(x.current),x.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(S(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,S()}},[S,e]),r.useEffect(()=>{if(f!=="loading"){S();return}const k=setTimeout(()=>{x.current=null,n()},o);return x.current=k,()=>{clearTimeout(k),x.current===k&&(x.current=null)}},[S,f,o,n]);const d=r.useCallback(()=>{const k=y.current;if(!k){u("embedded");return}try{if(k.contentWindow?.location?.href==="about:blank"&&k.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),U=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(S(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[S]);const _=r.useCallback(()=>{S(),j("unknown"),C(null)},[S]),M=_,E=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:E,isBlocked:D,blockReason:A,detectionMethod:P,iframeRef:y,resetEmbedStatus:_,setEmbedStatus:u,retry:M,embedContext:A,handleIframeLoad:d,handleIframeError:U}}const At=/\x1b\[[0-9;]*m/g;function pe(e){return e.replace(At,"")}function Ut(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 Mt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=pe(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Tt(e,i){if(!i)return e;const o=new RegExp(`(${Mt(i)})`,"ig"),g=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:g.map((x,f)=>x.toLowerCase()===y?t.jsx("mark",{children:x},`${x}-${f}`):t.jsx("span",{children:x},`${x}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:g,total:y,onLoadMore:x,isRunning:f}){const j=r.useRef(null),A=r.useRef(e.length),C=r.useRef(f),[P,S]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[_,M]=r.useState("all"),E=r.useMemo(()=>_==="all"?e:e.filter(p=>Pt(p)===_),[e,_]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?E.filter(L=>pe(L.text).toLowerCase().includes(p)):E},[E,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,L=A.current,R=e.length>L;f&&(!p||!u&&R)&&T(),C.current=f,A.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const R=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!R)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&T()},[e,f,u,i,T]),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(te,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${P?" 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:_,onChange:p=>M(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(ct,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>U(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:[k," match",k===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":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ot,{size:14}):t.jsx(dt,{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:x,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(te,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:j,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.":E.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const L=pe(p.text),R=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[R&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:R}),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:ut(Tt(L,d.trim()))})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:T,"data-testid":"devserver-log-jump-button",children:[t.jsx(vt,{size:14}),"New logs"]})]})]})}const Ft="devserver-preview-iframe";function $t({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:g,blockReason:y,onRetry:x,className:f=Ft,embedContext:j}){const A=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(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(te,{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(Pe,{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"}),A&&t.jsx("p",{className:"devserver-preview-blocked-context",children:A})]}),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"}),x&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:x,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Te,{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"}),A&&t.jsx("p",{className:"devserver-preview-blocked-context",children:A})]}),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"}),x&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:x,children:"Retry"})]})]})]}):null}const Re={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"}};let ue=!1;function _e(e){return e instanceof Error?e.message:String(e)}function Oe(e){return e==="."?"root":e}function De(e){return e?e==="root"?".":e:null}function Ae(e,i,o){return!i||e.scriptName!==i?!1:o?Oe(e.cwd)===o:!0}function Ot(e){return e.cwd==="."?"root":e.cwd}function Bt(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Gt({addToast:e,projectId:i}){r.useEffect(()=>(J({view:"DevServerView",trigger:ue?"route-active":"remount",projectId:i,replayAttempted:!1}),ue=!1,()=>{ue=!0,J({view:"DevServerView",trigger:"route-inactive",projectId:i,replayAttempted:!1})}),[i]);const{session:o,detectedCommands:g,previewUrl:y,isLoading:x,error:f,startServer:j,stopServer:A,restartServer:C,setPreviewUrl:P,detectCommands:S,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Re[n]??Re.stopped,{entries:_,loading:M,loadingMore:E,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[L,R]=r.useState(!0),[z,$]=r.useState(""),[O,H]=r.useState(""),[b,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),N=l==="embedded"?h:null,{embedStatus:w,setEmbedStatus:Be,resetEmbedStatus:Q,iframeRef:G,isEmbedded:He,isBlocked:re,blockReason:se,retry:he}=Dt(N),[ge,W]=r.useState(!1),be=r.useRef(w);r.useEffect(()=>{const m=be.current!==w;re&&m&&W(!0),w==="embedded"&&W(!1),be.current=w},[w,re]),r.useEffect(()=>{W(!1)},[h]);const K=r.useMemo(()=>{if(!b)return null;const m=De(p);return g.find(F=>!(F.scriptName!==b||m&&F.cwd!==m||o?.config?.command&&F.command!==o.config.command))??g.find(F=>Ae(F,b,p))??null},[g,o?.config?.command,b,p]);r.useEffect(()=>{typeof S=="function"&&S().catch(m=>{e(_e(m),"error")})},[e,S]),r.useEffect(()=>{if(b){R(!1);return}R(!0)},[b]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&$(o.config.command);return}if(K){$(K.command);return}g.length>0&&$(m=>m.trim().length>0?m:g[0]?.command??"")},[g,K,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const ne=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),we=r.useCallback(()=>{W(!1),he()},[he]),Ve=r.useCallback(()=>{try{const m=G.current;if(m?.contentWindow){m.contentWindow.location.reload(),W(!1),Q();return}}catch{}if(!(!h||!G.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),G.current.src=m.toString(),W(!1),Q()}catch{G.current.src=h,W(!1),Q()}},[h,G,Q]),Y=r.useCallback(async(m,F,ae)=>{c(m);try{await F(),e(ae,"success")}catch(et){e(_e(et),"error")}finally{c(null)}},[e]),We=r.useCallback(m=>{a(m.scriptName),R(!1),$(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),R(!0),e("Cleared selected dev server script.","success")},[e]),Ge=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const F=De(p)??".",ae=K?.cwd??F;Y("start",()=>j(m,ae),"Dev server started.")},Xe=()=>{Y("stop",A,"Dev server stopped.")},Je=()=>{Y("restart",C,"Dev server restarted.")},Qe=()=>{const m=O.trim(),F=m.length>0?m:null;Y("preview",()=>P(F),F?"Preview URL updated.":"Preview URL override cleared.")},Ke=r.useCallback(()=>{f&&u()},[f,u]),Ye=n==="starting"||n==="running"||s!==null,Ie=n==="stopped"||s!==null,Ze=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(mt,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${U.className}`,"data-testid":"dev-server-status-badge",children:U.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ge,disabled:Ye,"data-testid":"dev-server-start-button",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Xe,disabled:Ie,"data-testid":"dev-server-stop-button",children:[t.jsx(pt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Je,disabled:Ze,"data-testid":"dev-server-restart-button",children:[t.jsx(ht,{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"}),x&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),x&&!o&&g.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(te,{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:Ke,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),b&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:b}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>R(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:qe,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),L&&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."]}),L&&g.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:g.map(m=>{const F=Ae(m,b,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${F?"dev-server-candidate--selected":""}`,onClick:()=>We(m),"data-testid":`dev-server-candidate-${m.scriptName}-${Oe(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:Bt(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:Ot(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=>$(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:Qe,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:[k??_.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:_,loading:M,loadingMore:E,hasMore:D,total:k,onLoadMore:T,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(gt,{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:ne,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(bt,{})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:Ve,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(wt,{})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":w,"data-embedded":He?"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:ne,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&ge&&re&&t.jsxs("div",{className:w==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[w==="error"?t.jsx(Te,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Pe,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:w==="error"?"Preview failed":"Preview blocked"}),se&&t.jsx("p",{className:"devserver-preview-blocked-context",children:se})]}),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:ne,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:we,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!ge&&t.jsx($t,{url:h,embedStatus:w,onEmbedStatusChange:Be,iframeRef:G,blockReason:se,onRetry:we})]})]})]})}export{Gt 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{eX as N,eY as g,dD as b,b as y,aj as P,ae as H,af as C,L as O,ay as v}from"./index-BS-jSWPW.js";import{F as z}from"./folder-open-Doam5g-y.js";function B({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 N(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 f=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:f.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{B as D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a7 as K,a8 as W,a9 as ie,aa as de,ab as G,ac as ue,f as me,ad as he,F as T,ae as fe,af as pe,S as je,X as xe,R as we,ag as ke,ah as X,ai as V,a as Y,b as ge,aj as be}from"./index-CjuQj4qe.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";function ve(n){const{projectId:c,searchQuery:h,includeProjectFiles:a=!0}=n??{},l=c?`${ie.DOCUMENTS_PREFIX}${c}`:null,[o,m]=s.useState(()=>{if(!l)return[];const w=K(l,{maxAgeMs:W});return Array.isArray(w)?w:[]}),[d,i]=s.useState([]),[k,x]=s.useState(()=>o.length===0),[C,b]=s.useState(null),g=s.useRef(null),f=s.useRef(o.length>0),p=s.useRef(null),v=s.useCallback(async()=>{g.current&&g.current.abort();const w=new AbortController;g.current=w;const z=!f.current;z&&x(!0),b(null);const E=de(h?{q:h}:void 0,c),R=a?G(c):Promise.resolve({files:[]}),[j,M]=await Promise.allSettled([E,R]);if(w.signal.aborted)return;let A=null;if(j.status==="fulfilled"){if(m(j.value),l){const y=j.value.length>500?j.value.slice(0,500):j.value;ue(l,y,{maxBytes:5e5})}f.current=!0}else A=j.reason instanceof Error?j.reason.message:String(j.reason);if(M.status==="fulfilled"){const y=M.value.files,L=h?.trim().toLowerCase(),F=L?y.filter(P=>P.name.toLowerCase().includes(L)||P.path.toLowerCase().includes(L)):y;i(F)}b(A),z&&x(!1)},[l,a,c,h]);return s.useEffect(()=>{if(!l){f.current=!1,m([]),x(!0);return}const w=K(l,{maxAgeMs:W});Array.isArray(w)?(m(w),f.current=!0,x(!1)):(f.current=!1,m([]),x(!0))},[l]),s.useEffect(()=>(p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{v()},300),()=>{p.current&&clearTimeout(p.current)}),[v]),s.useEffect(()=>(v(),()=>{g.current&&g.current.abort()}),[]),{documents:o,projectFiles:d,loading:k,error:C,refresh:v}}function Ne(n,c){const[h,a]=s.useState([]),[l,o]=s.useState(!0),[m,d]=s.useState(null),i=s.useRef(null),k=s.useRef(!1),x=c?.showHidden??!1,C=s.useCallback(async b=>{i.current&&i.current.abort();const g=new AbortController;i.current=g;const f=!k.current;f&&o(!0),d(null);try{const p=await G(n,{showHidden:b?.showHidden??x});if(g.signal.aborted)return;a(p.files),k.current=!0}catch(p){if(g.signal.aborted)return;d(p instanceof Error?p.message:String(p))}finally{!g.signal.aborted&&f&&o(!1)}},[n,x]);return s.useEffect(()=>(k.current=!1,C({showHidden:x}),()=>{i.current&&i.current.abort()}),[C,x]),{files:h,loading:l,error:m,refresh:C}}const Se=768;function J(n){return n?new Date(n).toLocaleString():""}function Ce(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 Fe(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ee({document:n,renderMarkdown:c,onToggleMarkdown:h}){const[a,l]=s.useState(!1),o=Fe(n.content),m=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(T,{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:()=>l(d=>!d),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(be,{size:14}):e.jsx(Y,{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:J(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:h,"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(X,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:o}),m&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function ye({taskId:n,taskTitle:c,documents:h,onOpenTask:a,renderMarkdownStates:l,onToggleMarkdown:o}){const[m,d]=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:()=>d(i=>!i),"aria-expanded":m,"aria-label":`${m?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:m?e.jsx(Y,{size:16}):e.jsx(ge,{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:[h.length," doc",h.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),m&&e.jsx("div",{className:"documents-group-content",children:h.map(i=>e.jsx(Ee,{document:i,renderMarkdown:l.get(i.id)??!1,onToggleMarkdown:()=>o(i.id)},i.id))})]})}function ze({projectId:n,addToast:c,onOpenDetail:h}){const[a,l]=s.useState("project"),[o,m]=s.useState(""),[d,i]=s.useState(null),[k,x]=s.useState(!1),[C,b]=s.useState(null),[g,f]=s.useState(!1),[p,v]=s.useState(null),[w,z]=s.useState(!1),E=s.useRef(0),R=s.useRef(!1),[j,M]=s.useState(!1),[A,y]=s.useState(new Map),L=a==="tasks"?o.trim():"",{documents:F,loading:P,error:Z,refresh:B}=ve({projectId:n,searchQuery:L||void 0,includeProjectFiles:!1}),{files:S,loading:D,error:I,refresh:O}=Ne(n,{showHidden:k});s.useEffect(()=>{const t=()=>{z(window.innerWidth<=Se)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{R.current=!1,l("project"),i(null),x(!1),b(null),v(null),f(!1),M(!1),y(new Map)},[n]),s.useEffect(()=>{R.current||P||D||(S.length>0?l("project"):F.length>0&&l("tasks"),R.current=!0)},[F.length,P,S.length,D]);const $=s.useMemo(()=>{const t=new Map;for(const r of F){const u=t.get(r.taskId)||[];t.set(r.taskId,[...u,r])}return Array.from(t.entries()).map(([r,u])=>{const N=[...u].sort((oe,le)=>le.updatedAt.localeCompare(oe.updatedAt));return{taskId:r,taskTitle:N[0]?.taskTitle,documents:N,latestUpdated:N[0]?.updatedAt??""}}).sort((r,u)=>u.latestUpdated.localeCompare(r.latestUpdated))},[F]),H=s.useMemo(()=>{const t=o.trim().toLowerCase();return t?S.filter(r=>{const u=r.path.toLowerCase(),N=r.name.toLowerCase();return u.includes(t)||N.includes(t)}):S},[S,o]);s.useEffect(()=>{if(!d)return;S.some(r=>r.path===d.path)||(i(null),b(null),v(null),f(!1))},[S,d]);const ee=s.useCallback(t=>{m(t.target.value)},[]),se=s.useCallback(()=>{m("")},[]),U=s.useCallback(t=>{l(t)},[]),te=s.useCallback(async t=>{try{const r=await me(t,n);h(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,h,c]),ne=s.useCallback(async t=>{i(t),f(!0),v(null),b(null);const r=E.current+1;E.current=r;try{const u=await he("project",t.path,n);if(E.current!==r)return;b(u.content)}catch(u){if(E.current!==r)return;const N=u instanceof Error?u.message:`Failed to open ${t.path}`;v(N),c(N,"error")}finally{E.current===r&&f(!1)}},[n,c]),ae=s.useCallback(()=>{i(null),b(null),v(null),f(!1)},[]),re=s.useCallback(t=>{y(r=>{const u=new Map(r),N=u.get(t)??!1;return u.set(t,!N),u})},[]),_=a==="project"?I:Z,ce=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),Q=a==="project"?H.length:F.length,q=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(T,{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:()=>U("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:()=>U("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:$.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>x(t=>!t),"aria-pressed":k,"aria-label":k?"Hide hidden project files":"Show hidden project files",title:k?"Hide hidden files":"Show hidden files",children:[k?e.jsx(fe,{size:14}):e.jsx(pe,{size:14}),k?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(je,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:q,value:o,onChange:ee,"aria-label":q}),o&&e.jsx("button",{className:"documents-search-clear",onClick:se,"aria-label":"Clear search",children:e.jsx(xe,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:_?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",_]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ce(),"aria-label":"Retry loading documents",children:[e.jsx(we,{size:16}),"Retry"]})]}):a==="project"?D&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No project markdown files match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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${w?" documents-project-layout--mobile":""}`,children:[(!w||!d)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:H.map(t=>{const r=d?.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 ne(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:[Ce(t.size)," · ",J(t.mtime)]})]})},t.path)})})}),(!w||d)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[w&&d&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:ae,"aria-label":"Back to project files list",children:[e.jsx(ke,{size:14}),"Back to files"]}),d?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:d.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>M(t=>!t),"aria-label":j?"Switch to plain text":"Switch to markdown","aria-pressed":j,title:j?"Switch to plain text":"Switch to markdown",children:j?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):p?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:p}):j?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(X,{remarkPlugins:[V],children:C??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:C??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):P&&F.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):$.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No task documents match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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:$.map(({taskId:t,taskTitle:r,documents:u})=>e.jsx(ye,{taskId:t,taskTitle:r,documents:u,onOpenTask:te,renderMarkdownStates:A,onToggleMarkdown:re},t))})})})]})}export{ze as DocumentsView};
|
|
1
|
+
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a7 as K,a8 as W,a9 as ie,aa as de,ab as G,ac as ue,f as me,ad as he,F as T,ae as fe,af as pe,S as je,X as xe,R as we,ag as ke,ah as X,ai as V,a as Y,b as ge,aj as be}from"./index-BS-jSWPW.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";function ve(n){const{projectId:c,searchQuery:h,includeProjectFiles:a=!0}=n??{},l=c?`${ie.DOCUMENTS_PREFIX}${c}`:null,[o,m]=s.useState(()=>{if(!l)return[];const w=K(l,{maxAgeMs:W});return Array.isArray(w)?w:[]}),[d,i]=s.useState([]),[k,x]=s.useState(()=>o.length===0),[C,b]=s.useState(null),g=s.useRef(null),f=s.useRef(o.length>0),p=s.useRef(null),v=s.useCallback(async()=>{g.current&&g.current.abort();const w=new AbortController;g.current=w;const z=!f.current;z&&x(!0),b(null);const E=de(h?{q:h}:void 0,c),R=a?G(c):Promise.resolve({files:[]}),[j,M]=await Promise.allSettled([E,R]);if(w.signal.aborted)return;let A=null;if(j.status==="fulfilled"){if(m(j.value),l){const y=j.value.length>500?j.value.slice(0,500):j.value;ue(l,y,{maxBytes:5e5})}f.current=!0}else A=j.reason instanceof Error?j.reason.message:String(j.reason);if(M.status==="fulfilled"){const y=M.value.files,L=h?.trim().toLowerCase(),F=L?y.filter(P=>P.name.toLowerCase().includes(L)||P.path.toLowerCase().includes(L)):y;i(F)}b(A),z&&x(!1)},[l,a,c,h]);return s.useEffect(()=>{if(!l){f.current=!1,m([]),x(!0);return}const w=K(l,{maxAgeMs:W});Array.isArray(w)?(m(w),f.current=!0,x(!1)):(f.current=!1,m([]),x(!0))},[l]),s.useEffect(()=>(p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{v()},300),()=>{p.current&&clearTimeout(p.current)}),[v]),s.useEffect(()=>(v(),()=>{g.current&&g.current.abort()}),[]),{documents:o,projectFiles:d,loading:k,error:C,refresh:v}}function Ne(n,c){const[h,a]=s.useState([]),[l,o]=s.useState(!0),[m,d]=s.useState(null),i=s.useRef(null),k=s.useRef(!1),x=c?.showHidden??!1,C=s.useCallback(async b=>{i.current&&i.current.abort();const g=new AbortController;i.current=g;const f=!k.current;f&&o(!0),d(null);try{const p=await G(n,{showHidden:b?.showHidden??x});if(g.signal.aborted)return;a(p.files),k.current=!0}catch(p){if(g.signal.aborted)return;d(p instanceof Error?p.message:String(p))}finally{!g.signal.aborted&&f&&o(!1)}},[n,x]);return s.useEffect(()=>(k.current=!1,C({showHidden:x}),()=>{i.current&&i.current.abort()}),[C,x]),{files:h,loading:l,error:m,refresh:C}}const Se=768;function J(n){return n?new Date(n).toLocaleString():""}function Ce(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 Fe(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ee({document:n,renderMarkdown:c,onToggleMarkdown:h}){const[a,l]=s.useState(!1),o=Fe(n.content),m=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(T,{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:()=>l(d=>!d),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(be,{size:14}):e.jsx(Y,{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:J(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:h,"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(X,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:o}),m&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function ye({taskId:n,taskTitle:c,documents:h,onOpenTask:a,renderMarkdownStates:l,onToggleMarkdown:o}){const[m,d]=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:()=>d(i=>!i),"aria-expanded":m,"aria-label":`${m?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:m?e.jsx(Y,{size:16}):e.jsx(ge,{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:[h.length," doc",h.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),m&&e.jsx("div",{className:"documents-group-content",children:h.map(i=>e.jsx(Ee,{document:i,renderMarkdown:l.get(i.id)??!1,onToggleMarkdown:()=>o(i.id)},i.id))})]})}function ze({projectId:n,addToast:c,onOpenDetail:h}){const[a,l]=s.useState("project"),[o,m]=s.useState(""),[d,i]=s.useState(null),[k,x]=s.useState(!1),[C,b]=s.useState(null),[g,f]=s.useState(!1),[p,v]=s.useState(null),[w,z]=s.useState(!1),E=s.useRef(0),R=s.useRef(!1),[j,M]=s.useState(!1),[A,y]=s.useState(new Map),L=a==="tasks"?o.trim():"",{documents:F,loading:P,error:Z,refresh:B}=ve({projectId:n,searchQuery:L||void 0,includeProjectFiles:!1}),{files:S,loading:D,error:I,refresh:O}=Ne(n,{showHidden:k});s.useEffect(()=>{const t=()=>{z(window.innerWidth<=Se)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{R.current=!1,l("project"),i(null),x(!1),b(null),v(null),f(!1),M(!1),y(new Map)},[n]),s.useEffect(()=>{R.current||P||D||(S.length>0?l("project"):F.length>0&&l("tasks"),R.current=!0)},[F.length,P,S.length,D]);const $=s.useMemo(()=>{const t=new Map;for(const r of F){const u=t.get(r.taskId)||[];t.set(r.taskId,[...u,r])}return Array.from(t.entries()).map(([r,u])=>{const N=[...u].sort((oe,le)=>le.updatedAt.localeCompare(oe.updatedAt));return{taskId:r,taskTitle:N[0]?.taskTitle,documents:N,latestUpdated:N[0]?.updatedAt??""}}).sort((r,u)=>u.latestUpdated.localeCompare(r.latestUpdated))},[F]),H=s.useMemo(()=>{const t=o.trim().toLowerCase();return t?S.filter(r=>{const u=r.path.toLowerCase(),N=r.name.toLowerCase();return u.includes(t)||N.includes(t)}):S},[S,o]);s.useEffect(()=>{if(!d)return;S.some(r=>r.path===d.path)||(i(null),b(null),v(null),f(!1))},[S,d]);const ee=s.useCallback(t=>{m(t.target.value)},[]),se=s.useCallback(()=>{m("")},[]),U=s.useCallback(t=>{l(t)},[]),te=s.useCallback(async t=>{try{const r=await me(t,n);h(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,h,c]),ne=s.useCallback(async t=>{i(t),f(!0),v(null),b(null);const r=E.current+1;E.current=r;try{const u=await he("project",t.path,n);if(E.current!==r)return;b(u.content)}catch(u){if(E.current!==r)return;const N=u instanceof Error?u.message:`Failed to open ${t.path}`;v(N),c(N,"error")}finally{E.current===r&&f(!1)}},[n,c]),ae=s.useCallback(()=>{i(null),b(null),v(null),f(!1)},[]),re=s.useCallback(t=>{y(r=>{const u=new Map(r),N=u.get(t)??!1;return u.set(t,!N),u})},[]),_=a==="project"?I:Z,ce=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),Q=a==="project"?H.length:F.length,q=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(T,{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:()=>U("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:()=>U("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:$.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>x(t=>!t),"aria-pressed":k,"aria-label":k?"Hide hidden project files":"Show hidden project files",title:k?"Hide hidden files":"Show hidden files",children:[k?e.jsx(fe,{size:14}):e.jsx(pe,{size:14}),k?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(je,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:q,value:o,onChange:ee,"aria-label":q}),o&&e.jsx("button",{className:"documents-search-clear",onClick:se,"aria-label":"Clear search",children:e.jsx(xe,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:_?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",_]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ce(),"aria-label":"Retry loading documents",children:[e.jsx(we,{size:16}),"Retry"]})]}):a==="project"?D&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No project markdown files match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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${w?" documents-project-layout--mobile":""}`,children:[(!w||!d)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:H.map(t=>{const r=d?.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 ne(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:[Ce(t.size)," · ",J(t.mtime)]})]})},t.path)})})}),(!w||d)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[w&&d&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:ae,"aria-label":"Back to project files list",children:[e.jsx(ke,{size:14}),"Back to files"]}),d?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:d.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>M(t=>!t),"aria-label":j?"Switch to plain text":"Switch to markdown","aria-pressed":j,title:j?"Switch to plain text":"Switch to markdown",children:j?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):p?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:p}):j?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(X,{remarkPlugins:[V],children:C??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:C??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):P&&F.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):$.length===0?e.jsx("div",{className:"documents-view-empty",children:o.trim()?e.jsxs("p",{children:['No task documents match "',o.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(T,{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:$.map(({taskId:t,taskTitle:r,documents:u})=>e.jsx(ye,{taskId:t,taskTitle:r,documents:u,onOpenTask:te,renderMarkdownStates:A,onToggleMarkdown:re},t))})})})]})}export{ze as DocumentsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{a7 as C,a8 as _,a9 as D,
|
|
1
|
+
import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{a7 as C,a8 as _,a9 as D,aP as W,aQ as G,ac as V,aR as Q,x as Y,ax as J,R as Z,aB as ee}from"./index-BS-jSWPW.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const se=300,te=15e3;function B(r){if(!r.trim())return;const t=Number(r);return Number.isFinite(t)?t:void 0}function N(...r){for(const t of r)if(Array.isArray(t))return t;return[]}function p(r){return typeof r=="object"&&r!==null?r:{}}function K(r){const t=p(r),h=p(t.taskSnapshot);return{id:String(t.id??t.evalId??""),runId:String(t.runId??t.batchId??""),taskId:String(t.taskId??h.taskId??""),taskTitle:String(h.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:N(t.categoryScores,p(t.scores).categories)}}function ae(r){const t=p(r);return{...K(t),rationale:String(t.rationale??t.summary??""),evidence:N(t.evidence,p(t.details).evidence),followUps:N(t.followUps,p(t.recommendations).followUps)}}function re(r){const t=r?.projectId,h=t??"",f=`${D.EVALS_RUNS_PREFIX}${h}`,u=`${D.EVALS_RESULTS_PREFIX}${h}`,v=C(f,{maxAgeMs:_}),S=C(u,{maxAgeMs:_}),m=a.useRef(Array.isArray(v)&&v.length>0||Array.isArray(S)&&S.length>0),[c,E]=a.useState({q:"",runId:"",scoreMin:"",scoreMax:""}),[T,i]=a.useState(()=>Array.isArray(v)?v:[]),[L,R]=a.useState(()=>Array.isArray(S)?S:[]),[d,I]=a.useState(null),[F,s]=a.useState(null),[o,g]=a.useState(0),[b,U]=a.useState(!m.current),[X,z]=a.useState(null),k=a.useRef(0),$=a.useRef(t),w=a.useRef(d);w.current=d;const A=a.useCallback(async()=>{const l=++k.current;m.current||U(!0),z(null);try{const[n,x]=await Promise.all([W({q:c.q||void 0,runId:c.runId||void 0,scoreMin:B(c.scoreMin),scoreMax:B(c.scoreMax),limit:100,offset:0},t),G(t)]);if(l!==k.current)return;const y=N(n.results,n.evals,n.items).map(K);R(y),V(u,y.length>500?y.slice(0,500):y,{maxBytes:5e5}),g(typeof n.count=="number"?n.count:y.length);const O=N(x.runs,x.items).map(q=>{const j=p(q),P=p(j.counts);return{id:String(j.id??""),createdAt:String(j.createdAt??""),completedAt:typeof j.completedAt=="string"?j.completedAt:void 0,status:String(j.status??"pending"),evaluatedTaskCount:typeof P.totalTasks=="number"?P.totalTasks:0}});i(O),V(f,O,{maxBytes:5e5}),m.current=!0,w.current&&!y.some(q=>q.id===w.current)&&(I(null),s(null))}catch(n){if(l!==k.current)return;z(n instanceof Error?n.message:"Failed to load evals")}finally{l===k.current&&U(!1)}},[c.q,c.runId,c.scoreMax,c.scoreMin,t,u,f]),M=a.useCallback(async l=>{const n=await Q(l,t),x=n.result??n;s(ae(x))},[t]);a.useEffect(()=>{if($.current===t)return;$.current=t;const l=C(f,{maxAgeMs:_}),n=C(u,{maxAgeMs:_}),x=Array.isArray(l)&&l.length>0||Array.isArray(n)&&n.length>0;i(Array.isArray(l)?l:[]),R(Array.isArray(n)?n:[]),U(!x),m.current=x},[t,u,f]),a.useEffect(()=>{const l=window.setTimeout(()=>{A()},se);return()=>window.clearTimeout(l)},[A]),a.useEffect(()=>{if(!d){s(null);return}M(d)},[M,d]),a.useEffect(()=>{const l=window.setInterval(()=>{A(),d&&M(d)},te);return()=>window.clearInterval(l)},[M,A,d]);const H=a.useCallback(l=>{w.current=l,I(l)},[]);return{loading:b,error:X,results:L,count:o,runs:T,filters:c,setFilters:E,refresh:A,selectedEvalId:d,setSelectedEvalId:H,selectedEval:F}}function ue({projectId:r,onOpenSettings:t,onOpenTaskDetail:h}){const{loading:f,error:u,results:v,runs:S,filters:m,setFilters:c,selectedEvalId:E,setSelectedEvalId:T,selectedEval:i,refresh:L}=re({projectId:r}),[R,d]=a.useState(!0);a.useEffect(()=>{let s=!1;return Y(r).then(o=>{if(s)return;const g=o.evalSettings?.enabled;d(g??!1)}).catch(()=>{s||d(!1)}),()=>{s=!0}},[r]);const I=v.length>0,F=a.useMemo(()=>v.find(s=>s.id===E)??null,[v,E]);return R?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:m.q,onChange:s=>c(o=>({...o,q:s.target.value}))}),e.jsxs("select",{className:"select",value:m.runId,onChange:s=>c(o=>({...o,runId:s.target.value})),children:[e.jsx("option",{value:"",children:"All runs"}),S.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}),e.jsx("input",{className:"input",placeholder:"Min score",value:m.scoreMin,onChange:s=>c(o=>({...o,scoreMin:s.target.value}))}),e.jsx("input",{className:"input",placeholder:"Max score",value:m.scoreMax,onChange:s=>c(o=>({...o,scoreMax:s.target.value}))}),e.jsx("button",{className:"btn btn-icon",type:"button",onClick:()=>void L(),"aria-label":"Refresh evals",children:e.jsx(Z,{size:16})})]}),f&&e.jsx("p",{className:"evals-state","data-testid":"evals-loading",children:"Loading evals…"}),u&&e.jsx("p",{className:"evals-state evals-state--error",children:u}),!f&&!u&&!I&&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:v.map(s=>e.jsx("li",{children:e.jsxs("button",{className:`evals-result ${s.id===E?"evals-result--active":""}`,type:"button",onClick:()=>T(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:[!i&&e.jsx("p",{className:"evals-state",children:"Select an evaluation to inspect scores, rationale, and evidence."}),i&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"evals-detail-title",children:F?.taskTitle??i.taskTitle}),e.jsxs("p",{className:"evals-result-meta",children:[i.taskId," · ",i.runId]}),e.jsxs("p",{className:"evals-score",children:["Overall score: ",i.overallScore??"n/a"]}),e.jsx("ul",{className:"evals-categories",children:i.categoryScores.map(s=>e.jsxs("li",{children:[s.category,": ",s.finalScore]},s.category))}),e.jsx("p",{className:"evals-rationale",children:i.rationale||"No rationale recorded."}),e.jsxs("div",{children:[e.jsx("h4",{children:"Evidence"}),e.jsx("ul",{className:"evals-links",children:i.evidence.map((s,o)=>{const g=typeof s.metadata?.taskId=="string"?s.metadata.taskId:void 0,b=typeof s.metadata?.url=="string"?s.metadata.url:void 0;return e.jsx("li",{children:g?e.jsx("button",{type:"button",className:"btn",onClick:()=>h?.(g),children:s.ref}):b?e.jsxs("a",{href:b,target:"_blank",rel:"noreferrer",className:"evals-external-link",children:[s.ref,e.jsx(ee,{size:14})]}):e.jsx("span",{children:s.ref})},`${s.ref}-${o}`)})})]}),e.jsxs("div",{children:[e.jsx("h4",{children:"Suggested follow-up tasks"}),e.jsxs("ul",{className:"evals-follow-ups",children:[i.followUps.length===0&&e.jsx("li",{children:"None"}),i.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(J,{size:16}),"Open Scheduled Evals Settings"]})]})}export{ue 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{bO as F,eF as L,eG as H,eH as V,eI as U,eJ as K}from"./index-BS-jSWPW.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),F(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
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.goals-view{display:flex;flex-direction:column;gap:var(--space-lg);height:100%;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:var(--space-lg)}.goals-header{display:flex;justify-content:space-between;align-items:center;gap:var(--space-md)}.goals-title{margin:0;color:var(--text);font-size:calc(var(--space-lg) + var(--space-xs))}.goals-count{margin:0;color:var(--text-muted)}.goals-add-button{display:inline-flex;align-items:center;gap:var(--space-sm)}.goals-add-button:focus-visible,.goals-card:focus-visible,.goals-activate-button:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.goals-warning{margin:0;padding:var(--space-md);border-radius:var(--radius-md);border:calc(var(--space-xs) / 4) solid var(--color-warning);background:color-mix(in srgb,var(--color-warning) 10%,transparent);color:var(--color-warning)}.goals-error{margin:0}.goals-form{display:flex;flex-direction:column;gap:var(--space-sm)}.goals-form-label{color:var(--text-muted)}.goals-form textarea.input{min-height:calc(var(--space-2xl) * 2);resize:vertical}.goals-form-actions{display:flex;gap:var(--space-sm)}.goals-list{display:flex;flex-direction:column;gap:var(--space-md)}.goals-card{display:flex;align-items:center;justify-content:space-between;gap:var(--space-md)}.goals-card-archived{border-color:color-mix(in srgb,var(--text-muted) 25%,transparent)}.goals-card-main{min-width:0}.goals-card-edit{display:flex;flex:1;flex-direction:column;gap:var(--space-sm)}.goals-card-title{margin:0;color:var(--text);font-size:calc(var(--space-md) + var(--space-xs))}.goals-card-description,.goals-card-status{margin:var(--space-xs) 0 0;color:var(--text-muted)}.goals-card-actions{display:flex;gap:var(--space-sm)}.goals-activate-button{min-width:calc(var(--space-2xl) * 2)}.goals-empty{color:var(--text-muted)}@media(max-width:768px){.goals-header,.goals-card{flex-direction:column;align-items:stretch}.goals-form-actions,.goals-card-actions{flex-direction:column}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as i,j as a}from"./vendor-react-K0fH_qHe.js";import{J as X}from"./index-
|
|
1
|
+
import{r as i,j as a}from"./vendor-react-K0fH_qHe.js";import{J as X}from"./index-BS-jSWPW.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const B=5,K=3,_="Cannot activate more than 5 goals. Resolve an active goal before activating another.";function R(o){return!!(o&&typeof o=="object"&&"code"in o&&o.code==="ACTIVE_GOAL_LIMIT_EXCEEDED")}function tt({initialGoals:o}){const[c,g]=i.useState(()=>o??[]),[m,b]=i.useState(o===void 0),[x,n]=i.useState(null),[U,j]=i.useState(!1),[y,N]=i.useState(""),[E,S]=i.useState(""),[w,d]=i.useState(null),[A,C]=i.useState(!1),[h,$]=i.useState(null),[G,p]=i.useState(""),[T,f]=i.useState(""),[k,u]=i.useState(null),[F,P]=i.useState(!1);i.useEffect(()=>{if(o!==void 0)return;let t=!0;return(async()=>{try{b(!0),n(null);const s=await fetch("/api/goals");if(!s.ok)throw new Error(`Failed to load goals (${s.status})`);const l=await s.json();if(!t)return;g(Array.isArray(l.goals)?l.goals:[])}catch{if(!t)return;n("Unable to load goals right now. Please try again.")}finally{t&&b(!1)}})(),()=>{t=!1}},[o]);const v=i.useMemo(()=>c.filter(t=>t.status==="active").length,[c]),M=v>=K&&v<=B;function H(){n(null),d(null),j(!0)}function J(t){$(t.id),p(t.title),f(t.description??""),u(null)}function I(){$(null),p(""),f(""),u(null)}function L(){j(!1),N(""),S(""),d(null)}async function V(){const t=y.trim();if(!t){d("Title is required.");return}try{C(!0),d(null),n(null);const e=await fetch("/api/goals",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({title:t,description:E})});if(e.ok){const l=await e.json();g(r=>[...r,l]),L();return}let s=null;try{s=await e.json()}catch{s=null}if(e.status===409&&R(s)){n(_);return}d("Unable to create goal right now. Please try again.")}catch{d("Unable to create goal right now. Please try again.")}finally{C(!1)}}async function q(){if(!h)return;const t=G.trim();if(!t){u("Title is required.");return}try{P(!0),u(null);const e=await fetch(`/api/goals/${h}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({title:t,description:T})});if(!e.ok)throw new Error(`Failed to update goal (${e.status})`);const s=await e.json();g(l=>l.map(r=>r.id===s.id?s:r)),I()}catch{u("Unable to save goal right now. Please try again.")}finally{P(!1)}}async function O(t){const e=t.status==="active"?`/api/goals/${t.id}/archive`:`/api/goals/${t.id}/unarchive`;try{n(null);const s=await fetch(e,{method:"POST"});if(s.ok){const r=await s.json();g(W=>W.map(D=>D.id===r.id?r:D));return}let l=null;try{l=await s.json()}catch{l=null}if(s.status===409&&R(l)){n(_);return}n("Unable to update goal status right now. Please try again.")}catch{n("Unable to update goal status right now. Please try again.")}}return a.jsxs("section",{className:"goals-view","data-testid":"goals-view",children:[a.jsxs("header",{className:"goals-header",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"goals-title",children:"Goals"}),a.jsxs("p",{className:"goals-count","data-testid":"goals-active-count",children:[v," active goals"]})]}),a.jsxs("button",{type:"button",className:"btn btn-primary goals-add-button",onClick:H,"data-testid":"goals-add-button",children:[a.jsx(X,{"aria-hidden":"true"}),"Add Goal"]})]}),U?a.jsxs("div",{className:"card goals-form","data-testid":"goals-form",children:[a.jsx("label",{className:"goals-form-label",htmlFor:"goals-form-title",children:"Title"}),a.jsx("input",{id:"goals-form-title",className:"input",type:"text",value:y,maxLength:200,onChange:t=>N(t.target.value),"data-testid":"goals-form-title"}),a.jsx("label",{className:"goals-form-label",htmlFor:"goals-form-description",children:"Description"}),a.jsx("textarea",{id:"goals-form-description",className:"input",value:E,maxLength:5e3,onChange:t=>S(t.target.value),"data-testid":"goals-form-description"}),w?a.jsx("p",{className:"form-error goals-error",role:"alert",children:w}):null,a.jsxs("div",{className:"goals-form-actions",children:[a.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void V(),disabled:A,"data-testid":"goals-form-submit",children:"Save"}),a.jsx("button",{type:"button",className:"btn",onClick:L,disabled:A,"data-testid":"goals-form-cancel",children:"Cancel"})]})]}):null,M?a.jsx("p",{className:"goals-warning",role:"status",children:"Approaching the 5-active goal cap. Keep active goals focused."}):null,x?a.jsx("p",{className:"form-error goals-error",role:"alert","data-testid":"goals-error",children:x}):null,m?a.jsx("p",{className:"goals-loading",role:"status","data-testid":"goals-loading",children:"Loading goals…"}):null,!m&&c.length===0?a.jsx("div",{className:"goals-empty card","data-testid":"goals-empty-state",children:"No goals yet. Add one to begin tracking strategic outcomes."}):null,!m&&c.length>0?a.jsx("div",{className:"goals-list","data-testid":"goals-list",children:c.map(t=>a.jsx("article",{className:`card goals-card ${t.status==="archived"?"goals-card-archived":""}`.trim(),"data-testid":`goal-card-${t.id}`,children:h===t.id?a.jsxs("div",{className:"goals-card-main goals-card-edit",children:[a.jsx("label",{className:"goals-form-label",htmlFor:`goal-edit-title-${t.id}`,children:"Title"}),a.jsx("input",{id:`goal-edit-title-${t.id}`,className:"input",type:"text",value:G,maxLength:200,onChange:e=>p(e.target.value),"data-testid":`goal-edit-title-${t.id}`}),a.jsx("label",{className:"goals-form-label",htmlFor:`goal-edit-description-${t.id}`,children:"Description"}),a.jsx("textarea",{id:`goal-edit-description-${t.id}`,className:"input",value:T,maxLength:5e3,onChange:e=>f(e.target.value),"data-testid":`goal-edit-description-${t.id}`}),k?a.jsx("p",{className:"form-error goals-error",role:"alert",children:k}):null,a.jsxs("div",{className:"goals-card-actions",children:[a.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void q(),disabled:F,"data-testid":`goal-edit-save-${t.id}`,children:"Save"}),a.jsx("button",{type:"button",className:"btn",onClick:I,disabled:F,"data-testid":`goal-edit-cancel-${t.id}`,children:"Cancel"})]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"goals-card-main",children:[a.jsx("h3",{className:"goals-card-title",children:t.title}),t.description?a.jsx("p",{className:"goals-card-description",children:t.description}):null,a.jsxs("p",{className:"goals-card-status",children:["Status: ",t.status]})]}),a.jsxs("div",{className:"goals-card-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:()=>J(t),"data-testid":`goal-edit-${t.id}`,children:"Edit"}),t.status==="active"?a.jsx("button",{type:"button",className:"btn goals-activate-button",onClick:()=>void O(t),"data-testid":`goal-archive-${t.id}`,children:"Archive"}):a.jsx("button",{type:"button",className:"btn goals-activate-button",onClick:()=>void O(t),"data-testid":`goal-unarchive-${t.id}`,children:"Unarchive"})]})]})},t.id))}):null]})}export{tt as GoalsView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Re,a7 as te,a8 as be,a9 as we,ak as Se,al as Xe,ac as je,am as qe,an as We,ao as Ke,ap as Ye,aq as Ve,ar as Je,as as ke,at as Qe,
|
|
1
|
+
import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Re,a7 as te,a8 as be,a9 as we,ak as Se,al as Xe,ac as je,am as qe,an as We,ao as Ke,ap as Ye,aq as Ve,ar as Je,as as ke,at as Qe,i as Ze,au as Ce,av as C,A as es,X as Ne,aw as ge,R as N,ax as ss,m as ts,C as $e,ay as ie,az as Me,aA as is,J as ze,aB as as,aC as _e,aD as ns}from"./index-BS-jSWPW.js";import{U as Ae}from"./users-XNGnYBJb.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,4 +8,4 @@ import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Re,a7 as te,a8 as b
|
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const ls=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],os=Re("chart-line",ls),de=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],Ie={quality:"Quality",performance:"Performance",architecture:"Architecture",security:"Security",reliability:"Reliability",ux:"User Experience",testability:"Testability",documentation:"Documentation",dependency:"Dependencies",workflow:"Workflow",other:"Other",features:"Features",competitive_analysis:"Competitive Analysis",research:"Research",trends:"Trends"};function hs(d){const o=d??"",S=`${we.INSIGHTS_PREFIX}${o}`,w=`${we.INSIGHT_LATEST_RUN_PREFIX}${o}`,p=te(S,{maxAgeMs:be}),B=te(w,{maxAgeMs:Se}),M=r.useRef(Array.isArray(p)&&p.length>0),[A,f]=r.useState(()=>Array.isArray(p)?p:[]),[I,X]=r.useState(()=>de.map(n=>({category:n,label:Ie[n]??n,items:[],isLoading:!1,error:null}))),[q,$]=r.useState(!(Array.isArray(p)&&p.length>0)),[W,G]=r.useState(null),[K,E]=r.useState(B??null),[ae,P]=r.useState(!1),[Y,F]=r.useState(null),[V,z]=r.useState(new Map),[J,_]=r.useState(new Map),[L,h]=r.useState(new Map),[R,g]=r.useState(new Map),[T,ne]=r.useState(!1),v=r.useCallback(async()=>{M.current||$(!0),G(null);try{const t=(await Xe({status:void 0,limit:1e3},d)).insights.filter(u=>u.status!=="dismissed");f(t),je(S,t.length>500?t.slice(0,500):t,{maxBytes:5e5});const s=await qe(d);s.runs.length>0&&(E(s.runs[0]),je(w,s.runs[0],{maxBytes:5e5})),M.current=!0}catch(n){const t=n instanceof Error?n.message:"Failed to fetch insights";G(t)}finally{$(!1)}},[S,w,d]),re=r.useCallback(()=>{ne(n=>!n)},[]),y=r.useCallback(async(n,t)=>{P(!0),F(null);try{const s=await We("manual",void 0,d,n,t);E(s),s.status==="completed"?await v():s.status==="failed"&&s.error&&F(s.error)}catch(s){if(s instanceof Ke&&s.status===409&&s.details?.code==="ACTIVE_RUN_CONFLICT"){const m=typeof s.details.activeRunId=="string"?s.details.activeRunId:null;if(m)try{const oe=await Ye(m,d);E(oe)}catch{}throw F("Insight generation is already running"),s}const u=s instanceof Error?s.message:"Failed to generate insights";throw F(u),s}finally{P(!1)}},[d,v]),Q=r.useCallback(async n=>{z(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{await Ve(n,d),f(t=>t.filter(s=>s.id!==n)),z(t=>{const s=new Map(t);return s.set(n,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to dismiss insight";throw z(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]),ce=r.useCallback(async n=>{_(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{const t=await Je(n,d);return await ke(n,d),f(s=>s.map(u=>u.id===n?{...u,status:"archived",updatedAt:new Date().toISOString()}:u)),_(s=>{const u=new Map(s);return u.set(n,{running:!1,error:null}),u}),{title:t.suggestedTitle,description:t.suggestedDescription}}catch(t){const s=t instanceof Error?t.message:"Failed to create task";throw _(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]);r.useEffect(()=>{const n=new Map;for(const t of de)n.set(t,[]);for(const t of A){if(!T&&t.status==="archived")continue;const s=n.get(t.category)??[];n.set(t.category,[...s,t])}X(de.map(t=>({category:t,label:Ie[t]??t,items:n.get(t)??[],isLoading:!1,error:null})))},[A,T]);const le=r.useCallback(async n=>{h(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{await ke(n,d),f(t=>t.map(s=>s.id===n?{...s,status:"archived",updatedAt:new Date().toISOString()}:s)),h(t=>{const s=new Map(t);return s.set(n,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to archive insight";throw h(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]),x=r.useCallback(async n=>{g(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{await Qe(n,d),f(t=>t.map(s=>s.id===n?{...s,status:"confirmed",updatedAt:new Date().toISOString()}:s)),g(t=>{const s=new Map(t);return s.set(n,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to unarchive insight";throw g(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]),U=r.useMemo(()=>I.reduce((n,t)=>n+t.items.length,0),[I]),b=r.useMemo(()=>0,[]),H=r.useMemo(()=>A.filter(n=>n.status==="archived").length,[A]);return r.useEffect(()=>{const n=te(S,{maxAgeMs:be}),t=te(w,{maxAgeMs:Se}),s=Array.isArray(n)&&n.length>0;f(Array.isArray(n)?n:[]),E(t??null),$(!s),M.current=s},[S,w]),r.useEffect(()=>{v()},[v]),{sections:I,loading:q,error:W,latestRun:K,isRunInFlight:ae,runError:Y,refresh:v,runInsights:y,dismiss:Q,createTask:ce,archive:le,unarchive:x,toggleShowArchived:re,dismissStates:V,createTaskStates:J,archiveStates:L,unarchiveStates:R,totalCount:U,dismissedCount:b,archivedCount:H,showArchived:T}}const Le=["Backlog health:","Backlog pressure detected","Stale paused todo","Backlog health: dependency-blocked todos"];function Ee(d){return Le.some(o=>d.title.startsWith(o))}const Fe={architecture:cs,quality:$e,workflow:_e,performance:Me,reliability:N,security:ie,ux:Ae,testability:ge,documentation:as,dependency:ze,features:is,competitive_analysis:Ae,research:os,trends:Me,other:C};function vs({projectId:d,addToast:o,onClose:S,onCreateTask:w,models:p}){const{sections:B,loading:M,error:A,latestRun:f,isRunInFlight:I,runError:X,refresh:q,runInsights:$,dismiss:W,createTask:G,archive:K=async()=>{},unarchive:E=async()=>{},toggleShowArchived:ae=()=>{},dismissStates:P,createTaskStates:Y,archiveStates:F=new Map,unarchiveStates:V=new Map,totalCount:z,archivedCount:J=0,showArchived:_=!1}=hs(d),[L,h]=r.useState(null),[R,g]=r.useState("info"),[T,ne]=r.useState(!1),[v,re]=r.useState(!1),[y,Q]=r.useState(()=>localStorage.getItem("fusion-insight-model")??""),[ce,le]=r.useState([]),[x,U]=r.useState([]),[b,H]=r.useState([]),[n,t]=r.useState();r.useEffect(()=>{p||Ze().then(i=>{le(i.models),U(i.favoriteProviders),H(i.favoriteModels),t(i.resolvedPlanningProvider);const a=localStorage.getItem("fusion-insight-model");a&&(i.models.some(l=>`${l.provider}/${l.id}`===a)||(localStorage.removeItem("fusion-insight-model"),Q("")))}).catch(()=>{})},[p]);const s=p??ce,u=r.useMemo(()=>x.length>0?x:n?[n]:[],[x,n]),m=r.useCallback(async i=>{const c=x.includes(i)?x.filter(l=>l!==i):[i,...x];U(c);try{await Ce({favoriteProviders:c,favoriteModels:b})}catch{U(x)}},[x,b]),oe=r.useCallback(async i=>{const c=b.includes(i)?b.filter(l=>l!==i):[i,...b];H(c);try{await Ce({favoriteProviders:x,favoriteModels:c})}catch{H(b)}},[b,x]),Te=r.useCallback(i=>{Q(i),i?localStorage.setItem("fusion-insight-model",i):localStorage.removeItem("fusion-insight-model")},[]),O=r.useMemo(()=>B.filter(i=>i.items.length>0),[B]),ue=r.useMemo(()=>O.reduce((i,a)=>i+a.items.filter(Ee).length,0),[O]),j=r.useMemo(()=>v?O.map(i=>({...i,items:i.items.filter(Ee)})).filter(i=>i.items.length>0):O,[O,v]),[D,he]=r.useState(null);r.useEffect(()=>{if(j.length===0){D!==null&&he(null);return}D&&j.some(a=>a.category===D&&a.items.length>0)||he(j[0].category)},[j,D]);const k=r.useMemo(()=>j.find(i=>i.category===D)??j[0],[j,D]);r.useEffect(()=>{if(L){const i=setTimeout(()=>h(null),5e3);return()=>clearTimeout(i)}},[L]);const me=r.useCallback(async()=>{try{h("Generating insights..."),g("info");let i,a;if(y){const c=y.indexOf("/");if(c!==-1){const l=y.slice(0,c),Z=y.slice(c+1);l&&Z&&(i=l,a=Z)}}await $(i,a),h("Insight generation started"),g("success"),o("Insight generation started","success")}catch(i){const a=i instanceof Error?i.message:"Failed to start generation";if(a==="Insight generation is already running"){h("Insight generation is already running. Showing the active run."),g("info"),o("Insight generation is already running","info");return}h(a),g("error"),o(a,"error")}},[$,o,y]),De=r.useCallback(async(i,a)=>{try{h(`Dismissing "${a}"...`),g("info"),await W(i),h(`Dismissed "${a}"`),g("success"),o(`Insight dismissed: ${a}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to dismiss insight";h(l),g("error"),o(l,"error")}},[W,o]),Ge=r.useCallback(async(i,a)=>{try{h(`Archiving "${a}"...`),g("info"),await K(i),h(`Archived "${a}"`),g("success"),o(`Insight archived: ${a}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to archive insight";h(l),g("error"),o(l,"error")}},[K,o]),Pe=r.useCallback(async(i,a)=>{try{h(`Unarchiving "${a}"...`),g("info"),await E(i),h(`Unarchived "${a}"`),g("success"),o(`Insight unarchived: ${a}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to unarchive insight";h(l),g("error"),o(l,"error")}},[E,o]),Ue=r.useCallback(async(i,a)=>{try{if(h(`Creating task from "${a}"...`),g("info"),!w)throw new Error("Task creation is unavailable in this view");const c=await G(i);if(!c)throw new Error("Failed to prepare task payload from insight");await w({insightId:i,title:c.title,description:c.description}),h(`Task created from "${a}"`),g("success"),o(`Task created: ${c.title}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to create task";h(l),g("error"),o(l,"error")}},[G,w,o]),He=i=>{const a=Fe[i.category]??C,c=k?.category===i.category;return e.jsx("li",{children:e.jsxs("button",{type:"button",className:`insights-category-item${c?" insights-category-item--active":""}`,onClick:()=>he(i.category),"aria-current":c?"true":void 0,"data-testid":`insights-category-${i.category}`,children:[e.jsx(a,{size:16,className:"insights-category-icon"}),e.jsx("span",{className:"insights-category-label",children:i.label}),e.jsx("span",{className:"insights-category-count",children:i.items.length})]})},i.category)},Oe=()=>{if(!k)return null;const i=Fe[k.category]??C;return e.jsxs("section",{className:"insights-section","data-testid":`insights-section-${k.category}`,children:[e.jsx("div",{className:"insights-section-header",children:e.jsxs("div",{className:"insights-section-title",children:[e.jsx(i,{size:20,className:"insights-section-icon"}),e.jsx("h3",{children:k.label}),e.jsx("span",{className:"insights-section-count",children:k.items.length})]})}),e.jsx("div",{className:"insights-section-content",children:e.jsx("ul",{className:"insights-list",children:k.items.map(a=>{const c=P.get(a.id),l=Y.get(a.id),Z=F.get(a.id),Be=V.get(a.id),fe=c?.running??!1,ve=l?.running??!1,xe=Z?.running??!1,ye=Be?.running??!1,pe=a.status==="archived",ee=k.items.some(se=>P.get(se.id)?.running||Y.get(se.id)?.running||F.get(se.id)?.running||V.get(se.id)?.running);return e.jsxs("li",{className:`insight-item${pe?" insight-item--archived":""}`,"data-insight-id":a.id,children:[e.jsxs("div",{className:"insight-item-header",children:[e.jsx("h4",{className:"insight-item-title",children:a.title}),e.jsxs("div",{className:"insight-item-actions",children:[pe?e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Pe(a.id,a.title),disabled:ye||ee,title:"Unarchive this insight","aria-label":"Unarchive this insight","data-testid":`unarchive-${a.id}`,children:ye?e.jsx(N,{size:20,className:"spin"}):e.jsx(ns,{size:20})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Ue(a.id,a.title),disabled:ve||ee,title:"Create task from this insight","aria-label":"Create task from this insight","data-testid":`create-task-${a.id}`,children:ve?e.jsx(N,{size:20,className:"spin"}):e.jsx(ze,{size:20})}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Ge(a.id,a.title),disabled:xe||ee,title:"Archive this insight","aria-label":"Archive this insight","data-testid":`archive-${a.id}`,children:xe?e.jsx(N,{size:20,className:"spin"}):e.jsx(ge,{size:20})})]}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void De(a.id,a.title),disabled:fe||ee,title:"Dismiss this insight","aria-label":"Dismiss this insight","data-testid":`dismiss-${a.id}`,children:fe?e.jsx(N,{size:20,className:"spin"}):e.jsx(Ne,{size:20})})]})]}),a.content&&e.jsx("p",{className:"insight-item-content",children:a.content}),e.jsxs("div",{className:"insight-item-meta",children:[e.jsx("span",{className:`insight-item-status insight-item-status--${a.status}`,children:a.status}),a.createdAt&&e.jsxs("span",{className:"insight-item-date",children:[e.jsx(_e,{size:12}),new Date(a.createdAt).toLocaleDateString()]})]})]},a.id)})})})]})};return e.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[e.jsxs("div",{className:"insights-view-header",children:[e.jsxs("div",{className:"insights-view-title",children:[e.jsxs("h2",{children:[e.jsx(C,{size:20}),"Insights"]}),e.jsxs("span",{className:"insights-view-count",children:[z," total"]})]}),e.jsxs("div",{className:"insights-view-actions",children:[ue>0&&e.jsxs("button",{className:`btn btn-sm insights-backlog-health-toggle${v?" btn-icon--active":""}`,onClick:()=>re(i=>!i),"aria-pressed":v,"aria-label":v?"Show all insights":"Show only backlog health insights","data-testid":"toggle-backlog-health",title:Le.join(", "),children:[e.jsx(es,{size:14}),v?"All Insights":"Backlog Health"," ",e.jsxs("span",{children:["(",ue,")"]})]}),S&&e.jsx("button",{className:"btn btn-sm insights-view-close",onClick:S,"aria-label":"Close insights view",title:"Close",children:e.jsx(Ne,{size:16})}),J>0&&e.jsxs("button",{className:"btn btn-sm insights-show-archived-toggle",onClick:ae,"aria-label":_?"Hide archived insights":"Show archived insights","data-testid":"toggle-archived-insights",children:[e.jsx(ge,{size:14}),_?"Hide Archived":`Show Archived (${J})`]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void q(),disabled:M,"aria-label":"Refresh insights","data-testid":"refresh-insights",children:[e.jsx(N,{size:14,className:M?"spin":""}),"Refresh"]}),e.jsxs("button",{className:"btn btn-sm insights-model-toggle",onClick:()=>ne(i=>!i),"aria-label":"Configure insight generation model","aria-expanded":T,"data-testid":"toggle-model-config",title:y?`Model: ${y}`:"Configure model",children:[e.jsx(ss,{size:14}),y&&e.jsx("span",{className:"insights-model-indicator"})]}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void me(),disabled:I,"aria-label":"Generate new insights","data-testid":"run-insights",children:I?e.jsxs(e.Fragment,{children:[e.jsx(N,{size:14,className:"spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(C,{size:14}),"Generate Insights"]})})]})]}),T&&e.jsxs("div",{className:"insights-model-config","data-testid":"model-config",children:[e.jsx("label",{htmlFor:"insight-model-select",className:"insights-model-label",children:"Model"}),e.jsx(ts,{models:s,value:y,onChange:Te,placeholder:"Use planning default",label:"Insight generation model",disabled:I,id:"insight-model-select",favoriteProviders:u,favoriteModels:b,onToggleFavorite:m,onToggleModelFavorite:oe})]}),e.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:L&&e.jsxs("div",{className:`insights-status-message insights-status-message--${R}`,role:R==="error"?"alert":void 0,children:[R==="success"&&e.jsx($e,{size:16}),R==="error"&&e.jsx(ie,{size:16}),R==="info"&&e.jsx(C,{size:16}),e.jsx("span",{children:L})]})}),X&&e.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[e.jsx(ie,{size:16}),e.jsx("span",{children:X})]}),f&&e.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:e.jsxs("span",{className:"insights-run-status",children:["Latest run: ",f.status,f.status==="completed"&&e.jsxs(e.Fragment,{children:[" — ",f.insightsCreated," created, ",f.insightsUpdated," updated"]}),f.status==="failed"&&f.error&&e.jsxs(e.Fragment,{children:[" — ",f.error]})]})}),M?e.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[e.jsx(N,{size:24,className:"spin"}),e.jsx("p",{children:"Loading insights..."})]}):A?e.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[e.jsx(ie,{size:24}),e.jsx("p",{children:A}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void q(),children:"Retry"})]}):z===0?e.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[e.jsx(C,{size:48}),e.jsx("h3",{children:"No insights yet"}),e.jsx("p",{children:"Generate insights to get AI-powered recommendations for your project."}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void me(),children:[e.jsx(C,{size:14}),"Generate First Insights"]})]}):e.jsxs("div",{className:"insights-body",children:[e.jsx("aside",{className:"insights-sidebar","aria-label":"Insight categories",children:e.jsx("ul",{className:"insights-category-list",children:j.map(He)})}),e.jsx("div",{className:"insights-detail",children:Oe()})]})]})}export{vs as InsightsView};
|
|
11
|
+
*/const ls=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],os=Re("chart-line",ls),de=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],Ie={quality:"Quality",performance:"Performance",architecture:"Architecture",security:"Security",reliability:"Reliability",ux:"User Experience",testability:"Testability",documentation:"Documentation",dependency:"Dependencies",workflow:"Workflow",other:"Other",features:"Features",competitive_analysis:"Competitive Analysis",research:"Research",trends:"Trends"};function hs(d){const o=d??"",S=`${we.INSIGHTS_PREFIX}${o}`,w=`${we.INSIGHT_LATEST_RUN_PREFIX}${o}`,p=te(S,{maxAgeMs:be}),B=te(w,{maxAgeMs:Se}),M=r.useRef(Array.isArray(p)&&p.length>0),[A,f]=r.useState(()=>Array.isArray(p)?p:[]),[I,X]=r.useState(()=>de.map(n=>({category:n,label:Ie[n]??n,items:[],isLoading:!1,error:null}))),[q,$]=r.useState(!(Array.isArray(p)&&p.length>0)),[W,G]=r.useState(null),[K,E]=r.useState(B??null),[ae,P]=r.useState(!1),[Y,F]=r.useState(null),[V,z]=r.useState(new Map),[J,_]=r.useState(new Map),[L,h]=r.useState(new Map),[R,g]=r.useState(new Map),[D,ne]=r.useState(!1),v=r.useCallback(async()=>{M.current||$(!0),G(null);try{const t=(await Xe({status:void 0,limit:1e3},d)).insights.filter(u=>u.status!=="dismissed");f(t),je(S,t.length>500?t.slice(0,500):t,{maxBytes:5e5});const s=await qe(d);s.runs.length>0&&(E(s.runs[0]),je(w,s.runs[0],{maxBytes:5e5})),M.current=!0}catch(n){const t=n instanceof Error?n.message:"Failed to fetch insights";G(t)}finally{$(!1)}},[S,w,d]),re=r.useCallback(()=>{ne(n=>!n)},[]),y=r.useCallback(async(n,t)=>{P(!0),F(null);try{const s=await We("manual",void 0,d,n,t);E(s),s.status==="completed"?await v():s.status==="failed"&&s.error&&F(s.error)}catch(s){if(s instanceof Ke&&s.status===409&&s.details?.code==="ACTIVE_RUN_CONFLICT"){const m=typeof s.details.activeRunId=="string"?s.details.activeRunId:null;if(m)try{const oe=await Ye(m,d);E(oe)}catch{}throw F("Insight generation is already running"),s}const u=s instanceof Error?s.message:"Failed to generate insights";throw F(u),s}finally{P(!1)}},[d,v]),Q=r.useCallback(async n=>{z(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{await Ve(n,d),f(t=>t.filter(s=>s.id!==n)),z(t=>{const s=new Map(t);return s.set(n,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to dismiss insight";throw z(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]),ce=r.useCallback(async n=>{_(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{const t=await Je(n,d);return await ke(n,d),f(s=>s.map(u=>u.id===n?{...u,status:"archived",updatedAt:new Date().toISOString()}:u)),_(s=>{const u=new Map(s);return u.set(n,{running:!1,error:null}),u}),{title:t.suggestedTitle,description:t.suggestedDescription}}catch(t){const s=t instanceof Error?t.message:"Failed to create task";throw _(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]);r.useEffect(()=>{const n=new Map;for(const t of de)n.set(t,[]);for(const t of A){if(!D&&t.status==="archived")continue;const s=n.get(t.category)??[];n.set(t.category,[...s,t])}X(de.map(t=>({category:t,label:Ie[t]??t,items:n.get(t)??[],isLoading:!1,error:null})))},[A,D]);const le=r.useCallback(async n=>{h(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{await ke(n,d),f(t=>t.map(s=>s.id===n?{...s,status:"archived",updatedAt:new Date().toISOString()}:s)),h(t=>{const s=new Map(t);return s.set(n,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to archive insight";throw h(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]),x=r.useCallback(async n=>{g(t=>{const s=new Map(t);return s.set(n,{running:!0,error:null}),s});try{await Qe(n,d),f(t=>t.map(s=>s.id===n?{...s,status:"confirmed",updatedAt:new Date().toISOString()}:s)),g(t=>{const s=new Map(t);return s.set(n,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to unarchive insight";throw g(u=>{const m=new Map(u);return m.set(n,{running:!1,error:s}),m}),t}},[d]),U=r.useMemo(()=>I.reduce((n,t)=>n+t.items.length,0),[I]),b=r.useMemo(()=>0,[]),H=r.useMemo(()=>A.filter(n=>n.status==="archived").length,[A]);return r.useEffect(()=>{const n=te(S,{maxAgeMs:be}),t=te(w,{maxAgeMs:Se}),s=Array.isArray(n)&&n.length>0;f(Array.isArray(n)?n:[]),E(t??null),$(!s),M.current=s},[S,w]),r.useEffect(()=>{v()},[v]),{sections:I,loading:q,error:W,latestRun:K,isRunInFlight:ae,runError:Y,refresh:v,runInsights:y,dismiss:Q,createTask:ce,archive:le,unarchive:x,toggleShowArchived:re,dismissStates:V,createTaskStates:J,archiveStates:L,unarchiveStates:R,totalCount:U,dismissedCount:b,archivedCount:H,showArchived:D}}const Le=["Backlog health:","Backlog pressure detected","Stale paused todo","Backlog health: dependency-blocked todos"];function Ee(d){return Le.some(o=>d.title.startsWith(o))}const Fe={architecture:cs,quality:$e,workflow:_e,performance:Me,reliability:N,security:ie,ux:Ae,testability:ge,documentation:as,dependency:ze,features:is,competitive_analysis:Ae,research:os,trends:Me,other:C};function vs({projectId:d,addToast:o,onClose:S,onCreateTask:w,models:p}){const{sections:B,loading:M,error:A,latestRun:f,isRunInFlight:I,runError:X,refresh:q,runInsights:$,dismiss:W,createTask:G,archive:K=async()=>{},unarchive:E=async()=>{},toggleShowArchived:ae=()=>{},dismissStates:P,createTaskStates:Y,archiveStates:F=new Map,unarchiveStates:V=new Map,totalCount:z,archivedCount:J=0,showArchived:_=!1}=hs(d),[L,h]=r.useState(null),[R,g]=r.useState("info"),[D,ne]=r.useState(!1),[v,re]=r.useState(!1),[y,Q]=r.useState(()=>localStorage.getItem("fusion-insight-model")??""),[ce,le]=r.useState([]),[x,U]=r.useState([]),[b,H]=r.useState([]),[n,t]=r.useState();r.useEffect(()=>{p||Ze().then(i=>{le(i.models),U(i.favoriteProviders),H(i.favoriteModels),t(i.resolvedPlanningProvider);const a=localStorage.getItem("fusion-insight-model");a&&(i.models.some(l=>`${l.provider}/${l.id}`===a)||(localStorage.removeItem("fusion-insight-model"),Q("")))}).catch(()=>{})},[p]);const s=p??ce,u=r.useMemo(()=>x.length>0?x:n?[n]:[],[x,n]),m=r.useCallback(async i=>{const c=x.includes(i)?x.filter(l=>l!==i):[i,...x];U(c);try{await Ce({favoriteProviders:c,favoriteModels:b})}catch{U(x)}},[x,b]),oe=r.useCallback(async i=>{const c=b.includes(i)?b.filter(l=>l!==i):[i,...b];H(c);try{await Ce({favoriteProviders:x,favoriteModels:c})}catch{H(b)}},[b,x]),De=r.useCallback(i=>{Q(i),i?localStorage.setItem("fusion-insight-model",i):localStorage.removeItem("fusion-insight-model")},[]),O=r.useMemo(()=>B.filter(i=>i.items.length>0),[B]),ue=r.useMemo(()=>O.reduce((i,a)=>i+a.items.filter(Ee).length,0),[O]),j=r.useMemo(()=>v?O.map(i=>({...i,items:i.items.filter(Ee)})).filter(i=>i.items.length>0):O,[O,v]),[T,he]=r.useState(null);r.useEffect(()=>{if(j.length===0){T!==null&&he(null);return}T&&j.some(a=>a.category===T&&a.items.length>0)||he(j[0].category)},[j,T]);const k=r.useMemo(()=>j.find(i=>i.category===T)??j[0],[j,T]);r.useEffect(()=>{if(L){const i=setTimeout(()=>h(null),5e3);return()=>clearTimeout(i)}},[L]);const me=r.useCallback(async()=>{try{h("Generating insights..."),g("info");let i,a;if(y){const c=y.indexOf("/");if(c!==-1){const l=y.slice(0,c),Z=y.slice(c+1);l&&Z&&(i=l,a=Z)}}await $(i,a),h("Insight generation started"),g("success"),o("Insight generation started","success")}catch(i){const a=i instanceof Error?i.message:"Failed to start generation";if(a==="Insight generation is already running"){h("Insight generation is already running. Showing the active run."),g("info"),o("Insight generation is already running","info");return}h(a),g("error"),o(a,"error")}},[$,o,y]),Te=r.useCallback(async(i,a)=>{try{h(`Dismissing "${a}"...`),g("info"),await W(i),h(`Dismissed "${a}"`),g("success"),o(`Insight dismissed: ${a}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to dismiss insight";h(l),g("error"),o(l,"error")}},[W,o]),Ge=r.useCallback(async(i,a)=>{try{h(`Archiving "${a}"...`),g("info"),await K(i),h(`Archived "${a}"`),g("success"),o(`Insight archived: ${a}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to archive insight";h(l),g("error"),o(l,"error")}},[K,o]),Pe=r.useCallback(async(i,a)=>{try{h(`Unarchiving "${a}"...`),g("info"),await E(i),h(`Unarchived "${a}"`),g("success"),o(`Insight unarchived: ${a}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to unarchive insight";h(l),g("error"),o(l,"error")}},[E,o]),Ue=r.useCallback(async(i,a)=>{try{if(h(`Creating task from "${a}"...`),g("info"),!w)throw new Error("Task creation is unavailable in this view");const c=await G(i);if(!c)throw new Error("Failed to prepare task payload from insight");await w({insightId:i,title:c.title,description:c.description}),h(`Task created from "${a}"`),g("success"),o(`Task created: ${c.title}`,"success")}catch(c){const l=c instanceof Error?c.message:"Failed to create task";h(l),g("error"),o(l,"error")}},[G,w,o]),He=i=>{const a=Fe[i.category]??C,c=k?.category===i.category;return e.jsx("li",{children:e.jsxs("button",{type:"button",className:`insights-category-item${c?" insights-category-item--active":""}`,onClick:()=>he(i.category),"aria-current":c?"true":void 0,"data-testid":`insights-category-${i.category}`,children:[e.jsx(a,{size:16,className:"insights-category-icon"}),e.jsx("span",{className:"insights-category-label",children:i.label}),e.jsx("span",{className:"insights-category-count",children:i.items.length})]})},i.category)},Oe=()=>{if(!k)return null;const i=Fe[k.category]??C;return e.jsxs("section",{className:"insights-section","data-testid":`insights-section-${k.category}`,children:[e.jsx("div",{className:"insights-section-header",children:e.jsxs("div",{className:"insights-section-title",children:[e.jsx(i,{size:20,className:"insights-section-icon"}),e.jsx("h3",{children:k.label}),e.jsx("span",{className:"insights-section-count",children:k.items.length})]})}),e.jsx("div",{className:"insights-section-content",children:e.jsx("ul",{className:"insights-list",children:k.items.map(a=>{const c=P.get(a.id),l=Y.get(a.id),Z=F.get(a.id),Be=V.get(a.id),fe=c?.running??!1,ve=l?.running??!1,xe=Z?.running??!1,ye=Be?.running??!1,pe=a.status==="archived",ee=k.items.some(se=>P.get(se.id)?.running||Y.get(se.id)?.running||F.get(se.id)?.running||V.get(se.id)?.running);return e.jsxs("li",{className:`insight-item${pe?" insight-item--archived":""}`,"data-insight-id":a.id,children:[e.jsxs("div",{className:"insight-item-header",children:[e.jsx("h4",{className:"insight-item-title",children:a.title}),e.jsxs("div",{className:"insight-item-actions",children:[pe?e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Pe(a.id,a.title),disabled:ye||ee,title:"Unarchive this insight","aria-label":"Unarchive this insight","data-testid":`unarchive-${a.id}`,children:ye?e.jsx(N,{size:20,className:"spin"}):e.jsx(ns,{size:20})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Ue(a.id,a.title),disabled:ve||ee,title:"Create task from this insight","aria-label":"Create task from this insight","data-testid":`create-task-${a.id}`,children:ve?e.jsx(N,{size:20,className:"spin"}):e.jsx(ze,{size:20})}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Ge(a.id,a.title),disabled:xe||ee,title:"Archive this insight","aria-label":"Archive this insight","data-testid":`archive-${a.id}`,children:xe?e.jsx(N,{size:20,className:"spin"}):e.jsx(ge,{size:20})})]}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Te(a.id,a.title),disabled:fe||ee,title:"Dismiss this insight","aria-label":"Dismiss this insight","data-testid":`dismiss-${a.id}`,children:fe?e.jsx(N,{size:20,className:"spin"}):e.jsx(Ne,{size:20})})]})]}),a.content&&e.jsx("p",{className:"insight-item-content",children:a.content}),e.jsxs("div",{className:"insight-item-meta",children:[e.jsx("span",{className:`insight-item-status insight-item-status--${a.status}`,children:a.status}),a.createdAt&&e.jsxs("span",{className:"insight-item-date",children:[e.jsx(_e,{size:12}),new Date(a.createdAt).toLocaleDateString()]})]})]},a.id)})})})]})};return e.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[e.jsxs("div",{className:"insights-view-header",children:[e.jsxs("div",{className:"insights-view-title",children:[e.jsxs("h2",{children:[e.jsx(C,{size:20}),"Insights"]}),e.jsxs("span",{className:"insights-view-count",children:[z," total"]})]}),e.jsxs("div",{className:"insights-view-actions",children:[ue>0&&e.jsxs("button",{className:`btn btn-sm insights-backlog-health-toggle${v?" btn-icon--active":""}`,onClick:()=>re(i=>!i),"aria-pressed":v,"aria-label":v?"Show all insights":"Show only backlog health insights","data-testid":"toggle-backlog-health",title:Le.join(", "),children:[e.jsx(es,{size:14}),v?"All Insights":"Backlog Health"," ",e.jsxs("span",{children:["(",ue,")"]})]}),S&&e.jsx("button",{className:"btn btn-sm insights-view-close",onClick:S,"aria-label":"Close insights view",title:"Close",children:e.jsx(Ne,{size:16})}),J>0&&e.jsxs("button",{className:"btn btn-sm insights-show-archived-toggle",onClick:ae,"aria-label":_?"Hide archived insights":"Show archived insights","data-testid":"toggle-archived-insights",children:[e.jsx(ge,{size:14}),_?"Hide Archived":`Show Archived (${J})`]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void q(),disabled:M,"aria-label":"Refresh insights","data-testid":"refresh-insights",children:[e.jsx(N,{size:14,className:M?"spin":""}),"Refresh"]}),e.jsxs("button",{className:"btn btn-sm insights-model-toggle",onClick:()=>ne(i=>!i),"aria-label":"Configure insight generation model","aria-expanded":D,"data-testid":"toggle-model-config",title:y?`Model: ${y}`:"Configure model",children:[e.jsx(ss,{size:14}),y&&e.jsx("span",{className:"insights-model-indicator"})]}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void me(),disabled:I,"aria-label":"Generate new insights","data-testid":"run-insights",children:I?e.jsxs(e.Fragment,{children:[e.jsx(N,{size:14,className:"spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(C,{size:14}),"Generate Insights"]})})]})]}),D&&e.jsxs("div",{className:"insights-model-config","data-testid":"model-config",children:[e.jsx("label",{htmlFor:"insight-model-select",className:"insights-model-label",children:"Model"}),e.jsx(ts,{models:s,value:y,onChange:De,placeholder:"Use planning default",label:"Insight generation model",disabled:I,id:"insight-model-select",favoriteProviders:u,favoriteModels:b,onToggleFavorite:m,onToggleModelFavorite:oe})]}),e.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:L&&e.jsxs("div",{className:`insights-status-message insights-status-message--${R}`,role:R==="error"?"alert":void 0,children:[R==="success"&&e.jsx($e,{size:16}),R==="error"&&e.jsx(ie,{size:16}),R==="info"&&e.jsx(C,{size:16}),e.jsx("span",{children:L})]})}),X&&e.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[e.jsx(ie,{size:16}),e.jsx("span",{children:X})]}),f&&e.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:e.jsxs("span",{className:"insights-run-status",children:["Latest run: ",f.status,f.status==="completed"&&e.jsxs(e.Fragment,{children:[" — ",f.insightsCreated," created, ",f.insightsUpdated," updated"]}),f.status==="failed"&&f.error&&e.jsxs(e.Fragment,{children:[" — ",f.error]})]})}),M?e.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[e.jsx(N,{size:24,className:"spin"}),e.jsx("p",{children:"Loading insights..."})]}):A?e.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[e.jsx(ie,{size:24}),e.jsx("p",{children:A}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void q(),children:"Retry"})]}):z===0?e.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[e.jsx(C,{size:48}),e.jsx("h3",{children:"No insights yet"}),e.jsx("p",{children:"Generate insights to get AI-powered recommendations for your project."}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void me(),children:[e.jsx(C,{size:14}),"Generate First Insights"]})]}):e.jsxs("div",{className:"insights-body",children:[e.jsx("aside",{className:"insights-sidebar","aria-label":"Insight categories",children:e.jsx("ul",{className:"insights-category-list",children:j.map(He)})}),e.jsx("div",{className:"insights-detail",children:Oe()})]})]})}export{vs as InsightsView};
|