@runfusion/fusion 0.11.0 → 0.12.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.
Files changed (46) hide show
  1. package/dist/bin.js +1122 -356
  2. package/dist/client/assets/{AgentDetailView-DQBjJSPJ.js → AgentDetailView-B20ApPe1.js} +3 -3
  3. package/dist/client/assets/{AgentsView-xm_3NO4M.css → AgentsView-Bkk-uBij.css} +1 -1
  4. package/dist/client/assets/{AgentsView-DlA0yHBg.js → AgentsView-ChN1tgQ0.js} +17 -17
  5. package/dist/client/assets/ChatView-oPMFwmoc.js +1 -0
  6. package/dist/client/assets/{DevServerView-BVixhlF0.js → DevServerView-DQrVLbK5.js} +1 -1
  7. package/dist/client/assets/{DirectoryPicker-tvBgHxa7.js → DirectoryPicker-DVmy6sLM.js} +1 -1
  8. package/dist/client/assets/{DocumentsView-DVw_wT6V.js → DocumentsView-DHEv-Q2a.js} +1 -1
  9. package/dist/client/assets/{InsightsView-G3MZhwSx.js → InsightsView-ByyY7GX7.js} +2 -2
  10. package/dist/client/assets/{MemoryView-Bl9gx2Dw.js → MemoryView-Udiu0u8R.js} +1 -1
  11. package/dist/client/assets/{NodesView-dwVhD4V2.js → NodesView-CupS-GGc.js} +4 -4
  12. package/dist/client/assets/{PiExtensionsManager-CEHp6_Mj.js → PiExtensionsManager-DXs2xI8K.js} +2 -2
  13. package/dist/client/assets/PluginManager-BCpiZf4_.js +1 -0
  14. package/dist/client/assets/{ResearchView-BvlLYC_1.js → ResearchView-BG9Feaeb.js} +1 -1
  15. package/dist/client/assets/ResearchView-BzRdUzNq.css +1 -0
  16. package/dist/client/assets/{RoadmapsView-DdYXssP2.js → RoadmapsView-BTJtmBnF.js} +2 -2
  17. package/dist/client/assets/SettingsModal-DZ_LaEhd.js +31 -0
  18. package/dist/client/assets/{SettingsModal-CriZP5Lp.css → SettingsModal-DcGFm6NR.css} +1 -1
  19. package/dist/client/assets/{SettingsModal-CGWipm3s.js → SettingsModal-eNCZiHa6.js} +1 -1
  20. package/dist/client/assets/{SetupWizardModal-CKsJduYM.js → SetupWizardModal-yf79TN1L.js} +1 -1
  21. package/dist/client/assets/SkillMultiselect-DDHJnrkn.css +1 -0
  22. package/dist/client/assets/SkillMultiselect-DOj5vX4U.js +1 -0
  23. package/dist/client/assets/SkillsView-CgnCnikX.js +1 -0
  24. package/dist/client/assets/{TodoView-ByXJ90yL.js → TodoView-67BMyICY.js} +2 -2
  25. package/dist/client/assets/{folder-open-CxOUgHDf.js → folder-open-D11gjHGK.js} +1 -1
  26. package/dist/client/assets/index-BLn1R7Ob.css +1 -0
  27. package/dist/client/assets/index-CLAHcGnI.js +656 -0
  28. package/dist/client/assets/{list-checks--sf9u9ox.js → list-checks-CBzPc3GA.js} +1 -1
  29. package/dist/client/assets/{star-CF1f2iPu.js → star-BWcRk8nt.js} +1 -1
  30. package/dist/client/assets/{upload-rOBd4OhB.js → upload-91TM4ljC.js} +1 -1
  31. package/dist/client/assets/{users-De-vFat1.js → users-BAsI___L.js} +1 -1
  32. package/dist/client/index.html +2 -2
  33. package/dist/client/theme-data.css +1 -1
  34. package/dist/client/version.json +1 -1
  35. package/dist/extension.js +479 -74
  36. package/dist/pi-claude-cli/package.json +1 -1
  37. package/package.json +1 -1
  38. package/skill/fusion/references/cli-commands.md +14 -0
  39. package/skill/fusion/references/engine-tools.md +1 -0
  40. package/dist/client/assets/ChatView-DK5CmiAk.js +0 -1
  41. package/dist/client/assets/PluginManager-Dx0mcwat.js +0 -1
  42. package/dist/client/assets/ResearchView-BVJFgfat.css +0 -1
  43. package/dist/client/assets/SettingsModal-Bgjg_4CD.js +0 -31
  44. package/dist/client/assets/SkillsView-C4Tz7CxC.js +0 -1
  45. package/dist/client/assets/index-BCz4ye4p.css +0 -1
  46. package/dist/client/assets/index-D7gT6mCr.js +0 -656
