@runfusion/fusion 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/bin.js +28004 -16888
- package/dist/client/assets/AgentDetailView-B7QRcHJH.css +1 -0
- package/dist/client/assets/AgentDetailView-DwLmRXTY.js +18 -0
- package/dist/client/assets/{AgentsView-B3jYk8Kt.js → AgentsView-D-N6aA0P.js} +12 -7
- package/dist/client/assets/ChatView-DnCdKu8Z.js +1 -0
- package/dist/client/assets/{DevServerView-DyGDEiBP.js → DevServerView-BiA1nYtt.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-D5UIeIl6.js → DirectoryPicker-DvBviDG6.js} +1 -1
- package/dist/client/assets/{DocumentsView-DNHu1T8K.js → DocumentsView-BWXOxpuq.js} +1 -1
- package/dist/client/assets/{EvalsView-CpRobtDi.js → EvalsView-CJFbtL7i.js} +1 -1
- package/dist/client/assets/{ExperimentalAgentOnboardingModal-DOY_oZi7.js → ExperimentalAgentOnboardingModal-DuGIPd0B.js} +1 -1
- package/dist/client/assets/InsightsView-BBpRiolN.js +11 -0
- package/dist/client/assets/{MemoryView-PSc5lGJt.js → MemoryView-48LuNkKk.js} +2 -2
- package/dist/client/assets/NodesView-CGQWSNZM.js +14 -0
- package/dist/client/assets/{PiExtensionsManager-DL_QcN56.js → PiExtensionsManager-i-7UL2oh.js} +2 -2
- package/dist/client/assets/PluginManager-DoSAykD6.js +1 -0
- package/dist/client/assets/{ResearchView-BzCcDAS4.css → ResearchView-BEI4ZSGs.css} +1 -1
- package/dist/client/assets/ResearchView-XZuRtOxE.js +1 -0
- package/dist/client/assets/SettingsModal-Ci0_sqbU.css +1 -0
- package/dist/client/assets/{SettingsModal-CUCyaAyE.js → SettingsModal-CmeF8CN4.js} +1 -1
- package/dist/client/assets/SettingsModal-DBcjf9Bu.js +31 -0
- package/dist/client/assets/SettingsModal-DWKgRxBA.css +1 -0
- package/dist/client/assets/{SetupWizardModal-BKscasuh.js → SetupWizardModal-CgtvpMX9.js} +1 -1
- package/dist/client/assets/{SkillsView-BdELqTy7.js → SkillsView-DErYRumF.js} +1 -1
- package/dist/client/assets/StashRecoveryView-B_8WIQEo.css +1 -0
- package/dist/client/assets/StashRecoveryView-QJrNS4Vg.js +1 -0
- package/dist/client/assets/{TodoView-DFNGBDNV.js → TodoView-BD9NRwq0.js} +2 -2
- package/dist/client/assets/createLucideIcon-BazL2hk5.js +21 -0
- package/dist/client/assets/dashboard-view-BWGH_fAq.js +63 -0
- package/dist/client/assets/dashboard-view-BoTzlP8b.css +1 -0
- package/dist/client/assets/dashboard-view-DdGlfuu-.css +1 -0
- package/dist/client/assets/dashboard-view-Ws9_ZnKu.js +21 -0
- package/dist/client/assets/{folder-open-k1xmUMyr.js → folder-open-CHSlllzf.js} +1 -1
- package/dist/client/assets/index-DCovGm5b.css +1 -0
- package/dist/client/assets/index-bEwSVl7B.js +692 -0
- package/dist/client/assets/{star-ne32r3Y4.js → star-BgVwWAPz.js} +1 -1
- package/dist/client/assets/{upload-MS-2Gx53.js → upload-CAzycxr9.js} +1 -1
- package/dist/client/assets/{users-C519GSjH.js → users-CZnxCCCJ.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/droid-cli/src/__tests__/index.test.ts +228 -0
- package/dist/extension.js +15810 -10205
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/pi-claude-cli/src/__tests__/provider.test.ts +36 -22
- package/dist/pi-claude-cli/src/provider.ts +7 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/manifest.json +24 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +44 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/TestRunnerPanel.test.tsx +99 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/config-flow.test.ts +91 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/dashboard-view.test.tsx +40 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/dashboard-views.test.ts +46 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/draft-store.test.ts +50 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/fixtures/exec-mock.ts +80 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/fixtures/fixtures.test.ts +40 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/fixtures/registry.ts +82 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/generator.test.ts +54 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/manage-view.test.tsx +98 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/manifest.test.ts +36 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/registration.test.ts +29 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/run-routes.test.ts +98 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/runner.test.ts +55 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/runtime-availability.test.ts +61 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/validation.test.ts +30 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/wizard-routes.test.ts +61 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/workflow-integration.test.ts +19 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/dashboard-view.css +43 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/dashboard-view.tsx +49 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/generation/generator.ts +95 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/generation/redact.ts +9 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/generation/runner.ts +79 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/generation/types.ts +31 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/index.ts +58 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/manage/EditDraftModal.tsx +75 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/manage/useDrafts.ts +73 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/manage-view.css +79 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/manage-view.tsx +122 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/routes/wizard-routes.ts +272 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/run/TestRunnerPanel.css +70 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/run/TestRunnerPanel.tsx +98 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/run/useRunGeneratedCli.ts +37 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/runtime/__tests__/executor-runtime-env.test.ts +191 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/runtime/executor-runtime-env.ts +75 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/storage/draft-store.ts +85 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/store/__tests__/cli-press-store.test.ts +128 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/store/__tests__/credentials.test.ts +62 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/store/cli-press-store.ts +427 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/store/cli-press-types.ts +110 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/store/credentials.ts +95 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/wizard/steps.tsx +55 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/wizard/types.ts +33 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/wizard/validation.ts +63 -0
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/manifest.json +10 -0
- package/dist/plugins/fusion-plugin-reports/package.json +18 -2
- package/dist/plugins/fusion-plugin-reports/src/__tests__/approval.test.ts +164 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/manifest.test.ts +14 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/routes-approval.test.ts +109 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/scaffold.test.ts +60 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/share-blocks.test.ts +83 -0
- package/dist/plugins/fusion-plugin-reports/src/aggregation.ts +23 -0
- package/dist/plugins/fusion-plugin-reports/src/approval.ts +97 -0
- package/dist/plugins/fusion-plugin-reports/src/cadence.ts +23 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/ReportsView.css +82 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/ReportsView.tsx +24 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/ReportComparisonDrawer.test.tsx +12 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/ReportDetailPanel.test.tsx +12 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/ReportFiltersBar.test.tsx +14 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/ReportsView.test.tsx +27 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/api.test.ts +19 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/useReportSectionDiff.test.ts +11 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/useReports.test.ts +13 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/api.ts +85 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportApprovalPanel.css +59 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportApprovalPanel.tsx +58 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportComparisonDrawer.tsx +21 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportDetailPanel.tsx +29 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportEmptyState.tsx +3 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportFiltersBar.tsx +19 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ReportListItem.tsx +8 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ShareBlocksPanel.css +29 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ShareBlocksPanel.tsx +43 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/__tests__/ReportApprovalPanel.test.tsx +38 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/__tests__/ShareBlocksPanel.test.tsx +24 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts +18 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/types.ts +22 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/useReportPreview.ts +44 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/useReportSectionDiff.ts +59 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/useReports.ts +71 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/useViewportMode.ts +13 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard-view.tsx +6 -0
- package/dist/plugins/fusion-plugin-reports/src/index.ts +48 -2
- package/dist/plugins/fusion-plugin-reports/src/pipeline.ts +58 -0
- package/dist/plugins/fusion-plugin-reports/src/render/__tests__/escape.test.ts +20 -0
- package/dist/plugins/fusion-plugin-reports/src/render/__tests__/html-template.test.ts +110 -0
- package/dist/plugins/fusion-plugin-reports/src/render/__tests__/standalone-html.test.ts +66 -0
- package/dist/plugins/fusion-plugin-reports/src/render/escape.ts +12 -0
- package/dist/plugins/fusion-plugin-reports/src/render/html-styles.ts +40 -0
- package/dist/plugins/fusion-plugin-reports/src/render/html-template.ts +137 -0
- package/dist/plugins/fusion-plugin-reports/src/render/index.ts +4 -0
- package/dist/plugins/fusion-plugin-reports/src/render/standalone-html.ts +75 -0
- package/dist/plugins/fusion-plugin-reports/src/report-schema.ts +31 -0
- package/dist/plugins/fusion-plugin-reports/src/routes/__tests__/report-export-routes.test.ts +104 -0
- package/dist/plugins/fusion-plugin-reports/src/routes/report-approval-routes.ts +98 -0
- package/dist/plugins/fusion-plugin-reports/src/routes/report-export-routes.ts +77 -0
- package/dist/plugins/fusion-plugin-reports/src/routes/report-list-routes.ts +72 -0
- package/dist/plugins/fusion-plugin-reports/src/runs-store.ts +69 -0
- package/dist/plugins/fusion-plugin-reports/src/share-blocks.ts +82 -0
- package/dist/plugins/fusion-plugin-reports/src/store/report-store.ts +51 -2
- package/dist/plugins/fusion-plugin-reports/src/store/report-types.ts +6 -1
- package/dist/plugins/fusion-plugin-roadmap/bundled.js +1672 -0
- package/dist/plugins/fusion-plugin-roadmap/manifest.json +1 -1
- package/dist/plugins/fusion-plugin-roadmap/package.json +4 -41
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +2 -3
- package/skill/fusion/references/engine-tools.md +1 -1
- package/skill/fusion/references/extension-tools.md +3 -3
- package/skill/fusion/references/fusion-capabilities.md +1 -1
- package/dist/client/assets/AgentDetailView-BwJaLqZh.css +0 -1
- package/dist/client/assets/AgentDetailView-ZbHEbYRT.js +0 -18
- package/dist/client/assets/ChatView-DhPkiEGs.js +0 -1
- package/dist/client/assets/InsightsView-vp0RE8Mg.js +0 -11
- package/dist/client/assets/NodesView-DMj6HGeC.js +0 -14
- package/dist/client/assets/PluginManager-BtYKm8IT.js +0 -1
- package/dist/client/assets/ResearchView-BhWqfdV0.js +0 -1
- package/dist/client/assets/SettingsModal-BAgB4_AR.js +0 -31
- package/dist/client/assets/SettingsModal-BNSrO1M9.css +0 -1
- package/dist/client/assets/SettingsModal-DzsLquBu.css +0 -1
- package/dist/client/assets/index-Qq2JOOWx.css +0 -1
- package/dist/client/assets/index-TFYXEVpn.js +0 -692
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/api-client.test.ts +0 -101
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/index.test.ts +0 -92
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/roadmap-routes.test.ts +0 -48
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/roadmap-suggestions.test.ts +0 -31
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/RoadmapsView.css +0 -1299
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/RoadmapsView.tsx +0 -2559
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/__tests__/RoadmapsView.test.tsx +0 -1144
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/__tests__/useRoadmaps.test.ts +0 -1756
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/api.ts +0 -70
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/test-setup.ts +0 -7
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/types.ts +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useConfirm.ts +0 -8
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useRoadmaps.ts +0 -1188
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useViewportMode.ts +0 -20
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard-view.tsx +0 -6
- package/dist/plugins/fusion-plugin-roadmap/src/index.ts +0 -74
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-routes.ts +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-schema.ts +0 -41
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-suggestions.d.ts +0 -15
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-suggestions.ts +0 -15
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.d.ts +0 -283
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.js +0 -21
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.ts +0 -310
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.d.ts +0 -5
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.js +0 -361
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.ts +0 -408
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.d.ts +0 -68
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.js +0 -300
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.ts +0 -381
- package/dist/plugins/fusion-plugin-roadmap/src/server/index.d.ts +0 -3
- package/dist/plugins/fusion-plugin-roadmap/src/server/index.ts +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-handoff.test.ts +0 -445
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-ordering.test.ts +0 -334
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-store.test.ts +0 -1318
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-handoff.ts +0 -163
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.d.ts +0 -37
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.js +0 -188
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.ts +0 -311
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.d.ts +0 -299
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.js +0 -765
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.ts +0 -1001
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as s,a as Fs,j as t}from"./vendor-react-K0fH_qHe.js";import{i as dt,b3 as es,t as hs,b4 as zs,b5 as ts,b6 as Us,w as Pt,b7 as ze,b8 as _s,b9 as Os,ba as Hs,bb as Bs,bc as Ws,bd as Gs,s as fs,be as Vs,bf as Ks,bg as Rt,bh as qs,bi as Js,bj as Ys,bk as Xs,k as gs,bl as Qs,p as Zs,bm as en,bn as tn,u as sn,bo as nn,ab as ps,ac as bs,bp as an,bq as rn,S as on,W as At,P as Ye,I as ot,ao as cn,br as ss,bs as ns,bt as as,B as Xe,a as rs,a8 as ln,a9 as dn,bu as un,bv as mn,aS as hn,bw as fn,bx as os,by as gn,h as pn,j as is,m as bn}from"./index-bEwSVl7B.js";import"./vendor-xterm-DzcZoU0P.js";const Et="kb-chat-active-session";function cs(n){const r=typeof n=="string"?n.trim():"",m=r.indexOf("/");return!r||m<=0||m>=r.length-1?{}:{modelProvider:r.slice(0,m),modelId:r.slice(m+1)}}function vn(n){const r=n?.toolCalls;if(!Array.isArray(r))return;const m=r.map(o=>{if(!o||typeof o!="object")return null;const l=o,x=typeof l.toolName=="string"?l.toolName:"";if(!x)return null;const D=l.args;return{toolName:x,...D&&typeof D=="object"?{args:D}:{},isError:!!l.isError,result:l.result,status:"completed"}}).filter(o=>o!==null);return m.length>0?m:void 0}function xn(n){const r=n?.fallback;if(!r||typeof r!="object")return;const m=r,o=typeof m.primaryModel=="string"?m.primaryModel:"",l=typeof m.fallbackModel=="string"?m.fallbackModel:"",x=m.triggerPoint;if(!(!o||!l||x!=="session-creation"&&x!=="prompt-time"))return{primaryModel:o,fallbackModel:l,triggerPoint:x}}function Tt(n){return{id:n.id,sessionId:n.sessionId,role:n.role,content:n.content,thinkingOutput:n.thinkingOutput,toolCalls:vn(n.metadata),fallbackInfo:xn(n.metadata),attachments:n.attachments,createdAt:n.createdAt}}function wn(n,r){const[m,o]=s.useState([]),[l,x]=s.useState(null),[D,P]=s.useState(!0),[$,y]=s.useState([]),[ee,v]=s.useState(!1),[z,S]=s.useState(!1),[ne,R]=s.useState(""),[A,f]=s.useState(""),[k,E]=s.useState([]),[I,T]=s.useState(""),[oe,te]=s.useState(""),[U,b]=s.useState(!0),[h,d]=s.useState(new Map),i=s.useRef(null),u=s.useRef(!1),w=s.useRef(""),M=s.useRef(null),J=s.useRef(m),_=s.useRef(l),Y=s.useRef(z);J.current=m,_.current=l,Y.current=z,s.useEffect(()=>{w.current=I},[I]);const Re=s.useRef(new Set),V=s.useRef(0),pe=s.useRef(n);pe.current!==n&&(pe.current=n,V.current++),s.useEffect(()=>{const g=V.current;dt(void 0,n).then(p=>{if(V.current!==g)return;const C=new Map;for(const L of p)C.set(L.id,L);d(C)}).catch(()=>{})},[n]);const Ae=s.useCallback(async()=>{P(!0);try{const p=[...(await es(n)).sessions].sort((C,L)=>new Date(L.updatedAt).getTime()-new Date(C.updatedAt).getTime());o(p)}catch{}finally{P(!1)}},[n]);s.useEffect(()=>{Ae()},[Ae]);const De=s.useRef(()=>{}),X=s.useRef(!1);s.useEffect(()=>{X.current=!1},[n]),s.useEffect(()=>{if(D||X.current||_.current)return;const g=hs(Et,n);if(!g){X.current=!0;return}const p=m.find(C=>C.id===g);if(p){X.current=!0,De.current(g,p);return}X.current=!0},[D,m,n]);const N=s.useCallback(async(g,p)=>{v(!0);try{const C=await zs(g,{limit:50,...p},n),L=C.messages.map(Tt);p?.offset&&p.offset>0?y(Q=>[...L,...Q]):y(L),b(C.messages.length>=50)}catch{}finally{v(!1)}},[n]),ie=s.useCallback(()=>{M.current?.(),M.current=null,w.current="",T(""),R(""),f(""),E([]),S(!1)},[]),ue=s.useCallback((g,p)=>{if(i.current||!g)return!0;u.current=!1,p&&(R(p.streamingText),f(p.streamingThinking),E(p.toolCalls)),S(!0);const{handlers:C}=ts({sessionId:g,tempUserMessageId:"",setStreamingText:R,setStreamingThinking:f,setStreamingToolCalls:E,cancelStreamingFlushesRef:M,addToast:r,onFallbackSession:(Q,G)=>{const se=cs(Q.fallbackModel);o(O=>O.map(ae=>ae.id===G?{...ae,...se}:ae)),x(O=>O&&O.id===G?{...O,...se}:O)},onDone:()=>{R(""),f(""),E([]),S(!1),Y.current=!1,i.current=null,N(g)},onError:Q=>{R(""),f(""),E([]),S(!1),Y.current=!1,i.current=null;const G=typeof Q=="string"&&Q.trim()?Q:"Failed to get response";r?.(G,"error"),N(g)}}),L=Us(g,C,n,{...typeof p?.replayFromEventId=="number"?{lastEventId:p.replayFromEventId}:{}});return i.current=L,!0},[r,N,n]),be=s.useCallback((g,p)=>{const C=_.current?.id??null;if(g&&C===g&&!p)return;i.current&&(i.current.close(),i.current=null);const L=p??m.find(Q=>Q.id===g);x(L||null),ie(),b(!0),g?N(g):y([]),L?.isGenerating&&ue(L.id,L.inFlightGeneration),g?Pt(Et,g,n):ze(Et,n)},[ue,m,N,n,ie]);De.current=be;const Qe=s.useCallback(async g=>{const p=await _s(g,n);i.current&&(i.current.close(),i.current=null);const C={id:p.session.id,title:p.session.title,agentId:p.session.agentId,status:p.session.status,modelProvider:p.session.modelProvider,modelId:p.session.modelId,createdAt:p.session.createdAt,updatedAt:p.session.updatedAt};return o(L=>L.some(Q=>Q.id===C.id)?L:[C,...L]),ie(),be(C.id,C),y([]),C},[n,ie,be]),ut=s.useCallback(async g=>{await Os(g,{status:"archived"},n),o(p=>p.filter(C=>C.id!==g)),l?.id===g&&(x(null),y([]))},[l,n]),Ze=s.useCallback(async g=>{l?.id===g&&i.current&&(i.current.close(),i.current=null),await Hs(g,n),o(p=>p.filter(C=>C.id!==g)),l?.id===g&&(x(null),y([]))},[l,n]),ve=s.useCallback(async()=>{!l||!U||await N(l.id,{offset:$.length})},[l,U,N,$.length]),xe=s.useCallback(()=>{l&&(u.current=!0,M.current?.(),M.current=null,i.current?.close(),i.current=null,Bs(l.id,n).catch(()=>{}),S(!1),R(""),f(""),E([]))},[l,n]),_e=s.useCallback(()=>{w.current="",T("")},[]),we=s.useRef(()=>{}),ye=Ws(),Se=s.useCallback((g,p)=>{if(!l)return;if(Y.current){w.current=g,T(g);return}u.current=!1,i.current&&(i.current.close(),i.current=null);const C=`temp-${Date.now()}`,L={id:C,sessionId:l.id,role:"user",content:g,createdAt:new Date().toISOString()};y(G=>[...G,L]),R(""),f(""),E([]),S(!0);const{handlers:Q}=ts({sessionId:l.id,tempUserMessageId:C,setStreamingText:R,setStreamingThinking:f,setStreamingToolCalls:E,cancelStreamingFlushesRef:M,addToast:r,onFallbackSession:(G,se)=>{const O=cs(G.fallbackModel);o(ae=>ae.map(F=>F.id===se?{...F,...O}:F)),x(ae=>ae&&ae.id===se?{...ae,...O}:ae)},onDone:({messageId:G,message:se,accumulated:O})=>{const ae=se?Tt(se):{id:G||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:O.text,thinkingOutput:O.thinking,toolCalls:O.toolCalls.length>0?O.toolCalls:void 0,fallbackInfo:O.fallbackInfo,createdAt:new Date().toISOString()};Re.current.add(ae.id),y(B=>[...B,ae]),R(""),f(""),E([]),S(!1),Y.current=!1,i.current=null,setTimeout(()=>{Re.current.delete(ae.id)},1e3),Ae();const F=w.current.trim();F&&(w.current="",T(""),we.current(F))},onError:(G,se)=>{y(F=>F.filter(B=>B.id!==se)),R(""),f(""),E([]),S(!1),Y.current=!1,i.current=null,console.error("[useChat] Stream error:",G);const O=typeof G=="string"&&G.trim()?G:"Failed to get response";if(typeof G=="string"&&Vs(G)&&(ye.isHiddenNow()||ye.wasRecentlyHidden(5e3))?(console.info("[useChat] Suppressed tab-suspension stream error:",G),l?.id&&(l.isGenerating?ue(l.id,l.inFlightGeneration):N(l.id))):r?.(O,"error"),!u.current){const F=w.current.trim();F&&(w.current="",T(""),we.current(F))}}});i.current=Gs(l.id,g,Q,p,n)},[l,n,Ae,r,N,ue,ye]);we.current=Se;const ke=oe?m.filter(g=>g.title?.toLowerCase().includes(oe.toLowerCase())||g.agentId.toLowerCase().includes(oe.toLowerCase())):m;return s.useEffect(()=>{if(!_.current?.isGenerating||(i.current||ue(_.current.id,_.current.inFlightGeneration),!Y.current||i.current||!_.current))return;const g=setInterval(async()=>{if(!Y.current||i.current||!_.current){clearInterval(g);return}try{(await es(n)).sessions.find(L=>L.id===_.current?.id)?.isGenerating||(clearInterval(g),await N(_.current.id),R(""),f(""),E([]),S(!1))}catch{}},3e3);return()=>clearInterval(g)},[ue,N,n,l]),s.useEffect(()=>{const g=V.current,p=n?`?projectId=${encodeURIComponent(n)}`:"",C=()=>V.current!==g,L=F=>{if(C())return;const B=JSON.parse(F.data);o(K=>K.some(Z=>Z.id===B.id)?K:[B,...K])},Q=F=>{if(C())return;const B=JSON.parse(F.data);o(K=>[...K.map(ce=>ce.id===B.id?B:ce)]),_.current?.id===B.id&&(x(B),B.isGenerating&&!i.current&&ue(B.id,B.inFlightGeneration))},G=F=>{if(C())return;const{id:B}=JSON.parse(F.data);o(K=>K.filter(Z=>Z.id!==B)),_.current?.id===B&&(x(null),y([]))},se=F=>{if(C())return;const B=JSON.parse(F.data),K=Tt(B);if(!Re.current.has(K.id)){if(_.current?.id===K.sessionId&&Y.current&&!i.current&&K.role==="assistant"){y(Z=>Z.some(ce=>ce.id===K.id)?Z:[...Z,K]),R(""),f(""),E([]),S(!1);return}_.current?.id===K.sessionId&&!Y.current&&y(Z=>{if(Z.some(ce=>ce.id===K.id))return Z;if(K.role==="user"){const ce=Z.findIndex(me=>me.role==="user"&&me.id.startsWith("temp-")&&me.content.trim()===K.content.trim());if(ce>=0){const me=[...Z];return me[ce]=K,me}}return[...Z,K]})}},O=F=>{if(C())return;const{id:B}=JSON.parse(F.data);y(K=>K.filter(Z=>Z.id!==B))};return fs(`/api/events${p}`,{events:{"chat:session:created":L,"chat:session:updated":Q,"chat:session:deleted":G,"chat:message:added":se,"chat:message:deleted":O}})},[ue,n]),s.useEffect(()=>()=>{i.current&&(i.current.close(),i.current=null)},[]),{sessions:m,activeSession:l,sessionsLoading:D,messages:$,messagesLoading:ee,isStreaming:z,streamingText:ne,streamingThinking:A,streamingToolCalls:k,pendingMessage:I,selectSession:be,createSession:Qe,archiveSession:ut,deleteSession:Ze,sendMessage:Se,stopStreaming:xe,clearPendingMessage:_e,loadMoreMessages:ve,hasMoreMessages:U,searchQuery:oe,setSearchQuery:te,filteredSessions:ke,refreshSessions:Ae,agentsMap:h}}const je="fusion:chat-active-room";function $t(n){return[...n].sort((r,m)=>new Date(m.updatedAt).getTime()-new Date(r.updatedAt).getTime())}function Je(n,r){const m=n.findIndex(l=>l.id===r.id);if(m===-1)return $t([r,...n]);const o=[...n];return o[m]=r,$t(o)}function Me(n){try{return JSON.parse(n.data)}catch{return null}}function yn(n,r){return{id:`temp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,roomId:n,role:"user",content:r,thinkingOutput:null,metadata:null,senderAgentId:null,mentions:[],createdAt:new Date().toISOString()}}function Sn(n,r){const[m,o]=s.useState([]),[l,x]=s.useState(!0),[D,P]=s.useState(null),[$,y]=s.useState(null),[ee,v]=s.useState([]),[z,S]=s.useState([]),[ne,R]=s.useState(!1),A=s.useRef(m),f=s.useRef($),k=s.useRef(0),E=s.useRef(n);A.current=m,f.current=$,E.current!==n&&(E.current=n,k.current+=1);const I=s.useCallback(async(h,d=!0)=>{if(!h){v([]),S([]),R(!1);return}d&&S([]),R(!0);try{const[i,u]=await Promise.all([Ks(h.id,n),Rt(h.id,{limit:100},n)]);v(i.members),S(u.messages)}catch{v([]),S([])}finally{R(!1)}},[n]),T=s.useCallback(async()=>{x(!0);try{const h=await qs({},n),d=$t(h.rooms);o(d),P(null);const i=hs(je,n);if(i){const u=d.find(w=>w.id===i)??null;u?(y(u),I(u,!0)):ze(je,n)}}catch(h){const d=h instanceof Error?h.message:"Failed to load chat rooms";P(d),r?.(d,"error")}finally{x(!1)}},[r,I,n]),oe=s.useCallback(h=>{if(!h){y(null),ze(je,n),I(null,!0);return}const d=A.current.find(i=>i.id===h)??null;y(d),d&&(Pt(je,d.id,n),I(d,!0))},[I,n]),te=s.useCallback(async h=>{const i=(await Js({name:h.name,memberAgentIds:h.memberAgentIds},n)).room;return o(u=>Je(u,i)),y(i),Pt(je,i.id,n),await I(i,!0),i},[I,n]),U=s.useCallback(async h=>{await Ys(h,n),o(d=>d.filter(i=>i.id!==h)),f.current?.id===h&&(y(null),v([]),S([]),ze(je,n))},[n]),b=s.useCallback(async(h,d)=>{const i=f.current,u=i?.id;if(!u)throw new Error("Select a room before sending a message");const w=yn(u,h);f.current?.id===u&&S(M=>[...M,w]);try{const M=await Xs(u,{content:h,...d?.attachments?{attachments:d.attachments}:{}},n);M.message?.createdAt&&i&&o(_=>Je(_,{...i,updatedAt:M.message.createdAt})),f.current?.id===u&&S(_=>_.map(Y=>Y.id===w.id?M.message:Y));const J=await Rt(u,{limit:100},n);if(f.current?.id!==u)return;S(J.messages)}catch(M){try{const J=await Rt(u,{limit:100},n);f.current?.id===u&&S(J.messages)}catch{f.current?.id===u&&S(J=>J.filter(_=>_.id!==w.id))}throw M}},[n]);return s.useEffect(()=>{T()},[T]),s.useEffect(()=>{const h=k.current,d=n?`/api/events?projectId=${encodeURIComponent(n)}`:"/api/events";return fs(d,{onReconnect:()=>{T()},events:{"chat:room:created":i=>{if(k.current!==h)return;const u=Me(i);u&&o(w=>Je(w,u))},"chat:room:updated":i=>{if(k.current!==h)return;const u=Me(i);u&&(o(w=>Je(w,u)),f.current?.id===u.id&&y(u))},"chat:room:deleted":i=>{if(k.current!==h)return;const u=Me(i);u?.id&&(o(w=>w.filter(M=>M.id!==u.id)),f.current?.id===u.id&&(y(null),v([]),S([]),ze(je,n)))},"chat:room:member:added":i=>{if(k.current!==h)return;const u=Me(i);!u||f.current?.id!==u.roomId||v(w=>w.some(M=>M.agentId===u.agentId)?w:[...w,u])},"chat:room:member:removed":i=>{if(k.current!==h)return;const u=Me(i);!u||f.current?.id!==u.roomId||v(w=>w.filter(M=>M.agentId!==u.agentId))},"chat:room:message:added":i=>{if(k.current!==h)return;const u=Me(i);u&&(o(w=>{const M=w.find(J=>J.id===u.roomId);return M?Je(w,{...M,updatedAt:u.createdAt}):w}),f.current?.id===u.roomId&&S(w=>{if(w.some(M=>M.id===u.id))return w;if(u.role==="user"){const M=w.findIndex(J=>J.role==="user"&&J.id.startsWith("temp-")&&J.content.trim()===u.content.trim());if(M>=0){const J=[...w];return J[M]=u,J}}return[...w,u]}))},"chat:room:message:updated":i=>{if(k.current!==h)return;const u=Me(i);!u||f.current?.id!==u.roomId||S(w=>w.map(M=>M.id===u.id?u:M))},"chat:room:message:deleted":i=>{if(k.current!==h)return;const u=Me(i);u?.id&&S(w=>w.filter(M=>M.id!==u.id))}}})},[n,T]),s.useEffect(()=>{$&&(m.some(h=>h.id===$.id)||(y(null),v([]),S([]),ze(je,n)))},[$,n,m]),{rooms:m,roomsLoading:l,roomsError:D,activeRoom:$,activeRoomMembers:ee,messages:z,messagesLoading:ne,selectRoom:oe,createRoom:te,deleteRoom:U,sendRoomMessage:b,refreshRooms:T}}function kn(n,r=[]){const m=n.trim().replace(/^#/,"");if(!m)return{ok:!1,error:"Room name is required."};if(/[A-Z]/.test(m))return{ok:!1,error:"Use lowercase letters only."};const o=m.toLowerCase();return o.length>80?{ok:!1,error:"Room names can be at most 80 characters."}:/^[a-z0-9_-]+$/.test(o)?/^[-_]|[-_]$/.test(o)?{ok:!1,error:"Room names cannot start or end with a hyphen or underscore."}:r.some(l=>l.toLowerCase()===o)?{ok:!1,error:"A room with this name already exists."}:{ok:!0,name:o}:{ok:!1,error:"Use lowercase letters, numbers, hyphens, or underscores only."}}function Nn({isOpen:n,onClose:r,onCreate:m,projectId:o,existingRoomNames:l=[]}){const[x,D]=s.useState(""),[P,$]=s.useState([]),[y,ee]=s.useState(""),[v,z]=s.useState([]),[S,ne]=s.useState(!1),[R,A]=s.useState(null),[f,k]=s.useState(!1),E=s.useRef(null),I=s.useRef(null);s.useEffect(()=>{n&&(I.current=document.activeElement instanceof HTMLElement?document.activeElement:null,ne(!0),A(null),dt(void 0,o).then(d=>$(d)).catch(()=>{$([]),A("Failed to load agents.")}).finally(()=>ne(!1)))},[n,o]),s.useEffect(()=>{if(!n){D(""),ee(""),z([]),A(null),k(!1);return}const d=window.requestAnimationFrame(()=>E.current?.focus());return()=>window.cancelAnimationFrame(d)},[n]),s.useEffect(()=>{if(!n)return;const d=i=>{i.key==="Escape"&&r()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[n,r]),s.useEffect(()=>{n||I.current?.focus()},[n]);const T=s.useMemo(()=>kn(x,l),[x,l]),oe=s.useMemo(()=>{const d=y.trim().toLowerCase();return d?P.filter(i=>i.name.toLowerCase().includes(d)):P},[P,y]),te=s.useMemo(()=>P.filter(d=>v.includes(d.id)),[P,v]),U=T.ok&&v.length>0&&!f&&!S;if(!n)return null;const b=d=>{f||z(i=>i.includes(d)?i.filter(u=>u!==d):[...i,d])},h=async()=>{if(!T.ok){A(T.error);return}if(v.length===0){A("Select at least one member.");return}A(null),k(!0);try{await m({name:T.name,displayName:`#${T.name}`,memberAgentIds:v}),r()}catch(d){A(d instanceof Error?d.message:"Failed to create room.")}finally{k(!1)}};return Fs.createPortal(t.jsx("div",{className:"modal-overlay open",onClick:d=>d.target===d.currentTarget&&r(),children:t.jsxs("div",{className:"modal modal-lg create-room-modal",role:"dialog","aria-modal":"true","aria-label":"Create room",onClick:d=>d.stopPropagation(),children:[t.jsxs("div",{className:"modal-header",children:[t.jsx("h3",{children:"Create room"}),t.jsx("button",{type:"button",className:"modal-close","aria-label":"Close",onClick:r,children:"×"})]}),t.jsxs("div",{className:"form-group create-room-modal-name-group",children:[t.jsx("label",{htmlFor:"create-room-name",children:"Room name"}),t.jsxs("div",{className:"create-room-modal-name-field",children:[t.jsx("span",{"aria-hidden":"true",className:"create-room-modal-name-hash",children:"#"}),t.jsx("input",{ref:E,id:"create-room-name",className:"input",value:x,disabled:f,onChange:d=>{const i=d.target.value.replace(/^#/,"").replace(/\s+/g,"-").toLowerCase();D(i)}})]}),!T.ok&&t.jsx("div",{className:"form-error",children:T.error})]}),t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"create-room-member-search",children:"Members"}),t.jsx("input",{id:"create-room-member-search",className:"input",placeholder:"Search agents",value:y,disabled:f,onChange:d=>ee(d.target.value)})]}),te.length>0&&t.jsx("div",{className:"create-room-modal-selected","data-testid":"create-room-selected-chips",children:te.map(d=>t.jsxs("button",{type:"button",className:"btn btn-sm create-room-modal-chip",onClick:()=>b(d.id),disabled:f,children:[d.name," ×"]},d.id))}),t.jsx("div",{className:"create-room-modal-member-list","data-testid":"create-room-member-list",children:S?t.jsx("div",{className:"create-room-modal-empty",children:"Loading agents..."}):oe.length===0?t.jsx("div",{className:"create-room-modal-empty",children:P.length===0?"No agents in this project yet.":"No agents match your search."}):oe.map(d=>{const i=v.includes(d.id);return t.jsxs("button",{type:"button",className:`create-room-modal-member-row${i?" create-room-modal-member-row--selected":""}`,onClick:()=>b(d.id),disabled:f,children:[t.jsx(gs,{agent:d,size:20}),t.jsx("span",{children:d.name}),t.jsx("span",{className:"create-room-modal-member-role",children:d.role})]},d.id)})}),R&&t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"form-error",children:R})}),t.jsxs("div",{className:"modal-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:r,disabled:f,children:"Cancel"}),t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void h(),disabled:!U,children:f?"Creating...":"Create room"})]})]})}),document.body)}function vs(n){const r=new Date(n),o=new Date().getTime()-r.getTime(),l=Math.floor(o/1e3),x=Math.floor(l/60),D=Math.floor(x/60),P=Math.floor(D/24);return l<60?"just now":x<60?`${x}m ago`:D<24?`${D}h ago`:P<7?`${P}d ago`:r.toLocaleDateString()}function ls(n,r){if(!n||!r)return null;const m=r.toLowerCase();if(m.includes("claude")){let l=r.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return l=l.replace(/\s+/g," "),l.length>30?l.slice(0,30)+"…":l}if(m.includes("gpt")||m.includes("openai")){const l=r.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return l.length>30?l.slice(0,30)+"…":l}if(m.includes("gemini")){const l=r.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}const o=r.replace(/-/g," ").replace(/^\w/,l=>l.toUpperCase()).replace(/\s+/g," ").trim();return o.length>30?o.slice(0,30)+"…":o}function lt(n,r){return n.length<=r?n:`${n.slice(0,r)}…`}function Cn(n){if(!n)return null;const r=Object.entries(n);return r.length===0?null:r.map(([m,o])=>{const l=typeof o=="string"?o:(()=>{try{return JSON.stringify(o)}catch{return String(o)}})();return`${m}=${lt(l,50)}`}).join(", ")}function jn(n){if(n===void 0)return null;if(typeof n=="string")return lt(n,200);try{return lt(JSON.stringify(n),200)}catch{return lt(String(n),200)}}function xs(n){if(!n||n.length===0)return null;const r=(v,z)=>{const S=v.status==="running",ne=v.status==="completed"&&v.isError,R=Cn(v.args),A=jn(v.result),f=S?R:A?`result: ${A}`:R?`args: ${R}`:null,k=S?"running":ne?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${S?" chat-tool-call--running":""}${ne?" chat-tool-call--error":""}`,open:S,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),t.jsx("span",{className:"chat-tool-call-name",title:v.toolName,children:v.toolName}),f&&t.jsx("span",{className:"chat-tool-call-preview",title:f,children:f}),t.jsx("span",{className:"chat-tool-call-status-text",children:k})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[R&&t.jsxs("div",{className:"chat-tool-call-row",children:[t.jsx("span",{className:"chat-tool-call-label",children:"args"}),t.jsx("span",{className:"chat-tool-call-value",children:R})]}),A&&t.jsxs("div",{className:`chat-tool-call-row${ne?" chat-tool-call-row--error":""}`,children:[t.jsx("span",{className:"chat-tool-call-label",children:"result"}),t.jsx("span",{className:"chat-tool-call-value",children:A})]})]})]},`${v.toolName}-${z}`)},m="chat-tool-calls";if(n.length===1)return t.jsxs("div",{className:m,"data-testid":"chat-tool-calls",children:[t.jsxs("div",{className:"chat-tool-calls-header",children:[t.jsx(os,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),r(n[0],0)]});const o=n.filter(v=>v.status==="running").length,l=n.filter(v=>v.status==="completed"&&v.isError).length,x=o>0,D=Array.from(new Set(n.map(v=>v.toolName))),P=D.slice(0,5),$=Math.max(0,D.length-P.length),y=$>0?`${P.join(", ")}, +${$} more`:P.join(", "),ee=x?`(${o} running)`:l>0?`(${l} ${l===1?"error":"errors"})`:null;return t.jsx("div",{className:m,"data-testid":"chat-tool-calls",children:t.jsxs("details",{className:"chat-tool-calls-group","data-testid":"chat-tool-calls-group",open:x,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(os,{size:12,"aria-hidden":"true"}),t.jsxs("span",{className:"chat-tool-calls-count",children:[n.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:y,children:y}),ee&&t.jsx("span",{className:"chat-tool-calls-group-status",children:ee})]}),n.map((v,z)=>r(v,z))]})})}const ws={pre:({children:n,...r})=>t.jsx("pre",{...r,className:"chat-markdown-pre",children:n}),table:({children:n,...r})=>t.jsx("table",{...r,className:"chat-markdown-table",children:n})},Ue="__fn_agent__",Mn=280,it=180,ct=500,ds="fusion:chat-sidebar-width",us="fusion:chat-scope",Rn=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function ms(n){const r=/(^|[\s])\/([^\s]*)$/.exec(n);if(!r)return null;const m=r[1]??"",o=r[2]??"",l=r.index+m.length;return{filter:o,start:l,end:n.length}}function An(n,r){const m=n.slice(0,r),o=/(^|[\s\n])@([\w-]*)$/.exec(m);if(!o)return null;const l=o[2]??"",x=m.length-l.length-1;return{filter:l,start:x,end:r}}function En({projectId:n,onClose:r,onCreate:m}){const[o,l]=s.useState("agent"),[x,D]=s.useState([]),[P,$]=s.useState(!0),[y,ee]=s.useState(""),[v,z]=s.useState([]),[S,ne]=s.useState(!0),[R,A]=s.useState(""),[f,k]=s.useState([]),[E,I]=s.useState([]);s.useEffect(()=>{let b=!1;return $(!0),dt(void 0,n).then(h=>{b||D(h)}).catch(()=>{b||D([])}).finally(()=>{b||$(!1)}),()=>{b=!0}},[n]),s.useEffect(()=>{ne(!0),pn().then(b=>{z(b.models),k(b.favoriteProviders),I(b.favoriteModels)}).catch(()=>{z([]),k([]),I([])}).finally(()=>{ne(!1)})},[]);const T=s.useCallback(async b=>{const h=f,i=h.includes(b)?h.filter(u=>u!==b):[b,...h];k(i);try{await is({favoriteProviders:i,favoriteModels:E})}catch{k(h)}},[f,E]),oe=s.useCallback(async b=>{const h=E,i=h.includes(b)?h.filter(u=>u!==b):[b,...h];I(i);try{await is({favoriteProviders:f,favoriteModels:i})}catch{I(h)}},[E,f]),te=b=>{if(b.preventDefault(),o==="agent"){if(!y)return;m({agentId:y});return}if(!R)return;const h=R.indexOf("/");if(h<=0)return;const d=R.slice(0,h),i=R.slice(h+1);m({agentId:Ue,modelProvider:d,modelId:i})},U=o==="agent"?!y:!R;return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:r,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:b=>b.stopPropagation(),children:[t.jsx("h3",{children:"New Chat"}),t.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${o==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{l("agent"),A("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${o==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{l("model"),ee("")},children:"Model"})]}),t.jsxs("form",{onSubmit:te,children:[o==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",P?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):x.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:x.map(b=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${y===b.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>ee(b.id),"data-testid":`agent-option-${b.id}`,children:[t.jsx(Xe,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:b.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:b.role})]},b.id))})]}),o==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:S?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(bn,{models:v,value:R,onChange:A,label:"Model",placeholder:"Select a model",favoriteProviders:f,onToggleFavorite:T,favoriteModels:E,onToggleModelFavorite:oe})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:r,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:U,children:"Create"})]})]})]})})}const Dt=s.memo(function({message:r,forcePlain:m,agentName:o,hideAssistantIdentity:l,showAssistantModelTag:x,activeModelTag:D,activeModelProvider:P,activeSessionId:$,mentionAgentsByName:y,roomContext:ee,copyAction:v}){const z=r.role==="assistant",S=s.useMemo(()=>{if(z)return null;const A=r.content,f=/@([\w-]+)/g,k=[];let E=0,I=f.exec(A);for(;I;){const[T,oe=""]=I,te=I.index;te>E&&k.push(A.slice(E,te));const U=oe.replace(/_/g," ").toLowerCase(),b=y.get(U);if(b){const h=!!(ee&&!ee.memberIds.has(b.id)),d=h?`Not a member of ${ee?.roomName}`:void 0;k.push(t.jsxs("span",{className:`chat-mention-chip${h?" chat-mention-chip--non-member":""}`,title:d,"aria-label":d,children:["@",b.name.replace(/\s+/g,"_")]},`${b.id}-${te}`))}else k.push(T);E=te+T.length,I=f.exec(A)}return E<A.length&&k.push(A.slice(E)),k.length===0?A:k},[z,r.content,y,ee]),ne=s.useMemo(()=>{const A=r.attachments;if(!A||A.length===0||!$)return null;const f=`/api/chat/sessions/${encodeURIComponent($)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:A.map(k=>{const E=k.mimeType.startsWith("image/"),I=k.id||k.filename,T=`${f}${encodeURIComponent(k.filename)}`;return E?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:T,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:T,alt:k.originalName})},I):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:T,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(fn,{size:14}),t.jsx("span",{children:k.originalName})]},I)})})},[r.attachments,$]),R=s.useMemo(()=>z?m?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:r.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(ps,{remarkPlugins:[bs],components:ws,children:r.content})}):null,[z,m,r.content]);return t.jsxs("div",{className:`chat-message chat-message--${r.role}`,"data-testid":`chat-message-${r.id}`,children:[z&&!l&&t.jsxs("div",{className:"chat-message-avatar",children:[P?t.jsx(Ye,{provider:P,size:"sm"}):t.jsx(Xe,{size:14}),t.jsx("span",{children:o}),x&&D&&t.jsx("span",{className:"chat-model-tag",children:D})]}),z?R:t.jsx("div",{className:"chat-message-content",children:S}),v,xs(r.toolCalls),r.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:r.thinkingOutput})]}),ne,t.jsx("div",{className:"chat-message-time",children:vs(r.createdAt)})]})});function In({projectId:n,addToast:r,experimentalFeatures:m}){const{activeSession:o,sessionsLoading:l,messages:x,messagesLoading:D,isStreaming:P,streamingText:$,streamingThinking:y,streamingToolCalls:ee,selectSession:v,createSession:z,archiveSession:S,deleteSession:ne,sendMessage:R,stopStreaming:A,pendingMessage:f,clearPendingMessage:k,searchQuery:E,setSearchQuery:I,filteredSessions:T}=wn(n,r),[oe,te]=s.useState(!1),[U,b]=s.useState(""),[h,d]=s.useState(null),[i,u]=s.useState(null),[w,M]=s.useState(null),[J,_]=s.useState(!0),[Y,Re]=s.useState(Mn),[V,pe]=s.useState("direct"),[Ae,De]=s.useState(!1),X=m?.chatRooms===!0,N=Sn(n,r),[ie,ue]=s.useState(new Map),[be,Qe]=s.useState([]),[ut,Ze]=s.useState(!0),[ve,xe]=s.useState(!1),[_e,we]=s.useState(""),[ye,Se]=s.useState(0),[ke,g]=s.useState(""),[p,C]=s.useState(!1),[L,Q]=s.useState(0),[G,se]=s.useState(-1),[O,ae]=s.useState(!1),[F,B]=s.useState([]),[K,Z]=s.useState(!1),[ce,me]=s.useState(!1),[Pe,It]=s.useState({}),[et,Oe]=s.useState(!1),[,He]=s.useState(!1),[ys,Ss]=s.useState({top:0,left:0}),W=Qs({projectId:n}),mt=s.useCallback(e=>{if(!e||!W.mentionActive)return;const a=e.getBoundingClientRect();Ss({top:a.top-260,left:a.left+8})},[W.mentionActive]),Lt=s.useRef(null),Ft=s.useRef(null),ht=s.useRef(!1),ft=s.useRef(null),he=s.useRef(null),Ee=s.useRef(null),re=s.useRef(null),zt=s.useRef(null),Ut=s.useRef([]),Be=s.useRef(0),We=s.useRef(new Map),H=Zs()==="mobile";s.useEffect(()=>{try{const e=localStorage.getItem(ds);if(!e)return;const a=Number.parseInt(e,10);if(Number.isNaN(a))return;const c=Math.max(it,Math.min(ct,a));Re(c)}catch{}},[]),s.useEffect(()=>{try{const e=localStorage.getItem(us);if(e==="direct"){pe("direct");return}e==="rooms"&&X&&pe("rooms")}catch{}},[X]),s.useEffect(()=>{if(!X&&V==="rooms"){pe("direct");return}try{localStorage.setItem(us,V)}catch{}},[X,V]);const ks=X&&V==="rooms"&&!!N.activeRoom,{keyboardOverlap:tt,viewportHeight:_t,viewportOffsetTop:Ot,keyboardOpen:Ge}=en({enabled:H&&(!!o||ks)}),Ht=tt>0||Ot>0,Bt=Ge&&Ht?{"--keyboard-overlap":`${tt}px`,"--vv-offset-top":`${Ot}px`,..._t!==null?{"--vv-height":`${_t}px`}:{}}:{},Wt=`chat-thread${Ge&&Ht?" chat-thread--keyboard-active":""}`,le=s.useMemo(()=>{const e=_e.trim().toLowerCase();return(e?be.filter(c=>c.name.toLowerCase().includes(e)):be).slice(0,10)},[be,_e]),$e=s.useMemo(()=>Array.from(ie.values()),[ie]),fe=s.useMemo(()=>!X||V!=="rooms"||!N.activeRoom?null:{roomId:N.activeRoom.id,roomName:N.activeRoom.name,memberIds:new Set(N.activeRoomMembers.map(e=>e.agentId))},[X,V,N.activeRoom,N.activeRoomMembers]),Te=s.useMemo(()=>{const e=$e.filter(j=>tn(j.name,ke));if(!fe)return e;const a=e.filter(j=>fe.memberIds.has(j.id));if(ke.trim().length===0)return a;const c=e.filter(j=>!fe.memberIds.has(j.id));return[...a,...c]},[$e,ke,fe]),gt=s.useMemo(()=>{const e=new Map;for(const a of $e)e.set(a.name.toLowerCase(),a);return e},[$e]);s.useEffect(()=>{Se(0)},[le]),s.useEffect(()=>{Q(0)},[ke,p]),s.useEffect(()=>()=>{he.current!==null&&window.clearTimeout(he.current)},[]);const Gt=s.useCallback(()=>{const e=Ee.current;if(!e)return;const c=e.scrollTop+e.clientHeight>=e.scrollHeight-50;me(!c),ht.current=!c},[]),Ie=s.useCallback(e=>{if(!e.isConnected)return;let a=0,c=0,j=-1;const q=6,de=()=>{if(e.isConnected){if(e.scrollTop=e.scrollHeight,e.scrollHeight===j?c+=1:(c=0,j=e.scrollHeight),a+=1,a>=q||c>=2){me(!1),ht.current=!1;return}window.requestAnimationFrame(de)}};de()},[]),Ve=s.useCallback(()=>{const e=Ee.current;e&&Ie(e)},[Ie]);s.useLayoutEffect(()=>{const e=o?.id??null;if(!e){ft.current=null;return}const a={sessionId:e,loaded:!D,hasMessages:x.length>0},c=ft.current,j=c?.sessionId!==e,q=c?.sessionId===e&&!c.loaded&&a.loaded,de=c?.sessionId===e&&!c.hasMessages&&a.hasMessages;if(!(c===null||j||q||de))return;const ge=Ee.current;ge&&(Ie(ge),ft.current=a)},[o?.id,x.length,D,Ie]),s.useEffect(()=>{ht.current||Ve()},[x,$,y,P,Ve]),s.useEffect(()=>{tt<=0||!Ee.current||Ve()},[tt,Ve]),sn(H&&Ge),s.useEffect(()=>{const e=()=>d(null);if(h)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[h]),s.useEffect(()=>{if(!H||!Ge)return;const e=a=>{a.target?.closest(".chat-messages")||a.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>{document.removeEventListener("touchmove",e)}},[H,Ge]),s.useEffect(()=>{if(!H||!o)return;const e=()=>{const a=re.current;a&&document.activeElement===a&&(a.blur(),window.setTimeout(()=>{a.focus({preventScroll:!0})},0))};return document.addEventListener("visibilitychange",e),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("pageshow",e)}},[H,o]),s.useEffect(()=>{if(!H||!o)return;const e=()=>{const c=Ee.current;c&&Ie(c)},a=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",a),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("pageshow",e)}},[H,o,Ie]),s.useEffect(()=>{let e=!1;const a=n;return dt(void 0,n).then(c=>{if(e||a!==n)return;const j=new Map;for(const q of c)j.set(q.id,q);ue(j)}).catch(()=>{}),()=>{e=!0}},[n]),s.useEffect(()=>{let e=!1;return Ze(!0),nn(n).then(a=>{e||Qe(a)}).catch(()=>{e||Qe([])}).finally(()=>{e||Ze(!1)}),()=>{e=!0}},[n]),s.useEffect(()=>{Ut.current=F},[F]),s.useEffect(()=>()=>{for(const e of Ut.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);for(const e of We.current.values())window.clearTimeout(e);We.current.clear()},[]);const st=s.useCallback(e=>{if(!e||e.length===0)return;const a=[];for(const c of Array.from(e)){if(!Rn.includes(c.type))continue;const j=c.type.startsWith("image/");a.push({file:c,previewUrl:j?URL.createObjectURL(c):""})}a.length>0&&B(c=>[...c,...a])},[]),Ns=s.useCallback(e=>{B(a=>{const c=a[e];return c?.previewUrl&&URL.revokeObjectURL(c.previewUrl),a.filter((j,q)=>q!==e)})},[]),Cs=s.useCallback(e=>{const a=e.clipboardData?.files;if(!a||a.length===0)return;const c=Array.from(a).filter(j=>j.type.startsWith("image/"));c.length!==0&&st(c)},[st]),js=s.useCallback(async e=>{try{await z(e),te(!1),H&&_(!1)}catch{r("Failed to create chat session","error")}},[z,r,H]),Ke=s.useCallback(()=>{b(""),xe(!1),we(""),C(!1),g(""),se(-1),B(e=>{for(const a of e)a.previewUrl&&URL.revokeObjectURL(a.previewUrl);return[]})},[]),pt=s.useCallback(()=>{const e=U.trim(),a=F.map(c=>c.file);if(!(!e&&a.length===0||!o)){if(e==="/clear"||e==="/new"){Ke(),A(),k(),z({agentId:o.agentId,modelProvider:o.modelProvider??void 0,modelId:o.modelId??void 0}).catch(()=>{r("Failed to clear conversation","error")});return}Ke(),R(e,a)}},[U,F,o,Ke,A,k,z,r,R]),bt=s.useCallback(async()=>{const e=U.trim();if(e){if(X&&V==="rooms"){if(!N.activeRoom)return;try{await N.sendRoomMessage(e),Ke()}catch(a){const c=a instanceof Error&&a.message.trim()?a.message:"Failed to send room message";r(c,"error")}return}pt()}},[U,X,V,N,Ke,r,pt]),vt=s.useCallback(e=>{b(a=>{const c=ms(a);if(!c)return a;const j=`/skill:${e.name} `,q=a.slice(0,c.start)+j+a.slice(c.end);return window.requestAnimationFrame(()=>{re.current&&(re.current.style.height="auto",re.current.style.height=`${Math.min(re.current.scrollHeight,120)}px`,re.current.focus())}),q}),xe(!1),we(""),Se(0)},[]),nt=s.useCallback(e=>{const a=re.current;if(!a||G<0)return;const c=a.selectionStart??Be.current,j=a.selectionEnd??c,q=Math.max(c,j),de=Math.min(G,q),ge=`${`@${e.name.replace(/\s+/g,"_")}`} `,Mt=U.slice(0,de)+ge+U.slice(q),Fe=de+ge.length;b(Mt),C(!1),g(""),Q(0),se(-1),window.requestAnimationFrame(()=>{re.current&&(re.current.style.height="auto",re.current.style.height=`${Math.min(re.current.scrollHeight,120)}px`,re.current.focus(),re.current.setSelectionRange(Fe,Fe))})},[G,U]),Vt=s.useCallback(e=>{if(Be.current=e.currentTarget.selectionStart??Be.current,W.mentionActive&&W.files.length>0){if(W.handleKeyDown(e,U),e.key==="Enter"||e.key==="Tab"){const a=W.files[W.selectedIndex];if(a){const c=W.selectFile(a,U);b(c),W.dismissMention(),He(!1)}}return}if(p&&e.key==="ArrowDown"){e.preventDefault(),Te.length>0&&Q(a=>(a+1)%Te.length);return}if(p&&e.key==="ArrowUp"){e.preventDefault(),Te.length>0&&Q(a=>a===0?Te.length-1:a-1);return}if(p&&e.key==="Enter"){e.preventDefault();const a=Te[L]??Te[0];a&&nt(a);return}if(p&&e.key==="Escape"){e.preventDefault(),C(!1),g(""),se(-1);return}if(ve&&e.key==="ArrowDown"){e.preventDefault(),le.length>0&&Se(a=>(a+1)%le.length);return}if(ve&&e.key==="ArrowUp"){e.preventDefault(),le.length>0&&Se(a=>a===0?le.length-1:a-1);return}if(ve&&(e.key==="Enter"||e.key==="Tab")&&le.length>0){e.preventDefault();const a=le[ye]??le[0];a&&vt(a);return}if(ve&&e.key==="Escape"){e.preventDefault(),xe(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),bt())},[p,Te,L,nt,ve,le,ye,vt,bt,W,U]),at=s.useCallback((e,a)=>{const c=An(e,a);if(c){C(!0),g(c.filter),se(c.start);return}C(!1),g(""),se(-1)},[]),Kt=s.useCallback(e=>{const a=e.target,c=a.value,j=a.selectionStart??c.length;Be.current=j,b(c);const q=ms(c);q?(xe(!0),we(q.filter)):(xe(!1),we("")),at(c,j),W.detectMention(c,j),He(W.mentionActive),W.mentionActive&&mt(a),a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},[at]),rt=s.useCallback(e=>{const a=e.currentTarget,c=a.selectionStart??a.value.length;Be.current=c,at(a.value,c),W.detectMention(a.value,c),He(W.mentionActive),W.mentionActive&&mt(a)},[at,W,mt]),qt=s.useCallback(e=>{e.key!=="Escape"&&rt(e)},[rt]),Jt=s.useCallback(()=>{he.current!==null&&window.clearTimeout(he.current),he.current=window.setTimeout(()=>{xe(!1),C(!1),g(""),se(-1),He(!1),W.dismissMention(),he.current=null},120)},[W]),Yt=s.useCallback(()=>{he.current!==null&&(window.clearTimeout(he.current),he.current=null),typeof window<"u"&&window.innerWidth<=768&&window.setTimeout(()=>{(window.scrollY!==0||window.scrollX!==0)&&window.scrollTo(0,0)},0)},[]),Ms=s.useCallback(async e=>{d(null);try{await S(e),r("Conversation archived","success")}catch{r("Failed to archive conversation","error")}},[S,r]),Rs=s.useCallback(async e=>{u(null),d(null);try{await ne(e),r("Conversation deleted","success")}catch{r("Failed to delete conversation","error")}},[ne,r]),qe=s.useCallback(e=>{try{localStorage.setItem(ds,String(e))}catch{}},[]),As=s.useCallback(e=>{if(H)return;e.preventDefault(),e.stopPropagation();const a=e.currentTarget;typeof a.setPointerCapture=="function"&&a.setPointerCapture(e.pointerId);const c=e.clientX,j=Y;let q=j;document.body.style.userSelect="none";const de=ge=>{const Mt=ge.clientX-c,Fe=Math.max(it,Math.min(ct,j+Mt));q=Fe,Re(Fe),qe(Fe)},Le=ge=>{typeof a.releasePointerCapture=="function"&&a.releasePointerCapture(ge.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",de),document.removeEventListener("pointerup",Le),qe(q)};document.addEventListener("pointermove",de),document.addEventListener("pointerup",Le)},[H,qe,Y]),Es=s.useCallback(e=>{if(H||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const a=e.shiftKey?50:10,c=e.key==="ArrowLeft"?-a:a,j=Math.max(it,Math.min(ct,Y+c));Re(j),qe(j)},[H,qe,Y]),Xt=s.useCallback(e=>{v(e),Oe(!1),H&&_(!1)},[v,H]),Ts=s.useCallback(()=>{v(""),_(!0),Oe(!1)},[v]),Ds=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(gn,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>te(!0),children:[t.jsx(ot,{size:16}),"New Chat"]})]}),Ne=ls(o?.modelProvider,o?.modelId),Ce=o?.modelProvider??null,xt=!!(o||P||x.length>0),wt=o?.agentId===Ue?Ne??"Fusion":o?.title||ie.get(o?.agentId??"")?.name||o?.agentId||"Chat",Qt=!!(Ne&&Ne!==wt),Ps=H&&V==="direct"&&!!o,yt=ie.get(o?.agentId??"")?.name||(o?.agentId===Ue?Ne??"Fusion":o?.agentId?.slice(0,30)??"Fusion"),St=!1,kt=o?.agentId===Ue,$s=f.length>50?`${f.slice(0,50)}…`:f,Is=s.useCallback(()=>{ae(e=>!e)},[]);s.useEffect(()=>{if(!et)return;const e=a=>{Ft.current?.contains(a.target)||Oe(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[et]),s.useEffect(()=>{(!H||V!=="direct"||J)&&Oe(!1)},[H,V,J]);const Nt=s.useCallback((e,a)=>{const c=We.current.get(e);c&&window.clearTimeout(c),It(q=>({...q,[e]:a}));const j=window.setTimeout(()=>{It(q=>{const{[e]:de,...Le}=q;return Le}),We.current.delete(e)},2e3);We.current.set(e,j)},[]),Zt=s.useCallback(async(e,a)=>{try{if(!navigator.clipboard?.writeText)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(a),Nt(e,"success")}catch{Nt(e,"error")}},[Nt]),Ls=s.useCallback((e,a=!1)=>a?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:e}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(ps,{remarkPlugins:[bs],components:ws,children:e})}),[]),Ct=o?.agentId===Ue,jt=s.useCallback((e,a,c)=>t.jsx("button",{type:"button",className:`btn-icon chat-message-copy-action${Pe[e]==="success"?" chat-message-copy-action--success":""}${Pe[e]==="error"?" chat-message-copy-action--error":""}`,"data-testid":c??`chat-copy-response-${e}`,"aria-label":Pe[e]==="success"?"Response copied":Pe[e]==="error"?"Copy failed":"Copy response",onClick:()=>{Zt(e,a)},children:Pe[e]==="success"?t.jsx(an,{size:14}):t.jsx(rn,{size:14})}),[Pe,Zt]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${J?"":" chat-sidebar--hidden"}`,style:H?void 0:{width:`${Y}px`},children:[X&&t.jsxs("div",{className:"chat-sidebar-scope-toggle",role:"tablist","data-testid":"chat-sidebar-scope-toggle",children:[t.jsx("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${V==="direct"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":V==="direct","data-testid":"chat-sidebar-scope-direct",onClick:()=>pe("direct"),children:"Direct"}),t.jsx("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${V==="rooms"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":V==="rooms","data-testid":"chat-sidebar-scope-rooms",onClick:()=>pe("rooms"),children:"Rooms"})]}),!X||V==="direct"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"chat-sidebar-search-container",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(on,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:E,onChange:e=>I(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):T.length===0?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):T.map(e=>t.jsxs("div",{className:`chat-session-item${o?.id===e.id?" chat-session-item--active":""}`,onClick:()=>Xt(e.id),onContextMenu:a=>{a.preventDefault(),d({sessionId:e.id,x:a.clientX,y:a.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:a=>{a.stopPropagation(),u(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(At,{size:14})}),t.jsx("div",{className:"chat-session-title",children:e.title||"Untitled"}),t.jsx("div",{className:"chat-session-preview",children:e.lastMessagePreview||"No messages"}),t.jsxs("div",{className:"chat-session-meta",children:[t.jsxs("span",{className:"chat-session-meta-model",children:[e.modelProvider&&t.jsx(Ye,{provider:e.modelProvider,size:"sm"}),t.jsx("span",{children:ie.get(e.agentId)?.name||(e.agentId===Ue?ls(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))})]}),t.jsx("span",{children:e.updatedAt?vs(e.updatedAt):""})]})]},e.id))})]}):t.jsxs("div",{className:"chat-sidebar-rooms","data-testid":"chat-sidebar-rooms",children:[t.jsx("div",{className:"chat-sidebar-rooms-header",children:t.jsxs("button",{type:"button",className:"btn btn-sm btn-primary","data-testid":"chat-create-room-btn",onClick:()=>De(!0),children:[t.jsx(ot,{size:14}),"Create room"]})}),N.rooms.length===0?t.jsx("div",{className:"chat-sidebar-rooms-empty","data-testid":"chat-sidebar-rooms-empty",children:"No rooms yet."}):t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:N.rooms.map(e=>{const a=N.activeRoom?.id===e.id,c=a?N.activeRoomMembers.length:"—";return t.jsxs("div",{role:"button",tabIndex:0,className:`chat-room-item${a?" chat-room-item--active":""}`,"data-testid":`chat-room-item-${e.slug}`,onClick:()=>{N.selectRoom(e.id),H&&_(!1)},onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),N.selectRoom(e.id),H&&_(!1))},children:[t.jsxs("span",{className:"chat-room-item-details",children:[t.jsxs("span",{className:"chat-room-item-name",children:["#",e.name]}),t.jsxs("span",{className:"chat-room-item-meta",children:[c," ",c===1?"member":"members"]})]}),t.jsx("button",{type:"button",className:"btn-icon chat-room-item-delete","data-testid":`chat-room-delete-${e.slug}`,"aria-label":`Delete room ${e.name}`,onClick:j=>{j.stopPropagation(),M(e.id)},children:t.jsx(At,{size:14})})]},e.id)})})]}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>te(!0),"data-testid":"chat-new-btn",children:[t.jsx(ot,{size:14}),"New Chat"]})})]}),!H&&J&&t.jsx("div",{className:"chat-sidebar-resize-handle",role:"separator","aria-orientation":"vertical","aria-valuemin":it,"aria-valuemax":ct,"aria-valuenow":Y,"aria-label":"Resize chat sidebar",tabIndex:0,onPointerDown:As,onKeyDown:Es}),h&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:h.y,left:h.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Ms(h.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(cn,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{d(null),u(h.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(At,{size:14}),"Delete"]})]}),i&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>u(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>u(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Rs(i),children:"Delete"})]})]})}),X&&w&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>M(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Room?"}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:"This action cannot be undone. This room and all its messages will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>M(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>{(async()=>{try{await N.deleteRoom(w),M(null)}catch{r("Failed to delete room","error")}})()},children:"Delete"})]})]})}),X&&V==="rooms"?t.jsxs("div",{className:Wt,style:Bt,children:[N.activeRoom?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-room-thread-header",children:[H&&t.jsx("button",{className:"btn-icon",onClick:()=>{N.selectRoom(null),_(!0)},"data-testid":"chat-back-btn",children:t.jsx(ss,{size:16})}),t.jsxs("div",{className:"chat-thread-header-title",children:["#",N.activeRoom.name]}),t.jsx("div",{className:"chat-room-thread-members",children:N.activeRoomMembers.map(e=>t.jsx(gs,{agent:ie.get(e.agentId)??{id:e.agentId,name:e.agentId.slice(0,30)}},e.agentId))})]}),t.jsxs("div",{className:"chat-messages",ref:Ee,onScroll:Gt,children:[N.messagesLoading?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):N.messages.length===0?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):N.messages.map(e=>{const a=e.senderAgentId?ie.get(e.senderAgentId)?.name??e.senderAgentId.slice(0,30):"You",c={id:e.id,sessionId:e.roomId,role:e.role,content:e.content,thinkingOutput:e.thinkingOutput??void 0,toolCalls:void 0,fallbackInfo:void 0,attachments:e.attachments,createdAt:e.createdAt};return t.jsx(Dt,{message:c,forcePlain:O,agentName:a,hideAssistantIdentity:!1,showAssistantModelTag:!1,activeModelTag:null,activeModelProvider:null,activeSessionId:N.activeRoom?.id??null,mentionAgentsByName:gt,roomContext:fe},e.id)}),t.jsx("div",{ref:Lt})]})]}):t.jsx("div",{className:"chat-room-empty-pane","data-testid":"chat-rooms-empty-pane",children:"Select a room or create one"}),N.activeRoom&&t.jsx("div",{className:"chat-input-area",children:t.jsxs("div",{className:"chat-input-row",children:[t.jsxs("div",{className:"chat-input-wrapper",children:[t.jsx("textarea",{ref:re,className:"chat-input-textarea",placeholder:"Type a message...",value:U,onChange:Kt,onKeyDown:Vt,onKeyUp:qt,onClick:rt,onBlur:Jt,onFocus:Yt,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(ns,{agents:$e,filter:ke,highlightedIndex:L,visible:p,onSelect:nt,position:"below",roomMemberIds:fe?.memberIds,roomName:fe?.roomName})]}),t.jsx("button",{type:"button",className:"chat-input-send",onClick:()=>{bt()},disabled:!U.trim(),"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(as,{size:16})})]})})]}):t.jsxs("div",{className:Wt,style:Bt,children:[(xt||!H)&&t.jsxs("div",{className:"chat-thread-header",children:[H&&xt&&t.jsx("button",{className:"btn-icon",onClick:Ts,"data-testid":"chat-back-btn",children:t.jsx(ss,{size:16})}),t.jsx("div",{className:"chat-thread-header-identity","data-testid":"chat-thread-header-identity",children:Ps?t.jsxs("div",{className:"chat-mobile-session-menu",ref:Ft,children:[t.jsxs("button",{type:"button",className:"btn-icon chat-mobile-session-trigger","data-testid":"chat-mobile-session-trigger","aria-haspopup":"menu","aria-expanded":et,onClick:()=>Oe(e=>!e),children:[Ce?t.jsx(Ye,{provider:Ce,size:"md"}):t.jsx(Xe,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:wt}),Qt&&t.jsx("span",{className:"chat-model-tag",children:Ne}),t.jsx(rs,{"aria-hidden":"true"})]}),et&&t.jsx("div",{className:"chat-mobile-session-dropdown",role:"menu","data-testid":"chat-mobile-session-dropdown",children:T.map(e=>t.jsx("button",{type:"button",role:"menuitem",className:`chat-mobile-session-option${o?.id===e.id?" chat-mobile-session-option--active":""}`,"data-testid":`chat-mobile-session-option-${e.id}`,onClick:()=>Xt(e.id),children:t.jsx("span",{className:"chat-mobile-session-option-title",children:e.title||"Untitled"})},e.id))})]}):t.jsxs(t.Fragment,{children:[Ce?t.jsx(Ye,{provider:Ce,size:"md"}):t.jsx(Xe,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:wt}),Qt&&t.jsx("span",{className:"chat-model-tag",children:Ne})]})}),xt&&t.jsx("button",{type:"button",className:`chat-thread-header-render-toggle${O?" chat-thread-header-render-toggle--plain":""}`,"data-testid":"chat-thread-render-toggle","aria-label":O?"Show all messages as rendered Markdown":"Show all messages as plain text",onClick:Is,children:O?t.jsx(ln,{size:14}):t.jsx(dn,{size:14})}),!H&&t.jsxs("button",{className:"btn btn-sm btn-primary chat-thread-header-new-chat",onClick:()=>te(!0),"data-testid":"chat-thread-new-chat-btn",children:[t.jsx(ot,{size:14}),"New Chat"]})]}),t.jsxs("div",{className:"chat-messages",ref:Ee,onScroll:Gt,children:[P?t.jsxs(t.Fragment,{children:[x.map(e=>t.jsx(Dt,{message:e,forcePlain:O,agentName:yt,hideAssistantIdentity:kt,showAssistantModelTag:St,activeModelTag:Ne,activeModelProvider:Ce,activeSessionId:o?.id??null,mentionAgentsByName:gt,roomContext:null,copyAction:Ct&&e.role==="assistant"?jt(e.id,e.content):void 0},e.id)),t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[!kt&&t.jsxs("div",{className:"chat-message-avatar",children:[Ce?t.jsx(Ye,{provider:Ce,size:"sm"}):t.jsx(Xe,{size:14}),t.jsx("span",{children:yt}),St]}),$?Ls($,O):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:y?"Thinking…":"Connecting…"}),Ct&&$&&jt("__streaming__",$,"chat-copy-response-streaming"),xs(ee),y&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:y})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}):D?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):x.length===0&&!o?Ds():x.length===0&&o?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):t.jsx(t.Fragment,{children:x.map(e=>t.jsx(Dt,{message:e,forcePlain:O,agentName:yt,hideAssistantIdentity:kt,showAssistantModelTag:St,activeModelTag:Ne,activeModelProvider:Ce,activeSessionId:o?.id??null,mentionAgentsByName:gt,roomContext:null,copyAction:Ct&&e.role==="assistant"?jt(e.id,e.content):void 0},e.id))}),t.jsx("div",{ref:Lt})]}),ce&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:Ve,children:[t.jsx(rs,{size:14}),"Latest"]}),o&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:zt,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{st(e.target.files),e.target.value=""}}),ve&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:ut?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):le.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:_e?"No skills found":"No skills available"}):le.map((e,a)=>t.jsxs("button",{type:"button",role:"option","aria-selected":a===ye,className:`chat-skill-menu-item${a===ye?" chat-skill-menu-item--highlighted":""}`,onMouseDown:c=>c.preventDefault(),onMouseEnter:()=>Se(a),onClick:()=>vt(e),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.name}),t.jsx("span",{className:"chat-skill-menu-item-description",title:e.relativePath,children:e.relativePath})]},e.id))}),F.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:F.map((e,a)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${a}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>Ns(a),"data-testid":`chat-attachment-remove-${a}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${a}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":"Attach files",onClick:()=>zt.current?.click(),children:t.jsx(un,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${K?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),Z(!0)},onDragLeave:()=>Z(!1),onDrop:e=>{e.preventDefault(),Z(!1),st(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:re,className:"chat-input-textarea",placeholder:"Type a message...",value:U,onChange:Kt,onKeyDown:Vt,onKeyUp:qt,onClick:rt,onBlur:Jt,onFocus:Yt,onPaste:Cs,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(ns,{agents:$e,filter:ke,highlightedIndex:L,visible:p,onSelect:nt,position:"below",roomMemberIds:fe?.memberIds,roomName:fe?.roomName}),t.jsx(mn,{visible:W.mentionActive&&!p,position:ys,files:W.files,selectedIndex:W.selectedIndex,onSelect:e=>{const a=W.selectFile(e,U);b(a),W.dismissMention(),He(!1),re.current?.focus()},loading:W.loading}),f&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${$s}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:k,children:"×"})]})]}),P?t.jsx("button",{className:"chat-input-stop",onClick:A,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(hn,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{e.pointerType&&e.pointerType!=="mouse"&&e.preventDefault()},onMouseDown:e=>{e.preventDefault()},onClick:()=>{pt()},disabled:!U.trim()&&F.length===0,"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(as,{size:16})})]})]})]}),X&&t.jsx(Nn,{isOpen:Ae,onClose:()=>De(!1),projectId:n,existingRoomNames:N.rooms.map(e=>e.name),onCreate:async e=>{await N.createRoom({name:e.name,memberAgentIds:e.memberAgentIds}),De(!1)}}),oe&&t.jsx(En,{projectId:n,onClose:()=>te(!1),onCreate:js})]})}export{In as ChatView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{bP as De,bQ as de,bR as Ze,bS as ue,s as Ue,bT as ge,bU as we,bV as xe,bW as ye,bX as et,bY as ae,bZ as tt,b_ as rt,b$ as st,c0 as nt,c1 as at,c2 as ie,L as ee,S as it,M as lt,c3 as ct,a as ot,c4 as Me,T as Ae,c5 as dt,U as ut,aQ as vt,aR as mt,a9 as ft,ar as pt,R as ht}from"./index-TFYXEVpn.js";import"./vendor-xterm-DzcZoU0P.js";const ve=500,bt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Pe(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Pe([...e,i])}function G(e){try{return JSON.parse(e)}catch{return null}}function Y(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function gt(e){return e?.previewUrl??null}async function Se(e){return tt(e)}async function Ne(e,i){return rt(e,i)}async function wt(e){return st(e)}async function xt(e){return nt(e)}async function je(e){return at(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>De)=="function"}function X(e){return{config:{id:e.id??"default",name:e.name??"Dev Server",command:e.command??"",cwd:e.cwd??"."},status:e.status,runtime:e.pid?{pid:e.pid,startedAt:e.startedAt??new Date().toISOString(),exitCode:e.exitCode??void 0,previewUrl:e.previewUrl}:void 0,previewUrl:e.previewUrl??e.detectedUrl??e.manualUrl??void 0,logHistory:(e.logs??[]).map(i=>({timestamp:new Date().toISOString(),stream:i.startsWith("[stderr]")?"stderr":"stdout",text:i.replace(/^\[stderr\]\s*/,"")}))}}function yt(e){const[i,o]=r.useState(null),[b,y]=r.useState([]),[w,f]=r.useState([]),[k,U]=r.useState([]),[C,P]=r.useState(!0),[S,u]=r.useState(null),n=r.useRef(0),[d,M]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Y);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await De(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(M(s[0].config.id),R(s[0]))}else{const s=await Se(e);if(n.current!==a)return;const c=X(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),U([]),P(!0),u(null),M(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Se(e).then(N=>[X(N)]),typeof V(()=>ae)=="function"?ae(e):je(e).then(N=>N.map(g=>({name:g.name,command:g.command,cwd:g.cwd,scriptName:g.scriptName,packagePath:g.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const N=c.value;if(y(N),N.length>0){const g=N[0];ce()&&M(g.config.id),R(g)}}else v=B(c.reason);l.status==="fulfilled"&&U(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&P(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?Ze(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=G(l.data);if(v?.lines){const N=v.lines.map(Y);f(Pe(N))}},log:l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:Y(v);f(g=>le(g,N))}},"dev-server:log":l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:Y(v);f(g=>le(g,N))}},"dev-server:output":l=>{if(n.current!==s)return;const v=G(l.data);v?.line&&f(N=>le(N,v.line))},status:l=>{if(n.current!==s)return;const v=G(l.data),N=v?.status;N&&o(g=>g&&{...g,status:N,runtime:v.pid?{...g.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:g.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=G(l.data);if(v?.status){const N=X(v);o(N),y([N])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},bt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>ge)=="function")l=await ge(d,e);else{const v=await Ne({command:a,cwd:s},e);l=X(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await wt(e);s=X(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),j=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>xe)=="function")s=await xe(d,e);else{const c=await xt(e);s=X(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),T=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>ye)=="function")c=await ye(d,a,e);else{const l=await et({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await je(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;U(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e]),p=r.useCallback(async(a,s)=>{if(typeof a!="string"&&!d)try{const v=a,N=await Ne({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),g=X(N);o(g),y([g]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await j()},[j]),z=r.useCallback(async a=>{await T(a)},[T]),F=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=gt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:b,logs:w,detectedCommands:k,previewUrl:H,isLoading:C,error:S,startServer:_,stopServer:D,restartServer:j,setPreviewUrl:T,detectCommands:h,refresh:A,candidates:k,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:F,refreshStatus:O}}const ke=500,Ce=100;function Te(e){return e.length>ke?e.slice(-ke):e}function ze(e){return e==="stderr"?"stderr":"stdout"}function K(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:ze(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function St(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],b=new Set(e.map(y=>y.id));for(const y of i)b.has(y.id)||(b.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),Te(o)}function Nt(e,i){const[o,b]=r.useState([]),[y,w]=r.useState(!1),[f,k]=r.useState(!1),[U,C]=r.useState(!1),[P,S]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),M=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,b([]),w(!1),k(!1),C(!1),S(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++M.current;n.current=!1,w(!0);const z=(x,a)=>{const s=Te(x);b(s),S(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},F=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>St(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:ze(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),b(v=>oe(v,[l])),S(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||M.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||M.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&M.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=K(a);s&&O(s)},log:a=>{const s=K(a);s&&O(s)},history:a=>{const s=K(a);F(s)},"dev-server:history":a=>{const s=K(a);F(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}b(c=>oe(c,s)),S(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const T=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;k(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const F=z.lines.map((O,H)=>Z(O,H+1));b(O=>oe(F,O)),C(z.totalLines>L+F.length),S(z.totalLines)}catch{}finally{k(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{b([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:U,total:P,loadMore:T,clear:h,logs:o,isStreaming:p,clearLogs:h}}const jt="This preview appears to block iframe embedding. Open it in a new tab instead.",kt="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Ct="Preview is taking longer than expected and may block iframe embedding.";function Et(e){return e==="blocked"?jt:e==="error"?kt:null}function Lt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:b=null}=i,y=r.useRef(null),w=r.useRef(null),[f,k]=r.useState("unknown"),[U,C]=r.useState(null),[P]=r.useState(b),S=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(j=>{k(j),C(Et(j))},[]),n=r.useCallback(()=>{k("blocked"),C(Ct)},[]);r.useEffect(()=>{if(S(),!e){k("unknown"),C(null);return}k("unknown"),C(null);let j=!1;return queueMicrotask(()=>{j||(k("loading"),C(null))}),()=>{j=!0,S()}},[S,e]),r.useEffect(()=>{if(f!=="loading"){S();return}const j=setTimeout(()=>{w.current=null,n()},o);return w.current=j,()=>{clearTimeout(j),w.current===j&&(w.current=null)}},[S,f,o,n]);const d=r.useCallback(()=>{const j=y.current;if(!j){u("embedded");return}try{if(j.contentWindow?.location?.href==="about:blank"&&j.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),M=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(S(),!e){k("unknown"),C(null);return}k("unknown"),C(null)},[S]);const R=r.useCallback(()=>{S(),k("unknown"),C(null)},[S]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:U,detectionMethod:P,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:U,handleIframeLoad:d,handleIframeError:M}}const Rt=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(Rt,"")}function _t(e){if(!e)return"";const i=new Date(e);return Number.isNaN(i.getTime())?"":i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}function Dt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ut(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Mt(e,i){if(!i)return e;const o=new RegExp(`(${Dt(i)})`,"ig"),b=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:b.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function At({entries:e,loading:i,loadingMore:o,hasMore:b,total:y,onLoadMore:w,isRunning:f}){const k=r.useRef(null),U=r.useRef(e.length),C=r.useRef(f),[P,S]=r.useState(!1),[u,n]=r.useState(!1),[d,M]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Ut(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),j=D.length,T=r.useCallback(()=>{const p=k.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=U.current,L=e.length>E;f&&(!p||!u&&L)&&T(),C.current=f,U.current=e.length},[e.length,f,u,T]);const h=r.useCallback(()=>{const p=k.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&T()},[e,f,u,i,T]),i&&e.length===0?t.jsx("section",{className:"devserver-log-viewer","data-testid":"devserver-log-viewer",children:t.jsxs("div",{className:"devserver-log-viewer__loading","data-testid":"devserver-log-loading",children:[t.jsx(ee,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${P?" devserver-log-viewer--fullscreen":""}`,"data-testid":"devserver-log-viewer",children:[t.jsxs("header",{className:"devserver-log-viewer__toolbar",children:[t.jsxs("div",{className:"devserver-log-viewer__toolbar-meta",children:[t.jsx("span",{className:"devserver-log-viewer__title",children:"Logs"}),t.jsxs("span",{className:"devserver-log-viewer__count","data-testid":"devserver-log-count",children:[y!==null?`${e.length}/${y}`:`${e.length}`," lines"]})]}),t.jsxs("div",{className:"devserver-log-viewer__toolbar-actions",children:[t.jsxs("label",{className:"devserver-log-viewer__severity",htmlFor:"devserver-log-severity-filter",children:[t.jsx("span",{className:"visually-hidden",children:"Filter logs by severity"}),t.jsxs("select",{id:"devserver-log-severity-filter",className:"select devserver-log-viewer__severity-select",value:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(it,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>M(p.target.value),placeholder:"Search logs","data-testid":"devserver-log-search-input","aria-label":"Search logs"})]}),d.trim().length>0&&t.jsxs("span",{className:"devserver-log-viewer__matches","data-testid":"devserver-log-match-count",children:[j," match",j===1?"":"es"]}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",onClick:()=>S(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":P?"Exit fullscreen logs":"Enter fullscreen logs",children:P?t.jsx(lt,{size:14}):t.jsx(ct,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[b&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:k,className:"devserver-log-viewer__content",onScroll:h,"data-testid":"devserver-log-content",children:[!i&&D.length===0&&t.jsx("p",{className:"devserver-log-viewer__empty","data-testid":"devserver-log-empty",children:e.length===0?"No logs yet. Start the dev server to see output.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=_t(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:Mt(E,d.trim())})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:T,"data-testid":"devserver-log-jump-button",children:[t.jsx(ot,{size:14}),"New logs"]})]})]})}const Pt="devserver-preview-iframe";function Tt({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:b,blockReason:y,onRetry:w,className:f=Pt,embedContext:k}){const U=y??k??null,[C,P]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(P(d=>d+1),o("loading"))},[i,o,e]);const S=r.useCallback(()=>{const d=b.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[b,o]),u=r.useCallback(d=>{d.stopPropagation(),o("error")},[o]),n=r.useCallback(()=>{e&&window.open(e,"_blank","noopener,noreferrer")},[e]);return e?t.jsxs("div",{className:"devserver-preview-iframe-shell",children:[t.jsx("iframe",{src:e,ref:b,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:S,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(Me,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Preview cannot be embedded"}),U&&t.jsx("p",{className:"devserver-preview-blocked-context",children:U})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),U&&t.jsx("p",{className:"devserver-preview-blocked-context",children:U})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function $e(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?$e(e.cwd)===o:!0}function zt(e){return e.cwd==="."?"root":e.cwd}function $t(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Ht({addToast:e,projectId:i}){const{session:o,detectedCommands:b,previewUrl:y,isLoading:w,error:f,startServer:k,stopServer:U,restartServer:C,setPreviewUrl:P,detectCommands:S,refresh:u}=yt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",M=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:j,loadMore:T}=Nt(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,F]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),N=l==="embedded"?h:null,{embedStatus:g,setEmbedStatus:Fe,resetEmbedStatus:I,iframeRef:q,isEmbedded:Oe,isBlocked:te,blockReason:re,retry:fe}=Lt(N),[pe,W]=r.useState(!1),he=r.useRef(g);r.useEffect(()=>{const m=he.current!==g;te&&m&&W(!0),g==="embedded"&&W(!1),he.current=g},[g,te]),r.useEffect(()=>{W(!1)},[h]);const Q=r.useMemo(()=>{if(!x)return null;const m=Re(p);return b.find($=>!($.scriptName!==x||m&&$.cwd!==m||o?.config?.command&&$.command!==o.config.command))??b.find($=>_e($,x,p))??null},[b,o?.config?.command,x,p]);r.useEffect(()=>{typeof S=="function"&&S().catch(m=>{e(Le(m),"error")})},[e,S]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&F(o.config.command);return}if(Q){F(Q.command);return}b.length>0&&F(m=>m.trim().length>0?m:b[0]?.command??"")},[b,Q,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),be=r.useCallback(()=>{W(!1),fe()},[fe]),Be=r.useCallback(()=>{try{const m=q.current;if(m?.contentWindow){m.contentWindow.location.reload(),W(!1),I();return}}catch{}if(!(!h||!q.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),q.current.src=m.toString(),W(!1),I()}catch{q.current.src=h,W(!1),I()}},[h,q,I]),J=r.useCallback(async(m,$,ne)=>{c(m);try{await $(),e(ne,"success")}catch(Ke){e(Le(Ke),"error")}finally{c(null)}},[e]),He=r.useCallback(m=>{a(m.scriptName),L(!1),F(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),Ve=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const $=Re(p)??".",ne=Q?.cwd??$;J("start",()=>k(m,ne),"Dev server started.")},Xe=()=>{J("stop",U,"Dev server stopped.")},qe=()=>{J("restart",C,"Dev server restarted.")},Ge=()=>{const m=O.trim(),$=m.length>0?m:null;J("preview",()=>P($),$?"Preview URL updated.":"Preview URL override cleared.")},Ie=r.useCallback(()=>{f&&u()},[f,u]),Qe=n==="starting"||n==="running"||s!==null,Je=n==="stopped"||s!==null,Ye=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(dt,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${M.className}`,"data-testid":"dev-server-status-badge",children:M.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:We,disabled:Qe,"data-testid":"dev-server-start-button",children:[t.jsx(ut,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Xe,disabled:Je,"data-testid":"dev-server-stop-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:qe,disabled:Ye,"data-testid":"dev-server-restart-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&b.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Ie,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ve,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&b.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&b.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:b.map(m=>{const $=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${$?"dev-server-candidate--selected":""}`,onClick:()=>He(m),"data-testid":`dev-server-candidate-${m.scriptName}-${$e(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:$t(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:zt(m)})]},`${m.cwd}::${m.scriptName}::${m.command}`)})})]}),t.jsxs("div",{className:"dev-server-field-group",children:[t.jsx("label",{htmlFor:"dev-server-command",className:"dev-server-label",children:"Command"}),t.jsx("input",{id:"dev-server-command",className:"input",value:z,onChange:m=>F(m.target.value),placeholder:"pnpm dev","data-testid":"dev-server-command-input",readOnly:n==="running"||n==="starting"})]}),(n==="running"||n==="starting")&&o&&t.jsxs("div",{className:"dev-server-current-command","data-testid":"dev-server-current-command",children:[t.jsx("span",{className:"dev-server-label",children:"Running command"}),t.jsx("code",{children:o.config?.command??z})]}),t.jsxs("div",{className:"dev-server-preview-override",children:[t.jsx("label",{htmlFor:"dev-server-preview-input",className:"dev-server-label",children:"Preview URL Override"}),t.jsx("input",{id:"dev-server-preview-input",className:"input",type:"url",value:O,onChange:m=>H(m.target.value),placeholder:"http://localhost:3000","data-testid":"dev-server-preview-input"}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ge,disabled:s==="preview","data-testid":"dev-server-set-preview",children:"Save"})]}),h&&t.jsxs("p",{className:"dev-server-preview-hint",children:["Auto-detected: ",h]})]}),t.jsx("div",{className:"dev-server-content",children:t.jsxs("section",{className:"dev-server-panel dev-server-logs-panel","data-testid":"dev-server-logs-panel","aria-label":"Dev server logs",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Logs"}),t.jsxs("span",{className:"dev-server-muted",children:[j??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(At,{entries:R,loading:A,loadingMore:_,hasMore:D,total:j,onLoadMore:T,isRunning:d})})]})}),t.jsxs("section",{className:"dev-server-panel devserver-preview-panel","data-testid":"devserver-preview-panel","aria-label":"Dev server preview",children:[t.jsxs("div",{className:"devserver-preview-header",children:[t.jsxs("div",{className:"devserver-preview-title",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(pt,{})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:Be,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(ht,{})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":g,"data-embedded":Oe?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:g==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[g==="error"?t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Me,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:g==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:be,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx(Tt,{url:h,embedStatus:g,onEmbedStatusChange:Fe,iframeRef:q,blockReason:re,onRetry:be})]})]})]})}export{Ht as DevServerView};
|
|
1
|
+
import{r,j as t}from"./vendor-react-K0fH_qHe.js";import{bR as De,bS as de,bT as Ze,bU as ue,s as Ue,bV as be,bW as we,bX as xe,bY as ye,bZ as et,b_ as ae,b$ as tt,c0 as rt,c1 as st,c2 as nt,c3 as at,c4 as ie,L as ee,S as it,M as lt,c5 as ct,a as ot,c6 as Me,T as Ae,c7 as dt,U as ut,aS as vt,aT as mt,a9 as ft,at as pt,R as ht}from"./index-bEwSVl7B.js";import"./vendor-xterm-DzcZoU0P.js";const ve=500,gt=3e3;function B(e){return e instanceof Error?e.message:String(e)}function Te(e){return e.length<=ve?e:e.slice(-ve)}function le(e,i){return Te([...e,i])}function G(e){try{return JSON.parse(e)}catch{return null}}function Q(e){const i=e.text??"";return e.stream==="stderr"?`[stderr] ${i}`:i}function bt(e){return e?.previewUrl??null}async function Se(e){return tt(e)}async function Ne(e,i){return rt(e,i)}async function wt(e){return st(e)}async function xt(e){return nt(e)}async function je(e){return at(e)}function V(e){try{return e()}catch{return null}}function ce(){return typeof V(()=>de)=="function"&&typeof V(()=>De)=="function"}function X(e){return{config:{id:e.id??"default",name:e.name??"Dev Server",command:e.command??"",cwd:e.cwd??"."},status:e.status,runtime:e.pid?{pid:e.pid,startedAt:e.startedAt??new Date().toISOString(),exitCode:e.exitCode??void 0,previewUrl:e.previewUrl}:void 0,previewUrl:e.previewUrl??e.detectedUrl??e.manualUrl??void 0,logHistory:(e.logs??[]).map(i=>({timestamp:new Date().toISOString(),stream:i.startsWith("[stderr]")?"stderr":"stdout",text:i.replace(/^\[stderr\]\s*/,"")}))}}function yt(e){const[i,o]=r.useState(null),[g,y]=r.useState([]),[w,f]=r.useState([]),[k,U]=r.useState([]),[C,T]=r.useState(!0),[S,u]=r.useState(null),n=r.useRef(0),[d,M]=r.useState(null),R=r.useCallback(a=>{if(o(a),a?.logHistory){const s=a.logHistory.slice(-ve).map(Q);f(s)}},[]),A=r.useCallback(async()=>{const a=n.current;try{if(ce())if(d){const s=await De(d,e);if(n.current!==a)return;R(s)}else{const s=await de(e);if(n.current!==a)return;y(s),s.length>0&&(M(s[0].config.id),R(s[0]))}else{const s=await Se(e);if(n.current!==a)return;const c=X(s);y([c]),R(c)}u(null)}catch(s){if(n.current!==a)return;u(B(s))}},[R,e,d]);r.useEffect(()=>{n.current+=1;const a=n.current;o(null),y([]),f([]),U([]),T(!0),u(null),M(null),(async()=>{try{const[c,l]=await Promise.allSettled([ce()?de(e):Se(e).then(N=>[X(N)]),typeof V(()=>ae)=="function"?ae(e):je(e).then(N=>N.map(b=>({name:b.name,command:b.command,cwd:b.cwd,scriptName:b.scriptName,packagePath:b.packagePath})))]);if(n.current!==a)return;let v=null;if(c.status==="fulfilled"){const N=c.value;if(y(N),N.length>0){const b=N[0];ce()&&M(b.config.id),R(b)}}else v=B(c.reason);l.status==="fulfilled"&&U(l.value),v&&u(v)}catch(c){if(n.current!==a)return;u(B(c))}finally{n.current===a&&T(!1)}})()},[R,e]),r.useEffect(()=>{const a=d?Ze(d,e):typeof V(()=>ue)=="function"?ue(e):null;if(!a)return;const s=n.current,c=Ue(a,{events:{history:l=>{if(n.current!==s)return;const v=G(l.data);if(v?.lines){const N=v.lines.map(Q);f(Te(N))}},log:l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:Q(v);f(b=>le(b,N))}},"dev-server:log":l=>{if(n.current!==s)return;const v=G(l.data);if(v){const N=typeof v.line=="string"?v.line:Q(v);f(b=>le(b,N))}},"dev-server:output":l=>{if(n.current!==s)return;const v=G(l.data);v?.line&&f(N=>le(N,v.line))},status:l=>{if(n.current!==s)return;const v=G(l.data),N=v?.status;N&&o(b=>b&&{...b,status:N,runtime:v.pid?{...b.runtime??{startedAt:new Date().toISOString()},pid:v.pid}:b.runtime})},"dev-server:status":l=>{if(n.current!==s)return;const v=G(l.data);if(v?.status){const N=X(v);o(N),y([N])}},stopped:()=>{n.current},failed:()=>{n.current}},onReconnect:()=>{n.current===s&&A()},onError:()=>{n.current===s&&u(l=>l??"Lost log stream connection.")}});return()=>{c()}},[e,A,d]),r.useEffect(()=>{if(i?.status!=="running"&&i?.status!=="starting")return;const a=setInterval(()=>{A()},gt);return()=>{clearInterval(a)}},[A,i?.status]);const _=r.useCallback(async(a,s)=>{n.current+=1;const c=n.current;try{let l;if(d&&typeof V(()=>be)=="function")l=await be(d,e);else{const v=await Ne({command:a,cwd:s},e);l=X(v)}if(n.current!==c)return;o(l),u(null)}catch(l){if(n.current!==c)return;throw u(B(l)),l}},[e,d]),D=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>we)=="function")s=await we(d,e);else{const c=await wt(e);s=X(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),j=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;if(d&&typeof V(()=>xe)=="function")s=await xe(d,e);else{const c=await xt(e);s=X(c)}if(n.current!==a)return;o(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e,d]),P=r.useCallback(async a=>{n.current+=1;const s=n.current;try{let c;if(d&&typeof V(()=>ye)=="function")c=await ye(d,a,e);else{const l=await et({url:a},e);c={url:l.manualUrl??l.previewUrl??l.detectedUrl??null,source:l.manualUrl?"manual":"auto"}}if(n.current!==s)return;o(l=>l?{...l,previewUrl:c.url??void 0}:null),u(null)}catch(c){if(n.current!==s)return;throw u(B(c)),c}},[e,d]),h=r.useCallback(async()=>{n.current+=1;const a=n.current;try{let s;try{s=await ae(e)}catch{s=(await je(e)).map(l=>({name:l.name,command:l.command,cwd:l.cwd,scriptName:l.scriptName,packagePath:l.packagePath}))}if(n.current!==a)return;U(s),u(null)}catch(s){if(n.current!==a)return;throw u(B(s)),s}},[e]),p=r.useCallback(async(a,s)=>{if(typeof a!="string"&&!d)try{const v=a,N=await Ne({command:v.command,cwd:v.cwd,scriptName:v.scriptName,packagePath:v.packagePath??v.cwd},e),b=X(N);o(b),y([b]),u(null);return}catch(v){throw u(B(v)),v}const c=typeof a=="string"?a:a.command,l=typeof a=="string"?s:a.cwd;await _(c,l)},[e,_,d]),E=r.useCallback(async()=>{await D()},[D]),L=r.useCallback(async()=>{await j()},[j]),z=r.useCallback(async a=>{await P(a)},[P]),F=r.useCallback(async()=>{await h()},[h]),O=r.useCallback(async()=>{await A()},[A]),H=bt(i),x=i?{...i,pid:i.runtime?.pid}:null;return{session:i,sessions:g,logs:w,detectedCommands:k,previewUrl:H,isLoading:C,error:S,startServer:_,stopServer:D,restartServer:j,setPreviewUrl:P,detectCommands:h,refresh:A,candidates:k,serverState:x,loading:C,start:p,stop:E,restart:L,setManualUrl:z,detect:F,refreshStatus:O}}const ke=500,Ce=100;function Pe(e){return e.length>ke?e.slice(-ke):e}function ze(e){return e==="stderr"?"stderr":"stdout"}function K(e){try{return JSON.parse(e.data)}catch{return null}}function Z(e,i){return{id:typeof e.id=="number"&&Number.isFinite(e.id)?e.id:i,text:typeof e.text=="string"?e.text:"",stream:ze(e.stream),timestamp:typeof e.timestamp=="string"?e.timestamp:""}}function St(e,i){return{id:i,text:e,stream:"stdout",timestamp:""}}function oe(e,i){if(i.length===0)return e;const o=[...e],g=new Set(e.map(y=>y.id));for(const y of i)g.has(y.id)||(g.add(y.id),o.push(y));return o.sort((y,w)=>y.id-w.id),Pe(o)}function Nt(e,i){const[o,g]=r.useState([]),[y,w]=r.useState(!1),[f,k]=r.useState(!1),[U,C]=r.useState(!1),[T,S]=r.useState(null),u=r.useRef(null),n=r.useRef(!1),d=r.useRef(0),M=r.useRef(0),R=r.useRef(e),A=r.useRef(i),_=r.useRef(0),D=r.useRef(1);(R.current!==e||A.current!==i)&&(R.current=e,A.current=i,d.current++,n.current=!0,_.current=0,D.current=1,g([]),w(!1),k(!1),C(!1),S(null),u.current&&(u.current(),u.current=null)),r.useEffect(()=>{if(!i){u.current&&(u.current(),u.current=null);return}const E=d.current,L=++M.current;n.current=!1,w(!0);const z=(x,a)=>{const s=Pe(x);g(s),S(a),C(a!==null?a>s.length:!1);const c=s.length>0?s[s.length-1].id:0;_.current=c,D.current=c+1},F=x=>{if(n.current||d.current!==E||!x||typeof x!="object")return;const a=x.lines;if(!Array.isArray(a))return;if(a.length>0&&typeof a[0]=="string"){const c=a.filter(l=>typeof l=="string").map((l,v)=>St(l,v+1));z(c,c.length);return}const s=a.filter(c=>!!c&&typeof c=="object").map((c,l)=>Z(c,l+1));z(s,s.length)},O=x=>{if(n.current||d.current!==E)return;const a=typeof x.text=="string"?x.text:typeof x.line=="string"?x.line:null;if(!a)return;const s=D.current,c=typeof x.id=="number"&&Number.isFinite(x.id)?x.id:s,l={id:c,text:a,stream:ze(x.stream),timestamp:typeof x.timestamp=="string"?x.timestamp:""};_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1),g(v=>oe(v,[l])),S(v=>v===null?v:Math.max(v+1,l.id))};async function H(){try{const a=await ie({maxLines:Ce},e);if(n.current||d.current!==E||M.current!==L)return;const s=a.lines.map((c,l)=>Z(c,l+1));z(s,a.totalLines)}catch{if(n.current||d.current!==E||M.current!==L)return;z([],null)}finally{!n.current&&d.current===E&&M.current===L&&w(!1)}const x=ue(e);u.current=Ue(x,{events:{"dev-server:log":a=>{const s=K(a);s&&O(s)},log:a=>{const s=K(a);s&&O(s)},history:a=>{const s=K(a);F(s)},"dev-server:history":a=>{const s=K(a);F(s)}},onReconnect:()=>{n.current||d.current!==E||ie({lastEventId:_.current,maxLines:50},e).then(a=>{if(n.current||d.current!==E)return;const s=a.lines.map((c,l)=>Z(c,D.current+l));if(s.length>0){const c=s[s.length-1].id;_.current=Math.max(_.current,c),D.current=Math.max(D.current,c+1)}g(c=>oe(c,s)),S(a.totalLines)}).catch(()=>{})}})}return H(),()=>{n.current=!0,u.current&&(u.current(),u.current=null)}},[i,e]);const P=r.useCallback(async()=>{if(!i||f)return;const E=d.current,L=o.length;k(!0);try{const z=await ie({maxLines:Ce,offset:L},e);if(n.current||d.current!==E)return;const F=z.lines.map((O,H)=>Z(O,H+1));g(O=>oe(F,O)),C(z.totalLines>L+F.length),S(z.totalLines)}catch{}finally{k(!1)}},[i,o.length,f,e]),h=r.useCallback(()=>{g([])},[]),p=u.current!==null&&!y&&!n.current;return{entries:o,loading:y,loadingMore:f,hasMore:U,total:T,loadMore:P,clear:h,logs:o,isStreaming:p,clearLogs:h}}const jt="This preview appears to block iframe embedding. Open it in a new tab instead.",kt="The preview URL could not be loaded. Verify the server is running and the URL is correct.",Ct="Preview is taking longer than expected and may block iframe embedding.";function Et(e){return e==="blocked"?jt:e==="error"?kt:null}function Lt(e,i={}){const{loadTimeoutMs:o=1e4,detectionMethod:g=null}=i,y=r.useRef(null),w=r.useRef(null),[f,k]=r.useState("unknown"),[U,C]=r.useState(null),[T]=r.useState(g),S=r.useCallback(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),u=r.useCallback(j=>{k(j),C(Et(j))},[]),n=r.useCallback(()=>{k("blocked"),C(Ct)},[]);r.useEffect(()=>{if(S(),!e){k("unknown"),C(null);return}k("unknown"),C(null);let j=!1;return queueMicrotask(()=>{j||(k("loading"),C(null))}),()=>{j=!0,S()}},[S,e]),r.useEffect(()=>{if(f!=="loading"){S();return}const j=setTimeout(()=>{w.current=null,n()},o);return w.current=j,()=>{clearTimeout(j),w.current===j&&(w.current=null)}},[S,f,o,n]);const d=r.useCallback(()=>{const j=y.current;if(!j){u("embedded");return}try{if(j.contentWindow?.location?.href==="about:blank"&&j.src!=="about:blank"){u("blocked");return}}catch{}u("embedded")},[u]),M=r.useCallback(()=>{u("error")},[u]);r.useEffect(()=>{if(S(),!e){k("unknown"),C(null);return}k("unknown"),C(null)},[S]);const R=r.useCallback(()=>{S(),k("unknown"),C(null)},[S]),A=R,_=r.useMemo(()=>f==="embedded",[f]),D=r.useMemo(()=>f==="blocked"||f==="error",[f]);return{embedStatus:f,isEmbedded:_,isBlocked:D,blockReason:U,detectionMethod:T,iframeRef:y,resetEmbedStatus:R,setEmbedStatus:u,retry:A,embedContext:U,handleIframeLoad:d,handleIframeError:M}}const Rt=/\x1b\[[0-9;]*m/g;function me(e){return e.replace(Rt,"")}function _t(e){if(!e)return"";const i=new Date(e);return Number.isNaN(i.getTime())?"":i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}function Dt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ut(e){if(e.stream==="stderr")return"error";const i=me(e.text).toLowerCase();return/\b(warn|warning)\b/.test(i)?"warn":/\b(error|fatal)\b/.test(i)?"error":"info"}function Mt(e,i){if(!i)return e;const o=new RegExp(`(${Dt(i)})`,"ig"),g=e.split(o),y=i.toLowerCase();return t.jsx(t.Fragment,{children:g.map((w,f)=>w.toLowerCase()===y?t.jsx("mark",{children:w},`${w}-${f}`):t.jsx("span",{children:w},`${w}-${f}`))})}function At({entries:e,loading:i,loadingMore:o,hasMore:g,total:y,onLoadMore:w,isRunning:f}){const k=r.useRef(null),U=r.useRef(e.length),C=r.useRef(f),[T,S]=r.useState(!1),[u,n]=r.useState(!1),[d,M]=r.useState(""),[R,A]=r.useState("all"),_=r.useMemo(()=>R==="all"?e:e.filter(p=>Ut(p)===R),[e,R]),D=r.useMemo(()=>{const p=d.trim().toLowerCase();return p?_.filter(E=>me(E.text).toLowerCase().includes(p)):_},[_,d]),j=D.length,P=r.useCallback(()=>{const p=k.current;p&&(p.scrollTop=p.scrollHeight,n(!1))},[]);r.useEffect(()=>{const p=C.current,E=U.current,L=e.length>E;f&&(!p||!u&&L)&&P(),C.current=f,U.current=e.length},[e.length,f,u,P]);const h=r.useCallback(()=>{const p=k.current;if(!p)return;const L=p.scrollTop+p.clientHeight>=p.scrollHeight-50;n(!L)},[]);return r.useEffect(()=>{i||e.length===0||!u&&f&&P()},[e,f,u,i,P]),i&&e.length===0?t.jsx("section",{className:"devserver-log-viewer","data-testid":"devserver-log-viewer",children:t.jsxs("div",{className:"devserver-log-viewer__loading","data-testid":"devserver-log-loading",children:[t.jsx(ee,{size:16,className:"devserver-log-viewer__spinner"}),t.jsx("span",{children:"Loading logs…"})]})}):t.jsxs("section",{className:`devserver-log-viewer${T?" devserver-log-viewer--fullscreen":""}`,"data-testid":"devserver-log-viewer",children:[t.jsxs("header",{className:"devserver-log-viewer__toolbar",children:[t.jsxs("div",{className:"devserver-log-viewer__toolbar-meta",children:[t.jsx("span",{className:"devserver-log-viewer__title",children:"Logs"}),t.jsxs("span",{className:"devserver-log-viewer__count","data-testid":"devserver-log-count",children:[y!==null?`${e.length}/${y}`:`${e.length}`," lines"]})]}),t.jsxs("div",{className:"devserver-log-viewer__toolbar-actions",children:[t.jsxs("label",{className:"devserver-log-viewer__severity",htmlFor:"devserver-log-severity-filter",children:[t.jsx("span",{className:"visually-hidden",children:"Filter logs by severity"}),t.jsxs("select",{id:"devserver-log-severity-filter",className:"select devserver-log-viewer__severity-select",value:R,onChange:p=>A(p.target.value),"data-testid":"devserver-log-severity-filter","aria-label":"Filter logs by severity",children:[t.jsx("option",{value:"all",children:"All severities"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]})]}),t.jsxs("label",{className:"devserver-log-viewer__search",htmlFor:"devserver-log-search",children:[t.jsx("span",{className:"visually-hidden",children:"Search logs"}),t.jsx(it,{size:14}),t.jsx("input",{id:"devserver-log-search",className:"input devserver-log-viewer__search-input",type:"text",value:d,onChange:p=>M(p.target.value),placeholder:"Search logs","data-testid":"devserver-log-search-input","aria-label":"Search logs"})]}),d.trim().length>0&&t.jsxs("span",{className:"devserver-log-viewer__matches","data-testid":"devserver-log-match-count",children:[j," match",j===1?"":"es"]}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",onClick:()=>S(p=>!p),"data-testid":"devserver-log-fullscreen-toggle","aria-label":T?"Exit fullscreen logs":"Enter fullscreen logs",children:T?t.jsx(lt,{size:14}):t.jsx(ct,{size:14})})]})]}),t.jsxs("div",{className:"devserver-log-viewer__body",children:[g&&t.jsx("div",{className:"devserver-log-viewer__load-more","data-testid":"devserver-log-load-more",children:t.jsx("button",{type:"button",className:"btn btn-sm touch-target",onClick:w,disabled:o,"data-testid":"devserver-log-load-more-button",children:o?t.jsxs(t.Fragment,{children:[t.jsx(ee,{size:14,className:"devserver-log-viewer__spinner"}),"Loading older logs…"]}):"Load older logs"})}),t.jsxs("div",{ref:k,className:"devserver-log-viewer__content",onScroll:h,"data-testid":"devserver-log-content",children:[!i&&D.length===0&&t.jsx("p",{className:"devserver-log-viewer__empty","data-testid":"devserver-log-empty",children:e.length===0?"No logs yet. Start the dev server to see output.":_.length===0?"No log lines match the selected severity.":"No log lines match your search."}),D.map(p=>{const E=me(p.text),L=_t(p.timestamp);return t.jsxs("div",{className:"devserver-log-line",children:[L&&t.jsx("span",{className:"devserver-log-timestamp","data-testid":"devserver-log-timestamp",children:L}),p.stream==="stderr"&&t.jsx("span",{className:"devserver-log-stream-badge","data-testid":"devserver-log-stderr-badge",children:"ERR"}),t.jsx("span",{className:"devserver-log-text",children:Mt(E,d.trim())})]},p.id)})]}),u&&f&&t.jsxs("button",{type:"button",className:"btn btn-sm devserver-log-viewer__new-logs-button",onClick:P,"data-testid":"devserver-log-jump-button",children:[t.jsx(ot,{size:14}),"New logs"]})]})]})}const Tt="devserver-preview-iframe";function Pt({url:e,embedStatus:i,onEmbedStatusChange:o,iframeRef:g,blockReason:y,onRetry:w,className:f=Tt,embedContext:k}){const U=y??k??null,[C,T]=r.useState(0);r.useEffect(()=>{!e||i!=="unknown"||(T(d=>d+1),o("loading"))},[i,o,e]);const S=r.useCallback(()=>{const d=g.current;if(!d){o("embedded");return}try{if(d.contentWindow?.location?.href==="about:blank"&&d.src!=="about:blank"){o("blocked");return}}catch{}o("embedded")},[g,o]),u=r.useCallback(d=>{d.stopPropagation(),o("error")},[o]),n=r.useCallback(()=>{e&&window.open(e,"_blank","noopener,noreferrer")},[e]);return e?t.jsxs("div",{className:"devserver-preview-iframe-shell",children:[t.jsx("iframe",{src:e,ref:g,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",className:f,title:"Dev server preview",onLoad:S,onError:u,onErrorCapture:u,"data-testid":"devserver-preview-iframe"},`${e}-${C}`),i==="loading"&&t.jsxs("div",{className:"devserver-preview-overlay","data-testid":"devserver-preview-loading",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading preview..."})]}),i==="blocked"&&t.jsxs("div",{className:"devserver-preview-blocked-panel",role:"alert","data-testid":"devserver-preview-blocked-panel",children:[t.jsx(Me,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Preview cannot be embedded"}),U&&t.jsx("p",{className:"devserver-preview-blocked-context",children:U})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]}),i==="error"&&t.jsxs("div",{className:"devserver-preview-error-panel",role:"alert","data-testid":"devserver-preview-error-panel",children:[t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:"Unable to load preview"}),U&&t.jsx("p",{className:"devserver-preview-blocked-context",children:U})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"You can view the preview in a separate browser tab."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:n,children:"Open in new tab"}),w&&t.jsx("button",{type:"button",className:"btn btn-sm",onClick:w,children:"Retry"})]})]})]}):null}const Ee={stopped:{className:"dev-server-status-badge--stopped",label:"Stopped"},starting:{className:"dev-server-status-badge--starting",label:"Starting..."},running:{className:"dev-server-status-badge--running",label:"Running"},stopping:{className:"dev-server-status-badge--starting",label:"Stopping..."},failed:{className:"dev-server-status-badge--failed",label:"Failed"}};function Le(e){return e instanceof Error?e.message:String(e)}function $e(e){return e==="."?"root":e}function Re(e){return e?e==="root"?".":e:null}function _e(e,i,o){return!i||e.scriptName!==i?!1:o?$e(e.cwd)===o:!0}function zt(e){return e.cwd==="."?"root":e.cwd}function $t(e){return e.length<=60?e:`${e.slice(0,60)}…`}function Ht({addToast:e,projectId:i}){const{session:o,detectedCommands:g,previewUrl:y,isLoading:w,error:f,startServer:k,stopServer:U,restartServer:C,setPreviewUrl:T,detectCommands:S,refresh:u}=yt(i),n=o?.status??"stopped",d=n==="running"||n==="starting",M=Ee[n]??Ee.stopped,{entries:R,loading:A,loadingMore:_,hasMore:D,total:j,loadMore:P}=Nt(i,!!i),h=y,p=o?.config?.cwd??null,[E,L]=r.useState(!0),[z,F]=r.useState(""),[O,H]=r.useState(""),[x,a]=r.useState(null),[s,c]=r.useState(null),[l,v]=r.useState("embedded"),N=l==="embedded"?h:null,{embedStatus:b,setEmbedStatus:Fe,resetEmbedStatus:I,iframeRef:q,isEmbedded:Oe,isBlocked:te,blockReason:re,retry:fe}=Lt(N),[pe,W]=r.useState(!1),he=r.useRef(b);r.useEffect(()=>{const m=he.current!==b;te&&m&&W(!0),b==="embedded"&&W(!1),he.current=b},[b,te]),r.useEffect(()=>{W(!1)},[h]);const J=r.useMemo(()=>{if(!x)return null;const m=Re(p);return g.find($=>!($.scriptName!==x||m&&$.cwd!==m||o?.config?.command&&$.command!==o.config.command))??g.find($=>_e($,x,p))??null},[g,o?.config?.command,x,p]);r.useEffect(()=>{typeof S=="function"&&S().catch(m=>{e(Le(m),"error")})},[e,S]),r.useEffect(()=>{if(x){L(!1);return}L(!0)},[x]),r.useEffect(()=>{if(o?.status==="running"||o?.status==="starting"){o.config?.command?.trim().length>0&&F(o.config.command);return}if(J){F(J.command);return}g.length>0&&F(m=>m.trim().length>0?m:g[0]?.command??"")},[g,J,o?.config?.command,o?.status]),r.useEffect(()=>{H(h??"")},[h]);const se=r.useCallback(()=>{h&&window.open(h,"_blank","noopener,noreferrer")},[h]),ge=r.useCallback(()=>{W(!1),fe()},[fe]),Be=r.useCallback(()=>{try{const m=q.current;if(m?.contentWindow){m.contentWindow.location.reload(),W(!1),I();return}}catch{}if(!(!h||!q.current))try{const m=new URL(h);m.searchParams.set("_t",Date.now().toString()),q.current.src=m.toString(),W(!1),I()}catch{q.current.src=h,W(!1),I()}},[h,q,I]),Y=r.useCallback(async(m,$,ne)=>{c(m);try{await $(),e(ne,"success")}catch(Ke){e(Le(Ke),"error")}finally{c(null)}},[e]),He=r.useCallback(m=>{a(m.scriptName),L(!1),F(m.command),e(`Selected ${m.scriptName} script.`,"success")},[e]),Ve=r.useCallback(()=>{a(null),L(!0),e("Cleared selected dev server script.","success")},[e]),We=()=>{const m=z.trim();if(m.length===0){e("Enter a command before starting the dev server.","warning");return}const $=Re(p)??".",ne=J?.cwd??$;Y("start",()=>k(m,ne),"Dev server started.")},Xe=()=>{Y("stop",U,"Dev server stopped.")},qe=()=>{Y("restart",C,"Dev server restarted.")},Ge=()=>{const m=O.trim(),$=m.length>0?m:null;Y("preview",()=>T($),$?"Preview URL updated.":"Preview URL override cleared.")},Ie=r.useCallback(()=>{f&&u()},[f,u]),Je=n==="starting"||n==="running"||s!==null,Ye=n==="stopped"||s!==null,Qe=n==="stopped"||n==="starting"||s!==null;return t.jsxs("div",{className:"dev-server-view","data-testid":"dev-server-view",children:[t.jsxs("section",{className:"dev-server-header","aria-label":"Dev server controls header",children:[t.jsxs("div",{className:"dev-server-header-title",children:[t.jsx(dt,{size:16}),t.jsx("h2",{children:"Dev Server"}),t.jsx("span",{className:`dev-server-status-badge ${M.className}`,"data-testid":"dev-server-status-badge",children:M.label})]}),t.jsxs("div",{className:"dev-server-header-actions",children:[t.jsxs("button",{type:"button",className:"btn btn-primary btn-sm",onClick:We,disabled:Je,"data-testid":"dev-server-start-button",children:[t.jsx(ut,{size:14}),t.jsx("span",{children:s==="start"?"Starting...":"Start"})]}),t.jsxs("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Xe,disabled:Ye,"data-testid":"dev-server-stop-button",children:[t.jsx(vt,{size:14}),t.jsx("span",{children:s==="stop"?"Stopping...":"Stop"})]}),t.jsxs("button",{type:"button",className:"btn btn-sm",onClick:qe,disabled:Qe,"data-testid":"dev-server-restart-button",children:[t.jsx(mt,{size:14}),t.jsx("span",{children:s==="restart"?"Restarting...":"Restart"})]})]})]}),t.jsxs("section",{className:"dev-server-panel dev-server-config","aria-label":"Dev server configuration",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Configuration"}),w&&t.jsx("span",{className:"dev-server-muted",children:"Loading..."})]}),w&&!o&&g.length===0&&t.jsxs("div",{className:"dev-server-loading-state","data-testid":"dev-server-loading-state",children:[t.jsx(ee,{size:16,className:"dev-server-spin"}),t.jsx("span",{children:"Loading dev server configuration..."})]}),f&&t.jsxs("div",{className:"dev-server-error-box",role:"alert","data-testid":"dev-server-error-box",children:[t.jsx("p",{children:f}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:Ie,children:"Retry"})]}),t.jsxs("div",{className:"dev-server-section",children:[t.jsx("h3",{children:"Script Selection"}),x&&t.jsxs("div",{className:"dev-server-selected","data-testid":"dev-server-selected-summary",children:[t.jsx("span",{className:"dev-server-candidate-name",children:x}),t.jsx("span",{className:"dev-server-candidate-source",children:p??"root"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(!0),"data-testid":"dev-server-change-selection",children:"Change"}),t.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:Ve,"data-testid":"dev-server-clear-selection",children:"Clear"})]}),E&&g.length===0&&t.jsxs("p",{className:"dev-server-empty-state","data-testid":"dev-server-empty-candidates",children:["No dev server scripts detected. Check that your project has a ",t.jsx("code",{children:"package.json"})," with a ",t.jsx("code",{children:"dev"}),", ",t.jsx("code",{children:"start"}),", or similar script."]}),E&&g.length>0&&t.jsx("div",{className:"dev-server-candidates","data-testid":"dev-server-candidates",children:g.map(m=>{const $=_e(m,x,p);return t.jsxs("button",{type:"button",className:`dev-server-candidate ${$?"dev-server-candidate--selected":""}`,onClick:()=>He(m),"data-testid":`dev-server-candidate-${m.scriptName}-${$e(m.cwd)}`,children:[t.jsx("span",{className:"dev-server-candidate-name",children:m.scriptName}),t.jsx("span",{className:"dev-server-candidate-command",children:$t(m.command)}),t.jsx("span",{className:"dev-server-candidate-source",children:zt(m)})]},`${m.cwd}::${m.scriptName}::${m.command}`)})})]}),t.jsxs("div",{className:"dev-server-field-group",children:[t.jsx("label",{htmlFor:"dev-server-command",className:"dev-server-label",children:"Command"}),t.jsx("input",{id:"dev-server-command",className:"input",value:z,onChange:m=>F(m.target.value),placeholder:"pnpm dev","data-testid":"dev-server-command-input",readOnly:n==="running"||n==="starting"})]}),(n==="running"||n==="starting")&&o&&t.jsxs("div",{className:"dev-server-current-command","data-testid":"dev-server-current-command",children:[t.jsx("span",{className:"dev-server-label",children:"Running command"}),t.jsx("code",{children:o.config?.command??z})]}),t.jsxs("div",{className:"dev-server-preview-override",children:[t.jsx("label",{htmlFor:"dev-server-preview-input",className:"dev-server-label",children:"Preview URL Override"}),t.jsx("input",{id:"dev-server-preview-input",className:"input",type:"url",value:O,onChange:m=>H(m.target.value),placeholder:"http://localhost:3000","data-testid":"dev-server-preview-input"}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:Ge,disabled:s==="preview","data-testid":"dev-server-set-preview",children:"Save"})]}),h&&t.jsxs("p",{className:"dev-server-preview-hint",children:["Auto-detected: ",h]})]}),t.jsx("div",{className:"dev-server-content",children:t.jsxs("section",{className:"dev-server-panel dev-server-logs-panel","data-testid":"dev-server-logs-panel","aria-label":"Dev server logs",children:[t.jsxs("div",{className:"dev-server-section-header",children:[t.jsx("h3",{children:"Logs"}),t.jsxs("span",{className:"dev-server-muted",children:[j??R.length," lines"]})]}),t.jsx("div",{className:"dev-server-logs-viewer","data-testid":"dev-server-log-viewer",children:t.jsx(At,{entries:R,loading:A,loadingMore:_,hasMore:D,total:j,onLoadMore:P,isRunning:d})})]})}),t.jsxs("section",{className:"dev-server-panel devserver-preview-panel","data-testid":"devserver-preview-panel","aria-label":"Dev server preview",children:[t.jsxs("div",{className:"devserver-preview-header",children:[t.jsxs("div",{className:"devserver-preview-title",children:[t.jsx(ft,{size:14}),t.jsx("span",{children:"Preview"})]}),t.jsxs("span",{className:"devserver-preview-url-badge devserver-preview-url-badge--auto",title:h??"No preview URL","data-testid":"devserver-preview-url-badge",children:["Auto",h?` · ${h}`:" · Not available"]}),t.jsxs("div",{className:"devserver-preview-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(m=>m==="embedded"?"external":"embedded"),"data-testid":"devserver-preview-mode-toggle",children:l==="embedded"?"External only":"Embedded"}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Open in new tab",onClick:se,disabled:!h,"data-testid":"devserver-preview-open-tab",children:t.jsx(pt,{})}),t.jsx("button",{type:"button",className:"btn btn-sm btn-icon",title:"Refresh preview",onClick:Be,disabled:!h,"data-testid":"devserver-preview-refresh",children:t.jsx(ht,{})})]})]}),t.jsxs("div",{className:"devserver-preview-container","data-embed-status":b,"data-embedded":Oe?"true":"false",children:[!h&&!d&&t.jsx("p",{className:"devserver-preview-empty",children:"Start a dev server to see a live preview here."}),!h&&d&&t.jsx("p",{className:"devserver-preview-empty",children:"No preview URL detected. Start the dev server or set a manual URL to preview your app."}),h&&l==="external"&&t.jsxs("div",{className:"devserver-preview-external-only","data-testid":"devserver-preview-external-only",children:[t.jsx("p",{children:"Embedded preview is disabled. Open your app in a separate browser tab."}),t.jsx("button",{type:"button",className:"btn btn-primary btn-sm touch-target",onClick:se,"data-testid":"devserver-preview-external-open-tab",children:"Open in new tab"})]}),h&&l==="embedded"&&pe&&te&&t.jsxs("div",{className:b==="error"?"devserver-preview-error-panel":"devserver-preview-blocked-panel","data-testid":"devserver-preview-fallback",role:"alert",children:[b==="error"?t.jsx(Ae,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}):t.jsx(Me,{className:"devserver-preview-blocked-icon","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"devserver-preview-blocked-title",children:b==="error"?"Preview failed":"Preview blocked"}),re&&t.jsx("p",{className:"devserver-preview-blocked-context",children:re})]}),t.jsx("p",{className:"devserver-preview-blocked-description",children:"Open the preview in a new tab, or retry embedded mode after checking your server settings."}),t.jsxs("div",{className:"devserver-preview-blocked-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:se,"data-testid":"devserver-preview-fallback-open-tab",children:"Open preview in new tab"}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:ge,"data-testid":"devserver-preview-fallback-retry",children:"Retry embedded preview"})]})]}),h&&l==="embedded"&&!pe&&t.jsx(Pt,{url:h,embedStatus:b,onEmbedStatusChange:Fe,iframeRef:q,blockReason:re,onRetry:ge})]})]})]})}export{Ht as DevServerView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{
|
|
1
|
+
import{r as i,j as r}from"./vendor-react-K0fH_qHe.js";import{et as f,eu as g,dd as b,b as y,ad as P,a8 as H,a9 as C,L as O,aq as v}from"./index-bEwSVl7B.js";import{F as z}from"./folder-open-CHSlllzf.js";function D({value:o,onChange:d,placeholder:m,onInputKeyDown:x,nodeId:l,localNodeId:h}){const[e,n]=i.useState({isOpen:!1,loading:!1,error:null,currentPath:"",parentPath:null,entries:[],showHidden:!1}),a=i.useCallback(async(s,c=!1)=>{n(t=>({...t,loading:!0,error:null}));try{const t=await f(s,c,l,h);n(u=>({...u,loading:!1,currentPath:t.currentPath,parentPath:t.parentPath,entries:t.entries}))}catch(t){n(u=>({...u,loading:!1,error:t instanceof Error?t.message:"Failed to browse directory"}))}},[l,h]),j=i.useCallback(()=>{n(s=>s.isOpen?{...s,isOpen:!1}:{...s,isOpen:!0})},[]);i.useEffect(()=>{e.isOpen&&!e.loading&&e.entries.length===0&&!e.error&&a(o||void 0,e.showHidden)},[e.isOpen,e.loading,e.entries.length,e.error,o,e.showHidden,a,l,h]);const p=i.useCallback(s=>{a(s,e.showHidden)},[a,e.showHidden]),k=i.useCallback(()=>{d(e.currentPath),n(s=>({...s,isOpen:!1}))},[e.currentPath,d]),w=i.useCallback(()=>{n(s=>{const c=!s.showHidden;return{...s,showHidden:c}})},[]);i.useEffect(()=>{e.isOpen&&e.currentPath&&a(e.currentPath,e.showHidden)},[e.showHidden]);const N=e.currentPath?g(e.currentPath):[];return r.jsxs("div",{className:"directory-picker",children:[r.jsxs("div",{className:"directory-picker-input-row",children:[r.jsx("input",{type:"text",className:"input directory-picker-input",value:o,onChange:s=>d(s.target.value),onKeyDown:x,placeholder:m||"/path/to/your/project"}),r.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm directory-picker-browse-btn",onClick:j,"aria-label":e.isOpen?"Close directory browser":"Browse directories",children:[e.isOpen?r.jsx(z,{size:16}):r.jsx(b,{size:16}),r.jsx("span",{children:"Browse"})]})]}),e.isOpen&&r.jsxs("div",{className:"directory-picker-browser",role:"tree","aria-label":"Directory browser",children:[r.jsx("div",{className:"directory-picker-breadcrumbs",children:N.map((s,c)=>r.jsxs("span",{className:"directory-picker-breadcrumb-item",children:[c>0&&r.jsx(y,{size:12,className:"directory-picker-breadcrumb-sep"}),r.jsx("button",{type:"button",className:"directory-picker-breadcrumb",onClick:()=>p(s.path),title:s.path,children:s.label})]},s.path))}),r.jsxs("div",{className:"directory-picker-toolbar",children:[e.parentPath&&r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-up-btn",onClick:()=>p(e.parentPath),"aria-label":"Go to parent directory",title:"Parent directory",children:[r.jsx(P,{size:14}),r.jsx("span",{children:"Up"})]}),r.jsxs("button",{type:"button",className:"btn btn-sm btn-secondary directory-picker-hidden-toggle",onClick:w,"aria-label":e.showHidden?"Hide hidden directories":"Show hidden directories",title:e.showHidden?"Hide hidden":"Show hidden",children:[e.showHidden?r.jsx(H,{size:14}):r.jsx(C,{size:14}),r.jsx("span",{children:e.showHidden?"Hide hidden":"Show hidden"})]})]}),e.loading?r.jsxs("div",{className:"directory-picker-loading",children:[r.jsx(O,{size:20,className:"animate-spin"}),r.jsx("span",{children:"Loading…"})]}):e.error?r.jsxs("div",{className:"directory-picker-error",children:[r.jsx(v,{size:16}),r.jsx("span",{children:e.error})]}):r.jsx("div",{className:"directory-picker-entries",children:e.entries.length===0?r.jsx("div",{className:"directory-picker-empty",children:"No subdirectories"}):e.entries.map(s=>r.jsxs("button",{type:"button",className:"directory-picker-entry",onClick:()=>p(s.path),role:"treeitem",title:s.path,children:[r.jsx(b,{size:16,className:"directory-picker-entry-icon"}),r.jsx("span",{className:"directory-picker-entry-name",children:s.name}),s.hasChildren&&r.jsx(y,{size:14,className:"directory-picker-entry-arrow"})]},s.path))}),r.jsxs("div",{className:"directory-picker-actions",children:[r.jsx("span",{className:"directory-picker-selected-path",title:e.currentPath,children:e.currentPath}),r.jsx("button",{type:"button",className:"btn btn-primary directory-picker-select-btn",onClick:k,children:"Select"})]})]})]})}export{D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a5 as oe,a6 as K,f as le,a7 as ie,F as z,a8 as de,a9 as ue,S as me,X as he,R as pe,aa as fe,ab as W,ac as V,a as X,b as je,ad as xe}from"./index-TFYXEVpn.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?K(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await K(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function _(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:_(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:J,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:Y,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?Y:J,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,G=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:G,value:l,onChange:Z,"aria-label":G}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",_(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
|
|
1
|
+
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{a5 as oe,a6 as K,f as le,a7 as ie,F as z,a8 as de,a9 as ue,S as me,X as he,R as pe,aa as fe,ab as W,ac as V,a as X,b as je,ad as xe}from"./index-bEwSVl7B.js";import"./vendor-xterm-DzcZoU0P.js";function we(n){const{projectId:c,searchQuery:u,includeProjectFiles:a=!0}=n??{},[x,l]=s.useState([]),[h,i]=s.useState([]),[o,p]=s.useState(!0),[k,b]=s.useState(null),f=s.useRef(null),g=s.useRef(!1),m=s.useRef(null),j=s.useCallback(async()=>{f.current&&f.current.abort();const C=new AbortController;f.current=C;const E=!g.current;E&&p(!0),b(null);const L=oe(u?{q:u}:void 0,c),y=a?K(c):Promise.resolve({files:[]}),[v,F]=await Promise.allSettled([L,y]);if(C.signal.aborted)return;let R=null;if(v.status==="fulfilled"?(l(v.value),g.current=!0):R=v.reason instanceof Error?v.reason.message:String(v.reason),F.status==="fulfilled"){const M=F.value.files,P=u?.trim().toLowerCase(),T=P?M.filter(N=>N.name.toLowerCase().includes(P)||N.path.toLowerCase().includes(P)):M;i(T)}b(R),E&&p(!1)},[a,c,u]);return s.useEffect(()=>(m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{j()},300),()=>{m.current&&clearTimeout(m.current)}),[j]),s.useEffect(()=>(j(),()=>{f.current&&f.current.abort()}),[]),{documents:x,projectFiles:h,loading:o,error:k,refresh:j}}function ke(n,c){const[u,a]=s.useState([]),[x,l]=s.useState(!0),[h,i]=s.useState(null),o=s.useRef(null),p=s.useRef(!1),k=c?.showHidden??!1,b=s.useCallback(async f=>{o.current&&o.current.abort();const g=new AbortController;o.current=g;const m=!p.current;m&&l(!0),i(null);try{const j=await K(n,{showHidden:f?.showHidden??k});if(g.signal.aborted)return;a(j.files),p.current=!0}catch(j){if(g.signal.aborted)return;i(j instanceof Error?j.message:String(j))}finally{!g.signal.aborted&&m&&l(!1)}},[n,k]);return s.useEffect(()=>(p.current=!1,b({showHidden:k}),()=>{o.current&&o.current.abort()}),[b,k]),{files:u,loading:x,error:h,refresh:b}}const be=768;function _(n){return n?new Date(n).toLocaleString():""}function ge(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(n>=10*1024?0:1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}function ve(n,c=200){return n.length<=c?n:`${n.substring(0,c)}…`}function Ne({document:n,renderMarkdown:c,onToggleMarkdown:u}){const[a,x]=s.useState(!1),l=ve(n.content),h=n.content.length>200;return e.jsxs("div",{className:"document-card",children:[e.jsxs("div",{className:"document-card-header",children:[e.jsxs("div",{className:"document-card-key",children:[e.jsx(z,{size:14}),e.jsx("span",{className:"document-card-key-text",children:n.key}),e.jsxs("span",{className:"document-card-revision-badge",children:["v",n.revision]})]}),e.jsx("div",{className:"document-card-actions",children:e.jsx("button",{className:"btn btn-sm document-card-expand-btn",onClick:()=>x(i=>!i),title:a?"Collapse":"Expand","aria-label":a?"Collapse content":"Expand content",children:a?e.jsx(xe,{size:14}):e.jsx(X,{size:14})})})]}),e.jsxs("div",{className:"document-card-meta",children:[e.jsx("span",{className:"document-card-author",children:n.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:_(n.updatedAt)})]}),e.jsxs("div",{className:`document-card-content${a?" document-card-content--expanded":""}`,children:[a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"document-card-content-header",children:e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:u,"aria-label":c?"Switch to plain text":"Switch to markdown","aria-pressed":c,title:c?"Switch to plain text":"Switch to markdown",children:c?"Markdown":"Plain"})}),c?e.jsx("div",{className:"document-card-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:n.content})})}):e.jsx("pre",{className:"document-card-content-text",children:n.content})]}):e.jsx("p",{className:"document-card-preview",children:l}),h&&!a&&e.jsx("p",{className:"document-card-preview-truncated",children:"…"})]})]})}function Se({taskId:n,taskTitle:c,documents:u,onOpenTask:a,renderMarkdownStates:x,onToggleMarkdown:l}){const[h,i]=s.useState(!1);return e.jsxs("div",{className:"documents-group",children:[e.jsxs("div",{className:"documents-group-header",children:[e.jsxs("button",{className:"documents-group-toggle-btn",onClick:()=>i(o=>!o),"aria-expanded":h,"aria-label":`${h?"Collapse":"Expand"} documents for task ${n}`,children:[e.jsx("span",{className:"documents-group-toggle","aria-hidden":"true",children:h?e.jsx(X,{size:16}):e.jsx(je,{size:16})}),e.jsx("span",{className:"documents-group-task-id",children:n}),e.jsx("span",{className:"documents-group-task-title",children:c||"Untitled"})]}),e.jsxs("span",{className:"documents-group-count",children:[u.length," doc",u.length!==1?"s":""]}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>a(n),"aria-label":`Open task ${n}: ${c||"Untitled"}`,children:"Open task"})]}),h&&e.jsx("div",{className:"documents-group-content",children:u.map(o=>e.jsx(Ne,{document:o,renderMarkdown:x.get(o.id)??!1,onToggleMarkdown:()=>l(o.id)},o.id))})]})}function ye({projectId:n,addToast:c,onOpenDetail:u}){const[a,x]=s.useState("project"),[l,h]=s.useState(""),[i,o]=s.useState(null),[p,k]=s.useState(!1),[b,f]=s.useState(null),[g,m]=s.useState(!1),[j,C]=s.useState(null),[E,L]=s.useState(!1),y=s.useRef(0),v=s.useRef(!1),[F,R]=s.useState(!1),[M,P]=s.useState(new Map),T=a==="tasks"?l.trim():"",{documents:N,loading:D,error:J,refresh:B}=we({projectId:n,searchQuery:T||void 0,includeProjectFiles:!1}),{files:S,loading:$,error:Y,refresh:O}=ke(n,{showHidden:p});s.useEffect(()=>{const t=()=>{L(window.innerWidth<=be)};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[]),s.useEffect(()=>{v.current=!1,x("project"),o(null),k(!1),f(null),C(null),m(!1),R(!1),P(new Map)},[n]),s.useEffect(()=>{v.current||D||$||(S.length>0?x("project"):N.length>0&&x("tasks"),v.current=!0)},[N.length,D,S.length,$]);const H=s.useMemo(()=>{const t=new Map;for(const r of N){const d=t.get(r.taskId)||[];t.set(r.taskId,[...d,r])}return Array.from(t.entries()).map(([r,d])=>{const w=[...d].sort((re,ce)=>ce.updatedAt.localeCompare(re.updatedAt));return{taskId:r,taskTitle:w[0]?.taskTitle,documents:w,latestUpdated:w[0]?.updatedAt??""}}).sort((r,d)=>d.latestUpdated.localeCompare(r.latestUpdated))},[N]),A=s.useMemo(()=>{const t=l.trim().toLowerCase();return t?S.filter(r=>{const d=r.path.toLowerCase(),w=r.name.toLowerCase();return d.includes(t)||w.includes(t)}):S},[S,l]);s.useEffect(()=>{if(!i)return;S.some(r=>r.path===i.path)||(o(null),f(null),C(null),m(!1))},[S,i]);const Z=s.useCallback(t=>{h(t.target.value)},[]),I=s.useCallback(()=>{h("")},[]),Q=s.useCallback(t=>{x(t)},[]),ee=s.useCallback(async t=>{try{const r=await le(t,n);u(r)}catch{c(`Failed to open task ${t}`,"error")}},[n,u,c]),se=s.useCallback(async t=>{o(t),m(!0),C(null),f(null);const r=y.current+1;y.current=r;try{const d=await ie("project",t.path,n);if(y.current!==r)return;f(d.content)}catch(d){if(y.current!==r)return;const w=d instanceof Error?d.message:`Failed to open ${t.path}`;C(w),c(w,"error")}finally{y.current===r&&m(!1)}},[n,c]),te=s.useCallback(()=>{o(null),f(null),C(null),m(!1)},[]),ne=s.useCallback(t=>{P(r=>{const d=new Map(r),w=d.get(t)??!1;return d.set(t,!w),d})},[]),U=a==="project"?Y:J,ae=s.useCallback(async()=>{if(a==="project"){await O();return}await B()},[a,O,B]),q=a==="project"?A.length:N.length,G=a==="project"?"Search project markdown files…":"Search task documents…";return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsxs("div",{className:"documents-view-title-row",children:[e.jsxs("h2",{className:"documents-view-title",children:[e.jsx(z,{size:20}),"Documents"]}),e.jsxs("span",{className:"documents-view-count",children:[q," result",q!==1?"s":""]})]}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":"Documents sections",children:[e.jsxs("button",{className:`btn documents-tab${a==="project"?" active":""}`,role:"tab","aria-selected":a==="project","aria-label":"Show project markdown files",onClick:()=>Q("project"),children:["Project Files",e.jsx("span",{className:"documents-tab-count",children:S.length})]}),e.jsxs("button",{className:`btn documents-tab${a==="tasks"?" active":""}`,role:"tab","aria-selected":a==="tasks","aria-label":"Show task documents",onClick:()=>Q("tasks"),children:["Task Documents",e.jsx("span",{className:"documents-tab-count",children:H.length})]})]}),a==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>k(t=>!t),"aria-pressed":p,"aria-label":p?"Hide hidden project files":"Show hidden project files",title:p?"Hide hidden files":"Show hidden files",children:[p?e.jsx(de,{size:14}):e.jsx(ue,{size:14}),p?"Hide Hidden":"Show Hidden"]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(me,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:G,value:l,onChange:Z,"aria-label":G}),l&&e.jsx("button",{className:"documents-search-clear",onClick:I,"aria-label":"Clear search",children:e.jsx(he,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:U?e.jsxs("div",{className:"documents-view-error",children:[e.jsxs("p",{children:["Failed to load ",a==="project"?"project files":"task documents",": ",U]}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),"aria-label":"Retry loading documents",children:[e.jsx(pe,{size:16}),"Retry"]})]}):a==="project"?$&&S.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading project markdown files…"})}):A.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No project markdown files match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No Markdown files found in this project."})]})}):e.jsxs("div",{className:`documents-project-layout${E?" documents-project-layout--mobile":""}`,children:[(!E||!i)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":"Project markdown files",children:e.jsx("ul",{className:"markdown-file-list",children:A.map(t=>{const r=i?.path===t.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${r?" markdown-file-item--selected":""}`,onClick:()=>void se(t),"aria-label":`Open ${t.path}`,"aria-current":r?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:t.name}),e.jsx("span",{className:"markdown-file-item-path",children:t.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[ge(t.size)," · ",_(t.mtime)]})]})},t.path)})})}),(!E||i)&&e.jsxs("section",{className:"documents-view-main","aria-label":"Project file content preview",children:[E&&i&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:te,"aria-label":"Back to project files list",children:[e.jsx(fe,{size:14}),"Back to files"]}),i?e.jsxs("div",{className:"documents-content-viewer",children:[e.jsxs("div",{className:"documents-content-header",children:[e.jsx("p",{className:"documents-file-path-header",children:i.path}),e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>R(t=>!t),"aria-label":F?"Switch to plain text":"Switch to markdown","aria-pressed":F,title:F?"Switch to plain text":"Switch to markdown",children:F?"Markdown":"Plain"})]}),g?e.jsx("p",{className:"documents-content-state",children:"Loading file content…"}):j?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:j}):F?e.jsx("div",{className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(W,{remarkPlugins:[V],children:b??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text",children:b??""})]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:"Select a Markdown file to view its content."})})]})]}):D&&N.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:"Loading task documents…"})}):H.length===0?e.jsx("div",{className:"documents-view-empty",children:l.trim()?e.jsxs("p",{children:['No task documents match "',l.trim(),'".']}):e.jsxs(e.Fragment,{children:[e.jsx(z,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:"No task documents yet."}),e.jsx("p",{className:"documents-view-empty-hint",children:"Documents are created in task detail tabs."})]})}):e.jsx("div",{className:"documents-task-list-wrap",children:e.jsx("div",{className:"documents-view-list",children:H.map(({taskId:t,taskTitle:r,documents:d})=>e.jsx(Se,{taskId:t,taskTitle:r,documents:d,onOpenTask:ee,renderMarkdownStates:M,onToggleMarkdown:ne},t))})})})]})}export{ye as DocumentsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{
|
|
1
|
+
import{r as l,j as e}from"./vendor-react-K0fH_qHe.js";import{aG as z,aH as F,aI as O,x as U,ap as _,R as D,at as V}from"./index-bEwSVl7B.js";import"./vendor-xterm-DzcZoU0P.js";const $=300,P=15e3;function T(a){if(!a.trim())return;const t=Number(a);return Number.isFinite(t)?t:void 0}function j(...a){for(const t of a)if(Array.isArray(t))return t;return[]}function v(a){return typeof a=="object"&&a!==null?a:{}}function q(a){const t=v(a),r=v(t.taskSnapshot);return{id:String(t.id??t.evalId??""),runId:String(t.runId??t.batchId??""),taskId:String(t.taskId??r.taskId??""),taskTitle:String(r.title??t.taskTitle??t.title??"Untitled task"),createdAt:String(t.createdAt??t.timestamp??t.updatedAt??new Date(0).toISOString()),overallScore:typeof t.overallScore=="number"?t.overallScore:null,maxScore:typeof t.maxScore=="number"?t.maxScore:null,categoryScores:j(t.categoryScores,v(t.scores).categories)}}function B(a){const t=v(a);return{...q(t),rationale:String(t.rationale??t.summary??""),evidence:j(t.evidence,v(t.details).evidence),followUps:j(t.followUps,v(t.recommendations).followUps)}}function G(a){const t=a?.projectId,[r,g]=l.useState({q:"",runId:"",scoreMin:"",scoreMax:""}),[S,h]=l.useState([]),[I,p]=l.useState([]),[i,f]=l.useState(null),[k,c]=l.useState(null),[E,w]=l.useState(0),[N,b]=l.useState(!0),[R,s]=l.useState(null),n=l.useRef(0),d=l.useCallback(async()=>{const u=++n.current;b(!0),s(null);try{const[o,y]=await Promise.all([z({q:r.q||void 0,runId:r.runId||void 0,scoreMin:T(r.scoreMin),scoreMax:T(r.scoreMax),limit:100,offset:0},t),F(t)]);if(u!==n.current)return;const M=j(o.results,o.evals,o.items).map(q);p(M),w(typeof o.count=="number"?o.count:M.length);const L=j(y.runs,y.items);h(L.map(C=>{const x=v(C),A=v(x.counts);return{id:String(x.id??""),createdAt:String(x.createdAt??""),completedAt:typeof x.completedAt=="string"?x.completedAt:void 0,status:String(x.status??"pending"),evaluatedTaskCount:typeof A.totalTasks=="number"?A.totalTasks:0}})),i&&!M.some(C=>C.id===i)&&(f(null),c(null))}catch(o){if(u!==n.current)return;s(o instanceof Error?o.message:"Failed to load evals")}finally{u===n.current&&b(!1)}},[r.q,r.runId,r.scoreMax,r.scoreMin,t,i]),m=l.useCallback(async u=>{const o=await O(u,t),y=o.result??o;c(B(y))},[t]);return l.useEffect(()=>{const u=window.setTimeout(()=>{d()},$);return()=>window.clearTimeout(u)},[d]),l.useEffect(()=>{if(!i){c(null);return}m(i)},[m,i]),l.useEffect(()=>{const u=window.setInterval(()=>{d(),i&&m(i)},P);return()=>window.clearInterval(u)},[m,d,i]),{loading:N,error:R,results:I,count:E,runs:S,filters:r,setFilters:g,refresh:d,selectedEvalId:i,setSelectedEvalId:f,selectedEval:k}}function W({projectId:a,onOpenSettings:t,onOpenTaskDetail:r}){const{loading:g,error:S,results:h,runs:I,filters:p,setFilters:i,selectedEvalId:f,setSelectedEvalId:k,selectedEval:c,refresh:E}=G({projectId:a}),[w,N]=l.useState(!0);l.useEffect(()=>{let s=!1;return U(a).then(n=>{if(s)return;const d=n.evalSettings?.enabled;N(d??!1)}).catch(()=>{s||N(!1)}),()=>{s=!0}},[a]);const b=h.length>0,R=l.useMemo(()=>h.find(s=>s.id===f)??null,[h,f]);return w?e.jsxs("section",{className:"evals-view","data-testid":"evals-view",children:[e.jsxs("div",{className:"evals-list card",children:[e.jsxs("div",{className:"evals-toolbar",children:[e.jsx("input",{className:"input",placeholder:"Search task or rationale",value:p.q,onChange:s=>i(n=>({...n,q:s.target.value}))}),e.jsxs("select",{className:"select",value:p.runId,onChange:s=>i(n=>({...n,runId:s.target.value})),children:[e.jsx("option",{value:"",children:"All runs"}),I.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}),e.jsx("input",{className:"input",placeholder:"Min score",value:p.scoreMin,onChange:s=>i(n=>({...n,scoreMin:s.target.value}))}),e.jsx("input",{className:"input",placeholder:"Max score",value:p.scoreMax,onChange:s=>i(n=>({...n,scoreMax:s.target.value}))}),e.jsx("button",{className:"btn btn-icon",type:"button",onClick:()=>void E(),"aria-label":"Refresh evals",children:e.jsx(D,{size:16})})]}),g&&e.jsx("p",{className:"evals-state","data-testid":"evals-loading",children:"Loading evals…"}),S&&e.jsx("p",{className:"evals-state evals-state--error",children:S}),!g&&!S&&!b&&e.jsx("p",{className:"evals-state",children:"No evals yet. Scheduled evals review tasks completed since the last run."}),e.jsx("ul",{className:"evals-results","data-testid":"evals-results",children:h.map(s=>e.jsx("li",{children:e.jsxs("button",{className:`evals-result ${s.id===f?"evals-result--active":""}`,type:"button",onClick:()=>k(s.id),children:[e.jsx("span",{className:"evals-result-title",children:s.taskTitle}),e.jsxs("span",{className:"evals-result-meta",children:[s.taskId," · ",s.runId," · ",s.overallScore??"n/a"]})]})},s.id))})]}),e.jsxs("div",{className:"evals-detail card","data-testid":"evals-detail",children:[!c&&e.jsx("p",{className:"evals-state",children:"Select an evaluation to inspect scores, rationale, and evidence."}),c&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"evals-detail-title",children:R?.taskTitle??c.taskTitle}),e.jsxs("p",{className:"evals-result-meta",children:[c.taskId," · ",c.runId]}),e.jsxs("p",{className:"evals-score",children:["Overall score: ",c.overallScore??"n/a"]}),e.jsx("ul",{className:"evals-categories",children:c.categoryScores.map(s=>e.jsxs("li",{children:[s.category,": ",s.finalScore]},s.category))}),e.jsx("p",{className:"evals-rationale",children:c.rationale||"No rationale recorded."}),e.jsxs("div",{children:[e.jsx("h4",{children:"Evidence"}),e.jsx("ul",{className:"evals-links",children:c.evidence.map((s,n)=>{const d=typeof s.metadata?.taskId=="string"?s.metadata.taskId:void 0,m=typeof s.metadata?.url=="string"?s.metadata.url:void 0;return e.jsx("li",{children:d?e.jsx("button",{type:"button",className:"btn",onClick:()=>r?.(d),children:s.ref}):m?e.jsxs("a",{href:m,target:"_blank",rel:"noreferrer",className:"evals-external-link",children:[s.ref,e.jsx(V,{size:14})]}):e.jsx("span",{children:s.ref})},`${s.ref}-${n}`)})})]}),e.jsxs("div",{children:[e.jsx("h4",{children:"Suggested follow-up tasks"}),e.jsxs("ul",{className:"evals-follow-ups",children:[c.followUps.length===0&&e.jsx("li",{children:"None"}),c.followUps.map(s=>e.jsxs("li",{children:[e.jsx("strong",{children:s.title}),e.jsx("p",{children:s.rationale})]},s.suggestionId))]})]})]})]})]}):e.jsxs("section",{className:"evals-view card","data-testid":"evals-disabled",children:[e.jsx("h2",{className:"evals-title",children:"Scheduled evals are disabled"}),e.jsx("p",{className:"evals-empty-copy",children:"Enable Scheduled Evals to review scored tasks, evidence, and follow-up recommendations."}),e.jsxs("button",{className:"btn btn-primary",type:"button",onClick:()=>t?.("scheduled-evals"),children:[e.jsx(_,{size:16}),"Open Scheduled Evals Settings"]})]})}export{W as EvalsView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{
|
|
1
|
+
import{r as s,j as e}from"./vendor-react-K0fH_qHe.js";import{bo as L,ed as F,ee as H,ef as V,eg as U,eh as K}from"./index-bEwSVl7B.js";function fe({value:o,onChange:u,projectId:h,disabled:m=!1,id:g,label:w="Skills"}){const[k,l]=s.useState([]),[c,f]=s.useState(!0);s.useEffect(()=>{let n=!1;return f(!0),L(h).then(p=>{n||l(p)}).catch(()=>{n||l([])}).finally(()=>{n||f(!1)}),()=>{n=!0}},[h]);const j=n=>{o.includes(n)||u([...o,n])},d=n=>{u(o.filter(p=>p!==n))},I=n=>k.find(S=>S.id===n)?.name??n,x=k.filter(n=>!o.includes(n.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[w&&e.jsx("label",{htmlFor:g?`${g}-select`:void 0,className:"skill-multiselect-label",children:w}),o.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:o.map(n=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${n}`,children:[e.jsx("span",{className:"skill-chip-name",children:I(n)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>d(n),disabled:m,"aria-label":`Remove ${I(n)}`,"data-testid":`remove-skill-${n}`,children:"×"})]},n))}),e.jsx("div",{className:"skill-multiselect-add",children:c?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):x.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:o.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:g?`${g}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:n=>{n.target.value&&(j(n.target.value),n.target.value="")},disabled:m,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),x.map(n=>e.jsx("option",{value:n.id,children:n.name},n.id))]})})]})}const B=/(?:^|\/)skills\/([^/]+)\/SKILL\.md$/i;function ye(o){const u=o.trim();if(!u)return o;const h=u.match(B);return h?.[1]?h[1]:u}const Q=`# Soul: Chief Executive Officer
|
|
2
2
|
|
|
3
3
|
I am a strategic leader who connects every decision to business outcomes.
|
|
4
4
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{r,j as e}from"./vendor-react-K0fH_qHe.js";import{c as ye,ae as $e,af as De,ag as Le,ah as Pe,ai as Ue,aj as Te,ak as _e,al as de,am as Ge,h as Oe,j as ue,an as w,X as ge,ao as ne,R as j,ap as qe,m as Be,C as pe,aq as X,ar as me,as as He,I as be,at as Ve,au as we,av as Ye}from"./index-bEwSVl7B.js";import{U as ve}from"./users-CZnxCCCJ.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
|
+
* @license lucide-react v1.7.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Qe=[["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M9 22v-3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3",key:"cabbwy"}],["rect",{x:"4",y:"2",width:"16",height:"20",rx:"2",key:"1uxh74"}]],We=ye("building",Qe);/**
|
|
7
|
+
* @license lucide-react v1.7.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Xe=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],Je=ye("chart-line",Xe),ie=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],fe={quality:"Quality",performance:"Performance",architecture:"Architecture",security:"Security",reliability:"Reliability",ux:"User Experience",testability:"Testability",documentation:"Documentation",dependency:"Dependencies",workflow:"Workflow",other:"Other",features:"Features",competitive_analysis:"Competitive Analysis",research:"Research",trends:"Trends"};function Ke(m){const[l,y]=r.useState([]),[S,$]=r.useState(()=>ie.map(i=>({category:i,label:fe[i]??i,items:[],isLoading:!1,error:null}))),[P,N]=r.useState(!0),[U,v]=r.useState(null),[D,M]=r.useState(null),[T,L]=r.useState(!1),[_,k]=r.useState(null),[G,I]=r.useState(new Map),[J,F]=r.useState(new Map),[O,A]=r.useState(new Map),[q,E]=r.useState(new Map),[R,B]=r.useState(!1),x=r.useCallback(async()=>{N(!0),v(null);try{const i=await $e({status:void 0,limit:1e3},m);y(i.insights.filter(s=>s.status!=="dismissed"));const t=await De(m);t.runs.length>0&&M(t.runs[0])}catch(i){const t=i instanceof Error?i.message:"Failed to fetch insights";v(t)}finally{N(!1)}},[m]),d=r.useCallback(()=>{B(i=>!i)},[]),C=r.useCallback(async(i,t)=>{L(!0),k(null);try{const s=await Le("manual",void 0,m,i,t);M(s),s.status==="completed"?await x():s.status==="failed"&&s.error&&k(s.error)}catch(s){if(s instanceof Pe&&s.status===409&&s.details?.code==="ACTIVE_RUN_CONFLICT"){const g=typeof s.details.activeRunId=="string"?s.details.activeRunId:null;if(g)try{const se=await Ue(g,m);M(se)}catch{}throw k("Insight generation is already running"),s}const h=s instanceof Error?s.message:"Failed to generate insights";throw k(h),s}finally{L(!1)}},[m,x]),u=r.useCallback(async i=>{I(t=>{const s=new Map(t);return s.set(i,{running:!0,error:null}),s});try{await Te(i,m),y(t=>t.filter(s=>s.id!==i)),I(t=>{const s=new Map(t);return s.set(i,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to dismiss insight";throw I(h=>{const g=new Map(h);return g.set(i,{running:!1,error:s}),g}),t}},[m]),H=r.useCallback(async i=>{F(t=>{const s=new Map(t);return s.set(i,{running:!0,error:null}),s});try{const t=await _e(i,m);return await de(i,m),y(s=>s.map(h=>h.id===i?{...h,status:"archived",updatedAt:new Date().toISOString()}:h)),F(s=>{const h=new Map(s);return h.set(i,{running:!1,error:null}),h}),{title:t.suggestedTitle,description:t.suggestedDescription}}catch(t){const s=t instanceof Error?t.message:"Failed to create task";throw F(h=>{const g=new Map(h);return g.set(i,{running:!1,error:s}),g}),t}},[m]);r.useEffect(()=>{const i=new Map;for(const t of ie)i.set(t,[]);for(const t of l){if(!R&&t.status==="archived")continue;const s=i.get(t.category)??[];i.set(t.category,[...s,t])}$(ie.map(t=>({category:t,label:fe[t]??t,items:i.get(t)??[],isLoading:!1,error:null})))},[l,R]);const K=r.useCallback(async i=>{A(t=>{const s=new Map(t);return s.set(i,{running:!0,error:null}),s});try{await de(i,m),y(t=>t.map(s=>s.id===i?{...s,status:"archived",updatedAt:new Date().toISOString()}:s)),A(t=>{const s=new Map(t);return s.set(i,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to archive insight";throw A(h=>{const g=new Map(h);return g.set(i,{running:!1,error:s}),g}),t}},[m]),f=r.useCallback(async i=>{E(t=>{const s=new Map(t);return s.set(i,{running:!0,error:null}),s});try{await Ge(i,m),y(t=>t.map(s=>s.id===i?{...s,status:"confirmed",updatedAt:new Date().toISOString()}:s)),E(t=>{const s=new Map(t);return s.set(i,{running:!1,error:null}),s})}catch(t){const s=t instanceof Error?t.message:"Failed to unarchive insight";throw E(h=>{const g=new Map(h);return g.set(i,{running:!1,error:s}),g}),t}},[m]),V=r.useMemo(()=>S.reduce((i,t)=>i+t.items.length,0),[S]),Z=r.useMemo(()=>0,[]),ee=r.useMemo(()=>l.filter(i=>i.status==="archived").length,[l]);return r.useEffect(()=>{x()},[x]),{sections:S,loading:P,error:U,latestRun:D,isRunInFlight:T,runError:_,refresh:x,runInsights:C,dismiss:u,createTask:H,archive:K,unarchive:f,toggleShowArchived:d,dismissStates:G,createTaskStates:J,archiveStates:O,unarchiveStates:q,totalCount:V,dismissedCount:Z,archivedCount:ee,showArchived:R}}const xe={architecture:We,quality:pe,workflow:we,performance:me,reliability:j,security:X,ux:ve,testability:ne,documentation:Ve,dependency:be,features:He,competitive_analysis:ve,research:Je,trends:me,other:w};function is({projectId:m,addToast:l,onClose:y,onCreateTask:S,models:$}){const{sections:P,loading:N,error:U,latestRun:v,isRunInFlight:D,runError:M,refresh:T,runInsights:L,dismiss:_,createTask:k,archive:G=async()=>{},unarchive:I=async()=>{},toggleShowArchived:J=()=>{},dismissStates:F,createTaskStates:O,archiveStates:A=new Map,unarchiveStates:q=new Map,totalCount:E,archivedCount:R=0,showArchived:B=!1}=Ke(m),[x,d]=r.useState(null),[C,u]=r.useState("info"),[H,K]=r.useState(!1),[f,V]=r.useState(()=>localStorage.getItem("fusion-insight-model")??""),[Z,ee]=r.useState([]),[i,t]=r.useState([]),[s,h]=r.useState([]),[g,se]=r.useState();r.useEffect(()=>{$||Oe().then(a=>{ee(a.models),t(a.favoriteProviders),h(a.favoriteModels),se(a.resolvedPlanningProvider);const n=localStorage.getItem("fusion-insight-model");n&&(a.models.some(o=>`${o.provider}/${o.id}`===n)||(localStorage.removeItem("fusion-insight-model"),V("")))}).catch(()=>{})},[$]);const je=$??Z,Se=r.useMemo(()=>i.length>0?i:g?[g]:[],[i,g]),ke=r.useCallback(async a=>{const c=i.includes(a)?i.filter(o=>o!==a):[a,...i];t(c);try{await ue({favoriteProviders:c,favoriteModels:s})}catch{t(i)}},[i,s]),Ce=r.useCallback(async a=>{const c=s.includes(a)?s.filter(o=>o!==a):[a,...s];h(c);try{await ue({favoriteProviders:i,favoriteModels:c})}catch{h(s)}},[s,i]),Ne=r.useCallback(a=>{V(a),a?localStorage.setItem("fusion-insight-model",a):localStorage.removeItem("fusion-insight-model")},[]),p=r.useMemo(()=>P.filter(a=>a.items.length>0),[P]),[z,te]=r.useState(null);r.useEffect(()=>{if(p.length===0){z!==null&&te(null);return}z&&p.some(n=>n.category===z)||te(p[0].category)},[p,z]);const b=r.useMemo(()=>p.find(a=>a.category===z)??p[0],[p,z]);r.useEffect(()=>{if(x){const a=setTimeout(()=>d(null),5e3);return()=>clearTimeout(a)}},[x]);const ae=r.useCallback(async()=>{try{d("Generating insights..."),u("info");let a,n;if(f){const c=f.indexOf("/");if(c!==-1){const o=f.slice(0,c),Y=f.slice(c+1);o&&Y&&(a=o,n=Y)}}await L(a,n),d("Insight generation started"),u("success"),l("Insight generation started","success")}catch(a){const n=a instanceof Error?a.message:"Failed to start generation";if(n==="Insight generation is already running"){d("Insight generation is already running. Showing the active run."),u("info"),l("Insight generation is already running","info");return}d(n),u("error"),l(n,"error")}},[L,l,f]),Me=r.useCallback(async(a,n)=>{try{d(`Dismissing "${n}"...`),u("info"),await _(a),d(`Dismissed "${n}"`),u("success"),l(`Insight dismissed: ${n}`,"success")}catch(c){const o=c instanceof Error?c.message:"Failed to dismiss insight";d(o),u("error"),l(o,"error")}},[_,l]),Ie=r.useCallback(async(a,n)=>{try{d(`Archiving "${n}"...`),u("info"),await G(a),d(`Archived "${n}"`),u("success"),l(`Insight archived: ${n}`,"success")}catch(c){const o=c instanceof Error?c.message:"Failed to archive insight";d(o),u("error"),l(o,"error")}},[G,l]),Fe=r.useCallback(async(a,n)=>{try{d(`Unarchiving "${n}"...`),u("info"),await I(a),d(`Unarchived "${n}"`),u("success"),l(`Insight unarchived: ${n}`,"success")}catch(c){const o=c instanceof Error?c.message:"Failed to unarchive insight";d(o),u("error"),l(o,"error")}},[I,l]),Ae=r.useCallback(async(a,n)=>{try{if(d(`Creating task from "${n}"...`),u("info"),!S)throw new Error("Task creation is unavailable in this view");const c=await k(a);if(!c)throw new Error("Failed to prepare task payload from insight");await S({insightId:a,title:c.title,description:c.description}),d(`Task created from "${n}"`),u("success"),l(`Task created: ${c.title}`,"success")}catch(c){const o=c instanceof Error?c.message:"Failed to create task";d(o),u("error"),l(o,"error")}},[k,S,l]),Ee=a=>{const n=xe[a.category]??w,c=b?.category===a.category;return e.jsx("li",{children:e.jsxs("button",{type:"button",className:`insights-category-item${c?" insights-category-item--active":""}`,onClick:()=>te(a.category),"aria-current":c?"true":void 0,"data-testid":`insights-category-${a.category}`,children:[e.jsx(n,{size:16,className:"insights-category-icon"}),e.jsx("span",{className:"insights-category-label",children:a.label}),e.jsx("span",{className:"insights-category-count",children:a.items.length})]})},a.category)},Re=()=>{if(!b)return null;const a=xe[b.category]??w;return e.jsxs("section",{className:"insights-section","data-testid":`insights-section-${b.category}`,children:[e.jsx("div",{className:"insights-section-header",children:e.jsxs("div",{className:"insights-section-title",children:[e.jsx(a,{size:20,className:"insights-section-icon"}),e.jsx("h3",{children:b.label}),e.jsx("span",{className:"insights-section-count",children:b.items.length})]})}),e.jsx("div",{className:"insights-section-content",children:e.jsx("ul",{className:"insights-list",children:b.items.map(n=>{const c=F.get(n.id),o=O.get(n.id),Y=A.get(n.id),ze=q.get(n.id),re=c?.running??!1,ce=o?.running??!1,oe=Y?.running??!1,le=ze?.running??!1,he=n.status==="archived",Q=b.items.some(W=>F.get(W.id)?.running||O.get(W.id)?.running||A.get(W.id)?.running||q.get(W.id)?.running);return e.jsxs("li",{className:`insight-item${he?" insight-item--archived":""}`,"data-insight-id":n.id,children:[e.jsxs("div",{className:"insight-item-header",children:[e.jsx("h4",{className:"insight-item-title",children:n.title}),e.jsxs("div",{className:"insight-item-actions",children:[he?e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Fe(n.id,n.title),disabled:le||Q,title:"Unarchive this insight","aria-label":"Unarchive this insight","data-testid":`unarchive-${n.id}`,children:le?e.jsx(j,{size:20,className:"spin"}):e.jsx(Ye,{size:20})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Ae(n.id,n.title),disabled:ce||Q,title:"Create task from this insight","aria-label":"Create task from this insight","data-testid":`create-task-${n.id}`,children:ce?e.jsx(j,{size:20,className:"spin"}):e.jsx(be,{size:20})}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Ie(n.id,n.title),disabled:oe||Q,title:"Archive this insight","aria-label":"Archive this insight","data-testid":`archive-${n.id}`,children:oe?e.jsx(j,{size:20,className:"spin"}):e.jsx(ne,{size:20})})]}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Me(n.id,n.title),disabled:re||Q,title:"Dismiss this insight","aria-label":"Dismiss this insight","data-testid":`dismiss-${n.id}`,children:re?e.jsx(j,{size:20,className:"spin"}):e.jsx(ge,{size:20})})]})]}),n.content&&e.jsx("p",{className:"insight-item-content",children:n.content}),e.jsxs("div",{className:"insight-item-meta",children:[e.jsx("span",{className:`insight-item-status insight-item-status--${n.status}`,children:n.status}),n.createdAt&&e.jsxs("span",{className:"insight-item-date",children:[e.jsx(we,{size:12}),new Date(n.createdAt).toLocaleDateString()]})]})]},n.id)})})})]})};return e.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[e.jsxs("div",{className:"insights-view-header",children:[e.jsxs("div",{className:"insights-view-title",children:[e.jsxs("h2",{children:[e.jsx(w,{size:20}),"Insights"]}),e.jsxs("span",{className:"insights-view-count",children:[E," total"]})]}),e.jsxs("div",{className:"insights-view-actions",children:[y&&e.jsx("button",{className:"btn btn-sm insights-view-close",onClick:y,"aria-label":"Close insights view",title:"Close",children:e.jsx(ge,{size:16})}),R>0&&e.jsxs("button",{className:"btn btn-sm insights-show-archived-toggle",onClick:J,"aria-label":B?"Hide archived insights":"Show archived insights","data-testid":"toggle-archived-insights",children:[e.jsx(ne,{size:14}),B?"Hide Archived":`Show Archived (${R})`]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void T(),disabled:N,"aria-label":"Refresh insights","data-testid":"refresh-insights",children:[e.jsx(j,{size:14,className:N?"spin":""}),"Refresh"]}),e.jsxs("button",{className:"btn btn-sm insights-model-toggle",onClick:()=>K(a=>!a),"aria-label":"Configure insight generation model","aria-expanded":H,"data-testid":"toggle-model-config",title:f?`Model: ${f}`:"Configure model",children:[e.jsx(qe,{size:14}),f&&e.jsx("span",{className:"insights-model-indicator"})]}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void ae(),disabled:D,"aria-label":"Generate new insights","data-testid":"run-insights",children:D?e.jsxs(e.Fragment,{children:[e.jsx(j,{size:14,className:"spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{size:14}),"Generate Insights"]})})]})]}),H&&e.jsxs("div",{className:"insights-model-config","data-testid":"model-config",children:[e.jsx("label",{htmlFor:"insight-model-select",className:"insights-model-label",children:"Model"}),e.jsx(Be,{models:je,value:f,onChange:Ne,placeholder:"Use planning default",label:"Insight generation model",disabled:D,id:"insight-model-select",favoriteProviders:Se,favoriteModels:s,onToggleFavorite:ke,onToggleModelFavorite:Ce})]}),e.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:x&&e.jsxs("div",{className:`insights-status-message insights-status-message--${C}`,role:C==="error"?"alert":void 0,children:[C==="success"&&e.jsx(pe,{size:16}),C==="error"&&e.jsx(X,{size:16}),C==="info"&&e.jsx(w,{size:16}),e.jsx("span",{children:x})]})}),M&&e.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[e.jsx(X,{size:16}),e.jsx("span",{children:M})]}),v&&e.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:e.jsxs("span",{className:"insights-run-status",children:["Latest run: ",v.status,v.status==="completed"&&e.jsxs(e.Fragment,{children:[" — ",v.insightsCreated," created, ",v.insightsUpdated," updated"]}),v.status==="failed"&&v.error&&e.jsxs(e.Fragment,{children:[" — ",v.error]})]})}),N?e.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[e.jsx(j,{size:24,className:"spin"}),e.jsx("p",{children:"Loading insights..."})]}):U?e.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[e.jsx(X,{size:24}),e.jsx("p",{children:U}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void T(),children:"Retry"})]}):E===0?e.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[e.jsx(w,{size:48}),e.jsx("h3",{children:"No insights yet"}),e.jsx("p",{children:"Generate insights to get AI-powered recommendations for your project."}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void ae(),children:[e.jsx(w,{size:14}),"Generate First Insights"]})]}):e.jsxs("div",{className:"insights-body",children:[e.jsx("aside",{className:"insights-sidebar","aria-label":"Insight categories",children:e.jsx("ul",{className:"insights-category-list",children:p.map(Ee)})}),e.jsx("div",{className:"insights-detail",children:Re()})]})]})}export{is as InsightsView};
|