@runfusion/fusion 0.58.0 → 0.60.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 +2 -3
- package/dist/bin.js +16034 -13546
- package/dist/client/.vite/manifest.json +251 -248
- package/dist/client/assets/AgentDetailView-BBjuuYbU.js +18 -0
- package/dist/client/assets/{AgentPermissionPolicyEditor-3x5cc2cp.js → AgentPermissionPolicyEditor-DOdy1ln0.js} +1 -1
- package/dist/client/assets/{AgentsView-B77vHi_7.js → AgentsView-DlyT08sc.js} +4 -4
- package/dist/client/assets/ChatView-CJBnc6rJ.js +6 -0
- package/dist/client/assets/CommandCenter-BhRLZmOH.js +99 -0
- package/dist/client/assets/CommandCenter-DSrIaOro.css +1 -0
- package/dist/client/assets/{DevServerView-BXmkO05R.js → DevServerView-DRpi8Xqz.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-CZ3EXSE5.js → DirectoryPicker-Bw_A-64N.js} +1 -1
- package/dist/client/assets/{DocumentsView-BSWFgTsC.css → DocumentsView-BSC7wh2B.css} +1 -1
- package/dist/client/assets/{DocumentsView-GlAyW64J.js → DocumentsView-w0eDbpbG.js} +2 -2
- package/dist/client/assets/{EvalsView-BLmcsNNf.js → EvalsView-DxQALLwD.js} +1 -1
- package/dist/client/assets/ExperimentalAgentOnboardingModal-BuEWZrjl.js +1 -0
- package/dist/client/assets/{GoalsView-BRfZ4qGe.js → GoalsView-C3MGEtSt.js} +1 -1
- package/dist/client/assets/InsightsView-C0-BkE8_.js +11 -0
- package/dist/client/assets/{MemoryView-ChkuBpUf.js → MemoryView-Dd8uiLHH.js} +2 -2
- package/dist/client/assets/{PiExtensionsManager-DXwQdB7b.js → PiExtensionsManager-DlsEVOjG.js} +1 -1
- package/dist/client/assets/{PluginManager-B8zAjhqf.js → PluginManager-Cf9AOCcC.js} +1 -1
- package/dist/client/assets/{PullRequestView-DL1E1ixh.js → PullRequestView-hm77QtHV.js} +2 -2
- package/dist/client/assets/{ResearchView-BCYCHiyQ.js → ResearchView-BMQEnYH6.js} +1 -1
- package/dist/client/assets/SecretsView-Dc3sWf40.js +1 -0
- package/dist/client/assets/{SessionTerminal-BvK8A98c.css → SessionTerminal-CDTiqrd7.css} +1 -1
- package/dist/client/assets/SessionTerminal-CEv1G-9-.js +2 -0
- package/dist/client/assets/SettingsModal-DFrTDsBm.js +21 -0
- package/dist/client/assets/{SettingsModal-U7ma-5OU.js → SettingsModal-TuphE_CP.js} +1 -1
- package/dist/client/assets/{SetupWizardModal-BCDoA33s.js → SetupWizardModal-CNGogJJp.js} +2 -2
- package/dist/client/assets/{ShadcnColorPicker-EVU2cXpo.js → ShadcnColorPicker-1Z7JIWTE.js} +2 -2
- package/dist/client/assets/{SkillsView-V48VsthB.js → SkillsView-CjPvmnz6.js} +1 -1
- package/dist/client/assets/TodoView-CUD4xw3T.css +1 -0
- package/dist/client/assets/TodoView-DmJPSWOu.js +6 -0
- package/dist/client/assets/WorkflowNodeEditor-BqO2yRXe.js +8 -0
- package/dist/client/assets/{agentSkills-B-QDeW2q.js → agentSkills-BNahUMFe.js} +1 -1
- package/dist/client/assets/app-BzgEwAOr.js +13 -0
- package/dist/client/assets/{app-RIK4I745.js → app-C7eDKtXM.js} +3 -3
- package/dist/client/assets/{app-SHNioZxk.js → app-CL1Ik1qS.js} +3 -3
- package/dist/client/assets/{app-De_pkbYi.js → app-Ckb9wA3K.js} +3 -3
- package/dist/client/assets/{app-cZgmPvs6.js → app-Den3D7oy.js} +3 -3
- package/dist/client/assets/{app--U62_ZWS.js → app-nAsTBQMW.js} +3 -3
- package/dist/client/assets/{architectureDiagram-3BPJPVTR-DvR35aCH.js → architectureDiagram-3BPJPVTR-Bb_ZGdtz.js} +1 -1
- package/dist/client/assets/{blockDiagram-GPEHLZMM-ciQdpSqc.js → blockDiagram-GPEHLZMM-CWfWJnIM.js} +1 -1
- package/dist/client/assets/{c4Diagram-AAUBKEIU-CV0Z6UEL.js → c4Diagram-AAUBKEIU-Dufe_2hy.js} +1 -1
- package/dist/client/assets/channel-BYHFEnHT.js +1 -0
- package/dist/client/assets/{chunk-2J33WTMH-CkAQRX3g.js → chunk-2J33WTMH-BdKWX3Y7.js} +1 -1
- package/dist/client/assets/{chunk-4BX2VUAB-CJXvYVcN.js → chunk-4BX2VUAB-CQ9_zgu6.js} +1 -1
- package/dist/client/assets/{chunk-55IACEB6-DOv0lN1u.js → chunk-55IACEB6-DEFTCISD.js} +1 -1
- package/dist/client/assets/{chunk-727SXJPM-tRsHXz7i.js → chunk-727SXJPM-8RnJp1fx.js} +1 -1
- package/dist/client/assets/{chunk-AQP2D5EJ-CfzOMXn9.js → chunk-AQP2D5EJ-DJg6awe1.js} +1 -1
- package/dist/client/assets/{chunk-FMBD7UC4-BKvUZ2cn.js → chunk-FMBD7UC4-Bw-OImRT.js} +1 -1
- package/dist/client/assets/{chunk-ND2GUHAM-FqiVnW7u.js → chunk-ND2GUHAM-BSx9p0RO.js} +1 -1
- package/dist/client/assets/{chunk-QZHKN3VN-BAJDyCpZ.js → chunk-QZHKN3VN-Dbdv72P6.js} +1 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-BLstvJ1W.js +1 -0
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-BLstvJ1W.js +1 -0
- package/dist/client/assets/{cose-bilkent-S5V4N54A-DYizdcNp.js → cose-bilkent-S5V4N54A-CXtcC6U2.js} +1 -1
- package/dist/client/assets/{dagre-BM42HDAG-BDWwvXJx.js → dagre-BM42HDAG-BO0r4g14.js} +1 -1
- package/dist/client/assets/{dashboard-view-DmfIFCV-.js → dashboard-view-BTnVGch5.js} +1 -1
- package/dist/client/assets/{dashboard-view-BYn_jRw9.js → dashboard-view-CoDeYJbQ.js} +1 -1
- package/dist/client/assets/{diagram-2AECGRRQ-C8ic2E9q.js → diagram-2AECGRRQ-CLmeU2g6.js} +1 -1
- package/dist/client/assets/{diagram-5GNKFQAL-H5IDcv9E.js → diagram-5GNKFQAL-CKyM23Jy.js} +1 -1
- package/dist/client/assets/{diagram-KO2AKTUF-DkczJXd6.js → diagram-KO2AKTUF-ByeVRDs_.js} +1 -1
- package/dist/client/assets/{diagram-LMA3HP47-P1vh7RIU.js → diagram-LMA3HP47-r8qKTJDn.js} +1 -1
- package/dist/client/assets/{diagram-OG6HWLK6-CgeybA5t.js → diagram-OG6HWLK6-D2ugPdm7.js} +1 -1
- package/dist/client/assets/{erDiagram-TEJ5UH35-DSJa4zRQ.js → erDiagram-TEJ5UH35-dLzbDn0G.js} +1 -1
- package/dist/client/assets/{flowDiagram-I6XJVG4X-DG91ZWS9.js → flowDiagram-I6XJVG4X-et7EENd6.js} +1 -1
- package/dist/client/assets/{folder-open-iGyAYoN-.js → folder-open-BVtcjVIK.js} +1 -1
- package/dist/client/assets/{ganttDiagram-6RSMTGT7-dkOQjOK8.js → ganttDiagram-6RSMTGT7-DmiabChP.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-PVQCEYII-GqrJtmDT.js → gitGraphDiagram-PVQCEYII-I1vbhqer.js} +1 -1
- package/dist/client/assets/index-C2HFa2A-.css +1 -0
- package/dist/client/assets/index-inWk2g6R.js +2540 -0
- package/dist/client/assets/{infoDiagram-5YYISTIA-BfFhhqbU.js → infoDiagram-5YYISTIA-xd6L9Gq3.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-DBBV-PIS.js → ishikawaDiagram-YF4QCWOH-fUeEYBvD.js} +1 -1
- package/dist/client/assets/{journeyDiagram-JHISSGLW-xZisXOgZ.js → journeyDiagram-JHISSGLW-B7xjU8Oh.js} +1 -1
- package/dist/client/assets/{kanban-definition-UN3LZRKU-CbOJloOw.js → kanban-definition-UN3LZRKU-CJ8oRjFI.js} +1 -1
- package/dist/client/assets/{mermaid.core-DKBiVV3q.js → mermaid.core-2udKsaH3.js} +4 -4
- package/dist/client/assets/{mindmap-definition-RKZ34NQL-Bf9V63ac.js → mindmap-definition-RKZ34NQL-CVywzN7Q.js} +1 -1
- package/dist/client/assets/{pieDiagram-4H26LBE5-0ukMaTVl.js → pieDiagram-4H26LBE5-8vzzC4Mg.js} +1 -1
- package/dist/client/assets/{puzzle-BvEf9PLH.js → puzzle-D60d3Nv1.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-W4KKPZXB-CwXZAtYI.js → quadrantDiagram-W4KKPZXB-Cxyb4Mom.js} +1 -1
- package/dist/client/assets/{requirementDiagram-4Y6WPE33-DVsu9t-w.js → requirementDiagram-4Y6WPE33-Bs5RaG7r.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-5OEKKPKP-DOJUnv7J.js → sankeyDiagram-5OEKKPKP-Jf7Zq43D.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-3UESZ5HK-B67g0g9m.js → sequenceDiagram-3UESZ5HK-CG0I780H.js} +1 -1
- package/dist/client/assets/{shield-alert-4FPCIFZ2.js → shield-alert-B7JyuWPR.js} +1 -1
- package/dist/client/assets/{stateDiagram-AJRCARHV-CPPa0bHh.js → stateDiagram-AJRCARHV-C1c5XtKG.js} +1 -1
- package/dist/client/assets/{stateDiagram-v2-BHNVJYJU-Dyj14elw.js → stateDiagram-v2-BHNVJYJU-Cv7_pOt_.js} +1 -1
- package/dist/client/assets/{timeline-definition-PNZ67QCA-UVWf2E8M.js → timeline-definition-PNZ67QCA-BWg-lsI0.js} +1 -1
- package/dist/client/assets/{upload-BkgVjwwc.js → upload-Dxv5FPaS.js} +1 -1
- package/dist/client/assets/{users-9nCT4liw.js → users-DvKg3opr.js} +1 -1
- package/dist/client/assets/{vennDiagram-CIIHVFJN-CqGrv1wQ.js → vennDiagram-CIIHVFJN-gFjFmLlv.js} +1 -1
- package/dist/client/assets/{wardley-L42UT6IY-aA0pos_F.js → wardley-L42UT6IY-BaCNX8ou.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-YWT4CUSO-C-O5tD1L.js → wardleyDiagram-YWT4CUSO-BRR6aw0q.js} +1 -1
- package/dist/client/assets/{xychartDiagram-2RQKCTM6-qoIF674C.js → xychartDiagram-2RQKCTM6-D6Gwn1XW.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/extension.js +14159 -12709
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugin-sdk/index.d.ts +27 -1
- package/dist/plugins/fusion-plugin-acp-runtime/bundled.js +4 -7
- package/dist/plugins/fusion-plugin-acp-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
- package/dist/plugins/fusion-plugin-compound-engineering/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-compound-engineering/package.json +1 -1
- package/dist/plugins/fusion-plugin-cursor-runtime/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
- package/dist/plugins/fusion-plugin-droid-runtime/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-grok-runtime/bundled.js +4 -7
- package/dist/plugins/fusion-plugin-grok-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-hermes-runtime/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-linear-import/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-linear-import/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/ShareBlocksPanel.tsx +4 -1
- package/dist/plugins/fusion-plugin-reports/src/dashboard/components/__tests__/ShareBlocksPanel.test.tsx +41 -2
- package/dist/plugins/fusion-plugin-roadmap/bundled.js +0 -5
- package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +1 -1
- package/skill/fusion/SKILL.md +1 -1
- package/skill/fusion/references/engine-tools.md +1 -0
- package/skill/fusion/references/extension-tools.md +10 -0
- package/skill/fusion/references/fusion-capabilities.md +1 -0
- package/dist/client/assets/AgentDetailView-whCXABbu.js +0 -18
- package/dist/client/assets/ChatView-CninsTIm.js +0 -6
- package/dist/client/assets/CommandCenter-B9q-zM9p.css +0 -1
- package/dist/client/assets/CommandCenter-C6LmdUin.js +0 -71
- package/dist/client/assets/ExperimentalAgentOnboardingModal-DvDix9pH.js +0 -1
- package/dist/client/assets/InsightsView-X4RlcgrU.js +0 -11
- package/dist/client/assets/SecretsView-B48BIZKw.js +0 -1
- package/dist/client/assets/SessionTerminal-CUyYlq16.js +0 -2
- package/dist/client/assets/SettingsModal-DbjBoUYD.js +0 -21
- package/dist/client/assets/TodoView-DmpJmxu7.css +0 -1
- package/dist/client/assets/TodoView-MZ9Pfl65.js +0 -6
- package/dist/client/assets/WorkflowNodeEditor-B95Dvf-O.js +0 -8
- package/dist/client/assets/app-SucmTDhV.js +0 -13
- package/dist/client/assets/channel-Y_Uhrtqx.js +0 -1
- package/dist/client/assets/classDiagram-4FO5ZUOK-DhicwSPE.js +0 -1
- package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DhicwSPE.js +0 -1
- package/dist/client/assets/index-Bg8SMXUs.css +0 -1
- package/dist/client/assets/index-DO9Ch72Y.js +0 -2544
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as a,j as e}from"./vendor-react-SZ_qB27O.js";import{c as Me,
|
|
1
|
+
import{r as a,j as e}from"./vendor-react-SZ_qB27O.js";import{c as Me,aC as Je,aD as et,aE as Qt,cY as Yt,cZ as it,aH as Xt,ab as he,c_ as ct,b8 as J,c$ as W,a7 as Re,d0 as rt,s as De,aX as Pe,h as ue,r as me,d1 as lt,d2 as Zt,X as ot,d3 as Jt,d4 as es,d5 as oe,d6 as ts,d7 as tt,cD as ss,cS as as,d8 as ns,d9 as st,V as is,E as cs,o as rs,bW as ls,R as os,a9 as de,A as at}from"./index-inWk2g6R.js";import{u as dt}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -13,4 +13,4 @@ import{r as a,j as e}from"./vendor-react-SZ_qB27O.js";import{c as Me,aA as Je,aB
|
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const ms=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Ie=Me("video",ms);function hs(t){const{projectId:i,searchQuery:n,includeProjectFiles:u=!0}=t??{},o=i?`${Qt.DOCUMENTS_PREFIX}${i}`:null,[s,r]=a.useState(()=>{if(!o)return[];const j=Je(o,{maxAgeMs:et});return Array.isArray(j)?j:[]}),[k,l]=a.useState([]),[p,v]=a.useState(()=>s.length===0),[m,C]=a.useState(null),x=a.useRef(null),w=a.useRef(s.length>0),b=a.useRef(null),d=a.useCallback(async()=>{x.current&&x.current.abort();const j=new AbortController;x.current=j;const y=!w.current;y&&v(!0),C(null);const z=Yt(n?{q:n}:void 0,i),M=u?it(i):Promise.resolve({files:[]}),[E,D]=await Promise.allSettled([z,M]);if(j.signal.aborted)return;let A=null;if(E.status==="fulfilled"){if(r(E.value),o){const U=E.value.length>500?E.value.slice(0,500):E.value;Xt(o,U,{maxBytes:5e5})}w.current=!0}else A=E.reason instanceof Error?E.reason.message:String(E.reason);if(D.status==="fulfilled"){const U=D.value.files,P=n?.trim().toLowerCase(),F=P?U.filter(L=>L.name.toLowerCase().includes(P)||L.path.toLowerCase().includes(P)):U;l(F)}C(A),y&&v(!1)},[o,u,i,n]);return a.useEffect(()=>{if(!o){w.current=!1,r([]),v(!0);return}const j=Je(o,{maxAgeMs:et});Array.isArray(j)?(r(j),w.current=!0,v(!1)):(w.current=!1,r([]),v(!0))},[o]),a.useEffect(()=>(b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{d()},300),()=>{b.current&&clearTimeout(b.current)}),[d]),a.useEffect(()=>(d(),()=>{x.current&&x.current.abort()}),[]),{documents:s,projectFiles:k,loading:p,error:m,refresh:d}}function fs(t,i){const[n,u]=a.useState([]),[o,s]=a.useState(!0),[r,k]=a.useState(null),l=a.useRef(null),p=a.useRef(!1),v=i?.showHidden??!1,m=a.useCallback(async C=>{l.current&&l.current.abort();const x=new AbortController;l.current=x;const w=!p.current;w&&s(!0),k(null);try{const b=await it(t,{showHidden:C?.showHidden??v});if(x.signal.aborted)return;u(b.files),p.current=!0}catch(b){if(x.signal.aborted)return;k(b instanceof Error?b.message:String(b))}finally{!x.signal.aborted&&w&&s(!1)}},[t,v]);return a.useEffect(()=>(p.current=!1,m({showHidden:v}),()=>{l.current&&l.current.abort()}),[m,v]),{files:n,loading:o,error:r,refresh:m}}const nt=["image","doc","pdf","video","audio","other"];function ne(t){return(t.mimeType?.toLowerCase().split(";",1)[0]??"")==="application/pdf"||t.uri?.toLowerCase().endsWith(".pdf")?"pdf":t.type==="image"?"image":t.type==="video"?"video":t.type==="audio"?"audio":t.type==="document"?"doc":"other"}const Le={image:ut,doc:J,pdf:ct,video:Ie,audio:ze,other:he};function Ee(t,i){switch(i){case"image":return t("documents.artifactCategoryImages","Images");case"doc":return t("documents.artifactCategoryDocs","Docs");case"pdf":return t("documents.artifactCategoryPdfs","PDFs");case"video":return t("documents.artifactCategoryVideos","Videos");case"audio":return t("documents.artifactCategoryAudio","Audio");case"other":return t("documents.artifactCategoryOther","Other")}}function fe(t){return t?new Date(t).toLocaleString():""}function $e(t){return t===void 0?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t>=10*1024?0:1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ks({artifacts:t,projectId:i,isMobile:n,addToast:u,onOpenTask:o,onArtifactUpdated:s}){const{t:r}=dt("app"),[k,l]=a.useState("all"),[p,v]=a.useState(null),m=a.useRef(null),C=a.useMemo(()=>{const d=new Map;for(const j of t){const y=ne(j),z=d.get(y);z?z.push(j):d.set(y,[j])}return d},[t]);a.useEffect(()=>{k!=="all"&&!C.has(k)&&l("all")},[k,C]);const x=a.useCallback(d=>{const j=ne(d),y=j==="doc"?"doc":j==="pdf"?"pdf":"media";m.current=document.activeElement instanceof HTMLElement?document.activeElement:null,v({artifact:d,kind:y})},[]),w=a.useCallback(()=>{v(null),m.current?.focus(),m.current=null},[]),b=nt.filter(d=>C.has(d)&&(k==="all"||k===d));return e.jsxs("div",{className:"artifacts-gallery",children:[C.size>1&&e.jsxs("div",{className:"artifacts-gallery-filter",role:"group","aria-label":r("documents.artifactTypeFilterLabel","Filter artifacts by category"),children:[e.jsxs("button",{className:`btn btn-sm artifacts-gallery-chip${k==="all"?" active":""}`,"aria-pressed":k==="all",onClick:()=>l("all"),children:[r("documents.artifactFilterAll","All"),e.jsx("span",{className:"artifacts-gallery-chip-count",children:t.length})]}),nt.filter(d=>C.has(d)).map(d=>{const j=Le[d];return e.jsxs("button",{className:`btn btn-sm artifacts-gallery-chip${k===d?" active":""}`,"aria-pressed":k===d,onClick:()=>l(d),children:[e.jsx(j,{size:14,"aria-hidden":"true"}),Ee(r,d),e.jsx("span",{className:"artifacts-gallery-chip-count",children:C.get(d)?.length})]},d)})]}),b.map(d=>{const j=C.get(d)??[],y=Le[d];return e.jsxs("section",{className:"artifacts-gallery-section","aria-label":Ee(r,d),children:[k==="all"&&C.size>1&&e.jsxs("header",{className:"artifacts-gallery-section-header",children:[e.jsx(y,{size:16,"aria-hidden":"true"}),e.jsx("h3",{children:Ee(r,d)}),e.jsx("span",{className:"artifacts-gallery-section-count",children:j.length})]}),e.jsx(ps,{category:d,items:j,projectId:i,isMobile:n,t:r,onOpen:x,onOpenTask:o})]},d)}),p&&p.kind==="media"&&e.jsx(vs,{artifact:p.artifact,projectId:i,t:r,onClose:w,onOpenTask:o}),p&&p.kind==="pdf"&&e.jsx(ys,{artifact:p.artifact,projectId:i,t:r,onClose:w,onOpenTask:o}),p&&p.kind==="doc"&&e.jsx(Cs,{artifact:p.artifact,projectId:i,t:r,addToast:u,onClose:w,onOpenTask:o,onArtifactUpdated:s})]})}function ps({category:t,items:i,projectId:n,isMobile:u,t:o,onOpen:s,onOpenTask:r}){if(t==="audio")return e.jsx("div",{className:"artifacts-gallery-rows",children:i.map(l=>e.jsx(ws,{artifact:l,projectId:n,t:o,onOpenTask:r},l.id))});if(t==="other")return e.jsx("div",{className:"artifacts-gallery-rows",children:i.map(l=>e.jsx(gs,{artifact:l,projectId:n,t:o,onOpenTask:r},l.id))});const k=t==="image"||t==="video"?"artifacts-gallery-grid artifacts-gallery-grid--visual":"artifacts-gallery-grid artifacts-gallery-grid--cards";return e.jsx("div",{className:`${k}${u?" artifacts-gallery-grid--mobile":""}`,children:i.map(l=>t==="image"||t==="video"?e.jsx(xs,{artifact:l,category:t,projectId:n,t:o,onOpen:s},l.id):e.jsx(js,{artifact:l,category:t,t:o,onOpen:s,onOpenTask:r},l.id))})}function xs({artifact:t,category:i,projectId:n,t:u,onOpen:o}){const s=t.title||u("documents.untitledArtifact","Untitled artifact"),r=W(t.id,n),k=l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),o(t))};return e.jsx("article",{className:"artifacts-gallery-tile","aria-label":u("documents.artifactCardLabel","Artifact {{title}}",{title:s}),children:e.jsxs("div",{className:"artifacts-gallery-tile-media",role:"button",tabIndex:0,"aria-label":u("documents.expandArtifact","Expand {{title}}",{title:s}),onClick:()=>o(t),onKeyDown:k,children:[i==="image"?e.jsx("img",{src:r,alt:s,loading:"lazy"}):e.jsx("video",{src:r,muted:!0,preload:"metadata","aria-label":u("documents.artifactVideoLabel","Video artifact: {{title}}",{title:s})}),i==="video"&&e.jsx("span",{className:"artifacts-gallery-tile-play","aria-hidden":"true",children:e.jsx(Ie,{size:22})}),e.jsxs("div",{className:"artifacts-gallery-tile-overlay",children:[e.jsx("span",{className:"artifacts-gallery-tile-title",children:s}),t.taskId&&e.jsx("span",{className:"artifacts-gallery-tile-task",children:t.taskId})]})]})})}function js({artifact:t,category:i,t:n,onOpen:u,onOpenTask:o}){const s=t.title||n("documents.untitledArtifact","Untitled artifact"),r=Le[i],k=l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),u(t))};return e.jsxs("article",{className:"artifacts-gallery-card","aria-label":n("documents.artifactCardLabel","Artifact {{title}}",{title:s}),children:[e.jsxs("div",{className:"artifacts-gallery-card-main",role:"button",tabIndex:0,"aria-label":n("documents.openArtifactViewer","Open {{title}}",{title:s}),onClick:()=>u(t),onKeyDown:k,children:[e.jsx("div",{className:`artifacts-gallery-card-icon artifacts-gallery-card-icon--${i}`,children:e.jsx(r,{size:22,"aria-hidden":"true"})}),e.jsxs("div",{className:"artifacts-gallery-card-body",children:[e.jsx("h4",{className:"artifacts-gallery-card-title",children:s}),t.description&&e.jsx("p",{className:"artifacts-gallery-card-description",children:t.description}),e.jsxs("div",{className:"artifacts-gallery-card-meta",children:[e.jsx("span",{children:t.authorId}),e.jsx("span",{children:"·"}),e.jsx("span",{children:fe(t.createdAt)}),t.sizeBytes!==void 0&&e.jsxs("span",{children:["· ",$e(t.sizeBytes)]})]})]})]}),t.taskId&&e.jsx("button",{className:"artifacts-gallery-task-link artifacts-gallery-card-task",onClick:()=>o(t.taskId),"aria-label":n("documents.openTaskAria","Open task {{taskId}}: {{title}}",{taskId:t.taskId,title:t.taskTitle||n("documents.untitled","Untitled")}),children:t.taskId})]})}function ws({artifact:t,projectId:i,t:n,onOpenTask:u}){const o=t.title||n("documents.untitledArtifact","Untitled artifact");return e.jsxs("article",{className:"artifacts-gallery-row","aria-label":n("documents.artifactCardLabel","Artifact {{title}}",{title:o}),children:[e.jsxs("div",{className:"artifacts-gallery-row-info",children:[e.jsx(ze,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"artifacts-gallery-row-title",children:o}),t.taskId&&e.jsx("button",{className:"artifacts-gallery-task-link",onClick:()=>u(t.taskId),children:t.taskId}),e.jsx("span",{className:"artifacts-gallery-row-meta",children:fe(t.createdAt)})]}),e.jsx("audio",{className:"artifacts-gallery-audio",controls:!0,src:W(t.id,i),"aria-label":n("documents.artifactAudioLabel","Audio artifact: {{title}}",{title:o})})]})}function gs({artifact:t,projectId:i,t:n,onOpenTask:u}){const o=t.title||n("documents.untitledArtifact","Untitled artifact");return e.jsxs("article",{className:"artifacts-gallery-row","aria-label":n("documents.artifactCardLabel","Artifact {{title}}",{title:o}),children:[e.jsxs("div",{className:"artifacts-gallery-row-info",children:[e.jsx(he,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"artifacts-gallery-row-title",children:o}),t.mimeType&&e.jsx("span",{className:"artifacts-gallery-row-mime badge",children:t.mimeType}),t.taskId&&e.jsx("button",{className:"artifacts-gallery-task-link",onClick:()=>u(t.taskId),children:t.taskId}),e.jsxs("span",{className:"artifacts-gallery-row-meta",children:[$e(t.sizeBytes),t.sizeBytes!==void 0?" · ":"",fe(t.createdAt)]})]}),e.jsxs("a",{className:"btn btn-sm artifacts-gallery-row-download",href:W(t.id,i),target:"_blank",rel:"noreferrer","data-testid":"artifact-other-link","aria-label":n("documents.downloadArtifactAria","Download {{title}}",{title:o}),children:[e.jsx(lt,{size:14,"aria-hidden":"true"}),n("documents.downloadArtifact","Download")]})]})}function bs(t,i){a.useEffect(()=>{i.current?.focus();const n=u=>{u.key==="Escape"&&(u.preventDefault(),t())};return document.addEventListener("keydown",n),()=>{document.removeEventListener("keydown",n)}},[i,t])}function Ve({label:t,onClose:i,children:n,wide:u,closeRef:o,windowKey:s,persistKey:r}){return bs(i,o),e.jsx(Zt,{windowKey:s,title:null,onClose:i,hideHeader:!0,dragHandleSelector:".artifacts-gallery-viewer-header",className:"artifacts-gallery-window",ariaLabel:t,persistGeometryKey:r,defaultSize:u?{width:1024,height:720}:{width:720,height:640},minSize:{width:320,height:280},children:e.jsx("div",{className:"artifacts-gallery-viewer",children:n})})}function Oe({title:t,onClose:i,t:n,actions:u,closeRef:o}){return e.jsxs("div",{className:"artifacts-gallery-viewer-header",children:[e.jsx("h3",{className:"artifacts-gallery-viewer-title",children:t}),e.jsxs("div",{className:"artifacts-gallery-viewer-actions",children:[u,e.jsx("button",{ref:o,className:"modal-close",onClick:i,"aria-label":n("documents.closeLightbox","Close artifact preview"),children:e.jsx(ot,{size:20})})]})]})}function _e({artifact:t,t:i,onOpenTask:n}){return e.jsxs("div",{className:"artifacts-gallery-viewer-meta",children:[t.description&&e.jsx("p",{className:"artifacts-gallery-viewer-description",children:t.description}),e.jsxs("div",{className:"artifacts-gallery-viewer-meta-row",children:[e.jsx("span",{children:t.authorId}),e.jsx("span",{children:"·"}),e.jsx("span",{children:fe(t.createdAt)}),t.sizeBytes!==void 0&&e.jsxs("span",{children:["· ",$e(t.sizeBytes)]}),t.taskId&&e.jsxs("button",{className:"artifacts-gallery-task-link",onClick:()=>n(t.taskId),children:[i("documents.openTask","Open task")," ",t.taskId]})]})]})}function vs({artifact:t,projectId:i,t:n,onClose:u,onOpenTask:o}){const s=t.title||n("documents.untitledArtifact","Untitled artifact"),r=W(t.id,i),k=a.useRef(null);return e.jsxs(Ve,{label:n("documents.lightboxLabel","Artifact media preview"),onClose:u,wide:!0,closeRef:k,windowKey:`artifact-media-${t.id}`,persistKey:"fn-artifact-viewer-media-geometry",children:[e.jsx(Oe,{title:s,onClose:u,t:n,closeRef:k,actions:e.jsx("a",{className:"btn btn-sm",href:r,target:"_blank",rel:"noreferrer","aria-label":n("documents.openInNewTab","Open in new tab"),children:e.jsx(Re,{size:14,"aria-hidden":"true"})})}),e.jsx("div",{className:"artifacts-gallery-viewer-media-frame",children:t.type==="image"?e.jsx("img",{className:"artifacts-gallery-viewer-media",src:r,alt:s}):e.jsx("video",{className:"artifacts-gallery-viewer-media",src:r,controls:!0,autoPlay:!0,"aria-label":n("documents.artifactVideoLabel","Video artifact: {{title}}",{title:s})})}),e.jsx(_e,{artifact:t,t:n,onOpenTask:o})]})}function ys({artifact:t,projectId:i,t:n,onClose:u,onOpenTask:o}){const s=t.title||n("documents.untitledArtifact","Untitled artifact"),r=W(t.id,i),k=a.useRef(null);return e.jsxs(Ve,{label:n("documents.pdfViewerLabel","PDF artifact viewer"),onClose:u,wide:!0,closeRef:k,windowKey:`artifact-pdf-${t.id}`,persistKey:"fn-artifact-viewer-pdf-geometry",children:[e.jsx(Oe,{title:s,onClose:u,t:n,closeRef:k,actions:e.jsxs("a",{className:"btn btn-sm",href:r,target:"_blank",rel:"noreferrer","aria-label":n("documents.openInNewTab","Open in new tab"),children:[e.jsx(Re,{size:14,"aria-hidden":"true"}),n("documents.openInNewTab","Open in new tab")]})}),e.jsx("iframe",{className:"artifacts-gallery-viewer-pdf",src:r,title:s}),e.jsx(_e,{artifact:t,t:n,onOpenTask:o})]})}function Ns(t){const i=t.mimeType?.toLowerCase().split(";",1)[0]??"",n=i==="text/html"?".html":i==="application/json"?".json":i==="text/plain"?".txt":".md";return`${(t.title||"artifact").replace(/[^\w.-]+/g,"-")}${n}`}function Cs({artifact:t,projectId:i,t:n,addToast:u,onClose:o,onOpenTask:s,onArtifactUpdated:r}){const k=t.title||n("documents.untitledArtifact","Untitled artifact"),[l,p]=a.useState(null),[v,m]=a.useState(null),[C,x]=a.useState(!1),[w,b]=a.useState(""),[d,j]=a.useState(!1),[y,z]=a.useState(!0),M=a.useRef(null);a.useEffect(()=>{let F=!1;return rt(t.id,i).then(L=>{F||p(L)}).catch(L=>{F||m(L instanceof Error?L.message:String(L))}),()=>{F=!0}},[t.id,i]);const E=l!==null&&!l.uri,D=l?.content??"",A=(l?.mimeType??t.mimeType)?.toLowerCase().split(";",1)[0]==="text/html",U=()=>{b(D),x(!0)},P=async()=>{j(!0);try{const F=await Jt(t.id,{content:w},i);p(F),x(!1),u(n("documents.artifactSaved","Artifact saved"),"success"),r?.()}catch(F){u(F instanceof Error?F.message:String(F),"error")}finally{j(!1)}};return e.jsxs(Ve,{label:n("documents.docViewerLabel","Document artifact viewer"),onClose:o,wide:!0,closeRef:M,windowKey:`artifact-doc-${t.id}`,persistKey:"fn-artifact-viewer-doc-geometry",children:[e.jsx(Oe,{title:k,onClose:o,t:n,closeRef:M,actions:C?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>x(!1),disabled:d,children:n("documents.cancelEdit","Cancel")}),e.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void P(),disabled:d,children:d?n("documents.saving","Saving…"):n("documents.saveArtifact","Save")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>z(F=>!F),"aria-pressed":y,title:A?y?n("documents.switchToSource","Switch to source view"):n("documents.switchToPreview","Switch to live preview"):y?n("documents.switchToPlainText","Switch to plain text"):n("documents.switchToMarkdown","Switch to markdown"),children:A?y?n("documents.htmlPreview","Preview"):n("documents.htmlSource","Source"):y?n("documents.markdown","Markdown"):n("documents.plain","Plain")}),E&&e.jsxs("button",{className:"btn btn-sm",onClick:U,"aria-label":n("documents.editArtifact","Edit document"),children:[e.jsx(De,{size:14,"aria-hidden":"true"}),n("documents.edit","Edit")]})]})}),e.jsx("div",{className:"artifacts-gallery-viewer-doc",children:v?e.jsx("p",{className:"artifacts-gallery-viewer-error",children:v}):l===null?e.jsx("p",{className:"artifacts-gallery-viewer-loading",children:n("documents.loadingArtifact","Loading artifact…")}):C?e.jsx("div",{className:"artifacts-gallery-viewer-editor","aria-label":n("documents.artifactContentEditor","Artifact content editor"),children:e.jsx(Pe,{content:w,onChange:b,filePath:Ns(l),forceToolbarActionsVisible:!0})}):A&&y?e.jsx("iframe",{className:"artifacts-gallery-viewer-html",sandbox:"allow-scripts",title:k,...l.uri?{src:W(t.id,i)}:{srcDoc:D}}):l.uri?e.jsxs("p",{className:"artifacts-gallery-viewer-loading",children:[n("documents.binaryDocArtifact","This document is stored as a file.")," ",e.jsx("a",{href:W(t.id,i),target:"_blank",rel:"noreferrer",children:n("documents.openArtifactMedia","Open artifact media")})]}):y?e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:D})}):e.jsx("pre",{className:"artifacts-gallery-viewer-plain",children:D})}),e.jsx(_e,{artifact:t,t:n,onOpenTask:s})]})}const Ss=768,Ts={image:ut,doc:J,pdf:ct,video:Ie,audio:ze,other:he};function ae(t){return t?new Date(t).toLocaleString():""}function As(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t>=10*1024?0:1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Fs(t){return t==="done"?"status-dot status-dot--online":t==="archived"?"status-dot status-dot--offline":t==="todo"||t==="triage"?"status-dot status-dot--pending":"status-dot status-dot--connecting"}function mt(t,i){switch(i){case"image":return t("documents.artifactCategoryImage","Image");case"doc":return t("documents.artifactCategoryDoc","Document");case"pdf":return t("documents.artifactCategoryPdf","PDF");case"video":return t("documents.artifactCategoryVideo","Video");case"audio":return t("documents.artifactCategoryAudioSingle","Audio");case"other":return t("documents.artifactCategoryOtherSingle","Other")}}function Es(t,i){return i?[t.title,t.description,t.taskId,t.taskTitle,t.mimeType,t.authorId].some(n=>n?.toLowerCase().includes(i)):!0}function Ds(t){const i=t.mimeType?.toLowerCase().split(";",1)[0]??"";return!!t.content||t.type==="document"||i.startsWith("text/")||i==="application/json"||i==="application/xml"}function Ps({artifact:t,projectId:i,content:n,loading:u,error:o,renderMarkdown:s,onToggleMarkdown:r,onOpenTask:k,t:l}){const[p,v]=a.useState(null),m=ne(t),C=mt(l,m),x=t.title||l("documents.untitledArtifact","Untitled artifact"),w=W(t.id,i),b=m==="doc"&&Ds(t);a.useEffect(()=>{v(null)},[t.id]);const d=p?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:p}):null,j=m==="image"?e.jsxs(e.Fragment,{children:[d,e.jsx("img",{className:"documents-task-artifact-media",src:w,alt:x,onError:()=>v(l("documents.artifactMediaFailed","Failed to load artifact preview."))})]}):m==="video"?e.jsxs(e.Fragment,{children:[d,e.jsx("video",{className:"documents-task-artifact-media",controls:!0,src:w,"aria-label":l("documents.videoArtifactLabel","Video artifact: {{title}}",{title:x}),onError:()=>v(l("documents.artifactMediaFailed","Failed to load artifact preview."))})]}):m==="audio"?e.jsxs(e.Fragment,{children:[d,e.jsx("audio",{className:"documents-task-artifact-audio",controls:!0,src:w,"aria-label":l("documents.audioArtifactLabel","Audio artifact: {{title}}",{title:x}),onError:()=>v(l("documents.artifactMediaFailed","Failed to load artifact preview."))})]}):m==="pdf"?e.jsxs("div",{className:"documents-task-artifact-pdf",children:[e.jsx("iframe",{title:l("documents.pdfArtifactTitle","PDF artifact: {{title}}",{title:x}),src:w}),e.jsxs("a",{className:"btn btn-sm",href:w,target:"_blank",rel:"noreferrer",children:[e.jsx(Re,{size:14,"aria-hidden":"true"}),l("documents.openInNewTab","Open in new tab")]})]}):m==="doc"&&b?u?e.jsx("p",{className:"documents-content-state",children:e.jsx(de,{label:l("documents.loadingArtifactContent","Loading artifact content…")})}):o?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:o}):s?e.jsx("div",{className:"documents-content-markdown documents-task-artifact-doc-content",children:e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:n??t.content??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text documents-task-artifact-doc-content",children:n??t.content??""}):e.jsxs("div",{className:"documents-task-artifact-download",children:[e.jsx(he,{size:24,"aria-hidden":"true"}),e.jsx("p",{children:t.description||l("documents.binaryArtifactFallback","This artifact cannot be previewed inline.")}),e.jsxs("a",{className:"btn btn-sm",href:w,target:"_blank",rel:"noreferrer","data-testid":"task-artifact-open-link",children:[e.jsx(lt,{size:14,"aria-hidden":"true"}),l("documents.openArtifact","Open artifact")]})]});return e.jsxs("div",{className:"documents-content-viewer documents-task-artifact-viewer",children:[e.jsxs("div",{className:"documents-content-header documents-task-document-header",children:[e.jsxs("p",{className:"documents-file-path-header",children:[t.taskId," / ",x]}),m==="doc"&&b?e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:r,"aria-label":s?l("documents.switchToPlainText","Switch to plain text"):l("documents.switchToMarkdown","Switch to markdown"),"aria-pressed":s,title:s?l("documents.switchToPlainText","Switch to plain text"):l("documents.switchToMarkdown","Switch to markdown"),children:s?l("documents.markdown","Markdown"):l("documents.plain","Plain")}):null]}),e.jsxs("div",{className:"document-card-meta documents-task-document-meta documents-task-artifact-meta",children:[e.jsx("span",{children:C}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{children:t.authorId||l("documents.unknownAuthor","unknown")}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{children:ae(t.updatedAt)}),t.taskId?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("button",{className:"documents-task-artifact-open-task",onClick:()=>void k(t.taskId),children:l("documents.openTask","Open task")})]}):null]}),t.description?e.jsx("p",{className:"documents-task-artifact-description",children:t.description}):null,e.jsx("div",{className:`documents-task-artifact-preview documents-task-artifact-preview--${m}`,children:j})]})}function Vs({projectId:t,addToast:i,onOpenDetail:n,onOpenArtifactTaskDetail:u,onSendSelectionToTask:o}){const{t:s}=dt("app"),[r,k]=a.useState("artifacts"),l=es(),[p,v]=a.useState(""),[m,C]=a.useState(null),[x,w]=a.useState(null),[b,d]=a.useState(!1),[j,y]=a.useState(null),[z,M]=a.useState(!1),[E,D]=a.useState(null),[A,U]=a.useState(!1),P=a.useRef(0),F=a.useRef(null),L=a.useRef(null),He=a.useRef(null),Ue=a.useRef(null),[Y,Be]=a.useState(!1),[ht,Ke]=a.useState(new Map),[ft,I]=a.useState(null),[ke,R]=a.useState(""),[pe,xe]=a.useState(!1),[kt,$]=a.useState(null),[pt,B]=a.useState(!1),[xt,V]=a.useState(null),[jt,je]=a.useState(!0),ee=a.useRef(0),[we,G]=a.useState(!1),[ie,K]=a.useState(""),[ge,be]=a.useState(!1),[ce,qe]=a.useState(!1),wt=oe(F,{locked:ce}),gt=oe(L,{locked:ce}),bt=oe(He,{locked:ce}),vt=oe(Ue,{locked:ce}),ve=Y?wt:gt,ye=r==="tasks"?p.trim():"",yt=r==="artifacts"?p.trim():"",{documents:te,loading:Nt,error:Ct,refresh:re}=hs({projectId:t,searchQuery:ye||void 0,includeProjectFiles:!1}),{files:Q,loading:St,error:Tt,refresh:We}=fs(t,{showHidden:b}),{artifacts:O,loading:At,error:Ft,refresh:Ne}=ts({projectId:t,searchQuery:yt||void 0});a.useEffect(()=>{const c=()=>{U(window.innerWidth<=Ss)};return c(),window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}},[]),a.useEffect(()=>{k("artifacts"),C(null),w(null),d(!1),y(null),D(null),M(!1),Be(!1),Ke(new Map),I(null),R(""),xe(!1),$(null),B(!1),V(null),je(!0),G(!1),K(""),be(!1)},[t]);const X=a.useMemo(()=>{const c=ye.toLowerCase(),h=new Map;for(const f of te){const S=h.get(f.taskId)??{documents:[],artifacts:[]};S.documents.push(f),h.set(f.taskId,S)}for(const f of O){if(!f.taskId||!Es(f,c))continue;const S=h.get(f.taskId)??{documents:[],artifacts:[]};S.artifacts.push(f),h.set(f.taskId,S)}return Array.from(h.entries()).map(([f,S])=>{const H=[...S.documents].sort((T,se)=>se.updatedAt.localeCompare(T.updatedAt)),q=[...S.artifacts].sort((T,se)=>se.updatedAt.localeCompare(T.updatedAt)),Fe=[H[0]?.updatedAt,q[0]?.updatedAt].filter(Boolean).sort().at(-1)??"",N=H.find(T=>T.taskTitle)?.taskTitle??q.find(T=>T.taskTitle)?.taskTitle;return{taskId:f,taskTitle:N,taskColumn:H.find(T=>T.taskColumn)?.taskColumn??q.find(T=>T.taskColumn)?.taskColumn,documents:H,artifacts:q,latestUpdated:Fe}}).filter(f=>f.documents.length>0||f.artifacts.length>0).sort((f,S)=>S.latestUpdated.localeCompare(f.latestUpdated))},[O,te,ye]),g=a.useMemo(()=>x?.kind!=="document"?null:te.find(c=>c.id===x.id)??null,[te,x]),_=a.useMemo(()=>x?.kind!=="artifact"?null:O.find(c=>c.id===x.id)??null,[O,x]),le=g??_;a.useEffect(()=>{if(!x)return;X.some(h=>x.kind==="document"?h.documents.some(f=>f.id===x.id):h.artifacts.some(f=>f.id===x.id))||(w(null),I(null),R(""),$(null),B(!1),V(null))},[X,x]);const Ce=a.useMemo(()=>{const c=p.trim().toLowerCase();return c?Q.filter(h=>{const f=h.path.toLowerCase(),S=h.name.toLowerCase();return f.includes(c)||S.includes(c)}):Q},[Q,p]);a.useEffect(()=>{if(!m)return;Q.some(h=>h.path===m.path)||(C(null),y(null),D(null),M(!1))},[Q,m]);const Et=a.useCallback(c=>{v(c.target.value)},[]),Dt=a.useCallback(()=>{v("")},[]),Se=a.useCallback(c=>{k(c),c!=="tasks"&&(w(null),I(null),R(""),$(null),B(!1),V(null)),c!=="project"&&(G(!1),K(""))},[]),Pt=a.useCallback(async c=>{try{const h=await tt(c,t);n(h)}catch{i(`Failed to open task ${c}`,"error")}},[t,n,i]),Ge=a.useCallback(async c=>{try{const h=await tt(c,t);(u??n)(h)}catch{i(`Failed to open task ${c}`,"error")}},[t,u,n,i]),Lt=a.useCallback(async c=>{C(c),M(!0),D(null),y(null),G(!1),K("");const h=P.current+1;P.current=h;try{const f=await ss("project",c.path,t);if(P.current!==h)return;y(f.content)}catch(f){if(P.current!==h)return;const S=f instanceof Error?f.message:`Failed to open ${c.path}`;D(S),i(S,"error")}finally{P.current===h&&M(!1)}},[t,i]),Mt=a.useCallback(()=>{C(null),y(null),D(null),M(!1),G(!1),K("")},[]),Rt=a.useCallback(()=>{j!==null&&(K(j),G(!0))},[j]),zt=a.useCallback(()=>{G(!1),K("")},[]),It=a.useCallback(async()=>{if(m){be(!0);try{await as("project",m.path,ie,t),y(ie),G(!1),K(""),i(s("documents.projectFileSaved","File saved"),"success")}catch(c){i(c instanceof Error?c.message:String(c),"error")}finally{be(!1)}}},[m,ie,t,i,s]),$t=a.useCallback(c=>{w({kind:"document",id:c}),I(null),R(""),$(null),B(!1),V(null)},[]),Vt=a.useCallback(c=>{w({kind:"artifact",id:c}),I(null),R(""),$(null),V(null),je(!0)},[]),Ot=a.useCallback(()=>{w(null),I(null),R(""),$(null),B(!1),V(null)},[]),_t=a.useCallback(c=>{Ke(h=>{const f=new Map(h),S=f.get(c)??!0;return f.set(c,!S),f})},[]),Ht=a.useCallback(()=>{g&&(R(g.content),I(g.id))},[g]),Ut=a.useCallback(()=>{I(null),R("")},[]),Bt=a.useCallback(async()=>{if(g){xe(!0);try{await ns(g.taskId,g.key,ke,{},t),await re(),I(null),R(""),i(s("documents.taskDocumentSaved","Document saved"),"success")}catch(c){i(c instanceof Error?c.message:String(c),"error")}finally{xe(!1)}}},[g,ke,t,re,i,s]);a.useEffect(()=>{if(!_||ne(_)!=="doc"){$(null),B(!1),V(null);return}const c=ee.current+1;ee.current=c,B(!0),V(null),$(null),rt(_.id,t).then(h=>{ee.current===c&&$(h.content??_.content??"")}).catch(h=>{ee.current===c&&V(h instanceof Error?h.message:String(h))}).finally(()=>{ee.current===c&&B(!1)})},[t,_]);const Qe=r==="project"?Tt:r==="tasks"?Ct:Ft,Kt=a.useCallback(async()=>{if(r==="project"){await We();return}if(r==="tasks"){await re();return}await Ne()},[r,Ne,We,re]),Ye=r==="project"?Ce.length:r==="tasks"?X.length:O.length,Z=g?ht.get(g.id)??!0:!1,Te=Z?bt:vt,Ae=g!==null&&ft===g.id,qt=r==="project"&&m&&!we&&o&&ve?e.jsx(st,{selectedText:ve.selectedText,anchorRect:ve.anchorRect,filePath:m.path,onSubmit:o,onOpenChange:qe}):null,Wt=r==="tasks"&&g&&!Ae&&o&&Te?e.jsx(st,{selectedText:Te.selectedText,anchorRect:Te.anchorRect,filePath:`${g.taskId}/${g.key}`,onSubmit:o,onOpenChange:qe}):null,Xe=r==="project"?s("documents.searchProjectFiles","Search project markdown files…"):r==="tasks"?s("documents.searchTaskDocuments","Search task documents…"):s("documents.searchArtifacts","Search artifacts…");return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsx(is,{icon:J,title:s("documents.title","Artifacts"),actions:e.jsx("span",{className:"documents-view-count",children:s("documents.resultCount","{{count}} result{{plural}}",{count:Ye,plural:Ye!==1?"s":""})})}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":s("documents.sectionsLabel","Documents sections"),children:[e.jsxs("button",{className:`btn documents-tab${r==="artifacts"?" active":""}`,role:"tab","aria-selected":r==="artifacts","aria-label":s("documents.showArtifacts","Show artifacts"),onClick:()=>Se("artifacts"),children:[s("documents.artifactsTab","Artifacts"),e.jsx("span",{className:"documents-tab-count",children:O.length})]}),e.jsxs("button",{className:`btn documents-tab${r==="project"?" active":""}`,role:"tab","aria-selected":r==="project","aria-label":s("documents.showProjectFiles","Show project markdown files"),onClick:()=>Se("project"),children:[s("documents.projectFilesTab","Project Files"),e.jsx("span",{className:"documents-tab-count",children:Q.length})]}),e.jsxs("button",{className:`btn documents-tab${r==="tasks"?" active":""}`,role:"tab","aria-selected":r==="tasks","aria-label":s("documents.showTaskDocuments","Show task documents"),onClick:()=>Se("tasks"),children:[s("documents.taskDocumentsTab","Task Documents"),e.jsx("span",{className:"documents-tab-count",children:X.length})]})]}),r==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>d(c=>!c),"aria-pressed":b,"aria-label":b?s("documents.hideHidden","Hide hidden project files"):s("documents.showHidden","Show hidden project files"),title:b?s("documents.hideHiddenFiles","Hide hidden files"):s("documents.showHiddenFiles","Show hidden files"),children:[b?e.jsx(cs,{size:14}):e.jsx(rs,{size:14}),b?s("documents.hideHiddenLabel","Hide Hidden"):s("documents.showHiddenLabel","Show Hidden")]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(ls,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:Xe,value:p,onChange:Et,"aria-label":Xe}),p&&e.jsx("button",{className:"documents-search-clear",onClick:Dt,"aria-label":s("documents.clearSearch","Clear search"),children:e.jsx(ot,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:Qe?e.jsxs("div",{className:"documents-view-error",children:[e.jsx("p",{children:s("documents.failedToLoad","Failed to load {{type}}: {{error}}",{type:r==="project"?s("documents.projectFiles","project files"):r==="tasks"?s("documents.taskDocuments","task documents"):s("documents.artifacts","artifacts"),error:Qe})}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void Kt(),"aria-label":s("documents.retryLoading","Retry loading documents"),children:[e.jsx(os,{size:16}),s("documents.retry","Retry")]})]}):r==="project"?St&&Q.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:e.jsx(de,{label:s("documents.loadingProjectFiles","Loading project markdown files…")})})}):Ce.length===0?e.jsx("div",{className:"documents-view-empty",children:p.trim()?e.jsx("p",{children:s("documents.noMatchProject",'No project markdown files match "{{query}}".',{query:p.trim()})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:s("documents.noMarkdownFiles","No Markdown files found in this project.")})]})}):e.jsxs("div",{className:`documents-project-layout${A?" documents-project-layout--mobile":""}`,children:[(!A||!m)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":s("documents.projectMarkdownFilesLabel","Project markdown files"),children:e.jsx("ul",{className:"markdown-file-list",children:Ce.map(c=>{const h=m?.path===c.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${h?" markdown-file-item--selected":""}`,onClick:()=>void Lt(c),"aria-label":`Open ${c.path}`,"aria-current":h?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:c.name}),e.jsx("span",{className:"markdown-file-item-path",children:c.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[As(c.size)," · ",ae(c.mtime)]})]})},c.path)})})}),(!A||m)&&e.jsxs("section",{className:"documents-view-main","aria-label":s("documents.projectFilePreviewLabel","Project file content preview"),children:[A&&m&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:Mt,"aria-label":s("documents.backToFilesList","Back to project files list"),children:[e.jsx(at,{size:14}),s("documents.backToFiles","Back to files")]}),m?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:m.path}),e.jsx("div",{className:"documents-task-document-actions",children:we?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:zt,disabled:ge,children:s("documents.cancelEdit","Cancel")}),e.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void It(),disabled:ge,children:ge?s("documents.saving","Saving…"):s("documents.saveProjectFile","Save")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>Be(c=>!c),"aria-label":Y?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),"aria-pressed":Y,title:Y?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),children:Y?s("documents.markdown","Markdown"):s("documents.plain","Plain")}),e.jsxs("button",{className:"btn btn-sm",onClick:Rt,disabled:z||E!==null||j===null,"aria-label":s("documents.editProjectFile","Edit project file"),children:[e.jsx(De,{size:14,"aria-hidden":"true"}),s("documents.edit","Edit")]})]})})]}),z?e.jsx("p",{className:"documents-content-state",children:e.jsx(de,{label:s("documents.loadingFileContent","Loading file content…")})}):E?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:E}):we?e.jsx("div",{className:"documents-task-document-editor","aria-label":s("documents.projectFileContentEditor","Project file content editor"),children:e.jsx(Pe,{content:ie,onChange:K,filePath:m.path,forceToolbarActionsVisible:!0})}):Y?e.jsx("div",{ref:F,className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:j??""})})}):e.jsx("pre",{ref:L,className:"document-card-content-text documents-content-viewer-text",children:j??""}),qt]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:s("documents.selectFile","Select a Markdown file to view its content.")})})]})]}):r==="artifacts"?At&&O.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:s("documents.loadingArtifacts","Loading artifacts…")})}):O.length===0?e.jsx("div",{className:"documents-view-empty",children:p.trim()?e.jsx("p",{children:s("documents.noMatchArtifacts",'No artifacts match "{{query}}".',{query:p.trim()})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:s("documents.noArtifacts","No artifacts yet.")}),e.jsx("p",{className:"documents-view-empty-hint",children:s("documents.artifactsCreatedBy","Agents register screenshots, wireframes, mockups, recordings, and documents here as they work on tasks.")})]})}):e.jsx(ks,{artifacts:O,projectId:t,isMobile:A,addToast:i,onOpenTask:Ge,onArtifactUpdated:()=>void Ne()}):Nt&&te.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:e.jsx(de,{label:s("documents.loadingTaskDocuments","Loading task documents…")})})}):X.length===0?e.jsx("div",{className:"documents-view-empty",children:p.trim()?e.jsx("p",{children:s("documents.noMatchTask",'No task documents match "{{query}}".',{query:p.trim()})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:s("documents.noTaskDocuments","No task documents yet.")}),e.jsx("p",{className:"documents-view-empty-hint",children:s("documents.documentsCreatedIn","Documents are created in task detail tabs.")})]})}):e.jsxs("div",{className:`documents-project-layout documents-task-documents-layout${A?" documents-project-layout--mobile":""}`,children:[(!A||!le)&&e.jsx("aside",{className:"documents-view-sidebar documents-task-documents-sidebar","aria-label":s("documents.taskDocumentsListLabel","Task documents"),children:X.map(({taskId:c,taskTitle:h,taskColumn:f,documents:S,artifacts:H})=>{const q=f?l(f):null,Fe=f?Fs(f):"status-dot";return e.jsxs("section",{className:"documents-task-sidebar-group","aria-labelledby":`documents-task-group-${c}`,children:[e.jsxs("div",{className:"documents-task-sidebar-group-header",children:[e.jsxs("div",{className:"documents-task-sidebar-title-wrap",children:[e.jsxs("h3",{id:`documents-task-group-${c}`,className:"documents-task-sidebar-title",children:[e.jsx("span",{className:"documents-group-task-id",children:c}),e.jsx("span",{className:"documents-group-task-title",children:h||s("documents.untitled","Untitled")})]}),q?e.jsxs("span",{className:"documents-group-status badge","aria-label":s("documents.taskStatusAria","Task status: {{status}}",{status:q}),children:[e.jsx("span",{className:Fe,"aria-hidden":"true"}),e.jsx("span",{children:q})]}):null]}),e.jsxs("div",{className:"documents-task-sidebar-actions",children:[e.jsx("span",{className:"documents-group-count",children:s("documents.taskOutputCount","{{docCount}} doc{{docPlural}} · {{artifactCount}} artifact{{artifactPlural}}",{docCount:S.length,docPlural:S.length!==1?"s":"",artifactCount:H.length,artifactPlural:H.length!==1?"s":""})}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>void Pt(c),"aria-label":s("documents.openTaskAria","Open task {{taskId}}: {{title}}",{taskId:c,title:h||s("documents.untitled","Untitled")}),children:s("documents.openTask","Open task")})]})]}),e.jsxs("ul",{className:"markdown-file-list documents-task-document-list",children:[S.map(N=>{const T=g?.id===N.id;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item documents-task-document-item${T?" markdown-file-item--selected":""}`,onClick:()=>$t(N.id),"aria-label":s("documents.openTaskDocument","Open {{taskId}} {{key}}",{taskId:N.taskId,key:N.key}),"aria-current":T?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:N.key}),e.jsxs("span",{className:"markdown-file-item-path",children:[N.taskId," · ",N.taskTitle||s("documents.untitled","Untitled")]}),e.jsxs("span",{className:"markdown-file-item-meta",children:[s("documents.revisionShort","v{{revision}}",{revision:N.revision})," · ",N.author," · ",ae(N.updatedAt)]})]})},`document-${N.id}`)}),H.length>0?e.jsxs("li",{className:"documents-task-artifacts-subsection","aria-label":s("documents.taskArtifactsSubsection","Task artifacts"),children:[e.jsx("div",{className:"documents-task-artifacts-label",children:s("documents.taskArtifactsLabel","Artifacts")}),e.jsx("ul",{className:"markdown-file-list documents-task-artifact-list",children:H.map(N=>{const T=ne(N),se=Ts[T],Gt=mt(s,T),Ze=_?.id===N.id;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item documents-task-document-item documents-task-artifact-item${Ze?" markdown-file-item--selected":""}`,onClick:()=>Vt(N.id),"aria-label":s("documents.openTaskArtifact","Open {{taskId}} artifact {{title}}",{taskId:c,title:N.title||s("documents.untitledArtifact","Untitled artifact")}),"aria-current":Ze?"true":void 0,children:[e.jsxs("span",{className:"documents-task-artifact-title-row",children:[e.jsx(se,{size:14,"aria-hidden":"true"}),e.jsx("span",{className:"markdown-file-item-name",children:N.title||s("documents.untitledArtifact","Untitled artifact")})]}),e.jsxs("span",{className:"markdown-file-item-path",children:[Gt," · ",N.mimeType||N.type]}),e.jsxs("span",{className:"markdown-file-item-meta",children:[N.authorId||s("documents.unknownAuthor","unknown")," · ",ae(N.updatedAt)]})]})},`artifact-${N.id}`)})})]}):null]})]},c)})}),(!A||le)&&e.jsxs("section",{className:"documents-view-main","aria-label":s("documents.taskDocumentPreviewLabel","Task document content preview"),children:[A&&le&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:Ot,"aria-label":s("documents.backToTaskDocumentsList","Back to task documents list"),children:[e.jsx(at,{size:14}),s("documents.backToTaskDocuments","Back to documents")]}),le?_?e.jsx(Ps,{artifact:_,projectId:t,content:kt,loading:pt,error:xt,renderMarkdown:jt,onToggleMarkdown:()=>je(c=>!c),onOpenTask:Ge,t:s}):g?e.jsxs("div",{className:"documents-content-viewer documents-task-document-viewer",children:[e.jsxs("div",{className:"documents-content-header documents-task-document-header",children:[e.jsxs("p",{className:"documents-file-path-header",children:[g.taskId," / ",g.key]}),e.jsx("div",{className:"documents-task-document-actions",children:Ae?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:Ut,disabled:pe,children:s("documents.cancelEdit","Cancel")}),e.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void Bt(),disabled:pe,children:pe?s("documents.saving","Saving…"):s("documents.saveTaskDocument","Save")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>_t(g.id),"aria-label":Z?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),"aria-pressed":Z,title:Z?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),children:Z?s("documents.markdown","Markdown"):s("documents.plain","Plain")}),e.jsxs("button",{className:"btn btn-sm",onClick:Ht,"aria-label":s("documents.editTaskDocument","Edit task document"),children:[e.jsx(De,{size:14,"aria-hidden":"true"}),s("documents.edit","Edit")]})]})})]}),e.jsxs("div",{className:"document-card-meta documents-task-document-meta",children:[e.jsx("span",{className:"document-card-author",children:g.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{children:s("documents.revisionShort","v{{revision}}",{revision:g.revision})}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:ae(g.updatedAt)})]}),Ae?e.jsx("div",{className:"documents-task-document-editor","aria-label":s("documents.taskDocumentContentEditor","Task document content editor"),children:e.jsx(Pe,{content:ke,onChange:R,filePath:g.key.includes(".")?g.key:`${g.key}.md`,forceToolbarActionsVisible:!0})}):Z?e.jsx("div",{ref:He,className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:g.content})})}):e.jsx("pre",{ref:Ue,className:"document-card-content-text documents-content-viewer-text",children:g.content}),Wt]}):null:e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:s("documents.selectTaskDocument","Select a task document or artifact to view its content.")})})]})]})})]})}export{Vs as DocumentsView};
|
|
16
|
+
*/const ms=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Ie=Me("video",ms);function hs(t){const{projectId:i,searchQuery:n,includeProjectFiles:u=!0}=t??{},o=i?`${Qt.DOCUMENTS_PREFIX}${i}`:null,[s,r]=a.useState(()=>{if(!o)return[];const j=Je(o,{maxAgeMs:et});return Array.isArray(j)?j:[]}),[k,l]=a.useState([]),[p,v]=a.useState(()=>s.length===0),[m,C]=a.useState(null),x=a.useRef(null),w=a.useRef(s.length>0),b=a.useRef(null),d=a.useCallback(async()=>{x.current&&x.current.abort();const j=new AbortController;x.current=j;const y=!w.current;y&&v(!0),C(null);const z=Yt(n?{q:n}:void 0,i),M=u?it(i):Promise.resolve({files:[]}),[E,D]=await Promise.allSettled([z,M]);if(j.signal.aborted)return;let A=null;if(E.status==="fulfilled"){if(r(E.value),o){const U=E.value.length>500?E.value.slice(0,500):E.value;Xt(o,U,{maxBytes:5e5})}w.current=!0}else A=E.reason instanceof Error?E.reason.message:String(E.reason);if(D.status==="fulfilled"){const U=D.value.files,P=n?.trim().toLowerCase(),F=P?U.filter(L=>L.name.toLowerCase().includes(P)||L.path.toLowerCase().includes(P)):U;l(F)}C(A),y&&v(!1)},[o,u,i,n]);return a.useEffect(()=>{if(!o){w.current=!1,r([]),v(!0);return}const j=Je(o,{maxAgeMs:et});Array.isArray(j)?(r(j),w.current=!0,v(!1)):(w.current=!1,r([]),v(!0))},[o]),a.useEffect(()=>(b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{d()},300),()=>{b.current&&clearTimeout(b.current)}),[d]),a.useEffect(()=>(d(),()=>{x.current&&x.current.abort()}),[]),{documents:s,projectFiles:k,loading:p,error:m,refresh:d}}function fs(t,i){const[n,u]=a.useState([]),[o,s]=a.useState(!0),[r,k]=a.useState(null),l=a.useRef(null),p=a.useRef(!1),v=i?.showHidden??!1,m=a.useCallback(async C=>{l.current&&l.current.abort();const x=new AbortController;l.current=x;const w=!p.current;w&&s(!0),k(null);try{const b=await it(t,{showHidden:C?.showHidden??v});if(x.signal.aborted)return;u(b.files),p.current=!0}catch(b){if(x.signal.aborted)return;k(b instanceof Error?b.message:String(b))}finally{!x.signal.aborted&&w&&s(!1)}},[t,v]);return a.useEffect(()=>(p.current=!1,m({showHidden:v}),()=>{l.current&&l.current.abort()}),[m,v]),{files:n,loading:o,error:r,refresh:m}}const nt=["image","doc","pdf","video","audio","other"];function ne(t){return(t.mimeType?.toLowerCase().split(";",1)[0]??"")==="application/pdf"||t.uri?.toLowerCase().endsWith(".pdf")?"pdf":t.type==="image"?"image":t.type==="video"?"video":t.type==="audio"?"audio":t.type==="document"?"doc":"other"}const Le={image:ut,doc:J,pdf:ct,video:Ie,audio:ze,other:he};function Ee(t,i){switch(i){case"image":return t("documents.artifactCategoryImages","Images");case"doc":return t("documents.artifactCategoryDocs","Docs");case"pdf":return t("documents.artifactCategoryPdfs","PDFs");case"video":return t("documents.artifactCategoryVideos","Videos");case"audio":return t("documents.artifactCategoryAudio","Audio");case"other":return t("documents.artifactCategoryOther","Other")}}function fe(t){return t?new Date(t).toLocaleString():""}function $e(t){return t===void 0?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t>=10*1024?0:1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ks({artifacts:t,projectId:i,isMobile:n,addToast:u,onOpenTask:o,onArtifactUpdated:s}){const{t:r}=dt("app"),[k,l]=a.useState("all"),[p,v]=a.useState(null),m=a.useRef(null),C=a.useMemo(()=>{const d=new Map;for(const j of t){const y=ne(j),z=d.get(y);z?z.push(j):d.set(y,[j])}return d},[t]);a.useEffect(()=>{k!=="all"&&!C.has(k)&&l("all")},[k,C]);const x=a.useCallback(d=>{const j=ne(d),y=j==="doc"?"doc":j==="pdf"?"pdf":"media";m.current=document.activeElement instanceof HTMLElement?document.activeElement:null,v({artifact:d,kind:y})},[]),w=a.useCallback(()=>{v(null),m.current?.focus(),m.current=null},[]),b=nt.filter(d=>C.has(d)&&(k==="all"||k===d));return e.jsxs("div",{className:"artifacts-gallery",children:[C.size>1&&e.jsxs("div",{className:"artifacts-gallery-filter",role:"group","aria-label":r("documents.artifactTypeFilterLabel","Filter artifacts by category"),children:[e.jsxs("button",{className:`btn btn-sm artifacts-gallery-chip${k==="all"?" active":""}`,"aria-pressed":k==="all",onClick:()=>l("all"),children:[r("documents.artifactFilterAll","All"),e.jsx("span",{className:"artifacts-gallery-chip-count",children:t.length})]}),nt.filter(d=>C.has(d)).map(d=>{const j=Le[d];return e.jsxs("button",{className:`btn btn-sm artifacts-gallery-chip${k===d?" active":""}`,"aria-pressed":k===d,onClick:()=>l(d),children:[e.jsx(j,{size:14,"aria-hidden":"true"}),Ee(r,d),e.jsx("span",{className:"artifacts-gallery-chip-count",children:C.get(d)?.length})]},d)})]}),b.map(d=>{const j=C.get(d)??[],y=Le[d];return e.jsxs("section",{className:"artifacts-gallery-section","aria-label":Ee(r,d),children:[k==="all"&&C.size>1&&e.jsxs("header",{className:"artifacts-gallery-section-header",children:[e.jsx(y,{size:16,"aria-hidden":"true"}),e.jsx("h3",{children:Ee(r,d)}),e.jsx("span",{className:"artifacts-gallery-section-count",children:j.length})]}),e.jsx(ps,{category:d,items:j,projectId:i,isMobile:n,t:r,onOpen:x,onOpenTask:o})]},d)}),p&&p.kind==="media"&&e.jsx(vs,{artifact:p.artifact,projectId:i,t:r,onClose:w,onOpenTask:o}),p&&p.kind==="pdf"&&e.jsx(ys,{artifact:p.artifact,projectId:i,t:r,onClose:w,onOpenTask:o}),p&&p.kind==="doc"&&e.jsx(Cs,{artifact:p.artifact,projectId:i,t:r,addToast:u,onClose:w,onOpenTask:o,onArtifactUpdated:s})]})}function ps({category:t,items:i,projectId:n,isMobile:u,t:o,onOpen:s,onOpenTask:r}){if(t==="audio")return e.jsx("div",{className:"artifacts-gallery-rows",children:i.map(l=>e.jsx(ws,{artifact:l,projectId:n,t:o,onOpenTask:r},l.id))});if(t==="other")return e.jsx("div",{className:"artifacts-gallery-rows",children:i.map(l=>e.jsx(gs,{artifact:l,projectId:n,t:o,onOpenTask:r},l.id))});const k=t==="image"||t==="video"?"artifacts-gallery-grid artifacts-gallery-grid--visual":"artifacts-gallery-grid artifacts-gallery-grid--cards";return e.jsx("div",{className:`${k}${u?" artifacts-gallery-grid--mobile":""}`,children:i.map(l=>t==="image"||t==="video"?e.jsx(xs,{artifact:l,category:t,projectId:n,t:o,onOpen:s},l.id):e.jsx(js,{artifact:l,category:t,t:o,onOpen:s,onOpenTask:r},l.id))})}function xs({artifact:t,category:i,projectId:n,t:u,onOpen:o}){const s=t.title||u("documents.untitledArtifact","Untitled artifact"),r=W(t.id,n),k=l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),o(t))};return e.jsx("article",{className:"artifacts-gallery-tile","aria-label":u("documents.artifactCardLabel","Artifact {{title}}",{title:s}),children:e.jsxs("div",{className:"artifacts-gallery-tile-media",role:"button",tabIndex:0,"aria-label":u("documents.expandArtifact","Expand {{title}}",{title:s}),onClick:()=>o(t),onKeyDown:k,children:[i==="image"?e.jsx("img",{src:r,alt:s,loading:"lazy"}):e.jsx("video",{src:r,muted:!0,preload:"metadata","aria-label":u("documents.artifactVideoLabel","Video artifact: {{title}}",{title:s})}),i==="video"&&e.jsx("span",{className:"artifacts-gallery-tile-play","aria-hidden":"true",children:e.jsx(Ie,{size:22})}),e.jsxs("div",{className:"artifacts-gallery-tile-overlay",children:[e.jsx("span",{className:"artifacts-gallery-tile-title",children:s}),t.taskId&&e.jsx("span",{className:"artifacts-gallery-tile-task",children:t.taskId})]})]})})}function js({artifact:t,category:i,t:n,onOpen:u,onOpenTask:o}){const s=t.title||n("documents.untitledArtifact","Untitled artifact"),r=Le[i],k=l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),u(t))};return e.jsxs("article",{className:"artifacts-gallery-card","aria-label":n("documents.artifactCardLabel","Artifact {{title}}",{title:s}),children:[e.jsxs("div",{className:"artifacts-gallery-card-main",role:"button",tabIndex:0,"aria-label":n("documents.openArtifactViewer","Open {{title}}",{title:s}),onClick:()=>u(t),onKeyDown:k,children:[e.jsx("div",{className:`artifacts-gallery-card-icon artifacts-gallery-card-icon--${i}`,children:e.jsx(r,{size:22,"aria-hidden":"true"})}),e.jsxs("div",{className:"artifacts-gallery-card-body",children:[e.jsx("h4",{className:"artifacts-gallery-card-title",children:s}),t.description&&e.jsx("p",{className:"artifacts-gallery-card-description",children:t.description}),e.jsxs("div",{className:"artifacts-gallery-card-meta",children:[e.jsx("span",{children:t.authorId}),e.jsx("span",{children:"·"}),e.jsx("span",{children:fe(t.createdAt)}),t.sizeBytes!==void 0&&e.jsxs("span",{children:["· ",$e(t.sizeBytes)]})]})]})]}),t.taskId&&e.jsx("button",{className:"artifacts-gallery-task-link artifacts-gallery-card-task",onClick:()=>o(t.taskId),"aria-label":n("documents.openTaskAria","Open task {{taskId}}: {{title}}",{taskId:t.taskId,title:t.taskTitle||n("documents.untitled","Untitled")}),children:t.taskId})]})}function ws({artifact:t,projectId:i,t:n,onOpenTask:u}){const o=t.title||n("documents.untitledArtifact","Untitled artifact");return e.jsxs("article",{className:"artifacts-gallery-row","aria-label":n("documents.artifactCardLabel","Artifact {{title}}",{title:o}),children:[e.jsxs("div",{className:"artifacts-gallery-row-info",children:[e.jsx(ze,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"artifacts-gallery-row-title",children:o}),t.taskId&&e.jsx("button",{className:"artifacts-gallery-task-link",onClick:()=>u(t.taskId),children:t.taskId}),e.jsx("span",{className:"artifacts-gallery-row-meta",children:fe(t.createdAt)})]}),e.jsx("audio",{className:"artifacts-gallery-audio",controls:!0,src:W(t.id,i),"aria-label":n("documents.artifactAudioLabel","Audio artifact: {{title}}",{title:o})})]})}function gs({artifact:t,projectId:i,t:n,onOpenTask:u}){const o=t.title||n("documents.untitledArtifact","Untitled artifact");return e.jsxs("article",{className:"artifacts-gallery-row","aria-label":n("documents.artifactCardLabel","Artifact {{title}}",{title:o}),children:[e.jsxs("div",{className:"artifacts-gallery-row-info",children:[e.jsx(he,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"artifacts-gallery-row-title",children:o}),t.mimeType&&e.jsx("span",{className:"artifacts-gallery-row-mime badge",children:t.mimeType}),t.taskId&&e.jsx("button",{className:"artifacts-gallery-task-link",onClick:()=>u(t.taskId),children:t.taskId}),e.jsxs("span",{className:"artifacts-gallery-row-meta",children:[$e(t.sizeBytes),t.sizeBytes!==void 0?" · ":"",fe(t.createdAt)]})]}),e.jsxs("a",{className:"btn btn-sm artifacts-gallery-row-download",href:W(t.id,i),target:"_blank",rel:"noreferrer","data-testid":"artifact-other-link","aria-label":n("documents.downloadArtifactAria","Download {{title}}",{title:o}),children:[e.jsx(lt,{size:14,"aria-hidden":"true"}),n("documents.downloadArtifact","Download")]})]})}function bs(t,i){a.useEffect(()=>{i.current?.focus();const n=u=>{u.key==="Escape"&&(u.preventDefault(),t())};return document.addEventListener("keydown",n),()=>{document.removeEventListener("keydown",n)}},[i,t])}function Ve({label:t,onClose:i,children:n,wide:u,closeRef:o,windowKey:s,persistKey:r}){return bs(i,o),e.jsx(Zt,{windowKey:s,title:null,onClose:i,hideHeader:!0,dragHandleSelector:".artifacts-gallery-viewer-header",className:"artifacts-gallery-window",ariaLabel:t,persistGeometryKey:r,defaultSize:u?{width:1024,height:720}:{width:720,height:640},minSize:{width:320,height:280},children:e.jsx("div",{className:"artifacts-gallery-viewer",children:n})})}function Oe({title:t,onClose:i,t:n,actions:u,closeRef:o}){return e.jsxs("div",{className:"artifacts-gallery-viewer-header",children:[e.jsx("h3",{className:"artifacts-gallery-viewer-title",children:t}),e.jsxs("div",{className:"artifacts-gallery-viewer-actions",children:[u,e.jsx("button",{ref:o,className:"modal-close",onClick:i,"aria-label":n("documents.closeLightbox","Close artifact preview"),children:e.jsx(ot,{size:20})})]})]})}function He({artifact:t,t:i,onOpenTask:n}){return e.jsxs("div",{className:"artifacts-gallery-viewer-meta",children:[t.description&&e.jsx("p",{className:"artifacts-gallery-viewer-description",children:t.description}),e.jsxs("div",{className:"artifacts-gallery-viewer-meta-row",children:[e.jsx("span",{children:t.authorId}),e.jsx("span",{children:"·"}),e.jsx("span",{children:fe(t.createdAt)}),t.sizeBytes!==void 0&&e.jsxs("span",{children:["· ",$e(t.sizeBytes)]}),t.taskId&&e.jsxs("button",{className:"artifacts-gallery-task-link",onClick:()=>n(t.taskId),children:[i("documents.openTask","Open task")," ",t.taskId]})]})]})}function vs({artifact:t,projectId:i,t:n,onClose:u,onOpenTask:o}){const s=t.title||n("documents.untitledArtifact","Untitled artifact"),r=W(t.id,i),k=a.useRef(null);return e.jsxs(Ve,{label:n("documents.lightboxLabel","Artifact media preview"),onClose:u,wide:!0,closeRef:k,windowKey:`artifact-media-${t.id}`,persistKey:"fn-artifact-viewer-media-geometry",children:[e.jsx(Oe,{title:s,onClose:u,t:n,closeRef:k,actions:e.jsx("a",{className:"btn btn-sm",href:r,target:"_blank",rel:"noreferrer","aria-label":n("documents.openInNewTab","Open in new tab"),children:e.jsx(Re,{size:14,"aria-hidden":"true"})})}),e.jsx("div",{className:"artifacts-gallery-viewer-media-frame",children:t.type==="image"?e.jsx("img",{className:"artifacts-gallery-viewer-media",src:r,alt:s}):e.jsx("video",{className:"artifacts-gallery-viewer-media",src:r,controls:!0,autoPlay:!0,"aria-label":n("documents.artifactVideoLabel","Video artifact: {{title}}",{title:s})})}),e.jsx(He,{artifact:t,t:n,onOpenTask:o})]})}function ys({artifact:t,projectId:i,t:n,onClose:u,onOpenTask:o}){const s=t.title||n("documents.untitledArtifact","Untitled artifact"),r=W(t.id,i),k=a.useRef(null);return e.jsxs(Ve,{label:n("documents.pdfViewerLabel","PDF artifact viewer"),onClose:u,wide:!0,closeRef:k,windowKey:`artifact-pdf-${t.id}`,persistKey:"fn-artifact-viewer-pdf-geometry",children:[e.jsx(Oe,{title:s,onClose:u,t:n,closeRef:k,actions:e.jsxs("a",{className:"btn btn-sm",href:r,target:"_blank",rel:"noreferrer","aria-label":n("documents.openInNewTab","Open in new tab"),children:[e.jsx(Re,{size:14,"aria-hidden":"true"}),n("documents.openInNewTab","Open in new tab")]})}),e.jsx("iframe",{className:"artifacts-gallery-viewer-pdf",src:r,title:s}),e.jsx(He,{artifact:t,t:n,onOpenTask:o})]})}function Ns(t){const i=t.mimeType?.toLowerCase().split(";",1)[0]??"",n=i==="text/html"?".html":i==="application/json"?".json":i==="text/plain"?".txt":".md";return`${(t.title||"artifact").replace(/[^\w.-]+/g,"-")}${n}`}function Cs({artifact:t,projectId:i,t:n,addToast:u,onClose:o,onOpenTask:s,onArtifactUpdated:r}){const k=t.title||n("documents.untitledArtifact","Untitled artifact"),[l,p]=a.useState(null),[v,m]=a.useState(null),[C,x]=a.useState(!1),[w,b]=a.useState(""),[d,j]=a.useState(!1),[y,z]=a.useState(!0),M=a.useRef(null);a.useEffect(()=>{let F=!1;return rt(t.id,i).then(L=>{F||p(L)}).catch(L=>{F||m(L instanceof Error?L.message:String(L))}),()=>{F=!0}},[t.id,i]);const E=l!==null&&!l.uri,D=l?.content??"",A=(l?.mimeType??t.mimeType)?.toLowerCase().split(";",1)[0]==="text/html",U=()=>{b(D),x(!0)},P=async()=>{j(!0);try{const F=await Jt(t.id,{content:w},i);p(F),x(!1),u(n("documents.artifactSaved","Artifact saved"),"success"),r?.()}catch(F){u(F instanceof Error?F.message:String(F),"error")}finally{j(!1)}};return e.jsxs(Ve,{label:n("documents.docViewerLabel","Document artifact viewer"),onClose:o,wide:!0,closeRef:M,windowKey:`artifact-doc-${t.id}`,persistKey:"fn-artifact-viewer-doc-geometry",children:[e.jsx(Oe,{title:k,onClose:o,t:n,closeRef:M,actions:C?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>x(!1),disabled:d,children:n("documents.cancelEdit","Cancel")}),e.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void P(),disabled:d,children:d?n("documents.saving","Saving…"):n("documents.saveArtifact","Save")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:()=>z(F=>!F),"aria-pressed":y,title:A?y?n("documents.switchToSource","Switch to source view"):n("documents.switchToPreview","Switch to live preview"):y?n("documents.switchToPlainText","Switch to plain text"):n("documents.switchToMarkdown","Switch to markdown"),children:A?y?n("documents.htmlPreview","Preview"):n("documents.htmlSource","Source"):y?n("documents.markdown","Markdown"):n("documents.plain","Plain")}),E&&e.jsxs("button",{className:"btn btn-sm",onClick:U,"aria-label":n("documents.editArtifact","Edit document"),children:[e.jsx(De,{size:14,"aria-hidden":"true"}),n("documents.edit","Edit")]})]})}),e.jsx("div",{className:"artifacts-gallery-viewer-doc",children:v?e.jsx("p",{className:"artifacts-gallery-viewer-error",children:v}):l===null?e.jsx("p",{className:"artifacts-gallery-viewer-loading",children:n("documents.loadingArtifact","Loading artifact…")}):C?e.jsx("div",{className:"artifacts-gallery-viewer-editor","aria-label":n("documents.artifactContentEditor","Artifact content editor"),children:e.jsx(Pe,{content:w,onChange:b,filePath:Ns(l),forceToolbarActionsVisible:!0})}):A&&y?e.jsx("iframe",{className:"artifacts-gallery-viewer-html",sandbox:"allow-scripts",title:k,...l.uri?{src:W(t.id,i)}:{srcDoc:D}}):l.uri?e.jsxs("p",{className:"artifacts-gallery-viewer-loading",children:[n("documents.binaryDocArtifact","This document is stored as a file.")," ",e.jsx("a",{href:W(t.id,i),target:"_blank",rel:"noreferrer",children:n("documents.openArtifactMedia","Open artifact media")})]}):y?e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:D})}):e.jsx("pre",{className:"artifacts-gallery-viewer-plain",children:D})}),e.jsx(He,{artifact:t,t:n,onOpenTask:s})]})}const Ss=768,Ts={image:ut,doc:J,pdf:ct,video:Ie,audio:ze,other:he};function ae(t){return t?new Date(t).toLocaleString():""}function As(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t>=10*1024?0:1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Fs(t){return t==="done"?"status-dot status-dot--online":t==="archived"?"status-dot status-dot--offline":t==="todo"||t==="triage"?"status-dot status-dot--pending":"status-dot status-dot--connecting"}function mt(t,i){switch(i){case"image":return t("documents.artifactCategoryImage","Image");case"doc":return t("documents.artifactCategoryDoc","Document");case"pdf":return t("documents.artifactCategoryPdf","PDF");case"video":return t("documents.artifactCategoryVideo","Video");case"audio":return t("documents.artifactCategoryAudioSingle","Audio");case"other":return t("documents.artifactCategoryOtherSingle","Other")}}function Es(t,i){return i?[t.title,t.description,t.taskId,t.taskTitle,t.mimeType,t.authorId].some(n=>n?.toLowerCase().includes(i)):!0}function Ds(t){const i=t.mimeType?.toLowerCase().split(";",1)[0]??"";return!!t.content||t.type==="document"||i.startsWith("text/")||i==="application/json"||i==="application/xml"}function Ps({artifact:t,projectId:i,content:n,loading:u,error:o,renderMarkdown:s,onToggleMarkdown:r,onOpenTask:k,t:l}){const[p,v]=a.useState(null),m=ne(t),C=mt(l,m),x=t.title||l("documents.untitledArtifact","Untitled artifact"),w=W(t.id,i),b=m==="doc"&&Ds(t);a.useEffect(()=>{v(null)},[t.id]);const d=p?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:p}):null,j=m==="image"?e.jsxs(e.Fragment,{children:[d,e.jsx("img",{className:"documents-task-artifact-media",src:w,alt:x,onError:()=>v(l("documents.artifactMediaFailed","Failed to load artifact preview."))})]}):m==="video"?e.jsxs(e.Fragment,{children:[d,e.jsx("video",{className:"documents-task-artifact-media",controls:!0,src:w,"aria-label":l("documents.videoArtifactLabel","Video artifact: {{title}}",{title:x}),onError:()=>v(l("documents.artifactMediaFailed","Failed to load artifact preview."))})]}):m==="audio"?e.jsxs(e.Fragment,{children:[d,e.jsx("audio",{className:"documents-task-artifact-audio",controls:!0,src:w,"aria-label":l("documents.audioArtifactLabel","Audio artifact: {{title}}",{title:x}),onError:()=>v(l("documents.artifactMediaFailed","Failed to load artifact preview."))})]}):m==="pdf"?e.jsxs("div",{className:"documents-task-artifact-pdf",children:[e.jsx("iframe",{title:l("documents.pdfArtifactTitle","PDF artifact: {{title}}",{title:x}),src:w}),e.jsxs("a",{className:"btn btn-sm",href:w,target:"_blank",rel:"noreferrer",children:[e.jsx(Re,{size:14,"aria-hidden":"true"}),l("documents.openInNewTab","Open in new tab")]})]}):m==="doc"&&b?u?e.jsx("p",{className:"documents-content-state",children:e.jsx(de,{label:l("documents.loadingArtifactContent","Loading artifact content…")})}):o?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:o}):s?e.jsx("div",{className:"documents-content-markdown documents-task-artifact-doc-content",children:e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:n??t.content??""})})}):e.jsx("pre",{className:"document-card-content-text documents-content-viewer-text documents-task-artifact-doc-content",children:n??t.content??""}):e.jsxs("div",{className:"documents-task-artifact-download",children:[e.jsx(he,{size:24,"aria-hidden":"true"}),e.jsx("p",{children:t.description||l("documents.binaryArtifactFallback","This artifact cannot be previewed inline.")}),e.jsxs("a",{className:"btn btn-sm",href:w,target:"_blank",rel:"noreferrer","data-testid":"task-artifact-open-link",children:[e.jsx(lt,{size:14,"aria-hidden":"true"}),l("documents.openArtifact","Open artifact")]})]});return e.jsxs("div",{className:"documents-content-viewer documents-task-artifact-viewer",children:[e.jsxs("div",{className:"documents-content-header documents-task-document-header",children:[e.jsxs("p",{className:"documents-file-path-header",children:[t.taskId," / ",x]}),m==="doc"&&b?e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:r,"aria-label":s?l("documents.switchToPlainText","Switch to plain text"):l("documents.switchToMarkdown","Switch to markdown"),"aria-pressed":s,title:s?l("documents.switchToPlainText","Switch to plain text"):l("documents.switchToMarkdown","Switch to markdown"),children:s?l("documents.markdown","Markdown"):l("documents.plain","Plain")}):null]}),e.jsxs("div",{className:"document-card-meta documents-task-document-meta documents-task-artifact-meta",children:[e.jsx("span",{children:C}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{children:t.authorId||l("documents.unknownAuthor","unknown")}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{children:ae(t.updatedAt)}),t.taskId?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("button",{className:"documents-task-artifact-open-task",onClick:()=>void k(t.taskId),children:l("documents.openTask","Open task")})]}):null]}),t.description?e.jsx("p",{className:"documents-task-artifact-description",children:t.description}):null,e.jsx("div",{className:`documents-task-artifact-preview documents-task-artifact-preview--${m}`,children:j})]})}function Vs({projectId:t,addToast:i,onOpenDetail:n,onOpenArtifactTaskDetail:u,onSendSelectionToTask:o}){const{t:s}=dt("app"),[r,k]=a.useState("artifacts"),l=es(),[p,v]=a.useState(""),[m,C]=a.useState(null),[x,w]=a.useState(null),[b,d]=a.useState(!1),[j,y]=a.useState(null),[z,M]=a.useState(!1),[E,D]=a.useState(null),[A,U]=a.useState(!1),P=a.useRef(0),F=a.useRef(null),L=a.useRef(null),_e=a.useRef(null),Ue=a.useRef(null),[Y,Be]=a.useState(!1),[ht,Ke]=a.useState(new Map),[ft,I]=a.useState(null),[ke,R]=a.useState(""),[pe,xe]=a.useState(!1),[kt,$]=a.useState(null),[pt,B]=a.useState(!1),[xt,V]=a.useState(null),[jt,je]=a.useState(!0),ee=a.useRef(0),[we,G]=a.useState(!1),[ie,K]=a.useState(""),[ge,be]=a.useState(!1),[ce,qe]=a.useState(!1),wt=oe(F,{locked:ce}),gt=oe(L,{locked:ce}),bt=oe(_e,{locked:ce}),vt=oe(Ue,{locked:ce}),ve=Y?wt:gt,ye=r==="tasks"?p.trim():"",yt=r==="artifacts"?p.trim():"",{documents:te,loading:Nt,error:Ct,refresh:re}=hs({projectId:t,searchQuery:ye||void 0,includeProjectFiles:!1}),{files:Q,loading:St,error:Tt,refresh:We}=fs(t,{showHidden:b}),{artifacts:O,loading:At,error:Ft,refresh:Ne}=ts({projectId:t,searchQuery:yt||void 0});a.useEffect(()=>{const c=()=>{U(window.innerWidth<=Ss)};return c(),window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}},[]),a.useEffect(()=>{k("artifacts"),C(null),w(null),d(!1),y(null),D(null),M(!1),Be(!1),Ke(new Map),I(null),R(""),xe(!1),$(null),B(!1),V(null),je(!0),G(!1),K(""),be(!1)},[t]);const X=a.useMemo(()=>{const c=ye.toLowerCase(),h=new Map;for(const f of te){const S=h.get(f.taskId)??{documents:[],artifacts:[]};S.documents.push(f),h.set(f.taskId,S)}for(const f of O){if(!f.taskId||!Es(f,c))continue;const S=h.get(f.taskId)??{documents:[],artifacts:[]};S.artifacts.push(f),h.set(f.taskId,S)}return Array.from(h.entries()).map(([f,S])=>{const _=[...S.documents].sort((T,se)=>se.updatedAt.localeCompare(T.updatedAt)),q=[...S.artifacts].sort((T,se)=>se.updatedAt.localeCompare(T.updatedAt)),Fe=[_[0]?.updatedAt,q[0]?.updatedAt].filter(Boolean).sort().at(-1)??"",N=_.find(T=>T.taskTitle)?.taskTitle??q.find(T=>T.taskTitle)?.taskTitle;return{taskId:f,taskTitle:N,taskColumn:_.find(T=>T.taskColumn)?.taskColumn??q.find(T=>T.taskColumn)?.taskColumn,documents:_,artifacts:q,latestUpdated:Fe}}).filter(f=>f.documents.length>0||f.artifacts.length>0).sort((f,S)=>S.latestUpdated.localeCompare(f.latestUpdated))},[O,te,ye]),g=a.useMemo(()=>x?.kind!=="document"?null:te.find(c=>c.id===x.id)??null,[te,x]),H=a.useMemo(()=>x?.kind!=="artifact"?null:O.find(c=>c.id===x.id)??null,[O,x]),le=g??H;a.useEffect(()=>{if(!x)return;X.some(h=>x.kind==="document"?h.documents.some(f=>f.id===x.id):h.artifacts.some(f=>f.id===x.id))||(w(null),I(null),R(""),$(null),B(!1),V(null))},[X,x]);const Ce=a.useMemo(()=>{const c=p.trim().toLowerCase();return c?Q.filter(h=>{const f=h.path.toLowerCase(),S=h.name.toLowerCase();return f.includes(c)||S.includes(c)}):Q},[Q,p]);a.useEffect(()=>{if(!m)return;Q.some(h=>h.path===m.path)||(C(null),y(null),D(null),M(!1))},[Q,m]);const Et=a.useCallback(c=>{v(c.target.value)},[]),Dt=a.useCallback(()=>{v("")},[]),Se=a.useCallback(c=>{k(c),c!=="tasks"&&(w(null),I(null),R(""),$(null),B(!1),V(null)),c!=="project"&&(G(!1),K(""))},[]),Pt=a.useCallback(async c=>{try{const h=await tt(c,t);n(h)}catch{i(`Failed to open task ${c}`,"error")}},[t,n,i]),Ge=a.useCallback(async c=>{try{const h=await tt(c,t);(u??n)(h)}catch{i(`Failed to open task ${c}`,"error")}},[t,u,n,i]),Lt=a.useCallback(async c=>{C(c),M(!0),D(null),y(null),G(!1),K("");const h=P.current+1;P.current=h;try{const f=await ss("project",c.path,t);if(P.current!==h)return;y(f.content)}catch(f){if(P.current!==h)return;const S=f instanceof Error?f.message:`Failed to open ${c.path}`;D(S),i(S,"error")}finally{P.current===h&&M(!1)}},[t,i]),Mt=a.useCallback(()=>{C(null),y(null),D(null),M(!1),G(!1),K("")},[]),Rt=a.useCallback(()=>{j!==null&&(K(j),G(!0))},[j]),zt=a.useCallback(()=>{G(!1),K("")},[]),It=a.useCallback(async()=>{if(m){be(!0);try{await as("project",m.path,ie,t),y(ie),G(!1),K(""),i(s("documents.projectFileSaved","File saved"),"success")}catch(c){i(c instanceof Error?c.message:String(c),"error")}finally{be(!1)}}},[m,ie,t,i,s]),$t=a.useCallback(c=>{w({kind:"document",id:c}),I(null),R(""),$(null),B(!1),V(null)},[]),Vt=a.useCallback(c=>{w({kind:"artifact",id:c}),I(null),R(""),$(null),V(null),je(!0)},[]),Ot=a.useCallback(()=>{w(null),I(null),R(""),$(null),B(!1),V(null)},[]),Ht=a.useCallback(c=>{Ke(h=>{const f=new Map(h),S=f.get(c)??!0;return f.set(c,!S),f})},[]),_t=a.useCallback(()=>{g&&(R(g.content),I(g.id))},[g]),Ut=a.useCallback(()=>{I(null),R("")},[]),Bt=a.useCallback(async()=>{if(g){xe(!0);try{await ns(g.taskId,g.key,ke,{},t),await re(),I(null),R(""),i(s("documents.taskDocumentSaved","Document saved"),"success")}catch(c){i(c instanceof Error?c.message:String(c),"error")}finally{xe(!1)}}},[g,ke,t,re,i,s]);a.useEffect(()=>{if(!H||ne(H)!=="doc"){$(null),B(!1),V(null);return}const c=ee.current+1;ee.current=c,B(!0),V(null),$(null),rt(H.id,t).then(h=>{ee.current===c&&$(h.content??H.content??"")}).catch(h=>{ee.current===c&&V(h instanceof Error?h.message:String(h))}).finally(()=>{ee.current===c&&B(!1)})},[t,H]);const Qe=r==="project"?Tt:r==="tasks"?Ct:Ft,Kt=a.useCallback(async()=>{if(r==="project"){await We();return}if(r==="tasks"){await re();return}await Ne()},[r,Ne,We,re]),Ye=r==="project"?Ce.length:r==="tasks"?X.length:O.length,Z=g?ht.get(g.id)??!0:!1,Te=Z?bt:vt,Ae=g!==null&&ft===g.id,qt=r==="project"&&m&&!we&&o&&ve?e.jsx(st,{selectedText:ve.selectedText,anchorRect:ve.anchorRect,filePath:m.path,onSubmit:o,onOpenChange:qe}):null,Wt=r==="tasks"&&g&&!Ae&&o&&Te?e.jsx(st,{selectedText:Te.selectedText,anchorRect:Te.anchorRect,filePath:`${g.taskId}/${g.key}`,onSubmit:o,onOpenChange:qe}):null,Xe=r==="project"?s("documents.searchProjectFiles","Search project markdown files…"):r==="tasks"?s("documents.searchTaskDocuments","Search task documents…"):s("documents.searchArtifacts","Search artifacts…");return e.jsxs("div",{className:"documents-view",children:[e.jsxs("div",{className:"documents-view-header",children:[e.jsx(is,{icon:J,title:s("documents.title","Artifacts"),actions:e.jsx("span",{className:"documents-view-count",children:s("documents.resultCount","{{count}} result{{plural}}",{count:Ye,plural:Ye!==1?"s":""})})}),e.jsxs("div",{className:"documents-controls-row",children:[e.jsxs("div",{className:"documents-tab-bar",role:"tablist","aria-label":s("documents.sectionsLabel","Documents sections"),children:[e.jsxs("button",{className:`btn documents-tab${r==="artifacts"?" active":""}`,role:"tab","aria-selected":r==="artifacts","aria-label":s("documents.showArtifacts","Show artifacts"),onClick:()=>Se("artifacts"),children:[s("documents.artifactsTab","Artifacts"),e.jsx("span",{className:"documents-tab-count",children:O.length})]}),e.jsxs("button",{className:`btn documents-tab${r==="project"?" active":""}`,role:"tab","aria-selected":r==="project","aria-label":s("documents.showProjectFiles","Show project markdown files"),onClick:()=>Se("project"),children:[s("documents.projectFilesTab","Project Files"),e.jsx("span",{className:"documents-tab-count",children:Q.length})]}),e.jsxs("button",{className:`btn documents-tab${r==="tasks"?" active":""}`,role:"tab","aria-selected":r==="tasks","aria-label":s("documents.showTaskDocuments","Show task documents"),onClick:()=>Se("tasks"),children:[s("documents.taskDocumentsTab","Task Documents"),e.jsx("span",{className:"documents-tab-count",children:X.length})]})]}),r==="project"&&e.jsxs("button",{className:"btn btn-sm documents-hidden-toggle",onClick:()=>d(c=>!c),"aria-pressed":b,"aria-label":b?s("documents.hideHidden","Hide hidden project files"):s("documents.showHidden","Show hidden project files"),title:b?s("documents.hideHiddenFiles","Hide hidden files"):s("documents.showHiddenFiles","Show hidden files"),children:[b?e.jsx(cs,{size:14}):e.jsx(rs,{size:14}),b?s("documents.hideHiddenLabel","Hide Hidden"):s("documents.showHiddenLabel","Show Hidden")]}),e.jsxs("div",{className:"documents-search",children:[e.jsx(ls,{size:16,className:"documents-search-icon"}),e.jsx("input",{type:"text",className:"documents-search-input",placeholder:Xe,value:p,onChange:Et,"aria-label":Xe}),p&&e.jsx("button",{className:"documents-search-clear",onClick:Dt,"aria-label":s("documents.clearSearch","Clear search"),children:e.jsx(ot,{size:16})})]})]})]}),e.jsx("div",{className:"documents-view-content",children:Qe?e.jsxs("div",{className:"documents-view-error",children:[e.jsx("p",{children:s("documents.failedToLoad","Failed to load {{type}}: {{error}}",{type:r==="project"?s("documents.projectFiles","project files"):r==="tasks"?s("documents.taskDocuments","task documents"):s("documents.artifacts","artifacts"),error:Qe})}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void Kt(),"aria-label":s("documents.retryLoading","Retry loading documents"),children:[e.jsx(os,{size:16}),s("documents.retry","Retry")]})]}):r==="project"?St&&Q.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:e.jsx(de,{label:s("documents.loadingProjectFiles","Loading project markdown files…")})})}):Ce.length===0?e.jsx("div",{className:"documents-view-empty",children:p.trim()?e.jsx("p",{children:s("documents.noMatchProject",'No project markdown files match "{{query}}".',{query:p.trim()})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:s("documents.noMarkdownFiles","No Markdown files found in this project.")})]})}):e.jsxs("div",{className:`documents-project-layout${A?" documents-project-layout--mobile":""}`,children:[(!A||!m)&&e.jsx("aside",{className:"documents-view-sidebar","aria-label":s("documents.projectMarkdownFilesLabel","Project markdown files"),children:e.jsx("ul",{className:"markdown-file-list",children:Ce.map(c=>{const h=m?.path===c.path;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item${h?" markdown-file-item--selected":""}`,onClick:()=>void Lt(c),"aria-label":`Open ${c.path}`,"aria-current":h?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:c.name}),e.jsx("span",{className:"markdown-file-item-path",children:c.path}),e.jsxs("span",{className:"markdown-file-item-meta",children:[As(c.size)," · ",ae(c.mtime)]})]})},c.path)})})}),(!A||m)&&e.jsxs("section",{className:"documents-view-main","aria-label":s("documents.projectFilePreviewLabel","Project file content preview"),children:[A&&m&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:Mt,"aria-label":s("documents.backToFilesList","Back to project files list"),children:[e.jsx(at,{size:14}),s("documents.backToFiles","Back to files")]}),m?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:m.path}),e.jsx("div",{className:"documents-task-document-actions",children:we?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:zt,disabled:ge,children:s("documents.cancelEdit","Cancel")}),e.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void It(),disabled:ge,children:ge?s("documents.saving","Saving…"):s("documents.saveProjectFile","Save")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>Be(c=>!c),"aria-label":Y?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),"aria-pressed":Y,title:Y?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),children:Y?s("documents.markdown","Markdown"):s("documents.plain","Plain")}),e.jsxs("button",{className:"btn btn-sm",onClick:Rt,disabled:z||E!==null||j===null,"aria-label":s("documents.editProjectFile","Edit project file"),children:[e.jsx(De,{size:14,"aria-hidden":"true"}),s("documents.edit","Edit")]})]})})]}),z?e.jsx("p",{className:"documents-content-state",children:e.jsx(de,{label:s("documents.loadingFileContent","Loading file content…")})}):E?e.jsx("p",{className:"documents-content-state documents-content-state--error",children:E}):we?e.jsx("div",{className:"documents-task-document-editor","aria-label":s("documents.projectFileContentEditor","Project file content editor"),children:e.jsx(Pe,{content:ie,onChange:K,filePath:m.path,forceToolbarActionsVisible:!0})}):Y?e.jsx("div",{ref:F,className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:j??""})})}):e.jsx("pre",{ref:L,className:"document-card-content-text documents-content-viewer-text",children:j??""}),qt]}):e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:s("documents.selectFile","Select a Markdown file to view its content.")})})]})]}):r==="artifacts"?At&&O.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:s("documents.loadingArtifacts","Loading artifacts…")})}):O.length===0?e.jsx("div",{className:"documents-view-empty",children:p.trim()?e.jsx("p",{children:s("documents.noMatchArtifacts",'No artifacts match "{{query}}".',{query:p.trim()})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:s("documents.noArtifacts","No artifacts yet.")}),e.jsx("p",{className:"documents-view-empty-hint",children:s("documents.artifactsCreatedBy","Agents register screenshots, wireframes, mockups, recordings, and documents here as they work on tasks.")})]})}):e.jsx(ks,{artifacts:O,projectId:t,isMobile:A,addToast:i,onOpenTask:Ge,onArtifactUpdated:()=>void Ne()}):Nt&&te.length===0?e.jsx("div",{className:"documents-view-loading",children:e.jsx("p",{children:e.jsx(de,{label:s("documents.loadingTaskDocuments","Loading task documents…")})})}):X.length===0?e.jsx("div",{className:"documents-view-empty",children:p.trim()?e.jsx("p",{children:s("documents.noMatchTask",'No task documents match "{{query}}".',{query:p.trim()})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{size:48,className:"documents-view-empty-icon"}),e.jsx("p",{children:s("documents.noTaskDocuments","No task documents yet.")}),e.jsx("p",{className:"documents-view-empty-hint",children:s("documents.documentsCreatedIn","Documents are created in task detail tabs.")})]})}):e.jsxs("div",{className:`documents-project-layout documents-task-documents-layout${A?" documents-project-layout--mobile":""}`,children:[(!A||!le)&&e.jsx("aside",{className:"documents-view-sidebar documents-task-documents-sidebar","aria-label":s("documents.taskDocumentsListLabel","Task documents"),children:X.map(({taskId:c,taskTitle:h,taskColumn:f,documents:S,artifacts:_})=>{const q=f?l(f):null,Fe=f?Fs(f):"status-dot";return e.jsxs("section",{className:"documents-task-sidebar-group","aria-labelledby":`documents-task-group-${c}`,children:[e.jsxs("div",{className:"documents-task-sidebar-group-header",children:[e.jsxs("div",{className:"documents-task-sidebar-title-wrap",children:[e.jsxs("h3",{id:`documents-task-group-${c}`,className:"documents-task-sidebar-title",children:[e.jsx("span",{className:"documents-group-task-id",children:c}),e.jsx("span",{className:"documents-group-task-title",children:h||s("documents.untitled","Untitled")})]}),q?e.jsxs("span",{className:"documents-group-status badge","aria-label":s("documents.taskStatusAria","Task status: {{status}}",{status:q}),children:[e.jsx("span",{className:Fe,"aria-hidden":"true"}),e.jsx("span",{children:q})]}):null]}),e.jsxs("div",{className:"documents-task-sidebar-actions",children:[e.jsx("span",{className:"documents-group-count",children:s("documents.taskOutputCount","{{docCount}} doc{{docPlural}} · {{artifactCount}} artifact{{artifactPlural}}",{docCount:S.length,docPlural:S.length!==1?"s":"",artifactCount:_.length,artifactPlural:_.length!==1?"s":""})}),e.jsx("button",{className:"documents-group-task-link",onClick:()=>void Pt(c),"aria-label":s("documents.openTaskAria","Open task {{taskId}}: {{title}}",{taskId:c,title:h||s("documents.untitled","Untitled")}),children:s("documents.openTask","Open task")})]})]}),e.jsxs("ul",{className:"markdown-file-list documents-task-document-list",children:[S.map(N=>{const T=g?.id===N.id;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item documents-task-document-item${T?" markdown-file-item--selected":""}`,onClick:()=>$t(N.id),"aria-label":s("documents.openTaskDocument","Open {{taskId}} {{key}}",{taskId:N.taskId,key:N.key}),"aria-current":T?"true":void 0,children:[e.jsx("span",{className:"markdown-file-item-name",children:N.key}),e.jsxs("span",{className:"markdown-file-item-path",children:[N.taskId," · ",N.taskTitle||s("documents.untitled","Untitled")]}),e.jsxs("span",{className:"markdown-file-item-meta",children:[s("documents.revisionShort","v{{revision}}",{revision:N.revision})," · ",N.author," · ",ae(N.updatedAt)]})]})},`document-${N.id}`)}),_.length>0?e.jsxs("li",{className:"documents-task-artifacts-subsection","aria-label":s("documents.taskArtifactsSubsection","Task artifacts"),children:[e.jsx("div",{className:"documents-task-artifacts-label",children:s("documents.taskArtifactsLabel","Artifacts")}),e.jsx("ul",{className:"markdown-file-list documents-task-artifact-list",children:_.map(N=>{const T=ne(N),se=Ts[T],Gt=mt(s,T),Ze=H?.id===N.id;return e.jsx("li",{className:"markdown-file-list-item",children:e.jsxs("button",{className:`markdown-file-item documents-task-document-item documents-task-artifact-item${Ze?" markdown-file-item--selected":""}`,onClick:()=>Vt(N.id),"aria-label":s("documents.openTaskArtifact","Open {{taskId}} artifact {{title}}",{taskId:c,title:N.title||s("documents.untitledArtifact","Untitled artifact")}),"aria-current":Ze?"true":void 0,children:[e.jsxs("span",{className:"documents-task-artifact-title-row",children:[e.jsx(se,{size:14,"aria-hidden":"true"}),e.jsx("span",{className:"markdown-file-item-name",children:N.title||s("documents.untitledArtifact","Untitled artifact")})]}),e.jsxs("span",{className:"markdown-file-item-path",children:[Gt," · ",N.mimeType||N.type]}),e.jsxs("span",{className:"markdown-file-item-meta",children:[N.authorId||s("documents.unknownAuthor","unknown")," · ",ae(N.updatedAt)]})]})},`artifact-${N.id}`)})})]}):null]})]},c)})}),(!A||le)&&e.jsxs("section",{className:"documents-view-main","aria-label":s("documents.taskDocumentPreviewLabel","Task document content preview"),children:[A&&le&&e.jsxs("button",{className:"btn btn-sm documents-mobile-back",onClick:Ot,"aria-label":s("documents.backToTaskDocumentsList","Back to task documents list"),children:[e.jsx(at,{size:14}),s("documents.backToTaskDocuments","Back to documents")]}),le?H?e.jsx(Ps,{artifact:H,projectId:t,content:kt,loading:pt,error:xt,renderMarkdown:jt,onToggleMarkdown:()=>je(c=>!c),onOpenTask:Ge,t:s}):g?e.jsxs("div",{className:"documents-content-viewer documents-task-document-viewer",children:[e.jsxs("div",{className:"documents-content-header documents-task-document-header",children:[e.jsxs("p",{className:"documents-file-path-header",children:[g.taskId," / ",g.key]}),e.jsx("div",{className:"documents-task-document-actions",children:Ae?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm",onClick:Ut,disabled:pe,children:s("documents.cancelEdit","Cancel")}),e.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void Bt(),disabled:pe,children:pe?s("documents.saving","Saving…"):s("documents.saveTaskDocument","Save")})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm document-mode-toggle",onClick:()=>Ht(g.id),"aria-label":Z?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),"aria-pressed":Z,title:Z?s("documents.switchToPlainText","Switch to plain text"):s("documents.switchToMarkdown","Switch to markdown"),children:Z?s("documents.markdown","Markdown"):s("documents.plain","Plain")}),e.jsxs("button",{className:"btn btn-sm",onClick:_t,"aria-label":s("documents.editTaskDocument","Edit task document"),children:[e.jsx(De,{size:14,"aria-hidden":"true"}),s("documents.edit","Edit")]})]})})]}),e.jsxs("div",{className:"document-card-meta documents-task-document-meta",children:[e.jsx("span",{className:"document-card-author",children:g.author}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{children:s("documents.revisionShort","v{{revision}}",{revision:g.revision})}),e.jsx("span",{className:"document-card-separator",children:"·"}),e.jsx("span",{className:"document-card-date",children:ae(g.updatedAt)})]}),Ae?e.jsx("div",{className:"documents-task-document-editor","aria-label":s("documents.taskDocumentContentEditor","Task document content editor"),children:e.jsx(Pe,{content:ke,onChange:R,filePath:g.key.includes(".")?g.key:`${g.key}.md`,forceToolbarActionsVisible:!0})}):Z?e.jsx("div",{ref:_e,className:"documents-content-markdown",children:e.jsx("div",{className:"markdown-body",children:e.jsx(ue,{remarkPlugins:[me],children:g.content})})}):e.jsx("pre",{ref:Ue,className:"document-card-content-text documents-content-viewer-text",children:g.content}),Wt]}):null:e.jsx("div",{className:"documents-view-empty",children:e.jsx("p",{children:s("documents.selectTaskDocument","Select a task document or artifact to view its content.")})})]})]})})]})}export{Vs as DocumentsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e}from"./vendor-react-SZ_qB27O.js";import{
|
|
1
|
+
import{r as l,j as e}from"./vendor-react-SZ_qB27O.js";import{aC as F,aD as L,aE as $,aF as J,aG as Y,aH as D,aI as Q,aJ as Z,V as H,T as B,O as ee,R as se,a9 as ae,a7 as te}from"./index-inWk2g6R.js";import{u as le}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";const re=300,ne=15e3;function K(r){if(!r.trim())return;const s=Number(r);return Number.isFinite(s)?s:void 0}function w(...r){for(const s of r)if(Array.isArray(s))return s;return[]}function f(r){return typeof r=="object"&&r!==null?r:{}}function X(r){const s=f(r),m=f(s.taskSnapshot);return{id:String(s.id??s.evalId??""),runId:String(s.runId??s.batchId??""),taskId:String(s.taskId??m.taskId??""),taskTitle:String(m.title??s.taskTitle??s.title??"Untitled task"),createdAt:String(s.createdAt??s.timestamp??s.updatedAt??new Date(0).toISOString()),overallScore:typeof s.overallScore=="number"?s.overallScore:null,maxScore:typeof s.maxScore=="number"?s.maxScore:null,categoryScores:w(s.categoryScores,f(s.scores).categories)}}function ce(r){const s=f(r);return{...X(s),rationale:String(s.rationale??s.summary??""),evidence:w(s.evidence,f(s.details).evidence),followUps:w(s.followUps,f(s.recommendations).followUps)}}function ie(r){const s=r?.projectId,m=s??"",t=`${$.EVALS_RUNS_PREFIX}${m}`,h=`${$.EVALS_RESULTS_PREFIX}${m}`,p=F(t,{maxAgeMs:L}),v=F(h,{maxAgeMs:L}),S=l.useRef(Array.isArray(p)&&p.length>0||Array.isArray(v)&&v.length>0),[i,g]=l.useState({q:"",runId:"",scoreMin:"",scoreMax:""}),[A,k]=l.useState(()=>Array.isArray(p)?p:[]),[o,C]=l.useState(()=>Array.isArray(v)?v:[]),[u,R]=l.useState(null),[P,b]=l.useState(null),[a,d]=l.useState(0),[y,j]=l.useState(!S.current),[G,q]=l.useState(null),M=l.useRef(0),z=l.useRef(s),_=l.useRef(u);_.current=u;const I=l.useCallback(async()=>{const n=++M.current;S.current||j(!0),q(null);try{const[c,x]=await Promise.all([J({q:i.q||void 0,runId:i.runId||void 0,scoreMin:K(i.scoreMin),scoreMax:K(i.scoreMax),limit:100,offset:0},s),Y(s)]);if(n!==M.current)return;const E=w(c.results,c.evals,c.items).map(X);C(E),D(h,E.length>500?E.slice(0,500):E,{maxBytes:5e5}),d(typeof c.count=="number"?c.count:E.length);const O=w(x.runs,x.items).map(U=>{const N=f(U),V=f(N.counts);return{id:String(N.id??""),createdAt:String(N.createdAt??""),completedAt:typeof N.completedAt=="string"?N.completedAt:void 0,status:String(N.status??"pending"),evaluatedTaskCount:typeof V.totalTasks=="number"?V.totalTasks:0}});k(O),D(t,O,{maxBytes:5e5}),S.current=!0,_.current&&!E.some(U=>U.id===_.current)&&(R(null),b(null))}catch(c){if(n!==M.current)return;q(c instanceof Error?c.message:"Failed to load evals")}finally{n===M.current&&j(!1)}},[i.q,i.runId,i.scoreMax,i.scoreMin,s,h,t]),T=l.useCallback(async n=>{const c=await Q(n,s),x=c.result??c;b(ce(x))},[s]);l.useEffect(()=>{if(z.current===s)return;z.current=s;const n=F(t,{maxAgeMs:L}),c=F(h,{maxAgeMs:L}),x=Array.isArray(n)&&n.length>0||Array.isArray(c)&&c.length>0;k(Array.isArray(n)?n:[]),C(Array.isArray(c)?c:[]),j(!x),S.current=x},[s,h,t]),l.useEffect(()=>{const n=window.setTimeout(()=>{I()},re);return()=>window.clearTimeout(n)},[I]),l.useEffect(()=>{if(!u){b(null);return}T(u)},[T,u]),l.useEffect(()=>{const n=window.setInterval(()=>{I(),u&&T(u)},ne);return()=>window.clearInterval(n)},[T,I,u]);const W=l.useCallback(n=>{_.current=n,R(n)},[]);return{loading:y,error:G,results:o,count:a,runs:A,filters:i,setFilters:g,refresh:I,selectedEvalId:u,setSelectedEvalId:W,selectedEval:P}}function xe({projectId:r,onOpenSettings:s,onOpenTaskDetail:m}){const{t}=le("app"),{loading:h,error:p,results:v,runs:S,filters:i,setFilters:g,selectedEvalId:A,setSelectedEvalId:k,selectedEval:o,refresh:C}=ie({projectId:r}),[u,R]=l.useState(!0);l.useEffect(()=>{let a=!1;return Z(r).then(d=>{if(a)return;const y=d.evalSettings?.enabled;R(y??!1)}).catch(()=>{a||R(!1)}),()=>{a=!0}},[r]);const P=v.length>0,b=l.useMemo(()=>v.find(a=>a.id===A)??null,[v,A]);return u?e.jsxs("section",{className:"evals-view","data-testid":"evals-view",children:[e.jsx(H,{icon:B,title:t("evals.title","Evals")}),e.jsxs("div",{className:"evals-view__body",children:[e.jsxs("div",{className:"evals-list card",children:[e.jsxs("div",{className:"evals-toolbar",children:[e.jsx("input",{className:"input",placeholder:t("evals.searchPlaceholder","Search task or rationale"),value:i.q,onChange:a=>g(d=>({...d,q:a.target.value}))}),e.jsxs("select",{className:"select",value:i.runId,onChange:a=>g(d=>({...d,runId:a.target.value})),children:[e.jsx("option",{value:"",children:t("evals.allRuns","All runs")}),S.map(a=>e.jsx("option",{value:a.id,children:a.id},a.id))]}),e.jsx("input",{className:"input",placeholder:t("evals.minScorePlaceholder","Min score"),value:i.scoreMin,onChange:a=>g(d=>({...d,scoreMin:a.target.value}))}),e.jsx("input",{className:"input",placeholder:t("evals.maxScorePlaceholder","Max score"),value:i.scoreMax,onChange:a=>g(d=>({...d,scoreMax:a.target.value}))}),e.jsx("button",{className:"btn btn-icon",type:"button",onClick:()=>void C(),"aria-label":t("evals.refreshAria","Refresh evals"),children:e.jsx(se,{size:16})})]}),h&&e.jsx("p",{className:"evals-state","data-testid":"evals-loading",children:e.jsx(ae,{label:t("evals.loading","Loading evals…")})}),p&&e.jsx("p",{className:"evals-state evals-state--error",children:p}),!h&&!p&&!P&&e.jsx("p",{className:"evals-state",children:t("evals.empty","No evals yet. Scheduled evals review tasks completed since the last run.")}),e.jsx("ul",{className:"evals-results","data-testid":"evals-results",children:v.map(a=>e.jsx("li",{children:e.jsxs("button",{className:`evals-result ${a.id===A?"evals-result--active":""}`,type:"button",onClick:()=>k(a.id),children:[e.jsx("span",{className:"evals-result-title",children:a.taskTitle}),e.jsxs("span",{className:"evals-result-meta",children:[a.taskId," · ",a.runId," · ",a.overallScore??t("evals.naPlaceholder","n/a")]})]})},a.id))})]}),e.jsxs("div",{className:"evals-detail card","data-testid":"evals-detail",children:[!o&&e.jsx("p",{className:"evals-state",children:t("evals.selectPrompt","Select an evaluation to inspect scores, rationale, and evidence.")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"evals-detail-title",children:b?.taskTitle??o.taskTitle}),e.jsxs("p",{className:"evals-result-meta",children:[o.taskId," · ",o.runId]}),e.jsx("p",{className:"evals-score",children:t("evals.overallScore","Overall score: {{score}}",{score:o.overallScore??t("evals.naPlaceholder","n/a")})}),e.jsx("ul",{className:"evals-categories",children:o.categoryScores.map(a=>e.jsxs("li",{children:[a.category,": ",a.finalScore]},a.category))}),e.jsx("p",{className:"evals-rationale",children:o.rationale||t("evals.noRationale","No rationale recorded.")}),e.jsxs("div",{children:[e.jsx("h4",{children:t("evals.evidenceHeading","Evidence")}),e.jsx("ul",{className:"evals-links",children:o.evidence.map((a,d)=>{const y=typeof a.metadata?.taskId=="string"?a.metadata.taskId:void 0,j=typeof a.metadata?.url=="string"?a.metadata.url:void 0;return e.jsx("li",{children:y?e.jsx("button",{type:"button",className:"btn",onClick:()=>m?.(y),children:a.ref}):j?e.jsxs("a",{href:j,target:"_blank",rel:"noreferrer",className:"evals-external-link",children:[a.ref,e.jsx(te,{size:14})]}):e.jsx("span",{children:a.ref})},`${a.ref}-${d}`)})})]}),e.jsxs("div",{children:[e.jsx("h4",{children:t("evals.suggestedFollowupsHeading","Suggested follow-up tasks")}),e.jsxs("ul",{className:"evals-follow-ups",children:[o.followUps.length===0&&e.jsx("li",{children:t("evals.noFollowups","None")}),o.followUps.map(a=>e.jsxs("li",{children:[e.jsx("strong",{children:a.title}),e.jsx("p",{children:a.rationale})]},a.suggestionId))]})]})]})]})]})]}):e.jsxs("section",{className:"evals-view","data-testid":"evals-disabled",children:[e.jsx(H,{icon:B,title:t("evals.title","Evals")}),e.jsxs("div",{className:"evals-view__empty",children:[e.jsx("h2",{className:"evals-title",children:t("evals.disabledTitle","Scheduled evals are disabled")}),e.jsx("p",{className:"evals-empty-copy",children:t("evals.enablePrompt","Enable Scheduled Evals to review scored tasks, evidence, and follow-up recommendations.")}),e.jsxs("button",{className:"btn btn-primary",type:"button",onClick:()=>s?.("scheduled-evals"),children:[e.jsx(ee,{size:16}),t("evals.openSettings","Open Scheduled Evals Settings")]})]})]})}export{xe as EvalsView};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as s,j as n}from"./vendor-react-SZ_qB27O.js";import{w as F,x as V,y as W,z,B,D as G}from"./index-inWk2g6R.js";import{u as U}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";function en({isOpen:l,onClose:R,onUseDraft:M,projectId:x,existingAgents:P,mode:_="create",existingAgentConfig:L}){const{t:e}=U("app"),[m,d]=s.useState("initial"),[f,S]=s.useState(""),[c,k]=s.useState(null),[C,w]=s.useState(""),[I,A]=s.useState("answer"),[v,p]=s.useState(""),[t,T]=s.useState(null),[H,g]=s.useState(null),[E,y]=s.useState([]),b=_==="edit",o=s.useRef(l),N=s.useCallback(()=>{d("initial"),S(""),k(null),w(""),A("answer"),p(""),T(null),g(null),y([])},[]),D=s.useMemo(()=>F.map(a=>({id:a.id,label:a.name,description:a.description})),[]);s.useEffect(()=>{if(o.current=l,!c)return;const a=V(c,x,{onThinking:i=>{o.current&&y($=>{const h=[...$],j=h[h.length-1];return j&&!j.question?(h[h.length-1]={...j,thinkingOutput:`${j.thinkingOutput??""}${i}`},h):[...h,{response:{},thinkingOutput:i}]})},onQuestion:i=>{o.current&&(w(i.question),A(i.id),d("question"))},onSummary:i=>{o.current&&(T(i),d("summary"))},onError:i=>{o.current&&(g(i),d("error"))}});return()=>{o.current=!1,a.close()}},[l,c,x]);const u=async()=>{o.current=!1;try{c&&await z(c,x)}catch{}finally{N(),R()}};if(s.useEffect(()=>{o.current=l,l||N()},[l,N]),!l)return null;const r=a=>a==null||a===""?n.jsx("em",{className:"experimental-agent-onboarding-modal__summary-empty",children:e("agents.onboarding.notSet","Not set")}):n.jsx("span",{children:a}),q=async()=>{d("loading"),g(null);try{const a=await B(f,{mode:_,existingAgentConfig:L,existingAgents:P.map(i=>({id:i.id,name:i.name,role:i.role})),templates:D},x);if(!o.current)return;k(a.sessionId)}catch(a){if(!o.current)return;g(a.message),d("error")}},Q=async()=>{if(c){d("loading"),g(null);try{const a={[I]:v};if(y(i=>[...i,{question:{id:I,type:"text",question:C},response:a}]),await G(c,a,x),!o.current)return;p("")}catch(a){if(!o.current)return;g(a.message),d("error")}}},O=async()=>{t&&(M(t),await u())};return n.jsx("div",{className:"modal-overlay open",role:"presentation",children:n.jsxs("div",{className:"modal modal-lg experimental-agent-onboarding-modal",role:"dialog","aria-modal":"true","aria-label":e("agents.onboarding.dialogLabel","AI Interview"),children:[n.jsxs("div",{className:"modal-header",children:[n.jsx("h3",{children:e("agents.onboarding.title","AI Interview")}),n.jsx("button",{className:"modal-close",onClick:()=>void u(),"aria-label":e("common.closeAriaLabel","Close"),children:"×"})]}),E.length>0&&n.jsx(W,{entries:E}),m==="initial"&&n.jsxs("div",{className:"form-group",children:[n.jsx("label",{htmlFor:"agent-onboarding-intent",children:b?e("agents.onboarding.intentLabelEdit","What should this agent change or improve?"):e("agents.onboarding.intentLabelCreate","What should this new agent own?")}),n.jsx("textarea",{id:"agent-onboarding-intent",className:"input experimental-agent-onboarding-modal__textarea",value:f,onChange:a=>S(a.target.value)}),n.jsxs("div",{className:"modal-actions",children:[n.jsx("button",{className:"btn",onClick:()=>void u(),children:e("common.cancel","Cancel")}),n.jsx("button",{className:"btn btn-primary",disabled:!f.trim(),onClick:()=>void q(),children:b?e("agents.onboarding.startInterview","Start interview"):e("agents.onboarding.startOnboarding","Start onboarding")})]})]}),(m==="loading"||m==="question")&&n.jsxs("div",{className:"form-group",children:[n.jsx("label",{htmlFor:"agent-onboarding-answer",children:C||e("agents.onboarding.thinking","Thinking...")}),n.jsx("textarea",{id:"agent-onboarding-answer",className:"input experimental-agent-onboarding-modal__textarea",value:v,onChange:a=>p(a.target.value)}),n.jsxs("div",{className:"modal-actions",children:[n.jsx("button",{className:"btn",onClick:()=>void u(),children:e("common.cancel","Cancel")}),n.jsx("button",{className:"btn btn-primary",disabled:m==="loading"||!v.trim(),onClick:()=>void Q(),children:e("agents.onboarding.continue","Continue")})]})]}),m==="summary"&&t&&n.jsxs("div",{className:"form-group",children:[n.jsx("label",{children:b?e("agents.onboarding.updatedDraftReady","Updated draft ready for review"):e("agents.onboarding.draftReady","Draft ready for review")}),n.jsx("p",{className:"experimental-agent-onboarding-modal__summary-intro",children:e("agents.onboarding.draftIntro","Review this generated draft. Nothing is applied until you confirm.")}),n.jsxs("div",{className:"experimental-agent-onboarding-modal__summary card",children:[n.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[n.jsx("h4",{children:e("agents.onboarding.sectionIdentity","Identity")}),n.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldName","Name")}),n.jsx("dd",{children:r(t.name)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldRole","Role")}),n.jsx("dd",{children:r(t.role)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldTitle","Title")}),n.jsx("dd",{children:r(t.title)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldIcon","Icon")}),n.jsx("dd",{children:r(t.icon)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldReportsTo","Reports To")}),n.jsx("dd",{children:r(t.reportsTo)})]})]})]}),n.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[n.jsx("h4",{children:e("agents.onboarding.sectionConfiguration","Configuration")}),n.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldInlineInstructions","Inline Instructions")}),n.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:r(t.instructionsText)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldSoul","Soul")}),n.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:r(t.soul)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldAgentMemory","Agent Memory")}),n.jsx("dd",{className:"experimental-agent-onboarding-modal__summary-block",children:r(t.memory)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldSkills","Skills")}),n.jsx("dd",{children:r(t.skills?.join(", "))})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldThinkingLevel","Thinking Level")}),n.jsx("dd",{children:r(t.thinkingLevel)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldMaxTurns","Max Turns")}),n.jsx("dd",{children:r(t.maxTurns)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldTemplate","Template")}),n.jsx("dd",{children:r(t.templateId)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldPatternAgent","Pattern Agent")}),n.jsx("dd",{children:r(t.patternAgentId)})]})]})]}),(t.heartbeatProcedurePath||t.heartbeatIntervalMs||t.heartbeatEnabled!==void 0||t.modelHint||t.runtimeHint)&&n.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[n.jsx("h4",{children:e("agents.onboarding.sectionRuntimeHints","Runtime Hints")}),n.jsxs("dl",{className:"experimental-agent-onboarding-modal__summary-list",children:[n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldHeartbeatPath","Heartbeat Procedure Path")}),n.jsx("dd",{children:r(t.heartbeatProcedurePath)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldHeartbeatInterval","Heartbeat Interval")}),n.jsx("dd",{children:r(t.heartbeatIntervalMs?`${t.heartbeatIntervalMs}ms`:void 0)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldHeartbeatEnabled","Heartbeat Enabled")}),n.jsx("dd",{children:r(t.heartbeatEnabled===void 0?void 0:t.heartbeatEnabled?e("agents.onboarding.yes","yes"):e("agents.onboarding.no","no"))})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldModelHint","Model Hint")}),n.jsx("dd",{children:r(t.modelHint)})]}),n.jsxs("div",{children:[n.jsx("dt",{children:e("agents.onboarding.fieldRuntimeHint","Runtime Hint")}),n.jsx("dd",{children:r(t.runtimeHint)})]})]})]}),t.rationale&&n.jsxs("div",{className:"experimental-agent-onboarding-modal__summary-section",children:[n.jsx("h4",{children:e("agents.onboarding.sectionRationale","Rationale")}),n.jsx("p",{className:"experimental-agent-onboarding-modal__summary-block",children:t.rationale})]})]}),n.jsxs("div",{className:"modal-actions",children:[n.jsx("button",{className:"btn",onClick:()=>void u(),children:e("common.cancel","Cancel")}),n.jsx("button",{className:"btn btn-primary",onClick:()=>void O(),children:b?e("agents.onboarding.applyDraftSettings","Apply draft to settings form"):e("agents.onboarding.applyDraftAgent","Apply draft to agent form")})]})]}),m==="error"&&H&&n.jsxs("div",{className:"form-group",children:[n.jsx("div",{className:"form-error",children:H}),n.jsx("div",{className:"modal-actions",children:n.jsx("button",{className:"btn",onClick:()=>void u(),children:e("common.close","Close")})})]})]})})}export{en as ExperimentalAgentOnboardingModal};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as n,j as t}from"./vendor-react-SZ_qB27O.js";import{V as js,T as ws,P as Ns,S as Es,h as Ss,r as $s,j as Ms,X as Cs,k as Ts,l as As}from"./index-
|
|
1
|
+
import{r as n,j as t}from"./vendor-react-SZ_qB27O.js";import{V as js,T as ws,P as Ns,S as Es,h as Ss,r as $s,j as Ms,X as Cs,k as Ts,l as As}from"./index-inWk2g6R.js";import{u as Gs}from"./vendor-i18n-GF3RlKbq.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.js";const Ls=5,Ds=3,Ps=280;function h(r,m){if(!m)return r;const d=r.includes("?")?"&":"?";return`${r}${d}projectId=${encodeURIComponent(m)}`}function is(r){return!!(r&&typeof r=="object"&&"code"in r&&r.code==="ACTIVE_GOAL_LIMIT_EXCEEDED")}function qs({initialGoals:r,anchorGoalId:m,projectId:d,onNavigateToMission:as}){const{t:a}=Gs("app"),[c,k]=n.useState(()=>r??[]),[ns,j]=n.useState(null),p=n.useRef(null),[w,L]=n.useState(r===void 0),[D,l]=n.useState(null),[os,P]=n.useState(!1),[y,F]=n.useState(""),[U,N]=n.useState(""),[R,u]=n.useState(null),[O,_]=n.useState(!1),[v,E]=n.useState(!1),[S,V]=n.useState(null),[q,$]=n.useState(""),[B,M]=n.useState(""),[H,f]=n.useState(null),[I,W]=n.useState(!1),[ls,rs]=n.useState(()=>new Set),[ds,cs]=n.useState([]),[x,C]=n.useState({}),[T,z]=n.useState({}),[A,K]=n.useState(null),[us,X]=n.useState(null);n.useEffect(()=>{if(r!==void 0)return;let s=!0;return(async()=>{try{L(!0),l(null);const i=await fetch(h("/api/goals",d));if(!i.ok)throw new Error(`Failed to load goals (${i.status})`);const o=await i.json();if(!s)return;k(Array.isArray(o.goals)?o.goals:[])}catch{if(!s)return;l(a("goals.loadError","Unable to load goals right now. Please try again."))}finally{s&&L(!1)}})(),()=>{s=!1}},[r,d]),n.useEffect(()=>{let s=!0;return(async()=>{try{const i=await fetch(h("/api/missions",d));if(!i.ok)throw new Error(`Failed to load missions (${i.status})`);const o=await i.json(),g=Array.isArray(o)?o:Array.isArray(o.missions)?o.missions:[];s&&cs(g.map(b=>({id:b.id,title:b.title,status:b.status})))}catch{s&&l(a("goals.missionsLoadError","Unable to load missions right now. Please try again."))}})(),()=>{s=!1}},[d,a]);const J=async s=>{const e=await fetch(h(`/api/goals/${encodeURIComponent(s)}/missions`,d));if(!e.ok)throw new Error(`Failed to load linked missions (${e.status})`);const i=await e.json();return Array.isArray(i.missions)?i.missions:[]};n.useEffect(()=>{let s=!0;return(async()=>{if(c.length===0){C({});return}try{const i=await Promise.all(c.map(async o=>[o.id,await J(o.id)]));s&&C(Object.fromEntries(i))}catch{s&&l(a("goals.linkedMissionsLoadError","Unable to load linked missions right now. Please try again."))}})(),()=>{s=!1}},[c,a]);const G=n.useMemo(()=>c.filter(s=>s.status==="active").length,[c]),gs=G>=Ds&&G<=Ls;n.useEffect(()=>{if(!m){j(null);return}const s=document.getElementById(`goal-card-${m}`);if(s)return j(m),typeof s.scrollIntoView=="function"&&s.scrollIntoView({behavior:"smooth",block:"center"}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{j(e=>e===m?null:e),p.current=null},1600),()=>{p.current&&(clearTimeout(p.current),p.current=null)}},[m,c]);function ms(){l(null),u(null),P(!0)}function hs(s){V(s.id),$(s.title),M(s.description??""),f(null)}function Q(){V(null),$(""),M(""),f(null)}function Y(){P(!1),F(""),N(""),u(null),E(!1)}async function ps(){const s=y.trim();if(!s){u(a("goals.titleRequired","Title is required."));return}try{E(!0),u(null);const e=await Ts(s,d);N(e)}catch(e){u(As(e))}finally{E(!1)}}async function fs(){const s=y.trim();if(!s){u(a("goals.titleRequired","Title is required."));return}try{_(!0),u(null),l(null);const e=await fetch(h("/api/goals",d),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({title:s,description:U})});if(e.ok){const o=await e.json();k(g=>[...g,o]),Y();return}let i=null;try{i=await e.json()}catch{i=null}if(e.status===409&&is(i)){l(a("goals.capError","Cannot activate more than 5 goals. Resolve an active goal before activating another."));return}u(a("goals.createError","Unable to create goal right now. Please try again."))}catch{u(a("goals.createError","Unable to create goal right now. Please try again."))}finally{_(!1)}}async function bs(){if(!S)return;const s=q.trim();if(!s){f(a("goals.titleRequired","Title is required."));return}try{W(!0),f(null);const e=await fetch(h(`/api/goals/${S}`,d),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({title:s,description:B})});if(!e.ok)throw new Error(`Failed to update goal (${e.status})`);const i=await e.json();k(o=>o.map(g=>g.id===i.id?i:g)),Q()}catch{f(a("goals.saveError","Unable to save goal right now. Please try again."))}finally{W(!1)}}function ks(s){return s.length>Ps||s.includes(`
|
|
2
2
|
`)}function ys(s){rs(e=>{const i=new Set(e);return i.has(s)?i.delete(s):i.add(s),i})}function Z(s){const e=new Set((x[s]??[]).map(i=>i.id));return ds.filter(i=>!e.has(i.id))}async function ss(s){const e=await J(s);C(i=>({...i,[s]:e})),z(i=>({...i,[s]:""}))}async function vs(s){const e=T[s];if(e)try{K(s),l(null);const i=await fetch(h(`/api/missions/${encodeURIComponent(e)}/goals/${encodeURIComponent(s)}`,d),{method:"POST"});if(!i.ok)throw new Error(`Failed to link mission (${i.status})`);await ss(s)}catch{l(a("goals.linkMissionError","Unable to link mission right now. Please try again."))}finally{K(null)}}async function xs(s,e){try{X(`${s}:${e}`),l(null);const i=await fetch(h(`/api/missions/${encodeURIComponent(e)}/goals/${encodeURIComponent(s)}`,d),{method:"DELETE"});if(!i.ok)throw new Error(`Failed to unlink mission (${i.status})`);await ss(s)}catch{l(a("goals.unlinkMissionError","Unable to unlink mission right now. Please try again."))}finally{X(null)}}async function ts(s){const e=s.status==="active"?`/api/goals/${s.id}/archive`:`/api/goals/${s.id}/unarchive`;try{l(null);const i=await fetch(h(e,d),{method:"POST"});if(i.ok){const g=await i.json();k(b=>b.map(es=>es.id===g.id?g:es));return}let o=null;try{o=await i.json()}catch{o=null}if(i.status===409&&is(o)){l(a("goals.capError","Cannot activate more than 5 goals. Resolve an active goal before activating another."));return}l(a("goals.updateError","Unable to update goal status right now. Please try again."))}catch{l(a("goals.updateError","Unable to update goal status right now. Please try again."))}}return t.jsxs("section",{className:"goals-view","data-testid":"goals-view",children:[t.jsx(js,{icon:ws,title:a("goals.title","Goals"),actions:t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"goals-count","data-testid":"goals-active-count",children:a("goals.activeCount","{{count}} active goals",{count:G})}),t.jsxs("button",{type:"button",className:"btn btn-primary goals-add-button",onClick:ms,"data-testid":"goals-add-button",children:[t.jsx(Ns,{size:18,"aria-hidden":"true"}),a("goals.addGoal","Add Goal")]})]})}),t.jsxs("div",{className:"goals-view__content",children:[os?t.jsxs("div",{className:"card goals-form","data-testid":"goals-form",children:[t.jsx("label",{className:"goals-form-label",htmlFor:"goals-form-title",children:a("goals.labelTitle","Title")}),t.jsx("input",{id:"goals-form-title",className:"input",type:"text",value:y,maxLength:200,onChange:s=>F(s.target.value),"data-testid":"goals-form-title"}),t.jsxs("div",{className:"goals-form-label-row",children:[t.jsx("label",{className:"goals-form-label",htmlFor:"goals-form-description",children:a("goals.labelDescription","Description")}),t.jsxs("button",{type:"button",className:"btn goals-form-draft-button",onClick:()=>void ps(),disabled:!y.trim()||v,"data-testid":"goals-form-draft-ai",children:[t.jsx(Es,{"aria-hidden":"true"}),v?a("goals.drafting","Drafting…"):a("goals.draftWithAi","Draft with AI")]})]}),t.jsx("textarea",{id:"goals-form-description",className:"input",value:U,maxLength:5e3,onChange:s=>N(s.target.value),"data-testid":"goals-form-description"}),R?t.jsx("p",{className:"form-error goals-error",role:"alert",children:R}):null,t.jsxs("div",{className:"goals-form-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void fs(),disabled:O||v,"data-testid":"goals-form-submit",children:a("actions.save","Save")}),t.jsx("button",{type:"button",className:"btn",onClick:Y,disabled:O||v,"data-testid":"goals-form-cancel",children:a("actions.cancel","Cancel")})]})]}):null,gs?t.jsx("p",{className:"goals-warning",role:"status",children:a("goals.capWarning","Approaching the 5-active goal cap. Keep active goals focused.")}):null,D?t.jsx("p",{className:"form-error goals-error",role:"alert","data-testid":"goals-error",children:D}):null,w?t.jsx("p",{className:"goals-loading",role:"status","data-testid":"goals-loading",children:a("goals.loading","Loading goals…")}):null,!w&&c.length===0?t.jsx("div",{className:"goals-empty card","data-testid":"goals-empty-state",children:a("goals.emptyState","No goals yet. Add one to begin tracking strategic outcomes.")}):null,!w&&c.length>0?t.jsx("div",{className:"goals-list","data-testid":"goals-list",children:c.map(s=>t.jsxs("article",{id:`goal-card-${s.id}`,className:`card goals-card ${s.status==="archived"?"goals-card-archived":""} ${ns===s.id?"goals-card--anchored":""}`.trim(),"data-testid":`goal-card-${s.id}`,children:[S===s.id?t.jsxs("div",{className:"goals-card-main goals-card-edit",children:[t.jsx("label",{className:"goals-form-label",htmlFor:`goal-edit-title-${s.id}`,children:a("goals.labelTitle","Title")}),t.jsx("input",{id:`goal-edit-title-${s.id}`,className:"input",type:"text",value:q,maxLength:200,onChange:e=>$(e.target.value),"data-testid":`goal-edit-title-${s.id}`}),t.jsx("label",{className:"goals-form-label",htmlFor:`goal-edit-description-${s.id}`,children:a("goals.labelDescription","Description")}),t.jsx("textarea",{id:`goal-edit-description-${s.id}`,className:"input",value:B,maxLength:5e3,onChange:e=>M(e.target.value),"data-testid":`goal-edit-description-${s.id}`}),H?t.jsx("p",{className:"form-error goals-error",role:"alert",children:H}):null,t.jsxs("div",{className:"goals-card-actions",children:[t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void bs(),disabled:I,"data-testid":`goal-edit-save-${s.id}`,children:a("actions.save","Save")}),t.jsx("button",{type:"button",className:"btn",onClick:Q,disabled:I,"data-testid":`goal-edit-cancel-${s.id}`,children:a("actions.cancel","Cancel")})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"goals-card-main",children:[t.jsx("h3",{className:"goals-card-title",children:s.title}),s.description?(()=>{const e=ks(s.description),i=ls.has(s.id);return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`markdown-body goals-card-description ${e&&!i?"goals-card-description-collapsed":""}`.trim(),children:t.jsx(Ss,{remarkPlugins:[$s],children:s.description})}),e?t.jsx("button",{type:"button",className:"btn goals-card-description-toggle","aria-expanded":i,"data-testid":`goal-description-toggle-${s.id}`,onClick:()=>ys(s.id),children:i?a("actions.showLess","Show less"):a("actions.showMore","Show more")}):null]})})():null,t.jsxs("p",{className:"goals-card-status",children:[a("goals.status","Status"),": ",s.status]})]}),t.jsxs("div",{className:"goals-card-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:()=>hs(s),"data-testid":`goal-edit-${s.id}`,children:a("actions.edit","Edit")}),s.status==="active"?t.jsx("button",{type:"button",className:"btn goals-activate-button",onClick:()=>void ts(s),"data-testid":`goal-archive-${s.id}`,children:a("goals.archive","Archive")}):t.jsx("button",{type:"button",className:"btn goals-activate-button",onClick:()=>void ts(s),"data-testid":`goal-unarchive-${s.id}`,children:a("goals.unarchive","Unarchive")})]})]}),t.jsxs("section",{className:"goals-linked-missions","aria-label":a("goals.linkedMissions","Linked missions"),children:[t.jsxs("div",{className:"goals-linked-missions-header",children:[t.jsx("h4",{className:"goals-linked-missions-title",children:a("goals.linkedMissionsTitle","Linked Missions")}),t.jsx("span",{className:"goals-linked-missions-count",children:a("goals.linkedMissionsCount",{count:x[s.id]?.length??0,defaultValue_one:"{{count}} linked",defaultValue_other:"{{count}} linked"})})]}),t.jsxs("div",{className:"goals-linked-missions-controls",children:[t.jsxs("select",{className:"input goals-linked-missions-picker","data-testid":`goal-mission-picker-${s.id}`,value:T[s.id]??"",onChange:e=>z(i=>({...i,[s.id]:e.target.value})),"aria-label":a("goals.missionPicker","Mission to link"),disabled:A===s.id||Z(s.id).length===0,children:[t.jsx("option",{value:"",children:a("goals.selectMission","Select a mission")}),Z(s.id).map(e=>t.jsx("option",{value:e.id,children:e.title},e.id))]}),t.jsxs("button",{type:"button",className:"btn btn-primary goals-linked-missions-link-button","data-testid":`goal-mission-link-button-${s.id}`,disabled:!T[s.id]||A===s.id,onClick:()=>void vs(s.id),children:[t.jsx(Ms,{size:16,"aria-hidden":"true"}),A===s.id?a("goals.linkingMission","Linking…"):a("goals.linkMission","Link mission")]})]}),(x[s.id]?.length??0)>0?t.jsx("div",{className:"goals-linked-missions-list",children:(x[s.id]??[]).map(e=>t.jsxs("div",{className:"goals-linked-mission-chip","data-testid":`goal-linked-mission-chip-${e.id}`,children:[t.jsx("button",{type:"button",className:"btn goals-linked-mission-link",onClick:()=>as?.(e.id),children:e.title}),t.jsx("span",{className:"goals-linked-mission-status",children:e.status}),t.jsx("button",{type:"button",className:"btn-icon goals-linked-mission-unlink","data-testid":`goal-linked-mission-unlink-${e.id}`,"aria-label":a("goals.unlinkMission","Unlink mission"),disabled:us===`${s.id}:${e.id}`,onClick:()=>void xs(s.id,e.id),children:t.jsx(Cs,{size:16,"aria-hidden":"true"})})]},e.id))}):t.jsx("p",{className:"goals-linked-missions-empty",children:a("goals.noLinkedMissions","No linked missions.")})]})]},s.id))}):null]})]})}export{qs as GoalsView};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{r as c,j as e}from"./vendor-react-SZ_qB27O.js";import{c as _e,aC as ce,aD as we,aE as Ce,bt as je,bu as Ye,aH as Ie,bv as Je,bw as Qe,bx as Ze,by as es,bz as ss,bA as ts,bB as Me,bC as is,bD as ns,bE as Ae,V as as,S as A,bF as rs,X as Ne,bG as fe,R as N,O as cs,bH as ls,aA as ze,g as le,bI as Ee,bq as os,P as De,a7 as hs,a_ as Pe,bJ as gs}from"./index-inWk2g6R.js";import{u as $e}from"./vendor-i18n-GF3RlKbq.js";import{U as Fe}from"./users-DvKg3opr.js";import"./vendor-reactflow-9C3XTE7_.js";import"./vendor-codemirror-jBKmHyH0.js";import"./vendor-xterm-BNq00GSj.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 ds=[["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"}]],us=_e("building",ds);/**
|
|
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 ms=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],fs=_e("chart-line",ms),me=["architecture","quality","workflow","performance","reliability","security","ux","testability","documentation","dependency","features","competitive_analysis","research","trends","other"],Re={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 vs(d){const{t:g}=$e("app"),$=d??"",k=`${Ce.INSIGHTS_PREFIX}${$}`,S=`${Ce.INSIGHT_LATEST_RUN_PREFIX}${$}`,s=ce(k,{maxAgeMs:we}),V=ce(S,{maxAgeMs:je}),E=c.useRef(Array.isArray(s)&&s.length>0),G=c.useCallback(a=>g(`insights.category.${a}`,Re[a]??a),[g]),[v,x]=c.useState(()=>Array.isArray(s)?s:[]),[T,W]=c.useState(()=>me.map(a=>({category:a,label:Re[a]??a,items:[],isLoading:!1,error:null}))),[K,L]=c.useState(!(Array.isArray(s)&&s.length>0)),[Y,U]=c.useState(null),[J,_]=c.useState(V??null),[Q,H]=c.useState(!1),[Z,F]=c.useState(null),[ee,z]=c.useState(new Map),[se,C]=c.useState(new Map),[u,w]=c.useState(new Map),[m,D]=c.useState(new Map),[B,j]=c.useState(!1),R=c.useCallback(async()=>{E.current||L(!0),U(null);try{const t=(await Ye({status:void 0,limit:1e3},d)).insights.filter(l=>l.status!=="dismissed");x(t),Ie(k,t.length>500?t.slice(0,500):t,{maxBytes:5e5});const r=await Je(d);r.runs.length>0&&(_(r.runs[0]),Ie(S,r.runs[0],{maxBytes:5e5})),E.current=!0}catch(a){const t=a instanceof Error?a.message:"Failed to fetch insights";U(t)}finally{L(!1)}},[k,S,d]),y=c.useCallback(()=>{j(a=>!a)},[]),te=c.useCallback(async(a,t,r)=>{H(!0),F(null);try{const l=await Qe("manual",void 0,d,a,t,r);_(l),l.status==="completed"?await R():l.status==="failed"&&l.error&&F(l.error)}catch(l){if(l instanceof Ze&&l.status===409&&l.details?.code==="ACTIVE_RUN_CONFLICT"){const ie=typeof l.details.activeRunId=="string"?l.details.activeRunId:null;if(ie)try{const de=await es(ie,d);_(de)}catch{}throw F("Insight generation is already running"),l}const f=l instanceof Error?l.message:"Failed to generate insights";throw F(f),l}finally{H(!1)}},[d,R]),O=c.useCallback(async a=>{z(t=>{const r=new Map(t);return r.set(a,{running:!0,error:null}),r});try{await ss(a,d),x(t=>t.filter(r=>r.id!==a)),z(t=>{const r=new Map(t);return r.set(a,{running:!1,error:null}),r})}catch(t){const r=t instanceof Error?t.message:"Failed to dismiss insight";throw z(l=>{const f=new Map(l);return f.set(a,{running:!1,error:r}),f}),t}},[d]),oe=c.useCallback(async a=>{C(t=>{const r=new Map(t);return r.set(a,{running:!0,error:null}),r});try{const t=await ts(a,d);return await Me(a,d),x(r=>r.map(l=>l.id===a?{...l,status:"archived",updatedAt:new Date().toISOString()}:l)),C(r=>{const l=new Map(r);return l.set(a,{running:!1,error:null}),l}),{title:t.suggestedTitle,description:t.suggestedDescription}}catch(t){const r=t instanceof Error?t.message:"Failed to create task";throw C(l=>{const f=new Map(l);return f.set(a,{running:!1,error:r}),f}),t}},[d]);c.useEffect(()=>{const a=new Map;for(const t of me)a.set(t,[]);for(const t of v){if(!B&&t.status==="archived")continue;const r=a.get(t.category)??[];a.set(t.category,[...r,t])}W(me.map(t=>({category:t,label:G(t),items:a.get(t)??[],isLoading:!1,error:null})))},[v,B,G]);const he=c.useCallback(async a=>{w(t=>{const r=new Map(t);return r.set(a,{running:!0,error:null}),r});try{await Me(a,d),x(t=>t.map(r=>r.id===a?{...r,status:"archived",updatedAt:new Date().toISOString()}:r)),w(t=>{const r=new Map(t);return r.set(a,{running:!1,error:null}),r})}catch(t){const r=t instanceof Error?t.message:"Failed to archive insight";throw w(l=>{const f=new Map(l);return f.set(a,{running:!1,error:r}),f}),t}},[d]),ge=c.useCallback(async a=>{D(t=>{const r=new Map(t);return r.set(a,{running:!0,error:null}),r});try{await is(a,d),x(t=>t.map(r=>r.id===a?{...r,status:"confirmed",updatedAt:new Date().toISOString()}:r)),D(t=>{const r=new Map(t);return r.set(a,{running:!1,error:null}),r})}catch(t){const r=t instanceof Error?t.message:"Failed to unarchive insight";throw D(l=>{const f=new Map(l);return f.set(a,{running:!1,error:r}),f}),t}},[d]),b=c.useMemo(()=>T.reduce((a,t)=>a+t.items.length,0),[T]),X=c.useMemo(()=>0,[]),p=c.useMemo(()=>v.filter(a=>a.status==="archived").length,[v]);return c.useEffect(()=>{const a=ce(k,{maxAgeMs:we}),t=ce(S,{maxAgeMs:je}),r=Array.isArray(a)&&a.length>0;x(Array.isArray(a)?a:[]),_(t??null),L(!r),E.current=r},[k,S]),c.useEffect(()=>{R()},[R]),{sections:T,loading:K,error:Y,latestRun:J,isRunInFlight:Q,runError:Z,refresh:R,runInsights:te,dismiss:O,createTask:oe,archive:he,unarchive:ge,toggleShowArchived:y,dismissStates:ee,createTaskStates:se,archiveStates:u,unarchiveStates:m,totalCount:b,dismissedCount:X,archivedCount:p,showArchived:B}}const Ge=["Backlog health:","Backlog pressure detected","Stale paused todo","Backlog health: dependency-blocked todos"];function Te(d){return Ge.some(g=>d.title.startsWith(g))}const Le={architecture:us,quality:ze,workflow:Pe,performance:Ee,reliability:N,security:le,ux:Fe,testability:fe,documentation:hs,dependency:De,features:os,competitive_analysis:Fe,research:fs,trends:Ee,other:A};function Cs({projectId:d,addToast:g,onClose:$,onCreateTask:k,models:S}){const{t:s}=$e("app"),{sections:V,loading:E,error:G,latestRun:v,isRunInFlight:x,runError:T,refresh:W,runInsights:K,dismiss:L,createTask:Y,archive:U=async()=>{},unarchive:J=async()=>{},toggleShowArchived:_=()=>{},dismissStates:Q,createTaskStates:H,archiveStates:Z=new Map,unarchiveStates:F=new Map,totalCount:ee,archivedCount:z=0,showArchived:se=!1}=vs(d),[C,u]=c.useState(null),[w,m]=c.useState("info"),[D,B]=c.useState(!1),[j,R]=c.useState(!1),[y,te]=c.useState(()=>localStorage.getItem("fusion-insight-model")??""),[O,oe]=c.useState(()=>localStorage.getItem("fusion-insight-thinking")??""),[he,ge]=c.useState([]),[b,X]=c.useState([]),[p,a]=c.useState([]),[t,r]=c.useState();c.useEffect(()=>{S||ns().then(i=>{ge(i.models),X(i.favoriteProviders),a(i.favoriteModels),r(i.resolvedPlanningProvider);const n=localStorage.getItem("fusion-insight-model");n&&(i.models.some(h=>`${h.provider}/${h.id}`===n)||(localStorage.removeItem("fusion-insight-model"),te("")))}).catch(()=>{})},[S]);const l=S??he,f=c.useMemo(()=>b.length>0?b:t?[t]:[],[b,t]),ie=c.useCallback(async i=>{const o=b.includes(i)?b.filter(h=>h!==i):[i,...b];X(o);try{await Ae({favoriteProviders:o,favoriteModels:p})}catch{X(b)}},[b,p]),de=c.useCallback(async i=>{const o=p.includes(i)?p.filter(h=>h!==i):[i,...p];a(o);try{await Ae({favoriteProviders:b,favoriteModels:o})}catch{a(p)}},[p,b]),Ue=c.useCallback(i=>{te(i),i?localStorage.setItem("fusion-insight-model",i):localStorage.removeItem("fusion-insight-model")},[]),He=c.useCallback(i=>{oe(i),i?localStorage.setItem("fusion-insight-thinking",i):localStorage.removeItem("fusion-insight-thinking")},[]),q=c.useMemo(()=>V.filter(i=>i.items.length>0),[V]),ve=c.useMemo(()=>q.reduce((i,n)=>i+n.items.filter(Te).length,0),[q]),I=c.useMemo(()=>j?q.map(i=>({...i,items:i.items.filter(Te)})).filter(i=>i.items.length>0):q,[q,j]),[P,ue]=c.useState(null);c.useEffect(()=>{if(I.length===0){P!==null&&ue(null);return}P&&I.some(n=>n.category===P&&n.items.length>0)||ue(I[0].category)},[I,P]);const M=c.useMemo(()=>I.find(i=>i.category===P)??I[0],[I,P]);c.useEffect(()=>{if(C){const i=setTimeout(()=>u(null),5e3);return()=>clearTimeout(i)}},[C]);const be=c.useCallback(async()=>{try{u(s("insights.generatingInsights","Generating insights...")),m("info");let i,n;if(y){const o=y.indexOf("/");if(o!==-1){const h=y.slice(0,o),ne=y.slice(o+1);h&&ne&&(i=h,n=ne)}}await K(i,n,O||void 0),u(s("insights.generationStarted","Insight generation started")),m("success"),g(s("insights.generationStarted","Insight generation started"),"success")}catch(i){const n=i instanceof Error?i.message:s("insights.failedToStart","Failed to start generation");if(n==="Insight generation is already running"){u(s("insights.alreadyRunning","Insight generation is already running. Showing the active run.")),m("info"),g(s("insights.alreadyRunningShort","Insight generation is already running"),"info");return}u(n),m("error"),g(n,"error")}},[K,g,y,O,s]),Be=c.useCallback(async(i,n)=>{try{u(s("insights.dismissing",'Dismissing "{{title}}"...',{title:n})),m("info"),await L(i),u(s("insights.dismissed",'Dismissed "{{title}}"',{title:n})),m("success"),g(s("insights.dismissedMsg","Insight dismissed: {{title}}",{title:n}),"success")}catch(o){const h=o instanceof Error?o.message:s("insights.failedToDismiss","Failed to dismiss insight");u(h),m("error"),g(h,"error")}},[L,g,s]),Oe=c.useCallback(async(i,n)=>{try{u(s("insights.archiving",'Archiving "{{title}}"...',{title:n})),m("info"),await U(i),u(s("insights.archived",'Archived "{{title}}"',{title:n})),m("success"),g(s("insights.archivedMsg","Insight archived: {{title}}",{title:n}),"success")}catch(o){const h=o instanceof Error?o.message:s("insights.failedToArchive","Failed to archive insight");u(h),m("error"),g(h,"error")}},[U,g,s]),Xe=c.useCallback(async(i,n)=>{try{u(s("insights.unarchiving",'Unarchiving "{{title}}"...',{title:n})),m("info"),await J(i),u(s("insights.unarchived",'Unarchived "{{title}}"',{title:n})),m("success"),g(s("insights.unarchivedMsg","Insight unarchived: {{title}}",{title:n}),"success")}catch(o){const h=o instanceof Error?o.message:s("insights.failedToUnarchive","Failed to unarchive insight");u(h),m("error"),g(h,"error")}},[J,g,s]),qe=c.useCallback(async(i,n)=>{try{if(u(s("insights.creatingTask",'Creating task from "{{title}}"...',{title:n})),m("info"),!k)throw new Error(s("insights.taskCreationUnavailable","Task creation is unavailable in this view"));const o=await Y(i);if(!o)throw new Error(s("insights.failedToPreparePayload","Failed to prepare task payload from insight"));await k({insightId:i,title:o.title,description:o.description}),u(s("insights.taskCreated",'Task created from "{{title}}"',{title:n})),m("success"),g(s("insights.taskCreatedMsg","Task created: {{title}}",{title:o.title}),"success")}catch(o){const h=o instanceof Error?o.message:s("insights.failedToCreateTask","Failed to create task");u(h),m("error"),g(h,"error")}},[Y,k,g,s]),Ve=i=>{const n=Le[i.category]??A,o=M?.category===i.category;return e.jsx("li",{children:e.jsxs("button",{type:"button",className:`insights-category-item${o?" insights-category-item--active":""}`,onClick:()=>ue(i.category),"aria-current":o?"true":void 0,"data-testid":`insights-category-${i.category}`,children:[e.jsx(n,{size:16,className:"insights-category-icon"}),e.jsx("span",{className:"insights-category-label",children:i.label}),e.jsx("span",{className:"insights-category-count",children:i.items.length})]})},i.category)},We=()=>{if(!M)return null;const i=Le[M.category]??A;return e.jsxs("section",{className:"insights-section","data-testid":`insights-section-${M.category}`,children:[e.jsx("div",{className:"insights-section-header",children:e.jsxs("div",{className:"insights-section-title",children:[e.jsx(i,{size:18,className:"insights-section-icon"}),e.jsx("h3",{children:M.label}),e.jsx("span",{className:"insights-section-count",children:M.items.length})]})}),e.jsx("div",{className:"insights-section-content",children:e.jsx("ul",{className:"insights-list",children:M.items.map(n=>{const o=Q.get(n.id),h=H.get(n.id),ne=Z.get(n.id),Ke=F.get(n.id),ye=o?.running??!1,xe=h?.running??!1,pe=ne?.running??!1,ke=Ke?.running??!1,Se=n.status==="archived",ae=M.items.some(re=>Q.get(re.id)?.running||H.get(re.id)?.running||Z.get(re.id)?.running||F.get(re.id)?.running);return e.jsxs("li",{className:`insight-item${Se?" 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:[Se?e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Xe(n.id,n.title),disabled:ke||ae,title:s("insights.unarchiveTitle","Unarchive this insight"),"aria-label":s("insights.unarchiveLabel","Unarchive this insight"),"data-testid":`unarchive-${n.id}`,children:ke?e.jsx(N,{size:16,className:"spin"}):e.jsx(gs,{size:16})}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void qe(n.id,n.title),disabled:xe||ae,title:s("insights.createTaskTitle","Create task from this insight"),"aria-label":s("insights.createTaskLabel","Create task from this insight"),"data-testid":`create-task-${n.id}`,children:xe?e.jsx(N,{size:16,className:"spin"}):e.jsx(De,{size:16})}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Oe(n.id,n.title),disabled:pe||ae,title:s("insights.archiveTitle","Archive this insight"),"aria-label":s("insights.archiveLabel","Archive this insight"),"data-testid":`archive-${n.id}`,children:pe?e.jsx(N,{size:16,className:"spin"}):e.jsx(fe,{size:16})})]}),e.jsx("button",{className:"insight-item-action-btn",onClick:()=>void Be(n.id,n.title),disabled:ye||ae,title:s("insights.dismissTitle","Dismiss this insight"),"aria-label":s("insights.dismissLabel","Dismiss this insight"),"data-testid":`dismiss-${n.id}`,children:ye?e.jsx(N,{size:16,className:"spin"}):e.jsx(Ne,{size:16})})]})]}),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(Pe,{size:12}),new Date(n.createdAt).toLocaleDateString()]})]})]},n.id)})})})]})};return e.jsxs("div",{className:"insights-view","data-testid":"insights-view",children:[e.jsx(as,{icon:A,title:s("insights.title","Insights"),actions:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"insights-view-count",children:[ee," ",s("common.total","total")]}),ve>0&&e.jsxs("button",{className:`btn btn-sm insights-backlog-health-toggle${j?" btn-icon--active":""}`,onClick:()=>R(i=>!i),"aria-pressed":j,"aria-label":j?s("insights.showAllInsights","Show all insights"):s("insights.showBacklogHealth","Show only backlog health insights"),"data-testid":"toggle-backlog-health",title:Ge.join(", "),children:[e.jsx(rs,{size:14}),j?s("insights.allInsights","All Insights"):s("insights.backlogHealth","Backlog")," ",e.jsxs("span",{children:["(",ve,")"]})]}),$&&e.jsx("button",{className:"btn btn-sm insights-view-close",onClick:$,"aria-label":s("actions.closeInsightsView","Close insights view"),title:s("actions.close","Close"),children:e.jsx(Ne,{size:16})}),z>0&&e.jsxs("button",{className:"btn btn-sm insights-show-archived-toggle",onClick:_,"aria-label":se?s("insights.hideArchived","Hide archived insights"):s("insights.showArchived","Show archived insights"),"data-testid":"toggle-archived-insights",children:[e.jsx(fe,{size:14}),se?s("insights.hideArchivedLabel","Archived"):s("insights.showArchivedLabel","Archived ({{count}})",{count:z})]}),e.jsx("button",{className:"btn btn-icon btn-sm insights-refresh-btn",onClick:()=>void W(),disabled:E,"aria-label":s("actions.refreshInsights","Refresh insights"),title:s("actions.refreshInsights","Refresh insights"),"data-testid":"refresh-insights",children:e.jsx(N,{size:14,className:E?"spin":""})}),e.jsxs("button",{className:"btn btn-sm insights-model-toggle",onClick:()=>B(i=>!i),"aria-label":s("insights.configureModel","Configure insight generation model"),"aria-expanded":D,"data-testid":"toggle-model-config",title:y?s("insights.modelConfigured","Model: {{model}}",{model:y}):s("insights.configureModelTitle","Configure model"),children:[e.jsx(cs,{size:14}),y&&e.jsx("span",{className:"insights-model-indicator"})]}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>void be(),disabled:x,"aria-label":s("insights.generateInsights","Generate new insights"),"data-testid":"run-insights",children:x?e.jsxs(e.Fragment,{children:[e.jsx(N,{size:14,className:"spin"}),s("insights.generating","Generating...")]}):e.jsxs(e.Fragment,{children:[e.jsx(A,{size:14}),s("insights.generateInsightsBtn","Generate Insights")]})})]})}),D&&e.jsxs("div",{className:"insights-model-config","data-testid":"model-config",children:[e.jsx("label",{htmlFor:"insight-model-select",className:"insights-model-label",children:s("insights.model","Model")}),e.jsx(ls,{models:l,value:y,onChange:Ue,placeholder:s("insights.usePlanningDefault","Use planning default"),label:s("insights.generationModel","Insight generation model"),disabled:x,id:"insight-model-select",favoriteProviders:f,favoriteModels:p,onToggleFavorite:ie,onToggleModelFavorite:de,showThinkingLevel:!0,thinkingLevel:O,onThinkingLevelChange:He,defaultThinkingLevel:"off"})]}),e.jsx("div",{className:"insights-status-region","aria-live":"polite","data-testid":"insights-status",children:C&&e.jsxs("div",{className:`insights-status-message insights-status-message--${w}`,role:w==="error"?"alert":void 0,children:[w==="success"&&e.jsx(ze,{size:16}),w==="error"&&e.jsx(le,{size:16}),w==="info"&&e.jsx(A,{size:16}),e.jsx("span",{children:C})]})}),T&&e.jsxs("div",{className:"insights-error-callout",role:"alert","data-testid":"run-error",children:[e.jsx(le,{size:16}),e.jsx("span",{children:T})]}),v&&e.jsx("div",{className:"insights-run-info","data-testid":"latest-run",children:e.jsxs("span",{className:"insights-run-status",children:[s("insights.latestRun","Latest run:")," ",v.status,v.status==="completed"&&e.jsxs(e.Fragment,{children:[" — ",s("insights.runCompleted","{{created}} created, {{updated}} updated",{created:v.insightsCreated,updated:v.insightsUpdated})]}),v.status==="failed"&&v.error&&e.jsxs(e.Fragment,{children:[" — ",v.error]})]})}),E?e.jsxs("div",{className:"insights-loading","data-testid":"insights-loading",children:[e.jsx(N,{size:24,className:"spin"}),e.jsx("p",{children:s("insights.loading","Loading insights...")})]}):G?e.jsxs("div",{className:"insights-error","data-testid":"insights-error",children:[e.jsx(le,{size:24}),e.jsx("p",{children:G}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void W(),children:s("actions.retry","Retry")})]}):ee===0?e.jsxs("div",{className:"insights-empty","data-testid":"insights-empty",children:[e.jsx(A,{size:48}),e.jsx("h3",{children:s("insights.noInsightsYet","No insights yet")}),e.jsx("p",{children:s("insights.generateDescription","Generate insights to get AI-powered recommendations for your project.")}),e.jsxs("button",{className:"btn btn-primary",onClick:()=>void be(),children:[e.jsx(A,{size:14}),s("insights.generateFirst","Generate First Insights")]})]}):e.jsxs("div",{className:"insights-body",children:[e.jsx("aside",{className:"insights-sidebar","aria-label":s("insights.categoriesLabel","Insight categories"),children:e.jsx("ul",{className:"insights-category-list",children:I.map(Ve)})}),e.jsx("div",{className:"insights-detail",children:We()})]})]})}export{Cs as InsightsView};
|