@@ -1,14 +1,14 @@
1
- import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Y,aC as xe,aD as ge,aE as pe,aF as je,aG as Z,aH as Q,A as T,aI as _e,_ as Ne,$ as be,aJ as ee,aK as ve,aL as Ce,X as B,aM as ke,aN as Se,R as J,N as G,G as we}from"./index-D7gT6mCr.js";import{U as se}from"./upload-rOBd4OhB.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as n,j as e}from"./vendor-react-K0fH_qHe.js";import{c as W,aB as xe,aC as ge,aD as pe,aE as je,aF as Z,aG as Q,A as T,aH as _e,Y as Ne,_ as be,aI as ee,aJ as ve,aK as Ce,X as V,aL as ke,aM as Se,R as J,M as G,G as we}from"./index-CLAHcGnI.js";import{U as se}from"./upload-91TM4ljC.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.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const Me=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],Ae=Y("wifi-off",Me);/**
6
+ */const Me=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],Ae=W("wifi-off",Me);/**
7
7
  * @license lucide-react v1.7.0 - ISC
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 Ee=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],Re=Y("wifi",Ee);function U(t){const{lastSyncAt:l,remoteReachable:s,diff:r}=t,f=r.global.length+r.project.length;return l===null?{syncState:"never-synced",lastSyncAt:l,diffCount:0}:s?f>0?{syncState:"diff",lastSyncAt:l,diffCount:f}:{syncState:"synced",lastSyncAt:l,diffCount:0}:{syncState:"error",lastSyncAt:l,diffCount:f}}function te(t){if(t===null)return"Never synced";const l=new Date(t);if(Number.isNaN(l.getTime()))return"Never synced";const r=Date.now()-l.getTime(),f=Math.floor(r/1e3),m=Math.floor(f/60),c=Math.floor(m/60),u=Math.floor(c/24);return m<1?"Synced just now":m<60?`Synced ${m}m ago`:c<24?`Synced ${c}h ago`:`Synced ${u}d ago`}function ae(t){switch(t){case"synced":return"var(--color-success)";case"pending":return"var(--color-warning)";case"diff":return"var(--color-warning)";case"error":return"var(--color-error)";case"never-synced":return"var(--text-muted)"}}const Pe=3e4;function $e(){const[t,l]=n.useState({}),[s,r]=n.useState(!1),[f,m]=n.useState({}),[c,u]=n.useState(null),o=n.useRef(new Set),y=n.useRef(!1),g=n.useRef(null),j=n.useRef(null),C=n.useCallback(async(h,d)=>{try{const p=await xe(h);l(z=>({...z,[h]:p})),u(null)}catch(p){console.error(`Failed to fetch sync status for node ${h}:`,p),u(p instanceof Error?p.message:"Failed to fetch sync status")}},[]),_=n.useCallback(async()=>{const h=Array.from(o.current);if(h.length===0)return;g.current&&g.current.abort(),g.current=new AbortController;const d=!y.current;d&&r(!0),u(null);try{const p=await Promise.allSettled(h.map(L=>C(L,d)));y.current=!0,p.filter(L=>L.status==="rejected").length>0&&u("Some sync status requests failed")}catch(p){if(p instanceof Error&&p.name==="AbortError")return;u(p instanceof Error?p.message:"Failed to fetch sync status"),y.current=!0}finally{r(!1)}},[C]),S=n.useCallback(()=>{j.current&&clearInterval(j.current),j.current=setInterval(()=>{_()},Pe)},[_]),M=n.useCallback(()=>{j.current&&(clearInterval(j.current),j.current=null)},[]);n.useEffect(()=>(_(),S(),()=>{M(),g.current&&g.current.abort()}),[_,S,M]);const a=n.useCallback(h=>{o.current.has(h)||(o.current.add(h),C(h,!y.current))},[C]),i=n.useCallback(h=>{o.current.delete(h),l(d=>{const p={...d};return delete p[h],p}),o.current.size===0&&M()},[M]),x=n.useCallback(async h=>{m(d=>({...d,[h]:!0})),u(null);try{const d=await ge(h);return C(h,!1),!d.success&&d.error&&u(d.error),d}catch(d){const p=d instanceof Error?d.message:"Push settings failed";throw u(p),d}finally{m(d=>{const p={...d};return delete p[h],p})}},[C]),b=n.useCallback(async h=>{m(d=>({...d,[h]:!0})),u(null);try{const d=await pe(h);return C(h,!1),!d.success&&d.error&&u(d.error),d}catch(d){const p=d instanceof Error?d.message:"Pull settings failed";throw u(p),d}finally{m(d=>{const p={...d};return delete p[h],p})}},[C]),w=n.useCallback(async h=>{m(d=>({...d,[h]:!0})),u(null);try{return await je(h)}catch(d){const p=d instanceof Error?d.message:"Auth sync failed";throw u(p),d}finally{m(d=>{const p={...d};return delete p[h],p})}},[]),$=n.useCallback(h=>t[h]?.authMatch,[t]),v=n.useCallback(h=>t[h]?.authDiff,[t]);return{syncStatusMap:t,loading:s,actionLoading:f,error:c,refresh:_,trackNode:a,untrackNode:i,pushSettings:x,pullSettings:b,syncAuth:w,getAuthSyncState:$,getAuthProviders:v}}function Le(t,l){return l.type==="remote"?t.nodeId===l.id:t.nodeId===l.id||t.nodeId===void 0||t.nodeId===null}function ne(t,l){return t.filter(s=>Le(s,l))}function H(t,l){return ne(t,l).length}const ze={online:{label:"Online",color:"var(--color-success)",className:"node-card__status--online"},offline:{label:"Offline",color:"var(--color-error)",className:"node-card__status--offline"},connecting:{label:"Connecting",color:"var(--color-warning)",className:"node-card__status--connecting"},error:{label:"Error",color:"var(--color-error)",className:"node-card__status--error"}},De={match:"var(--color-success)",differs:"var(--color-warning)","not-synced":"var(--text-muted)"};function Oe(t,l){if(t==="match")return"Auth credentials match";if(t==="not-synced")return"Auth not synced";if(l&&Object.keys(l).length>0){const s=Object.entries(l).filter(([,r])=>r==="differs").map(([r])=>r);if(s.length>0)return`Auth credentials differ: ${s.join(", ")}`}return"Auth credentials differ"}function Fe(t,l=42){return t.length<=l?t:`${t.slice(0,l-3)}...`}function Ie(t,l){const s=t.node,r=l.node;if(s.id!==r.id||s.name!==r.name||s.type!==r.type||s.url!==r.url||s.status!==r.status||s.maxConcurrent!==r.maxConcurrent||s.updatedAt!==r.updatedAt||t.isLoading!==l.isLoading)return!1;const f=t.syncStatus,m=l.syncStatus;if(!(!f&&!m)){if(!f||!m)return!1;if(f.syncState!==m.syncState||f.lastSyncAt!==m.lastSyncAt||f.diffCount!==m.diffCount)return!1}if(t.authSyncState!==l.authSyncState)return!1;const c=t.authSyncProviders,u=l.authSyncProviders;if(c!==u){if(!c||!u)return!1;{const g=Object.keys(c),j=Object.keys(u);if(g.length!==j.length||g.some(C=>c[C]!==u[C]))return!1}}const o=H(t.projects,s),y=H(l.projects,r);return o===y}function Ke({node:t,projects:l,onHealthCheck:s,onEdit:r,onRemove:f,isLoading:m=!1,syncStatus:c,authSyncState:u,authSyncProviders:o}){const[y,g]=n.useState(!1),j=ze[t.status],C=n.useMemo(()=>H(l,t),[l,t]),_=n.useCallback(()=>{r(t)},[r,t]),S=n.useCallback(x=>{x.stopPropagation(),s(t.id)},[s,t.id]),M=n.useCallback(x=>{x.stopPropagation(),r(t)},[r,t]),a=n.useCallback(x=>{if(x.stopPropagation(),!y){g(!0);return}f(t.id),g(!1)},[y,f,t.id]),i=n.useCallback(x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),r(t))},[r,t]);return e.jsxs("article",{className:`node-card ${m?"node-card--loading":""}`,"data-node-id":t.id,role:"button",tabIndex:0,onClick:_,onKeyDown:i,children:[e.jsx("header",{className:"node-card__header",children:e.jsxs("div",{className:"node-card__title-wrap",children:[e.jsx("div",{className:"node-card__icon",children:e.jsx(Z,{size:18})}),e.jsxs("div",{children:[e.jsx("h3",{className:"node-card__name",title:t.name,children:t.name}),e.jsxs("div",{className:"node-card__meta-row",children:[e.jsx("span",{className:"node-card__type-badge",children:t.type==="local"?"Local":"Remote"}),e.jsxs("span",{className:`node-card__status ${j.className}`,style:{color:j.color},"data-status":t.status,children:[e.jsx("span",{className:"node-card__status-indicator",style:{backgroundColor:j.color},"aria-hidden":!0}),j.label]}),t.type==="remote"&&u&&e.jsx("span",{className:`node-card__auth-indicator node-card__auth-indicator--${u}`,title:Oe(u,o),"aria-label":`Auth sync: ${u==="match"?"credentials match":u==="differs"?"credentials differ":"not synced"}`,style:{color:De[u]},children:e.jsx(Q,{size:14})})]})]})]})}),e.jsxs("div",{className:"node-card__body",children:[t.type==="remote"&&t.url&&e.jsx("div",{className:"node-card__url",title:t.url,children:Fe(t.url)}),e.jsxs("div",{className:"node-card__metrics",children:[e.jsxs("div",{className:"node-card__metric",children:[e.jsx("span",{className:"node-card__metric-label",children:"Projects"}),e.jsx("span",{className:"node-card__metric-value",children:C})]}),e.jsxs("div",{className:"node-card__metric",children:[e.jsx("span",{className:"node-card__metric-label",children:"Concurrency"}),e.jsx("span",{className:"node-card__metric-value",children:t.maxConcurrent})]})]}),t.type==="remote"&&c&&e.jsxs("div",{className:"node-card__sync","data-sync-state":c.syncState,"data-testid":"node-card-sync",children:[e.jsx("span",{className:"node-card__sync-dot",style:{backgroundColor:ae(c.syncState)},"aria-hidden":!0}),e.jsx("span",{className:"node-card__sync-time",children:te(c.lastSyncAt)})]})]}),e.jsxs("footer",{className:"node-card__actions",children:[e.jsxs("button",{className:"btn btn-sm node-card__action",type:"button",onClick:S,disabled:m,"aria-label":"Run node health check",title:"Health Check",children:[e.jsx(T,{size:14}),e.jsx("span",{children:"Health"})]}),e.jsxs("button",{className:"btn btn-sm node-card__action",type:"button",onClick:M,disabled:m,"aria-label":"Edit node",title:"Edit",children:[e.jsx(_e,{size:14}),e.jsx("span",{children:"Edit"})]}),e.jsxs("button",{className:`btn btn-sm node-card__action node-card__action--remove ${y?"btn-danger is-armed":""}`,type:"button",onClick:a,disabled:m,"aria-label":y?"Confirm remove node":"Remove node",title:y?"Confirm remove":"Remove",children:[e.jsx(Ne,{size:14}),e.jsx("span",{children:y?"Confirm":"Remove"})]})]})]})}const Ue=n.memo(Ke,Ie),O={online:"var(--success, var(--color-success))",offline:"var(--text-dim)",connecting:"var(--triage)",error:"var(--color-error)"},D=28,W=12,Ve=300,Be=120;function He({nodes:t,className:l}){const s=n.useMemo(()=>t.find(o=>o.type==="local")??t[0],[t]),r=n.useMemo(()=>t.filter(o=>o.type==="remote"),[t]),f=n.useMemo(()=>{const o=Ve,y=Math.max(0,r.length-4)*20;return o+y},[r.length]),m=f/2,c=f/2,u=n.useMemo(()=>{if(r.length===0)return[];const o=Math.min(Be,f/2-D-10),y=2*Math.PI/r.length,g=-Math.PI/2;return r.map((j,C)=>{const _=g+C*y;return{node:j,x:m+o*Math.cos(_),y:c+o*Math.sin(_)}})},[r,f,m,c]);return t.length===0?e.jsx("div",{className:`mesh-topology mesh-topology--empty ${l??""}`,children:e.jsx("div",{className:"mesh-topology__empty-state",children:e.jsx("p",{children:"No nodes to display"})})}):e.jsxs("div",{className:`mesh-topology ${l??""}`,children:[e.jsxs("svg",{className:"mesh-topology__svg",viewBox:`0 0 ${f} ${f}`,preserveAspectRatio:"xMidYMid meet","aria-label":"Node mesh topology visualization",children:[u.map(o=>e.jsx("line",{className:"mesh-topology__link",x1:m,y1:c,x2:o.x,y2:o.y},`link-${o.node.id}`)),s&&e.jsxs("g",{className:"mesh-topology__node",transform:`translate(${m}, ${c})`,children:[e.jsx("circle",{className:"mesh-topology__node-circle",r:D,fill:O[s.status],"aria-label":`${s.name} (${s.status})`}),e.jsx("text",{className:"mesh-topology__node-label",y:D+W,textAnchor:"middle",children:s.name.length>12?`${s.name.slice(0,10)}…`:s.name}),e.jsxs("g",{className:"mesh-topology__node-type",transform:`translate(0 ${-D-10})`,children:[e.jsx("circle",{className:"mesh-topology__node-type-badge",r:"8"}),e.jsx("text",{className:"mesh-topology__node-type-text",textAnchor:"middle",dominantBaseline:"middle",children:s.type==="local"?"L":"R"})]})]}),u.map(o=>e.jsxs("g",{className:"mesh-topology__node",transform:`translate(${o.x}, ${o.y})`,children:[e.jsx("circle",{className:"mesh-topology__node-circle",r:D,fill:O[o.node.status],"aria-label":`${o.node.name} (${o.node.status})`}),e.jsx("text",{className:"mesh-topology__node-label",y:D+W,textAnchor:"middle",children:o.node.name.length>12?`${o.node.name.slice(0,10)}…`:o.node.name}),e.jsxs("g",{className:"mesh-topology__node-type",transform:`translate(0 ${-D-10})`,children:[e.jsx("circle",{className:"mesh-topology__node-type-badge",r:"8"}),e.jsx("text",{className:"mesh-topology__node-type-text",textAnchor:"middle",dominantBaseline:"middle",children:o.node.type==="local"?"L":"R"})]})]},o.node.id))]}),e.jsxs("div",{className:"mesh-topology__legend",children:[e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.online}}),e.jsx("span",{children:"Online"})]}),e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.offline}}),e.jsx("span",{children:"Offline"})]}),e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.connecting}}),e.jsx("span",{children:"Connecting"})]}),e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.error}}),e.jsx("span",{children:"Error"})]})]}),e.jsx("p",{className:"mesh-topology__notice",children:"Peer-to-peer discovery data unavailable."})]})}const qe=n.memo(He),q=1,X=10;function Xe(t){const l={};return t.name.trim()||(l.name="Name is required"),t.type==="remote"&&!t.url?.trim()&&(l.url="URL is required for remote nodes"),(!Number.isFinite(t.maxConcurrent)||t.maxConcurrent<q||t.maxConcurrent>X)&&(l.maxConcurrent=`Concurrency must be between ${q} and ${X}`),l}function Je({isOpen:t,onClose:l,onSubmit:s,addToast:r}){const[f,m]=n.useState(""),[c,u]=n.useState("local"),[o,y]=n.useState(""),[g,j]=n.useState(""),[C,_]=n.useState(2),[S,M]=n.useState({}),[a,i]=n.useState(!1),x=n.useCallback(()=>{m(""),u("local"),y(""),j(""),_(2),M({}),i(!1)},[]),b=n.useCallback(()=>{a||(x(),l())},[a,l,x]);n.useEffect(()=>{if(!t){x();return}const v=h=>{h.key==="Escape"&&(h.preventDefault(),b())};return document.addEventListener("keydown",v),()=>{document.removeEventListener("keydown",v)}},[b,t,x]);const w=n.useMemo(()=>({name:f.trim(),type:c,url:c==="remote"&&o.trim()||void 0,apiKey:c==="remote"&&g||void 0,maxConcurrent:C}),[g,C,f,c,o]),$=n.useCallback(async()=>{if(a)return;const v=Xe(w);if(M(v),!(Object.keys(v).length>0)){i(!0);try{await s(w),r(`Node "${w.name}" registered`,"success"),b()}catch(h){const d=h instanceof Error?h.message:"Failed to register node";r(d,"error")}finally{i(!1)}}},[r,b,w,a,s]);return t?e.jsx("div",{className:"modal-overlay open",onClick:b,children:e.jsxs("div",{className:"modal modal-md add-node-modal",onClick:v=>v.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add Node",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Add Node"}),e.jsx("button",{className:"modal-close",onClick:b,disabled:a,"aria-label":"Close add node modal",children:"×"})]}),e.jsxs("div",{className:"modal-body add-node-modal__body",children:[e.jsx("p",{className:"add-node-modal__description",children:"Register a node to distribute task execution across machines."}),e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{className:"input",type:"text",value:f,onChange:v=>m(v.target.value),placeholder:"Build Machine",disabled:a,"aria-invalid":!!S.name,autoFocus:!0}),S.name&&e.jsx("span",{className:"form-error add-node-modal__error",children:S.name})]}),e.jsxs("div",{className:"add-node-modal__type-toggle",children:[e.jsx("button",{type:"button",className:`add-node-modal__type-btn ${c==="local"?"active":""}`,"data-type":"local",onClick:()=>u("local"),disabled:a,"aria-pressed":c==="local",children:"Local"}),e.jsx("button",{type:"button",className:`add-node-modal__type-btn ${c==="remote"?"active":""}`,"data-type":"remote",onClick:()=>u("remote"),disabled:a,"aria-pressed":c==="remote",children:"Remote"})]}),e.jsxs("div",{className:"add-node-modal__remote-fields","data-testid":"remote-fields-container","data-visible":c==="remote",children:[e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"URL"}),e.jsx("input",{className:"input",type:"text",value:o,onChange:v=>y(v.target.value),placeholder:"https://node.example.com",disabled:a,"aria-invalid":!!S.url}),S.url&&e.jsx("span",{className:"form-error add-node-modal__error",children:S.url})]}),e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"API Key"}),e.jsx("input",{className:"input",type:"password",value:g,onChange:v=>j(v.target.value),placeholder:"Optional",disabled:a})]})]}),e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"Max Concurrent"}),e.jsx("input",{className:"input",type:"number",min:q,max:X,value:C,onChange:v=>_(Number(v.target.value)),disabled:a,"aria-invalid":!!S.maxConcurrent}),e.jsx("span",{className:"add-node-modal__hint",children:"Max simultaneous task agents (1–10)"}),S.maxConcurrent&&e.jsx("span",{className:"form-error add-node-modal__error",children:S.maxConcurrent})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:b,disabled:a,children:"Cancel"}),e.jsx("button",{className:"btn btn-primary btn-sm","data-testid":"add-node-submit",onClick:$,disabled:a,children:a?"Adding...":"Add Node"})]})]})}):null}function Ge({nodeId:t,entries:l,loading:s=!1,singleNode:r=!1}){const[f,m]=n.useState(!1),[c,u]=n.useState("all"),[o,y]=n.useState("all"),g=n.useCallback(()=>{m(a=>!a)},[]),j=n.useMemo(()=>{const a=new Set;for(const i of l)a.add(i.nodeName);return Array.from(a).sort()},[l]),C=n.useMemo(()=>{let a=[...l];return c!=="all"&&(a=a.filter(i=>i.direction===c)),!r&&o!=="all"&&(a=a.filter(i=>i.nodeName===o)),a.sort((i,x)=>{const b=new Date(i.timestamp).getTime();return new Date(x.timestamp).getTime()-b}),a},[l,c,o,r]),_=n.useCallback(a=>new Date(a).toLocaleString(),[]),S=n.useCallback(a=>{switch(a){case"success":return"settings-sync-log__badge--success";case"conflict":return"settings-sync-log__badge--conflict";case"error":return"settings-sync-log__badge--error";default:return""}},[]),M=n.useCallback(a=>{switch(a){case"success":return"Success";case"conflict":return"Conflict";case"error":return"Error";default:return a}},[]);return e.jsxs("div",{className:"settings-sync-log",children:[e.jsxs("button",{className:"settings-sync-log__header",type:"button",onClick:g,"aria-expanded":f,"data-testid":"settings-sync-log-header",children:[e.jsx(be,{size:16,className:`settings-sync-log__chevron ${f?"settings-sync-log__chevron--expanded":""}`}),e.jsxs("span",{children:[l.length," ",l.length===1?"entry":"entries"]})]}),f&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"settings-sync-log__filters",children:[e.jsxs("label",{children:["Direction:",e.jsxs("select",{value:c,onChange:a=>u(a.target.value),children:[e.jsx("option",{value:"all",children:"All"}),e.jsx("option",{value:"push",children:"Push"}),e.jsx("option",{value:"pull",children:"Pull"})]})]}),!r&&e.jsxs("label",{children:["Node:",e.jsxs("select",{value:o,onChange:a=>y(a.target.value),children:[e.jsx("option",{value:"all",children:"All Nodes"}),j.map(a=>e.jsx("option",{value:a,children:a},a))]})]})]}),s&&l.length===0?e.jsx("div",{className:"settings-sync-log__empty",children:"Loading..."}):C.length===0?e.jsx("div",{className:"settings-sync-log__empty",children:"No sync history available"}):e.jsx("div",{className:"settings-sync-log__list",children:C.map(a=>e.jsxs("div",{className:"settings-sync-log__entry",children:[e.jsx("span",{className:"settings-sync-log__entry-timestamp",children:_(a.timestamp)}),e.jsx("span",{className:"settings-sync-log__entry-direction",children:a.direction==="push"?e.jsx(se,{size:14,"data-testid":"upload-icon"}):e.jsx(ee,{size:14,"data-testid":"download-icon"})}),e.jsx("span",{className:`settings-sync-log__entry-result ${S(a.result)}`,children:M(a.result)}),!r&&e.jsx("span",{className:"settings-sync-log__entry-node",children:a.nodeName}),a.details&&e.jsx("span",{className:"settings-sync-log__entry-details",title:a.details,children:a.details})]},a.id))})]})]})}function We(t,l){const s=typeof t=="string"?t:JSON.stringify(t,null,2),r=typeof l=="string"?l:JSON.stringify(l,null,2);if(s===r)return s;const f=s.split(`
11
+ */const Ee=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],Re=W("wifi",Ee);function U(t){const{lastSyncAt:l,remoteReachable:s,diff:r}=t,f=r.global.length+r.project.length;return l===null?{syncState:"never-synced",lastSyncAt:l,diffCount:0}:s?f>0?{syncState:"diff",lastSyncAt:l,diffCount:f}:{syncState:"synced",lastSyncAt:l,diffCount:0}:{syncState:"error",lastSyncAt:l,diffCount:f}}function te(t){if(t===null)return"Never synced";const l=new Date(t);if(Number.isNaN(l.getTime()))return"Never synced";const r=Date.now()-l.getTime(),f=Math.floor(r/1e3),m=Math.floor(f/60),c=Math.floor(m/60),u=Math.floor(c/24);return m<1?"Synced just now":m<60?`Synced ${m}m ago`:c<24?`Synced ${c}h ago`:`Synced ${u}d ago`}function ae(t){switch(t){case"synced":return"var(--color-success)";case"pending":return"var(--color-warning)";case"diff":return"var(--color-warning)";case"error":return"var(--color-error)";case"never-synced":return"var(--text-muted)"}}const Pe=3e4;function $e(){const[t,l]=n.useState({}),[s,r]=n.useState(!1),[f,m]=n.useState({}),[c,u]=n.useState(null),o=n.useRef(new Set),y=n.useRef(!1),g=n.useRef(null),j=n.useRef(null),C=n.useCallback(async(h,d)=>{try{const p=await xe(h);l(z=>({...z,[h]:p})),u(null)}catch(p){console.error(`Failed to fetch sync status for node ${h}:`,p),u(p instanceof Error?p.message:"Failed to fetch sync status")}},[]),_=n.useCallback(async()=>{const h=Array.from(o.current);if(h.length===0)return;g.current&&g.current.abort(),g.current=new AbortController;const d=!y.current;d&&r(!0),u(null);try{const p=await Promise.allSettled(h.map(L=>C(L,d)));y.current=!0,p.filter(L=>L.status==="rejected").length>0&&u("Some sync status requests failed")}catch(p){if(p instanceof Error&&p.name==="AbortError")return;u(p instanceof Error?p.message:"Failed to fetch sync status"),y.current=!0}finally{r(!1)}},[C]),S=n.useCallback(()=>{j.current&&clearInterval(j.current),j.current=setInterval(()=>{_()},Pe)},[_]),M=n.useCallback(()=>{j.current&&(clearInterval(j.current),j.current=null)},[]);n.useEffect(()=>(_(),S(),()=>{M(),g.current&&g.current.abort()}),[_,S,M]);const a=n.useCallback(h=>{o.current.has(h)||(o.current.add(h),C(h,!y.current))},[C]),i=n.useCallback(h=>{o.current.delete(h),l(d=>{const p={...d};return delete p[h],p}),o.current.size===0&&M()},[M]),x=n.useCallback(async h=>{m(d=>({...d,[h]:!0})),u(null);try{const d=await ge(h);return C(h,!1),!d.success&&d.error&&u(d.error),d}catch(d){const p=d instanceof Error?d.message:"Push settings failed";throw u(p),d}finally{m(d=>{const p={...d};return delete p[h],p})}},[C]),b=n.useCallback(async h=>{m(d=>({...d,[h]:!0})),u(null);try{const d=await pe(h);return C(h,!1),!d.success&&d.error&&u(d.error),d}catch(d){const p=d instanceof Error?d.message:"Pull settings failed";throw u(p),d}finally{m(d=>{const p={...d};return delete p[h],p})}},[C]),w=n.useCallback(async h=>{m(d=>({...d,[h]:!0})),u(null);try{return await je(h)}catch(d){const p=d instanceof Error?d.message:"Auth sync failed";throw u(p),d}finally{m(d=>{const p={...d};return delete p[h],p})}},[]),$=n.useCallback(h=>t[h]?.authMatch,[t]),v=n.useCallback(h=>t[h]?.authDiff,[t]);return{syncStatusMap:t,loading:s,actionLoading:f,error:c,refresh:_,trackNode:a,untrackNode:i,pushSettings:x,pullSettings:b,syncAuth:w,getAuthSyncState:$,getAuthProviders:v}}function Le(t,l){return l.type==="remote"?t.nodeId===l.id:t.nodeId===l.id||t.nodeId===void 0||t.nodeId===null}function ne(t,l){return t.filter(s=>Le(s,l))}function H(t,l){return ne(t,l).length}const ze={online:{label:"Online",color:"var(--color-success)",className:"node-card__status--online"},offline:{label:"Offline",color:"var(--color-error)",className:"node-card__status--offline"},connecting:{label:"Connecting",color:"var(--color-warning)",className:"node-card__status--connecting"},error:{label:"Error",color:"var(--color-error)",className:"node-card__status--error"}},De={match:"var(--color-success)",differs:"var(--color-warning)","not-synced":"var(--text-muted)"};function Oe(t,l){if(t==="match")return"Auth credentials match";if(t==="not-synced")return"Auth not synced";if(l&&Object.keys(l).length>0){const s=Object.entries(l).filter(([,r])=>r==="differs").map(([r])=>r);if(s.length>0)return`Auth credentials differ: ${s.join(", ")}`}return"Auth credentials differ"}function Fe(t,l=42){return t.length<=l?t:`${t.slice(0,l-3)}...`}function Ie(t,l){const s=t.node,r=l.node;if(s.id!==r.id||s.name!==r.name||s.type!==r.type||s.url!==r.url||s.status!==r.status||s.maxConcurrent!==r.maxConcurrent||s.updatedAt!==r.updatedAt||t.isLoading!==l.isLoading)return!1;const f=t.syncStatus,m=l.syncStatus;if(!(!f&&!m)){if(!f||!m)return!1;if(f.syncState!==m.syncState||f.lastSyncAt!==m.lastSyncAt||f.diffCount!==m.diffCount)return!1}if(t.authSyncState!==l.authSyncState)return!1;const c=t.authSyncProviders,u=l.authSyncProviders;if(c!==u){if(!c||!u)return!1;{const g=Object.keys(c),j=Object.keys(u);if(g.length!==j.length||g.some(C=>c[C]!==u[C]))return!1}}const o=H(t.projects,s),y=H(l.projects,r);return o===y}function Ke({node:t,projects:l,onHealthCheck:s,onEdit:r,onRemove:f,isLoading:m=!1,syncStatus:c,authSyncState:u,authSyncProviders:o}){const[y,g]=n.useState(!1),j=ze[t.status],C=n.useMemo(()=>H(l,t),[l,t]),_=n.useCallback(()=>{r(t)},[r,t]),S=n.useCallback(x=>{x.stopPropagation(),s(t.id)},[s,t.id]),M=n.useCallback(x=>{x.stopPropagation(),r(t)},[r,t]),a=n.useCallback(x=>{if(x.stopPropagation(),!y){g(!0);return}f(t.id),g(!1)},[y,f,t.id]),i=n.useCallback(x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),r(t))},[r,t]);return e.jsxs("article",{className:`node-card ${m?"node-card--loading":""}`,"data-node-id":t.id,role:"button",tabIndex:0,onClick:_,onKeyDown:i,children:[e.jsx("header",{className:"node-card__header",children:e.jsxs("div",{className:"node-card__title-wrap",children:[e.jsx("div",{className:"node-card__icon",children:e.jsx(Z,{size:18})}),e.jsxs("div",{children:[e.jsx("h3",{className:"node-card__name",title:t.name,children:t.name}),e.jsxs("div",{className:"node-card__meta-row",children:[e.jsx("span",{className:"node-card__type-badge",children:t.type==="local"?"Local":"Remote"}),e.jsxs("span",{className:`node-card__status ${j.className}`,style:{color:j.color},"data-status":t.status,children:[e.jsx("span",{className:"node-card__status-indicator",style:{backgroundColor:j.color},"aria-hidden":!0}),j.label]}),t.type==="remote"&&u&&e.jsx("span",{className:`node-card__auth-indicator node-card__auth-indicator--${u}`,title:Oe(u,o),"aria-label":`Auth sync: ${u==="match"?"credentials match":u==="differs"?"credentials differ":"not synced"}`,style:{color:De[u]},children:e.jsx(Q,{size:14})})]})]})]})}),e.jsxs("div",{className:"node-card__body",children:[t.type==="remote"&&t.url&&e.jsx("div",{className:"node-card__url",title:t.url,children:Fe(t.url)}),e.jsxs("div",{className:"node-card__metrics",children:[e.jsxs("div",{className:"node-card__metric",children:[e.jsx("span",{className:"node-card__metric-label",children:"Projects"}),e.jsx("span",{className:"node-card__metric-value",children:C})]}),e.jsxs("div",{className:"node-card__metric",children:[e.jsx("span",{className:"node-card__metric-label",children:"Concurrency"}),e.jsx("span",{className:"node-card__metric-value",children:t.maxConcurrent})]})]}),t.type==="remote"&&c&&e.jsxs("div",{className:"node-card__sync","data-sync-state":c.syncState,"data-testid":"node-card-sync",children:[e.jsx("span",{className:"node-card__sync-dot",style:{backgroundColor:ae(c.syncState)},"aria-hidden":!0}),e.jsx("span",{className:"node-card__sync-time",children:te(c.lastSyncAt)})]})]}),e.jsxs("footer",{className:"node-card__actions",children:[e.jsxs("button",{className:"btn btn-sm node-card__action",type:"button",onClick:S,disabled:m,"aria-label":"Run node health check",title:"Health Check",children:[e.jsx(T,{size:14}),e.jsx("span",{children:"Health"})]}),e.jsxs("button",{className:"btn btn-sm node-card__action",type:"button",onClick:M,disabled:m,"aria-label":"Edit node",title:"Edit",children:[e.jsx(_e,{size:14}),e.jsx("span",{children:"Edit"})]}),e.jsxs("button",{className:`btn btn-sm node-card__action node-card__action--remove ${y?"btn-danger is-armed":""}`,type:"button",onClick:a,disabled:m,"aria-label":y?"Confirm remove node":"Remove node",title:y?"Confirm remove":"Remove",children:[e.jsx(Ne,{size:14}),e.jsx("span",{children:y?"Confirm":"Remove"})]})]})]})}const Ue=n.memo(Ke,Ie),O={online:"var(--success, var(--color-success))",offline:"var(--text-dim)",connecting:"var(--triage)",error:"var(--color-error)"},D=28,Y=12,Be=300,Ve=120;function He({nodes:t,className:l}){const s=n.useMemo(()=>t.find(o=>o.type==="local")??t[0],[t]),r=n.useMemo(()=>t.filter(o=>o.type==="remote"),[t]),f=n.useMemo(()=>{const o=Be,y=Math.max(0,r.length-4)*20;return o+y},[r.length]),m=f/2,c=f/2,u=n.useMemo(()=>{if(r.length===0)return[];const o=Math.min(Ve,f/2-D-10),y=2*Math.PI/r.length,g=-Math.PI/2;return r.map((j,C)=>{const _=g+C*y;return{node:j,x:m+o*Math.cos(_),y:c+o*Math.sin(_)}})},[r,f,m,c]);return t.length===0?e.jsx("div",{className:`mesh-topology mesh-topology--empty ${l??""}`,children:e.jsx("div",{className:"mesh-topology__empty-state",children:e.jsx("p",{children:"No nodes to display"})})}):e.jsxs("div",{className:`mesh-topology ${l??""}`,children:[e.jsxs("svg",{className:"mesh-topology__svg",viewBox:`0 0 ${f} ${f}`,preserveAspectRatio:"xMidYMid meet","aria-label":"Node mesh topology visualization",children:[u.map(o=>e.jsx("line",{className:"mesh-topology__link",x1:m,y1:c,x2:o.x,y2:o.y},`link-${o.node.id}`)),s&&e.jsxs("g",{className:"mesh-topology__node",transform:`translate(${m}, ${c})`,children:[e.jsx("circle",{className:"mesh-topology__node-circle",r:D,fill:O[s.status],"aria-label":`${s.name} (${s.status})`}),e.jsx("text",{className:"mesh-topology__node-label",y:D+Y,textAnchor:"middle",children:s.name.length>12?`${s.name.slice(0,10)}…`:s.name}),e.jsxs("g",{className:"mesh-topology__node-type",transform:`translate(0 ${-D-10})`,children:[e.jsx("circle",{className:"mesh-topology__node-type-badge",r:"8"}),e.jsx("text",{className:"mesh-topology__node-type-text",textAnchor:"middle",dominantBaseline:"middle",children:s.type==="local"?"L":"R"})]})]}),u.map(o=>e.jsxs("g",{className:"mesh-topology__node",transform:`translate(${o.x}, ${o.y})`,children:[e.jsx("circle",{className:"mesh-topology__node-circle",r:D,fill:O[o.node.status],"aria-label":`${o.node.name} (${o.node.status})`}),e.jsx("text",{className:"mesh-topology__node-label",y:D+Y,textAnchor:"middle",children:o.node.name.length>12?`${o.node.name.slice(0,10)}…`:o.node.name}),e.jsxs("g",{className:"mesh-topology__node-type",transform:`translate(0 ${-D-10})`,children:[e.jsx("circle",{className:"mesh-topology__node-type-badge",r:"8"}),e.jsx("text",{className:"mesh-topology__node-type-text",textAnchor:"middle",dominantBaseline:"middle",children:o.node.type==="local"?"L":"R"})]})]},o.node.id))]}),e.jsxs("div",{className:"mesh-topology__legend",children:[e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.online}}),e.jsx("span",{children:"Online"})]}),e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.offline}}),e.jsx("span",{children:"Offline"})]}),e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.connecting}}),e.jsx("span",{children:"Connecting"})]}),e.jsxs("div",{className:"mesh-topology__legend-item",children:[e.jsx("span",{className:"mesh-topology__legend-dot",style:{background:O.error}}),e.jsx("span",{children:"Error"})]})]}),e.jsx("p",{className:"mesh-topology__notice",children:"Peer-to-peer discovery data unavailable."})]})}const qe=n.memo(He),q=1,X=10;function Xe(t){const l={};return t.name.trim()||(l.name="Name is required"),t.type==="remote"&&!t.url?.trim()&&(l.url="URL is required for remote nodes"),(!Number.isFinite(t.maxConcurrent)||t.maxConcurrent<q||t.maxConcurrent>X)&&(l.maxConcurrent=`Concurrency must be between ${q} and ${X}`),l}function Je({isOpen:t,onClose:l,onSubmit:s,addToast:r}){const[f,m]=n.useState(""),[c,u]=n.useState("local"),[o,y]=n.useState(""),[g,j]=n.useState(""),[C,_]=n.useState(2),[S,M]=n.useState({}),[a,i]=n.useState(!1),x=n.useCallback(()=>{m(""),u("local"),y(""),j(""),_(2),M({}),i(!1)},[]),b=n.useCallback(()=>{a||(x(),l())},[a,l,x]);n.useEffect(()=>{if(!t){x();return}const v=h=>{h.key==="Escape"&&(h.preventDefault(),b())};return document.addEventListener("keydown",v),()=>{document.removeEventListener("keydown",v)}},[b,t,x]);const w=n.useMemo(()=>({name:f.trim(),type:c,url:c==="remote"&&o.trim()||void 0,apiKey:c==="remote"&&g||void 0,maxConcurrent:C}),[g,C,f,c,o]),$=n.useCallback(async()=>{if(a)return;const v=Xe(w);if(M(v),!(Object.keys(v).length>0)){i(!0);try{await s(w),r(`Node "${w.name}" registered`,"success"),b()}catch(h){const d=h instanceof Error?h.message:"Failed to register node";r(d,"error")}finally{i(!1)}}},[r,b,w,a,s]);return t?e.jsx("div",{className:"modal-overlay open",onClick:b,children:e.jsxs("div",{className:"modal modal-md add-node-modal",onClick:v=>v.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add Node",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Add Node"}),e.jsx("button",{className:"modal-close",onClick:b,disabled:a,"aria-label":"Close add node modal",children:"×"})]}),e.jsxs("div",{className:"modal-body add-node-modal__body",children:[e.jsx("p",{className:"add-node-modal__description",children:"Register a node to distribute task execution across machines."}),e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"Name"}),e.jsx("input",{className:"input",type:"text",value:f,onChange:v=>m(v.target.value),placeholder:"Build Machine",disabled:a,"aria-invalid":!!S.name,autoFocus:!0}),S.name&&e.jsx("span",{className:"form-error add-node-modal__error",children:S.name})]}),e.jsxs("div",{className:"add-node-modal__type-toggle",children:[e.jsx("button",{type:"button",className:`add-node-modal__type-btn ${c==="local"?"active":""}`,"data-type":"local",onClick:()=>u("local"),disabled:a,"aria-pressed":c==="local",children:"Local"}),e.jsx("button",{type:"button",className:`add-node-modal__type-btn ${c==="remote"?"active":""}`,"data-type":"remote",onClick:()=>u("remote"),disabled:a,"aria-pressed":c==="remote",children:"Remote"})]}),e.jsxs("div",{className:"add-node-modal__remote-fields","data-testid":"remote-fields-container","data-visible":c==="remote",children:[e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"URL"}),e.jsx("input",{className:"input",type:"text",value:o,onChange:v=>y(v.target.value),placeholder:"https://node.example.com",disabled:a,"aria-invalid":!!S.url}),S.url&&e.jsx("span",{className:"form-error add-node-modal__error",children:S.url})]}),e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"API Key"}),e.jsx("input",{className:"input",type:"password",value:g,onChange:v=>j(v.target.value),placeholder:"Optional",disabled:a})]})]}),e.jsxs("label",{className:"add-node-modal__field",children:[e.jsx("span",{children:"Max Concurrent"}),e.jsx("input",{className:"input",type:"number",min:q,max:X,value:C,onChange:v=>_(Number(v.target.value)),disabled:a,"aria-invalid":!!S.maxConcurrent}),e.jsx("span",{className:"add-node-modal__hint",children:"Max simultaneous task agents (1–10)"}),S.maxConcurrent&&e.jsx("span",{className:"form-error add-node-modal__error",children:S.maxConcurrent})]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:b,disabled:a,children:"Cancel"}),e.jsx("button",{className:"btn btn-primary btn-sm","data-testid":"add-node-submit",onClick:$,disabled:a,children:a?"Adding...":"Add Node"})]})]})}):null}function Ge({nodeId:t,entries:l,loading:s=!1,singleNode:r=!1}){const[f,m]=n.useState(!1),[c,u]=n.useState("all"),[o,y]=n.useState("all"),g=n.useCallback(()=>{m(a=>!a)},[]),j=n.useMemo(()=>{const a=new Set;for(const i of l)a.add(i.nodeName);return Array.from(a).sort()},[l]),C=n.useMemo(()=>{let a=[...l];return c!=="all"&&(a=a.filter(i=>i.direction===c)),!r&&o!=="all"&&(a=a.filter(i=>i.nodeName===o)),a.sort((i,x)=>{const b=new Date(i.timestamp).getTime();return new Date(x.timestamp).getTime()-b}),a},[l,c,o,r]),_=n.useCallback(a=>new Date(a).toLocaleString(),[]),S=n.useCallback(a=>{switch(a){case"success":return"settings-sync-log__badge--success";case"conflict":return"settings-sync-log__badge--conflict";case"error":return"settings-sync-log__badge--error";default:return""}},[]),M=n.useCallback(a=>{switch(a){case"success":return"Success";case"conflict":return"Conflict";case"error":return"Error";default:return a}},[]);return e.jsxs("div",{className:"settings-sync-log",children:[e.jsxs("button",{className:"settings-sync-log__header",type:"button",onClick:g,"aria-expanded":f,"data-testid":"settings-sync-log-header",children:[e.jsx(be,{size:16,className:`settings-sync-log__chevron ${f?"settings-sync-log__chevron--expanded":""}`}),e.jsxs("span",{children:[l.length," ",l.length===1?"entry":"entries"]})]}),f&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"settings-sync-log__filters",children:[e.jsxs("label",{children:["Direction:",e.jsxs("select",{value:c,onChange:a=>u(a.target.value),children:[e.jsx("option",{value:"all",children:"All"}),e.jsx("option",{value:"push",children:"Push"}),e.jsx("option",{value:"pull",children:"Pull"})]})]}),!r&&e.jsxs("label",{children:["Node:",e.jsxs("select",{value:o,onChange:a=>y(a.target.value),children:[e.jsx("option",{value:"all",children:"All Nodes"}),j.map(a=>e.jsx("option",{value:a,children:a},a))]})]})]}),s&&l.length===0?e.jsx("div",{className:"settings-sync-log__empty",children:"Loading..."}):C.length===0?e.jsx("div",{className:"settings-sync-log__empty",children:"No sync history available"}):e.jsx("div",{className:"settings-sync-log__list",children:C.map(a=>e.jsxs("div",{className:"settings-sync-log__entry",children:[e.jsx("span",{className:"settings-sync-log__entry-timestamp",children:_(a.timestamp)}),e.jsx("span",{className:"settings-sync-log__entry-direction",children:a.direction==="push"?e.jsx(se,{size:14,"data-testid":"upload-icon"}):e.jsx(ee,{size:14,"data-testid":"download-icon"})}),e.jsx("span",{className:`settings-sync-log__entry-result ${S(a.result)}`,children:M(a.result)}),!r&&e.jsx("span",{className:"settings-sync-log__entry-node",children:a.nodeName}),a.details&&e.jsx("span",{className:"settings-sync-log__entry-details",title:a.details,children:a.details})]},a.id))})]})]})}function Ye(t,l){const s=typeof t=="string"?t:JSON.stringify(t,null,2),r=typeof l=="string"?l:JSON.stringify(l,null,2);if(s===r)return s;const f=s.split(`
12
12
  `),m=r.split(`
13
13
  `),c=[],u=Math.max(f.length,m.length);for(let o=0;o<u;o++){const y=f[o],g=m[o];y!==void 0&&y!==g&&c.push(`- ${y}`),g!==void 0&&g!==y&&c.push(`+ ${g}`),y!==void 0&&y===g&&c.push(` ${y}`)}return c.join(`
14
- `)}function Ye({isOpen:t,onClose:l,onResolve:s,conflicts:r,localNodeName:f,remoteNodeName:m,addToast:c}){const[u,o]=n.useState({}),[y,g]=n.useState(!1);n.useEffect(()=>{const a={};for(const i of r)u[i.key]||(a[i.key]={resolution:"local"});Object.keys(a).length>0&&o(i=>({...i,...a}))},[r,u]),n.useEffect(()=>{if(!t)return;const a=i=>{i.key==="Escape"&&(i.preventDefault(),l())};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t,l]);const j=n.useCallback((a,i)=>{o(x=>{const b=x[a]??{};return i==="manual"?{...x,[a]:{resolution:"manual",manualValue:b.manualValue??JSON.stringify(r.find(w=>w.key===a)?.localValue??null,null,2)}}:{...x,[a]:{resolution:i}}})},[r]),C=n.useCallback((a,i)=>{o(x=>({...x,[a]:{...x[a],resolution:"manual",manualValue:i}}))},[]),_=n.useCallback(a=>{const i={};for(const x of r)i[x.key]={resolution:a};o(i)},[r]),S=n.useCallback(async()=>{g(!0);try{const a=r.map(i=>{const x=u[i.key]??{resolution:"local"};let b;switch(x.resolution){case"remote":b=i.remoteValue;break;case"manual":try{b=JSON.parse(x.manualValue??"null")}catch{b=x.manualValue??null}break;case"local":default:b=i.localValue;break}return{key:i.key,value:b}});await s(a),c("Settings conflicts resolved successfully","success"),l()}catch(a){const i=a instanceof Error?a.message:"Failed to resolve conflicts";c(i,"error")}finally{g(!1)}},[c,r,l,s,u]),M=n.useMemo(()=>{const a={};for(const i of r)a[i.key]=We(i.localValue,i.remoteValue);return a},[r]);return!t||r.length===0?null:e.jsx("div",{className:"modal-overlay open",onClick:l,children:e.jsxs("div",{className:"modal modal-lg settings-sync-conflict-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Resolve Settings Conflicts",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Resolve Settings Conflicts"}),e.jsx("button",{className:"modal-close",onClick:l,"aria-label":"Close conflict modal",children:"×"})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("div",{className:"settings-sync-conflict-modal__conflict-list",children:r.map(a=>{const i=u[a.key]??{resolution:"local"},x=M[a.key];return e.jsxs("div",{className:"settings-sync-conflict-modal__conflict-item",children:[e.jsx("div",{className:"settings-sync-conflict-modal__key",children:a.key}),e.jsxs("div",{className:"settings-sync-conflict-modal__diff-panel",children:[e.jsxs("div",{className:"settings-sync-conflict-modal__diff-side",children:[e.jsx("div",{className:"settings-sync-conflict-modal__diff-label",children:f}),e.jsx("div",{className:"settings-sync-conflict-modal__diff-content",children:e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap"},children:x})})]}),e.jsxs("div",{className:"settings-sync-conflict-modal__diff-side",children:[e.jsx("div",{className:"settings-sync-conflict-modal__diff-label",children:m}),e.jsx("div",{className:"settings-sync-conflict-modal__diff-content",children:e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap"},children:x})})]})]}),e.jsxs("div",{className:"settings-sync-conflict-modal__resolution",children:[e.jsxs("label",{children:[e.jsx("input",{type:"radio",name:`resolution-${a.key}`,checked:i.resolution==="local",onChange:()=>j(a.key,"local")}),"Keep Local"]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",name:`resolution-${a.key}`,checked:i.resolution==="remote",onChange:()=>j(a.key,"remote")}),"Keep Remote"]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",name:`resolution-${a.key}`,checked:i.resolution==="manual",onChange:()=>j(a.key,"manual")}),"Merge Manually"]})]}),i.resolution==="manual"&&e.jsx("textarea",{className:"settings-sync-conflict-modal__manual-input",value:i.manualValue??"",onChange:b=>C(a.key,b.target.value),placeholder:"Enter JSON value..."})]},a.key)})}),e.jsxs("div",{className:"settings-sync-conflict-modal__bulk-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>_("local"),type:"button",children:"Resolve All: Keep Local"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>_("remote"),type:"button",children:"Resolve All: Keep Remote"})]})]}),e.jsxs("div",{className:"modal-actions settings-sync-conflict-modal__footer",children:[e.jsx("button",{className:"btn btn-sm",onClick:l,children:"Cancel"}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:S,disabled:y,children:y?"Resolving...":"Confirm"})]})]})})}function V(t){if(!t)return"—";const l=new Date(t);return Number.isNaN(l.getTime())?"—":l.toLocaleString()}function Ze({isOpen:t,onClose:l,node:s,projects:r,onUpdate:f,onHealthCheck:m,addToast:c,syncStatus:u,onPushSettings:o,onPullSettings:y,onSyncAuth:g,syncHistory:j=[],onResolveConflicts:C}){const _=n.useRef(!0),[S,M]=n.useState(!1),[a,i]=n.useState(""),[x,b]=n.useState(""),[w,$]=n.useState(""),[v,h]=n.useState(2),[d,p]=n.useState(!1),[z,L]=n.useState(!1),[k,A]=n.useState(!1),[P,F]=n.useState(!1),[I,E]=n.useState(null),[le,re]=n.useState(!1),[ce]=n.useState([]);n.useEffect(()=>(_.current=!0,()=>{_.current=!1}),[]),n.useEffect(()=>{if(!s||!t){M(!1);return}i(s.name),b(s.url??""),$(s.apiKey??""),h(s.maxConcurrent),M(!1)},[t,s]),n.useEffect(()=>{if(!t)return;const N=R=>{R.key==="Escape"&&(R.preventDefault(),l())};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[t,l]);const K=n.useMemo(()=>s?ne(r,s):[],[s,r]),oe=n.useCallback(async()=>{if(s)try{if(await m(s.id),!_.current)return;c(`Health check completed for ${s.name}`,"success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Health check failed";c(R,"error")}},[c,s,m]),ie=n.useCallback(async()=>{if(!(!s||!o)){E(null),L(!0);try{if(await o(s.id),!_.current)return;c("Settings pushed successfully","success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Push settings failed";E(R),c(R,"error")}finally{_.current&&L(!1)}}},[c,s,o]),de=n.useCallback(async()=>{if(!(!s||!y)){E(null),A(!0);try{if(await y(s.id),!_.current)return;c("Settings pulled successfully","success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Pull settings failed";E(R),c(R,"error")}finally{_.current&&A(!1)}}},[c,s,y]),ue=n.useCallback(async()=>{if(!(!s||!g)){E(null),F(!0);try{if(await g(s.id),!_.current)return;c("Auth credentials synced successfully","success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Auth sync failed";E(R),c(R,"error")}finally{_.current&&F(!1)}}},[c,s,g]),me=n.useCallback(()=>{E(null)},[]),he=n.useCallback(async()=>{if(!s||d)return;const N=a.trim();if(!N){c("Name is required","error");return}if(s.type==="remote"&&!x.trim()){c("URL is required for remote nodes","error");return}if(!Number.isFinite(v)||v<1){c("Concurrency must be at least 1","error");return}p(!0);try{await f(s.id,{name:N,url:s.type==="remote"&&x.trim()||void 0,apiKey:s.type==="remote"&&w||void 0,maxConcurrent:v}),c(`Updated ${N}`,"success"),M(!1)}catch(R){const ye=R instanceof Error?R.message:"Failed to update node";c(ye,"error")}finally{p(!1)}},[c,w,d,v,a,s,f,x]),fe=n.useCallback(()=>{s&&(i(s.name),b(s.url??""),$(s.apiKey??""),h(s.maxConcurrent),M(!1))},[s]);return!t||!s?null:e.jsxs("div",{className:"modal-overlay open",onClick:l,children:[e.jsxs("div",{className:"modal modal-lg node-detail-modal",onClick:N=>N.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":`Node details for ${s.name}`,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Node Details"}),e.jsx("button",{className:"modal-close",onClick:l,"aria-label":"Close node detail modal",children:"×"})]}),e.jsxs("div",{className:"modal-body node-detail-modal__body",children:[e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsxs("div",{className:"node-detail-modal__section-header",children:[e.jsx("h4",{children:"Overview"}),!S&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>M(!0),children:[e.jsx(ve,{size:14}),"Edit"]})]}),e.jsxs("div",{className:"node-detail-modal__grid",children:[e.jsxs("label",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Name"}),S?e.jsx("input",{className:"input",value:a,onChange:N=>i(N.target.value),disabled:d}):e.jsx("strong",{children:s.name})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Type"}),e.jsx("strong",{children:s.type==="local"?"Local":"Remote"})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Status"}),e.jsx("strong",{children:s.status})]}),e.jsxs("label",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Max Concurrent"}),S?e.jsx("input",{className:"input",type:"number",min:1,max:10,value:v,onChange:N=>h(Number(N.target.value)),disabled:d}):e.jsx("strong",{children:s.maxConcurrent})]}),s.type==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"node-detail-modal__field node-detail-modal__field--full",children:[e.jsx("span",{children:"URL"}),S?e.jsx("input",{className:"input",value:x,onChange:N=>b(N.target.value),disabled:d}):e.jsx("strong",{children:s.url??"—"})]}),e.jsxs("label",{className:"node-detail-modal__field node-detail-modal__field--full",children:[e.jsx("span",{children:"API Key"}),S?e.jsx("input",{className:"input",type:"password",value:w,onChange:N=>$(N.target.value),placeholder:"Leave blank to keep unchanged",disabled:d}):e.jsx("strong",{children:s.apiKey?"••••••••":"Not configured"})]})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Created"}),e.jsx("strong",{children:V(s.createdAt)})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Updated"}),e.jsx("strong",{children:V(s.updatedAt)})]})]}),S&&e.jsxs("div",{className:"node-detail-modal__edit-actions",children:[e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:he,disabled:d,children:[e.jsx(Ce,{size:14}),d?"Saving...":"Save"]}),e.jsxs("button",{className:"btn btn-sm",onClick:fe,disabled:d,children:[e.jsx(B,{size:14}),"Cancel"]})]})]}),e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsxs("h4",{children:[s.type==="local"?"Projects":"Assigned Projects"," (",K.length,")"]}),K.length===0?e.jsx("p",{className:"node-detail-modal__empty",children:s.type==="local"?"No projects are running on this node.":"No projects are assigned to this node."}):e.jsx("ul",{className:"node-detail-modal__project-list",children:K.map(N=>e.jsxs("li",{className:"node-detail-modal__project-item",children:[e.jsx("span",{children:N.name}),e.jsx("code",{children:N.id})]},N.id))})]}),e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsx("h4",{children:"Health"}),e.jsxs("div",{className:"node-detail-modal__health-row",children:[e.jsxs("span",{children:["Status: ",e.jsx("strong",{children:s.status})]}),e.jsxs("span",{children:["Last check: ",e.jsx("strong",{children:V(s.updatedAt)})]})]})]}),s.type==="remote"&&e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsx("h4",{children:"Settings Sync"}),u&&e.jsxs("div",{className:"node-detail-modal__sync-status",children:[e.jsx("span",{className:"node-detail-modal__sync-dot",style:{backgroundColor:ae(u.syncState)},"aria-hidden":!0}),e.jsxs("span",{children:["Last sync:"," ",e.jsx("strong",{children:u.lastSyncAt?te(u.lastSyncAt):"Never synced"})]}),u.diffCount>0&&e.jsxs("span",{className:"node-detail-modal__sync-diff",children:["Differences: ",e.jsx("strong",{children:u.diffCount})]})]}),e.jsxs("div",{className:"node-detail-modal__sync-actions",children:[e.jsxs("button",{className:"btn btn-sm",onClick:ie,disabled:z||!o,children:[e.jsx(se,{size:14}),z?"Pushing...":"Push Settings"]}),e.jsxs("button",{className:"btn btn-sm",onClick:de,disabled:k||!y,children:[e.jsx(ee,{size:14}),k?"Pulling...":"Pull Settings"]}),e.jsxs("button",{className:"btn btn-sm",onClick:ue,disabled:P||!g,children:[e.jsx(Q,{size:14}),P?"Syncing...":"Sync Auth"]})]}),I&&e.jsxs("div",{className:"node-detail-modal__sync-error",children:[e.jsx("span",{children:I}),e.jsx("button",{className:"node-detail-modal__sync-error-dismiss",onClick:me,"aria-label":"Dismiss error",children:e.jsx(B,{size:14})})]})]}),s.type==="remote"&&e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsx("h4",{children:"Sync History"}),e.jsx(Ge,{nodeId:s.id,entries:j,singleNode:!0})]})]}),e.jsxs("div",{className:"modal-actions node-detail-modal__actions",children:[e.jsxs("button",{className:"btn btn-sm",onClick:oe,children:[e.jsx(T,{size:14}),"Health Check"]}),e.jsx("button",{className:"btn btn-sm",onClick:l,children:"Close"})]})]}),s.type==="remote"&&e.jsx(Ye,{isOpen:le,onClose:()=>re(!1),onResolve:C??(async()=>{}),conflicts:ce,localNodeName:"Local",remoteNodeName:s.name,addToast:c})]})}function ts({addToast:t,onClose:l}){const{nodes:s,loading:r,error:f,refresh:m,register:c,update:u,unregister:o,healthCheck:y}=ke(),{projects:g}=Se(),{syncStatusMap:j,pushSettings:C,pullSettings:_,syncAuth:S,trackNode:M,getAuthSyncState:a,getAuthProviders:i}=$e(),[x,b]=n.useState(!1),[w,$]=n.useState(null);n.useEffect(()=>{const k=s.filter(A=>A.type==="remote");for(const A of k)M(A.id)},[s,M]),n.useEffect(()=>{if(!w)return;const k=s.find(A=>A.id===w.id)??null;$(k)},[s,w]);const v=n.useMemo(()=>{const k=s.length,A=s.filter(E=>E.status==="online").length,P=s.filter(E=>E.status==="offline"||E.status==="error").length,F=s.filter(E=>E.type==="remote").length,I=s.filter(E=>E.type==="remote"&&j[E.id]&&U(j[E.id]).syncState==="synced").length;return{total:k,online:A,offline:P,remote:F,synced:I}},[s,j]),h=n.useCallback(async k=>{await c(k)},[c]),d=n.useCallback(async()=>{try{await m()}catch{t("Failed to refresh nodes","error")}},[t,m]),p=n.useCallback(async k=>{try{await y(k),t("Node health check complete","success")}catch(A){const P=A instanceof Error?A.message:"Health check failed";t(P,"error")}},[t,y]),z=n.useCallback(async k=>{try{await o(k),t("Node removed","success"),w?.id===k&&$(null)}catch(A){const P=A instanceof Error?A.message:"Failed to remove node";t(P,"error")}},[t,w?.id,o]),L=n.useCallback(async(k,A)=>{await u(k,A)},[u]);return e.jsxs("div",{className:"nodes-view","data-testid":"nodes-view",children:[e.jsxs("div",{className:"nodes-view-header",children:[e.jsxs("div",{className:"nodes-view-title",children:[e.jsxs("h2",{children:[e.jsx(Z,{size:20}),"Nodes"]}),e.jsxs("span",{className:"nodes-view-count",children:[s.length," registered"]})]}),e.jsxs("div",{className:"nodes-view-actions",children:[e.jsx("button",{className:"btn-icon nodes-view-close",onClick:l,"aria-label":"Close nodes view",children:e.jsx(B,{size:16})}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void d(),disabled:r,children:[e.jsx(J,{size:14,className:r?"spin":""}),"Refresh"]}),e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:()=>b(!0),children:[e.jsx(G,{size:14}),"Add Node"]})]})]}),e.jsxs("div",{className:"nodes-view-stats",children:[e.jsxs("div",{className:"nodes-view-stat","data-testid":"nodes-stat-total",children:[e.jsx("span",{children:"Total"}),e.jsx("strong",{children:v.total})]}),e.jsxs("div",{className:"nodes-view-stat nodes-view-stat--online","data-testid":"nodes-stat-online",children:[e.jsxs("span",{children:[e.jsx(Re,{size:14})," Online"]}),e.jsx("strong",{children:v.online})]}),e.jsxs("div",{className:"nodes-view-stat nodes-view-stat--offline","data-testid":"nodes-stat-offline",children:[e.jsxs("span",{children:[e.jsx(Ae,{size:14})," Offline"]}),e.jsx("strong",{children:v.offline})]}),e.jsxs("div",{className:"nodes-view-stat","data-testid":"nodes-stat-remote",children:[e.jsxs("span",{children:[e.jsx(we,{size:14})," Remote"]}),e.jsx("strong",{children:v.remote})]}),e.jsxs("div",{className:"nodes-view-stat nodes-view-stat--synced","data-testid":"nodes-stat-synced",children:[e.jsxs("span",{children:[e.jsx(J,{size:14})," Synced"]}),e.jsx("strong",{children:v.synced})]})]}),f&&e.jsx("div",{className:"nodes-view-error",children:f}),!r&&s.length>0&&e.jsxs("section",{className:"nodes-view-topology","aria-label":"Mesh Topology",children:[e.jsx("h3",{className:"nodes-view-section-title",children:"Mesh Topology"}),e.jsx(qe,{nodes:s})]}),r?e.jsx("div",{className:"nodes-view-grid",children:Array.from({length:4}).map((k,A)=>e.jsx("div",{className:"node-card node-card--loading","aria-hidden":!0},A))}):s.length===0?e.jsxs("div",{className:"nodes-view-empty",children:[e.jsx("p",{children:"No nodes are registered yet."}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>b(!0),children:[e.jsx(G,{size:14}),"Add First Node"]})]}):e.jsx("div",{className:"nodes-view-grid",children:s.map(k=>{const A=k.type==="remote"&&j[k.id]?U(j[k.id]):void 0;return e.jsx(Ue,{node:k,projects:g,onHealthCheck:P=>{p(P)},onEdit:P=>$(P),onRemove:P=>{z(P)},isLoading:r,syncStatus:A,authSyncState:k.type==="remote"?a(k.id):void 0,authSyncProviders:k.type==="remote"?i(k.id):void 0},k.id)})}),e.jsx(Je,{isOpen:x,onClose:()=>b(!1),onSubmit:h,addToast:t}),e.jsx(Ze,{isOpen:w!==null,onClose:()=>$(null),node:w,projects:g,onUpdate:L,onHealthCheck:p,addToast:t,syncStatus:w?.type==="remote"&&w&&j[w.id]?U(j[w.id]):void 0,onPushSettings:C,onPullSettings:_,onSyncAuth:S})]})}export{ts as NodesView};
14
+ `)}function We({isOpen:t,onClose:l,onResolve:s,conflicts:r,localNodeName:f,remoteNodeName:m,addToast:c}){const[u,o]=n.useState({}),[y,g]=n.useState(!1);n.useEffect(()=>{const a={};for(const i of r)u[i.key]||(a[i.key]={resolution:"local"});Object.keys(a).length>0&&o(i=>({...i,...a}))},[r,u]),n.useEffect(()=>{if(!t)return;const a=i=>{i.key==="Escape"&&(i.preventDefault(),l())};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t,l]);const j=n.useCallback((a,i)=>{o(x=>{const b=x[a]??{};return i==="manual"?{...x,[a]:{resolution:"manual",manualValue:b.manualValue??JSON.stringify(r.find(w=>w.key===a)?.localValue??null,null,2)}}:{...x,[a]:{resolution:i}}})},[r]),C=n.useCallback((a,i)=>{o(x=>({...x,[a]:{...x[a],resolution:"manual",manualValue:i}}))},[]),_=n.useCallback(a=>{const i={};for(const x of r)i[x.key]={resolution:a};o(i)},[r]),S=n.useCallback(async()=>{g(!0);try{const a=r.map(i=>{const x=u[i.key]??{resolution:"local"};let b;switch(x.resolution){case"remote":b=i.remoteValue;break;case"manual":try{b=JSON.parse(x.manualValue??"null")}catch{b=x.manualValue??null}break;case"local":default:b=i.localValue;break}return{key:i.key,value:b}});await s(a),c("Settings conflicts resolved successfully","success"),l()}catch(a){const i=a instanceof Error?a.message:"Failed to resolve conflicts";c(i,"error")}finally{g(!1)}},[c,r,l,s,u]),M=n.useMemo(()=>{const a={};for(const i of r)a[i.key]=Ye(i.localValue,i.remoteValue);return a},[r]);return!t||r.length===0?null:e.jsx("div",{className:"modal-overlay open",onClick:l,children:e.jsxs("div",{className:"modal modal-lg settings-sync-conflict-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Resolve Settings Conflicts",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Resolve Settings Conflicts"}),e.jsx("button",{className:"modal-close",onClick:l,"aria-label":"Close conflict modal",children:"×"})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("div",{className:"settings-sync-conflict-modal__conflict-list",children:r.map(a=>{const i=u[a.key]??{resolution:"local"},x=M[a.key];return e.jsxs("div",{className:"settings-sync-conflict-modal__conflict-item",children:[e.jsx("div",{className:"settings-sync-conflict-modal__key",children:a.key}),e.jsxs("div",{className:"settings-sync-conflict-modal__diff-panel",children:[e.jsxs("div",{className:"settings-sync-conflict-modal__diff-side",children:[e.jsx("div",{className:"settings-sync-conflict-modal__diff-label",children:f}),e.jsx("div",{className:"settings-sync-conflict-modal__diff-content",children:e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap"},children:x})})]}),e.jsxs("div",{className:"settings-sync-conflict-modal__diff-side",children:[e.jsx("div",{className:"settings-sync-conflict-modal__diff-label",children:m}),e.jsx("div",{className:"settings-sync-conflict-modal__diff-content",children:e.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap"},children:x})})]})]}),e.jsxs("div",{className:"settings-sync-conflict-modal__resolution",children:[e.jsxs("label",{children:[e.jsx("input",{type:"radio",name:`resolution-${a.key}`,checked:i.resolution==="local",onChange:()=>j(a.key,"local")}),"Keep Local"]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",name:`resolution-${a.key}`,checked:i.resolution==="remote",onChange:()=>j(a.key,"remote")}),"Keep Remote"]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",name:`resolution-${a.key}`,checked:i.resolution==="manual",onChange:()=>j(a.key,"manual")}),"Merge Manually"]})]}),i.resolution==="manual"&&e.jsx("textarea",{className:"settings-sync-conflict-modal__manual-input",value:i.manualValue??"",onChange:b=>C(a.key,b.target.value),placeholder:"Enter JSON value..."})]},a.key)})}),e.jsxs("div",{className:"settings-sync-conflict-modal__bulk-actions",children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>_("local"),type:"button",children:"Resolve All: Keep Local"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>_("remote"),type:"button",children:"Resolve All: Keep Remote"})]})]}),e.jsxs("div",{className:"modal-actions settings-sync-conflict-modal__footer",children:[e.jsx("button",{className:"btn btn-sm",onClick:l,children:"Cancel"}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:S,disabled:y,children:y?"Resolving...":"Confirm"})]})]})})}function B(t){if(!t)return"—";const l=new Date(t);return Number.isNaN(l.getTime())?"—":l.toLocaleString()}function Ze({isOpen:t,onClose:l,node:s,projects:r,onUpdate:f,onHealthCheck:m,addToast:c,syncStatus:u,onPushSettings:o,onPullSettings:y,onSyncAuth:g,syncHistory:j=[],onResolveConflicts:C}){const _=n.useRef(!0),[S,M]=n.useState(!1),[a,i]=n.useState(""),[x,b]=n.useState(""),[w,$]=n.useState(""),[v,h]=n.useState(2),[d,p]=n.useState(!1),[z,L]=n.useState(!1),[k,A]=n.useState(!1),[P,F]=n.useState(!1),[I,E]=n.useState(null),[le,re]=n.useState(!1),[ce]=n.useState([]);n.useEffect(()=>(_.current=!0,()=>{_.current=!1}),[]),n.useEffect(()=>{if(!s||!t){M(!1);return}i(s.name),b(s.url??""),$(s.apiKey??""),h(s.maxConcurrent),M(!1)},[t,s]),n.useEffect(()=>{if(!t)return;const N=R=>{R.key==="Escape"&&(R.preventDefault(),l())};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[t,l]);const K=n.useMemo(()=>s?ne(r,s):[],[s,r]),oe=n.useCallback(async()=>{if(s)try{if(await m(s.id),!_.current)return;c(`Health check completed for ${s.name}`,"success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Health check failed";c(R,"error")}},[c,s,m]),ie=n.useCallback(async()=>{if(!(!s||!o)){E(null),L(!0);try{if(await o(s.id),!_.current)return;c("Settings pushed successfully","success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Push settings failed";E(R),c(R,"error")}finally{_.current&&L(!1)}}},[c,s,o]),de=n.useCallback(async()=>{if(!(!s||!y)){E(null),A(!0);try{if(await y(s.id),!_.current)return;c("Settings pulled successfully","success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Pull settings failed";E(R),c(R,"error")}finally{_.current&&A(!1)}}},[c,s,y]),ue=n.useCallback(async()=>{if(!(!s||!g)){E(null),F(!0);try{if(await g(s.id),!_.current)return;c("Auth credentials synced successfully","success")}catch(N){if(!_.current)return;const R=N instanceof Error?N.message:"Auth sync failed";E(R),c(R,"error")}finally{_.current&&F(!1)}}},[c,s,g]),me=n.useCallback(()=>{E(null)},[]),he=n.useCallback(async()=>{if(!s||d)return;const N=a.trim();if(!N){c("Name is required","error");return}if(s.type==="remote"&&!x.trim()){c("URL is required for remote nodes","error");return}if(!Number.isFinite(v)||v<1){c("Concurrency must be at least 1","error");return}p(!0);try{await f(s.id,{name:N,url:s.type==="remote"&&x.trim()||void 0,apiKey:s.type==="remote"&&w||void 0,maxConcurrent:v}),c(`Updated ${N}`,"success"),M(!1)}catch(R){const ye=R instanceof Error?R.message:"Failed to update node";c(ye,"error")}finally{p(!1)}},[c,w,d,v,a,s,f,x]),fe=n.useCallback(()=>{s&&(i(s.name),b(s.url??""),$(s.apiKey??""),h(s.maxConcurrent),M(!1))},[s]);return!t||!s?null:e.jsxs("div",{className:"modal-overlay open",onClick:l,children:[e.jsxs("div",{className:"modal modal-lg node-detail-modal",onClick:N=>N.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":`Node details for ${s.name}`,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Node Details"}),e.jsx("button",{className:"modal-close",onClick:l,"aria-label":"Close node detail modal",children:"×"})]}),e.jsxs("div",{className:"modal-body node-detail-modal__body",children:[e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsxs("div",{className:"node-detail-modal__section-header",children:[e.jsx("h4",{children:"Overview"}),!S&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>M(!0),children:[e.jsx(ve,{size:14}),"Edit"]})]}),e.jsxs("div",{className:"node-detail-modal__grid",children:[e.jsxs("label",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Name"}),S?e.jsx("input",{className:"input",value:a,onChange:N=>i(N.target.value),disabled:d}):e.jsx("strong",{children:s.name})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Type"}),e.jsx("strong",{children:s.type==="local"?"Local":"Remote"})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Status"}),e.jsx("strong",{children:s.status})]}),e.jsxs("label",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Max Concurrent"}),S?e.jsx("input",{className:"input",type:"number",min:1,max:10,value:v,onChange:N=>h(Number(N.target.value)),disabled:d}):e.jsx("strong",{children:s.maxConcurrent})]}),s.type==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"node-detail-modal__field node-detail-modal__field--full",children:[e.jsx("span",{children:"URL"}),S?e.jsx("input",{className:"input",value:x,onChange:N=>b(N.target.value),disabled:d}):e.jsx("strong",{children:s.url??"—"})]}),e.jsxs("label",{className:"node-detail-modal__field node-detail-modal__field--full",children:[e.jsx("span",{children:"API Key"}),S?e.jsx("input",{className:"input",type:"password",value:w,onChange:N=>$(N.target.value),placeholder:"Leave blank to keep unchanged",disabled:d}):e.jsx("strong",{children:s.apiKey?"••••••••":"Not configured"})]})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Created"}),e.jsx("strong",{children:B(s.createdAt)})]}),e.jsxs("div",{className:"node-detail-modal__field",children:[e.jsx("span",{children:"Updated"}),e.jsx("strong",{children:B(s.updatedAt)})]})]}),S&&e.jsxs("div",{className:"node-detail-modal__edit-actions",children:[e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:he,disabled:d,children:[e.jsx(Ce,{size:14}),d?"Saving...":"Save"]}),e.jsxs("button",{className:"btn btn-sm",onClick:fe,disabled:d,children:[e.jsx(V,{size:14}),"Cancel"]})]})]}),e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsxs("h4",{children:[s.type==="local"?"Projects":"Assigned Projects"," (",K.length,")"]}),K.length===0?e.jsx("p",{className:"node-detail-modal__empty",children:s.type==="local"?"No projects are running on this node.":"No projects are assigned to this node."}):e.jsx("ul",{className:"node-detail-modal__project-list",children:K.map(N=>e.jsxs("li",{className:"node-detail-modal__project-item",children:[e.jsx("span",{children:N.name}),e.jsx("code",{children:N.id})]},N.id))})]}),e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsx("h4",{children:"Health"}),e.jsxs("div",{className:"node-detail-modal__health-row",children:[e.jsxs("span",{children:["Status: ",e.jsx("strong",{children:s.status})]}),e.jsxs("span",{children:["Last check: ",e.jsx("strong",{children:B(s.updatedAt)})]})]})]}),s.type==="remote"&&e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsx("h4",{children:"Settings Sync"}),u&&e.jsxs("div",{className:"node-detail-modal__sync-status",children:[e.jsx("span",{className:"node-detail-modal__sync-dot",style:{backgroundColor:ae(u.syncState)},"aria-hidden":!0}),e.jsxs("span",{children:["Last sync:"," ",e.jsx("strong",{children:u.lastSyncAt?te(u.lastSyncAt):"Never synced"})]}),u.diffCount>0&&e.jsxs("span",{className:"node-detail-modal__sync-diff",children:["Differences: ",e.jsx("strong",{children:u.diffCount})]})]}),e.jsxs("div",{className:"node-detail-modal__sync-actions",children:[e.jsxs("button",{className:"btn btn-sm",onClick:ie,disabled:z||!o,children:[e.jsx(se,{size:14}),z?"Pushing...":"Push Settings"]}),e.jsxs("button",{className:"btn btn-sm",onClick:de,disabled:k||!y,children:[e.jsx(ee,{size:14}),k?"Pulling...":"Pull Settings"]}),e.jsxs("button",{className:"btn btn-sm",onClick:ue,disabled:P||!g,children:[e.jsx(Q,{size:14}),P?"Syncing...":"Sync Auth"]})]}),I&&e.jsxs("div",{className:"node-detail-modal__sync-error",children:[e.jsx("span",{children:I}),e.jsx("button",{className:"node-detail-modal__sync-error-dismiss",onClick:me,"aria-label":"Dismiss error",children:e.jsx(V,{size:14})})]})]}),s.type==="remote"&&e.jsxs("section",{className:"node-detail-modal__section",children:[e.jsx("h4",{children:"Sync History"}),e.jsx(Ge,{nodeId:s.id,entries:j,singleNode:!0})]})]}),e.jsxs("div",{className:"modal-actions node-detail-modal__actions",children:[e.jsxs("button",{className:"btn btn-sm",onClick:oe,children:[e.jsx(T,{size:14}),"Health Check"]}),e.jsx("button",{className:"btn btn-sm",onClick:l,children:"Close"})]})]}),s.type==="remote"&&e.jsx(We,{isOpen:le,onClose:()=>re(!1),onResolve:C??(async()=>{}),conflicts:ce,localNodeName:"Local",remoteNodeName:s.name,addToast:c})]})}function ts({addToast:t,onClose:l}){const{nodes:s,loading:r,error:f,refresh:m,register:c,update:u,unregister:o,healthCheck:y}=ke(),{projects:g}=Se(),{syncStatusMap:j,pushSettings:C,pullSettings:_,syncAuth:S,trackNode:M,getAuthSyncState:a,getAuthProviders:i}=$e(),[x,b]=n.useState(!1),[w,$]=n.useState(null);n.useEffect(()=>{const k=s.filter(A=>A.type==="remote");for(const A of k)M(A.id)},[s,M]),n.useEffect(()=>{if(!w)return;const k=s.find(A=>A.id===w.id)??null;$(k)},[s,w]);const v=n.useMemo(()=>{const k=s.length,A=s.filter(E=>E.status==="online").length,P=s.filter(E=>E.status==="offline"||E.status==="error").length,F=s.filter(E=>E.type==="remote").length,I=s.filter(E=>E.type==="remote"&&j[E.id]&&U(j[E.id]).syncState==="synced").length;return{total:k,online:A,offline:P,remote:F,synced:I}},[s,j]),h=n.useCallback(async k=>{await c(k)},[c]),d=n.useCallback(async()=>{try{await m()}catch{t("Failed to refresh nodes","error")}},[t,m]),p=n.useCallback(async k=>{try{await y(k),t("Node health check complete","success")}catch(A){const P=A instanceof Error?A.message:"Health check failed";t(P,"error")}},[t,y]),z=n.useCallback(async k=>{try{await o(k),t("Node removed","success"),w?.id===k&&$(null)}catch(A){const P=A instanceof Error?A.message:"Failed to remove node";t(P,"error")}},[t,w?.id,o]),L=n.useCallback(async(k,A)=>{await u(k,A)},[u]);return e.jsxs("div",{className:"nodes-view","data-testid":"nodes-view",children:[e.jsxs("div",{className:"nodes-view-header",children:[e.jsxs("div",{className:"nodes-view-title",children:[e.jsxs("h2",{children:[e.jsx(Z,{size:20}),"Nodes"]}),e.jsxs("span",{className:"nodes-view-count",children:[s.length," registered"]})]}),e.jsxs("div",{className:"nodes-view-actions",children:[e.jsx("button",{className:"btn-icon nodes-view-close",onClick:l,"aria-label":"Close nodes view",children:e.jsx(V,{size:16})}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void d(),disabled:r,children:[e.jsx(J,{size:14,className:r?"spin":""}),"Refresh"]}),e.jsxs("button",{className:"btn btn-primary btn-sm",onClick:()=>b(!0),children:[e.jsx(G,{size:14}),"Add Node"]})]})]}),e.jsxs("div",{className:"nodes-view-stats",children:[e.jsxs("div",{className:"nodes-view-stat","data-testid":"nodes-stat-total",children:[e.jsx("span",{children:"Total"}),e.jsx("strong",{children:v.total})]}),e.jsxs("div",{className:"nodes-view-stat nodes-view-stat--online","data-testid":"nodes-stat-online",children:[e.jsxs("span",{children:[e.jsx(Re,{size:14})," Online"]}),e.jsx("strong",{children:v.online})]}),e.jsxs("div",{className:"nodes-view-stat nodes-view-stat--offline","data-testid":"nodes-stat-offline",children:[e.jsxs("span",{children:[e.jsx(Ae,{size:14})," Offline"]}),e.jsx("strong",{children:v.offline})]}),e.jsxs("div",{className:"nodes-view-stat","data-testid":"nodes-stat-remote",children:[e.jsxs("span",{children:[e.jsx(we,{size:14})," Remote"]}),e.jsx("strong",{children:v.remote})]}),e.jsxs("div",{className:"nodes-view-stat nodes-view-stat--synced","data-testid":"nodes-stat-synced",children:[e.jsxs("span",{children:[e.jsx(J,{size:14})," Synced"]}),e.jsx("strong",{children:v.synced})]})]}),f&&e.jsx("div",{className:"nodes-view-error",children:f}),!r&&s.length>0&&e.jsxs("section",{className:"nodes-view-topology","aria-label":"Mesh Topology",children:[e.jsx("h3",{className:"nodes-view-section-title",children:"Mesh Topology"}),e.jsx(qe,{nodes:s})]}),r?e.jsx("div",{className:"nodes-view-grid",children:Array.from({length:4}).map((k,A)=>e.jsx("div",{className:"node-card node-card--loading","aria-hidden":!0},A))}):s.length===0?e.jsxs("div",{className:"nodes-view-empty",children:[e.jsx("p",{children:"No nodes are registered yet."}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>b(!0),children:[e.jsx(G,{size:14}),"Add First Node"]})]}):e.jsx("div",{className:"nodes-view-grid",children:s.map(k=>{const A=k.type==="remote"&&j[k.id]?U(j[k.id]):void 0;return e.jsx(Ue,{node:k,projects:g,onHealthCheck:P=>{p(P)},onEdit:P=>$(P),onRemove:P=>{z(P)},isLoading:r,syncStatus:A,authSyncState:k.type==="remote"?a(k.id):void 0,authSyncProviders:k.type==="remote"?i(k.id):void 0},k.id)})}),e.jsx(Je,{isOpen:x,onClose:()=>b(!1),onSubmit:h,addToast:t}),e.jsx(Ze,{isOpen:w!==null,onClose:()=>$(null),node:w,projects:g,onUpdate:L,onHealthCheck:p,addToast:t,syncStatus:w?.type==="remote"&&w&&j[w.id]?U(j[w.id]):void 0,onPushSettings:C,onPullSettings:_,onSyncAuth:S})]})}export{ts as NodesView};
@@ -1,4 +1,4 @@
1
- import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{c as W,dU as Z,dV as H,dW as J,R as $,dM as y,N as Q,$ as T,U as ee,_ as se,cr as L,F as _,dX as ae,dY as te,dZ as D,X as ie}from"./index-D7gT6mCr.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{c as W,dW as Z,dX as H,dY as J,R as $,dO as y,M as V,_ as T,Q as ee,Y as se,cr as L,F as _,dZ as ae,d_ as te,d$ as D,X as ie}from"./index-CLAHcGnI.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 l,j as e}from"./vendor-react-K0fH_qHe.js";import{c as W,dU as Z,dV 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 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"}]],U=W("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,I]=l.useState(new Set),[p,O]=l.useState([]),[b,z]=l.useState(!0),[X,C]=l.useState(!1),r=l.useCallback(async()=>{try{P(!0);const s=await Z();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 H(x);O(s.extensions)}catch(s){t(`Failed to load extensions: ${s instanceof Error?s.message:String(s)}`,"error")}finally{z(!1)}},[t,x]),q=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 J(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 B=s=>{I(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)}},K=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)}},V=async s=>{if(!c)return;const i=c.packages.filter(a=>(typeof a=="string"?a:a.source)!==s);try{await D({packages:i}),t("Package removed","success"),await r()}catch(a){t(`Failed to remove package: ${a instanceof Error?a.message:String(a)}`,"error")}},Y=async(s,i)=>{if(!c)return;const a=c[s].filter(n=>n!==i);try{await D({[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:()=>Y(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(Q,{size:14}),N?"Installing…":"Add"]})]}),e.jsx("div",{className:"pi-ext-add-form-row",children:e.jsx("button",{className:"btn",onClick:K,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:()=>B(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:()=>V(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(U,{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(_,{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(M,{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",U,"extensions"),u("Skills",L,"skills"),u("Prompts",_,"prompts"),u("Themes",M,"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 q(s),disabled:X,"aria-label":`Toggle ${s.name}`}),e.jsx("span",{className:"toggle-slider"})]})})]},s.id))})]})]})}export{he as PiExtensionsManager};
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"}]],O=W("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,I]=l.useState(new Set),[p,X]=l.useState([]),[b,z]=l.useState(!0),[Y,C]=l.useState(!1),r=l.useCallback(async()=>{try{P(!0);const s=await Z();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 H(x);X(s.extensions)}catch(s){t(`Failed to load extensions: ${s instanceof Error?s.message:String(s)}`,"error")}finally{z(!1)}},[t,x]),q=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 J(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 B=s=>{I(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)}},K=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)}},Q=async s=>{if(!c)return;const i=c.packages.filter(a=>(typeof a=="string"?a:a.source)!==s);try{await D({packages:i}),t("Package removed","success"),await r()}catch(a){t(`Failed to remove package: ${a instanceof Error?a.message:String(a)}`,"error")}},U=async(s,i)=>{if(!c)return;const a=c[s].filter(n=>n!==i);try{await D({[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:()=>U(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(V,{size:14}),N?"Installing…":"Add"]})]}),e.jsx("div",{className:"pi-ext-add-form-row",children:e.jsx("button",{className:"btn",onClick:K,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:()=>B(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:()=>Q(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(O,{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(_,{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(M,{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",O,"extensions"),u("Skills",L,"skills"),u("Prompts",_,"prompts"),u("Themes",M,"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 q(s),disabled:Y,"aria-label":`Toggle ${s.name}`}),e.jsx("span",{className:"toggle-slider"})]})})]},s.id))})]})]})}export{he as PiExtensionsManager};
@@ -0,0 +1 @@
1
+ import{r as u,j as s}from"./vendor-react-K0fH_qHe.js";import{y as ee,dM as se,s as ne,X as k,ap as te,M as O,dN as A,Y as M,R as ie,dO as ae,aH as le,ch as re,dP as ce,dQ as de,dR as ue,dS as oe,dT as _,ce as ge}from"./index-CLAHcGnI.js";import{D as me}from"./DirectoryPicker-DVmy6sLM.js";import"./vendor-xterm-DzcZoU0P.js";import"./folder-open-D11gjHGK.js";const H=[{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}],j={started:"var(--color-success)",loaded:"var(--color-warning)",error:"var(--color-error)",stopped:"var(--color-muted)",installed:"var(--color-info)"};function fe({addToast:l,projectId:c}){const[N,x]=u.useState([]),[S,w]=u.useState(!0),[V,f]=u.useState(!1),[b,v]=u.useState(""),[C,P]=u.useState(!1),[h,I]=u.useState(null),[i,y]=u.useState(null),[a,p]=u.useState({}),[G,R]=u.useState(!1),[$,E]=u.useState(null),{confirm:J}=ee(),o=u.useCallback(async()=>{try{w(!0);const e=await se(c);x(e)}catch(e){l(`Failed to load plugins: ${e instanceof Error?e.message:String(e)}`,"error")}finally{w(!1)}},[c,l]);u.useEffect(()=>{o()},[o]);const K=u.useRef([]);K.current=N,u.useEffect(()=>{const e=c?`?projectId=${encodeURIComponent(c)}`:"",n=g=>{try{const t=JSON.parse(g.data);if(c&&t.projectId&&t.projectId!==c)return;switch(t.transition){case"installing":case"enabled":case"disabled":case"settings-updated":x(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 o(),d});break;case"uninstalled":x(d=>d.filter(m=>m.id!==t.pluginId));break;case"error":x(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 ne(`/api/events${e}`,{events:{"plugin:lifecycle":n},onReconnect:()=>{o()}})},[c,o]);const z=async()=>{if(!b.trim()){l("Please enter a plugin path","error");return}try{P(!0),await _({path:b},c),l("Plugin installed successfully","success"),f(!1),v(""),await o()}catch(e){l(`Failed to install plugin: ${e instanceof Error?e.message:String(e)}`,"error")}finally{P(!1)}},Q=async e=>{try{E(e.id),await _({path:e.path},c),l(`${e.name} installed successfully`,"success"),await o()}catch(n){l(`Failed to install ${e.name}: ${n instanceof Error?n.message:String(n)}`,"error")}finally{E(null)}},F=async e=>{try{await ue(e.id,c),l(`${e.name} enabled`,"success"),await o()}catch(n){l(`Failed to enable plugin: ${n instanceof Error?n.message:String(n)}`,"error")}},B=async e=>{try{await de(e.id,c),l(`${e.name} disabled`,"success"),await o()}catch(n){l(`Failed to disable plugin: ${n instanceof Error?n.message:String(n)}`,"error")}},L=async e=>{try{I(e.id),await ce(e.id,c),l(`${e.name} reloaded`,"success"),await o()}catch(n){l(`Failed to reload plugin: ${n instanceof Error?n.message:String(n)}`,"error")}finally{I(null)}},U=async e=>{if(await J({title:"Uninstall Plugin",message:`Are you sure you want to uninstall "${e.name}"?`,danger:!0}))try{await oe(e.id,c),l(`${e.name} uninstalled`,"success"),await o(),y(null)}catch(g){l(`Failed to uninstall plugin: ${g instanceof Error?g.message:String(g)}`,"error")}},X=async e=>{y(e);try{R(!0);const n=await ge(e.id,c);p(n)}catch{p({})}finally{R(!1)}},Y=async()=>{if(i)try{await re(i.id,a,c),l("Settings saved","success")}catch(e){l(`Failed to save settings: ${e instanceof Error?e.message:String(e)}`,"error")}};if(i)return s.jsxs("div",{className:"plugin-manager-detail","data-testid":"plugin-manager-detail",children:[s.jsxs("div",{className:"plugin-manager-detail-header",children:[s.jsx("button",{className:"btn-icon",onClick:()=>y(null),"aria-label":"Back to plugin list",children:s.jsx(k,{size:16})}),s.jsxs("div",{className:"plugin-detail-title",children:[s.jsx("h4",{className:"plugin-detail-name",children:i.name}),s.jsx("span",{className:"plugin-state-badge",style:{color:j[i.state]||j.installed},children:i.state})]})]}),s.jsxs("div",{className:"plugin-detail-content",children:[s.jsxs("div",{className:"plugin-detail-card",children:[i.description&&s.jsx("p",{className:"plugin-description",children:i.description}),i.author&&s.jsxs("p",{className:"plugin-detail-meta-row",children:[s.jsx("span",{className:"text-muted",children:"Author:"}),i.author]}),i.homepage&&s.jsxs("p",{className:"plugin-detail-meta-row plugin-homepage",children:[s.jsx("span",{className:"text-muted",children:"Homepage:"}),s.jsxs("a",{href:i.homepage,target:"_blank",rel:"noopener noreferrer",children:[i.homepage,s.jsx(te,{size:12})]})]}),s.jsxs("p",{className:"plugin-detail-meta-row",children:[s.jsx("span",{className:"text-muted",children:"Version:"}),i.version]})]}),s.jsxs("div",{className:"plugin-detail-card",children:[s.jsx("h5",{className:"plugin-detail-section-heading",children:"Settings"}),G?s.jsx("p",{className:"text-muted",children:"Loading..."}):i.settingsSchema&&Object.keys(i.settingsSchema).length>0?s.jsxs("div",{className:"plugin-settings-form",children:[Object.entries(i.settingsSchema).map(([e,n])=>{const g=`setting-${e}-help`;return s.jsxs("div",{className:"form-group",children:[s.jsxs("label",{htmlFor:`setting-${e}`,children:[n.label||e,n.required&&" *"]}),n.type==="string"&&!n.multiline&&s.jsx("input",{type:"text",id:`setting-${e}`,value:a[e]??"",onChange:t=>p({...a,[e]:t.target.value}),placeholder:n.description,"aria-describedby":n.description&&!n.required?g:void 0}),n.type==="string"&&n.multiline&&s.jsx("textarea",{id:`setting-${e}`,rows:4,value:a[e]??"",onChange:t=>p({...a,[e]:t.target.value}),placeholder:n.description,"aria-describedby":n.description&&!n.required?g:void 0}),n.type==="password"&&s.jsx("input",{type:"password",id:`setting-${e}`,value:a[e]??"",onChange:t=>p({...a,[e]:t.target.value}),placeholder:n.description,"aria-describedby":n.description&&!n.required?g:void 0}),n.type==="number"&&s.jsx("input",{type:"number",id:`setting-${e}`,value:a[e]??"",onChange:t=>p({...a,[e]:Number(t.target.value)}),"aria-describedby":n.description&&!n.required?g:void 0}),n.type==="boolean"&&s.jsxs("label",{className:"checkbox-label",children:[s.jsx("input",{type:"checkbox",checked:a[e]??!1,onChange:t=>p({...a,[e]:t.target.checked})}),n.description]}),n.type==="enum"&&s.jsxs("select",{id:`setting-${e}`,value:a[e]??"",onChange:t=>p({...a,[e]:t.target.value}),"aria-describedby":n.description&&!n.required?g:void 0,children:[s.jsx("option",{value:"",children:"Select..."}),n.enumValues?.map(t=>s.jsx("option",{value:t,children:t},t))]}),n.type==="array"&&s.jsxs("div",{className:"plugin-settings-array",children:[a[e]?.map((t,d)=>s.jsxs("div",{className:"plugin-settings-array-item",children:[s.jsx("input",{type:n.itemType==="number"?"number":"text",value:t??"",onChange:m=>{const r=m.target.value,D=[...a[e]||[]];D[d]=n.itemType==="number"?Number(r):r,p({...a,[e]:D})}}),s.jsx("button",{className:"btn-icon",onClick:()=>{const r=[...a[e]||[]];r.splice(d,1),p({...a,[e]:r})},"aria-label":"Remove item",children:s.jsx(k,{size:14})})]},d)),s.jsxs("button",{className:"btn btn-secondary",onClick:()=>{const t=a[e]||[],d=n.itemType==="number"?0:"";p({...a,[e]:[...t,d]})},children:[s.jsx(O,{size:14})," Add Item"]})]}),n.description&&!n.required&&!n.multiline&&s.jsx("span",{id:g,className:"form-help",children:n.description})]},e)}),s.jsx("button",{className:"btn btn-primary",onClick:Y,children:"Save Settings"})]}):s.jsx("p",{className:"text-muted",children:"No configurable settings."})]}),s.jsxs("div",{className:"plugin-detail-actions",children:[i.state==="started"&&s.jsxs("button",{className:"btn btn-secondary",onClick:()=>L(i),disabled:h===i.id,children:[s.jsx(A,{size:14,className:h===i.id?"spin":""}),h===i.id?"Reloading...":"Reload"]}),i.enabled?s.jsx("button",{className:"btn btn-secondary",onClick:()=>B(i),children:"Disable"}):s.jsx("button",{className:"btn btn-primary",onClick:()=>F(i),children:"Enable"}),s.jsxs("button",{className:"btn btn-danger",onClick:()=>U(i),children:[s.jsx(M,{size:14})," Uninstall"]})]})]})]});const W=new Set(N.map(e=>e.id)),Z=new Set(H.map(e=>e.id)),q=N.filter(e=>!Z.has(e.id)),T=()=>s.jsxs("section",{className:"plugin-bundled-runtime-section","aria-label":"Bundled Runtime Plugins",children:[s.jsxs("div",{className:"plugin-bundled-runtime-header",children:[s.jsx("h4",{className:"plugin-bundled-runtime-heading",children:"Bundled Runtime Plugins"}),s.jsx("p",{className:"plugin-bundled-runtime-description",children:"Install Fusion's bundled runtimes directly from this screen."})]}),s.jsx("div",{className:"plugin-bundled-runtime-list","aria-label":"Bundled runtime plugin recommendations",children:H.map(e=>{const n=W.has(e.id);return s.jsxs("div",{className:"plugin-bundled-runtime-item",children:[s.jsxs("div",{className:"plugin-bundled-runtime-meta",children:[s.jsx("span",{className:"plugin-bundled-runtime-name",children:e.name}),e.experimental&&s.jsx("span",{className:"plugin-bundled-runtime-badge",children:"Experimental"}),s.jsx("span",{className:`plugin-bundled-runtime-status ${n?"plugin-bundled-runtime-status--installed":"plugin-bundled-runtime-status--available"}`,children:n?"Installed":"Not installed"})]}),s.jsx("button",{className:`btn ${n?"btn-secondary":"btn-primary"} btn-sm`,onClick:()=>Q(e),disabled:n||$===e.id,children:n?"Installed":$===e.id?"Installing...":`Install ${e.name}`})]},e.id)})})]});return s.jsxs("div",{className:"plugin-manager","data-testid":"plugin-manager",children:[s.jsxs("div",{className:"plugin-manager-header",children:[s.jsx("span",{className:"plugin-manager-header-title",children:"Installed Plugins"}),s.jsxs("div",{className:"plugin-manager-actions",children:[s.jsxs("button",{className:"btn btn-sm btn-ghost",onClick:o,title:"Refresh","aria-label":"Refresh plugin list",children:[s.jsx(ie,{size:14,className:S?"spin":""}),"Refresh"]}),s.jsxs("button",{className:"btn btn-primary btn-sm",onClick:()=>f(!0),children:[s.jsx(O,{size:14})," Install"]})]})]}),V&&s.jsxs("div",{className:"plugin-install-form",children:[s.jsxs("p",{className:"plugin-install-hint",children:["Browse to a plugin package root (contains ",s.jsx("code",{children:"manifest.json"}),") or a built ",s.jsx("code",{children:"dist"})," directory."]}),s.jsx(me,{value:b,onChange:v,placeholder:"Absolute path to plugin directory or dist folder",onInputKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),z())}}),s.jsxs("div",{className:"plugin-install-actions",children:[s.jsx("button",{className:"btn btn-primary",onClick:z,disabled:C||!b.trim(),children:C?"Installing...":"Install Plugin"}),s.jsx("button",{className:"btn btn-secondary",onClick:()=>{f(!1),v("")},children:"Cancel"})]})]}),S?s.jsx("div",{className:"settings-empty-state",children:"Loading plugins..."}):s.jsxs(s.Fragment,{children:[q.length===0?s.jsxs("div",{className:"settings-empty-state",children:[s.jsx(ae,{size:32,className:"text-muted"}),s.jsx("p",{children:"No plugins installed."}),s.jsx("p",{className:"text-muted",children:"Install a plugin to get started, or use a bundled runtime below."})]}):s.jsx("div",{className:"plugin-list",children:q.map(e=>s.jsxs("div",{className:"plugin-item",children:[s.jsxs("div",{className:"plugin-info",children:[s.jsx("span",{className:"plugin-name",children:e.name}),s.jsxs("span",{className:"plugin-version text-muted",children:["v",e.version]}),s.jsx("span",{className:"plugin-state-badge",style:{color:j[e.state]||j.installed},children:e.state})]}),s.jsxs("div",{className:"plugin-actions",children:[e.state==="started"&&s.jsx("button",{className:"btn-icon",onClick:()=>L(e),disabled:h===e.id,title:"Reload",children:s.jsx(A,{size:14,className:h===e.id?"spin":""})}),s.jsxs("label",{className:"toggle-switch",children:[s.jsx("input",{type:"checkbox",checked:e.enabled,onChange:()=>e.enabled?B(e):F(e)}),s.jsx("span",{className:"toggle-slider"})]}),s.jsx("button",{className:"btn-icon",onClick:()=>X(e),title:"Settings",children:s.jsx(le,{size:14})}),s.jsx("button",{className:"btn-icon",onClick:()=>U(e),title:"Uninstall",children:s.jsx(M,{size:14})})]})]},e.id))}),T()]})]})}export{fe as PluginManager,j as STATE_COLORS};
@@ -1 +1 @@
1
- import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{at as ae,au as ne,s as ce,av as ie,aw as le,ax as oe,ay as de,az as ue,aA as he,D as me,aB as be,L as ve,S as pe}from"./index-D7gT6mCr.js";import"./vendor-xterm-DzcZoU0P.js";const C={webSearch:!0,pageFetch:!0,github:!1,localDocs:!0,llmSynthesis:!0};function K(d){const r=d?.researchGlobalDefaults,o=d?.researchSettings;return{enabled:o?.enabled??d?.researchEnabled??d?.researchGlobalEnabled??!0,searchProvider:o?.searchProvider??r?.searchProvider,synthesisProvider:o?.synthesisProvider??r?.synthesisProvider,synthesisModelId:o?.synthesisModelId??r?.synthesisModelId,enabledSources:{webSearch:o?.enabledSources?.webSearch??r?.enabledSources?.webSearch??C.webSearch,pageFetch:o?.enabledSources?.pageFetch??r?.enabledSources?.pageFetch??C.pageFetch,github:o?.enabledSources?.github??r?.enabledSources?.github??C.github,localDocs:o?.enabledSources?.localDocs??r?.enabledSources?.localDocs??C.localDocs,llmSynthesis:o?.enabledSources?.llmSynthesis??r?.enabledSources?.llmSynthesis??C.llmSynthesis},limits:{maxConcurrentRuns:o?.limits?.maxConcurrentRuns??d?.researchMaxConcurrentRuns??d?.researchGlobalMaxConcurrentRuns??3,maxSourcesPerRun:o?.limits?.maxSourcesPerRun??r?.maxSourcesPerRun??d?.researchMaxSourcesPerRun??d?.researchGlobalMaxSourcesPerRun??20,maxDurationMs:o?.limits?.maxDurationMs??d?.researchDefaultTimeout??d?.researchGlobalDefaultTimeout??3e5,requestTimeoutMs:o?.limits?.requestTimeoutMs??d?.researchFetchTimeoutMs??3e4},defaultExportFormat:r?.defaultExportFormat??"markdown"}}const fe=300,xe=4e3;function ye(d){const r=d?.projectId,[o,T]=a.useState([]),[u,t]=a.useState(null),[q,y]=a.useState(null),[f,R]=a.useState({available:!0}),[w,E]=a.useState(!0),[O,P]=a.useState(null),[S,U]=a.useState(""),_=a.useRef(0),g=a.useRef(0),A=a.useRef(r);a.useEffect(()=>{A.current!==r&&(A.current=r,g.current++)},[r]);const p=a.useCallback(async(n=S)=>{const c=++_.current,i=r;P(null);try{const h=await ae({q:n||void 0,limit:100},i);if(c!==_.current||i!==r)return;T(h.runs),R(h.availability),u&&!h.runs.some(m=>m.id===u)&&(t(null),y(null))}catch(h){if(c!==_.current||i!==r)return;P(h instanceof Error?h.message:"Failed to load research runs")}finally{c===_.current&&E(!1)}},[r,S,u]),x=a.useCallback(async n=>{const c=await ne(n,r);return y(c.run),R(c.availability),c.run},[r]);return a.useEffect(()=>{E(!0);const n=window.setTimeout(()=>{p(S)},fe);return()=>window.clearTimeout(n)},[p,S]),a.useEffect(()=>{if(!u){y(null);return}x(u)},[x,u]),a.useEffect(()=>{const n=g.current,c=()=>g.current!==n,i=r?`?projectId=${encodeURIComponent(r)}`:"";let h=!0;const m=()=>{!h||c()||(p(),u&&x(u))},V=ce(`/api/events${i}`,{events:{"research:run:created":m,"research:run:updated":m,"research:run:completed":m,"research:run:failed":m,"research:run:cancelled":m},onReconnect:m}),M=window.setInterval(m,xe);return()=>{h=!1,V(),window.clearInterval(M)}},[r,p,u,x]),{runs:o,selectedRun:q,selectedRunId:u,setSelectedRunId:t,availability:f,loading:w,error:O,searchQuery:S,setSearchQuery:U,refresh:p,createRun:n=>he(n,r),cancelRun:async n=>{const c=await ue(n,r);return u===n&&y(c.run),await p(),c},retryRun:async n=>{const c=await de(n,r);return u===n&&y(c.run),await p(),c},exportRun:(n,c)=>oe(n,c,r),createTaskFromRun:(n,c)=>le(n,{title:c},r),attachRunToTask:(n,c,i)=>ie(n,{taskId:c,mode:i},r),statusCounts:o.reduce((n,c)=>(n[c.status]+=1,n),{pending:0,running:0,completed:0,failed:0,cancelled:0})}}const Se=["web-search","page-fetch","github","local-docs","llm-synthesis"],je={"web-search":"webSearch","page-fetch":"pageFetch",github:"github","local-docs":"localDocs","llm-synthesis":"llmSynthesis"},Re={"web-search":"Web Search","page-fetch":"Page Fetch",github:"GitHub","local-docs":"Local Docs","llm-synthesis":"LLM Synthesis"};function ke({projectId:d,addToast:r,onOpenSettings:o,readinessVersion:T=0}){const{runs:u,selectedRun:t,selectedRunId:q,setSelectedRunId:y,availability:f,loading:R,error:w,searchQuery:E,setSearchQuery:O,createRun:P,cancelRun:S,retryRun:U,exportRun:_,createTaskFromRun:g,attachRunToTask:A,statusCounts:p,refresh:x}=ye({projectId:d}),[n,c]=a.useState(""),[i,h]=a.useState(()=>K(void 0)),[m,V]=a.useState([]),[M,J]=a.useState(!1),[W,Y]=a.useState([]),[$,ee]=a.useState(""),[j,I]=a.useState(null),G=f.supportedProviders??Se,D=s=>i.enabledSources[je[s]];a.useEffect(()=>{const s=G.filter(l=>D(l));Y(l=>{const b=l.filter(v=>s.includes(v));return b.length>0?b:s})},[i.enabledSources,G]),a.useEffect(()=>{let s=!1;return Promise.all([me(d),be().catch(()=>({providers:[]}))]).then(([l,b])=>{s||(h(K(l)),V(b.providers.filter(v=>v.type==="api_key").map(v=>({id:v.id,authenticated:v.authenticated}))))}).catch(()=>{s||h(K(void 0))}),()=>{s=!0}},[d,T]);const se=a.useMemo(()=>t?t.status:"No run selected",[t]),re=a.useMemo(()=>t?t.status==="pending"?"status-dot status-dot--pending":t.status==="running"?"status-dot status-dot--connecting":t.status==="completed"?"status-dot status-dot--online":t.status==="failed"||t.status==="cancelled"?"status-dot status-dot--error":"status-dot":"status-dot",[t]),Q=f.supportedExportFormats??["markdown","json","html"],F=i.searchProvider,X=i.enabledSources.webSearch&&!F,Z=i.enabledSources.llmSynthesis&&(!i.synthesisProvider||!i.synthesisModelId),B=a.useMemo(()=>new Map(m.map(s=>[s.id,s.authenticated])),[m]),z=a.useMemo(()=>{const s=new Set;return i.enabledSources.webSearch&&F&&s.add(F),i.enabledSources.llmSynthesis&&i.synthesisProvider&&s.add(i.synthesisProvider),[...s].filter(l=>B.has(l))},[i.enabledSources.llmSynthesis,i.enabledSources.webSearch,i.synthesisProvider,F,B]).find(s=>B.get(s)!==!0),N=a.useMemo(()=>f.available?i.enabled?X||Z?{reason:"Research defaults are incomplete.",details:"Select the required provider/model defaults in Research settings.",settingsSection:"research-global"}:z?{reason:`Missing API key for ${z}.`,details:"Add provider credentials in Authentication settings.",settingsSection:"authentication"}:null:{reason:"Research is disabled for this project.",details:"Enable project research settings to create runs.",settingsSection:"research-project"}:{reason:f.reason??"Research is unavailable for this project.",details:f.setupInstructions,settingsSection:"research-project"},[f.available,f.reason,f.setupInstructions,i.enabled,z,X,Z]),L=async(s,l,b)=>{I(s);try{await l(),r?.(b,"success"),await x()}catch(v){r?.(v instanceof Error?v.message:"Action failed","error")}finally{I(null)}},H=async s=>{if(t){I(`export-${s}`);try{const l=await _(t.id,s),b=new Blob([l.content],{type:"text/plain;charset=utf-8"}),v=URL.createObjectURL(b),k=document.createElement("a");k.href=v,k.download=l.filename,document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(v),r?.(`Exported ${l.filename}`,"success")}catch(l){r?.(l instanceof Error?l.message:"Export failed","error")}finally{I(null)}}},te=async()=>{if(n.trim()){J(!0);try{const s=W.filter(b=>D(b));if(s.length===0){r?.("No enabled research sources are available for this project.","error");return}const l=await P({query:n.trim(),providers:s});y(l.run.id),c(""),r?.("Research run created","success"),await x()}catch(s){r?.(s instanceof Error?s.message:"Failed to create run","error")}finally{J(!1)}}};return e.jsxs("section",{className:"research-view","aria-label":"Research view",children:[e.jsxs("header",{className:"research-view__header",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"research-view__title",children:"Research"}),e.jsx("p",{className:"research-view__subtitle",children:"Create and track research runs with cited findings."})]}),e.jsx("button",{className:"btn",type:"button",onClick:()=>void x(),children:"Refresh"})]}),N?e.jsxs("div",{className:"research-view__state research-view__state--error card","data-testid":"research-state-unavailable",children:[e.jsx("p",{children:N.reason}),N.details&&e.jsx("p",{children:N.details}),e.jsxs("p",{children:["Current defaults: provider ",i.searchProvider??"(not set)",", max sources ",i.limits.maxSourcesPerRun]}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:()=>void x(),children:"Refresh"}),e.jsx("button",{className:"btn btn-primary",type:"button",onClick:()=>o?.(N.settingsSection),children:"Open Settings"})]})]}):e.jsxs("div",{className:"research-view__layout",children:[e.jsxs("aside",{className:"research-view__sidebar card",children:[e.jsxs("div",{className:"research-view__form",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-query",children:"Query"}),e.jsx("textarea",{id:"research-query",className:"input research-view__textarea",value:n,onChange:s=>c(s.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:"Providers"}),e.jsx("div",{className:"research-view__providers",children:G.map(s=>e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:W.includes(s),disabled:!D(s),onChange:()=>{D(s)&&Y(l=>l.includes(s)?l.filter(b=>b!==s):[...l,s])}}),e.jsx("span",{children:Re[s]??s})]},s))})]}),e.jsxs("button",{className:"btn btn-primary",type:"button",disabled:!n.trim()||M,onClick:()=>void te(),children:[M?e.jsx(ve,{className:"animate-spin",size:14}):null,"Create Run"]})]}),e.jsxs("div",{className:"research-view__history-header form-group",children:[e.jsx("label",{htmlFor:"research-run-search",children:"Search"}),e.jsxs("div",{className:"research-view__history-search-row",children:[e.jsx(pe,{size:14}),e.jsx("input",{id:"research-run-search",className:"input",placeholder:"Search runs",value:E,onChange:s=>O(s.target.value)})]})]}),e.jsx("div",{className:"research-view__history","data-testid":"research-state-running",children:u.map(s=>e.jsxs("button",{className:`research-view__history-item${q===s.id?" research-view__history-item--active":""}`,onClick:()=>y(s.id),children:[e.jsx("span",{className:"card-id",children:s.id}),e.jsx("span",{children:s.title})]},s.id))})]}),e.jsxs("div",{className:"research-view__reader card",children:[R&&e.jsx("p",{"data-testid":"research-state-loading",children:"Loading research runs…"}),!R&&w&&e.jsx("p",{"data-testid":"research-state-error",children:w}),!R&&!w&&u.length===0&&e.jsx("p",{"data-testid":"research-state-empty",children:"No research runs yet"}),t&&e.jsxs("div",{children:[e.jsxs("div",{className:"research-view__status-row",children:[e.jsx("span",{className:re}),e.jsx("strong",{children:se})]}),e.jsx("h3",{className:"research-view__run-title",children:t.title}),e.jsx("p",{className:"research-view__run-query",children:t.query}),e.jsx("p",{className:"research-view__run-summary","data-testid":"research-state-results",children:t.results?.summary??"No summary yet."}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",disabled:j==="cancel",onClick:()=>void L("cancel",()=>S(t.id),"Run cancelled"),children:"Cancel"}),e.jsx("button",{className:"btn",type:"button",disabled:j==="retry",onClick:()=>void L("retry",()=>U(t.id),"Run retried"),children:"Retry"}),Q.includes("markdown")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-markdown",onClick:()=>void H("markdown"),children:"Export MD"}),Q.includes("json")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-json",onClick:()=>void H("json"),children:"Export JSON"}),Q.includes("html")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-html",onClick:()=>void H("html"),children:"Export HTML"})]}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn btn-primary",type:"button",disabled:j==="create-task",onClick:()=>void L("create-task",()=>g(t.id,`Research: ${t.title}`),"Task created from research"),children:"Create Task"}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-task-id",children:"Task ID"}),e.jsx("input",{id:"research-task-id",className:"input",placeholder:"Task ID",value:$,onChange:s=>ee(s.target.value)})]}),e.jsx("button",{className:"btn",type:"button",disabled:!$.trim()||j==="attach-task",onClick:()=>void L("attach-task",()=>A(t.id,$.trim(),"document"),"Attached to task"),children:"Attach to Task"})]}),t.error&&e.jsx("p",{className:"research-view__error",children:t.error}),Array.isArray(t.results?.findings)&&t.results.findings.length>0&&e.jsx("div",{className:"research-view__findings",children:t.results.findings.map(s=>e.jsxs("article",{className:"research-view__finding card",children:[e.jsx("h4",{children:s.heading}),e.jsx("p",{children:s.content})]},s.heading))}),Array.isArray(t.results?.citations)&&t.results.citations.length>0&&e.jsx("ul",{className:"research-view__citations",children:t.results.citations.map(s=>e.jsx("li",{children:e.jsx("a",{href:s,target:"_blank",rel:"noreferrer",children:s})},s))}),t.events.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:"Run history"}),e.jsx("ul",{className:"research-view__events",children:t.events.map(s=>e.jsx("li",{children:s.message},s.id))})]})]}),!t&&u.length>0&&e.jsx("p",{children:"Select a run to view details."}),e.jsxs("div",{className:"research-view__stats",children:[e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Running"}),e.jsx("div",{className:"research-view__stat-value",children:p.running})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Completed"}),e.jsx("div",{className:"research-view__stat-value",children:p.completed})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Failed"}),e.jsx("div",{className:"research-view__stat-value",children:p.failed})]})]})]})]})]})}export{ke as ResearchView};
1
+ import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{as as ae,at as ne,s as ce,au as ie,av as le,aw as oe,ax as de,ay as ue,az as he,z as me,aA as be,L as ve,S as pe}from"./index-CLAHcGnI.js";import"./vendor-xterm-DzcZoU0P.js";const C={webSearch:!0,pageFetch:!0,github:!1,localDocs:!0,llmSynthesis:!0};function K(d){const r=d?.researchGlobalDefaults,o=d?.researchSettings;return{enabled:o?.enabled??d?.researchEnabled??d?.researchGlobalEnabled??!0,searchProvider:o?.searchProvider??r?.searchProvider,synthesisProvider:o?.synthesisProvider??r?.synthesisProvider,synthesisModelId:o?.synthesisModelId??r?.synthesisModelId,enabledSources:{webSearch:o?.enabledSources?.webSearch??r?.enabledSources?.webSearch??C.webSearch,pageFetch:o?.enabledSources?.pageFetch??r?.enabledSources?.pageFetch??C.pageFetch,github:o?.enabledSources?.github??r?.enabledSources?.github??C.github,localDocs:o?.enabledSources?.localDocs??r?.enabledSources?.localDocs??C.localDocs,llmSynthesis:o?.enabledSources?.llmSynthesis??r?.enabledSources?.llmSynthesis??C.llmSynthesis},limits:{maxConcurrentRuns:o?.limits?.maxConcurrentRuns??d?.researchMaxConcurrentRuns??d?.researchGlobalMaxConcurrentRuns??3,maxSourcesPerRun:o?.limits?.maxSourcesPerRun??r?.maxSourcesPerRun??d?.researchMaxSourcesPerRun??d?.researchGlobalMaxSourcesPerRun??20,maxDurationMs:o?.limits?.maxDurationMs??d?.researchDefaultTimeout??d?.researchGlobalDefaultTimeout??3e5,requestTimeoutMs:o?.limits?.requestTimeoutMs??d?.researchFetchTimeoutMs??3e4},defaultExportFormat:r?.defaultExportFormat??"markdown"}}const fe=300,xe=4e3;function ye(d){const r=d?.projectId,[o,D]=a.useState([]),[u,t]=a.useState(null),[q,y]=a.useState(null),[f,R]=a.useState({available:!0}),[w,E]=a.useState(!0),[O,P]=a.useState(null),[S,U]=a.useState(""),_=a.useRef(0),g=a.useRef(0),A=a.useRef(r);a.useEffect(()=>{A.current!==r&&(A.current=r,g.current++)},[r]);const p=a.useCallback(async(n=S)=>{const c=++_.current,i=r;P(null);try{const h=await ae({q:n||void 0,limit:100},i);if(c!==_.current||i!==r)return;D(h.runs),R(h.availability),u&&!h.runs.some(m=>m.id===u)&&(t(null),y(null))}catch(h){if(c!==_.current||i!==r)return;P(h instanceof Error?h.message:"Failed to load research runs")}finally{c===_.current&&E(!1)}},[r,S,u]),x=a.useCallback(async n=>{const c=await ne(n,r);return y(c.run),R(c.availability),c.run},[r]);return a.useEffect(()=>{E(!0);const n=window.setTimeout(()=>{p(S)},fe);return()=>window.clearTimeout(n)},[p,S]),a.useEffect(()=>{if(!u){y(null);return}x(u)},[x,u]),a.useEffect(()=>{const n=g.current,c=()=>g.current!==n,i=r?`?projectId=${encodeURIComponent(r)}`:"";let h=!0;const m=()=>{!h||c()||(p(),u&&x(u))},V=ce(`/api/events${i}`,{events:{"research:run:created":m,"research:run:updated":m,"research:run:completed":m,"research:run:failed":m,"research:run:cancelled":m},onReconnect:m}),M=window.setInterval(m,xe);return()=>{h=!1,V(),window.clearInterval(M)}},[r,p,u,x]),{runs:o,selectedRun:q,selectedRunId:u,setSelectedRunId:t,availability:f,loading:w,error:O,searchQuery:S,setSearchQuery:U,refresh:p,createRun:n=>he(n,r),cancelRun:async n=>{const c=await ue(n,r);return u===n&&y(c.run),await p(),c},retryRun:async n=>{const c=await de(n,r);return u===n&&y(c.run),await p(),c},exportRun:(n,c)=>oe(n,c,r),createTaskFromRun:(n,c)=>le(n,{title:c},r),attachRunToTask:(n,c,i)=>ie(n,{taskId:c,mode:i},r),statusCounts:o.reduce((n,c)=>(n[c.status]+=1,n),{pending:0,running:0,completed:0,failed:0,cancelled:0})}}const Se=["web-search","page-fetch","github","local-docs","llm-synthesis"],je={"web-search":"webSearch","page-fetch":"pageFetch",github:"github","local-docs":"localDocs","llm-synthesis":"llmSynthesis"},Re={"web-search":"Web Search","page-fetch":"Page Fetch",github:"GitHub","local-docs":"Local Docs","llm-synthesis":"LLM Synthesis"};function ke({projectId:d,addToast:r,onOpenSettings:o,readinessVersion:D=0}){const{runs:u,selectedRun:t,selectedRunId:q,setSelectedRunId:y,availability:f,loading:R,error:w,searchQuery:E,setSearchQuery:O,createRun:P,cancelRun:S,retryRun:U,exportRun:_,createTaskFromRun:g,attachRunToTask:A,statusCounts:p,refresh:x}=ye({projectId:d}),[n,c]=a.useState(""),[i,h]=a.useState(()=>K(void 0)),[m,V]=a.useState([]),[M,J]=a.useState(!1),[W,Y]=a.useState([]),[$,ee]=a.useState(""),[j,I]=a.useState(null),G=f.supportedProviders??Se,F=s=>i.enabledSources[je[s]];a.useEffect(()=>{const s=G.filter(l=>F(l));Y(l=>{const b=l.filter(v=>s.includes(v));return b.length>0?b:s})},[i.enabledSources,G]),a.useEffect(()=>{let s=!1;return Promise.all([me(d),be().catch(()=>({providers:[]}))]).then(([l,b])=>{s||(h(K(l)),V(b.providers.filter(v=>v.type==="api_key").map(v=>({id:v.id,authenticated:v.authenticated}))))}).catch(()=>{s||h(K(void 0))}),()=>{s=!0}},[d,D]);const se=a.useMemo(()=>t?t.status:"No run selected",[t]),re=a.useMemo(()=>t?t.status==="pending"?"status-dot status-dot--pending":t.status==="running"?"status-dot status-dot--connecting":t.status==="completed"?"status-dot status-dot--online":t.status==="failed"||t.status==="cancelled"?"status-dot status-dot--error":"status-dot":"status-dot",[t]),Q=f.supportedExportFormats??["markdown","json","html"],L=i.searchProvider,X=i.enabledSources.webSearch&&!L,Z=i.enabledSources.llmSynthesis&&(!i.synthesisProvider||!i.synthesisModelId),z=a.useMemo(()=>new Map(m.map(s=>[s.id,s.authenticated])),[m]),B=a.useMemo(()=>{const s=new Set;return i.enabledSources.webSearch&&L&&s.add(L),i.enabledSources.llmSynthesis&&i.synthesisProvider&&s.add(i.synthesisProvider),[...s].filter(l=>z.has(l))},[i.enabledSources.llmSynthesis,i.enabledSources.webSearch,i.synthesisProvider,L,z]).find(s=>z.get(s)!==!0),N=a.useMemo(()=>f.available?i.enabled?X||Z?{reason:"Research defaults are incomplete.",details:"Select the required provider/model defaults in Research settings.",settingsSection:"research-global"}:B?{reason:`Missing API key for ${B}.`,details:"Add provider credentials in Authentication settings.",settingsSection:"authentication"}:null:{reason:"Research is disabled for this project.",details:"Enable project research settings to create runs.",settingsSection:"research-project"}:{reason:f.reason??"Research is unavailable for this project.",details:f.setupInstructions,settingsSection:"research-project"},[f.available,f.reason,f.setupInstructions,i.enabled,B,X,Z]),T=async(s,l,b)=>{I(s);try{await l(),r?.(b,"success"),await x()}catch(v){r?.(v instanceof Error?v.message:"Action failed","error")}finally{I(null)}},H=async s=>{if(t){I(`export-${s}`);try{const l=await _(t.id,s),b=new Blob([l.content],{type:"text/plain;charset=utf-8"}),v=URL.createObjectURL(b),k=document.createElement("a");k.href=v,k.download=l.filename,document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(v),r?.(`Exported ${l.filename}`,"success")}catch(l){r?.(l instanceof Error?l.message:"Export failed","error")}finally{I(null)}}},te=async()=>{if(n.trim()){J(!0);try{const s=W.filter(b=>F(b));if(s.length===0){r?.("No enabled research sources are available for this project.","error");return}const l=await P({query:n.trim(),providers:s});y(l.run.id),c(""),r?.("Research run created","success"),await x()}catch(s){r?.(s instanceof Error?s.message:"Failed to create run","error")}finally{J(!1)}}};return e.jsxs("section",{className:"research-view","aria-label":"Research view",children:[e.jsxs("header",{className:"research-view__header",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"research-view__title",children:"Research"}),e.jsx("p",{className:"research-view__subtitle",children:"Create and track research runs with cited findings."})]}),e.jsx("button",{className:"btn",type:"button",onClick:()=>void x(),children:"Refresh"})]}),N?e.jsxs("div",{className:"research-view__state research-view__state--error card","data-testid":"research-state-unavailable",children:[e.jsx("p",{children:N.reason}),N.details&&e.jsx("p",{children:N.details}),e.jsxs("p",{children:["Current defaults: provider ",i.searchProvider??"(not set)",", max sources ",i.limits.maxSourcesPerRun]}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",onClick:()=>void x(),children:"Refresh"}),e.jsx("button",{className:"btn btn-primary",type:"button",onClick:()=>o?.(N.settingsSection),children:"Open Settings"})]})]}):e.jsxs("div",{className:"research-view__layout",children:[e.jsxs("aside",{className:"research-view__sidebar card",children:[e.jsxs("div",{className:"research-view__form",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-query",children:"Query"}),e.jsx("textarea",{id:"research-query",className:"input research-view__textarea",value:n,onChange:s=>c(s.target.value)})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:"Providers"}),e.jsx("div",{className:"research-view__providers",children:G.map(s=>e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:W.includes(s),disabled:!F(s),onChange:()=>{F(s)&&Y(l=>l.includes(s)?l.filter(b=>b!==s):[...l,s])}}),e.jsx("span",{children:Re[s]??s})]},s))})]}),e.jsxs("button",{className:"btn btn-primary",type:"button",disabled:!n.trim()||M,onClick:()=>void te(),children:[M?e.jsx(ve,{className:"animate-spin",size:14}):null,"Create Run"]})]}),e.jsxs("div",{className:"research-view__history-header form-group",children:[e.jsx("label",{htmlFor:"research-run-search",children:"Search"}),e.jsxs("div",{className:"research-view__history-search-row",children:[e.jsx(pe,{size:14}),e.jsx("input",{id:"research-run-search",className:"input",placeholder:"Search runs",value:E,onChange:s=>O(s.target.value)})]})]}),e.jsx("div",{className:"research-view__history","data-testid":"research-state-running",children:u.map(s=>e.jsxs("button",{type:"button",className:`research-view__history-item${q===s.id?" research-view__history-item--active":""}`,onClick:()=>y(s.id),children:[e.jsx("span",{className:"card-id",children:s.id}),e.jsx("span",{children:s.title})]},s.id))})]}),e.jsxs("div",{className:"research-view__reader card",children:[R&&e.jsx("p",{"data-testid":"research-state-loading",children:"Loading research runs…"}),!R&&w&&e.jsx("p",{"data-testid":"research-state-error",children:w}),!R&&!w&&u.length===0&&e.jsx("p",{"data-testid":"research-state-empty",children:"No research runs yet"}),t&&e.jsxs("div",{children:[e.jsxs("div",{className:"research-view__status-row",children:[e.jsx("span",{className:re}),e.jsx("strong",{children:se})]}),e.jsx("h3",{className:"research-view__run-title",children:t.title}),e.jsx("p",{className:"research-view__run-query",children:t.query}),e.jsx("p",{className:"research-view__run-summary","data-testid":"research-state-results",children:t.results?.summary??"No summary yet."}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn",type:"button",disabled:j==="cancel",onClick:()=>void T("cancel",()=>S(t.id),"Run cancelled"),children:"Cancel"}),e.jsx("button",{className:"btn",type:"button",disabled:j==="retry",onClick:()=>void T("retry",()=>U(t.id),"Run retried"),children:"Retry"}),Q.includes("markdown")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-markdown",onClick:()=>void H("markdown"),children:"Export MD"}),Q.includes("json")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-json",onClick:()=>void H("json"),children:"Export JSON"}),Q.includes("html")&&e.jsx("button",{className:"btn",type:"button",disabled:j==="export-html",onClick:()=>void H("html"),children:"Export HTML"})]}),e.jsxs("div",{className:"research-view__actions",children:[e.jsx("button",{className:"btn btn-primary",type:"button",disabled:j==="create-task",onClick:()=>void T("create-task",()=>g(t.id,`Research: ${t.title}`),"Task created from research"),children:"Create Task"}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"research-task-id",children:"Task ID"}),e.jsx("input",{id:"research-task-id",className:"input",placeholder:"Task ID",value:$,onChange:s=>ee(s.target.value)})]}),e.jsx("button",{className:"btn",type:"button",disabled:!$.trim()||j==="attach-task",onClick:()=>void T("attach-task",()=>A(t.id,$.trim(),"document"),"Attached to task"),children:"Attach to Task"})]}),t.error&&e.jsx("p",{className:"research-view__error",children:t.error}),Array.isArray(t.results?.findings)&&t.results.findings.length>0&&e.jsx("div",{className:"research-view__findings",children:t.results.findings.map(s=>e.jsxs("article",{className:"research-view__finding card",children:[e.jsx("h4",{children:s.heading}),e.jsx("p",{children:s.content})]},s.heading))}),Array.isArray(t.results?.citations)&&t.results.citations.length>0&&e.jsx("ul",{className:"research-view__citations",children:t.results.citations.map(s=>e.jsx("li",{children:e.jsx("a",{href:s,target:"_blank",rel:"noreferrer",children:s})},s))}),t.events.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:"Run history"}),e.jsx("ul",{className:"research-view__events",children:t.events.map(s=>e.jsx("li",{children:s.message},s.id))})]})]}),!t&&u.length>0&&e.jsx("p",{children:"Select a run to view details."}),e.jsxs("div",{className:"research-view__stats",children:[e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Running"}),e.jsx("div",{className:"research-view__stat-value",children:p.running})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Completed"}),e.jsx("div",{className:"research-view__stat-value",children:p.completed})]}),e.jsxs("div",{className:"research-view__stat-card",children:[e.jsx("div",{className:"research-view__stat-label",children:"Failed"}),e.jsx("div",{className:"research-view__stat-value",children:p.failed})]})]})]})]})]})}export{ke as ResearchView};
@@ -0,0 +1 @@
1
+ .research-view{display:flex;flex-direction:column;gap:var(--space-md);height:100%;min-height:0;padding:var(--space-lg);padding-bottom:calc(var(--space-lg) + var(--mobile-nav-height) + env(safe-area-inset-bottom,0px) + var(--standalone-bottom-gap))}.research-view__header{display:flex;align-items:flex-start;justify-content:space-between;gap:var(--space-md)}.research-view__title{margin:0}.research-view__subtitle{margin:var(--space-xs) 0 0;color:var(--text-muted)}.research-view__layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,2fr);gap:var(--space-md);min-height:0;flex:1}.research-view__sidebar,.research-view__reader{padding:var(--space-md);display:flex;flex-direction:column;gap:var(--space-md);min-height:0}.research-view__form{display:flex;flex-direction:column;gap:var(--space-sm)}.research-view__form .form-group,.research-view__history-header.form-group,.research-view__actions .form-group{margin:0;padding:0}.research-view__textarea{min-height:calc(var(--space-2xl) * 3);resize:vertical}.research-view__providers{display:grid;gap:var(--space-xs)}.research-view__history-header{display:flex;flex-direction:column;align-items:stretch;gap:var(--space-xs)}.research-view__history-search-row{display:flex;align-items:center;gap:var(--space-xs)}.research-view__history{display:flex;flex-direction:column;gap:var(--space-xs);overflow:auto}.research-view__history-item{border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-sm);background:var(--surface);color:var(--text);text-align:left;padding:var(--space-sm);min-height:calc(var(--space-lg) * 2 + var(--space-xs));display:flex;flex-direction:column;justify-content:center;gap:var(--space-xs);cursor:pointer;transition:border-color var(--transition-fast),box-shadow var(--transition-fast),background-color var(--transition-fast),transform var(--transition-fast)}.research-view__history-item:hover{background:var(--card-hover);border-color:var(--todo)}.research-view__history-item:focus-visible{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring-strong)}.research-view__history-item:active{transform:scale(.97)}.research-view__history-item--active{border-color:var(--todo);box-shadow:var(--focus-ring)}.research-view__status-row{display:flex;align-items:center;gap:var(--space-xs);text-transform:capitalize}.research-view__run-title,.research-view__run-query,.research-view__run-summary{margin:0}.research-view__run-query{color:var(--text-muted)}.research-view__actions{display:flex;flex-wrap:wrap;gap:var(--space-xs);margin-top:var(--space-sm)}.research-view__citations{margin:var(--space-sm) 0 0;padding-left:var(--space-lg);display:flex;flex-direction:column;gap:var(--space-xs)}.research-view__citations a{color:var(--text)}.research-view__error{color:var(--color-error)}.research-view__findings{display:flex;flex-direction:column;gap:var(--space-sm)}.research-view__finding{padding:var(--space-sm)}.research-view__finding h4,.research-view__finding p{margin:0}.research-view__events{margin:var(--space-sm) 0 0;padding-left:var(--space-lg)}.research-view__stats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:var(--space-sm)}.research-view__stat-card{border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-sm);padding:var(--space-sm);background:var(--surface)}.research-view__stat-label{color:var(--text-muted);text-transform:uppercase;font-size:.6875rem}.research-view__stat-value{font-family:var(--font-mono);font-size:.8125rem}.research-view__state--error{border-color:var(--color-error)}@media(max-width:768px){.research-view{padding:var(--space-md);padding-bottom:calc(var(--space-md) + var(--mobile-nav-height) + env(safe-area-inset-bottom,0px) + var(--standalone-bottom-gap))}.research-view__layout{grid-template-columns:minmax(0,1fr)}.research-view__header{flex-direction:column}.research-view__stats{grid-template-columns:minmax(0,1fr)}.research-view__history-item{min-height:calc(var(--space-lg) * 2 + var(--space-sm))}}