@runfusion/fusion 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +8488 -6999
- package/dist/client/assets/{AgentDetailView-BMrHuWGs.css → AgentDetailView-C1b9PC5l.css} +1 -1
- package/dist/client/assets/{AgentDetailView-CBdzWtd-.js → AgentDetailView-CJIxNRq-.js} +3 -3
- package/dist/client/assets/{AgentsView-DPlnCa_B.js → AgentsView-BS17exn3.js} +5 -5
- package/dist/client/assets/ChatView-BUlq3WNJ.js +1 -0
- package/dist/client/assets/{DevServerView-BY5cGz23.js → DevServerView-qMPpnXRb.js} +2 -2
- package/dist/client/assets/DirectoryPicker-CTwgv9LY.js +1 -0
- package/dist/client/assets/DirectoryPicker-DzKVmxOf.css +1 -0
- package/dist/client/assets/{DocumentsView-lQwJmc4G.js → DocumentsView-DOz1KFGN.js} +1 -1
- package/dist/client/assets/{InsightsView-DUiZZ0z8.js → InsightsView-CHZTJUic.js} +2 -2
- package/dist/client/assets/MemoryView-V0QdeO3e.js +2 -0
- package/dist/client/assets/{NodesView-DgyM-ktg.js → NodesView-BtGNRj2z.js} +1 -1
- package/dist/client/assets/PiExtensionsManager-D9Ye2Vak.js +11 -0
- package/dist/client/assets/PiExtensionsManager-kgTOHPE9.css +1 -0
- package/dist/client/assets/PluginManager-DRiIqol2.css +1 -0
- package/dist/client/assets/PluginManager-LeHp0jJ_.js +1 -0
- package/dist/client/assets/{RoadmapsView-ANn2jmsU.js → RoadmapsView-C413ISVU.js} +2 -2
- package/dist/client/assets/SettingsModal--vWmKBpT.css +1 -0
- package/dist/client/assets/SettingsModal-BZLL2xAP.js +31 -0
- package/dist/client/assets/SettingsModal-CDWvhvrd.css +1 -0
- package/dist/client/assets/SettingsModal-olTBmYJs.js +1 -0
- package/dist/client/assets/SetupWizardModal-BMa6p24b.css +1 -0
- package/dist/client/assets/{SetupWizardModal-UxlAtKWA.js → SetupWizardModal-WdaR2eQQ.js} +1 -1
- package/dist/client/assets/SkillsView-BcE57w8i.js +1 -0
- package/dist/client/assets/{folder-open-J7yPbaCt.js → folder-open-Ec4hU1xL.js} +1 -1
- package/dist/client/assets/index-CCYdhck-.js +616 -0
- package/dist/client/assets/index-lJ5WOmO9.css +1 -0
- package/dist/client/assets/{upload-B_grq4hM.js → upload-BksRDuGJ.js} +1 -1
- package/dist/client/assets/users-EFU4n9Qr.js +6 -0
- package/dist/client/index.html +2 -2
- package/dist/extension.js +1271 -205
- package/dist/pi-claude-cli/index.ts +72 -28
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/pi-claude-cli/src/__tests__/event-bridge.test.ts +34 -0
- package/dist/pi-claude-cli/src/__tests__/mcp-config.test.ts +22 -0
- package/dist/pi-claude-cli/src/__tests__/prompt-builder.test.ts +72 -10
- package/dist/pi-claude-cli/src/__tests__/provider.test.ts +9 -9
- package/dist/pi-claude-cli/src/event-bridge.ts +17 -6
- package/dist/pi-claude-cli/src/mcp-config.ts +36 -3
- package/dist/pi-claude-cli/src/prompt-builder.ts +111 -7
- package/dist/pi-claude-cli/src/provider.ts +18 -2
- package/package.json +6 -5
- package/skill/fusion/SKILL.md +6 -1
- package/skill/fusion/references/engine-tools.md +54 -0
- package/skill/fusion/references/extension-tools.md +83 -84
- package/skill/fusion/references/fusion-capabilities.md +33 -31
- package/dist/client/assets/ChatView-BXzYysNG.js +0 -1
- package/dist/client/assets/DirectoryPicker-DZ90eSBn.js +0 -1
- package/dist/client/assets/MemoryView-DvSmMN6G.js +0 -2
- package/dist/client/assets/PiExtensionsManager-K7HQ08L4.css +0 -1
- package/dist/client/assets/PiExtensionsManager-wxB-q06A.js +0 -11
- package/dist/client/assets/PluginManager-LH02ybSH.js +0 -1
- package/dist/client/assets/PluginManager-tCFMZMLL.css +0 -1
- package/dist/client/assets/SkillsView-DEjGh7wW.js +0 -1
- package/dist/client/assets/index-BdJsO65L.css +0 -1
- package/dist/client/assets/index-CHoVMPAA.js +0 -649
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,
|
|
1
|
+
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bm as Me,bn as de,bo as et,bp as ue,s as Ue,bq as ge,br as we,bs as xe,bt as ye,bu as tt,bv as ae,bw as rt,bx as st,by as nt,bz as at,bA as it,bB as ie,L as ee,S as lt,bC as ct,bD as ot,K as dt,T as Ae,bE as ut,E as vt,aJ as mt,a3 as ft,ah as pt,R as ht}from"./index-CCYdhck-.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,4 +8,4 @@ import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{c as De,bo as Me,bp as d
|
|
|
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 wt=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Pe=De("shield-alert",wt),ve=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Te(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Te([...e,i])}function I(e){try{return JSON.parse(e)}catch{return null}}function Q(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function Ne(e){return rt(e)}async function Se(e,i){return st(e,i)}async function Nt(e){return nt(e)}async function St(e){return at(e)}async function ke(e){return it(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>Me)=="function"}function W(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),[b,y]=r.useState([]),[w,f]=r.useState([]),[j,M]=r.useState([]),[C,P]=r.useState(!0),[N,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Q);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await Me(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),R(s[0]))}else{const s=await Ne(e);if(n.current!==a)return;const c=W(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),M([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Ne(e).then(S=>[W(S)]),typeof V(()=>ae)=="function"?ae(e):ke(e).then(S=>S.map(g=>({name:g.name,command:g.command,cwd:g.cwd,scriptName:g.scriptName,packagePath:g.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const S=c.value;if(y(S),S.length>0){const g=S[0];ce()&&U(g.config.id),R(g)}}else v=B(c.reason);l.status==="fulfilled"&&M(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?et(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=I(l.data);if(v?.lines){const S=v.lines.map(Q);f(Te(S))}},log:l=>{if(n.current!==s)return;const v=I(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:log":l=>{if(n.current!==s)return;const v=I(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:output":l=>{if(n.current!==s)return;const v=I(l.data);v?.line&&f(S=>le(S,v.line))},status:l=>{if(n.current!==s)return;const v=I(l.data),S=v?.status;S&&o(g=>g&&{...g,status:S,runtime:v.pid?{...g.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:g.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=I(l.data);if(v?.status){const S=W(v);o(S),y([S])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},xt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>ge)=="function")l=await ge(d,e);else{const v=await Se({command:a,cwd:s},e);l=W(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await Nt(e);s=W(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(()=>xe)=="function")s=await xe(d,e);else{const c=await St(e);s=W(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(()=>ye)=="function")c=await ye(d,a,e);else{const l=await tt({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await ke(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;M(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,S=await Se({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),g=W(S);o(g),y([g]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await k()},[k]),z=r.useCallback(async a=>{await T(a)},[T]),$=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=yt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:b,logs:w,detectedCommands:j,previewUrl:H,isLoading:C,error:N,startServer:_,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:A,candidates:j,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:$,refreshStatus:O}}const je=500,Ce=100;function ze(e){return e.length>je?e.slice(-je):e}function Fe(e){return e==="stderr"?"stderr":"stdout"}function Y(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:Fe(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function jt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],b=new Set(e.map(y=>y.id));for(const y of i)b.has(y.id)||(b.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),ze(o)}function Ct(e,i){const[o,b]=r.useState([]),[y,w]=r.useState(!1),[f,j]=r.useState(!1),[M,C]=r.useState(!1),[P,N]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,b([]),w(!1),j(!1),C(!1),N(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++U.current;n.current=!1,w(!0);const z=(x,a)=>{const s=ze(x);b(s),N(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},$=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>jt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:Fe(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),b(v=>oe(v,[l])),N(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||U.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||U.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&U.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=Y(a);s&&O(s)},log:a=>{const s=Y(a);s&&O(s)},history:a=>{const s=Y(a);$(s)},"dev-server:history":a=>{const s=Y(a);$(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}b(c=>oe(c,s)),N(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;j(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const $=z.lines.map((O,H)=>Z(O,H+1));b(O=>oe($,O)),C(z.totalLines>L+$.length),N(z.totalLines)}catch{}finally{j(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{b([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:M,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:b=null}=i,y=r.useRef(null),w=r.useRef(null),[f,j]=r.useState("unknown"),[M,C]=r.useState(null),[P]=r.useState(b),N=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,N()}},[N,e]),r.useEffect(()=>{if(f!=="loading"){N();return}const k=setTimeout(()=>{w.current=null,n()},o);return w.current=k,()=>{clearTimeout(k),w.current===k&&(w.current=null)}},[N,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(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[N]);const R=r.useCallback(()=>{N(),j("unknown"),C(null)},[N]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:M,detectionMethod:P,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:M,handleIframeLoad:d,handleIframeError:U}}const Mt=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(Mt,"")}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 At(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Tt(e,i){if(!i)return e;const o=new RegExp(`(${At(i)})`,"ig"),b=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:b.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:b,total:y,onLoadMore:w,isRunning:f}){const j=r.useRef(null),M=r.useRef(e.length),C=r.useRef(f),[P,N]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Pt(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=M.current,L=e.length>E;f&&(!p||!u&&L)&&T(),C.current=f,M.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);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(ee,{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:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(lt,{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:()=>N(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ct,{size:14}):t.jsx(ot,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[b&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref: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.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:Tt(E,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(dt,{size:14}),"New logs"]})]})]})}const Ft="devserver-preview-iframe";function $t({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:b,blockReason:y,onRetry:w,className:f=Ft,embedContext:j}){const M=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(d=>d+1),o("loading"))},[i,o,e]);const N=r.useCallback(()=>{const d=b.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[b,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:b,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:N,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(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"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function $e(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?$e(e.cwd)===o:!0}function Ot(e){return e.cwd==="."?"root":e.cwd}function Bt(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Wt({addToast:e,projectId:i}){const{session:o,detectedCommands:b,previewUrl:y,isLoading:w,error:f,startServer:j,stopServer:M,restartServer:C,setPreviewUrl:P,detectCommands:N,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,$]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),S=l==="embedded"?h:null,{embedStatus:g,setEmbedStatus:Oe,resetEmbedStatus:X,iframeRef:G,isEmbedded:Be,isBlocked:te,blockReason:re,retry:fe}=Dt(S),[pe,q]=r.useState(!1),he=r.useRef(g);r.useEffect(()=>{const m=he.current!==g;te&&m&&q(!0),g==="embedded"&&q(!1),he.current=g},[g,te]),r.useEffect(()=>{q(!1)},[h]);const J=r.useMemo(()=>{if(!x)return null;const m=Re(p);return b.find(F=>!(F.scriptName!==x||m&&F.cwd!==m||o?.config?.command&&F.command!==o.config.command))??b.find(F=>_e(F,x,p))??null},[b,o?.config?.command,x,p]);r.useEffect(()=>{typeof N=="function"&&N().catch(m=>{e(Le(m),"error")})},[e,N]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&$(o.config.command);return}if(J){$(J.command);return}b.length>0&&$(m=>m.trim().length>0?m:b[0]?.command??"")},[b,J,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),be=r.useCallback(()=>{q(!1),fe()},[fe]),He=r.useCallback(()=>{try{const m=G.current;if(m?.contentWindow){m.contentWindow.location.reload(),q(!1),X();return}}catch{}if(!(!h||!G.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),G.current.src=m.toString(),q(!1),X()}catch{G.current.src=h,q(!1),X()}},[h,G,X]),K=r.useCallback(async(m,F,ne)=>{c(m);try{await F(),e(ne,"success")}catch(Ze){e(Le(Ze),"error")}finally{c(null)}},[e]),Ve=r.useCallback(m=>{a(m.scriptName),L(!1),$(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const F=Re(p)??".",ne=J?.cwd??F;K("start",()=>j(m,ne),"Dev server started.")},Ge=()=>{K("stop",M,"Dev server stopped.")},Ie=()=>{K("restart",C,"Dev server restarted.")},Xe=()=>{const m=O.trim(),F=m.length>0?m:null;K("preview",()=>P(F),F?"Preview URL updated.":"Preview URL override cleared.")},Je=r.useCallback(()=>{f&&u()},[f,u]),Ke=n==="starting"||n==="running"||s!==null,Qe=n==="stopped"||s!==null,Ye=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(ut,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${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:We,disabled:Ke,"data-testid":"dev-server-start-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ge,disabled:Qe,"data-testid":"dev-server-stop-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Ie,disabled:Ye,"data-testid":"dev-server-restart-button",children:[t.jsx(gt,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&b.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Je,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:qe,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&b.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&b.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:b.map(m=>{const F=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${F?"dev-server-candidate--selected":""}`,onClick:()=>Ve(m),"data-testid":`dev-server-candidate-${m.scriptName}-${$e(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children: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:Xe,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.jsxs("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??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:R,loading:A,loadingMore:_,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(ft,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(pt,{size:14})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:He,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(ht,{size:14})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":g,"data-embedded":Be?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:g==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[g==="error"?t.jsx(Ae,{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:g==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:be,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx($t,{url:h,embedStatus:g,onEmbedStatusChange:Oe,iframeRef:G,blockReason:re,onRetry:be})]})]})]})]})}export{Wt as DevServerView};
|
|
11
|
+
*/const wt=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Pe=De("shield-alert",wt),ve=500,xt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Te(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Te([...e,i])}function X(e){try{return JSON.parse(e)}catch{return null}}function Q(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function yt(e){return e?.previewUrl??null}async function Ne(e){return rt(e)}async function Se(e,i){return st(e,i)}async function Nt(e){return nt(e)}async function St(e){return at(e)}async function ke(e){return it(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>Me)=="function"}function W(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),[b,y]=r.useState([]),[w,f]=r.useState([]),[j,M]=r.useState([]),[C,P]=r.useState(!0),[N,u]=r.useState(null),n=r.useRef(0),[d,U]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Q);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await Me(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(U(s[0].config.id),R(s[0]))}else{const s=await Ne(e);if(n.current!==a)return;const c=W(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),M([]),P(!0),u(null),U(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Ne(e).then(S=>[W(S)]),typeof V(()=>ae)=="function"?ae(e):ke(e).then(S=>S.map(g=>({name:g.name,command:g.command,cwd:g.cwd,scriptName:g.scriptName,packagePath:g.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const S=c.value;if(y(S),S.length>0){const g=S[0];ce()&&U(g.config.id),R(g)}}else v=B(c.reason);l.status==="fulfilled"&&M(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?et(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=X(l.data);if(v?.lines){const S=v.lines.map(Q);f(Te(S))}},log:l=>{if(n.current!==s)return;const v=X(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:log":l=>{if(n.current!==s)return;const v=X(l.data);if(v){const S=typeof v.line=="string"?v.line:Q(v);f(g=>le(g,S))}},"dev-server:output":l=>{if(n.current!==s)return;const v=X(l.data);v?.line&&f(S=>le(S,v.line))},status:l=>{if(n.current!==s)return;const v=X(l.data),S=v?.status;S&&o(g=>g&&{...g,status:S,runtime:v.pid?{...g.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:g.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=X(l.data);if(v?.status){const S=W(v);o(S),y([S])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},xt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>ge)=="function")l=await ge(d,e);else{const v=await Se({command:a,cwd:s},e);l=W(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await Nt(e);s=W(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(()=>xe)=="function")s=await xe(d,e);else{const c=await St(e);s=W(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(()=>ye)=="function")c=await ye(d,a,e);else{const l=await tt({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await ke(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;M(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,S=await Se({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),g=W(S);o(g),y([g]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await k()},[k]),z=r.useCallback(async a=>{await T(a)},[T]),F=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=yt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:b,logs:w,detectedCommands:j,previewUrl:H,isLoading:C,error:N,startServer:_,stopServer:D,restartServer:k,setPreviewUrl:T,detectCommands:h,refresh:A,candidates:j,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:F,refreshStatus:O}}const je=500,Ce=100;function ze(e){return e.length>je?e.slice(-je):e}function $e(e){return e==="stderr"?"stderr":"stdout"}function Y(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:$e(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function jt(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],b=new Set(e.map(y=>y.id));for(const y of i)b.has(y.id)||(b.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),ze(o)}function Ct(e,i){const[o,b]=r.useState([]),[y,w]=r.useState(!1),[f,j]=r.useState(!1),[M,C]=r.useState(!1),[P,N]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),U=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,b([]),w(!1),j(!1),C(!1),N(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++U.current;n.current=!1,w(!0);const z=(x,a)=>{const s=ze(x);b(s),N(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},F=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>jt(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:$e(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),b(v=>oe(v,[l])),N(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||U.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||U.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&U.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=Y(a);s&&O(s)},log:a=>{const s=Y(a);s&&O(s)},history:a=>{const s=Y(a);F(s)},"dev-server:history":a=>{const s=Y(a);F(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}b(c=>oe(c,s)),N(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;j(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const F=z.lines.map((O,H)=>Z(O,H+1));b(O=>oe(F,O)),C(z.totalLines>L+F.length),N(z.totalLines)}catch{}finally{j(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{b([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:M,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:b=null}=i,y=r.useRef(null),w=r.useRef(null),[f,j]=r.useState("unknown"),[M,C]=r.useState(null),[P]=r.useState(b),N=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(k=>{j(k),C(_t(k))},[]),n=r.useCallback(()=>{j("blocked"),C(Rt)},[]);r.useEffect(()=>{if(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null);let k=!1;return queueMicrotask(()=>{k||(j("loading"),C(null))}),()=>{k=!0,N()}},[N,e]),r.useEffect(()=>{if(f!=="loading"){N();return}const k=setTimeout(()=>{w.current=null,n()},o);return w.current=k,()=>{clearTimeout(k),w.current===k&&(w.current=null)}},[N,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(N(),!e){j("unknown"),C(null);return}j("unknown"),C(null)},[N]);const R=r.useCallback(()=>{N(),j("unknown"),C(null)},[N]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:M,detectionMethod:P,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:M,handleIframeLoad:d,handleIframeError:U}}const Mt=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(Mt,"")}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 At(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pt(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Tt(e,i){if(!i)return e;const o=new RegExp(`(${At(i)})`,"ig"),b=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:b.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function zt({entries:e,loading:i,loadingMore:o,hasMore:b,total:y,onLoadMore:w,isRunning:f}){const j=r.useRef(null),M=r.useRef(e.length),C=r.useRef(f),[P,N]=r.useState(!1),[u,n]=r.useState(!1),[d,U]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Pt(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),k=D.length,T=r.useCallback(()=>{const p=j.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=M.current,L=e.length>E;f&&(!p||!u&&L)&&T(),C.current=f,M.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=j.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);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(ee,{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:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(lt,{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:()=>N(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(ct,{size:14}):t.jsx(ot,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[b&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref: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.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=Ut(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:Tt(E,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(dt,{size:14}),"New logs"]})]})]})}const $t="devserver-preview-iframe";function Ft({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:b,blockReason:y,onRetry:w,className:f=$t,embedContext:j}){const M=y??j??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(d=>d+1),o("loading"))},[i,o,e]);const N=r.useCallback(()=>{const d=b.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[b,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:b,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:N,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(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"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),M&&t.jsx("p",{className:"devserver-preview-blocked-context",children:M})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function Fe(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?Fe(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 Wt({addToast:e,projectId:i}){const{session:o,detectedCommands:b,previewUrl:y,isLoading:w,error:f,startServer:j,stopServer:M,restartServer:C,setPreviewUrl:P,detectCommands:N,refresh:u}=kt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",U=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:k,loadMore:T}=Ct(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,F]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),S=l==="embedded"?h:null,{embedStatus:g,setEmbedStatus:Oe,resetEmbedStatus:G,iframeRef:I,isEmbedded:Be,isBlocked:te,blockReason:re,retry:fe}=Dt(S),[pe,q]=r.useState(!1),he=r.useRef(g);r.useEffect(()=>{const m=he.current!==g;te&&m&&q(!0),g==="embedded"&&q(!1),he.current=g},[g,te]),r.useEffect(()=>{q(!1)},[h]);const J=r.useMemo(()=>{if(!x)return null;const m=Re(p);return b.find($=>!($.scriptName!==x||m&&$.cwd!==m||o?.config?.command&&$.command!==o.config.command))??b.find($=>_e($,x,p))??null},[b,o?.config?.command,x,p]);r.useEffect(()=>{typeof N=="function"&&N().catch(m=>{e(Le(m),"error")})},[e,N]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&F(o.config.command);return}if(J){F(J.command);return}b.length>0&&F(m=>m.trim().length>0?m:b[0]?.command??"")},[b,J,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),be=r.useCallback(()=>{q(!1),fe()},[fe]),He=r.useCallback(()=>{try{const m=I.current;if(m?.contentWindow){m.contentWindow.location.reload(),q(!1),G();return}}catch{}if(!(!h||!I.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),I.current.src=m.toString(),q(!1),G()}catch{I.current.src=h,q(!1),G()}},[h,I,G]),K=r.useCallback(async(m,$,ne)=>{c(m);try{await $(),e(ne,"success")}catch(Ze){e(Le(Ze),"error")}finally{c(null)}},[e]),Ve=r.useCallback(m=>{a(m.scriptName),L(!1),F(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),qe=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const $=Re(p)??".",ne=J?.cwd??$;K("start",()=>j(m,ne),"Dev server started.")},Ie=()=>{K("stop",M,"Dev server stopped.")},Xe=()=>{K("restart",C,"Dev server restarted.")},Ge=()=>{const m=O.trim(),$=m.length>0?m:null;K("preview",()=>P($),$?"Preview URL updated.":"Preview URL override cleared.")},Je=r.useCallback(()=>{f&&u()},[f,u]),Ke=n==="starting"||n==="running"||s!==null,Qe=n==="stopped"||s!==null,Ye=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(ut,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${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:We,disabled:Ke,"data-testid":"dev-server-start-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ie,disabled:Qe,"data-testid":"dev-server-stop-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Xe,disabled:Ye,"data-testid":"dev-server-restart-button",children:[t.jsx(gt,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&b.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Je,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:qe,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&b.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&b.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:b.map(m=>{const $=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${$?"dev-server-candidate--selected":""}`,onClick:()=>Ve(m),"data-testid":`dev-server-candidate-${m.scriptName}-${Fe(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=>F(m.target.value),placeholder:"pnpm dev","data-testid":"dev-server-command-input",readOnly:n==="running"||n==="starting"})]}),(n==="running"||n==="starting")&&o&&t.jsxs("div",{className:"dev-server-current-command","data-testid":"dev-server-current-command",children:[t.jsx("span",{className:"dev-server-label",children:"Running command"}),t.jsx("code",{children:o.config?.command??z})]}),t.jsxs("div",{className:"dev-server-preview-override",children:[t.jsx("label",{htmlFor:"dev-server-preview-input",className:"dev-server-label",children:"Preview URL Override"}),t.jsx("input",{id:"dev-server-preview-input",className:"input",type:"url",value:O,onChange:m=>H(m.target.value),placeholder:"http://localhost:3000","data-testid":"dev-server-preview-input"}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ge,disabled:s==="preview","data-testid":"dev-server-set-preview",children:"Save"})]}),h&&t.jsxs("p",{className:"dev-server-preview-hint",children:["Auto-detected: ",h]})]}),t.jsxs("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??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(zt,{entries:R,loading:A,loadingMore:_,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(ft,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(pt,{size:14})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:He,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(ht,{size:14})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":g,"data-embedded":Be?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:g==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[g==="error"?t.jsx(Ae,{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:g==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:be,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx(Ft,{url:h,embedStatus:g,onEmbedStatusChange:Oe,iframeRef:I,blockReason:re,onRetry:be})]})]})]})]})}export{Wt as DevServerView};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{cN as f,c1 as m,D as y,a7 as g,a2 as P,a3 as C,L as H,ae as O}from"./index-CCYdhck-.js";import{F as v}from"./folder-open-Ec4hU1xL.js";function S({value:d,onChange:l,placeholder:x,onInputKeyDown:j,nodeId:h,localNodeId:p}){const[e,n]=i.useState({isOpen:!1,loading:!1,error:null,currentPath:"",parentPath:null,entries:[],showHidden:!1}),a=i.useCallback(async(s,c=!1)=>{n(t=>({...t,loading:!0,error:null}));try{const t=await f(s,c,h,p);n(b=>({...b,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(b=>({...b,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[h,p]),k=i.useCallback(()=>{n(s=>s.isOpen?{...s,isOpen:!1}:{...s,isOpen:!0})},[]);i.useEffect(()=>{e.isOpen&&!e.loading&&e.entries.length===0&&!e.error&&a(d||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,d,e.showHidden,a,h,p]);const o=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),w=i.useCallback(()=>{l(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,l]),N=i.useCallback(()=>{n(s=>{const c=!s.showHidden;return{...s,showHidden:c}})},[]);i.useEffect(()=>{e.isOpen&&e.currentPath&&a(e.currentPath,e.showHidden)},[e.showHidden]);const u=e.currentPath?e.currentPath.split("/").filter(Boolean):[];return r.jsxs("div",{className:"directory-picker",children:[r.jsxs("div",{className:"directory-picker-input-row",children:[r.jsx("input",{type:"text",className:"input directory-picker-input",value:d,onChange:s=>l(s.target.value),onKeyDown:j,placeholder:x||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:k,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(v,{size:16}):r.jsx(m,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsxs("div",{className:"directory-picker-breadcrumbs",children:[r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o("/"),title:"Root",children:"/"}),u.map((s,c)=>{const t="/"+u.slice(0,c+1).join("/");return r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>o(t),title:t,children:s})]},t)})]}),r.jsxs("div",{className:"directory-picker-toolbar",children:[e.parentPath&&r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-up-btn",onClick:()=>o(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(g,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:N,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(P,{size:14}):r.jsx(C,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(H,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(O,{size:16}),r.jsx("span",{children:e.error})]}):r.jsx("div",{className:"directory-picker-entries",children:e.entries.length===0?r.jsx("div",{className:"directory-picker-empty",children:"No subdirectories"}):e.entries.map(s=>r.jsxs("button",{type:"button",className:"directory-picker-entry",onClick:()=>o(s.path),role:"treeitem",title:s.path,children:[r.jsx(m,{size:16,className:"directory-picker-entry-icon"}),r.jsx("span",{className:"directory-picker-entry-name",children:s.name}),s.hasChildren&&r.jsx(y,{size:14,className:"directory-picker-entry-arrow"})]},s.path))}),r.jsxs("div",{className:"directory-picker-actions",children:[r.jsx("span",{className:"directory-picker-selected-path",title:e.currentPath,children:e.currentPath}),r.jsx("button",{type:"button",className:"btn btn-primary directory-picker-select-btn",onClick:w,children:"Select"})]})]})]})}export{S as D};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.directory-picker{display:flex;flex-direction:column;gap:var(--space-sm)}.directory-picker-input-row{display:flex;gap:var(--space-sm)}.directory-picker-input{flex:1;min-width:0}.directory-picker-browse-btn{flex-shrink:0;white-space:nowrap}.directory-picker-browser{display:flex;flex-direction:column;background:var(--card);border:1px solid var(--border);border-radius:var(--radius-lg);overflow:hidden;animation:fadeIn var(--transition-fast)}.directory-picker-breadcrumbs{display:flex;align-items:center;gap:var(--space-xs);padding:var(--space-sm) var(--space-md);background:var(--surface);border-bottom:1px solid var(--border);overflow-x:auto;white-space:nowrap}.directory-picker-breadcrumb{background:none;border:none;padding:var(--space-xs);border-radius:var(--radius-sm);color:var(--todo);cursor:pointer;font-family:var(--font-mono)}.directory-picker-breadcrumb:hover{background:var(--card-hover);text-decoration:underline}.directory-picker-breadcrumb:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.directory-picker-breadcrumb-item{display:inline-flex;align-items:center}.directory-picker-breadcrumb-sep{color:var(--text-dim);flex-shrink:0}.directory-picker-toolbar{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-xs) var(--space-md);border-bottom:1px solid var(--border)}.directory-picker-up-btn,.directory-picker-hidden-toggle{color:var(--text-muted)}.directory-picker-up-btn:hover,.directory-picker-hidden-toggle:hover{color:var(--text)}.directory-picker-up-btn:focus-visible,.directory-picker-hidden-toggle:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.directory-picker-entries{max-height:calc(var(--space-2xl) * 8);overflow-y:auto;padding:var(--space-xs) 0}.directory-picker-entry{display:flex;align-items:center;gap:var(--space-sm);width:100%;padding:var(--space-xs) var(--space-md);background:none;border:none;color:var(--text);cursor:pointer;text-align:left;transition:background-color var(--transition-fast)}.directory-picker-entry:hover{background:var(--card-hover)}.directory-picker-entry:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.directory-picker-entry-icon{color:var(--todo);flex-shrink:0}.directory-picker-entry-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.directory-picker-entry-arrow{color:var(--text-dim);flex-shrink:0}.directory-picker-loading,.directory-picker-empty{display:flex;align-items:center;justify-content:center;gap:var(--space-sm);padding:var(--space-xl);color:var(--text-muted)}.directory-picker-error{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-md);margin:var(--space-sm) var(--space-md);background:color-mix(in srgb,var(--color-error) 10%,transparent);border:1px solid var(--color-error);border-radius:var(--radius-md);color:var(--color-error)}.directory-picker-actions{display:flex;align-items:center;justify-content:space-between;gap:var(--space-md);padding:var(--space-sm) var(--space-md);border-top:1px solid var(--border);background:var(--surface)}.directory-picker-selected-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--font-mono);color:var(--text-muted)}.directory-picker-select-btn{flex-shrink:0;padding:var(--space-sm) var(--space-lg)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{Y as oe,$ as G,a0 as le,a1 as ie,F as z,a2 as de,a3 as ue,S as me,X as he,R as pe,a4 as fe,a5 as W,a6 as V,K as X,D as je,a7 as xe}from"./index-CHoVMPAA.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?G(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await G(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function Y(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:Y(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:_,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:J,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?J:_,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,K=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:K,value:l,onChange:Z,"aria-label":K}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",Y(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
|
|
1
|
+
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{Y as oe,$ as G,a0 as le,a1 as ie,F as z,a2 as de,a3 as ue,S as me,X as he,R as pe,a4 as fe,a5 as W,a6 as V,K as X,D as je,a7 as xe}from"./index-CCYdhck-.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?G(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await G(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function Y(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:Y(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:_,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:J,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?J:_,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,K=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:K,value:l,onChange:Z,"aria-label":K}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",Y(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 as V,aa as W,ab as X,ac as J,ad as x,X as T,R as j,C as q,ae as F,af as G,ag as
|
|
1
|
+
import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 as V,aa as W,ab as X,ac as J,ad as x,X as T,R as j,C as q,ae as F,af as G,ag as K,w as B,ah as Z,ai as ss,aj as P}from"./index-CCYdhck-.js";import{U as _}from"./users-EFU4n9Qr.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,4 +8,4 @@ import{r as c,j as s}from"./vendor-react-K0fH_qHe.js";import{c as U,a8 as Q,a9 a
|
|
|
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 is=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],as=U("chart-line",is),A=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],O={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 ns(h){const[l,b]=c.useState(()=>A.map(t=>({category:t,label:O[t]??t,items:[],isLoading:!1,error:null}))),[k,S]=c.useState(!0),[N,v]=c.useState(null),[u,w]=c.useState(null),[M,C]=c.useState(!1),[I,p]=c.useState(null),[R,f]=c.useState(new Map),[z,y]=c.useState(new Map),m=c.useCallback(async()=>{S(!0),v(null);try{const t=await Q({status:void 0,limit:1e3},h),a=new Map;for(const i of A)a.set(i,[]);for(const i of t.insights)if(i.status!=="dismissed"){const r=a.get(i.category)??[];a.set(i.category,[...r,i])}b(A.map(i=>({category:i,label:O[i]??i,items:a.get(i)??[],isLoading:!1,error:null})));const e=await V(h);e.runs.length>0&&w(e.runs[0])}catch(t){const a=t instanceof Error?t.message:"Failed to fetch insights";v(a)}finally{S(!1)}},[h]),o=c.useCallback(async()=>{C(!0),p(null);try{const t=await W("manual",void 0,h);w(t),t.status==="completed"?await m():t.status==="failed"&&t.error&&p(t.error)}catch(t){const a=t instanceof Error?t.message:"Failed to generate insights";throw p(a),t}finally{C(!1)}},[h,m]),g=c.useCallback(async t=>{f(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{await X(t,h),b(a=>a.map(e=>({...e,items:e.items.filter(i=>i.id!==t)}))),f(a=>{const e=new Map(a);return e.set(t,{running:!1,error:null}),e})}catch(a){const e=a instanceof Error?a.message:"Failed to dismiss insight";throw f(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),d=c.useCallback(async t=>{y(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{const a=await J(t,h);return y(e=>{const i=new Map(e);return i.set(t,{running:!1,error:null}),i}),{title:a.suggestedTitle,description:a.suggestedDescription}}catch(a){const e=a instanceof Error?a.message:"Failed to create task";throw y(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),E=c.useMemo(()=>l.reduce((t,a)=>t+a.items.length,0),[l]),D=c.useMemo(()=>0,[l]);return c.useMemo(()=>{m()},[]),{sections:l,loading:k,error:N,latestRun:u,isRunInFlight:M,runError:I,refresh:m,runInsights:o,dismiss:g,createTask:d,dismissStates:R,createTaskStates:z,totalCount:E,dismissedCount:D}}const rs={architecture:ts,quality:q,workflow:P,performance:G,reliability:j,security:F,ux:_,testability:ss,documentation:Z,dependency:B,features:K,competitive_analysis:_,research:as,trends:G,other:x};function
|
|
11
|
+
*/const is=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],as=U("chart-line",is),A=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],O={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 ns(h){const[l,b]=c.useState(()=>A.map(t=>({category:t,label:O[t]??t,items:[],isLoading:!1,error:null}))),[k,S]=c.useState(!0),[N,v]=c.useState(null),[u,w]=c.useState(null),[M,C]=c.useState(!1),[I,p]=c.useState(null),[R,f]=c.useState(new Map),[z,y]=c.useState(new Map),m=c.useCallback(async()=>{S(!0),v(null);try{const t=await Q({status:void 0,limit:1e3},h),a=new Map;for(const i of A)a.set(i,[]);for(const i of t.insights)if(i.status!=="dismissed"){const r=a.get(i.category)??[];a.set(i.category,[...r,i])}b(A.map(i=>({category:i,label:O[i]??i,items:a.get(i)??[],isLoading:!1,error:null})));const e=await V(h);e.runs.length>0&&w(e.runs[0])}catch(t){const a=t instanceof Error?t.message:"Failed to fetch insights";v(a)}finally{S(!1)}},[h]),o=c.useCallback(async()=>{C(!0),p(null);try{const t=await W("manual",void 0,h);w(t),t.status==="completed"?await m():t.status==="failed"&&t.error&&p(t.error)}catch(t){const a=t instanceof Error?t.message:"Failed to generate insights";throw p(a),t}finally{C(!1)}},[h,m]),g=c.useCallback(async t=>{f(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{await X(t,h),b(a=>a.map(e=>({...e,items:e.items.filter(i=>i.id!==t)}))),f(a=>{const e=new Map(a);return e.set(t,{running:!1,error:null}),e})}catch(a){const e=a instanceof Error?a.message:"Failed to dismiss insight";throw f(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),d=c.useCallback(async t=>{y(a=>{const e=new Map(a);return e.set(t,{running:!0,error:null}),e});try{const a=await J(t,h);return y(e=>{const i=new Map(e);return i.set(t,{running:!1,error:null}),i}),{title:a.suggestedTitle,description:a.suggestedDescription}}catch(a){const e=a instanceof Error?a.message:"Failed to create task";throw y(i=>{const r=new Map(i);return r.set(t,{running:!1,error:e}),r}),a}},[h]),E=c.useMemo(()=>l.reduce((t,a)=>t+a.items.length,0),[l]),D=c.useMemo(()=>0,[l]);return c.useMemo(()=>{m()},[]),{sections:l,loading:k,error:N,latestRun:u,isRunInFlight:M,runError:I,refresh:m,runInsights:o,dismiss:g,createTask:d,dismissStates:R,createTaskStates:z,totalCount:E,dismissedCount:D}}const rs={architecture:ts,quality:q,workflow:P,performance:G,reliability:j,security:F,ux:_,testability:ss,documentation:Z,dependency:B,features:K,competitive_analysis:_,research:as,trends:G,other:x};function ds({projectId:h,addToast:l,onClose:b,onCreateTask:k}){const{sections:S,loading:N,error:v,latestRun:u,isRunInFlight:w,runError:M,refresh:C,runInsights:I,dismiss:p,createTask:R,dismissStates:f,createTaskStates:z,totalCount:y}=ns(h),[m,o]=c.useState(null),[g,d]=c.useState("info");c.useEffect(()=>{if(m){const e=setTimeout(()=>o(null),5e3);return()=>clearTimeout(e)}},[m]);const E=c.useCallback(async()=>{try{o("Generating insights..."),d("info"),await I(),o("Insight generation started"),d("success"),l("Insight generation started","success")}catch(e){const i=e instanceof Error?e.message:"Failed to start generation";o(i),d("error"),l(i,"error")}},[I,l]),D=c.useCallback(async(e,i)=>{try{o(`Dismissing "${i}"...`),d("info"),await p(e),o(`Dismissed "${i}"`),d("success"),l(`Insight dismissed: ${i}`,"success")}catch(r){const n=r instanceof Error?r.message:"Failed to dismiss insight";o(n),d("error"),l(n,"error")}},[p,l]),t=c.useCallback(async(e,i)=>{try{o(`Creating task from "${i}"...`),d("info");const r=await R(e);r&&k&&k(r.title,r.description),o(`Task created from "${i}"`),d("success"),l(`Task created: ${r?.title??i}`,"success")}catch(r){const n=r instanceof Error?r.message:"Failed to create task";o(n),d("error"),l(n,"error")}},[R,k,l]),a=e=>{const i=rs[e.category]??x,r=e.items.some(n=>f.get(n.id)?.running||z.get(n.id)?.running)??!1;return s.jsxs("section",{className:"insights-section","data-testid":`insights-section-${e.category}`,children:[s.jsx("div",{className:"insights-section-header",children:s.jsxs("div",{className:"insights-section-title",children:[s.jsx(i,{size:18,className:"insights-section-icon"}),s.jsx("h3",{children:e.label}),s.jsx("span",{className:"insights-section-count",children:e.items.length})]})}),s.jsx("div",{className:"insights-section-content",children:e.items.length===0?s.jsx("div",{className:"insights-empty-section","data-testid":`insights-empty-${e.category}`,children:s.jsx("p",{children:"No insights in this category"})}):s.jsx("ul",{className:"insights-list",children:e.items.map(n=>{const Y=f.get(n.id),H=z.get(n.id),L=Y?.running??!1,$=H?.running??!1;return s.jsxs("li",{className:"insight-item","data-insight-id":n.id,children:[s.jsxs("div",{className:"insight-item-header",children:[s.jsx("h4",{className:"insight-item-title",children:n.title}),s.jsxs("div",{className:"insight-item-actions",children:[s.jsx("button",{className:"btn btn-sm btn-icon",onClick:()=>void t(n.id,n.title),disabled:$||r,title:"Create task from this insight","aria-label":"Create task from this insight","data-testid":`create-task-${n.id}`,children:$?s.jsx(j,{size:14,className:"spin"}):s.jsx(B,{size:14})}),s.jsx("button",{className:"btn btn-sm btn-icon",onClick:()=>void D(n.id,n.title),disabled:L||r,title:"Dismiss this insight","aria-label":"Dismiss this insight","data-testid":`dismiss-${n.id}`,children:L?s.jsx(j,{size:14,className:"spin"}):s.jsx(T,{size:14})})]})]}),n.content&&s.jsx("p",{className:"insight-item-content",children:n.content}),s.jsxs("div",{className:"insight-item-meta",children:[s.jsx("span",{className:`insight-item-status insight-item-status--${n.status}`,children:n.status}),n.createdAt&&s.jsxs("span",{className:"insight-item-date",children:[s.jsx(P,{size:12}),new Date(n.createdAt).toLocaleDateString()]})]})]},n.id)})})})]},e.category)};return s.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[s.jsxs("div",{className:"insights-view-header",children:[s.jsxs("div",{className:"insights-view-title",children:[s.jsxs("h2",{children:[s.jsx(x,{size:20}),"Insights"]}),s.jsxs("span",{className:"insights-view-count",children:[y," total"]})]}),s.jsxs("div",{className:"insights-view-actions",children:[b&&s.jsx("button",{className:"btn btn-icon insights-view-close",onClick:b,"aria-label":"Close insights view",children:s.jsx(T,{size:16})}),s.jsxs("button",{className:"btn btn-sm",onClick:()=>void C(),disabled:N,"aria-label":"Refresh insights","data-testid":"refresh-insights",children:[s.jsx(j,{size:14,className:N?"spin":""}),"Refresh"]}),s.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void E(),disabled:w,"aria-label":"Generate new insights","data-testid":"run-insights",children:w?s.jsxs(s.Fragment,{children:[s.jsx(j,{size:14,className:"spin"}),"Generating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(x,{size:14}),"Generate Insights"]})})]})]}),s.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:m&&s.jsxs("div",{className:`insights-status-message insights-status-message--${g}`,role:g==="error"?"alert":void 0,children:[g==="success"&&s.jsx(q,{size:16}),g==="error"&&s.jsx(F,{size:16}),g==="info"&&s.jsx(x,{size:16}),s.jsx("span",{children:m})]})}),M&&s.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[s.jsx(F,{size:16}),s.jsx("span",{children:M})]}),u&&s.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:s.jsxs("span",{className:"insights-run-status",children:["Latest run: ",u.status,u.status==="completed"&&s.jsxs(s.Fragment,{children:[" — ",u.insightsCreated," created, ",u.insightsUpdated," updated"]}),u.status==="failed"&&u.error&&s.jsxs(s.Fragment,{children:[" — ",u.error]})]})}),N?s.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[s.jsx(j,{size:24,className:"spin"}),s.jsx("p",{children:"Loading insights..."})]}):v?s.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[s.jsx(F,{size:24}),s.jsx("p",{children:v}),s.jsx("button",{className:"btn btn-sm",onClick:()=>void C(),children:"Retry"})]}):y===0?s.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[s.jsx(x,{size:48}),s.jsx("h3",{children:"No insights yet"}),s.jsx("p",{children:"Generate insights to get AI-powered recommendations for your project."}),s.jsxs("button",{className:"btn btn-primary",onClick:()=>void E(),children:[s.jsx(x,{size:14}),"Generate First Insights"]})]}):s.jsx("div",{className:"insights-sections",children:S.map(a)})]})}export{ds as InsightsView};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{u as Ae}from"./SettingsModal-olTBmYJs.js";import{b8 as Se,b9 as Ne,ba as Fe,o as ze,bb as De,bc as Ie,bd as Le,be as Ce,bf as Ee,bg as Re,bh as Te,bi as ke,bj as We,n as qe,bk as Pe,L as A,bl as Me}from"./index-CCYdhck-.js";import"./vendor-xterm-DzcZoU0P.js";const U=".fusion/memory/MEMORY.md",_e=5e4,Oe="0 3 * * *",Ue="0 4 * * *";function me(l){return{memoryEnabled:l.memoryEnabled!==!1,memoryAutoSummarizeEnabled:l.memoryAutoSummarizeEnabled??!1,memoryAutoSummarizeThresholdChars:l.memoryAutoSummarizeThresholdChars??_e,memoryAutoSummarizeSchedule:l.memoryAutoSummarizeSchedule??Oe,memoryDreamsEnabled:l.memoryDreamsEnabled??!1,memoryDreamsSchedule:l.memoryDreamsSchedule??Ue}}function we(l,t){return l.some(o=>o.path===t)?t:l.find(o=>o.path===U)?.path??l[0]?.path??U}function Qe(l={}){const{projectId:t}=l,[o,b]=a.useState(""),[F,E]=a.useState(!0),[S,N]=a.useState(!1),[y,g]=a.useState(!1),[r,p]=a.useState(null),[Q,J]=a.useState(!0),[X,z]=a.useState(!1),[f,T]=a.useState(()=>me({})),[k,ee]=a.useState(!0),[oe,B]=a.useState(!1),[c,v]=a.useState([]),[se,D]=a.useState(!0),[m,C]=a.useState(U),[W,u]=a.useState(""),[d,te]=a.useState(!1),[H,x]=a.useState(!1),[ae,$]=a.useState(!1),[ne,Y]=a.useState(!1),[G,q]=a.useState(null),[M,P]=a.useState(!0),[ce,I]=a.useState(!1),[de,V]=a.useState(!1),[re,Z]=a.useState(null),{status:K,loading:j,refresh:ie}=Ae({projectId:t}),L=a.useCallback(n=>{u(n),x(!0)},[]),_=a.useCallback(async n=>{te(!0);try{const{content:s}=await Se(n,t);C(n),u(s),x(!1)}finally{te(!1)}},[t]),w=a.useCallback(async()=>{D(!0);try{const{files:n}=await Ne(t);if(v(n),n.length===0){C(U),u(""),x(!1);return}const s=we(n,m);s!==m&&await _(s)}finally{D(!1)}},[t,m,_]);a.useEffect(()=>{let n=!1;async function s(){try{const i=await We(t);n||(b(i.content),E(!1))}catch{n||(b(""),E(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const i=await Ee(t);n||(p(i.content),z(i.exists),J(!1))}catch{n||(p(null),z(!1),J(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){ee(!0);try{const i=await qe(t);n||T(me(i))}catch{n||T(me({}))}finally{n||ee(!1)}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){D(!0);try{const{files:i}=await Ne(t);if(n)return;if(v(i),i.length===0){C(U),u(""),x(!1);return}const h=we(i,m),{content:je}=await Se(h,t);if(n)return;C(h),u(je),x(!1)}catch{n||(v([]),C(U),u(""),x(!1))}finally{n||D(!1)}}return s(),()=>{n=!0}},[t,m]),a.useEffect(()=>{let n=!1;async function s(){try{const i=await Ce(t);n||(q(i),P(!1))}catch{n||(q(null),P(!1))}}return s(),()=>{n=!0}},[t]),a.useEffect(()=>{let n=!1;async function s(){try{const i=await Pe(t);n||Z(i)}catch{n||Z(null)}}return s(),()=>{n=!0}},[t]);const le=a.useCallback(n=>{b(n),N(!0)},[]),he=a.useCallback(async()=>{if(S){g(!0);try{await Fe(o,t),N(!1)}finally{g(!1)}}},[o,S,t]),ue=a.useCallback(async n=>{B(!0);try{const s=await ze(n,t);T(me(s))}finally{B(!1)}},[t]),ye=a.useCallback(async n=>{await _(n)},[_]),ge=a.useCallback(async()=>{if(H){$(!0);try{await De(m,W,t),x(!1),await w()}finally{$(!1)}}},[W,H,m,t,w]),pe=a.useCallback(async()=>{V(!0);try{const n=await Ie(t);return await ie(),n}finally{V(!1)}},[t,ie]),xe=a.useCallback(async n=>Le(n,t),[t]),O=a.useCallback(async()=>{try{const n=await Ce(t);q(n)}catch{q(null)}},[t]),R=a.useCallback(async()=>{try{const n=await Ee(t);p(n.content),z(n.exists)}catch{p(null),z(!1)}},[t]),be=a.useCallback(async n=>{await Re(n,t),await R()},[t,R]),fe=a.useCallback(async()=>{Y(!0);try{const n=await Te(t);return await Promise.all([R(),O()]),{success:n.success,summary:n.summary}}finally{Y(!1)}},[t,R,O]),ve=a.useCallback(async n=>{I(!0);try{const s=n?await ke(n,t):await ke(t);if(n){const i=s.path??n;C(i),u(s.content),x(!1),await w();return}b(s.content),N(!0)}finally{I(!1)}},[t,w]);return{workingMemory:o,workingMemoryLoading:F,workingMemoryDirty:S,setWorkingMemory:le,saveWorkingMemory:he,savingWorkingMemory:y,insightsContent:r,insightsLoading:Q,insightsExists:X,refreshInsights:R,saveInsights:be,memorySettings:f,settingsLoading:k,savingMemorySettings:oe,saveMemorySettings:ue,memoryFiles:c,memoryFilesLoading:se,selectedFilePath:m,selectedFileContent:W,selectedFileLoading:d,selectedFileDirty:H,setSelectedFileContent:L,selectFile:ye,saveSelectedFile:ge,savingSelectedFile:ae,reloadMemoryFiles:w,backendStatus:K,backendLoading:j,extractInsights:fe,extracting:ne,auditReport:G,auditLoading:M,refreshAudit:O,compactMemory:ve,compacting:ce,installQmdAction:pe,installingQmd:de,testRetrieval:xe,stats:re}}const Be={Patterns:"pattern",Principles:"principle",Conventions:"convention",Pitfalls:"pitfall",Context:"context"},He={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},$e={"long-term":"Curated durable decisions, conventions, constraints, and pitfalls promoted from dreams.",daily:"Raw daily observations, open loops, and running context for dream processing.",dreams:"Synthesized patterns and open loops promoted from daily memory."};function Ye(l){if(!l)return[];const t=[],o=l.split(/(?=^## )/m);for(const b of o){const F=b.trim();if(!F)continue;const E=F.match(/^##\s+(.+?)(\n|$)/);if(E){const S=E[1].trim(),N=Be[S]??S.toLowerCase(),y=F.slice(E[0].length).trim(),g=y.split(`
|
|
2
|
+
`).map(r=>r.replace(/^-\s+/,"").trim()).filter(r=>r.length>0&&(r.startsWith("- ")||r.startsWith("* ")));(g.length>0||y.length>0)&&t.push({name:S,key:N,items:g.length>0?g:y.length>0?[y]:[],expanded:!0})}}return t}function Ge(l){if(!l)return null;const t=l.match(/##\s+Last\s+Updated:\s*(\d{4}-\d{2}-\d{2})/i);return t?t[1]:null}function Ve(l){return l.reduce((t,o)=>t+o.items.length,0)}function Ze(l){switch(l){case"file":return"File (.fusion/memory/)";case"readonly":return"Read-Only";case"qmd":return"QMD (Quantized Memory Distillation)";default:return l}}function Ke(l){switch(l){case"healthy":return"Healthy";case"warning":return"Warning";case"issues":return"Issues Found"}}function ts({projectId:l,addToast:t}){const[o,b]=a.useState("working"),[F,E]=a.useState(new Set),[S,N]=a.useState(!1),[y,g]=a.useState(null),[r,p]=a.useState({memoryEnabled:!0,memoryAutoSummarizeEnabled:!1,memoryAutoSummarizeThresholdChars:5e4,memoryAutoSummarizeSchedule:"0 3 * * *",memoryDreamsEnabled:!1,memoryDreamsSchedule:"0 4 * * *"}),[Q,J]=a.useState(""),[X,z]=a.useState(!1),[f,T]=a.useState(null),{insightsContent:k,insightsLoading:ee,insightsExists:oe,saveInsights:B,memorySettings:c,settingsLoading:v,saveMemorySettings:se,savingMemorySettings:D,backendStatus:m,backendLoading:C,extractInsights:W,extracting:u,auditReport:d,auditLoading:te,refreshAudit:H,compactMemory:x,compacting:ae,installQmdAction:$,installingQmd:ne,testRetrieval:Y,memoryFiles:G,memoryFilesLoading:q,selectedFilePath:M,selectedFileContent:P,selectedFileLoading:ce,selectedFileDirty:I,setSelectedFileContent:de,selectFile:V,saveSelectedFile:re,savingSelectedFile:Z}=Qe({projectId:l});a.useEffect(()=>{p(c)},[c]);const K=a.useMemo(()=>r.memoryEnabled!==c.memoryEnabled||r.memoryAutoSummarizeEnabled!==c.memoryAutoSummarizeEnabled||r.memoryAutoSummarizeThresholdChars!==c.memoryAutoSummarizeThresholdChars||r.memoryAutoSummarizeSchedule!==c.memoryAutoSummarizeSchedule||r.memoryDreamsEnabled!==c.memoryDreamsEnabled||r.memoryDreamsSchedule!==c.memoryDreamsSchedule,[r,c]),j=a.useMemo(()=>G.find(s=>s.path===M),[G,M]),ie=j?$e[j.layer]:"Edits the selected memory file.",L=a.useMemo(()=>Ye(k),[k]),_=a.useMemo(()=>Ve(L),[L]),w=a.useMemo(()=>Ge(k),[k]),le=a.useCallback(s=>{E(i=>{const h=new Set(i);return h.has(s)?h.delete(s):h.add(s),h})},[]),he=a.useCallback(async s=>{try{await V(s)}catch{t("Failed to load memory file","error")}},[V,t]),ue=a.useCallback(async()=>{try{await re(),t("Memory saved","success")}catch{t("Failed to save memory","error")}},[re,t]),ye=a.useCallback(async()=>{if(!K)return;const s={};r.memoryEnabled!==c.memoryEnabled&&(s.memoryEnabled=r.memoryEnabled),r.memoryAutoSummarizeEnabled!==c.memoryAutoSummarizeEnabled&&(s.memoryAutoSummarizeEnabled=r.memoryAutoSummarizeEnabled),r.memoryAutoSummarizeThresholdChars!==c.memoryAutoSummarizeThresholdChars&&(s.memoryAutoSummarizeThresholdChars=r.memoryAutoSummarizeThresholdChars),r.memoryAutoSummarizeSchedule!==c.memoryAutoSummarizeSchedule&&(s.memoryAutoSummarizeSchedule=r.memoryAutoSummarizeSchedule),r.memoryDreamsEnabled!==c.memoryDreamsEnabled&&(s.memoryDreamsEnabled=r.memoryDreamsEnabled),r.memoryDreamsSchedule!==c.memoryDreamsSchedule&&(s.memoryDreamsSchedule=r.memoryDreamsSchedule);try{await se(s),t("Memory settings saved","success")}catch{t("Failed to save memory settings","error")}},[K,r,c,se,t]),ge=a.useCallback(async()=>{try{const s=await $();t(s.qmdAvailable?"qmd installed successfully":"qmd install finished, but qmd is still unavailable",s.qmdAvailable?"success":"info")}catch{t("Failed to install qmd","error")}},[$,t]),pe=a.useCallback(async()=>{z(!0),T(null);try{const s=await Y(Q);T(s),t(s.qmdAvailable?"Memory retrieval test complete":"qmd is not installed; local fallback was used",s.qmdAvailable?"success":"info")}catch{t("Failed to test memory retrieval","error")}finally{z(!1)}},[Q,Y,t]),xe=a.useCallback(async()=>{try{await x(M),t("Memory file compacted","success")}catch{t("Failed to compact memory","error")}},[x,M,t]),O=a.useCallback(async()=>{try{const s=await W();t(s.summary,"success")}catch(s){t(s instanceof Error?s.message:"Failed to extract insights","error")}},[W,t]),R=a.useCallback(async()=>{if(y!==null)try{await B(y),N(!1),g(null),t("Insights saved","success")}catch{t("Failed to save insights","error")}},[y,B,t]),be=a.useCallback(()=>{g(k??""),N(!0)},[k]),fe=a.useCallback(()=>{N(!1),g(null)},[]),ve=!C&&m!==null,n=m?.capabilities?.writable??!1;return e.jsxs("div",{className:"memory-view",children:[e.jsx("div",{className:"memory-view-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Memory"}),e.jsx("p",{className:"memory-view-description",children:"Working memory, long-term insights, and engine status"})]})}),e.jsxs("div",{className:"memory-view-tabs",role:"tablist",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":o==="working",className:`memory-view-tab${o==="working"?" memory-view-tab--active":""}`,onClick:()=>b("working"),"data-testid":"memory-tab-working",children:"Working Memory"}),e.jsx("button",{type:"button",role:"tab","aria-selected":o==="insights",className:`memory-view-tab${o==="insights"?" memory-view-tab--active":""}`,onClick:()=>b("insights"),"data-testid":"memory-tab-insights",children:"Insights"}),e.jsx("button",{type:"button",role:"tab","aria-selected":o==="engines",className:`memory-view-tab${o==="engines"?" memory-view-tab--active":""}`,onClick:()=>b("engines"),"data-testid":"memory-tab-engines",children:"Engines"})]}),e.jsxs("div",{className:"memory-view-content",children:[o==="working"&&e.jsxs("div",{className:"memory-working-tab",children:[ve&&!n&&e.jsx("div",{className:"memory-readonly-banner",children:"This memory backend is read-only. Changes cannot be saved."}),q||ce?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading memory file…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-editor-section",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryViewFilePath",children:"Memory File"}),e.jsx("select",{id:"memoryViewFilePath",className:"select",value:M,onChange:s=>{he(s.target.value)},disabled:I,children:G.map(s=>e.jsxs("option",{value:s.path,children:[s.label," - ",s.path]},s.path))}),e.jsx("small",{children:I?"Save or discard the current edits before switching files.":"Choose any project memory file to view or edit."})]}),j&&e.jsxs("div",{className:"memory-file-summary",children:[e.jsx("span",{children:He[j.layer]}),e.jsx("strong",{children:j.path}),e.jsxs("small",{children:[j.size.toLocaleString()," bytes · updated ",new Date(j.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:j?.label||"Memory Editor"}),e.jsx("small",{children:ie}),e.jsx("div",{className:"memory-editor-container",children:e.jsx(Me,{content:P,onChange:de,readOnly:!n,filePath:M})})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsxs("span",{className:"memory-char-count",children:[P.length," characters"]}),e.jsx("div",{style:{flex:1}}),n&&P.length>0&&e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:xe,disabled:ae||I,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Compacting…"]}):"Compact Selected File"}),I&&n&&e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ue,disabled:Z,children:Z?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Saving…"]}):"Save"})]}),e.jsxs("div",{className:"memory-config-section",children:[e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:"memoryDreamsEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryDreamsEnabled",type:"checkbox",checked:r.memoryDreamsEnabled,onChange:s=>{p(i=>({...i,memoryDreamsEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Process dreams from daily memory"]}),e.jsx("small",{children:"Turns daily notes into DREAMS.md and promotes reusable lessons into MEMORY.md."})]}),r.memoryEnabled&&r.memoryDreamsEnabled&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryDreamsSchedule",children:"Dream Schedule"}),e.jsx("input",{id:"memoryDreamsSchedule",type:"text",className:"input",value:r.memoryDreamsSchedule,onChange:s=>{p(i=>({...i,memoryDreamsSchedule:s.target.value}))},placeholder:"0 4 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for dream processing."})]})]}),e.jsxs("div",{className:"memory-settings-group",children:[e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:"memoryAutoSummarizeEnabled",className:"checkbox-label",children:[e.jsx("input",{id:"memoryAutoSummarizeEnabled",type:"checkbox",checked:r.memoryAutoSummarizeEnabled,onChange:s=>{p(i=>({...i,memoryAutoSummarizeEnabled:s.target.checked}))},disabled:!r.memoryEnabled||v}),"Auto-Summarize Memory"]}),e.jsx("small",{children:"Automatically compact memory when it exceeds the threshold on a schedule"})]}),r.memoryEnabled&&r.memoryAutoSummarizeEnabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeThresholdChars",children:"Compaction Threshold (chars)"}),e.jsx("input",{id:"memoryAutoSummarizeThresholdChars",type:"number",className:"input",value:r.memoryAutoSummarizeThresholdChars,onChange:s=>{p(i=>({...i,memoryAutoSummarizeThresholdChars:parseInt(s.target.value,10)||5e4}))},min:1e3,disabled:v}),e.jsx("small",{children:"Memory will be compacted when it exceeds this character count"})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"memoryAutoSummarizeSchedule",children:"Schedule (cron)"}),e.jsx("input",{id:"memoryAutoSummarizeSchedule",type:"text",className:"input",value:r.memoryAutoSummarizeSchedule,onChange:s=>{p(i=>({...i,memoryAutoSummarizeSchedule:s.target.value}))},placeholder:"0 3 * * *",disabled:v}),e.jsx("small",{children:"Cron expression for auto-summarize schedule (default: daily at 3 AM)"})]})]})]}),!r.memoryEnabled&&e.jsx("div",{className:"settings-empty-state memory-status-message",children:"Memory is currently disabled. Enable memory tools in Settings to edit these automations."}),K&&e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:ye,disabled:D||v,children:D?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Settings"})})]})]})]}),o==="insights"&&e.jsx("div",{className:"memory-insights-tab",children:ee?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading insights…"})]}):S?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"memory-editor-container",children:e.jsx(Me,{content:y??"",onChange:g,readOnly:!1,filePath:".fusion/memory/INSIGHTS.md"})}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:fe,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:R,children:"Save Insights"})]})]}):!oe||L.length===0?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx("p",{children:"No insights extracted yet."}),e.jsx("p",{children:'Insights are automatically extracted from working memory. Click "Extract Now" to trigger extraction manually.'}),e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:O,disabled:u,style:{marginTop:"var(--space-md)"},children:u?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-stats-row",children:[e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:_}),e.jsx("div",{className:"memory-stat-label",children:"Total Insights"})]}),e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",children:L.length}),e.jsx("div",{className:"memory-stat-label",children:"Categories"})]}),w&&e.jsxs("div",{className:"memory-stat-card",children:[e.jsx("div",{className:"memory-stat-value",style:{fontSize:"16px"},children:w}),e.jsx("div",{className:"memory-stat-label",children:"Last Updated"})]})]}),e.jsxs("div",{className:"memory-action-bar",children:[e.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:O,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14,className:"animate-spin"}),"Extracting…"]}):"Extract Now"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:be,children:"Edit Raw"})]}),e.jsx("div",{className:"memory-categories-list",children:L.map(s=>{const i=!F.has(s.key);return e.jsxs("div",{className:"memory-category-section",children:[e.jsxs("div",{className:"memory-category-header",onClick:()=>le(s.key),role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),le(s.key))},children:[e.jsx("h4",{children:s.name}),e.jsx("span",{className:"memory-category-count",children:s.items.length})]}),i&&e.jsx("div",{className:"memory-category-items",children:s.items.map((h,je)=>e.jsx("div",{className:"memory-insight-item",children:h.replace(/^-\s+/,"").replace(/^\*\s+/,"")},je))})]},s.key)})})]})}),o==="engines"&&e.jsx("div",{className:"memory-engines-tab",children:C||te?e.jsxs("div",{className:"memory-empty-state",children:[e.jsx(A,{size:20,className:"animate-spin"}),e.jsx("span",{children:"Loading engine status…"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"memory-engine-card memory-qmd-card",children:[e.jsx("h3",{children:"QMD Integration"}),m?.qmdAvailable===!0?e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge memory-health-badge--healthy",children:"Installed"}),e.jsx("span",{className:"memory-char-count",children:"qmd is available on PATH."})]}):m?.qmdAvailable===!1?e.jsxs("div",{className:"settings-empty-state memory-status-message",children:[e.jsxs("span",{children:["qmd is not installed. Search will use local files. Install indexed retrieval: ",e.jsx("code",{children:m.qmdInstallCommand||"bun install -g @tobilu/qmd"})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ge,disabled:ne,children:ne?"Installing…":"Install qmd"})]}):e.jsxs("div",{className:"memory-engine-status",children:[e.jsx("span",{className:"memory-health-badge",children:"Checking"}),e.jsx("span",{className:"memory-char-count",children:"Checking qmd availability…"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-xs)",marginTop:"var(--space-sm)",flexWrap:"wrap"},children:[m?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),m?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),m?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),m?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:"Persistent"})]})]}),e.jsxs("div",{className:"memory-engine-card memory-retrieval-card",children:[e.jsx("h3",{children:"Test Memory Search"}),e.jsxs("div",{className:"memory-retrieval-input-row",children:[e.jsx("input",{type:"text",className:"input",value:Q,onChange:s=>J(s.target.value),placeholder:"Search memory with qmd"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:pe,disabled:X,children:X?"Testing…":"Test Retrieval"})]}),e.jsx("small",{className:"settings-muted",children:"Runs the same qmd-backed memory_search path agents use."}),f&&e.jsxs("div",{className:"memory-test-result",children:[e.jsxs("strong",{children:[f.results.length," result",f.results.length===1?"":"s"," ",'for "',f.query,'"']}),e.jsxs("small",{children:["qmd ",f.qmdAvailable?"available":"missing"," · ",f.usedFallback?"local fallback used":"qmd path used"]}),f.results.length>0?e.jsx("ul",{children:f.results.map((s,i)=>e.jsxs("li",{children:[e.jsxs("span",{children:[s.path,":",s.lineStart]}),e.jsx("p",{children:s.snippet})]},`${s.path}-${s.lineStart}-${i}`))}):e.jsx("small",{children:"No matching memory found."})]})]}),e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:"Current Backend"}),e.jsx("div",{className:"memory-engine-status",children:e.jsx("span",{style:{fontWeight:500},children:Ze(m?.currentBackend??"unknown")})}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-xs)",marginTop:"var(--space-sm)",flexWrap:"wrap"},children:[m?.capabilities?.readable&&e.jsx("span",{className:"memory-capability-badge",children:"Readable"}),m?.capabilities?.writable&&e.jsx("span",{className:"memory-capability-badge",children:"Writable"}),m?.capabilities?.supportsAtomicWrite&&e.jsx("span",{className:"memory-capability-badge",children:"Atomic Writes"}),m?.capabilities?.persistent&&e.jsx("span",{className:"memory-capability-badge",children:"Persistent"})]})]}),d&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"var(--space-md)"},children:[e.jsx("h3",{children:"Health Status"}),e.jsx("span",{className:`memory-health-badge memory-health-badge--${d.health}`,children:Ke(d.health)})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"var(--space-md)"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--text-muted)",textTransform:"uppercase",marginBottom:"var(--space-xs)"},children:"Working Memory"}),e.jsxs("div",{style:{fontWeight:500},children:[d.workingMemory.size," chars"]}),e.jsxs("div",{style:{fontSize:"13px",color:"var(--text-muted)"},children:[d.workingMemory.sectionCount," sections"]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--text-muted)",textTransform:"uppercase",marginBottom:"var(--space-xs)"},children:"Insights Memory"}),e.jsxs("div",{style:{fontWeight:500},children:[d.insightsMemory.size," chars"]}),e.jsxs("div",{style:{fontSize:"13px",color:"var(--text-muted)"},children:[d.insightsMemory.insightCount," insights"]})]})]}),e.jsxs("div",{style:{marginTop:"var(--space-md)",paddingTop:"var(--space-md)",borderTop:"1px solid var(--border)"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--text-muted)",textTransform:"uppercase",marginBottom:"var(--space-xs)"},children:"Last Extraction"}),e.jsx("div",{style:{fontWeight:500},children:d.extraction.success?e.jsx("span",{style:{color:"var(--color-success)"},children:"Success"}):e.jsx("span",{style:{color:"var(--color-error)"},children:"Failed"})}),e.jsx("div",{style:{fontSize:"13px",color:"var(--text-muted)"},children:d.extraction.summary||`${d.extraction.insightCount} insights extracted`})]}),e.jsxs("div",{style:{marginTop:"var(--space-md)",paddingTop:"var(--space-md)",borderTop:"1px solid var(--border)"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--text-muted)",textTransform:"uppercase",marginBottom:"var(--space-xs)"},children:"Pruning"}),e.jsx("div",{style:{fontWeight:500},children:d.pruning.applied?e.jsx("span",{style:{color:"var(--color-warning)"},children:"Applied"}):e.jsx("span",{style:{color:"var(--text-muted)"},children:"Not needed"})}),d.pruning.applied&&e.jsx("div",{style:{fontSize:"13px",color:"var(--text-muted)"},children:d.pruning.reason})]})]}),d&&d.checks.length>0&&e.jsxs("div",{className:"memory-engine-card",children:[e.jsx("h3",{children:"Audit Checks"}),e.jsx("div",{children:d.checks.map(s=>e.jsxs("div",{className:"memory-audit-check",children:[e.jsx("span",{className:s.passed?"memory-audit-check-passed":"memory-audit-check-failed",children:s.passed?"✓":"✗"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:s.name}),e.jsx("div",{style:{fontSize:"13px",color:"var(--text-muted)"},children:s.details})]})]},s.id))})]}),e.jsx("div",{className:"memory-action-bar",children:e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>H(),children:"Run Audit"})}),e.jsxs("div",{style:{marginTop:"var(--space-lg)",fontSize:"13px",color:"var(--text-muted)"},children:["Note: Change backend type in"," ",e.jsx("span",{style:{cursor:"pointer",textDecoration:"underline"},onClick:()=>{t("Open Settings → Memory to change backend type","info")},children:"Settings → Memory"})]})]})})]})]})}export{ts as MemoryView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,
|
|
1
|
+
import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,ak as xe,al as ge,am as pe,an as je,ao as Z,ap as Q,A as T,aq as _e,I as Ne,K as be,ar as ee,as as ve,at as Ce,X as B,au as ke,av as Se,R as J,w as G,G as we}from"./index-CCYdhck-.js";import{U as se}from"./upload-BksRDuGJ.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{c as O,cO as H,cP as V,cQ as Y,R as $,cF as y,w as Z,K as T,D as ee,I as se,bJ as L,F as D,cR as ae,cS as te,cT as _,X as ie}from"./index-CCYdhck-.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
|
+
* @license lucide-react v1.7.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const ne=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],I=O("palette",ne);/**
|
|
7
|
+
* @license lucide-react v1.7.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const le=[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]],M=O("puzzle",le);function ce(t){return t.replace(/-/g,"-")}function re(t){return{"fusion-global":"Fusion Global","pi-global":"Pi Global","fusion-project":"Fusion Project","pi-project":"Pi Project",package:"Package"}[t]??t}function oe(t){return t.startsWith("npm:")?"npm":t.startsWith("git:")?"git":"local"}function de(t){return t.replace(/^(npm:|git:)/,"")}function he({addToast:t,projectId:x}){const[c,A]=l.useState(null),[f,P]=l.useState(!0),[N,S]=l.useState(!1),[E,w]=l.useState(!1),[h,F]=l.useState(""),[G,K]=l.useState(new Set),[p,W]=l.useState([]),[b,z]=l.useState(!0),[q,C]=l.useState(!1),r=l.useCallback(async()=>{try{P(!0);const s=await H();A(s)}catch(s){t(`Failed to load Pi settings: ${s instanceof Error?s.message:String(s)}`,"error")}finally{P(!1)}},[t]),m=l.useCallback(async()=>{try{z(!0);const s=await V(x);W(s.extensions)}catch(s){t(`Failed to load extensions: ${s instanceof Error?s.message:String(s)}`,"error")}finally{z(!1)}},[t,x]),B=l.useCallback(async s=>{try{C(!0);const i=s.enabled?[...p.filter(a=>a.enabled&&a.id!==s.id).map(a=>a.id),s.id]:p.filter(a=>a.enabled&&a.id!==s.id).map(a=>a.id);await Y(i,x),await m(),t(s.enabled?"Extension disabled":"Extension enabled","success")}catch(i){t(`Failed to update extension: ${i instanceof Error?i.message:String(i)}`,"error")}finally{C(!1)}},[p,x,m,t]);l.useEffect(()=>{r()},[r]),l.useEffect(()=>{m()},[m]);const J=s=>{K(i=>{const a=new Set(i);return a.has(s)?a.delete(s):a.add(s),a})},R=async()=>{if(!h.trim()){t("Please enter a package source","error");return}try{S(!0),await ae(h.trim()),t("Package installed successfully","success"),F(""),await r()}catch(s){t(`Failed to install package: ${s instanceof Error?s.message:String(s)}`,"error")}finally{S(!1)}},Q=async()=>{try{w(!0),await te(x),await Promise.all([r(),m()]),t("Fusion skill reinstalled successfully","success")}catch(s){t(`Failed to reinstall Fusion skill: ${s instanceof Error?s.message:String(s)}`,"error")}finally{w(!1)}},U=async s=>{if(!c)return;const i=c.packages.filter(a=>(typeof a=="string"?a:a.source)!==s);try{await _({packages:i}),t("Package removed","success"),await r()}catch(a){t(`Failed to remove package: ${a instanceof Error?a.message:String(a)}`,"error")}},X=async(s,i)=>{if(!c)return;const a=c[s].filter(n=>n!==i);try{await _({[s]:a}),t(`${s.slice(0,-1)} removed`,"success"),await r()}catch(n){t(`Failed to update settings: ${n instanceof Error?n.message:String(n)}`,"error")}},u=(s,i,a)=>!c||c[a].length===0?null:e.jsxs("div",{className:"pi-ext-section",children:[e.jsxs("div",{className:"pi-ext-section-header",children:[e.jsx(i,{size:14}),e.jsx("span",{children:s}),e.jsx("span",{className:"pi-ext-count",children:c[a].length})]}),e.jsx("div",{className:"pi-ext-resource-list",children:c[a].map((n,g)=>e.jsxs("span",{className:"pi-ext-resource-tag",children:[e.jsx("span",{className:"pi-ext-resource-path",children:n}),e.jsx("button",{className:"btn-icon touch-target pi-ext-resource-remove",onClick:()=>X(a,n),title:`Remove ${n}`,"aria-label":`Remove ${n}`,children:e.jsx(ie,{size:12})})]},g))})]});return e.jsxs("div",{className:"pi-ext-manager",children:[e.jsxs("div",{className:"pi-ext-manager-header",children:[e.jsx("h4",{className:"pi-ext-manager-title",children:"Pi Extensions"}),e.jsx("div",{className:"pi-ext-manager-actions",children:e.jsx("button",{className:"btn-icon",onClick:r,title:"Refresh",disabled:f,children:e.jsx($,{size:16,className:f?"spin":""})})})]}),f?e.jsx("div",{className:"loading-state",children:"Loading Pi settings…"}):c?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pi-ext-add-form",children:[e.jsxs("div",{className:"pi-ext-add-form-row",children:[e.jsx("input",{type:"text",className:"input",placeholder:"npm:pi-extension-name or git:https://github.com/...",value:h,onChange:s=>F(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),R())},disabled:N}),e.jsxs("button",{className:"btn btn-primary",onClick:R,disabled:N||!h.trim(),children:[e.jsx(Z,{size:14}),N?"Installing…":"Add"]})]}),e.jsx("div",{className:"pi-ext-add-form-row",children:e.jsx("button",{className:"btn",onClick:Q,disabled:E,children:E?"Reinstalling Fusion…":"Reinstall Fusion skill"})})]}),c.packages.length>0?e.jsx("div",{className:"pi-ext-package-list",children:c.packages.map((s,i)=>{const a=typeof s=="string"?s:s.source,n=oe(a),g=de(a),j=typeof s=="object"&&s!==null,v=j&&(s.extensions?.length??0)>0||(s.skills?.length??0)>0||(s.prompts?.length??0)>0||(s.themes?.length??0)>0,k=G.has(i);return e.jsxs("div",{className:"pi-ext-package-card",children:[e.jsxs("div",{className:"pi-ext-package-header",children:[j&&v?e.jsx("button",{className:"pi-ext-expand-btn",onClick:()=>J(i),"aria-expanded":k,children:k?e.jsx(T,{size:14}):e.jsx(ee,{size:14})}):e.jsx("span",{className:"pi-ext-expand-placeholder"}),e.jsx("span",{className:`pi-ext-source-badge pi-ext-source-badge--${n}`,children:n}),e.jsx("span",{className:"pi-ext-package-source",children:g}),e.jsxs("div",{className:"pi-ext-package-actions",children:[j&&v&&e.jsxs("span",{className:"pi-ext-filter-hint",children:[s.extensions?.length??0," ext,"," ",s.skills?.length??0," skill,"," ",s.prompts?.length??0," prompt,"," ",s.themes?.length??0," theme"]}),e.jsx("button",{className:"btn-icon touch-target pi-ext-remove-btn",onClick:()=>U(a),title:"Remove package","aria-label":`Remove package ${g}`,children:e.jsx(se,{size:14})})]})]}),j&&v&&k&&e.jsxs("div",{className:"pi-ext-filter-list",children:[s.extensions?.length?e.jsxs("div",{className:"pi-ext-filter-section",children:[e.jsx(M,{size:12}),e.jsx("span",{className:"pi-ext-filter-label",children:"Extensions:"}),s.extensions.map((o,d)=>e.jsx("span",{className:"pi-ext-filter-tag",children:o},d))]}):null,s.skills?.length?e.jsxs("div",{className:"pi-ext-filter-section",children:[e.jsx(L,{size:12}),e.jsx("span",{className:"pi-ext-filter-label",children:"Skills:"}),s.skills.map((o,d)=>e.jsx("span",{className:"pi-ext-filter-tag",children:o},d))]}):null,s.prompts?.length?e.jsxs("div",{className:"pi-ext-filter-section",children:[e.jsx(D,{size:12}),e.jsx("span",{className:"pi-ext-filter-label",children:"Prompts:"}),s.prompts.map((o,d)=>e.jsx("span",{className:"pi-ext-filter-tag",children:o},d))]}):null,s.themes?.length?e.jsxs("div",{className:"pi-ext-filter-section",children:[e.jsx(I,{size:12}),e.jsx("span",{className:"pi-ext-filter-label",children:"Themes:"}),s.themes.map((o,d)=>e.jsx("span",{className:"pi-ext-filter-tag",children:o},d))]}):null]})]},i)})}):e.jsxs("div",{className:"empty-state",children:[e.jsx(y,{size:32,className:"text-muted"}),e.jsx("p",{children:"No packages configured."}),e.jsx("p",{className:"text-muted",children:"Add a package source above to get started."})]}),e.jsxs("div",{className:"pi-ext-top-level",children:[u("Extensions",M,"extensions"),u("Skills",L,"skills"),u("Prompts",D,"prompts"),u("Themes",I,"themes")]})]}):e.jsxs("div",{className:"empty-state",children:[e.jsx(y,{size:32,className:"text-muted"}),e.jsx("p",{children:"Failed to load Pi settings."})]}),e.jsxs("div",{className:"pi-ext-discovered-section",children:[e.jsxs("div",{className:"pi-ext-discovered-header",children:[e.jsx("h4",{children:"Discovered Extensions"}),e.jsx("button",{className:"btn-icon",onClick:m,disabled:b,title:"Refresh extensions",children:e.jsx($,{size:14,className:b?"spin":""})})]}),e.jsx("p",{className:"pi-ext-description",children:"Installed extensions resolved from packages and configured paths."}),b?e.jsx("div",{className:"loading-state",children:"Loading extensions…"}):p.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx(y,{size:32,className:"text-muted"}),e.jsx("p",{children:"No extensions discovered."})]}):e.jsx("div",{className:"pi-ext-list",children:p.map(s=>e.jsxs("div",{className:"pi-ext-item",children:[e.jsxs("div",{className:"pi-ext-item-content",children:[e.jsxs("div",{className:"pi-ext-info",children:[e.jsx("span",{className:"pi-ext-name",children:s.name}),e.jsx("span",{className:`pi-ext-source-badge pi-ext-source-badge--${ce(s.source)}`,children:re(s.source)})]}),e.jsx("span",{className:"pi-ext-path",children:s.path})]}),e.jsx("div",{className:"pi-ext-actions",children:e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:()=>void B(s),disabled:q,"aria-label":`Toggle ${s.name}`}),e.jsx("span",{className:"toggle-slider"})]})})]},s.id))})]})]})}export{he as PiExtensionsManager};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.pi-ext-manager{display:flex;flex-direction:column;gap:var(--space-lg)}.pi-ext-manager-header{display:flex;align-items:center;justify-content:space-between;padding-bottom:var(--space-sm);border-bottom:1px solid var(--border)}.pi-ext-manager-title{margin:0;font-size:.9rem;font-weight:600;color:var(--text)}.pi-ext-manager-actions{display:flex;gap:var(--space-sm);align-items:center}.pi-ext-description{font-size:.82rem;color:var(--text-muted);line-height:1.45;margin:0}.pi-ext-item{display:flex;align-items:flex-start;justify-content:space-between;padding:var(--space-sm) var(--space-md);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);transition:border-color var(--transition-fast);flex-wrap:wrap;gap:var(--space-sm)}.pi-ext-item:hover{border-color:var(--text-dim)}.pi-ext-item-content{display:flex;flex-direction:column;gap:var(--space-xs);min-width:0;flex:1}.pi-ext-info{display:flex;align-items:center;gap:var(--space-sm);flex-wrap:wrap}.pi-ext-name{font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.pi-ext-source-badge{display:inline-flex;align-items:center;padding:var(--space-xs) var(--space-sm);border-radius:var(--radius-pill);font-size:.7rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;background:color-mix(in srgb,currentColor 12%,transparent)}.pi-ext-source-badge--global{color:var(--color-info)}.pi-ext-source-badge--project{color:var(--color-success)}.pi-ext-path{font-size:.75rem;font-family:var(--font-mono);color:var(--text-dim);word-break:break-all;line-height:1.4}.pi-ext-actions{display:flex;align-items:center;gap:var(--space-xs);flex-shrink:0}.pi-ext-manager .empty-state,.pi-ext-manager .loading-state{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--space-sm);padding:var(--space-2xl);text-align:center;color:var(--text-muted)}.pi-ext-list{display:flex;flex-direction:column;gap:var(--space-sm)}.pi-ext-item{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-md);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md)}.pi-ext-add-form{display:flex;flex-direction:column;gap:var(--space-sm);margin-bottom:var(--space-md)}.pi-ext-add-form-row{display:flex;gap:var(--space-sm);align-items:center}.pi-ext-add-form-row .input{flex:1;min-width:0}.pi-ext-package-list{display:flex;flex-direction:column;gap:var(--space-sm)}.pi-ext-package-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);overflow:hidden}.pi-ext-package-header{display:flex;align-items:center;gap:var(--space-sm);padding:calc(var(--space-sm) + 2px) var(--space-md);flex-wrap:wrap}.pi-ext-expand-btn{background:none;border:none;padding:var(--space-xs);cursor:pointer;color:var(--text-muted);display:flex;align-items:center;border-radius:var(--radius-sm);transition:color var(--transition-fast)}.pi-ext-expand-btn:hover{color:var(--text)}.pi-ext-expand-btn:focus-visible{box-shadow:var(--focus-ring-strong);outline:none}.pi-ext-expand-placeholder{width:18px;height:18px;flex-shrink:0}.pi-ext-source-badge--npm{color:var(--color-info);background:color-mix(in srgb,var(--color-info) 12%,transparent)}.pi-ext-source-badge--git{color:var(--color-success);background:color-mix(in srgb,var(--color-success) 12%,transparent)}.pi-ext-source-badge--local{color:var(--text-muted);background:color-mix(in srgb,var(--text-muted) 12%,transparent)}.pi-ext-package-source{font-family:var(--font-mono);font-size:.82rem;flex:1;min-width:0;word-break:break-all}.pi-ext-filter-hint{font-size:.72rem;color:var(--text-muted);flex-shrink:0}.pi-ext-package-actions{display:flex;align-items:center;gap:var(--space-xs);flex-shrink:0}.pi-ext-remove-btn{background:none;border:none;padding:var(--space-xs);min-width:var(--space-2xl);min-height:var(--space-2xl);cursor:pointer;color:var(--text-muted);display:inline-flex;align-items:center;justify-content:center;border-radius:var(--radius-sm);transition:color var(--transition-fast),background-color var(--transition-fast)}.pi-ext-remove-btn:hover{color:var(--color-error);background:color-mix(in srgb,var(--color-error) 10%,transparent)}.pi-ext-remove-btn:focus-visible{box-shadow:var(--focus-ring-strong);outline:none}.pi-ext-filter-list{padding:var(--space-sm) var(--space-md);border-top:1px solid var(--border);background:var(--bg);display:flex;flex-direction:column;gap:var(--space-sm)}.pi-ext-filter-section{display:flex;align-items:center;gap:var(--space-xs);flex-wrap:wrap;color:var(--text-muted)}.pi-ext-filter-label{font-size:.72rem;font-weight:500}.pi-ext-filter-tag{display:inline-flex;align-items:center;gap:var(--space-xs);padding:var(--space-xs) var(--space-sm);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-sm);font-size:.72rem;font-family:var(--font-mono);color:var(--text-muted)}.pi-ext-top-level{display:flex;flex-direction:column;gap:var(--space-md);margin-top:var(--space-md);padding-top:var(--space-md);border-top:1px solid var(--border)}.pi-ext-section{display:flex;flex-direction:column;gap:var(--space-sm)}.pi-ext-section-header{display:flex;align-items:center;gap:var(--space-xs);color:var(--text-muted);font-size:.82rem}.pi-ext-section-header span:first-of-type{font-weight:500}.pi-ext-count{display:inline-flex;align-items:center;justify-content:center;min-width:18px;height:18px;padding:0 var(--space-xs);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-pill);font-size:.68rem;color:var(--text-dim)}.pi-ext-resource-list{display:flex;flex-wrap:wrap;gap:var(--space-xs)}.pi-ext-resource-tag{display:inline-flex;align-items:center;gap:var(--space-xs);padding:var(--space-xs) var(--space-sm);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-sm)}.pi-ext-resource-path{font-size:.75rem;font-family:var(--font-mono);color:var(--text-muted);max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.pi-ext-resource-remove{background:none;border:none;padding:var(--space-xs);min-width:var(--space-2xl);min-height:var(--space-2xl);cursor:pointer;color:var(--text-dim);display:inline-flex;align-items:center;justify-content:center;border-radius:var(--radius-sm);transition:color var(--transition-fast),background-color var(--transition-fast)}.pi-ext-resource-remove:hover{color:var(--color-error);background:color-mix(in srgb,var(--color-error) 10%,transparent)}.pi-ext-resource-remove:focus-visible{box-shadow:var(--focus-ring-strong);outline:none}@media(max-width:768px){.pi-ext-list{gap:var(--space-xs)}.pi-ext-item{padding:var(--space-sm)}.pi-ext-add-form-row{flex-direction:column;align-items:stretch}.pi-ext-add-form-row .btn,.pi-ext-add-form-row .btn-primary{width:100%}.pi-ext-package-header{padding:var(--space-sm) var(--space-md)}.pi-ext-resource-path{max-width:120px}}.pi-ext-discovered-section{margin-top:var(--space-lg);padding-top:var(--space-lg);border-top:1px solid var(--border)}.pi-ext-discovered-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:var(--space-sm)}.pi-ext-discovered-header h4{margin:0;font-size:.9rem;font-weight:600}.pi-ext-source-badge--fusion-global{color:var(--color-info);background:color-mix(in srgb,var(--color-info) 12%,transparent)}.pi-ext-source-badge--pi-global{color:var(--color-warning);background:color-mix(in srgb,var(--color-warning) 12%,transparent)}.pi-ext-source-badge--fusion-project{color:var(--color-success);background:color-mix(in srgb,var(--color-success) 12%,transparent)}.pi-ext-source-badge--pi-project{color:var(--color-muted);background:color-mix(in srgb,var(--color-muted) 12%,transparent)}.pi-ext-source-badge--package{color:var(--in-progress);background:color-mix(in srgb,var(--in-progress) 12%,transparent)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.plugin-manager,.plugin-manager-detail{display:flex;flex-direction:column;gap:var(--space-lg)}.plugin-manager-header{display:flex;align-items:center;justify-content:space-between;padding-bottom:var(--space-sm);border-bottom:var(--btn-border-width) solid var(--border)}.plugin-manager-actions{display:flex;gap:var(--space-sm);align-items:center}.plugin-install-form{display:flex;flex-direction:column;gap:var(--space-sm);padding:var(--space-lg);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.plugin-install-hint{margin:0;font-size:.85rem;color:var(--text-secondary, var(--text-muted));line-height:1.45}.plugin-install-hint code{padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-sm);background:color-mix(in srgb,var(--text-muted) 12%,transparent);font-size:.85em}.plugin-install-actions{display:flex;gap:var(--space-sm);justify-content:flex-end}.plugin-list{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-item{display:flex;align-items:center;justify-content:space-between;padding:var(--space-md) var(--space-lg);background:var(--surface);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);transition:border-color var(--transition-fast)}.plugin-item:hover{border-color:var(--text-dim)}.plugin-info{display:flex;align-items:center;gap:var(--space-sm);min-width:0}.plugin-name{font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.plugin-version{font-size:.85rem}.plugin-state-badge{display:inline-flex;align-items:center;padding:var(--space-xs) var(--space-sm);border-radius:var(--radius-pill);font-size:.7rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;background:color-mix(in srgb,currentColor 12%,transparent)}.plugin-actions{display:flex;align-items:center;gap:var(--space-xs);flex-shrink:0}.plugin-manager-detail-header,.plugin-detail-title{display:flex;align-items:center;gap:var(--space-md);flex-wrap:wrap}.plugin-detail-name{margin:0}.plugin-detail-content{display:flex;flex-direction:column;gap:var(--space-lg)}.plugin-detail-card{background:var(--surface);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);padding:var(--space-lg);display:flex;flex-direction:column;gap:var(--space-md)}.plugin-description{font-size:.95rem;color:var(--text-secondary, var(--text-muted));line-height:1.5}.plugin-detail-meta-row{display:flex;align-items:center;gap:var(--space-xs);font-size:.9rem;color:var(--text-muted)}.plugin-homepage a{display:inline-flex;align-items:center;gap:var(--space-xs);color:var(--color-info);font-size:.85rem}.plugin-detail-section-heading{margin:0;padding:0;border:0;font-size:.95rem}.plugin-settings-form{display:flex;flex-direction:column;gap:var(--space-lg);margin-top:var(--space-xs)}.plugin-settings-form .form-group{padding:0;margin:0}.plugin-settings-array{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-settings-array-item{display:flex;align-items:center;gap:var(--space-sm)}.plugin-settings-array-item input{flex:1}.plugin-detail-actions{display:flex;gap:var(--space-sm);padding-top:var(--space-md);border-top:var(--btn-border-width) solid var(--border);justify-content:flex-end}.plugin-manager .empty-state,.plugin-manager .loading-state,.plugin-manager .settings-empty-state{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--space-sm);padding:var(--space-2xl);text-align:center;color:var(--text-muted)}.plugin-bundled-runtime-list{width:100%;display:flex;flex-direction:column;gap:var(--space-sm);margin-top:var(--space-sm)}.plugin-bundled-runtime-item{display:flex;align-items:center;justify-content:space-between;gap:var(--space-sm);padding:var(--space-sm) var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.plugin-bundled-runtime-meta{display:flex;align-items:center;gap:var(--space-sm);min-width:0}.plugin-bundled-runtime-name{color:var(--text);font-size:.9rem;font-weight:500}.plugin-bundled-runtime-badge{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);background:var(--status-in-review-bg);color:var(--in-review);font-size:.75rem;font-weight:600;text-transform:uppercase}.plugin-bundled-runtime-section{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-bundled-runtime-header{display:flex;flex-direction:column;gap:var(--space-xs)}.plugin-bundled-runtime-heading{margin:0;font-size:.95rem}.plugin-bundled-runtime-description{margin:0;font-size:.85rem;color:var(--text-muted)}.plugin-bundled-runtime-status{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);font-size:.75rem;font-weight:600;text-transform:uppercase}.plugin-bundled-runtime-status--installed{background:var(--status-done-bg);color:var(--done)}.plugin-bundled-runtime-status--available{background:var(--status-todo-bg);color:var(--todo)}@media(max-width:768px){.plugin-manager-detail-header{gap:var(--space-sm)}.plugin-detail-title{gap:var(--space-xs)}.plugin-detail-card{padding:var(--space-md);gap:var(--space-sm)}.plugin-list{gap:var(--space-xs)}.plugin-item{padding:var(--space-md);flex-direction:column;align-items:stretch;gap:var(--space-sm)}.plugin-info{width:100%;flex-wrap:wrap;row-gap:var(--space-xs)}.plugin-name{flex:1 1 100%;white-space:normal}.plugin-actions{width:100%;justify-content:flex-end;flex-wrap:wrap;gap:var(--space-sm)}.plugin-actions .btn-icon,.plugin-actions .toggle-switch{min-width:36px;min-height:36px}.plugin-actions .toggle-switch{display:inline-flex;align-items:center;justify-content:center}.plugin-detail-actions{flex-wrap:wrap;justify-content:flex-start}.plugin-detail-actions button{flex:1 1 auto;min-height:36px}.plugin-bundled-runtime-item{flex-direction:column;align-items:stretch}.plugin-bundled-runtime-item .btn{min-height:36px}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as o,j as e}from"./vendor-react-K0fH_qHe.js";import{cD as W,s as Y,X as k,ah as Z,w as U,cE as O,I as A,R as T,cF as ee,aq as se,cG as ne,cH as te,cI as ie,cJ as ae,cK as le,cL as _,cM as re}from"./index-CCYdhck-.js";import{D as ce}from"./DirectoryPicker-CTwgv9LY.js";import"./vendor-xterm-DzcZoU0P.js";import"./folder-open-Ec4hU1xL.js";const de=[{id:"fusion-plugin-hermes-runtime",name:"Hermes Runtime",path:"./plugins/fusion-plugin-hermes-runtime",experimental:!0},{id:"fusion-plugin-paperclip-runtime",name:"Paperclip Runtime",path:"./plugins/fusion-plugin-paperclip-runtime"},{id:"fusion-plugin-openclaw-runtime",name:"OpenClaw Runtime",path:"./plugins/fusion-plugin-openclaw-runtime",experimental:!0}],N={started:"var(--color-success)",loaded:"var(--color-warning)",error:"var(--color-error)",stopped:"var(--color-muted)",installed:"var(--color-info)"};function xe({addToast:l,projectId:c}){const[x,b]=o.useState([]),[S,w]=o.useState(!0),[H,f]=o.useState(!1),[j,v]=o.useState(""),[C,I]=o.useState(!1),[h,P]=o.useState(null),[i,y]=o.useState(null),[a,g]=o.useState({}),[M,$]=o.useState(!1),[R,E]=o.useState(null),u=o.useCallback(async()=>{try{w(!0);const s=await W(c);b(s)}catch(s){l(`Failed to load plugins: ${s instanceof Error?s.message:String(s)}`,"error")}finally{w(!1)}},[c,l]);o.useEffect(()=>{u()},[u]);const V=o.useRef([]);V.current=x,o.useEffect(()=>{const s=c?`?projectId=${encodeURIComponent(c)}`:"",n=p=>{try{const t=JSON.parse(p.data);if(c&&t.projectId&&t.projectId!==c)return;switch(t.transition){case"installing":case"enabled":case"disabled":case"settings-updated":b(d=>{const m=d.findIndex(r=>r.id===t.pluginId);if(m>=0){const r=[...d];return r[m]={...r[m],enabled:t.enabled,state:t.state,settings:t.settings,error:t.error},r}else return u(),d});break;case"uninstalled":b(d=>d.filter(m=>m.id!==t.pluginId));break;case"error":b(d=>{const m=d.findIndex(r=>r.id===t.pluginId);if(m>=0){const r=[...d];return r[m]={...r[m],state:t.state,error:t.error},r}return d});break}}catch{}};return Y(`/api/events${s}`,{events:{"plugin:lifecycle":n},onReconnect:()=>{u()}})},[c,u]);const z=async()=>{if(!j.trim()){l("Please enter a plugin path","error");return}try{I(!0),await _({path:j},c),l("Plugin installed successfully","success"),f(!1),v(""),await u()}catch(s){l(`Failed to install plugin: ${s instanceof Error?s.message:String(s)}`,"error")}finally{I(!1)}},G=async s=>{try{E(s.id),await _({path:s.path},c),l(`${s.name} installed successfully`,"success"),await u()}catch(n){l(`Failed to install ${s.name}: ${n instanceof Error?n.message:String(n)}`,"error")}finally{E(null)}},F=async s=>{try{await ae(s.id,c),l(`${s.name} enabled`,"success"),await u()}catch(n){l(`Failed to enable plugin: ${n instanceof Error?n.message:String(n)}`,"error")}},L=async s=>{try{await ie(s.id,c),l(`${s.name} disabled`,"success"),await u()}catch(n){l(`Failed to disable plugin: ${n instanceof Error?n.message:String(n)}`,"error")}},B=async s=>{try{P(s.id),await te(s.id,c),l(`${s.name} reloaded`,"success"),await u()}catch(n){l(`Failed to reload plugin: ${n instanceof Error?n.message:String(n)}`,"error")}finally{P(null)}},q=async s=>{if(confirm(`Are you sure you want to uninstall "${s.name}"?`))try{await le(s.id,c),l(`${s.name} uninstalled`,"success"),await u(),y(null)}catch(n){l(`Failed to uninstall plugin: ${n instanceof Error?n.message:String(n)}`,"error")}},J=async s=>{y(s);try{$(!0);const n=await re(s.id,c);g(n)}catch{g({})}finally{$(!1)}},K=async()=>{if(i)try{await ne(i.id,a,c),l("Settings saved","success")}catch(s){l(`Failed to save settings: ${s instanceof Error?s.message:String(s)}`,"error")}};if(i)return e.jsxs("div",{className:"plugin-manager-detail","data-testid":"plugin-manager-detail",children:[e.jsxs("div",{className:"plugin-manager-detail-header",children:[e.jsx("button",{className:"btn-icon",onClick:()=>y(null),"aria-label":"Back to plugin list",children:e.jsx(k,{size:16})}),e.jsxs("div",{className:"plugin-detail-title",children:[e.jsx("h4",{className:"plugin-detail-name",children:i.name}),e.jsx("span",{className:"plugin-state-badge",style:{color:N[i.state]||N.installed},children:i.state})]})]}),e.jsxs("div",{className:"plugin-detail-content",children:[e.jsxs("div",{className:"plugin-detail-card",children:[i.description&&e.jsx("p",{className:"plugin-description",children:i.description}),i.author&&e.jsxs("p",{className:"plugin-detail-meta-row",children:[e.jsx("span",{className:"text-muted",children:"Author:"}),i.author]}),i.homepage&&e.jsxs("p",{className:"plugin-detail-meta-row plugin-homepage",children:[e.jsx("span",{className:"text-muted",children:"Homepage:"}),e.jsxs("a",{href:i.homepage,target:"_blank",rel:"noopener noreferrer",children:[i.homepage,e.jsx(Z,{size:12})]})]}),e.jsxs("p",{className:"plugin-detail-meta-row",children:[e.jsx("span",{className:"text-muted",children:"Version:"}),i.version]})]}),e.jsxs("div",{className:"plugin-detail-card",children:[e.jsx("h5",{className:"plugin-detail-section-heading",children:"Settings"}),M?e.jsx("p",{className:"text-muted",children:"Loading..."}):i.settingsSchema&&Object.keys(i.settingsSchema).length>0?e.jsxs("div",{className:"plugin-settings-form",children:[Object.entries(i.settingsSchema).map(([s,n])=>{const p=`setting-${s}-help`;return e.jsxs("div",{className:"form-group",children:[e.jsxs("label",{htmlFor:`setting-${s}`,children:[n.label||s,n.required&&" *"]}),n.type==="string"&&!n.multiline&&e.jsx("input",{type:"text",id:`setting-${s}`,value:a[s]??"",onChange:t=>g({...a,[s]:t.target.value}),placeholder:n.description,"aria-describedby":n.description&&!n.required?p:void 0}),n.type==="string"&&n.multiline&&e.jsx("textarea",{id:`setting-${s}`,rows:4,value:a[s]??"",onChange:t=>g({...a,[s]:t.target.value}),placeholder:n.description,"aria-describedby":n.description&&!n.required?p:void 0}),n.type==="password"&&e.jsx("input",{type:"password",id:`setting-${s}`,value:a[s]??"",onChange:t=>g({...a,[s]:t.target.value}),placeholder:n.description,"aria-describedby":n.description&&!n.required?p:void 0}),n.type==="number"&&e.jsx("input",{type:"number",id:`setting-${s}`,value:a[s]??"",onChange:t=>g({...a,[s]:Number(t.target.value)}),"aria-describedby":n.description&&!n.required?p:void 0}),n.type==="boolean"&&e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:a[s]??!1,onChange:t=>g({...a,[s]:t.target.checked})}),n.description]}),n.type==="enum"&&e.jsxs("select",{id:`setting-${s}`,value:a[s]??"",onChange:t=>g({...a,[s]:t.target.value}),"aria-describedby":n.description&&!n.required?p:void 0,children:[e.jsx("option",{value:"",children:"Select..."}),n.enumValues?.map(t=>e.jsx("option",{value:t,children:t},t))]}),n.type==="array"&&e.jsxs("div",{className:"plugin-settings-array",children:[a[s]?.map((t,d)=>e.jsxs("div",{className:"plugin-settings-array-item",children:[e.jsx("input",{type:n.itemType==="number"?"number":"text",value:t??"",onChange:m=>{const r=m.target.value,D=[...a[s]||[]];D[d]=n.itemType==="number"?Number(r):r,g({...a,[s]:D})}}),e.jsx("button",{className:"btn-icon",onClick:()=>{const r=[...a[s]||[]];r.splice(d,1),g({...a,[s]:r})},"aria-label":"Remove item",children:e.jsx(k,{size:14})})]},d)),e.jsxs("button",{className:"btn btn-secondary",onClick:()=>{const t=a[s]||[],d=n.itemType==="number"?0:"";g({...a,[s]:[...t,d]})},children:[e.jsx(U,{size:14})," Add Item"]})]}),n.description&&!n.required&&!n.multiline&&e.jsx("span",{id:p,className:"form-help",children:n.description})]},s)}),e.jsx("button",{className:"btn btn-primary",onClick:K,children:"Save Settings"})]}):e.jsx("p",{className:"text-muted",children:"No configurable settings."})]}),e.jsxs("div",{className:"plugin-detail-actions",children:[i.state==="started"&&e.jsxs("button",{className:"btn btn-secondary",onClick:()=>B(i),disabled:h===i.id,children:[e.jsx(O,{size:14,className:h===i.id?"spin":""}),h===i.id?"Reloading...":"Reload"]}),i.enabled?e.jsx("button",{className:"btn btn-secondary",onClick:()=>L(i),children:"Disable"}):e.jsx("button",{className:"btn btn-primary",onClick:()=>F(i),children:"Enable"}),e.jsxs("button",{className:"btn btn-danger",onClick:()=>q(i),children:[e.jsx(A,{size:14})," Uninstall"]})]})]})]});const X=new Set(x.map(s=>s.id)),Q=()=>e.jsxs("section",{className:"plugin-bundled-runtime-section","aria-label":"Bundled Runtime Plugins",children:[e.jsxs("div",{className:"plugin-bundled-runtime-header",children:[e.jsx("h4",{className:"plugin-bundled-runtime-heading",children:"Bundled Runtime Plugins"}),e.jsx("p",{className:"plugin-bundled-runtime-description",children:"Install Fusion's bundled runtimes directly from this screen."})]}),e.jsx("div",{className:"plugin-bundled-runtime-list","aria-label":"Bundled runtime plugin recommendations",children:de.map(s=>{const n=X.has(s.id);return e.jsxs("div",{className:"plugin-bundled-runtime-item",children:[e.jsxs("div",{className:"plugin-bundled-runtime-meta",children:[e.jsx("span",{className:"plugin-bundled-runtime-name",children:s.name}),s.experimental&&e.jsx("span",{className:"plugin-bundled-runtime-badge",children:"Experimental"}),e.jsx("span",{className:`plugin-bundled-runtime-status ${n?"plugin-bundled-runtime-status--installed":"plugin-bundled-runtime-status--available"}`,children:n?"Installed":"Not installed"})]}),e.jsx("button",{className:`btn ${n?"btn-secondary":"btn-primary"} btn-sm`,onClick:()=>G(s),disabled:n||R===s.id,children:n?"Installed":R===s.id?"Installing...":`Install ${s.name}`})]},s.id)})})]});return e.jsxs("div",{className:"plugin-manager","data-testid":"plugin-manager",children:[e.jsx("div",{className:"plugin-manager-header",children:e.jsxs("div",{className:"plugin-manager-actions",children:[e.jsx("button",{className:"btn-icon",onClick:u,title:"Refresh",children:e.jsx(T,{size:16,className:S?"spin":""})}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>f(!0),children:[e.jsx(U,{size:14})," Install"]})]})}),H&&e.jsxs("div",{className:"plugin-install-form",children:[e.jsxs("p",{className:"plugin-install-hint",children:["Browse to a plugin package root (contains ",e.jsx("code",{children:"manifest.json"}),") or a built ",e.jsx("code",{children:"dist"})," directory."]}),e.jsx(ce,{value:j,onChange:v,placeholder:"Absolute path to plugin directory or dist folder",onInputKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),z())}}),e.jsxs("div",{className:"plugin-install-actions",children:[e.jsx("button",{className:"btn btn-primary",onClick:z,disabled:C||!j.trim(),children:C?"Installing...":"Install Plugin"}),e.jsx("button",{className:"btn btn-secondary",onClick:()=>{f(!1),v("")},children:"Cancel"})]})]}),S?e.jsx("div",{className:"settings-empty-state",children:"Loading plugins..."}):e.jsxs(e.Fragment,{children:[x.length===0?e.jsxs("div",{className:"settings-empty-state",children:[e.jsx(ee,{size:32,className:"text-muted"}),e.jsx("p",{children:"No plugins installed."}),e.jsx("p",{className:"text-muted",children:"Install a plugin to get started, or use a bundled runtime below."})]}):e.jsx("div",{className:"plugin-list",children:x.map(s=>e.jsxs("div",{className:"plugin-item",children:[e.jsxs("div",{className:"plugin-info",children:[e.jsx("span",{className:"plugin-name",children:s.name}),e.jsxs("span",{className:"plugin-version text-muted",children:["v",s.version]}),e.jsx("span",{className:"plugin-state-badge",style:{color:N[s.state]||N.installed},children:s.state})]}),e.jsxs("div",{className:"plugin-actions",children:[s.state==="started"&&e.jsx("button",{className:"btn-icon",onClick:()=>B(s),disabled:h===s.id,title:"Reload",children:e.jsx(O,{size:14,className:h===s.id?"spin":""})}),e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:()=>s.enabled?L(s):F(s)}),e.jsx("span",{className:"toggle-slider"})]}),e.jsx("button",{className:"btn-icon",onClick:()=>J(s),title:"Settings",children:e.jsx(se,{size:14})}),e.jsx("button",{className:"btn-icon",onClick:()=>q(s),title:"Uninstall",children:e.jsx(A,{size:14})})]})]},s.id))}),Q()]})]})}export{xe as PluginManager,N as STATE_COLORS};
|