1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/bridge-files-BJMqnMlc.js","assets/index-C11G29by.js","assets/react-dIJTUJVE.js","assets/firebase-C7EYTMAQ.js","assets/index-CnxszyAm.css","assets/api-url-DLodfFrf.js","assets/App-B0xi6QKB.js","assets/App-wBPkvLrr.css","assets/workspaceTree-DLTdRSO1.js","assets/percentages-BXMCSKIN-CjKe5fGn.js","assets/tslib.es6-DEAt-OyE.js","assets/extends-CF3RwP-h.js","assets/StreamingMarkdown-DOkfYjgm.js","assets/index-OwaqD2Hs.js","assets/index-Bwd2g-Nx.js","assets/square-check-big-xPOqrTQO.js","assets/artifact-validation-6sQJTJ1Y.js","assets/motion-CNngsM_T.js","assets/circle-question-mark-CopOPzd-.js","assets/pencil-XIhRmLy8.js","assets/message-square-text-CgisRh1U.js","assets/arrow-up-qXuqvH2E.js","assets/htmlDocumentTitle-Dhf1RWaV.js","assets/useBridgeFileAccessToken-CQTFigIo.js","assets/useArtifactPreviewSource-lY6__QjV.js","assets/ArtifactThumbnail-Dabo6O3B.js","assets/ArtifactMarkdownPreview-CCoFiQgq.js","assets/openclawMediaMarkdown-CdhVoFIf.js","assets/MermaidDiagram-Cxn2qd4O.js","assets/code-xml-BxUbH-VE.js","assets/zoom-out-DePrSaDK.js","assets/maximize-2-BjQ2jqL3.js","assets/settings-2-C4K0hVr0.js","assets/VideoProjectArtifactCard-D1QblFra.js","assets/play-DEWq-60x.js","assets/file-code-CffEJzMa.js","assets/file-DvIrRJKi.js","assets/library-3WluyWuk.js","assets/link-2-DvNv9hSL.js","assets/sticky-note-BtkwUIYs.js","assets/percentages-BXMCSKIN-BcAUh2Nm.css","assets/TerminalPage-Cyg0C-BW.js","assets/xterm-BS7OUDs9.js","assets/xterm-6GBZ9nXN.css","assets/workspace-device-label-G6B_sfhX.js","assets/cloud-CRcFBbpu.js","assets/trash-2-BDsDy3gR.js","assets/ellipsis-BAmgce7q.js","assets/SideVideoEditorPanel-Dy3LfEHr.js","assets/video-editor-preload-DwsSUJvT.js","assets/AppsBrowser-RLiBZQkN.js","assets/select-DEM7TBBp.js","assets/chevron-up-7RIBeIs5.js","assets/isElementDisabled-CwHw_lZC.js","assets/resolveAriaLabelledBy-CZd1bu7B.js","assets/clamp-DyuOe9kr.js","assets/bridge-data-WEwRgw-H.js","assets/file-spreadsheet-BClyFhZx.js","assets/bridge-apps-BZk9uT9n.js","assets/tabs-LUqGrWfE.js","assets/CompositeRoot-SMvD_Fv4.js","assets/app-window-onVEKfkg.js","assets/boxes-D1mSkMkQ.js","assets/ChatPanel-DT90xFdG.js","assets/composerMentisAdapter-DM0KlTo_.js","assets/composer-plugin-chip-O6DfYSkU.js","assets/plugin-hero-gradient-B9RIdNkm.js","assets/package-C9nsiFco.js","assets/zap-DOyFGPoB.js","assets/file-image-jxJImllV.js","assets/file-archive-B_BgsXiH.js","assets/index-BK254JOO.js","assets/urlPreview-CL_oMJ0w.js","assets/toolDiff-DIrh_71I.js","assets/git-branch-DRy-lKL8.js","assets/ArtifactShareButton-B88bFGyl.js","assets/ComposerStatusPanels-BTSD1WUN.js","assets/apiResponse-DYkfnH0b.js","assets/ToolTimeline-Bq0b2JHy.js","assets/codeFenceInfo-AlTYuH6e.js","assets/index-CvVbjaaV.js","assets/at-sign-CGs3Pake.js","assets/volume-2-Bb9RnzSI.js","assets/table-2L4RosRO.js","assets/circle-CcldZjL8.js","assets/network-BkQm21yA.js","assets/flask-conical-DQAO7GtR.js","assets/core.esm-DYp12Gts.js","assets/useOpenClawDashboardServer-Ck7aElVV.js","assets/circle-dashed-DFAUbnie.js","assets/gauge-DUamjeke.js","assets/arrow-up-right-BtPmoXoo.js","assets/layers-DhUKMb1_.js","assets/thumbs-up-Ca4fGdt-.js","assets/SkeletonLoader-ud9Ymvmu.js","assets/markEvents-Cg9f14WA.js","assets/ConfirmDoubtsCard-5-Tr80hR.js","assets/toolEventOutputFiles-CIulsOCW.js","assets/PowerComputerDesktopViewer-kx82ag50.js","assets/LocalModelSleepBanner-D6yoO6b0.js","assets/info-Jciv6U4s.js","assets/page-shell-layout-BlPjmhhQ.js","assets/useComposerPluginTag-CEtpXjxF.js","assets/popover-Bz-_ODEM.js","assets/workflowShortcutMapping-CLcCookh.js","assets/wallet-C0RfU4od.js","assets/composerPluginRecommendations-DH8eVkXj.js","assets/SettingsPluginFavicon-De86jn1p.js","assets/orbit-CPhzD6en.js","assets/modelPickerCore-g-OGHH8k.js","assets/funnel-GrDHDW-p.js","assets/star-
1B0CxB3P_.js","assets/ComboboxItem-Bw-Tq1PE.js","assets/switch-CF0DIvqJ.js","assets/paperclip-CdXAD342.js","assets/sliders-horizontal-xHxLpW_v.js","assets/arrow-left-right-CULctuYC.js","assets/puzzle-BLfxJ85J.js","assets/audio-lines-DmHAnQg4.js","assets/composer-mention-groups-mSqaKIwn.js","assets/useAgentMessagingChannels-C3ws_KTu.js","assets/ComposerErrorBoundary-roM9qkba.js","assets/circle-x-ChJHvhq0.js","assets/wand-sparkles-Buiop1xZ.js","assets/drawer-hSoyjkmV.js","assets/taskLiveState-CjVBpxIP.js","assets/useTaskLivePresence-C7vqf0Xr.js","assets/TaskProgressCard-CqRQVFK8.js","assets/taskAssignee-BVYUmHbR.js","assets/laptop-minimal-CxzY1X7Q.js","assets/RunDiffBrowser-BvTzGGAL.js","assets/commandPreviewSafety-DJGCLSvE.js","assets/chatBubbleStyles-C7sH5wGP.js","assets/SuggestedHireCard-DfLioq6V.js","assets/composerSlashCatalog-D25z60t6.js","assets/verificationEvidence-mYD5lqcH.js","assets/list-checks-DXDOLBK7.js","assets/rotate-ccw-ODDHly_F.js","assets/clipboard-CoHmB2YL.js","assets/provider-auth-B-R4BeLA.js","assets/workspaceRecentArtifacts-VbnkZ_HS.js","assets/acpActivity-DeoewVuV.js","assets/badge-aEbtcL2n.js","assets/markdownComponents-CcfEPWZ7.js","assets/PluginConnectDialog-DlaR1NpO.js","assets/usePluginConnections-D6nb7Ciz.js","assets/key-round-0trrxj9d.js","assets/panel-right-close-Bj9xj2wE.js","assets/formatDistanceToNow-Ca8XUcSB.js","assets/en-US-CHWDLVng.js","assets/endOfMonth-d-B-NzGW.js"])))=>i.map(i=>d[i]); 2import{_ as Tt,V as Ac,f as V,P as Wi,U as Pc,u as Ec,b as q,cC as Tc,a1 as gt,H as Ue,a3 as ri,de as Lc,df as $c,bu as _c,cU as oi,cW as ii,dg as li,j as za,bv as Mc,R as Wa,g as mt,aP as Oc,aQ as Dc,dh as Fc,di as ci,ah as Bc,ai as zc,aj as Wc,aM as Ts,at as Kc,dj as di,bt as Vc,av as Hc,aa as Ka,a6 as qc,B as Gc,dk as Jc,dl as Uc,c_ as Yc,G as Xc,bH as Va,aS as Ki,aT as Vi,ak as Hi,dm as Qc,ab as Ha,aR as Zc}from"./index-C11G29by.js";import{r as f,j as e,W as Ls}from"./react-dIJTUJVE.js";import{g as Ia,e as ed,b as td,s as sd,i as nd,f as ad,C as rd,M as od,a as id,n as mi,r as ld,h as cd,o as dd,l as md,c as yn}from"./composerMentisAdapter-DM0KlTo_.js";import{ct as qi,cu as ui,bb as Gi,cv as ud,D as Ji,c as Ui,d as Yi,B as T,X as En,I as Nn,P as pd,L as Xa,cw as fd,cx as hd,cy as Ra,aJ as pi,a5 as Rs,cz as Sn,n as As,cA as xd,cB as Zt,a4 as gd,E as bd,bA as vd,e as Tn,aD as wd,aE as jd,aF as yd,aG as fi,f as Nd,a7 as qa,g as Sd,C as $s,l as Xe,cj as Cd,cC as kd,a as Id,a6 as Cn,Z as hi}from"./App-B0xi6QKB.js";import{C as Rd}from"./chatBubbleStyles-C7sH5wGP.js";import{fetchBridgeFile as kn}from"./bridge-files-BJMqnMlc.js";import{b as xi,a as Ad,s as gi}from"./taskFileScope-Brd2audK.js";import{u as Pd,W as Ed}from"./WorkspaceFilesPanel-ByOzef8I.js";import{S as Td,a as Ld,b as $d,c as _d,d as In}from"./select-DEM7TBBp.js";import"./firebase-C7EYTMAQ.js";import{a as bi,I as Md,A as Xi,c as Od}from"./urlPreview-CL_oMJ0w.js";import{A as Aa}from"./ArtifactPanel-CY8kVxTn.js";import Dd from"./ArtifactCanvasView-BDr_tAem.js";import Fd from"./SideWorkspaceShell-C6HcWvcd.js";import Bd from"./SideActivityPanel-arb47l_8.js";import zd from"./SideSessionDiffsPanel-FiChD0Dd.js";import Wd from"./SideBrowserPanel-Dd2yaEi6.js";import{b as vi,e as Ga}from"./toolDiff-DIrh_71I.js";import{b as Kd,C as Vd,i as Hd,m as qd,a as Gd,R as Jd,c as Ud,d as Yd}from"./composerSlashCatalog-D25z60t6.js";import{e as Xd}from"./RunDiffBrowser-BvTzGGAL.js";import Qd from"./ArtifactBottomSheet-DQ-ws0T6.js";import{u as Zd,a as em,c as tm,r as sm,g as nm,l as am,m as rm,d as om,h as im,C as lm,S as cm,j as dm,V as mm,i as um,t as pm,k as wi}from"./useComposerPluginTag-CEtpXjxF.js";import"./ArtifactShareButton-B88bFGyl.js";import"./api-url-DLodfFrf.js";import{r as fm}from"./taskAssignee-BVYUmHbR.js";import{B as ji}from"./badge-aEbtcL2n.js";import{g as hm,r as xm,a as Qi,C as gm,b as bm,T as vm,A as wm,c as jm}from"./ToolTimeline-Bq0b2JHy.js";import{S as ym}from"./StreamingMarkdown-DOkfYjgm.js";import Nm from"./ActivityDrawer-DAqrMYy3.js";import{T as Zi}from"./trash-2-BDsDy3gR.js";import{P as el}from"./play-DEWq-60x.js";import Sm from"./AgentMessage-DS0QJHcf.js";import{T as Cm,Q as yi,C as km}from"./ComposerStatusPanels-BTSD1WUN.js";import{t as Im}from"./verificationEvidence-mYD5lqcH.js";import{e as Rm,r as Am}from"./taskLiveState-CjVBpxIP.js";import{b as Pm}from"./useTaskLivePresence-C7vqf0Xr.js";import{b as Em}from"./ConfirmDoubtsCard-5-Tr80hR.js";import{W as Tm,a as Lm,b as $m}from"./WorkGraphLineagePanel-qNQIEObD.js";import{u as _m,h as Mm,a as Om,b as Dm,c as Fm}from"./useWorkGraph-Bmmt9lAH.js";import{a as Bm}from"./WorkflowCanvas-D77MNqUy.js";import{a as zm,f as Ni,c as Si}from"./composerPluginRecommendations-DH8eVkXj.js";import{b as Ci,C as Rn,s as ki,c as Wm}from"./composer-mention-groups-mSqaKIwn.js";import{u as Km,P as Vm}from"./PluginConnectDialog-DlaR1NpO.js";import{C as Ii}from"./cloud-CRcFBbpu.js";import{f as Ri}from"./formatDistanceToNow-Ca8XUcSB.js";import{C as ts}from"./circle-x-ChJHvhq0.js";import{E as Hm}from"./ellipsis-BAmgce7q.js";import{Z as tl}from"./zap-DOyFGPoB.js";import{L as qm}from"./lock-Jc79EEeh.js";import{A as Gm}from"./activity-CmhMRZ-q.js";import{A as sl}from"./arrow-down-DDhgIMRF.js";import{r as Jm}from"./index-OwaqD2Hs.js";import{r as Um}from"./index-Bwd2g-Nx.js";import{P as Ym}from"./package-C9nsiFco.js";import{C as Xm}from"./chevron-up-7RIBeIs5.js";import{P as Qm}from"./paperclip-CdXAD342.js";import"./composer-plugin-chip-O6DfYSkU.js";import"./plugin-hero-gradient-B9RIdNkm.js";import"./settings-2-C4K0hVr0.js";import"./app-window-onVEKfkg.js";import"./file-image-jxJImllV.js";import"./file-spreadsheet-BClyFhZx.js";import"./file-archive-B_BgsXiH.js";import"./workspaceTree-DLTdRSO1.js";import"./WorkspaceIDE-mFopb5i-.js";import"./git-compare-arrows-CQYEeVeb.js";import"./save-DhA2IETK.js";import"./file-DvIrRJKi.js";import"./reactSandpackFiles-Ckq6L-NX.js";import"./isElementDisabled-CwHw_lZC.js";import"./resolveAriaLabelledBy-CZd1bu7B.js";import"./clamp-DyuOe9kr.js";import"./git-branch-DRy-lKL8.js";import"./artifact-validation-6sQJTJ1Y.js";import"./motion-CNngsM_T.js";import"./circle-question-mark-CopOPzd-.js";import"./pencil-XIhRmLy8.js";import"./message-square-text-CgisRh1U.js";import"./arrow-up-qXuqvH2E.js";import"./htmlDocumentTitle-Dhf1RWaV.js";import"./VideoProjectArtifactCard-D1QblFra.js";import"./layers-DhUKMb1_.js";import"./thumbs-up-Ca4fGdt-.js";import"./file-code-CffEJzMa.js";import"./folder-B2yf9f_m.js";import"./useBridgeFileAccessToken-CQTFigIo.js";import"./ArtifactMarkdownPreview-CCoFiQgq.js";import"./openclawMediaMarkdown-CdhVoFIf.js";import"./MermaidDiagram-Cxn2qd4O.js";import"./code-xml-BxUbH-VE.js";import"./zoom-out-DePrSaDK.js";import"./maximize-2-BjQ2jqL3.js";import"./WorkspaceSitePreview-BJbFMile.js";import"./bridge-apps-BZk9uT9n.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./video-editor-preload-DwsSUJvT.js";import"./rotate-ccw-ODDHly_F.js";import"./index-Chjiymov.js";import"./useArtifactPreviewSource-lY6__QjV.js";import"./ArtifactThumbnail-Dabo6O3B.js";import"./minus-DOl5gGwP.js";import"./file-diff-Dp5qecI4.js";import"./panel-right-close-Bj9xj2wE.js";import"./format-rfWXufZF.js";import"./en-US-CHWDLVng.js";import"./codeFenceInfo-AlTYuH6e.js";import"./extends-CF3RwP-h.js";import"./index-CvVbjaaV.js";import"./at-sign-CGs3Pake.js";import"./volume-2-Bb9RnzSI.js";import"./link-2-DvNv9hSL.js";import"./table-2L4RosRO.js";import"./circle-CcldZjL8.js";import"./network-BkQm21yA.js";import"./flask-conical-DQAO7GtR.js";import"./arrow-right-DHJTl3u2.js";import"./list-checks-DXDOLBK7.js";import"./clipboard-CoHmB2YL.js";import"./drawer-hSoyjkmV.js";import"./popover-Bz-_ODEM.js";import"./workflowShortcutMapping-CLcCookh.js";import"./wallet-C0RfU4od.js";
2import"./SettingsPluginFavicon-De86jn1p.js";import"./orbit-CPhzD6en.js";import"./modelPickerCore-g-OGHH8k.js";import"./funnel-GrDHDW-p.js";import"./star-B0CxB3P_.js";import"./ComboboxItem-Bw-Tq1PE.js";import"./switch-CF0DIvqJ.js";import"./sliders-horizontal-xHxLpW_v.js";import"./arrow-left-right-CULctuYC.js";import"./puzzle-BLfxJ85J.js";import"./audio-lines-DmHAnQg4.js";import"./tabs-LUqGrWfE.js";import"./CompositeRoot-SMvD_Fv4.js";import"./apiResponse-DYkfnH0b.js";import"./info-Jciv6U4s.js";import"./TaskProgressCard-CqRQVFK8.js";import"./laptop-minimal-CxzY1X7Q.js";import"./toolEventOutputFiles-CIulsOCW.js";import"./core.esm-DYp12Gts.js";import"./useOpenClawDashboardServer-Ck7aElVV.js";import"./circle-dashed-DFAUbnie.js";import"./gauge-DUamjeke.js";import"./arrow-up-right-BtPmoXoo.js";import"./lightbulb-0kSASKe6.js";import"./boxes-D1mSkMkQ.js";import"./style-Bc4P4rGl.js";import"./zoom-CLhniufO.js";import"./transform-DXgNwI-K.js";import"./value-BejbUmDB.js";import"./confirmAction-CCsCq1jr.js";import"./usePluginConnections-D6nb7Ciz.js";import"./key-round-0trrxj9d.js";import"./endOfMonth-d-B-NzGW.js";const Zm=new Set(["md","markdown","txt","text","csv","doc","docx","pdf","rtf"]),eu=new Set(["html","htm","jsx","tsx","react"]),nl=["md","markdown","txt","html"];function vt(n=""){return String(n||"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function oe(n){if(!n||typeof n!="string")return"";const a=(n.includes("/")?n.split("/").pop():n).split(".");if(a.length<2)return"";const m=a.pop();return m&&m.length<=12?m.toLowerCase():""}function Ja(n,d){const a=String(n||"").replace(/^\/+/,"").trim();return a?Gi(d,a):""}const Pa=Ja;function Re(n,d=[],a=""){const m=String(n||"").trim();if(!m)return"";const h=Qa({path:m,name:m.split("/").filter(Boolean).pop()||m},d);if(h!=null&&h.path){const k=String(h.path);return k.startsWith("/")?k:Pa(k,a)}const t=qi(m,d),j=(t==null?void 0:t.path)||m;if(String(j).startsWith("/"))return j;const N=String(j).split("/").filter(Boolean).pop()||j,v=/\.[a-z0-9]{1,12}$/i.test(N);if(!String(j).includes("/")&&!v&&a){const k=vt(N.replace(/\.[^.]+$/,""));if(k){for(const R of nl){const E=`${k}.${R}`,O=d.find(w=>{const $=String((w==null?void 0:w.name)||"").toLowerCase(),_=vt($.replace(/\.[^.]+$/,""));return $===E||$===`${k}.${R}`||_===k});if(O!=null&&O.path){const w=String(O.path);return w.startsWith("/")?w:Pa(w,a)}}return""}}return Pa(j,a)}function Qa(n={},d=[]){var E,O,w;const a=String((n==null?void 0:n.path)||(n==null?void 0:n.relativePath)||((E=n==null?void 0:n.artifactRef)==null?void 0:E.path)||((O=n==null?void 0:n.delivery)==null?void 0:O.fileName)||"").trim(),m=String((n==null?void 0:n.name)||(n==null?void 0:n.title)||((w=n==null?void 0:n.artifactRef)==null?void 0:w.title)||a.split("/").filter(Boolean).pop()||"").trim(),h=ui(a).toLowerCase(),t=m.toLowerCase(),j=t.replace(/\.[^.]+$/,""),N=vt(j),b=(h.split("/").filter(Boolean).pop()||"").toLowerCase(),k=vt(b.replace(/\.[^.]+$/,""));let R=null;for(const $ of d){const _=ui(($==null?void 0:$.path)||($==null?void 0:$.relativePath)||"").toLowerCase(),B=String(($==null?void 0:$.name)||"").toLowerCase(),G=B.replace(/\.[^.]+$/,""),J=vt(G);if(h&&(_===h||_.endsWith(`/${h}`))||b&&(B===b||_.endsWith(`/${b}`))||t&&B===t||j&&G===j||N&&J===N)return $;!R&&N&&J&&N===J&&(R=$),!R&&k&&J&&k===J&&(R=$)}return R}function tu(n="",d="",a={}){var N,v;const m=[],h=b=>{const k=String(b||"").trim();!k||m.includes(k)||m.push(k)};h(n);const t=String((a==null?void 0:a.name)||(a==null?void 0:a.title)||((N=a==null?void 0:a.artifactRef)==null?void 0:N.title)||"").trim(),j=vt(t.replace(/\.[^.]+$/,""))||vt(((v=String(n).split("/").pop())==null?void 0:v.replace(/\.[^.]+$/,""))||"");if(j&&d){for(const b of["md","html","htm","txt","markdown"])h(Ja(`${j}.${b}`,d));h(Ja("index.html",d))}return m}function Ea(n={},d=[],a=""){var N,v,b,k;const m=typeof(n==null?void 0:n.content)=="string"?n.content:typeof((N=n==null?void 0:n.artifactRef)==null?void 0:N.code)=="string"?n.artifactRef.code:"",h=Qa(n,d);if(h!=null&&h.path){const R=String(h.path);
2return{path:Re(R,d,a),name:h.name||R.split("/").filter(Boolean).pop()||"file",content:m,ext:oe(h.name||R)}}const t=String((n==null?void 0:n.path)||(n==null?void 0:n.relativePath)||((v=n==null?void 0:n.artifactRef)==null?void 0:v.path)||((b=n==null?void 0:n.delivery)==null?void 0:b.fileName)||"").trim(),j=String((n==null?void 0:n.name)||(n==null?void 0:n.title)||((k=n==null?void 0:n.artifactRef)==null?void 0:k.title)||t.split("/").filter(Boolean).pop()||"").trim();if(t){const R=Re(t,d,a);return{path:R,name:j||R.split("/").filter(Boolean).pop()||"file",content:m,ext:oe(t||j)}}if(j&&a){const R=vt(j.replace(/\.[^.]+$/,""));if(R){for(const O of nl){const w=j.includes(".")?j:`${R}.${O}`,$=d.find(_=>{const B=String((_==null?void 0:_.name)||"").toLowerCase();return B===w.toLowerCase()||B===`${R}.${O}`});if($!=null&&$.path)return{path:Re($.path,d,a),name:$.name||w,content:m,ext:oe($.name||w)}}const E=j.includes(".")?j:`${R}.md`;return{path:null,name:E,content:m,ext:oe(E)}}}return null}async function su(n,{orgId:d,workspaceFiles:a=[],workspaceFolder:m=""}={}){if(!n)return null;if(n.filesRef)return n;if(n.fileRef||n.artifactRef){const b=n.fileRef||n.artifactRef;if((b==null?void 0:b.content)!=null&&String(b.content).length>0||(b==null?void 0:b.code)!=null&&String(b.code).length>0||!(b!=null&&b.path))return n;const R=Re(b.path,a,m);try{const{fetchBridgeFile:E}=await Tt(async()=>{const{fetchBridgeFile:$}=await import("./bridge-files-BJMqnMlc.js");return{fetchBridgeFile:$}},__vite__mapDeps([0,1,2,3,4,5,6,7,8])),O=await E(R||b.path,{orgId:d,signal:AbortSignal.timeout(1e4)});if(!O.ok)return n;const w=await O.text();return n.fileRef?{...n,fileRef:{...n.fileRef,content:w,path:R||n.fileRef.path}}:{...n,artifactRef:{...n.artifactRef,code:w,path:R||n.artifactRef.path}}}catch{return n}}if(!(n.type!==void 0||n.title||n.path||n.code!==void 0))return n;let t=n.code??"",j=Re(n.path,a,m);if(!t&&j)try{const{fetchBridgeFile:b}=await Tt(async()=>{const{fetchBridgeFile:R}=await import("./bridge-files-BJMqnMlc.js");return{fetchBridgeFile:R}},__vite__mapDeps([0,1,2,3,4,5,6,7,8])),k=await b(j,{orgId:d,signal:AbortSignal.timeout(1e4)});k.ok&&(t=await k.text())}catch{}const N=n.title||(j?String(j).split("/").filter(Boolean).pop():"")||"File",v=oe(j||N)||String(n.lang||n.type||"txt").toLowerCase();if(eu.has(v)&&!Zm.has(v)){const b=["jsx","tsx"].includes(v)?"react":v==="htm"?"html":v;return{artifactRef:{...n,type:b,title:N,code:t,path:j||n.path,lang:v}}}return{fileRef:{name:N,ext:v||"txt",content:t,path:j||n.path}}}function nu(n="",d=""){const a=String(n||"").trim();if(!a)return"";if(/^diff --git /m.test(a)||/^\*\*\* (?:Update|Add|Delete) File:/m.test(a))return a;const m=String(d||"").trim()||Ac(a)||"file";return`diff --git a/${m} b/${m} 3${a}`}function au(n=[]){const d=[];for(const a of Array.isArray(n)?n:[]){if(!a||typeof a!="object")continue;const m=Number(a.timestamp)||0,h=String(a.path||"").trim(),t={...a.runId?{runId:a.runId}:{},...a.taskId?{taskId:a.taskId}:{},...a.agentName?{agentName:a.agentName}:{},...a.sessionKey?{sessionKey:a.sessionKey}:{}};if(h&&typeof a.before=="string"&&typeof a.after=="string"&&a.before!==a.after){d.push({event:"tool_result",time:m,...t,data:{tool:"edit",params:{path:h,old_string:a.before,new_string:a.after},...t}});continue}const j=nu(a.diffText,h);j&&d.push({event:"diff_artifact",time:m,...t,data:{diff:j,...t}})}return d}const ru=f.forwardRef(({className:n,orientation:d="horizontal",decorative:a=!0,...m},h)=>e.jsx(ud,{ref:h,orientation:d,role:a?"none":void 0,className:V("shrink-0 bg-border",d==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",n),...m}));ru.displayName="Separator";function ou({repo:n,taskId:d,onClose:a,onSave:m,onRun:h,isRunning:t=!1}){var ss,ns,Ms,as;const[j,N]=f.useState(((ss=n==null?void 0:n.runConfig)==null?void 0:ss.setupCommands)||"npm install"),[v,b]=f.useState(((ns=n==null?void 0:n.runConfig)==null?void 0:ns.runCommand)||"npm run dev"),[k,R]=f.useState(((Ms=n==null?void 0:n.runConfig)==null?void 0:Ms.envVars)||[]),[E,O]=f.useState(""),[w,$]=f.useState(""),[_,B]=f.useState(((as=n==null?void 0:n.runConfig)==null?void 0:as.recordSession)!==!1),[G,J]=f.useState(!1),$e=()=>{E.trim()&&(R(K=>[...K,{key:E.trim(),value:w}]),O(""),$(""))},Lt=K=>{R(xe=>xe.filter((ut,Ae)=>Ae!==K))},Qe=K=>{var Ae;const xe=(Ae=K.target.files)==null?void 0:Ae[0];if(!xe)return;const ut=new FileReader;ut.onload=$t=>{var _t;const Ze=(_t=$t.target)==null?void 0:_t.result;if(typeof Ze!="string")return;const rs=Ze.split(` 4`).map(je=>je.trim()).filter(je=>je&&!je.startsWith("#")).map(je=>{const et=je.indexOf("=");return et===-1?null:{key:je.slice(0,et).trim(),value:je.slice(et+1).trim().replace(/^["']|["']$/g,"")}}
4).filter(Boolean);R(je=>{const et=new Set(je.map(os=>os.key)),Mt=rs.filter(os=>!et.has(os.key));return[...je,...Mt]})},ut.readAsText(xe),K.target.value=""},_s=async()=>{J(!0);const K={setupCommands:j.trim(),runCommand:v.trim(),envVars:k,recordSession:_};await(m==null?void 0:m(K)),J(!1)},_e=async()=>{await _s(),h==null||h()},Mn=n!=null&&n.url?n.url.split("/").slice(-2).join("/"):(n==null?void 0:n.path)||"Repo";return e.jsx(Ji,{open:!0,modal:!1,disablePointerDismissal:!0,onOpenChange:K=>{K||a()},children:e.jsxs(Ui,{children:[e.jsx(Yi,{className:"z-[70]",onClick:a}),e.jsx("div",{className:"fixed inset-0 z-[70] flex items-end sm:items-center justify-center p-0 sm:p-4 overscroll-contain pointer-events-none",children:e.jsxs("div",{className:"pointer-events-auto mx-auto max-h-[85dvh] sm:max-h-[90vh] w-full max-w-[min(32rem,calc(100vw-1rem))] overflow-hidden rounded-t-2xl sm:rounded-2xl bg-white shadow-2xl",onClick:K=>K.stopPropagation(),onPointerDown:K=>K.stopPropagation(),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-neutral-100 px-4 py-4 sm:px-5 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(Wi,{className:"w-4 h-4 text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-neutral-900",children:"Run Configuration"}),e.jsx("p",{className:"text-[11px] text-neutral-500 font-mono",children:Mn})]})]}),e.jsx(T,{variant:"ghost",size:"icon",onClick:a,className:"h-7 w-7 text-neutral-400 hover:text-neutral-600",children:e.jsx(En,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"max-h-[min(60dvh,60vh)] space-y-4 overflow-y-auto px-4 py-4 sm:px-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-neutral-700 mb-1.5",children:"Setup commands"}),e.jsx("p",{className:"text-[11px] text-neutral-400 mb-2",children:"Run before starting the app (install dependencies, build, etc.)"}),e.jsx("textarea",{value:j,onChange:K=>N(K.target.value),placeholder:`npm install 5npm run build`,rows:3,className:"w-full px-3 py-2 text-sm font-mono rounded-lg border border-neutral-200 bg-stone-50 outline-none focus:border-2 focus:border-emerald-200 focus:border-emerald-300 resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-neutral-700 mb-1.5",children:"Run command"}),e.jsx("p",{className:"text-[11px] text-neutral-400 mb-2",children:"Command to start the app (dev server, preview, etc.)"}),e.jsx(Nn,{value:v,onChange:K=>b(K.target.value),placeholder:"npm run dev",className:"w-full font-mono border-neutral-200 bg-stone-50 focus:border-2 focus:border-emerald-200 focus:border-emerald-300"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-neutral-700",children:"Environment variables"}),e.jsxs("label",{className:"inline-flex items-center gap-1 px-2 py-1 text-[11px] font-medium text-neutral-500 bg-stone-50 rounded-md border border-neutral-200 hover:bg-stone-100 cursor-pointer transition-colors",children:[e.jsx(Pc,{className:"w-3 h-3"}),"Upload .env",e.jsx("input",{type:"file",accept:".env,.env.local,.env.production",className:"hidden",onChange:Qe})]})]}),k.length>0&&e.jsx("div",{className:"space-y-1.5 mb-2",children:k.map((K,xe)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-0 rounded-md border border-neutral-200 overflow-hidden text-xs font-mono",children:[e.jsx("span",{className:"px-2 py-1.5 bg-stone-50 text-neutral-600 border-r border-neutral-200 min-w-[100px]",children:K.key}),e.jsx(Nn,{value:K.value,onChange:ut=>{const Ae=[...k];Ae[xe]={...Ae[xe],value:ut.target.value},R(Ae)},className:"flex-1 px-2 py-1.5 bg-white text-neutral-800 border-0 rounded-none shadow-none focus-visible:ring-0",type:K.key.toLowerCase().includes("secret")||K.key.toLowerCase().includes("key")||K.key.toLowerCase().includes("token")?"password":"text"})]}),e.jsx(T,{variant:"ghost",size:"icon",onClick:()=>Lt(xe),className:"p-1 text-neutral-300 hover:text-green-500 h-auto w-auto",children:e.jsx(Zi,{className:"w-3.5 h-3.5"})})]},xe))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Nn,{value:E,onChange:K=>O(K.target.value),placeholder:"KEY",className:"w-[120px] px-2 py-1.5 text-xs font-mono border-neutral-200 bg-stone-50 focus:border focus:border-emerald-200",onKeyDown:K=>{K.key==="Enter"&&(K.preventDefault(),$e())}}),e.jsx(Nn,{value:w,onChange:K=>$(K.target.value),placeholder:"value",className:"flex-1 px-2 py-1.5 text-xs font-mono border-neutral-200 bg-stone-50 focus:border focus:border-emerald-200",onKeyDown:K=>{K.key==="Enter"&&(K.preventDefault(),$e())}}),e.jsx(T,{variant:"ghost",size:"icon",onClick:$e,className:"p-1.5 text-neutral-400 hover:text-emerald-600 hover:bg-emerald-50 h-auto w-auto",children:e.jsx(pd,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-neutral-700",children:"Record session"}),e.jsx("p",{className:"text-[11px] text-neutral-400",children:"Capture screen recording (ffmpeg) and save to task folder"})]}),e.jsx(T,{variant:"ghost",onClick:()=>B(!_),className:V("w-9 h-5 rounded-full relative p-0",_?"bg-emerald-500":"bg-stone-300"),children:e.jsx("span",{className:V("absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform",_?"translate-x-4":"translate-x-0.5")})})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-neutral-100 bg-stone-50/50",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:a,children:"Cancel"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{variant:"outline",size:"sm",onClick:_s,disabled:G,children:G?"Savingâ¦":"Save"}),e.jsx(T,{size:"sm",onClick:_e,disabled:t||!v.trim(),className:V(t?"bg-amber-100 text-amber-700 cursor-wait hover:bg-amber-100":"bg-emerald-600 text-white hover:bg-emerald-700"),children:t?e.jsxs(e.Fragment,{children:[e.jsx(Xa,{className:"w-3.5 h-3.5 animate-spin"})," Runningâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(el,{className:"w-3.5 h-3.5"})," Save & Run"]}
5)})]})]})]})})]})})}const iu=f.lazy(()=>Tt(()=>import("./percentages-BXMCSKIN-CjKe5fGn.js").then(n=>n.E),__vite__mapDeps([9,1,2,3,4,10,11,6,7,12,13,14,15,16,17,18,19,20,21,22,0,5,8,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40]))),lu=f.lazy(()=>Tt(()=>import("./TerminalPage-Cyg0C-BW.js"),__vite__mapDeps([41,1,2,3,4,42,43,6,7,44,45,46,47]))),cu=f.lazy(()=>Tt(()=>import("./SideVideoEditorPanel-Dy3LfEHr.js"),__vite__mapDeps([48,2,6,1,3,4,7,49]))),du=f.lazy(()=>Tt(()=>import("./AppsBrowser-RLiBZQkN.js"),__vite__mapDeps([50,2,1,3,4,51,6,7,52,53,54,55,56,5,57,58,59,60,61,62]))),mu=f.lazy(()=>Tt(()=>import("./ChatPanel-DT90xFdG.js"),__vite__mapDeps([63,2,64,6,1,3,4,7,65,66,67,32,61,68,69,57,70,17,71,72,73,35,74,16,18,19,20,21,22,33,0,5,8,34,75,38,76,77,78,79,11,80,13,52,28,29,30,31,81,82,14,12,24,23,36,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,45,105,106,107,108,109,110,111,112,54,113,114,115,116,117,118,119,120,121,122,123,124,55,59,60,53,125,126,127,128,129,130,131,132,133,134,135,136,137,138,46,139,140,141,142,143,144,145,146,147,148,149,150]))),Ln=vd,uu=120;function bt(n,d){return(n==null?void 0:n.id)||(n==null?void 0:n.path)||(n==null?void 0:n.title)||`artifact-${d}`}function Ta(n){const d=String(bt(n,0)||"");return d?Xe(d).toLowerCase():""}function La(n,d,a){const m=Qa(n,d);if(m!=null&&m.path)return Re(m.path,d,a);const h=_n(n)||dt(n);return Re(h,d,a)}function pu(n=""){var h;const d=[];if(!n)return d;const a=/^\*\*\* (?:Update|Add|Delete) File: (.+)$/gm;let m;for(;m=a.exec(String(n));){const t=(h=m[1])==null?void 0:h.trim();t&&!d.includes(t)&&d.push(t)}return d}function fu(n=[]){const d=[],a=new Set,m=(h,t=null)=>{var N;if(!h||a.has(h))return;const j=h.split("/").pop()||h;za({name:j,path:h})||(a.add(h),d.push({path:h,name:j,ext:((N=j.split(".").pop())==null?void 0:N.toLowerCase())||"",...t?{description:t}:{}}))};for(const h of Array.isArray(n)?n:[]){const t=(h==null?void 0:h.data)||{};if((h==null?void 0:h.event)==="file_written"){m(t.path||t.filePath||t.name||"",t.description||null);continue}if((h==null?void 0:h.event)!=="tool_result"||t.success===!1)continue;const j=String(t.tool||t.name||"").toLowerCase(),N=t.params||t.args||{};if(j==="write"||j==="edit"||j==="write_file"){m(N.path||N.file_path||N.filePath||t.path||t.filePath||"",j==="edit"?"Edited file":"Wrote file");continue}if(j==="apply_patch"){const v=N.patch||t.patch||t.raw||t.summary||"";pu(v).forEach(b=>m(b,"Patched file"))}}return d}function Ai(n){const d=oe(n.title||"")||oe(n.path||""),a=String(n.type||n.lang||n.ext||"").toLowerCase();return(d||a||"txt").toLowerCase()}function $a(n){if(!n)return null;if(n.artifactRef){const d=n.artifactRef,a=d.path||d.title||"artifact",m=d.title||(typeof d.path=="string"?d.path.split("/").pop():null)||"Artifact",h=String(oe(m)||oe(d.path)||d.lang||d.type||"").toLowerCase();return{id:a,title:m,code:d.code||"",type:h||"html",lang:h||"html",path:d.path}}if(n.fileRef){const d=n.fileRef,a=d.name||(typeof d.path=="string"?d.path.split("/").pop():null)||"file",m=d.path||a;if(!d.content&&!d.path)return null;const h=String(oe(a)||oe(d.path)||d.ext||"").toLowerCase();return{id:m,title:a,path:d.path,code:d.content||"",type:h,lang:h}}return Array.isArray(n.filesRef)&&n.filesRef.length>0?n.filesRef.map((d,a)=>{const m=d.name||d.path||`File ${a+1}`,h=String(oe(m)||oe(d.path)||d.ext||"").toLowerCase();return{id:d.path||d.name||`file-${a}`,title:m,path:d.path,code:d.content||"",type:h,lang:h}}):null}function hu(n){return n&&String(n).replace(/\*\*([^*]+)\*\*/g,"$1").replace(/\*([^*]+)\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/_{2}([^_]+)_{2}/g,"$1").replace(/_([^_]+)_/g,"$1")}function Pi(n){if(!n||typeof n!="string")return n;const d=n.lastIndexOf("."),a=d>=0?n.slice(0,d):n,m=d>=0?n.slice(d):"";return a.replace(/[-_]\d{10,}$/,"").replace(/[-_]/g," ").trim().split(/\s+/).map(N=>N.charAt(0).toUpperCase()+N.slice(1).toLowerCase()).join(" ")+m}function Ei(n){if(!n)return"FILE";const d=n.split(".");return d.length<=1?"MD":d.pop().toUpperCase()}function Ti(n){var m;const d=(m=n==null?void 0:n.split(".").pop())==null?void 0:m.toLowerCase();return["js","jsx","ts","tsx","py","html","css","json","sh","bash"].includes(d)?"code":"document"}function xu(n,d){const a=String(n||"").replace(/^\/+/,"").trim();return a?Gi(d,a):""}function Li(n,d){const a=n==null?void 0:n.path;if(!a)return"";const m=String(a);return m.startsWith("/")?m:xu(m,d)}function _a(n,d){if(!n||!d||typeof d!="object")return"";if(typeof d[n]=="string")return d[n];const a=Xe(n).toLowerCase();if(!a)return"";for(const[t,j]of Object.entries(d))if(typeof j=="string"&&Xe(t).toLowerCase()===a)return j;
5const m=a.split("/").filter(Boolean).pop();if(!m)return"";const h=[];for(const[t,j]of Object.entries(d)){if(typeof j!="string")continue;Xe(t).toLowerCase().split("/").filter(Boolean).pop()===m&&h.push(j)}return h.length===1?h[0]:""}function $i(n={}){const d=n&&typeof n=="object"?n:{},m={...typeof d.input=="object"&&d.input?d.input:{},...typeof d.params=="object"&&d.params?d.params:{},...typeof d.args=="object"&&d.args?d.args:{}},h=d.tool||d.name||"";let t="";if(typeof d.raw=="string")t=d.raw;else if(d.raw!=null)try{t=JSON.stringify(d.raw)}catch{t=String(d.raw)}const j=typeof d.summary=="string"?d.summary:"";return{tool:h,params:m,result:d.result??null,raw:t,summary:j}}function _i(n,d){var m;const a=new Set;if(!(n!=null&&n.id))return[];for(const h of n.comments||[]){h.runId&&a.add(String(h.runId));for(const t of h.toolEvents||[])(m=t==null?void 0:t.data)!=null&&m.runId&&a.add(String(t.data.runId))}for(const h of Object.values(d||{}))h!=null&&h.runId&&(h==null?void 0:h.taskId)!=null&&String(h.taskId)===String(n.id)&&a.add(String(h.runId));return[...a].filter(Boolean)}function Mi(n){var a;const d=new Set;for(const m of(n==null?void 0:n.comments)||[]){m.sessionKey&&d.add(String(m.sessionKey));for(const h of m.toolEvents||[])(a=h==null?void 0:h.data)!=null&&a.sessionKey&&d.add(String(h.data.sessionKey))}return[...d].filter(Boolean)}function Ps({label:n="Loadingâ¦"}){return e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-white text-xs text-neutral-400",children:n})}const gu=["files","diffs","activity","browser","terminal","canvas","video","apps","chat"],bu=["files","diffs","activity","browser"];function Ua(n,d,a){const m=n&&typeof n=="object"?n:{},h=m.data||{};if(Array.isArray(h.events)&&h.events.length>0){for(const N of h.events)if(!(!N||typeof N!="object"))if(N.event!=null&&N.data!=null)Ua(N,d,a);else{const v=$i(N),b=Ga({tool:v.tool,params:v.params,result:v.result,raw:v.raw,summary:v.summary});b!=null&&b.diffText&&a(b.diffText,b.path,m.time||N.time||d,b)}}const t=$i(h),j=Ga({tool:t.tool,params:t.params,result:t.result,raw:t.raw,summary:t.summary});j!=null&&j.diffText&&a(j.diffText,j.path,m.time||d,j)}const vu=new Set(["exec","bash","shell","sh","zsh","openclaw_exec","run_terminal_cmd","run_terminal_command","execute","execute_command","command","terminal","subprocess","process"]);function An(n){const d=String(n.tool||n.name||"").toLowerCase();return!!(vu.has(d)||d.includes("terminal")||d.includes("exec")||d.includes("shell"))}function wu(n){const d={...typeof n.params=="object"&&n.params?n.params:{},...typeof n.args=="object"&&n.args?n.args:{}};return d.command??d.cmd??d.shell_command??d.line??d.script??n.command??""}function Oi(n,d=[]){var h;if(!(n!=null&&n.fileName))return null;const a=(h=n.fileName.split("/").pop())==null?void 0:h.toLowerCase(),m=a==null?void 0:a.replace(/\.[^.]+$/,"");return d.find(t=>{const j=String(t.name||"").toLowerCase(),N=j.replace(/\.[^.]+$/,"");return j===a||N===m})||null}function _n(n){var d;return(n==null?void 0:n.path)||(n==null?void 0:n.relativePath)||((d=n==null?void 0:n.delivery)==null?void 0:d.fileName)||""}function dt(n){var d;return(n==null?void 0:n.name)||((d=n==null?void 0:n.delivery)==null?void 0:d.fileName)||"Artifact"}function Ye(n){const d=dt(n),a=_n(n);return String((n==null?void 0:n.ext)||oe(a)||oe(d)||"").toLowerCase()}function Di(n){var h;const d=(n==null?void 0:n.path)||(n==null?void 0:n.relativePath)||((h=n==null?void 0:n.delivery)==null?void 0:h.fileName)||(n==null?void 0:n.name)||"",a=Xe(d),m=a.lastIndexOf("/");return m>=0?a.slice(0,m):""}function Ya(n){return["html","htm"].includes(Ye(n))}function ju(n=[]){return!Array.isArray(n)||n.length===0?null:n.find(d=>/(^|\/)index\.html?$/i.test(_n(d)||dt(d)))||n.find(d=>Ya(d))||n[0]||null}function Ma(n,d=(n==null?void 0:n.content)||""){var j;const a=dt(n),m=(n==null?void 0:n.path)||(n==null?void 0:n.relativePath)||((j=n==null?void 0:n.artifactRef)==null?void 0:j.path)||"",h=oe(m)||oe(a)||Ye(n)||"txt",t=["jsx","tsx"].includes(h)?"react":["html","htm"].includes(h)?"html":null;
5return t?{artifactRef:{type:t,title:a,code:d,path:m||(n==null?void 0:n.path),lang:h}}:{fileRef:{name:a,ext:h,content:d,path:m||(n==null?void 0:n.path)}}}function Pn(n){var d,a;return String((n==null?void 0:n.sourcePath)||((d=n==null?void 0:n.fileRef)==null?void 0:d.path)||((a=n==null?void 0:n.artifactRef)==null?void 0:a.path)||"").trim()}const yu=18,Fi={background:"#f6f8fa",margin:0,padding:"0.9rem 1.1rem",fontSize:"0.78rem",lineHeight:1.7,overflowX:"auto",fontFamily:"ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace",color:"#24292e",whiteSpace:"pre"},Nu={display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0.3rem 1rem",background:"#eef0f3",borderBottom:"1px solid #e2e4e9"},Bi={width:"100%",padding:"0.45rem",fontSize:11,fontWeight:600,color:"#57606a",borderTop:"1px solid #e2e4e9",background:"#eef0f3",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:6};function Su({language:n,codeString:d,lines:a}){const m=a>yu,[h,t]=Ls.useState(!m);return e.jsxs("div",{style:{margin:"0.75rem 0",borderRadius:8,overflow:"hidden",border:"1px solid #e2e4e9",background:"#f6f8fa"},children:[e.jsxs("div",{style:Nu,children:[e.jsx("span",{style:{fontSize:10,fontWeight:600,color:"#8b949e",textTransform:"uppercase",letterSpacing:"0.06em",fontFamily:"monospace"},children:n||"code"}),e.jsxs("span",{style:{fontSize:10,color:"#8b949e"},children:[a," lines"]})]}),h?e.jsxs(e.Fragment,{children:[e.jsx("pre",{style:Fi,children:d}),m&&e.jsxs(T,{variant:"ghost",onClick:()=>t(!1),style:Bi,children:[e.jsx($s,{size:12,style:{transform:"rotate(180deg)"}})," Collapse"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx("pre",{style:{...Fi,maxHeight:148,overflow:"hidden",paddingBottom:0},children:d.split(` 6`).slice(0,10).join(` 7`)}),e.jsx("div",{style:{position:"absolute",bottom:0,left:0,right:0,height:60,background:"linear-gradient(to bottom, transparent, #f6f8fa)"}})]}),e.jsxs(T,{variant:"ghost",onClick:()=>t(!0),style:Bi,children:[e.jsx($s,{size:13})," Show ",a-7," more lines"]})]})]})}function Cu(n=[],d=[]){return{p:({children:a})=>{const m=Ls.Children.toArray(a),h=m[0];if(typeof h=="string"){const t=[{re:/^â \s*/,Icon:Cn,cls:"text-green-700"},{re:/^â\s*/,Icon:ts,cls:"text-green-500"},{re:/^ð\s*/,Icon:Cn,cls:"text-green-700"},{re:/^ð\s*/,Icon:hi,cls:"text-neutral-500"},{re:/^â ï¸\s*/,Icon:qa,cls:"text-amber-500"},{re:/^ð\s*/,Icon:Ha,cls:"text-neutral-500"},{re:/^ð\s*/,Icon:mt,cls:"text-neutral-600"},{re:/^ð\s*/,Icon:mt,cls:"text-neutral-600"},{re:/^ð\s*/,Icon:Qm,cls:"text-neutral-600"},{re:/^ð¡\s*/,Icon:hi,cls:"text-amber-400"},{re:/^ð\s*/,Icon:sl,cls:"text-neutral-500"},{re:/^â±\s*/,Icon:Wa,cls:"text-neutral-600"}];for(const{re:j,Icon:N,cls:v}of t){const b=h.match(j);if(b){const k=h.slice(b[0].length),R=k?[k,...m.slice(1)]:m.slice(1);return e.jsxs("p",{className:"font-[inherit] break-words whitespace-normal leading-[1.75] my-0.5 flex items-start gap-1.5",children:[e.jsx(N,{className:V("w-3.5 h-3.5 shrink-0 translate-y-[2px]",v)}),e.jsx("span",{className:"min-w-0 flex-1 [&_br]:block [&_br]:my-1",children:R})]})}}}return e.jsx("p",{className:"font-[inherit] break-words whitespace-normal leading-[1.75] my-1 [&_br]:block [&_br]:my-1",children:a})},strong:({children:a})=>e.jsx("strong",{className:"font-medium text-neutral-900",children:a}),em:({children:a})=>e.jsx("em",{className:"italic",children:a}),code:({className:a,children:m,node:h,...t})=>{var R,E,O,w;const j=/language-(\w+)/.exec(a||""),N=j?j[1]:"",v=String(m).replace(/\n$/,"");if(!(N||String(m).includes(` 8`)||((E=(R=h==null?void 0:h.position)==null?void 0:R.start)==null?void 0:E.line)!==((w=(O=h==null?void 0:h.position)==null?void 0:O.end)==null?void 0:w.line)))return e.jsx("code",{className:"px-1.5 py-0.5 bg-stone-50 text-neutral-900 rounded-md text-dense font-mono border border-neutral-200 whitespace-normal break-all max-w-full align-baseline [overflow-wrap:anywhere]",children:m});const k=v.split(` 9`).length;return e.jsx(Su,{language:N,codeString:v,lines:k})},ul:({children:a})=>e.jsx("ul",{className:"list-disc flex flex-col gap-1.5 pl-8 my-3",children:a}),ol:({children:a})=>e.jsx("ol",{className:"list-decimal flex flex-col gap-1.5 pl-8 my-3",children:a}),li:({children:a})=>{const m=[{re:/^â \s*/,Icon:Cn,cls:"text-green-700"},{re:/^â\s*/,Icon:ts,cls:"text-green-500"},{re:/^ð\s*/,Icon:Cn,cls:"text-green-700"}
9,{re:/^â ï¸\s*/,Icon:qa,cls:"text-amber-500"},{re:/^ð\s*/,Icon:Ha,cls:"text-neutral-500"},{re:/^ð\s*/,Icon:mt,cls:"text-neutral-600"}],h=Ls.Children.toArray(a),t=h[0];if(typeof t=="string")for(const{re:j,Icon:N,cls:v}of m){const b=t.match(j);if(b){const k=[t.slice(b[0].length),...h.slice(1)];return e.jsxs("li",{className:"whitespace-normal break-words leading-[1.75] list-none flex items-start gap-1.5 pl-0",children:[e.jsx(N,{className:V("w-3.5 h-3.5 shrink-0 translate-y-[2px]",v)}),e.jsx("span",{className:"min-w-0 flex-1 [&_br]:block [&_br]:my-1",children:k})]})}}return e.jsx("li",{className:"whitespace-normal break-words pl-2 leading-[1.75]",children:a})},blockquote:({children:a})=>e.jsx("blockquote",{className:"border-l-[3px] border-neutral-200 pl-4 italic my-4 text-neutral-600",children:a}),a:({href:a,children:m})=>e.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"text-neutral-900 underline underline-offset-2 decoration-neutral-200 hover:decoration-neutral-900",children:m}),h1:({children:a})=>e.jsx("h1",{className:"text-neutral-900 mt-6 mb-2 text-[1.05rem] font-semibold tracking-tight border-b border-neutral-200/60 pb-2",children:a}),h2:({children:a})=>e.jsx("h2",{className:"text-neutral-900 mt-5 mb-1 text-[0.95rem] font-semibold",children:a}),h3:({children:a})=>e.jsx("h3",{className:"text-neutral-600 mt-4 mb-1 text-[0.875rem] font-medium uppercase tracking-wide",children:a}),hr:()=>e.jsx("hr",{className:"my-5 border-neutral-200"}),br:()=>e.jsx("br",{className:"block my-1"}),pre:({children:a})=>e.jsx(e.Fragment,{children:a}),table:({children:a})=>e.jsx("div",{className:"overflow-x-auto my-4 rounded-xl border border-neutral-200",children:e.jsx("table",{className:"min-w-full text-sm border-collapse",children:a})}),thead:({children:a})=>e.jsx("thead",{className:"bg-stone-50 border-b border-neutral-200",children:a}),tbody:({children:a})=>e.jsx("tbody",{className:"divide-y divide-neutral-200",children:a}),tr:({children:a})=>e.jsx("tr",{className:"border-b border-neutral-100 last:border-0 hover:bg-stone-50/50",children:a}),th:({children:a})=>e.jsx("th",{className:"px-4 py-2.5 text-left font-semibold text-neutral-600 text-xs uppercase tracking-wider",children:a}),td:({children:a})=>e.jsx("td",{className:"px-4 py-2.5 text-neutral-600 align-top",children:a}),span:({node:a,children:m,...h})=>{var j;const t=h["data-mention"]||((j=a==null?void 0:a.properties)==null?void 0:j["data-mention"]);if(t){const N=n.find(k=>k.name.toLowerCase()===t.toLowerCase()),v=(d||[]).find(k=>k.name.toLowerCase()===t.toLowerCase()),b=N||v;if(b){const k=$n(b.name);return e.jsxs("span",{className:V("inline-flex items-center gap-1 px-1.5 py-0 rounded-md text-xs font-semibold align-middle whitespace-nowrap cursor-pointer hover:opacity-80 transition-opacity leading-5",k),children:[e.jsx(Ln,{src:b.avatar,name:b.name,size:"w-3.5 h-3.5 text-xxs",agent:N||b}),"@",b.name]})}return e.jsxs("span",{className:"inline-flex items-center text-xs font-semibold text-neutral-500 bg-stone-50 border border-neutral-200 px-1.5 rounded-md align-middle",children:["@",t]})}return e.jsx("span",{...h,children:m})}}}function ku(n=""){let d=String(n||"").replace(/<br\s*\/?>/gi,` 10`).replace(/\r\n/g,` 11`).replace(/\u00a0/g," ").replace(/\s*\[\/TOOL\]\s*/gi,"").replace(/\s*<\/TOOL>\s*/gi,"").replace(/<TOOL:\s*\w+[^>]*>/gi,"").replace(/\s*Output:\s*null\s*/gi,"").replace(/\s*Output for Next Step:[\s\S]*$/gi,"").replace(/\[TASK_COMMENT\]([\s\S]*?)\[\/TASK_COMMENT\]/gi,"$1").replace(/\[\/?TASK_COMMENT\]/gi,"").replace(/<task>[\s\S]*?<\/task>/gi,"").replace(/<task>[\s\S]*$/gi,"").replace(/<delivery>[\s\S]*?<\/delivery>/gi,"").replace(/<delivery>[\s\S]*$/gi,"").replace(/<file\s+[^>]*>[\s\S]*?<\/file>/gi,"").replace(/<file\s+[^>]*>[\s\S]*$/gi,"").replace(/<file\s+(?:[^>]*?)path="([^"]+)"[^>]*\/?>/gi,(h,t)=>`ð [${t.split("/").pop()}](${t})`).replace(/<file\s+[^>]*\/?>/gi,"").replace(/<diff>[\s\S]*?<\/diff>/gi,"").replace(/<diff>[\s\S]*$/gi,"").replace(/<artifact[^>]*>[\s\S]*?<\/artifact>/gi,"").replace(/<artifact[^>]*>[\s\S]*$/gi,"").replace(/<!--\s*TOOL_ACTIVITY[\s\S]*?-->/gi,"").replace(/<!--\s*TOOL_ACTIVITY[\s\S]*$/gi,"").replace(/<!--\s*TOOL_LOG[\s\S]*?(?:\/TOOL_LOG\s*)?-->/gi,"").replace(/<!--\s*TOOL_LOG[\s\S]*$/gi,"");return(d.match(/\*\*/g)||[]).length%2!==0&&(d=d.replace(/\*\*/g,"")),(d.match(/^```/gm)||[]).length%2!==0&&(d+="\n```"),d=d.replace(/\n{4,}/g,` 12 13 14`).replace(/[ \t]+\n/g,` 15`).replace(/\n[ \t]+/g,` 16`).trim(),d}function Iu(n=""){const d=String(n||"").toLowerCase();return["done","completed"].includes(d)?"completed":["running","in_progress","working"].includes(d)?"in_progress":"pending"}function al(n=[],d="Task checklist",a=null){if(!Array.isArray(n)||n.length===0)return null;const m=n.map((j,N)=>{const v=Iu(j==null?void 0:j.status),b=(j==null?void 0:j.assigneeName)||(j==null?void 0:j.assignee)||null,k=["failed","blocked"].includes(String((j==null?void 0:j.status)||"").toLowerCase())?` (${String(j.status).toLowerCase()==="failed"?"failed":"waiting"})`:"",R=`${(j==null?void 0:j.title)||`Step ${N+1}`}${k}${b?` â ${b}`:""}`,E=String((j==null?void 0:j.result)||"").split(` 17`).map(O=>O.trim()).find(Boolean);return{id:(j==null?void 0:j.id)||String(N+1),status:v,content:R,activeForm:v==="in_progress"&&E?`${R} â ${E.substring(0,120)}`:R}}),h=m.filter(j=>j.status==="completed").length,t=m.filter(j=>j.status==="in_progress").length;return{title:d,todos:m,summary:{completed:h,inProgress:t,pending:Math.max(0,m.length-h-t),total:m.length},updatedAt:a}}function Ru(n=[],d=null){return!Array.isArray(n)||n.length===0?null:al(n.map((a,m)=>({id:(a==null?void 0:a.id)||String(m+1),title:(a==null?void 0:a.title)||`Step ${m+1}`,assignee:(a==null?void 0:a.assigneeName)||(a==null?void 0:a.assignee)||null,status:a!=null&&a.completed?"completed":(a==null?void 0:a.status)||"pending",result:(a==null?void 0:a.outputSummary)||(a==null?void 0:a.output)||(a==null?void 0:a.failureReason)||""})),"Task checklist",d)}function Au(n=null){var m;if(!n)return!1;const d=String(n.executionPhase||"").toLowerCase(),a=String(((m=n.planReview)==null?void 0:m.status)||"").toLowerCase();return(d==="plan_review"||a==="pending")&&Array.isArray(n.executionSteps)&&n.executionSteps.length>0}function Pu(n=""){const d=String(n||"").replace(/\*\*/g,"").trim().replace(/^[^\p{L}\p{N}@]+/u,"");return/^(Plan|Pipeline Plan|Execution Plan|Task plan)\b/i.test(d)||/^(Paused|Incomplete|Complete|Task paused|Task incomplete|Task complete)\b/i.test(d)}function Es({content:n,agents:d,humans:a,className:m=""}){if(!n)return null;let h=ku(n);return e.jsx("div",{className:V("leading-[1.75]",m||"text-sm"),children:e.jsx(wm,{content:h,agents:d,mdComponents:Cu(d,a),remarkPlugins:[Jm,Um],rehypePlugins:[Qi]})})}function Oa(n){if(!n)return null;try{return JSON.parse(n)}catch{const d={},a=/(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|(\S+))/g;let m;
17for(;(m=a.exec(n))!==null;)d[m[1]]=m[2]||m[3]||m[4];return Object.keys(d).length>0?d:null}}function Da(n){if(!n||typeof n!="string")return[{type:"text",value:n||""}];const d=[];let a=n;const m=[];a=a.replace(/\n*<!-- TOOL_ACTIVITY\s+([\s\S]*?)\s*-->/g,($,_)=>{const B=m.length;return m.push(_.trim()),`\0TOOLACT_${B}\0`}),a=a.replace(/\n*<!-- TOOL_LOG\s+([\s\S]*?)\s+\/TOOL_LOG -->/g,($,_)=>{const B=m.length;return m.push(_.trim()),`\0TOOLACT_${B}\0`}),a=a.replace(/\n*<!-- TOOL_LOG -->\n([\s\S]*?)\n<!-- \/TOOL_LOG -->/g,($,_)=>{const B=m.length;return m.push(_.trim()),`\0TOOLACT_${B}\0`}),a=a.replace(/\n*---\nð§\s*\*\*Tool Activity\*\*\s*\([^)]*\):\n((?:>\s*.*\n?)+)/g,($,_)=>{const B=m.length,G=_.split(` 18`).map(J=>J.replace(/^>\s*/,"")).filter(J=>J.trim()).join(` 19`);return m.push(G),`\0TOOLACT_${B}\0`});const h=[];a=a.replace(/\[TOOL:(\w+)\s*(\{[^}]*\})?\]([\s\S]*?)\[\/TOOL\]/gi,($,_,B,G)=>{const J=h.length;return h.push({type:"tool",toolName:_,params:Oa(B),value:(G||"").trim()}),`\0TOOL_${J}\0`}),a=a.replace(/TOOL:\s*(\w+)\s*(\{[^}]*\})?\s*\[\/TOOL\]/gi,($,_,B)=>{const G=h.length;return h.push({type:"tool",toolName:_,params:Oa(B),value:""}),`\0TOOL_${G}\0`}),a=a.replace(/<TOOL:\s*(\w+)\s*(\{[^}]*\})?>([\s\S]*?)<\/TOOL>/gi,($,_,B,G)=>{const J=h.length;return h.push({type:"tool",toolName:_,params:Oa(B),value:(G||"").trim()}),`\0TOOL_${J}\0`}),a=a.replace(/<task>[\s\S]*?<\/task>/gi,""),a=a.replace(/<file\s+[^>]*\/>/gi,""),a=a.replace(/\[DELIVERY(?:\s[^\]]*?)?\]([\s\S]*?)\[\/DELIVERY\]/gi,"<delivery>$1</delivery>"),a=a.replace(/\[FILE(?:\s[^\]]*?)?\]([\s\S]*?)\[\/FILE\]/gi,($,_)=>{const B=$.match(/name=["']?([^"'\]]+)["']?/i);return`<file${B?` name="${B[1]}"`:""}>${_}</file>`}),a=a.replace(/\[ACTION\]([\s\S]*?)\[\/ACTION\]/gi,"<action>$1</action>"),a=a.replace(/\[\/?(?:DELIVERY|FILE|ACTION)(?:\s[^\]]*?)?\]/gi,"");const t=[];a=a.replace(/<file(?:\s([^>]*))?>(?:[\s]*)([\s\S]*?)<\/file>/gi,($,_,B)=>{const G=(_||"").match(/name=["']?([^"'\s>]+)["']?/i),J=t.length;return t.push({name:(G==null?void 0:G[1])||"file",content:B.trim()}),`\0FILE_${J}\0`});const j=[];a=a.replace(/<action(?:\s[^>]*)?>(?:[\s]*)([\s\S]*?)<\/action>/gi,($,_)=>{const B=j.length;return j.push(_.trim()),`\0ACTION_${B}\0`});const N=[];a=a.replace(/<artifact(?:\s([^>]*))?>(?:[\s]*)([\s\S]*?)<\/artifact>/gi,($,_,B)=>{const G=(_||"").match(/type=["']?([^"'\s>]+)["']?/i),J=(_||"").match(/title=["']([^"']+)["']|title=([^\s>]+)/i),$e=(_||"").match(/lang=["']?([^"'\s>]+)["']?/i),Lt=N.length;return N.push({type:(G==null?void 0:G[1])||"html",title:(J==null?void 0:J[1])||(J==null?void 0:J[2])||"Artifact",lang:($e==null?void 0:$e[1])||"",code:B.trim()}),`\0ARTIFACT_${Lt}\0`});const v=[];a=a.replace(/<diff(?:\s[^>]*)?>(?:[\s]*)([\s\S]*?)<\/diff>/gi,($,_)=>{const B=v.length;return v.push(_.trim()),`\0DIFF_${B}\0`});const b=/<(report|delivery)(?:\s[^>]*)?>(?:[\s]*)([\s\S]*?)(<\/\1>)/gi;let k=0,R;for(;(R=b.exec(a))!==null;){if(R.index>k){const _=a.slice(k,R.index).trim();_&&Fa(_,h,m,d,t,j,N,v)}const $=R[2].trim();$&&d.push({type:R[1].toLowerCase(),value:$}),k=R.index+R[0].length}const E=a.slice(k),w=/<(report|delivery)(?:\s[^>]*)?>(?:[\s]*)([\s\S]*)$/gi.exec(E);if(w){const $=E.slice(0,w.index).trim();$&&Fa($,h,m,d,t,j,N,v);const _=w[2].trim();_&&d.push({type:w[1].toLowerCase(),value:_})}else E.trim()&&Fa(E.trim(),h,m,d,t,j,N,v);return d.length>0?d:[{type:"text",value:n}]}function Fa(n,d,a,m,h=[],t=[],j=[],N=[]){const v=/\x00(TOOL|TOOLACT|FILE|ACTION|ARTIFACT|DIFF)_(\d+)\x00/g;let b=0,k;for(;(k=v.exec(n))!==null;){if(k.index>b){const E=n.slice(b,k.index).trim();E&&m.push({type:"text",value:E})}const R=parseInt(k[2]);if(k[1]==="TOOL"){const E=d[R];E&&m.push(E)}else if(k[1]==="FILE"){const E=h[R];E&&m.push({type:"file",name:E.name,value:E.content})}else if(k[1]==="ACTION"){const E=t[R];E&&m.push({type:"action",value:E})}else if(k[1]==="ARTIFACT"){const E=j[R];E&&m.push({type:"artifact",artifactType:E.type,title:E.title,lang:E.lang,value:E.code})}else if(k[1]==="DIFF"){const E=N[R];E&&m.push({type:"diff",value:E})}else{const E=a[R];if(E)try{JSON.parse(E),m.push({type:"tool_activity",value:E})}catch{}}b=k.index+k[0].length}if(b<n.length){const R=n.slice(b).trim();R&&m.push({type:"text",value:R})}}function Eu({content:n,taskId:d,authorName:a}){const{createDelivery:m}=q(),[h,t]=f.useState(!1),[j,N]=f.useState(!1),[v,b]=f.useState(!1),k=async _=>{if(_==null||_.stopPropagation(),!(h||j||!d)){t(!0);try{await m(d,{content:n,fileName:`delivery-${Date.now()}.md`,authorName:a||"Agent"}),N(!0)}catch(B){console.error(B)}finally{t(!1)}}},R=n.split(` 20`).filter(_=>_.trim())[0]||"Deliverable",E=R.length>50?R.slice(0,50)+"â¦":R,O=`${a||"Agent"} · Document · MD`,w=n.length>200?n.slice(0,200)+"â¦":n,$=!!d;return e.jsx("div",{className:"flex text-left rounded-lg overflow-hidden border border-neutral-200/50 transition duration-300 w-full hover:bg-white/50 px-4 hover:border-neutral-300 cursor-pointer group/artifact-block my-2",onClick:()=>b(!v),role:"button",tabIndex:0,onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),b(!v))},children:e.jsxs("div",{className:"artifact-block-cell group/artifact-block flex flex-1 items-start justify-between w-full",children:[e.jsxs("div",{className:"flex flex-1 gap-2 min-w-0",children:[e.jsx("div",{className:"flex items-end w-[68px] relative shrink-0",children:e.jsx("div",{className:"absolute right-2 flex flex-1 overflow-hidden w-[52px] h-[71px] rounded-t-lg border border-neutral-200 select-none scale-100 group-hover/artifact-block:scale-[1.035] -rotate-[0.1rad] group-hover/artifact-block:-rotate-[0.065rad] duration-300 ease-out transition-transform backface-hidden will-change-transform translate-y-[19%] bg-gradient-to-b from-white to-w
20hite/0 pt-4 items-start justify-center h-full",children:e.jsx(mt,{className:"w-5 h-5 text-neutral-500"})})}),e.jsxs("div",{className:"flex flex-col gap-1 py-4 min-w-0 flex-1",children:[e.jsx("div",{className:"leading-tight text-sm line-clamp-1 text-neutral-900",children:E}),e.jsx("div",{className:"text-xs line-clamp-1 text-neutral-500",children:O}),v&&e.jsx("div",{className:"mt-2 text-sm text-neutral-900 whitespace-pre-wrap pt-2 border-t border-neutral-200/50",children:w})]})]}),e.jsx("div",{className:"flex min-w-0 items-center justify-center gap-2 shrink-0",children:$&&!j?e.jsx(T,{variant:"outline",onClick:k,disabled:h,className:"border-neutral-200/40 hover:border-neutral-200 bg-white text-neutral-900",children:h?"Savingâ¦":"Save"}):$&&j?e.jsxs("span",{className:"h-9 px-4 py-2 rounded-lg text-sm font-medium flex items-center gap-1.5 text-neutral-600",children:[e.jsx(Hi,{className:"w-4 h-4"})," Saved"]}):null})]})})}function Tu({name:n,content:d,agents:a,humans:m,onOpenInPane:h,onOpenArtifact:t,path:j=null}){var _;const[N,v]=f.useState(!1),b=((_=n==null?void 0:n.split(".").pop())==null?void 0:_.toLowerCase())||"",k=["tsx","jsx","ts","js","py","rb","go","rs","java","css","html","json","yaml","yml","sh"].includes(b),R=(d==null?void 0:d.split(` 21`).length)||0,E=(d||"").trimStart(),O=["html","htm"].includes(b)||E.startsWith("<!DOCTYPE")||E.startsWith("<html")||["jsx","tsx"].includes(b),w=k?"ð»":["md","txt"].includes(b)?"ð":["pdf"].includes(b)?"ð":"ð",$=h||(t?()=>t():null);if($&&O){const B=["jsx","tsx"].includes(b)?"react":"html",G={type:B,title:n||"Preview",code:d,lang:B==="react"?"jsx":"html"};return e.jsx(Xi,{artifact:G,onClick:()=>$({name:n,content:d,ext:b,artifact:G}),className:"my-2 w-full max-w-md"})}if($){const B=k?Ki:mt;return e.jsx("div",{onClick:()=>$({name:n,content:d,ext:b}),className:"flex text-left rounded-lg overflow-hidden border border-neutral-300/40 transition duration-300 w-full hover:bg-white/50 px-4 hover:border-neutral-300 cursor-pointer group/artifact-block my-2 w-full max-w-md",role:"button",tabIndex:0,"aria-label":`Open file: ${n}`,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),$({name:n,content:d,ext:b}))},children:e.jsx("div",{className:"flex flex-1 items-start justify-between w-full",children:e.jsxs("div",{className:"flex flex-1 gap-2 min-w-0",children:[e.jsx("div",{className:"flex items-end w-[68px] relative shrink-0",children:e.jsx("div",{className:"absolute right-2 flex flex-1 overflow-hidden w-[52px] h-[71px] rounded-t-lg border border-neutral-300 select-none scale-100 group-hover/artifact-block:scale-[1.035] -rotate-[0.1rad] group-hover/artifact-block:-rotate-[0.065rad] duration-300 ease-out transition-transform backface-hidden will-change-transform translate-y-[19%] bg-gradient-to-b from-white to-white/0 pt-4 items-start justify-center h-full",children:e.jsx(B,{className:"w-5 h-5 text-neutral-400"})})}),e.jsxs("div",{className:"flex flex-col gap-1 py-4 min-w-0 flex-1",children:[e.jsx("div",{className:"leading-tight text-sm line-clamp-1 text-neutral-900",children:n||"File"}),e.jsxs("div",{className:"text-xs line-clamp-1 text-neutral-400",children:[k?"Code":"Document",e.jsx("span",{className:"opacity-50",children:" · "}),(b||"file").toUpperCase()]}),j&&e.jsx("div",{className:"text-meta line-clamp-1 text-neutral-400",children:j})]})]})})})}return e.jsxs("div",{className:"my-2 rounded-lg overflow-hidden border border-stone-200 bg-stone-50/40",children:[e.jsxs(T,{variant:"ghost",onClick:()=>v(!N),className:"w-full flex items-center gap-2 px-3 py-2 h-auto text-left hover:bg-stone-100/50 rounded-none justify-start",children:[e.jsx(Id,{className:V("w-4 h-4 text-stone-600 flex-shrink-0 transition-transform duration-200",N&&"rotate-90")}),e.jsx("span",{className:"text-sm flex-shrink-0",children:w}),e.jsx("span",{className:"text-xs font-medium text-stone-600 truncate",children:n||"File"}),!N&&e.jsxs("span",{className:"text-xs text-stone-600 ml-auto",children:[R," lines"]})]}),N&&e.jsx("div",{className:"px-4 pb-3 pt-1 border-t border-stone-200 text-sm text-neutral-700 max-h-80 overflow-y-auto",children:e.jsx(Es,{content:d,agents:a,humans:m})})]})}function Lu({content:n}){return Qc(n)?e.jsx(jm,{content:n,className:"my-2"}):e.jsxs("div",{className:"my-1.5 flex items-start gap-2 px-3 py-1.5 rounded-md bg-amber-50 border border-amber-200",children:[e.jsx(tl,{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"text-xs text-amber-700",children:n})]})}function zi({active:n=!1,className:d=""}){return e.jsx("div",{className:V("w-[1px] h-full duration-150",n?"bg-stone-200":"",d)})}const Ba=["bg-stone-50 text-neutral-900 border border-neutral-200","bg-stone-100 text-stone-800 border border-stone-200","bg-green-50/90 text-green-800 border border-green-200/80","bg-amber-50/90 text-amber-600 border border-amber-200/80","bg-green-50/90 text-red-600 border border-green-200/80","bg-stone-100 text-neutral-900 border border-neutral-100","bg-stone-50 text-stone-700 border border-neutral-200","bg-stone-100 text-neutral-800 border border-neutral-200"];
21function $n(n){if(!n)return Ba[0];let d=0;for(let a=0;a<n.length;a++)d=(d<<5)-d+n.charCodeAt(a)|0;return Ba[Math.abs(d)%Ba.length]}function rl({icon:n,label:d,summary:a,detail:m,status:h="done",children:t,defaultOpen:j=!1,fileName:N,assigneeName:v,assigneeTitle:b}){const[k,R]=f.useState(j),E=()=>h==="done"?e.jsx("div",{className:"text-neutral-600",style:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Tn,{className:"w-4 h-4"})}):h==="running"?e.jsx("div",{className:"text-neutral-600",style:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Zc,{className:"w-4 h-4 animate-spin",style:{animationDuration:"3s"}})}):h==="failed"?e.jsx("div",{className:"text-green-500",style:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ts,{className:"w-4 h-4"})}):e.jsx("div",{className:"text-neutral-600",style:{width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center"},children:n==="file"?e.jsx(mt,{className:"w-4 h-4"}):n==="code"?e.jsx(Wi,{className:"w-4 h-4"}):n==="search"?e.jsx(Ha,{className:"w-4 h-4"}):n==="globe"?e.jsx(Vi,{className:"w-4 h-4"}):e.jsx(Ts,{className:"w-4 h-4"})});return e.jsxs("div",{className:"flex flex-col shrink-0",children:[e.jsx("div",{className:"flex flex-row h-2",children:e.jsx("div",{className:"w-5 flex justify-center",children:e.jsx(zi,{active:!0})})}),e.jsx("div",{className:"transition-colors rounded-lg duration-150",children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx("div",{className:"w-5 flex justify-center shrink-0",children:e.jsxs("div",{className:"flex flex-col items-center pt-1",children:[e.jsx(E,{}),t&&e.jsx("div",{className:"w-[1px] flex-1 mt-1 duration-150 bg-stone-200"})]})}),e.jsx("div",{className:"flex-1 min-w-0",children:m||t?e.jsxs(e.Fragment,{children:[e.jsxs(T,{variant:"ghost",onClick:()=>R(!k),className:"group/row flex flex-row items-center rounded-lg px-2.5 w-full justify-between text-neutral-600 cursor-pointer hover:text-neutral-900 h-auto",children:[e.jsx("div",{className:"flex flex-row items-center gap-2 min-w-0 flex-1",children:e.jsx("div",{className:"text-sm text-neutral-600 text-left truncate w-0 flex-grow",children:e.jsxs("span",{className:"truncate inline",children:[v&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:V("inline px-1 py-0.5 rounded text-xs font-medium shrink-0",$n(v)),children:["@",v.replace(/^@/,"")]}),b&&e.jsx("span",{className:"inline px-1 py-0.5 rounded text-xxs font-medium shrink-0 bg-stone-100 text-neutral-600 ml-1",children:b})]}),v&&" ",e.jsx("span",{children:d})]})})}),e.jsx($s,{className:V("w-3 h-3 text-neutral-600 transition-transform duration-200 shrink-0",!k&&"-rotate-90")})]}),N&&e.jsx("div",{className:"mx-2.5 mt-1",children:e.jsx("span",{className:"inline-flex items-center align-middle leading-none flex-shrink-0 bg-stone-200/40 text-neutral-600 h-5 px-1.5 rounded-md text-[0.625rem]",children:N})}),k&&m&&e.jsx("div",{className:"pt-0.5",children:e.jsx("div",{className:"px-2.5 py-1.5 text-neutral-500 text-sm leading-[1.9] bg-stone-100 rounded-md border border-neutral-200",children:e.jsx("div",{className:"max-h-[280px] overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words",children:m})})}),k&&t]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pl-2.5 pt-0.5 text-neutral-600 text-sm",children:e.jsxs("span",{className:"inline",children:[v&&e.jsxs("span",{className:V("inline px-1 py-0.5 rounded text-xs font-medium",$n(v)),children:["@",v.replace(/^@/,"")]}),v&&" ",e.jsx("span",{children:a||d})]})}),N&&e.jsx("div",{className:"mx-2.5 mt-1",children:e.jsx("span",{className:"inline-flex items-center align-middle leading-none flex-shrink-0 bg-stone-200/40 text-neutral-600 h-5 px-1.5 rounded-md text-[0.625rem]",children:N})})]})})]})}),t&&e.jsx("div",{className:"flex flex-row h-2",children:e.jsx("div",{className:"w-5 flex justify-center",children:e.jsx(zi,{})})})]})}function $u({title:n,steps:d=[],children:a,agents:m,humans:h,defaultOpen:t=!1}){const[j,N]=f.useState(t);return e.jsxs("div",{className:"min-w-0 pl-2 py-1.5",children:[e.jsx(T,{variant:"ghost",onClick:()=>N(!j),className:"group/status flex items-center gap-2 py-1 text-sm cursor-pointer w-full text-left text-neutral-500 hover:text-neutral-900 h-auto px-0 justify-start",children:e.jsxs("div",{className:"inline-flex items-center gap-1 min-w-0",style:{opacity:1},children:[e.jsx("span",{className:"truncate text-sm",children:n}),e.jsx("span",{className:V("inline-flex transition-transform duration-200 shrink-0",!j&&"-rotate-90"),children:e.jsx($s,{className:"w-3 h-3"})})]})}),e.jsx("div",{className:V("grid transition-[grid-template-rows] duration-300 ease-out",j?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"overflow-hidden min-w-0",children:e.jsxs("div",{className:"flex flex-col leading-normal",children:[d.map((v,b)=>e.jsx(rl,{label:v.label,summary:v.summary,status:v.status||"done",icon:v.icon,fileName:v.fileName,detail
21:v.detail,assigneeName:v.assigneeName},b)),a]})})})]})}function _u({data:n}){const[d,a]=f.useState(!0),m=(()=>{if(!n)return[];try{const N=JSON.parse(n);if(Array.isArray(N))return N}catch{return n.split(` 22`).filter(N=>N.trim()).map(N=>{const v=N.match(/^(â |â)\s*\*\*(\w+)\*\*\(([^)]*)\)\s*â\s*(.*)/);return v?{tool:v[2],params:{query:v[3]},success:v[1]==="â ",summary:v[4]}:{tool:"unknown",params:{},success:!0,summary:N}})}return[]})();if(m.length===0)return null;const h={};m.forEach(N=>{const v=N.tool||"unknown";h[v]=(h[v]||0)+1});const j=Object.entries(h).map(([N,v])=>{const b=Va(N);return v>1?`${b.label} Ã${v}`:b.label}).join(", ");return e.jsxs("div",{className:"flex flex-col gap-3 min-w-0 text-quiet relative my-2",children:[e.jsx("div",{className:"flex items-center gap-2 relative group/tool-wrapper",children:e.jsxs(T,{variant:"ghost",onClick:()=>a(!d),className:"min-w-0 flex items-center gap-2 w-fit max-w-full group/tool-button cursor-pointer text-left hover:text-foreground h-auto p-0",children:[e.jsxs("div",{className:"relative rounded-full size-5 flex items-center justify-center shrink-0 p-1",children:[e.jsx("div",{className:"absolute inset-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full size-6"}),e.jsx(Ts,{className:"w-5 h-5 shrink-0 relative text-stone-700 p-0.5"})]}),e.jsxs("div",{className:"min-w-0 font-sans text-base text-quiet text-sm select-none truncate group-hover/tool-wrapper:text-foreground",children:[j," â ",m.length," call",m.length!==1?"s":""]}),e.jsx(Xm,{className:V("w-3.5 h-3.5 shrink-0 transition-transform",!d&&"rotate-180")})]})}),d&&e.jsx("div",{className:"pl-7",children:e.jsx("div",{className:"grid gap-2 grid-cols-1",children:m.map((N,v)=>{var O,w;const{label:b,icon:k}=Va(N.tool),R=((O=N.params)==null?void 0:O.query)||((w=N.params)==null?void 0:w.url)||"",E=v===m.length-1;return e.jsxs("div",{className:"relative min-w-0",children:[!E&&e.jsx("span",{className:"absolute top-0 w-px rounded-bl-lg border-l border-b border-subtle",style:{bottom:"-24px",left:"-19px"},"aria-hidden":"true"}),e.jsx("div",{className:"absolute rounded-bl-lg border-l border-b border-subtle",style:{top:"-5px",left:"-19px",width:"30px",height:"16px"},"aria-hidden":"true"}),e.jsx("div",{className:"flex flex-col gap-3 min-w-0 text-quiet relative",children:e.jsx("div",{className:"flex items-center gap-2 relative group/tool-wrapper",children:e.jsxs("div",{className:"min-w-0 flex items-center gap-2 w-fit max-w-full cursor-default",children:[e.jsxs("div",{className:"relative rounded-full size-5 flex items-center justify-center shrink-0 p-1",children:[e.jsx("div",{className:"absolute inset-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full size-6"}),k?e.jsx(k,{className:"w-5 h-5 shrink-0 relative text-stone-700 p-0.5"}):e.jsx(Ts,{className:"w-5 h-5 shrink-0 relative text-stone-700 p-0.5"})]}),e.jsxs("div",{className:"min-w-0 font-sans text-base text-quiet text-sm select-none truncate",children:[b,R?` â ${R.slice(0,50)}`:""]})]})})})]},v)})})})]})}const Mu={weather:"ð¤",github:"ð",git:"ð",email:"ð§",calendar:"ð ",slack:"ð¬",discord:"ð®",search:"ð",web:"ð",browser:"ð",code:"ð»",database:"ð",file:"ð",ai:"ð¤",translate:"ð",pdf:"ð",note:"ð",todo:"â ",crypto:"ð°",analytics:"ð",security:"ð",api:"ð",automation:"â¡"};function Ou(n){const d=(n||"").toLowerCase();for(const[a,m]of Object.entries(Mu))if(d.includes(a))return m;return null}function Du({data:n}){var N;const[d,a]=f.useState(null),[m,h]=f.useState(new Set),t="https://app.trooper.so",j=async v=>{a(v.slug);try{(await fetch(`${t}/api/skills/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:v.slug,name:v.name,description:v.description,version:v.version})})).ok&&h(k=>new Set([...k,v.slug]))}catch(b){console.error("Failed to install skill:",b)}a(null)};return(N=n==null?void 0:n.suggestions)!=null&&N.length?e.jsxs("div",{className:"my-2 rounded-xl border border-neutral-200 bg-stone-100/50 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-neutral-200/50 flex items-center gap-2",children:[e.jsx(Ym,{className:"w-3.5 h-3.5 text-neutral-600"}),e.jsx("span",{className:"text-xs font-medium text-neutral-600",children:n.reason||"Suggested skills"})]}),e.jsx("div",{className:"divide-y divide-neutral-200",children:n.suggestions.map(v=>{const b=v.installed||m.has(v.slug),k=d===v.slug,R=Ou(v.name);return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 hover:bg-white/60 transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center bg-stone-100 flex-shrink-0",children:R?e.jsx("span",{className:"text-sm leading-none",children:R}
22):e.jsx(Ts,{className:"w-3.5 h-3.5 text-neutral-600",strokeWidth:1.5})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-dense font-medium text-neutral-900 truncate",children:v.name}),e.jsx("div",{className:"text-meta text-neutral-600 truncate",children:v.description||"No description"}),v.whyRecommended?e.jsx("div",{className:"mt-0.5 text-meta text-neutral-500 line-clamp-2",children:v.whyRecommended}):null]}),e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>!b&&!k&&j(v),disabled:b||k,className:V("px-2.5 py-1 text-meta font-medium flex items-center gap-1 flex-shrink-0 h-auto",b?"bg-stone-100 text-neutral-600 border-neutral-200 cursor-default":"bg-white text-neutral-900 border-neutral-200 hover:bg-stone-100 cursor-pointer"),children:[k?e.jsx(Xa,{className:"w-3 h-3 animate-spin"}):b?e.jsx(Hi,{className:"w-3 h-3 text-green-700"}):e.jsx(Ka,{className:"w-3 h-3"}),b?"Installed":k?"Installing":"Install"]})]},v.slug)})}),e.jsx("div",{className:"px-3 py-2 border-t border-neutral-200/50 bg-stone-100/30",children:e.jsx(T,{variant:"link",onClick:()=>{var v,b;return(b=(v=q.getState()).setShowSkillStore)==null?void 0:b.call(v,!0)},className:"text-meta text-neutral-600 hover:text-neutral-900 font-medium h-auto p-0",children:"See all skills â"})})]}):null}function Fu({fileName:n,subtitle:d,icon:a,onDownload:m,onPreview:h,onGoogleDrive:t,children:j}){var k;const N=((k=n==null?void 0:n.split(".").pop())==null?void 0:k.toLowerCase())||"",b=["tsx","jsx","ts","js","py","rb","go","rs","java","css","html","json","yaml","yml","sh"].includes(N)?Ki:mt;return e.jsx("div",{className:"flex text-left rounded-lg overflow-hidden border border-neutral-300/40 transition duration-300 mb-4 w-full hover:bg-white/50 px-4 hover:border-neutral-300 cursor-pointer group/artifact-block",onClick:h,role:"button",tabIndex:0,children:e.jsxs("div",{className:"flex flex-1 items-start justify-between w-full",children:[e.jsxs("div",{className:"flex flex-1 gap-2 min-w-0",children:[e.jsx("div",{className:"flex items-end w-[68px] relative shrink-0",children:e.jsx("div",{className:"absolute right-2 flex flex-1 overflow-hidden w-[52px] h-[71px] rounded-t-lg border border-neutral-300 select-none scale-100 group-hover/artifact-block:scale-[1.035] -rotate-[0.1rad] group-hover/artifact-block:-rotate-[0.065rad] duration-300 ease-out transition-transform backface-hidden will-change-transform translate-y-[19%] bg-gradient-to-b from-white to-white/0 pt-4 items-start justify-center h-full",children:e.jsx(b,{className:"w-5 h-5 text-neutral-400"})})}),e.jsxs("div",{className:"flex flex-col gap-1 py-4 min-w-0 flex-1",children:[e.jsx("div",{className:"leading-tight text-sm line-clamp-1 text-neutral-900",children:n}),e.jsx("div",{className:"text-xs line-clamp-1 text-neutral-400",children:d})]})]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-center gap-2 shrink-0 py-3 m-auto h-full",children:[t&&e.jsx(T,{variant:"outline",size:"icon",onClick:R=>{R.stopPropagation(),t()},className:"h-8 w-8 border-neutral-300/60 hover:border-neutral-300 bg-white",children:e.jsx(Vi,{className:"w-3.5 h-3.5 text-neutral-400"})}),e.jsx(T,{variant:"secondary",size:"sm",onClick:R=>{R.stopPropagation(),m==null||m()},className:"h-8 px-3.5 text-xs text-neutral-900 bg-stone-200 hover:bg-stone-300",children:"Download"})]})]})})}const Bu=Ls.memo(function({agent:d=null,avatarSrc:a,name:m,subtitle:h,showManagerBadge:t,showSpecialistBadge:j,delegatedTo:N=null}){return e.jsxs("div",{className:"task-live-agent-header mb-2.5 flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"relative flex shrink-0",children:e.jsx(Ln,{src:a,name:m,size:"w-7 h-7 text-[9px]",agent:d})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"min-w-0 max-w-full text-[13px] font-semibold text-neutral-900",children:m}),h?e.jsx("span",{className:"shrink-0 text-[11px] text-neutral-500",children:h}):null,t?e.jsx("span",{className:"text-micro px-1.5 py-0.5 bg-amber-50 text-amber-600 rounded-md font-semibold border border-amber-100",children:"Manager"}):j?e.jsx("span",{className:"text-micro px-1.5 py-0.5 bg-stone-50 text-neutral-500 border border-neutral-200 rounded-md font-medium",children:"Specialist"}):null,N?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"shrink-0 text-[11px] text-neutral-500",children:"â"}),e.jsx("span",{className:"max-w-[40%] truncate text-[13px] font-semibold text-neutral-900 sm:max-w-none",title:N,children:N})]}):null]})]})},(n,d)=>n.avatarSrc===d.avatarSrc&&n.name===d.name&&(n.subtitle||"")===(d.subtitle||"")&&n.showManagerBadge===d.showManagerBadge&&n.showSpecialistBadge===d.showSpecialistBadge&&(n.delegatedTo||"")===(d.delegatedTo||""));function zu({step:n,stepIdx:d,totalSteps:a,onRetry:m}){var N;const h=(N=n.assigneeName)==null?void 0:N.replace(/^@/,""),t=n.status==="failed",j=n.failureReason;return e.jsxs("div",{className:"my-2",children:[e.jsxs("div",{className:"flex items-center gap-2 py-1 text-meta text-neutral-400",children:[e.jsx("div",{className:`flex-1 h-px ${t?"bg-red-200":"bg-stone-200"}`}),e.jsxs("span",{className:"px-2 shrink-0 flex items-center gap-1.5",children:[e.jsxs("span",{children:["Step ",d+1,"/",a,":"]}),e.jsx("span",{className:`truncate max-w-[200px] ${t?"text-red-500":"text-neutral-500"}`,children:n.title}),h&&e.jsxs("span",{className:V("px-1 py-0.5 rounded text-xxs font-medium",$n(h)),children:["@",h]})]}),e.jsx("div",{className:`flex-1 h-px ${t?"bg-red-200":"bg-stone-200"}`})]}),t&&j&&e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-1 mb-1",children:[e.jsx("span",{className:"text-meta text-red-400 max-w-[400px] text-center truncate",title:j,children:j.length>80?j.substring(0,80)+"â¦":j}),m&&e.jsx(T,{variant:"ghost",size:"sm",onClick:m,className:"text-meta text-neutral-500 hover:text-neutral-900 font-medium underline decoration-dotted",children:"Retry"})]})]})}function me(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`wf-${Date.now()}-${Math.random().toString(36).slice(2)}`}function es(n,d=900){const a=String(n||"").replace(/\s+/g," ").trim();return a?a.length>d?`${a.slice(0,d-1).trimEnd()}â¦`:a:""}function Za(n,d=[]){const a=Array.isArray(n==null?void 0:n.comments)?n.comments:[],m=d.find(b=>b.id===(n==null?void 0:n.assigneeId)||b.name===(n==null?void 0:n.assigneeName)),h=[...Array.isArray(n==null?void 0:n.subtasks)?n.subtasks:[],...Array.isArray(n==null?void 0:n.checklist)?n.checklist:[],...Array.isArray(n==null?void 0:n.steps)?n.steps:[]],t=h.map((b,k)=>es((b==null?void 0:b.title)||(b==null?void 0:b.name)||(b==null?void 0:b.description)||(b==null?void 0:b.content)||`Step ${k+1}
22`,220)).filter(Boolean).slice(0,12),j=a.map(b=>es((b==null?void 0:b.content)||(b==null?void 0:b.text)||(b==null?void 0:b.message)||(b==null?void 0:b.outputSummary)||(b==null?void 0:b.summary)||"",520)).filter(Boolean).slice(-8),N=[n==null?void 0:n.failureReason,n==null?void 0:n.blockedReason,n==null?void 0:n.startWorkError,...h.map(b=>(b==null?void 0:b.failureReason)||(b==null?void 0:b.skipReason)).filter(Boolean),...a.map(b=>(b==null?void 0:b.error)||(b==null?void 0:b.failureReason)).filter(Boolean)].map(b=>es(b,320)).filter(Boolean).slice(0,6),v=[n==null?void 0:n.outputSummary,n==null?void 0:n.output,...Array.isArray(n==null?void 0:n.deliveries)?n.deliveries.map(b=>(b==null?void 0:b.summary)||(b==null?void 0:b.fileName)):[]].map(b=>es(b,360)).filter(Boolean).slice(0,6);return{assigneeName:(m==null?void 0:m.name)||(n==null?void 0:n.assigneeName)||"",title:es((n==null?void 0:n.title)||"Untitled task",160),description:es(n==null?void 0:n.description,900),status:gt(n==null?void 0:n.status),steps:t,commentSummaries:j,failureNotes:N,outputNotes:v}}function Wu(n,d=[]){const a=Za(n,d),m=[`Repeat this task as a reliable routine: ${a.title}`,a.description?`Original goal: ${a.description}`:"",a.assigneeName?`Preferred agent: ${a.assigneeName}`:"","","Runbook:",...a.steps.length?a.steps.map((h,t)=>`${t+1}. ${h}`):["1. Re-read the task goal and confirm the needed inputs.","2. Execute the same research, analysis, and delivery path that worked in the completed task.","3. Produce the final answer or artifact with clear evidence and next actions."],"",a.outputNotes.length?`What worked / expected output: 23${a.outputNotes.map(h=>`- ${h}`).join(` 24`)}`:"",a.failureNotes.length?`Avoid / recover from: 25${a.failureNotes.map(h=>`- ${h}`).join(` 26`)}`:"",a.commentSummaries.length?`Useful context from the run: 27${a.commentSummaries.map(h=>`- ${h}`).join(` 28`)}`:"","","Before finishing, verify the result, mention any missing inputs, and attach or link generated deliverables."].filter(Boolean);return{type:"routine",name:`Routine: ${a.title}`,cronExpression:"0 9 * * 1",targetAgent:a.assigneeName,message:m.join(` 29`)}}function er(n){const d=Array.isArray(n==null?void 0:n.nodes)?n.nodes:[],a=Array.isArray(n==null?void 0:n.edges)?n.edges:[];return{nodes:d.map((m,h)=>{var t,j,N,v,b,k;return{id:m.id||me(),type:m.type==="condition"?"check":m.type||"ai",label:m.label||`Step ${h+1}`,subtitle:m.subtitle||((t=m.config)==null?void 0:t.summary)||"",tags:Array.isArray(m.tags)?m.tags:[],prompt:m.prompt||((j=m.config)==null?void 0:j.prompt)||((N=m.config)==null?void 0:N.content)||"",promptRefs:Array.isArray(m.promptRefs)?m.promptRefs:[],config:m.config||{},values:m.values||((v=m.config)==null?void 0:v.values)||{},inputs:Array.isArray(m.inputs)?m.inputs:Array.isArray((b=m.config)==null?void 0:b.inputs)?m.config.inputs:[],outputs:Array.isArray(m.outputs)?m.outputs:Array.isArray((k=m.config)==null?void 0:k.outputs)?m.config.outputs:[],position:m.position||{x:120+h*180,y:120+h%2*140}}}),edges:a.map(m=>({id:m.id||me(),source:m.source||m.from,target:m.target||m.to,condition:m.condition||null})).filter(m=>m.source&&m.target)}}function Ku(n,d){return{...n,graph:d,nodes:((d==null?void 0:d.nodes)||[]).map(a=>{var m,h;return{id:a.id||me(),type:a.type==="check"?"condition":a.type,label:a.label||"Workflow node",subtitle:a.subtitle||"",tags:Array.isArray(a.tags)?a.tags:[],prompt:a.prompt||"",promptRefs:Array.isArray(a.promptRefs)?a.promptRefs:[],values:a.values||{},inputs:Array.isArray(a.inputs)?a.inputs:[],outputs:Array.isArray(a.outputs)?a.outputs:[],config:{...a.config||{},...a.prompt?{prompt:a.prompt}:{},...a.values?{values:a.values}:{},inputs:Array.isArray(a.inputs)?a.inputs:((m=a.config)==null?void 0:m.inputs)||[],outputs:Array.isArray(a.outputs)?a.outputs:((h=a.config)==null?void 0:h.outputs)||[]},position:a.position||{x:0,y:0}}}),edges:((d==null?void 0:d.edges)||[]).map(a=>({id:a.id||me(),from:a.source||a.from,to:a.target||a.to,condition:a.condition||null})).filter(a=>a.from&&a.to),updatedAt:Date.now()}}function Vu(n,d){const a=(n==null?void 0:n.workflow)||{},m=d&&typeof d=="object"?d:{}
29,h=Array.isArray(m.nodes)&&m.nodes.length?m.nodes:Array.isArray(a.nodes)?a.nodes:[],t=Array.isArray(m.edges)&&m.edges.length?m.edges:Array.isArray(a.edges)?a.edges:[],j={...a,...m,id:a.id||m.id||me(),status:"draft",tags:Array.isArray(m.tags)&&m.tags.length?m.tags.map(N=>String(N).trim()).filter(Boolean):Array.isArray(a.tags)?a.tags:[],runbook:String(m.runbook||a.runbook||""),nodes:h,edges:t,sourceTaskId:a.sourceTaskId||m.sourceTaskId||null,sourceChat:!0,createdAt:a.createdAt||Date.now(),updatedAt:Date.now(),runCount:a.runCount||0,lastRunAt:a.lastRunAt||null};return{type:"workflow",workflow:{...j,graph:er(j)}}}function Hu(n,d=[]){const a=Za(n,d),m=me(),h=me(),t=me(),j=me(),N=me(),v=me(),b=[n==null?void 0:n.status,n!=null&&n.priority?`priority:${n.priority}`:"",a.assigneeName?`agent:${a.assigneeName}`:""].filter(Boolean).slice(0,5),k=[a.description?`Goal: ${a.description}`:`Goal: ${a.title}`,a.steps.length?`Steps: 30${a.steps.map((E,O)=>`${O+1}. ${E}`).join(` 31`)}`:"",a.outputNotes.length?`What worked: 32${a.outputNotes.map(E=>`- ${E}`).join(` 33`)}`:"",a.failureNotes.length?`What did not work / recovery notes: 34${a.failureNotes.map(E=>`- ${E}`).join(` 35`)}`:"",a.commentSummaries.length?`Run context: 36${a.commentSummaries.map(E=>`- ${E}`).join(` 37`)}`:""].filter(Boolean).join(` 38 39`),R={id:me(),name:`Workflow: ${a.title}`,description:`Reusable OpenClaw workflow generated from task "${a.title}".`,status:"draft",tags:["task-workflow",...b],sourceTaskId:(n==null?void 0:n.id)||null,sourceChat:!0,runbook:k,nodes:[{id:m,type:"ai",label:"Collect context",subtitle:"Goal, comments, outputs, and recovery notes",tags:["context","files","memory"],prompt:"Gather the task goal, comments, attachments, completed outputs, and failure notes before planning.",config:{content:k,inputs:["task","comments","artifacts"],outputs:["context_summary"]},position:{x:80,y:120}},{id:h,type:"ai",label:"Plan execution",subtitle:"Create steps, assumptions, and tool choices",tags:["prompt","planning"],prompt:a.steps.length?`Turn these observed steps into a reusable plan: 40${a.steps.map((E,O)=>`${O+1}. ${E}`).join(` 41`)}`:"Create a concrete plan from the task goal and available context.",config:{model:"auto",inputs:["context_summary"],outputs:["execution_plan"]},position:{x:360,y:120}},{id:t,type:"tool",label:"Use tagged tools and files",subtitle:"Plugins, skills, files, devices, or browser actions",tags:["plugins","skills","files"],prompt:"Use the tagged resources needed for this workflow. Ask only when required credentials, files, or approvals are missing.",config:{inputs:["execution_plan"],outputs:["tool_results"],values:{requiredApprovals:[]}},position:{x:640,y:120}},{id:j,type:"agent",label:a.assigneeName||"Assigned agent",subtitle:"Runs the workflow with OpenClaw",tags:["agent",a.assigneeName||"auto"],prompt:k,config:{agentName:a.assigneeName||"Auto",inputs:["execution_plan","tool_results"],outputs:["draft_result"]},position:{x:640,y:300}},{id:N,type:"condition",label:"Verify completion",subtitle:"Checks expected output and recovery notes",tags:["verification","quality"],prompt:"Verify the final result against success criteria and note any missing inputs or risks.",config:{successChecks:a.outputNotes.length?a.outputNotes:["Final answer or artifact is complete","Any missing inputs are explicit"],failureNotes:a.failureNotes,inputs:["draft_result"],outputs:["verified_result"]},position:{x:920,y:210}},{id:v,type:"output",label:"Deliver result",subtitle:"Final answer, files, or next actions",tags:["output","handoff"],prompt:"Return the final answer with relevant files, links, evidence, and next actions.",config:{expected:a.outputNotes.join(` 42`)||"Final response and deliverables",inputs:["verified_result"]},position:{x:1180,y:210}}],edges:[{id:me(),from:m,to:h},{id:me(),from:h,to:t},{id:me(),from:t,to:j},{id:me(),from:j,to:N},{id:me(),from:N,to:v}],createdAt:Date.now(),updatedAt:Date.now(),runCount:0,lastRunAt:null};return{type:"workflow",workflow:{...R,graph:er(R)}}}function qu({inline:n,onClose:d,children:a}){return n?e.jsx("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden bg-background",children:a}):e.jsx(Ji,{open:!0,modal:!0,onOpenChange:(m,h)=>{var t;m||(t=h==null?void 0:h.cancel)==null||t.call(h)},children:e.jsxs(Ui,{children:[e.jsx(Yi,{className:"z-[220] bg-black/55",onClick:m=>{m.target===m.currentTarget&&d()}}),e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[220] flex min-h-0 items-stretch justify-center overscroll-contain p-0 pt-[env(safe-area-inset-top,0px)] pb-[env(safe-area-inset-bottom,0px)] sm:p-3 sm:pt-[max(0.75rem,env(safe-area-inset-top))] sm:pb-[max(0.75rem,env(safe-area-inset-bottom))]",onClick:m=>{m.target===m.currentTarget&&d()},children:a})]})})}function Uh({inline:n=!1,onInlineClose:d=null}){var no,ao,ro,oo,io,lo,co,mo,uo,po,fo,ho,xo,go,bo,vo,wo,jo,yo,No,So,Co,ko,Io,Ro,Ao,Po,Eo,To,Lo,$o,_o,Mo,Oo;const{currentOrg:a,getIdToken:m}=Ec(),h="https://app.trooper.so",{selectedTask:t,setSelectedTask:j,mergeHydratedTaskFromServer:N,agents:v,moveTask:b,assignTask:k,addComment:R,deleteTask:E,humans:O,currentUser:w,approveTask:$,tasks:_,taskStepMeta:B,stopGeneration:G,channels:J,taskFileWriteCounter:$e,projects:Lt,devices:Qe,goals:_s,liveRunsBySession:_e,taskArtifacts:Mn,messages:ss,messageQueue:ns,enqueueMessage:Ms,dequeueMessage:as,editQueuedMessage:K,updateQueuedMessage:xe,reorderQueuedMessage:ut,setQueueItemEditing:Ae,drainMessageQueue:$t,runInterruptPrompt:Ze,continueInterruptedRun:rs,discardInterruptedRunAndProceed:_t,autoAssignTask:je,voiceCapabilities:et,connected:Mt,acpPermissionPreference:os,setAcpPermissionPreference:Os,updateAcpPermissions:Ds,acpAgents:Fs,acpSessions:Ot,acpCommands:tr,fetchAcpAgents:Bs,fetchAcpSessions:zs,fetchAcpCommands:Ws,installedSkills:Pe,memories:Gu}
42=q(),Me=f.useRef({taskId:null,snapshot:null}),ye=f.useRef({taskId:null,events:[],model:null,stream:"",streamAgentId:null}),tt=f.useRef({taskId:null,label:null,rank:-1}),On=q(s=>s.planMode),Dn=q(s=>s.executeMode),Fn=q(s=>s.bridgeGatewayUrl),Bn=q(s=>s.setSelectedAgentProfile),ol=q(s=>s.selectedChatDeviceMode||"auto"),il=q(s=>s.selectedChatDeviceId||null),zn=q(s=>s.setSelectedChatDeviceSelection),[st,wt]=f.useState(""),[Ks,is]=f.useState([]),[jt,ll]=f.useState([]);f.useEffect(()=>{a!=null&&a.id&&(Bs==null||Bs({force:!0}),zs==null||zs(),Ws==null||Ws())},[a==null?void 0:a.id,Bs,Ws,zs]);const cl=f.useCallback(s=>{wt(o=>o+(o?" ":"")+s)},[]),ls=(et==null?void 0:et.stt)!==!1,ce=Zd({onTranscript:cl,disabled:!ls||!w||!Mt});f.useEffect(()=>{if(!ls)return;const s=o=>{o.ctrlKey&&!o.metaKey&&!o.shiftKey&&!o.altKey&&o.key.toLowerCase()==="s"&&(o.preventDefault(),ce.state==="idle"?ce.startRecording():ce.state==="recording"&&ce.stopAndTranscribe())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[ls,ce.state,ce.startRecording,ce.stopAndTranscribe]);const ge=f.useMemo(()=>{if(!(t!=null&&t.id))return null;const s=(Ot||[]).filter(o=>o.taskId===t.id&&(o.status==="running"||o.status==="spawning"||o.isStreaming));return s[s.length-1]||null},[Ot,t==null?void 0:t.id]),dl=f.useCallback(async s=>{const o=Tc(s);Os==null||Os(o);const c="https://app.trooper.so";if(a!=null&&a.id&&c)try{await fetch(`${c}/api/organizations/${a.id}/chat/permissions`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({permissions:o,sessionKey:(ge==null?void 0:ge.sessionKey)||null})})}catch(r){console.warn("[task chat] Failed to sync permission preference:",r)}ge!=null&&ge.sessionId&&await(Ds==null?void 0:Ds(ge.sessionId,o))},[ge==null?void 0:ge.sessionId,ge==null?void 0:ge.sessionKey,a==null?void 0:a.id,Os,Ds]),[Dt,Vs]=f.useState([]),[sr,Hs]=f.useState(!1),[Wn,qs]=f.useState(!1),[U,ue]=f.useState(null),[cs,nr]=f.useState(!1),[Ft,ar]=f.useState(!1),[Bt,rr]=f.useState(null),[Oe,yt]=f.useState(null),[Gs,ml]=f.useState(50),[nt,Kn]=f.useState(()=>!n&&typeof window<"u"?window.matchMedia("(min-width: 1024px)").matches:!1);f.useEffect(()=>{if(n){Kn(!1);return}const s=window.matchMedia("(min-width: 1024px)"),o=()=>Kn(s.matches);return Kn(s.matches),s.addEventListener("change",o),()=>s.removeEventListener("change",o)},[n]);const or=f.useRef(!1),[ul,at]=f.useState(null),[pl,ir]=f.useState(!1),[Ju,fl]=f.useState({}),[Uu,hl]=f.useState([]),[Ee,rt]=f.useState(!1),[Te,Nt]=f.useState(""),[ds,St]=f.useState(-1),[Js,ot]=f.useState(0),[lr,cr]=f.useState(!1),[Yu,Vn]=f.useState(""),[Xu,Hn]=f.useState(-1),[Qu,dr]=f.useState(0),[be,Us]=f.useState(null),[I,ve]=f.useState(null),[pe,De]=f.useState("files"),[zt,Fe]=f.useState(!1),[Be,qn]=f.useState([]),[Ct,mr]=f.useState({}),[ur,pr]=f.useState([]),xl=f.useRef(new Set),[Ys,Gn]=f.useState([]),[Jn,Ne]=f.useState(!1),Wt=f.useRef(!1),Kt=f.useRef(0),[gl,it]=f.useState(!1),[fr,hr]=f.useState(""),[Xs,Un]=f.useState(!1),[xr,Yn]=f.useState(null);f.useEffect(()=>{Yn(null)},[t==null?void 0:t.id]);const pt=gt(t==null?void 0:t.status),ft=_m({tasks:_,projects:Lt,goals:_s,taskArtifacts:Mn,liveRunsBySession:_e}),bl=f.useMemo(()=>{const s=_i(t,_e).sort().join(","),o=Mi(t).sort().join(",");return`${s}|${o}`},[t,_e]),Xn=f.useMemo(()=>{if(!(t!=null&&t.id))return[];const s=Array.isArray(t.subtasks)?t.subtasks:[];return Array.from(new Set([t.assigneeId,...s.map(o=>o.assigneeId)].filter(Boolean)))},[t==null?void 0:t.id,t==null?void 0:t.assigneeId,t==null?void 0:t.subtasks]),vl=Pm({taskId:(t==null?void 0:t.id)??null,preferredAgentIds:Xn,assigneeId:(t==null?void 0:t.assigneeId)??null}),lt=f.useMemo(()=>t!=null&&t.id?Mm(ft,t.id):null,[ft,t==null?void 0:t.id]),Qs=f.useMemo(()=>t!=null&&t.id?Om(ft,{taskId:t.id}):null,[ft,t==null?void 0:t.id]),Zs=f.useMemo(()=>t!=null&&t.id?Dm(ft,{taskId:t.id}):null,[ft,t==null?void 0:t.id]),en=f.useMemo(()=>t!=null&&t.id?Fm(ft,{taskId:t.id,maxRuns:6,maxArtifacts:8}):null,[ft,t==null?void 0:t.id]),gr=(lt==null?void 0:lt.goal)||null,br=(lt==null?void 0:lt.project)||null,Qn=(lt==null?void 0:lt.artifactCount)||0,Zn=f.useCallback(s=>{const o=_.find(c=>(c==null?void 0:c.id)===s);o&&j(o)},[_,j]),vr=async(s,o)=>
42{if(!(!(t!=null&&t.id)||!(a!=null&&a.id)))try{const c=await m(),i=await fetch(`https://app.trooper.so/api/tasks/${t.id}/memory/${s}/${o}`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json"},body:JSON.stringify({orgId:a.id})}),p=await i.json().catch(()=>({}));if(!i.ok)throw new Error(p.error||`${o} failed`);const u=(t.memorySuggestions||[]).map(l=>l.suggestionId===s?{...l,status:o==="accept"?"accepted":"rejected"}:l);j({...t,memorySuggestions:u}),hr(o==="accept"?"Memory saved":"Suggestion rejected")}catch(c){hr(c.message)}};f.useEffect(()=>{var r,i;const s=Pn(I);if(!s)return;const o=((r=I==null?void 0:I.fileRef)==null?void 0:r.content)??((i=I==null?void 0:I.artifactRef)==null?void 0:i.code);if(o!=null&&String(o).trim())return;const c=new AbortController;return(async()=>{try{const p=await kn(s,{orgId:w==null?void 0:w.orgId,signal:c.signal});if(!p.ok)return;const u=await p.text();ve(l=>Pn(l)!==s?l:l!=null&&l.fileRef?{...l,fileRef:{...l.fileRef,content:u,path:l.fileRef.path||s}}:l!=null&&l.artifactRef?{...l,artifactRef:{...l.artifactRef,code:u,path:l.artifactRef.path||s}}:l)}catch(p){p.name!=="AbortError"&&console.warn("[TaskModal] Failed to auto-fetch file content:",p.message)}})(),()=>c.abort()},[w==null?void 0:w.orgId,(no=I==null?void 0:I.artifactRef)==null?void 0:no.code,(ao=I==null?void 0:I.fileRef)==null?void 0:ao.content,I==null?void 0:I.sourcePath,(ro=I==null?void 0:I.fileRef)==null?void 0:ro.path,(oo=I==null?void 0:I.artifactRef)==null?void 0:oo.path]);const[ze,tn]=f.useState(null),[wr,ea]=f.useState(null),[wl,ms]=f.useState(!1),[jr,jl]=f.useState({top:!1,bottom:!1}),[ta,us]=f.useState(!1),[sa,ps]=f.useState(!1),[Vt,na]=f.useState(""),[yr,fs]=f.useState(!1),[ht,Nr]=f.useState(!1),[sn,aa]=f.useState(null),[Sr,hs]=f.useState(""),[ra,nn]=f.useState(!1),[Cr,an]=f.useState(""),[oa,xs]=f.useState(!1),[kr,gs]=f.useState(""),[Zu,yl]=f.useState({}),[Ir,Nl]=f.useState(null),We=f.useRef(null),ne=Km(),Sl=em({inputRootRef:We,setInput:wt}),Cl=f.useMemo(()=>{const s=We.current?Ia(We.current):st.length;return zm(st,Pe,{extraInstalledAliases:jt,connectedSlugs:ne.connectedSlugs,caretOffset:s})},[st,Pe,jt,ne.connectedSlugs]),Rr=f.useRef(null),Ar=f.useRef(null),Pr=f.useRef({}),bs=f.useRef(null),vs=f.useRef(null),kt=f.useRef(0),It=f.useCallback(()=>{const s=bs.current;if(!s)return{nearBottom:!0};const o=Math.max(0,s.scrollHeight-s.scrollTop-s.clientHeight),c={top:s.scrollTop>12,bottom:o>12};return jl(r=>r.top===c.top&&r.bottom===c.bottom?r:c),{nearBottom:o<120}},[]);f.useEffect(()=>{var s;if(t!=null&&t.id){const o="https://app.trooper.so";w!=null&&w.id&&fetch(`${o}/api/tasks/${t.id}/notifications/read`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({participantId:w.id})}).catch(()=>{}),fetch(`${o}/api/tasks/${t.id}/subscribers`).then(l=>l.ok?l.json():[]).then(l=>hl(Array.isArray(l)?l:[])).catch(()=>{});const c=setTimeout(()=>{fetch(`${o}/api/tasks/${t.id}/subscriber-notifications`).then(l=>l.ok?l.json():{}).then(l=>fl(l&&typeof l=="object"?l:{})).catch(()=>{})},100),r=Array.isArray(t.deliveries)?t.deliveries:[],i=pt;typeof window<"u"&&window.matchMedia("(min-width: 1024px)").matches&&r.length>0&&["review","done"].includes(i)&&setTimeout(()=>hn(r[r.length-1]),50);const u=((s=t==null?void 0:t.comments)==null?void 0:s.length)??0;return kt.current=u,requestAnimationFrame(()=>{var g;const l=bs.current;u>0?(g=vs.current)==null||g.scrollIntoView({behavior:"auto"}):l&&(l.scrollTop=0),It()}),()=>clearTimeout(c)}},[t==null?void 0:t.id,w==null?void 0:w.id,It]),f.useEffect(()=>{t!=null&&t.id&&(kt.current=(t.comments||[]).length,ms(!1),yt(null),at(null),ve(null),Wt.current=!1,Kt.current=0,Ne(!0),it(!1),De("files"),Fe(!1),qn([]),mr({}),pr([]),xl.current=new Set,us(!1),ps(!1),hs(""),xs(!1),gs(""),Me.current={taskId:null,snapshot:null})},[t==null?void 0:t.id]),f.useEffect(()=>{Un(!1)},[t==null?void 0:t.id]),f.useEffect(()=>{const s=t==null?void 0:t.id;if(!s)return;const o=new AbortController;return(async()=>{var c;
42try{const r=await(m==null?void 0:m()),p=await fetch(`https://app.trooper.so/api/tasks/${s}`,{signal:o.signal,headers:r?{Authorization:`Bearer ${r}`}:{}});if(!p.ok)return;const u=await p.json().catch(()=>null);if(!(u!=null&&u.id)||((c=q.getState().selectedTask)==null?void 0:c.id)!==s)return;N(u)}catch(r){if((r==null?void 0:r.name)==="AbortError")return}})(),()=>o.abort()},[t==null?void 0:t.id,m,N]),f.useEffect(()=>{const s=t==null?void 0:t.id;if(!s){Gn([]);return}let o=[...new Set(_i(t,_e))];const c=Mi(t);let r=!1;return(async()=>{var p,u,l;if(c.length>0)try{const g=await Ue("/api/runs/resolve",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({sessionKeys:c})},{auth:!0});if(g.ok){const y=await g.json().catch(()=>({})),S=y.runsBySessionKey||((p=y.data)==null?void 0:p.runsBySessionKey)||{};for(const A of Object.values(S)){const C=(A==null?void 0:A.id)||(A==null?void 0:A.runId);C&&o.push(String(C))}}}catch{}if(o=[...new Set(o)].filter(Boolean),o.length===0){!r&&((u=q.getState().selectedTask)==null?void 0:u.id)===s&&Gn([]);return}const i=[];await Promise.all(o.map(async g=>{var y;try{const S=await Ue(`/api/runs/${encodeURIComponent(g)}/events?limit=${uu}`,{headers:{Accept:"application/json"}},{auth:!0});if(!S.ok)return;const A=await S.json().catch(()=>({})),C=((y=A.data)==null?void 0:y.events)||A.events||[];for(const P of C)i.push({event:P.event,data:P.data||{},time:P.timestamp??P.time??Date.now()})}catch{}})),!(r||((l=q.getState().selectedTask)==null?void 0:l.id)!==s)&&Gn(ri([i]))})(),()=>{r=!0}},[t,_e,bl]);const Ht=f.useMemo(()=>fd(t),[t==null?void 0:t.id,t==null?void 0:t.title,t==null?void 0:t.projectFolder]),H=f.useMemo(()=>hd(t)||"",[t==null?void 0:t.id,t==null?void 0:t.title,t==null?void 0:t.projectFolder]),Er=f.useMemo(()=>{var c,r,i;const s=new Set,o=p=>{const l=Xe(p||"").match(/^(Tasks\/[^/]+)\//i);if(!l)return;const g=l[1];!g||g===H||Ad(g,t)&&s.add(g)};for(const p of(t==null?void 0:t.executionSteps)||[]){for(const u of p.filesWritten||[])o(typeof u=="string"?u:u==null?void 0:u.path);o((c=p.fileRef)==null?void 0:c.path)}for(const p of(t==null?void 0:t.comments)||[]){o((r=p.fileRef)==null?void 0:r.path),o((i=p.artifactRef)==null?void 0:i.path);for(const u of p.writtenFiles||[])o(u==null?void 0:u.path)}return[...s]},[t,t==null?void 0:t.executionSteps,t==null?void 0:t.comments,H]),{files:z}=Pd({orgId:w==null?void 0:w.orgId,rootFolder:H,extraFolders:Er,refreshToken:`${$e}:${((io=t==null?void 0:t.comments)==null?void 0:io.length)||0}`,enabled:!!(t!=null&&t.id)});f.useEffect(()=>{yl(H?{[H]:!0}:{})},[H]),f.useEffect(()=>{var u,l,g,y,S,A;if(!I||!H)return;const s=Pn(I),o=((u=I==null?void 0:I.fileRef)==null?void 0:u.content)??((l=I==null?void 0:I.artifactRef)==null?void 0:l.code)??"";if(String(o).trim()&&!s){const C=z.find(P=>{var M,ie;const F=String((P==null?void 0:P.name)||"").toLowerCase(),x=String(((M=I==null?void 0:I.fileRef)==null?void 0:M.name)||((ie=I==null?void 0:I.artifactRef)==null?void 0:ie.title)||"").toLowerCase();return x&&(F===x||F==="plan.md")});if(!(C!=null&&C.path))return}const c={path:s||((g=I==null?void 0:I.artifactRef)==null?void 0:g.path)||((y=I==null?void 0:I.fileRef)==null?void 0:y.path)||"",name:((S=I==null?void 0:I.fileRef)==null?void 0:S.name)||((A=I==null?void 0:I.artifactRef)==null?void 0:A.title)||"",artifactRef:I==null?void 0:I.artifactRef,content:o},r=!String(o).trim()&&c.name?Ea({name:c.name,artifactRef:I==null?void 0:I.artifactRef},z,H):null,i=r!=null&&r.path?r:Ea(c,z,H);if(!(i!=null&&i.path))return;const p=Re(i.path,z,H);!p||p===s||ve(C=>{if(Pn(C)!==s)return C;const F={...C,sourceKey:p,sourcePath:p};return C!=null&&C.fileRef?{...F,fileRef:{...C.fileRef,path:p,name:i.name||C.fileRef.name,ext:i.ext||C.fileRef.ext}}:C!=null&&C.artifactRef?{...F,artifactRef:{...C.artifactRef,path:p,title:i.name||C.artifactRef.title,lang:i.ext||C.artifactRef.lang}}:C})},[z,H,I==null?void 0:I.sourcePath,(lo=I==null?void 0:I.fileRef)==null?void 0:lo.path,(co=I==null?void 0:I.artifactRef)==null?void 0:co.path,(mo=I==null?void 0:I.fileRef)==null?void 0:mo.name,(uo=I==null?void 0:I.artifactRef)==null?void 0:uo.title,(po=I==null?void 0:I.fileRef)==null?void 0:po.content,(fo=I==null?void 0:I.artifactRef)==null?void 0:fo.code]),f.useEffect(()=>{const s=o=>{o.key==="Escape"&&(Wn?(qs(!1),o.preventDefault()):ta?(us(!1),o.preventDefault()):ra?(nn(!1),an(""),o.preventDefault()):sa?(ps(!1),hs(""),o.preventDefault()):oa?(xs(!1),gs(""),o.preventDefault()):Ee?(rt(!1),St(-1),Nt(""),ot(0),o.preventDefault()):t&&(j(null),o.preventDefault()))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[t,Wn,ta,ra,sa,oa,Ee]);const ia=((ho=t==null?void 0:t.comments)==null?void 0:ho.length)??0;f.useEffect(()=>{if(ia<=kt.current)return;const s=bs.current;if(!s)return;const{scrollHeight:o,scrollTop:c,clientHeight:r}=s;o-c-r<200?(kt.current=ia,requestAnimationFrame(()=>{var p;return(p=vs.current)==null?void 0:p.scrollIntoView({behavior:"smooth"})})):ms(!0),It()},[ia,It]);const la=f.useRef(0),kl=f.useCallback(()=>{la.current||(la.current=requestAnimationFrame(()=>{var p;la.current=0;const s=bs.current;if(!s)return;const{scrollHeight:o,scrollTop:c,clientHeight:r}=s,i=o-c-r<120;It(),i&&(kt.current=((p=t==null?void 0:t.comments)==null?void 0:p.length)??0,ms(!1))}))},[It,(xo=t==null?void 0:t.comments)==null?void 0:xo.length]),Il=()=>{var s,o;(s=vs.current)==null||s.scrollIntoView({behavior:"smooth"}),kt.current=((o=t==null?void 0:t.comments)==null?void 0:o.length)??0,ms(!1),requestAnimationFrame(()=>It())};if(!t)return null;const se=Array.isArray(t.comments)?t.comments:[],ca=Array.isArray(t.history)?t.history:[],qt=Array.isArray(t.subtasks)?t.subtasks:[],Ke=Array.isArray(t.deliveries)?t.deliveries:[],Y=fm(t,v),Rl=Xn,{taskTypingEntries:da,taskStream:ae,taskRunId:Gt,taskSessionKey:Le,taskLiveEvents:Al,hasActiveLive:Pl}=vl,Jt=(()=>
42{if(Le)return Le;const s=[...se].reverse().find(o=>(o==null?void 0:o.sessionKey)&&String(o.sessionKey).trim());return s?String(s.sessionKey).trim():null})(),rn=f.useMemo(()=>Em({comments:se,liveRunsBySession:_e,taskId:t.id,agents:v}),[se,_e,t.id,v]),Tr=q(s=>s.setOpenClawLaneSessionEntries),Lr=q(s=>s.bumpOpenClawLaneSessionResync);f.useEffect(()=>{Tr(rn)},[rn,Tr]),f.useEffect(()=>()=>{Lr()},[Lr]);const $r=f.useDeferredValue(Al),ee=f.useMemo(()=>Lc($r,{maxEvents:120,windowMs:600*1e3}),[$r]),on=(ae==null?void 0:ae.text)||"",ma=f.useDeferredValue(on),ua=["done","review","blocked","paused","cancelled"].includes(gt(t.status))||String(t.executionPhase||"").toLowerCase()==="done",ln=!!(Pl||da.length>0),El=8e3,cn=f.useRef(0),[,Tl]=f.useState(0);ua?cn.current=0:ln&&(cn.current=Date.now()+El);const te=ln||!ua&&Date.now()<cn.current;f.useEffect(()=>{if(ln||!te)return;const s=Math.max(60,cn.current-Date.now()),o=setTimeout(()=>Tl(c=>c+1),s);return()=>clearTimeout(o)},[ln,te]);const Ll=!!(te||gt(t.status)==="in_progress"||t.executionPhase&&t.executionPhase!=="done"||t.lastRunSignalPending||qt.some(s=>s.status==="in_progress")),$l=!!(String(st||"").trim()||Dt.length>0),_l=q(s=>s.chatModelId),_r=f.useRef(null),Rt=(w==null?void 0:w.orgId)||(a==null?void 0:a.id)||null,dn=f.useCallback(async s=>{await Ue(`/api/tasks/${t.id}/${s}`,{method:"POST",headers:{"Content-Type":"application/json"}},{orgId:Rt})},[t.id,Rt]),Ut=f.useCallback(async(s,o="")=>{Nr(!0),aa(null);try{const c=await Ue(`/api/tasks/${t.id}/plan-action`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:s,feedback:o})},{orgId:Rt}),r=await c.json().catch(()=>null);if(!c.ok){aa((r==null?void 0:r.message)||(r==null?void 0:r.error)||`Request failed (${c.status}) â try again`);return}fs(!1),na("")}catch(c){aa((c==null?void 0:c.message)||"Network error â try again")}finally{Nr(!1)}},[t.id,Rt]),Ml=f.useCallback(()=>dn("pause"),[dn]),Ol=f.useCallback(()=>dn("resume"),[dn]),pa=f.useMemo(()=>ee.length>0||ma?Ra(ee,{isLive:te,liveStreamingText:ma}):null,[ee,ma,te]),Dl=f.useMemo(()=>{var s;return ee.length&&((s=$c(ee))==null?void 0:s.latestContextBudget)||null},[ee]),At=t.executionTarget||{type:t.executionTargetType||"brain",deviceName:t.executionDeviceName,deviceId:t.executionDeviceId},ws=t.deviceRef||(At.type==="device"?{mode:"device",deviceId:At.deviceId,deviceName:At.deviceName,label:At.deviceName||"Selected device"}:{mode:"auto"}),Fl=ws.mode==="device"?pi:Ii,js=t.blockedType==="device_dispatch"||((go=t.executionDispatch)==null?void 0:go.status)==="pending_dispatch",Ve=[...qt].sort((s,o)=>(s.stepOrder||0)-(o.stepOrder||0)),fa=Ve.length,Bl=Ve.filter(s=>s.completed||s.status==="completed").length,zl=Ve.find(s=>s.status==="in_progress"),Wl=Ve.find(s=>!(s.completed||s.status==="completed")),Mr=zl||Wl||null;Mr&&Ve.findIndex(s=>s.id===Mr.id)+1;const ys=Ve.find(s=>s.status==="blocked"&&s.blockedType==="browser_handoff")||null,ke=(ys==null?void 0:ys.browserHandoff)||t.browserHandoff||null,ha=ys?qt.findIndex(s=>s.id===ys.id):-1,Kl=f.useCallback(async()=>{if(!(!ke||ha<0))try{await fetch(`${h}/api/tasks/${t.id}/pipeline/retry`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({stepIndex:ha,reply:"The user completed the manual browser step. Continue from the blocker without asking again."})}),Rs()}catch(s){console.warn("Failed to resume browser handoff step:",s.message),Sn()}},[ke,ha,t.id]),Or=()=>{j(null),d==null||d()},Dr=f.useMemo(()=>hm({agents:v,humans:O,bridgeUrl:Fn}),[v,O,Fn]),Fr=f.useCallback(s=>e.jsx("div",{className:"text-[14px] text-neutral-900 leading-[1.75] break-words font-sans min-w-0 [overflow-wrap:anywhere] [&_a]:text-neutral-900 [&_a]:underline [&_a]:decoration-neutral-200 [&_a]:underline-offset-2",children:e.jsx(ym,{content:_c(String(s||"")),streaming:!0,remarkPlugins:gm,rehypePlugins:[xm,Qi],components:Dr,className:"leading-[1.75]"})}),[Dr]),Vl=f.useCallback(s=>{if(s.preventDefault(),!window.matchMedia("(min-width: 1024px)").matches)return;const o=s.currentTarget.closest(".task-modal-split");if(!o)return;const c=s.clientX,r=o.getBoundingClientRect().width,i=Gs;or.current=!0,document.documentElement.style.setProperty("--resize-pointer-events","none"),document.body.style.cursor="col-resize",document.body.style.userSelect="none";const p=l=>{const g=l.clientX-c,y=i+g/r*100;ml(Math.max(30,Math.min(70,y)))},u=()=>{document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",u),document.body.style.cursor="",document.body.style.userSelect="",document.documentElement.style.removeProperty("--resize-pointer-events"),or.current=!1};document.addEventListener("mousemove",p),document.addEventListener("mouseup",u)},[Gs]),Br=s=>{var o;if(s==="done"){const c=[t==null?void 0:t.result,t==null?void 0:t.outputSummary,t==null?void 0:t.lastAgentMessage,...((t==null?void 0:t.comments)||[]).slice(-5).map(i=>
42i==null?void 0:i.content)].filter(Boolean).join(` 43`),r=Im(c,{toolCount:Number((t==null?void 0:t.toolCount)||((o=t==null?void 0:t.metrics)==null?void 0:o.toolCount)||0),fileEditCount:Number((t==null?void 0:t.fileEditCount)||0)});if(r&&typeof window<"u"&&!window.confirm(`${r} 44 45Mark task done anyway?`))return;Rs()}else Cd();b(t.id,s)},Hl=s=>k(t.id,s),ql=f.useCallback(async()=>{var c;if(Xs)return;Yn(null);const s=q.getState().selectedTask;if(!(s!=null&&s.id))return;const o=gt(s.status);if(["inbox","assigned"].includes(o)){Un(!0);try{const r=s,i=r.pipeline?await Ue(`/api/tasks/${r.id}/pipeline/start`,{method:"POST"},{auth:!0,timeoutMs:65e3}):await Ue(`/api/tasks/${r.id}/run`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({startedBy:(w==null?void 0:w.name)||"user"})},{auth:!0,timeoutMs:65e3}),p=await i.json().catch(()=>({}));if(!i.ok)throw new Error(p.error||`Could not start task (${i.status})`);if(Rs(),(c=p==null?void 0:p.task)!=null&&c.id)N(p.task);else{const u=r.id;q.setState(l=>{const g=y=>(y==null?void 0:y.id)!==u?y:{...y,status:"in_progress",executionPhase:y.executionPhase||"planning"};return{tasks:l.tasks.map(g),selectedTask:l.selectedTask?g(l.selectedTask):l.selectedTask}})}}catch(r){console.error("[TaskModal] Start work failed:",r);const i=(r==null?void 0:r.message)||(r==null?void 0:r.name)||"";if(/timeout|timed out|abort|signal/i.test(i)){const p=s.id;q.setState(u=>{const l=g=>(g==null?void 0:g.id)!==p?g:{...g,status:"in_progress",executionPhase:g.executionPhase||"planning",lastRunSignalPending:!0,lastRunSignalPendingAt:Date.now()};return{tasks:u.tasks.map(l),selectedTask:u.selectedTask?l(u.selectedTask):u.selectedTask}}),Rs();return}Yn((r==null?void 0:r.message)||"Start work failed"),Sn()}finally{Un(!1)}}},[Xs,N,w==null?void 0:w.name]),zr=f.useCallback(async s=>{if(!(t!=null&&t.id))return;if(s!=="workflow"){ue(Wu(t,v));return}const o=Hu(t,v),c=Za(t,v);ue(o),ar(!0);try{const r=await Ue("/api/workflows/generate-from-task",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:t.id,context:{...c,taskId:t.id,priority:t.priority||"",labels:Array.isArray(t.labels)?t.labels:[],files:Array.isArray(t.files)?t.files:[],repos:Array.isArray(t.repos)?t.repos:[]},fallbackDraft:o})},{auth:!0,orgId:(a==null?void 0:a.id)||(w==null?void 0:w.orgId)||null,timeoutMs:35e3}),i=await r.json().catch(()=>({}));if(!r.ok)throw new Error((i==null?void 0:i.message)||(i==null?void 0:i.error)||`Could not generate workflow (${r.status})`);i!=null&&i.workflow&&ue(Vu(o,i.workflow))}catch(r){console.warn("[TaskModal] AI workflow generation fell back to local draft:",r)}finally{ar(!1)}},[v,a==null?void 0:a.id,w==null?void 0:w.orgId,t]),Gl=f.useCallback(async()=>{if(!(!U||cs||Ft)){nr(!0);try{if(U.type==="routine"){const s=await fetch(`${h}/api/cron/jobs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:U.name,cronExpression:U.cronExpression,message:U.message,targetAgent:U.targetAgent||void 0,taskId:t==null?void 0:t.id})}),o=await s.json().catch(()=>({}));if(!s.ok)throw new Error(o.error||`Could not create routine (${s.status})`);As.success("Routine created")}else{const s={...U.workflow,updatedAt:Date.now()},o=await fetch(`${h}/api/saved-workflows/${s.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),c=await o.json().catch(()=>({}));if(!o.ok)throw new Error(c.error||`Could not create workflow (${o.status})`);As.success("Workflow added"),window.dispatchEvent(new CustomEvent("navigate-page",{detail:"workflows"}))}ue(null),Rs()}catch(s){As.error((s==null?void 0:s.message)||"Could not save"),Sn()}finally{nr(!1)}}},[h,U,Ft,cs,t==null?void 0:t.id]),Jl=s=>{const o=Array.from(s.target.files||[]);o.length&&Vs(c=>[...c,...o.map(r=>({file:r,name:r.name}))]),s.target.value=""},Ul=s=>Vs(o=>o.filter((c,r)=>r!==s)),xa=async s=>{if(s.preventDefault(),!st.trim()&&Dt.length===0&&Ks.length===0||sr)return;Hs(!0);let o="";if(Dt.length>0)try{const M=new FormData;for(const de of Dt)M.append("files",de.file);M.append("path","/");const Z=await fetch("https://app.trooper.so/api/bridge/files/upload",{method:"POST",body:M});Z.ok?o=` 46ð `+((await Z.json()).files||[]).map(D=>D.name).join(", "):console.warn("[TaskModal] File upload failed")}catch(M){console.warn("[TaskModal] File upload error:",M.message)}
46const c=(st.trim()+o).trim(),r=pm(c,Pe||[]),i=r.content;if(!i&&Ks.length===0){Hs(!1);return}const p=dd(Ks,c),u=Y||v[0],l=Wm({composerRefs:p,agents:v,text:i}),g=[...new Set([...l||[],...u!=null&&u.id?[u.id]:[]])],y=t!=null&&t.projectId?(Lt||[]).find(M=>M.id===t.projectId):null,S=t!=null&&t.id?`task-chat-${t.id}`:null;if(!ua&&te&&(u!=null&&u.id)){Ms(i,{replyTo:(be==null?void 0:be.id)||null,mentions:g,composerRefs:p,mode:"chat",agentId:u.id,sessionId:Le||null,taskId:t.id,channel:S,projectRef:y?{id:y.id,name:y.name,localPath:y.localPath||"",githubUrl:y.githubUrl||"",branch:y.branch||"main"}:null,messageType:"task_chat",planModeOverride:r.planMode===!0}),wt(""),is([]),Vs([]),Us(null),rt(!1),Hs(!1);return}const A=`local-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,C=(u==null?void 0:u.id)||t.assigneeId||"lead",P=(u==null?void 0:u.name)||t.assigneeName||"Manager",F=`task-chat:pending:${A}`;q.setState(M=>{var D,he,Q;const ie={id:A,authorId:(w==null?void 0:w.id)||null,authorName:(w==null?void 0:w.name)||"You",isAgent:!1,content:i,replyTo:(be==null?void 0:be.id)||null,createdAt:Date.now(),reactions:[]},Z=[...Array.isArray((D=M.selectedTask)==null?void 0:D.comments)?M.selectedTask.comments:[],ie];return{liveRunsBySession:Jc(M.liveRunsBySession,{agentId:C,agentName:P,runId:F,sessionKey:(t==null?void 0:t.managerSessionKey)||Jt||null,taskId:t.id,channel:S,status:"working",source:"task-chat-optimistic",lastWorkAt:Date.now(),updatedAt:Date.now()}),typingAgents:{...M.typingAgents||{},[C]:{...((he=M.typingAgents)==null?void 0:he[C])||{},name:P,time:Date.now(),taskId:t.id,channel:S,runId:F,status:"working",source:"task-chat-optimistic"}},selectedTask:((Q=M.selectedTask)==null?void 0:Q.id)===t.id?{...M.selectedTask,comments:Z}:M.selectedTask,tasks:M.tasks.map(X=>X.id===t.id?{...X,comments:Z}:X)}}),window.setTimeout(()=>{const M=q.getState().liveRunsBySession;Object.values(M||{}).some(Z=>String((Z==null?void 0:Z.runId)||"")===F&&String((Z==null?void 0:Z.source)||"")==="task-chat-optimistic")&&q.setState(Z=>{var he;const de=Uc(Z.liveRunsBySession,Q=>String((Q==null?void 0:Q.runId)||"")===F),D={...Z.typingAgents||{}};return((he=D[C])==null?void 0:he.runId)===F&&delete D[C],{liveRunsBySession:de,typingAgents:D}})},45e3),R(t.id,{authorName:(w==null?void 0:w.name)||"You",authorId:(w==null?void 0:w.id)||null,content:i,replyTo:(be==null?void 0:be.id)||null,skipMentions:!0});const{sendMessage:x}=q.getState();if(x){const M=(t==null?void 0:t.managerSessionKey)||Jt||void 0;x(i,{taskRef:t.id,channel:S,mentions:g,explicitMentions:l||[],composerRefs:p,type:"task_chat",sessionKey:M,steer:!!M,agentId:(u==null?void 0:u.id)||void 0,planModeOverride:r.planMode===!0})}wt(""),is([]),Vs([]),Us(null),rt(!1),Hs(!1),requestAnimationFrame(()=>{var M,ie;(M=vs.current)==null||M.scrollIntoView({behavior:"smooth"}),kt.current=(((ie=t==null?void 0:t.comments)==null?void 0:ie.length)??0)+1,ms(!1)})},Yl=f.useMemo(()=>Kd("task",tr),[tr]),Yt=f.useMemo(()=>{const s=new Set,o=[],c=r=>{const i=(r==null?void 0:r.path)||(r==null?void 0:r.fullPath)||"",p=i?Xe(i):"",u=(r==null?void 0:r.name)||p.split("/").pop()||"",l=p||u;!l||s.has(l)||(s.add(l),o.push({key:`recent-file:${l}`,kind:"file",label:u||"File",subtitle:p||"Recent file",ext:(u.split(".").pop()||"").toLowerCase()}))};return(ss||[]).forEach(r=>{var i,p,u,l,g,y;((r==null?void 0:r.files)||[]).forEach(c),((r==null?void 0:r.attachments)||[]).forEach(c),((i=r==null?void 0:r.fileRef)!=null&&i.path||(p=r==null?void 0:r.fileRef)!=null&&p.name)&&c(r.fileRef),((u=r==null?void 0:r.artifactRef)!=null&&u.path||(l=r==null?void 0:r.artifactRef)!=null&&l.name)&&c(r.artifactRef),((g=r==null?void 0:r.artifact)!=null&&g.path||(y=r==null?void 0:r.artifact)!=null&&y.title)&&
46c({path:r.artifact.path,name:r.artifact.title})}),o.slice(0,16)},[ss]),Xl=f.useMemo(()=>{const s=new Map,o=[],c=(i,p,u)=>{!i||!p||(o.some(l=>l.value===p)||o.push({label:i,value:p}),s.set(p,u))};[...O||[],...v||[]].forEach(i=>{if(!(i!=null&&i.id)||!(i!=null&&i.name))return;const p=`agent:${i.id}`;c(i.name,p,()=>({id:p,kind:"agent",label:i.name,subtitle:i.title||i.role||"Agent",agentId:i.id}))});const r=oi({agents:Fs,sessions:Ot,channel:t!=null&&t.id?`task-chat-${t.id}`:""});return[...r.activeSessions,...r.availableAgents].forEach(i=>{const p=`${i.kind}:${i.id}`;c(i.label,p,()=>({...i,id:p}))}),Yt.forEach(i=>{const p=`file:${i.key||i.label}`;c(i.label||"File",p,()=>({id:p,kind:"file",label:i.label||"File",path:i.subtitle||"",fileType:i.ext||"",ext:i.ext||""}))}),{options:o,registry:s}},[Fs,Ot,v,O,Yt,t==null?void 0:t.id]),mn=f.useCallback((s=null)=>{setTimeout(()=>{var r,i;const o=We.current,c=(r=o==null?void 0:o.querySelector)==null?void 0:r.call(o,'[contenteditable="true"]');(i=c==null?void 0:c.focus)==null||i.call(c),s!==null&&o&&ed(o,s)},0)},[]),Ql=s=>{var i;const o=typeof s=="string"?s:String(((i=s==null?void 0:s.target)==null?void 0:i.value)||""),c=Ia(We.current);wt(o);const r=md(o,c);if(r){St(r.start),Nt(r.query),rt(!0),ot(0),r.trigger==="/"?(Hn(r.start),Vn(r.query)):(Hn(-1),Vn("")),cr(!1),dr(0);return}rt(!1),St(-1),Nt(""),cr(!1),Hn(-1),Vn(""),dr(0)},ga=f.useMemo(()=>{var F;const s=Te.trim().toLowerCase(),o=(...x)=>
46s?x.filter(Boolean).some(M=>String(M).toLowerCase().includes(s)):!0;let c=0;const r=x=>x.map(M=>({...M,pickerIndex:c++})),i=[],p=td(Yl,Te);p.length>0&&i.push({key:"commands",label:"Commands",items:r(p)});const u=Ci({agents:v,humans:O,query:Te,currentUserId:w==null?void 0:w.id,maxPeople:Rn.people});u.length&&i.push({id:"people",label:"People & Agents",items:r(u)});const l=oi({agents:Fs,sessions:Ot,channel:t!=null&&t.id?`task-chat-${t.id}`:""}),g=l.activeSessions.filter(x=>o(x.label,x.subtitle,x.providerId,x.recentActivity)).map(x=>({key:`${x.kind}:${x.id}`,kind:x.kind,label:x.label,subtitle:x.subtitle,iconUrl:x.icon,ref:x}));g.length&&i.push({id:"acp-sessions",label:"Active ACP sessions",items:r(g)});const y=l.availableAgents.filter(x=>o(x.label,x.subtitle,x.providerId)).map(x=>({key:`${x.kind}:${x.id}`,kind:x.kind,label:x.label,subtitle:x.subtitle,iconUrl:x.icon,ref:x}));y.length&&i.push({id:"acp-agents",label:"Available ACP agents",items:r(y)});const S=[...(z||[]).filter(x=>(x==null?void 0:x.type)!=="dir").filter(x=>o(x==null?void 0:x.name,x==null?void 0:x.path,x==null?void 0:x.relativePath,x==null?void 0:x.fullPath)).slice(0,s?10:5).map(x=>{var Z;const M=x.name||((Z=x.path)==null?void 0:Z.split("/").pop())||"File",ie=(M.split(".").pop()||"").toLowerCase();return{key:`file:${x.path||x.fullPath||x.relativePath||M}`,kind:"file",label:M,subtitle:x.relativePath||x.path||x.fullPath||"Workspace file",ext:ie}}),...(Yt||[]).filter(x=>o(x==null?void 0:x.label,x==null?void 0:x.subtitle))];S.length&&i.push({id:"files",label:"Files",items:r(S)});const A=(Pe||[]).filter(x=>o(x==null?void 0:x.name,x==null?void 0:x.slug,x==null?void 0:x.description,x==null?void 0:x.category)).slice(0,s?8:4).map(x=>({key:`skill:${x.id||x.slug||x.name}`,kind:"skill",label:x.name||x.slug||"Skill",subtitle:x.description||x.slug||"Installed skill"}));A.length&&i.push({id:"skills",label:"Skills",items:r(A)});const C=Ni(void 0,{installedSkills:Pe,connectedSlugs:ne.connectedSlugs,extraInstalledAliases:jt}).filter(x=>o(x==null?void 0:x.name,x==null?void 0:x.id,x==null?void 0:x.category,x==null?void 0:x.domain,...Array.isArray(x==null?void 0:x.keywords)?x.keywords:[])).slice(0,s?Rn.plugins:6).map(x=>Si(x)).filter(Boolean);if(C.length&&i.push({id:"plugins",label:"Plugins",items:r(C)}),s){const x=Array.isArray((F=a==null?void 0:a.onboarding)==null?void 0:F.recommendedSkills)?a.onboarding.recommendedSkills:[];tm({mentionFilter:Te,installedSkills:Pe,connectedSlugs:ne.connectedSlugs,extraInstalledAliases:jt,skillCandidates:x}).forEach(M=>{var ie;(ie=M.items)!=null&&ie.length&&i.push({id:M.id,label:M.label,items:r(M.items)})})}const P=(Qe||[]).filter(x=>(x==null?void 0:x.kind)!=="brain").filter(x=>!ii(x)).filter(x=>o(x==null?void 0:x.name,x==null?void 0:x.status,x==null?void 0:x.platform,x==null?void 0:x.kind)).slice(0,s?8:4).map(x=>({key:`device:${x.id||x.name}`,kind:"device",label:x.name||"Device",subtitle:x.status||x.platform||"Connected device",status:x.status||"",platform:x.platform||x.os||"",deviceId:x.id||x.deviceId||"",ref:{kind:"device",id:x.id||x.name,label:x.name||"Device",subtitle:x.status||x.platform||"Connected device",deviceId:x.id||x.deviceId||"",platform:x.platform||x.os||"",status:x.status||""}}));return P.length&&i.push({id:"devices",label:"Devices",items:r(P)}),ki(i)},[v,Fs,Ot,jt,(bo=a==null?void 0:a.onboarding)==null?void 0:bo.recommendedSkills,w==null?void 0:w.id,Qe,O,Pe,Te,ne.connectedSlugs,Yt,z,t==null?void 0:t.id]),Zl=f.useMemo(()=>{const s=[],o=Ci({agents:v,humans:O,query:"",currentUserId:w==null?void 0:w.id,maxPeople:Rn.people});o.length&&s.push({id:"people",label:"People & Agents",items:o});const c=[...(z||[]).filter(u=>(u==null?void 0:u.type)!=="dir").slice(0,24).map(u=>{var y;const l=u.name||((y=u.path)==null?void 0:y.split("/").pop())||"File",g=(l.split(".").pop()||"").toLowerCase();return{key:`file:${u.path||u.fullPath||u.relativePath||l}`,kind:"file",label:l,subtitle:u.relativePath||u.path||u.fullPath||"Workspace file",ext:g,ref:{kind:"file",id:`file:${u.path||u.fullPath||u.relativePath||l}`,label:l,path:u.path||u.fullPath||u.relativePath||l,ext:g}}}),...Yt||[]];c.length&&s.push({id:"files",label:"Files",items:c});const r=(Pe||[]).slice(0,24).map(u=>({key:`skill:${u.id||u.slug||u.name}
46`,kind:"skill",label:u.name||u.slug||"Skill",subtitle:u.description||u.slug||"Installed skill",ref:{kind:"skill",id:u.id||u.slug||u.name,slug:u.slug||u.name,label:u.name||u.slug||"Skill"}}));r.length&&s.push({id:"skills",label:"Skills",items:r});const i=Ni(void 0,{installedSkills:Pe,connectedSlugs:ne.connectedSlugs,extraInstalledAliases:jt}).slice(0,Rn.plugins).map(u=>Si(u)).filter(Boolean);i.length&&s.push({id:"plugins",label:"Plugins",items:i});const p=(Qe||[]).filter(u=>(u==null?void 0:u.kind)!=="brain").filter(u=>!ii(u)).slice(0,16).map(u=>({key:`device:${u.id||u.name}`,kind:"device",label:u.name||"Device",subtitle:u.status||u.platform||"Connected device",status:u.status||"",platform:u.platform||u.os||"",deviceId:u.id||u.deviceId||"",ref:{kind:"device",id:u.id||u.name,label:u.name||"Device",subtitle:u.status||u.platform||"Connected device",deviceId:u.id||u.deviceId||"",platform:u.platform||u.os||"",status:u.status||""}}));return p.length&&s.push({id:"devices",label:"Devices",items:p}),ki(s)},[v,jt,w==null?void 0:w.id,Qe,O,Pe,ne.connectedSlugs,Yt,z]),Pt=f.useMemo(()=>ga.flatMap(s=>s.items||[]),[ga]);f.useEffect(()=>{Ee&&ot(s=>Math.min(s,Math.max(0,Pt.length-1)))},[Ee,Pt.length]);const ec=f.useCallback(()=>{rt(!1),St(-1),Nt(""),ot(0)},[]);f.useEffect(()=>{Ee&&sd(Pr.current[Js])},[Js,Ee]);const Wr=f.useCallback(s=>{if(!s)return;if(s.installAction){rt(!1),St(-1),Nt(""),ot(0),sm(s.installAction,{onPluginConnect:ne.openPluginConnect,onSkillInstall:Yc}),mn();return}const o=s.kind==="person"||s.kind==="agent",c=s.ref||{id:`${s.kind||"ref"}:${s.personId||s.id||s.key||s.label}`,kind:s.kind||"reference",label:s.label||s.name||"Reference",subtitle:s.subtitle||"",agentId:s.personId||s.id||"",avatar:s.avatarUrl||s.avatar||"",ext:s.ext||"",fileType:s.fileType||s.ext||""},r=nd(We.current,{...s,ref:c},{triggerStart:ds,query:Te,resolveAvatarUrl:i=>Xc(i)});if(is(i=>{const p=`${c.kind}:${c.id||c.sessionId||c.providerId||c.label}`;return i.some(u=>`${u.kind}:${u.id||u.sessionId||u.providerId||u.label}`===p)?i:[...i,c]}),!r){const i=o?`@${s.label||s.name||""}`:s.label||c.label||"",p=ds>=0?ds+1+String(Te||"").length:Ia(We.current),{nextValue:u,nextCursor:l}=ad(st,{cursor:p,tokenStart:ds,insertText:i});wt(u),mn(l)}rt(!1),St(-1),Nt(""),ot(0)},[st,mn,Te,ds]),un=s=>{if(Ee){if(s.key==="ArrowDown"){yn(s),ot(o=>Math.min(o+1,Pt.length-1));return}if(s.key==="ArrowUp"){yn(s),ot(o=>Math.max(o-1,0));return}if(mi(s.key,Te)&&Pt.length>0){yn(s),Wr(Pt[Js]);return}if(s.key==="Escape"||s.key==="Enter"&&!String(Te||"").trim()){if(yn(s),rt(!1),St(-1),Nt(""),ot(0),s.key!=="Enter")return}else return}};f.useEffect(()=>{if(!Ee&&!lr)return;const s=new Set(["ArrowDown","ArrowUp","Enter","Tab","Escape"]),o=c=>{if(!s.has(c.key))return;const r=We.current,i=document.activeElement;!r||!i||!r.contains(i)||un(c)};return window.addEventListener("keydown",o,!0),()=>window.removeEventListener("keydown",o,!0)},[un,Ee,lr]);const Kr=async(s,o)=>{if(w!=null&&w.id)try{await fetch(`https://app.trooper.so/api/tasks/${t.id}/comments/${s}/reaction`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({emoji:o,userId:w.id})})}catch(c){console.error(c)}},we=f.useCallback((s,o={})=>{Wt.current=!1,Ne(!1),Fe(!1),De(s),s==="files"?(it(!0),o.artifact!==void 0&&ve(o.artifact),o.delivery!==void 0&&(yt(o.delivery),o.delivery||at(null))):(ve(null),yt(null),at(null))},[]),pn=f.useCallback(()=>{Wt.current=!0,Ne(!0),it(!1),De("files"),Fe(!1),yt(null),at(null),ve(null)},[]),tc=f.useCallback((s,o)=>{const c=Ta(s);c&&pr(r=>r.includes(c)?r:[...r,c]),qn(r=>r.filter((i,p)=>bt(i,p)!==bt(s,o))),ve(r=>{const i=$a(r);if(!i)return r;const p=Array.isArray(i)?i:[i],u=bt(s,o);return p.some(l=>bt(l,0)===u)?null:r})},[]);f.useEffect(()=>{const s=$a(I);if(!s)return;const o=Array.isArray(s)?s:[s];qn(c=>{let r=c;for(const i of o){if(!i.code&&!i.path)continue;const p=bt(i,0),u=r.filter((l,g)=>bt(l,g)!==p);r=[i,...u].slice(0,12)}return r})},[I]);const Vr=f.useCallback(s=>{if(!(s!=null&&s.path)||!Ya(s))return[];const o=Di(s),c=z.filter(i=>Di(i)===o).filter(i=>["html","htm","css","js","mjs","json"].includes(Ye(i))).sort((i,p)=>{const u=Ye(i),l=Ye(p),g=["html","htm"].includes(u)?0:u==="css"?1:["js","mjs"].includes(u)?2:3,
46y=["html","htm"].includes(l)?0:l==="css"?1:["js","mjs"].includes(l)?2:3;return g!==y?g-y:dt(i).localeCompare(dt(p))});return c.some(i=>Ya(i))?c:[]},[z]),Et=f.useCallback(async s=>{var u;const o=String((s==null?void 0:s.content)||((u=s==null?void 0:s.artifactRef)==null?void 0:u.code)||"").trim(),c=Re((s==null?void 0:s.path)||(s==null?void 0:s.name),z,H),r=tu(c,H,s);if(!c&&!r.length&&!o)return;const i=(s==null?void 0:s.name)||(c==null?void 0:c.split("/").filter(Boolean).pop())||"file",p=(l="",g=c||"")=>{we("files",{artifact:{...Ma({...s,path:g||void 0,name:i},l),sourceKey:g||i,sourcePath:g||void 0}})};try{const l=c?Vr({...s,path:c}):[];if(l.length>1){const g=await Promise.all(l.map(async y=>{var C;const S=await kn(y.path,{orgId:w==null?void 0:w.orgId,signal:AbortSignal.timeout(1e4)});if(!S.ok)throw new Error(`Failed to load ${y.name||y.path}`);const A=await S.text();return{name:y.name||((C=y.path)==null?void 0:C.split("/").pop())||"file",path:y.path,ext:Ye(y),content:A}}));we("files",{artifact:{filesRef:g,sourceKey:c,sourcePath:c}});return}o&&p(o,"");for(const g of r){const y=await kn(g,{orgId:w==null?void 0:w.orgId,signal:AbortSignal.timeout(1e4)});if(!y.ok)continue;const S=await y.text();p(S,g);return}o||p("")}catch(l){console.warn("[TaskModal] Failed to open workspace file:",l.message),o?p(o,""):p("")}},[w==null?void 0:w.orgId,we,Vr,H,z]),fn=f.useCallback(async s=>{const o=await su(s,{orgId:w==null?void 0:w.orgId,workspaceFiles:z});o&&we("files",{artifact:o})},[w==null?void 0:w.orgId,we,H,z]),Ns=String(t.executionPhase||"").toLowerCase(),Ss=Ns==="plan_review"||Ns==="planning"?String(((vo=t.planReview)==null?void 0:vo.markdown)||""):"",Hr=f.useRef(null);f.useEffect(()=>{var c,r,i;if(!Ss)return;const s=[t.id,((c=t.planReview)==null?void 0:c.requestedAt)||"",((r=t.planReview)==null?void 0:r.revisionCount)||0].join(":"),o=()=>{if(Hr.current!==s){Hr.current=s,we("files",{artifact:{fileRef:{name:"PLAN.md",ext:"md",content:Ss}}});return}ve(p=>{const u=p==null?void 0:p.fileRef;return!u||String(u.name||"").toLowerCase()!=="plan.md"||String(u.content||"")===Ss?p:{...p,fileRef:{...u,name:"PLAN.md",ext:"md",content:Ss,path:u.path&&Ns==="plan_review"?u.path:void 0}}})};if(Ns==="planning"||((i=t.planReview)==null?void 0:i.status)==="drafting"){const p=setTimeout(o,400);return()=>clearTimeout(p)}o()},[Ss,Ns,t.id,(wo=t.planReview)==null?void 0:wo.requestedAt,(jo=t.planReview)==null?void 0:jo.revisionCount,(yo=t.planReview)==null?void 0:yo.status,we]),f.useEffect(()=>{const s=o=>{var p,u;const c=(p=o==null?void 0:o.detail)==null?void 0:p.path;if(!c||kd([t],c)==null&&/(?:^|\/)Tasks\//i.test(String(c)))return;const r=qi(c,z);if(!r)return;(u=o.preventDefault)==null||u.call(o);const i=Re(r.path||c,z,H);Et({...r,path:i||r.path||c,name:r.name||i.split("/").filter(Boolean).pop()||"file"})};return window.addEventListener("trooper:open-workspace-file",s),()=>window.removeEventListener("trooper:open-workspace-file",s)},[Et,t,H,z]);const qr=async s=>{var r,i,p,u,l;if(!s)return;if(Ne(!1),it(!0),De("files"),Fe(!1),s.type==="delivery"&&s.delivery){const g=Oi(s.delivery,z);if(g){await Et(g);return}await hn(s.delivery);return}const o=Ea(s,z,H);if(o!=null&&o.path){await Et({...s,path:o.path,name:o.name,content:o.content||s.content||((r=s.artifactRef)==null?void 0:r.code)||"",ext:o.ext||Ye(s)});return}if(s.content&&String(s.content).trim()||(i=s.artifactRef)!=null&&i.code&&String(s.artifactRef.code).trim()){const g=Re(s.path||s.relativePath||((p=s.artifactRef)==null?void 0:p.path)||"",z,H);we("files",{artifact:{...Ma({...s,path:g||s.path||s.relativePath},s.content||((u=s.artifactRef)==null?void 0:u.code)||""),sourceKey:g||s.path||s.relativePath||s.name,sourcePath:g||s.path||s.relativePath||""}});return}const c=Re(s.path||s.relativePath||((l=s.artifactRef)==null?void 0:l.path)||s.name||"",z,H);we("files",{artifact:{...Ma({...s,path:c||s.path||s.relativePath}),sourceKey:c||s.path||s.relativePath||s.name,sourcePath:c||s.path||s.relativePath||""}})},hn=async s=>{De("files");const o=Oi(s,z);if(o){await Et(o);return}yt(s),ir(!0),at(null);try{const r=await(await fetch(`https://app.trooper.so/api/tasks/${t.id}/deliveries/${s.id}`)).json();let i=r.content;const p=r.files||s.files;!i&&(p==null?void 0:p.length)>0&&(i=p.map(u=>`## ${u.name} 47 48${u.content||""}`).join(` 49 50--- 51 52`)),at(i??"")}catch{at("Failed to load content")}finally{ir(!1)}},ba=(s,o,c)=>{s&&s.stopPropagation();const r=document.createElement("a");r.href=o,r.download=c,document.body.appendChild(r),r.click(),document.body.removeChild(r)},sc=s=>Da(s.content).map((o,c)=>{var r,i,p,u,l;if(o.type==="report")return e.jsx($u,{title:"Report generated",steps:[{label:"View report",status:"done"}],children:e.jsx("div",{className:"px-4 pb-3 pt-1 text-sm text-neutral-600",children:e.jsx(Es,{content:o.value,agents:v,humans:O})})},c);if(o.type==="delivery")return e.jsx(Eu,{content:o.value,taskId:t.id,authorName:s.authorName},c);if(o.type==="tool"){const{label:g}=Va(o.toolName);return e.jsx(rl,{label:`${g}
52${(r=o.params)!=null&&r.query?` â ${hu(o.params.query).slice(0,60)}`:(i=o.params)!=null&&i.url?` â ${o.params.url.slice(0,50)}`:""}`,status:"done",icon:"wrench",detail:o.value?e.jsx(Es,{content:o.value,agents:v,humans:O,className:"text-sm"}):null},c)}if(o.type==="tool_activity"){try{const y=JSON.parse(o.value);if(Array.isArray(y)){const S=y.find(A=>A.tool==="suggest_skills"&&A.success!==!1);if(S!=null&&S.summary){const A=typeof S.summary=="string"?JSON.parse(S.summary):S.summary;if(((p=A.suggestions)==null?void 0:p.length)>0)return e.jsx(Du,{data:A},c)}}}catch{}const g=(()=>{try{const y=JSON.parse(o.value);if(Array.isArray(y)){const S=[];return y.forEach((A,C)=>{const P=A.timestamp||Date.now();S.push({event:"tool_start",data:{tool:A.tool,params:A.params,index:C},time:P}),S.push({event:"tool_result",data:{tool:A.tool,index:C,success:A.success!==!1,summary:A.summary||""},time:P+1})}),Ra(S).semanticTimelineEntries}}catch{}return[]})();return g.length>0?e.jsx(vm,{entries:g,isLive:!1},c):e.jsx(_u,{data:o.value},c)}if(o.type==="file"){const g=((l=(u=o.name)==null?void 0:u.split(".").pop())==null?void 0:l.toLowerCase())||"";return e.jsx(Tu,{name:o.name,content:o.value,agents:v,humans:O,onOpenArtifact:()=>{we("files",{artifact:{fileRef:{name:o.name,ext:g,content:o.value}}})}},c)}if(o.type==="action")return e.jsx(Lu,{content:o.value},c);if(o.type==="artifact"){const g={type:o.artifactType||"html",title:o.title||"Artifact",code:o.value,lang:o.lang||o.artifactType||""};return e.jsx(Xi,{artifact:g,onClick:()=>we("files",{artifact:{artifactRef:g}}),className:"my-2 w-full max-w-md"},c)}if(o.type==="diff"){const g={title:"File Changes",diff:o.value};return e.jsx(bi,{artifact:g,className:"my-2 w-full max-w-2xl"},c)}return e.jsx("div",{className:"leading-[1.9]",children:e.jsx(Es,{content:o.value,agents:v,humans:O,className:"text-sm"})},c)}),nc=s=>{var u;let o=s.authorName,c=s.authorId;if((o||"").toLowerCase()==="system"){const l=(t.assigneeId?v.find(g=>g.id===t.assigneeId):null)||v.find(g=>g.role==="LEAD")||v.find(g=>["Team Lead","Product Manager","Operations Manager","Manager","Lead","Director","VP","Head","Chief of Staff"].some(y=>{var S;return(S=g.title)==null?void 0:S.includes(y)}))||v[0];l&&(o=l.name,c=l.id)}const r=(o||"").replace(/^@/,"").trim().toLowerCase(),i=c?v.find(l=>l.id===c)||(O==null?void 0:O.find(l=>l.id===c)):v.find(l=>
52l.name.toLowerCase()===r)||(O==null?void 0:O.find(l=>l.name.toLowerCase()===r)),p=s.authorAvatar||(i==null?void 0:i.avatar)||((u=v.find(l=>l.name.toLowerCase()===r))==null?void 0:u.avatar)||null;return{name:(i==null?void 0:i.name)||o,avatar:p,title:(i==null?void 0:i.title)||"",role:(i==null?void 0:i.role)||null,id:(i==null?void 0:i.id)||c}},ac=se.filter((s,o,c)=>{if(o===c.length-1)return!0;const r=c[o+1];return!(r&&s.content&&r.content&&s.content===r.content)}),fe=q(s=>s.browserLiveView),rc=q(s=>s.agentTodos),oc=!0,Gr=!0,ic=!0,Cs=!0,Xt=f.useMemo(()=>{var c;const s=[];return!!(fe&&(t!=null&&t.id)&&(fe.taskId===t.id||fe.agentId!=null&&fe.agentId===t.assigneeId))&&s.push({type:"browser_live",key:"live",...fe}),se.forEach(r=>{if(!r.content)return;const i=r.content.match(/data:image\/[^;]+;base64,[A-Za-z0-9+/=]+/g);i&&i.forEach((p,u)=>s.push({type:"image",key:`img-${r.id}-${u}`,src:p}))}),ee.forEach((r,i)=>{var p;r.event==="screenshot_frame"&&((p=r.data)!=null&&p.base64)&&s.push({type:"screenshot",key:`ss-${i}`,base64:r.data.base64,timestamp:r.data.timestamp})}),((c=t.deliveries)==null?void 0:c.length)>0&&s.length===0&&t.deliveries.forEach((r,i)=>{r.content&&r.content.length>50&&s.push({type:"deliverable",key:`del-${i}`,content:r.content,fileName:r.fileName,mimeType:r.mimeType})}),s},[oc,fe,t==null?void 0:t.id,t==null?void 0:t.assigneeId,t==null?void 0:t.deliveries,se,ee]),Qt=Xt.some(s=>s.type==="browser_live");f.useEffect(()=>{Qt&&(Wt.current||(Ne(!1),it(!0),De("browser")))},[Qt,fe==null?void 0:fe.tabId,fe==null?void 0:fe.screenshotBase64,fe==null?void 0:fe.updatedAt]);const He=Rm(rc,t.id,Rl),lc=f.useMemo(()=>{var i,p,u;if(!((i=He==null?void 0:He.todos)!=null&&i.length))return null;const s=((p=He.summary)==null?void 0:p.completed)||0,o=((u=He.summary)==null?void 0:u.total)||He.todos.length,c=o>0&&s===o,r=He.updatedAt&&Date.now()-He.updatedAt<3e5;return c&&!r?null:He},[He]),cc=f.useMemo(()=>{const s=B==null?void 0:B[t.id],o=t.executionSteps||(s==null?void 0:s.steps)||[];return al(o,"Task checklist",(s==null?void 0:s.updatedAt)||t.updatedAt||Date.now())},[t,B]),dc=f.useMemo(()=>Ru(Ve,t.updatedAt||Date.now()),[Ve,t.updatedAt]),qe=cc||dc||lc,xn=!!((No=qe==null?void 0:qe.todos)!=null&&No.length),va=Au(t),xt=f.useMemo(()=>t!=null&&t.id?(ns||[]).filter(s=>(s==null?void 0:s.taskId)===t.id):[],[ns,t==null?void 0:t.id]);f.useEffect(()=>{if(!Mt||!w||te||xt.length===0||li(Ze,{taskId:t==null?void 0:t.id}))return;const s=setTimeout(()=>{$t==null||$t({trigger:"task-composer-idle"})},150);return()=>clearTimeout(s)},[Mt,w,$t,te,xt.length,Ze,t==null?void 0:t.id]);const Jr=f.useCallback(s=>{s!=null&&s.id&&(xe==null||xe(s.id,{mode:s.mode==="steer"?"chat":"steer",agentId:(Y==null?void 0:Y.id)||s.agentId||null,sessionId:Le||s.sessionId||null,taskId:(t==null?void 0:t.id)||s.taskId||null}))},[Y==null?void 0:Y.id,Le,t==null?void 0:t.id,xe]),Ur=f.useMemo(()=>{const s=[],o=new Set,c=l=>l?l.fromBridge||l.type==="delivery"?gi([l],H)[0]||l:Array.isArray(z)&&z.length>0?xi([l],z,H)[0]||null:gi([l],H)[0]||null:null,r=l=>{const g=c(l)||l,y=(g==null?void 0:g.path)||(l==null?void 0:l.path)||(l==null?void 0:l.relativePath)||"",S=(g==null?void 0:g.name)||(l==null?void 0:l.name)||y.split("/").pop()||"";y&&o.add(Xe(y).toLowerCase()),S&&o.add(`name:${S.toLowerCase()}`)},i=l=>{const g=c(l);if(!g&&(l!=null&&l.path))return!0;const y=(g==null?void 0:g.path)||(l==null?void 0:l.path)||(l==null?void 0:l.relativePath)||"",S=(g==null?void 0:g.name)||(l==null?void 0:l.name)||y.split("/").pop()||"";return!!(y&&o.has(Xe(y).toLowerCase())||S&&o.has(`name:${S.toLowerCase()}`))},p=l=>c(l);return Ke.forEach(l=>{l.contentLength!=null&&l.contentLength<1||l.isEmpty||l.size!=null&&l.size<10||typeof l.content=="string"&&l.content.trim().length<10||l.fileName&&/-deliverable-\d+\.md$/i.test(l.fileName)||l.fileName&&/_b64\.|\.b64\.|base64|publish\.sh/i.test(l.fileName)||(s.push({type:"delivery",id:l.id,name:l.fileName,author:l.authorName,createdAt:l.createdAt,delivery:l}),r({name:l.fileName}))}),(Array.isArray(t.executionSteps)&&t.executionSteps.length>0?t.executionSteps:qt).forEach((l,g)=>{var y;if(((y=l.filesWritten)==null?void 0:y.length)>0){const S=l.assigneeId?v.find(A=>A.id===l.assigneeId):null;
52l.filesWritten.forEach(A=>{var x;const C=typeof A=="string"?A:(A==null?void 0:A.path)||(A==null?void 0:A.name)||"";if(!C)return;const P=typeof A=="object"&&(A==null?void 0:A.name)||C.split("/").pop(),F=p({path:C,name:P,ext:typeof A=="object"&&(A==null?void 0:A.ext)||void 0});F&&(i(F)||(r(F),s.push({type:"workspace",name:F.name,path:F.path,ext:F.ext||((x=P.match(/\.(\w+)$/))==null?void 0:x[1])||"",author:(S==null?void 0:S.name)||l.assigneeName||l.assignee||"Agent",createdAt:l.completedAt||l.updatedAt,stepIndex:g})))})}}),se.forEach(l=>{var y,S,A;const g=xi([...Array.isArray(l.writtenFiles)?l.writtenFiles:[],...fu(l.toolEvents||[])],z,H);if(g.length>0&&g.forEach(C=>{i(C)||(r(C),s.push({type:"workspace",name:C.name,path:C.path,ext:C.ext,author:l.authorName,createdAt:l.createdAt}))}),l.fileRef){const C=p(l.fileRef);C&&!i(C)&&(r(C),s.push({type:"fileRef",name:C.name,ext:C.ext||l.fileRef.ext,content:l.fileRef.content,path:C.path,author:l.authorName,createdAt:l.createdAt}))}if((y=l.artifactRef)!=null&&y.path||(S=l.artifactRef)!=null&&S.title){const C=l.artifactRef,P=C.title||((A=C.path)==null?void 0:A.split("/").pop())||"Artifact",F=C.path||"",x=F?p({path:F,name:P}):{path:"",name:P};x&&!i(x)&&(r(x),s.push({type:"artifactRef",name:x.name||P,path:x.path||F,content:C.code,ext:oe(x.path||F||P)||C.lang||C.type||"md",author:l.authorName,createdAt:l.createdAt,artifactRef:F?{...C,path:x.path||F}:C}))}}),se.forEach(l=>{l.content&&Da(l.content).filter(g=>g.type==="file").forEach(g=>{i({name:g.name})||(r({name:g.name}),s.push({type:"file",name:g.name,content:g.value,author:l.authorName,createdAt:l.createdAt}))})}),z.forEach(l=>{var S;const g=p(l);if(!g||i(g))return;r(g);const y=((S=g.name.match(/\.(\w+)$/))==null?void 0:S[1])||"";
52s.push({type:"workspace",name:g.name,path:g.path||l.path,ext:y,author:"Team",createdAt:l.modified,projectFolder:l.projectFolder,fromBridge:!0,relativePath:l.relativePath})}),ee.filter(l=>{var g,y;return l.event==="file_written"&&(((g=l.data)==null?void 0:g.path)||((y=l.data)==null?void 0:y.name))}).forEach(l=>{var S,A,C,P,F,x,M;const g=((S=l.data)==null?void 0:S.name)||((C=(A=l.data)==null?void 0:A.path)==null?void 0:C.split("/").pop()),y=p({path:(P=l.data)==null?void 0:P.path,name:g});!y||i(y)||(r(y),s.push({type:"live",name:y.name,path:y.path,ext:((F=l.data)==null?void 0:F.ext)||y.ext||((x=g.match(/\.(\w+)$/))==null?void 0:x[1])||"",author:((M=l.data)==null?void 0:M.agentName)||"Agent",createdAt:l.time||Date.now(),live:!0}))}),s.filter(l=>!za(l))},[Gr,Ke,qt,v,se,z,ee,t.executionSteps,H]),ks=f.useMemo(()=>{var i,p,u;const s=[],o=new Set,c=(l,g,y,S=null)=>{if(!(l!=null&&l.trim()))return;const A=l.trim().slice(0,200);if(o.has(A))return;o.add(A);const C=typeof(S==null?void 0:S.before)=="string"?S.before:void 0,P=typeof(S==null?void 0:S.after)=="string"?S.after:void 0;s.push({diffText:l.trim(),path:g,timestamp:y,before:C,after:P,taskId:(S==null?void 0:S.taskId)||(t==null?void 0:t.id)||null,runId:(S==null?void 0:S.runId)||null,agentName:(S==null?void 0:S.agentName)||null})};for(const l of se){if((p=(i=l.diffRef)==null?void 0:i.files)!=null&&p.length)for(const S of l.diffRef.files)!(S!=null&&S.path)||S.before==null||S.after==null||String(S.before)!==String(S.after)&&c(vi(S.path,S.before,S.after),S.path,l.createdAt,{before:String(S.before),after:String(S.after)});if(l.diffArtifact){const S=l.diffArtifact.diff||l.diffArtifact.patch||"";S&&c(S,l.diffArtifact.title||"",l.createdAt)}const g=l.content||"";if(g)for(const S of Da(g))S.type==="diff"&&S.value&&c(S.value,"",l.createdAt);const y=l.rawContent||l.content||"";if(y){const S=Mc(y);if(Array.isArray(S))for(const A of S){if(!A||typeof A!="object")continue;const C=Ga({tool:A.tool||"",params:A.params||{},result:A.result??null,raw:typeof A.summary=="string"?A.summary:"",summary:typeof A.summary=="string"?A.summary:""});C!=null&&C.diffText&&c(C.diffText,C.path,l.createdAt,C)}}if(l.toolEvents)for(const S of l.toolEvents)Ua(S,l.createdAt,c)}for(const l of ee)Ua(l,l.time,c);const r=Xd(Ys);for(const l of r.files){const g=l.updatedAt||0;l.before!=null&&l.after!=null&&String(l.before)!==String(l.after)?c(vi(l.path,l.before,l.after),l.path,g,{before:String(l.before),after:String(l.after),runId:l.runId||null,agentName:l.agentName||null,taskId:l.taskId||null}):(u=l.patch)!=null&&u.trim()&&c(l.patch.trim(),l.path,g)}return s.sort((l,g)=>(l.timestamp||0)-(g.timestamp||0))},[ic,se,ee,Ys,t==null?void 0:t.id]),mc=f.useMemo(()=>au(ks),[ks]),Yr=f.useMemo(()=>{let s=0,o=0;for(const c of ks)for(const r of c.diffText.split(` 53`))r.startsWith("+")&&!r.startsWith("+++")&&s++,r.startsWith("-")&&!r.startsWith("---")&&o++;return{additions:s,deletions:o,count:ks.length}},[ks]),Xr=f.useMemo(()=>{const s=[],o=(r,i,p,u)=>{const l=wu(r),g=typeof r.raw=="string"?r.raw:"",y=typeof r.summary=="string"?r.summary:"";if(!l&&!g&&!y)return;const S={...typeof r.params=="object"&&r.params?r.params:{},...typeof r.args=="object"&&r.args?r.args:{}};s.push({command:l||y.slice(0,200),cwd:S.cwd??S.workdir??S.working_directory??"",raw:g||y,success:r.success,timestamp:i.time??p,isLive:!!u})},c=(r,i,p,u)=>{if(Array.isArray(r.events)&&r.events.length>0){for(const l of r.events)if(!(!l||typeof l!="object"))if(l.event!=null&&l.data!=null){const g=l.data||{};An(g)&&o(g,l,p,l.event==="tool_start"),c(g,l,p,l.event==="tool_start")}else An(l)&&o(l,i,p,u)}};for(const r of se)if(r.toolEvents)for(const i of r.toolEvents){const p=i.data||{};An(p)&&o(p,i,r.createdAt,!1),c(p,i,r.createdAt,!1)}for(const r of ee){const i=r.data||{};An(i)&&o(i,r,null,r.event==="tool_start"),c(i,r,r.time,r.event==="tool_start")}return s.sort((r,i)=>(r.timestamp||0)-(i.timestamp||0))},[Cs,se,ee]),Qr=f.useMemo(()=>{const s=[];for(const o of se){if(!Array.isArray(o.toolEvents))continue;const c=o.createdAt??o.timestamp??Date.now();
53for(const r of o.toolEvents)s.push({...r,time:r.time??c})}return s},[Cs,se]),Zr=f.useMemo(()=>ri([Qr,ee,Ys]),[Cs,Qr,ee,Ys]),Is=f.useMemo(()=>Ra(Zr,{agentName:(Y==null?void 0:Y.name)||"Agent",isLive:te}),[Cs,Zr,Y==null?void 0:Y.name,te]),wa=f.useMemo(()=>xd(Is),[Cs,Is]),eo=wa.length>0?wa.length:Xr.length,Ge=f.useMemo(()=>{const s=[],o=new Set,c=new Set(["AGENTS.md","BOOTSTRAP.md","COMPANY.md","HEARTBEAT.md","IDENTITY.md","MEMORY.md","MEMORIES.md","SOUL.md","TOOLS.md","USER.md","CAPABILITIES.md"]),r=i=>{const p=_n(i),u=dt(i);if(c.has(u)||/_b64\.|\.b64\.|base64|publish\.sh|BLOCKED\.md/i.test(u))return;if(i.type==="delivery"&&i.delivery){const g=i.delivery;if(g.isEmpty||g.contentLength!=null&&g.contentLength<1||g.size!=null&&g.size<10||typeof g.content=="string"&&g.content.trim().length<10)return}const l=Xe(p||u).toLowerCase();!l||o.has(l)||(o.add(l),s.push(i))};return z.forEach(i=>r({...i,type:"workspace"})),Ur.forEach(i=>r(i)),s},[Gr,z,Ur]),gn=f.useMemo(()=>new Set(ur),[ur]),uc=f.useMemo(()=>{const s=new Map,o=p=>Ta(p),c=p=>{var x,M;if(!p||typeof p!="object")return;const u=o(p);if(!u||gn.has(u))return;const l=Ai(p),g=Li(p,H)||p.path||"",y=_a(g,Ct)||_a(p.path,Ct),S=p.code!=null?String(p.code):"",A=(S.trim()?S:"")||y||"",C={...p,type:l||p.type||"txt",lang:l||p.lang||"txt",code:A,path:g||p.path},P=s.get(u);if(!P){s.set(u,C);return}const F=(((x=C.code)==null?void 0:x.length)||0)>=(((M=P.code)==null?void 0:M.length)||0)?C.code:P.code;s.set(u,{...P,...C,code:F||C.code||P.code})};for(const p of Be)c(p);for(const p of Ge){const u=dt(p),l=La(p,z,H),g=Ye(p),y=typeof p.content=="string"?p.content:"",S=_a(l,Ct);c({id:l||u,title:u,path:l||void 0,code:y||S||"",type:g,lang:g})}const r=[],i=new Set;for(const p of Be){const u=o(p);if(!u||i.has(u)||gn.has(u))continue;i.add(u);const l=s.get(u);l&&r.push(l)}for(const p of Ge){const u=dt(p),l=La(p,z,H),y=o({id:l||u,title:u,path:l||void 0});if(!y||i.has(y)||gn.has(y))continue;i.add(y);const S=s.get(y);S&&r.push(S)}return r},[Be,Ge,Ct,z,H,gn]),bn=f.useMemo(()=>new Set(["md","txt","json","csv","tsv","html","htm","css","js","mjs","jsx","tsx","ts","py","yml","yaml","sh","sql","xml","svg","log"]),[]),vn=f.useMemo(()=>{const s=new Set;for(const c of z){const r=Ye(c);bn.has(r)&&c.path&&String(c.path).startsWith("/")&&s.add(c.path)}for(const c of Ge){const r=La(c,z,H);if(!r||!r.startsWith("/"))continue;const i=Ye(c);!bn.has(i)||typeof c.content=="string"&&c.content.trim().length>0||s.add(r)}for(const c of Be){const r=Li(c,H)||c.path;if(!r||!String(r).startsWith("/"))continue;const i=Ai(c);!bn.has(i)||typeof c.code=="string"&&c.code.trim().length>0||s.add(String(r))}const o=[...s].sort().slice(0,96);return{paths:o,pathsKey:o.join("\0")}},[z,Ge,Be,H,bn]);f.useEffect(()=>{const s=Ge.length,o=!!(H&&z.length>0);if(s===0&&!o){Kt.current=0;return}const c=s>Kt.current,r=Kt.current===0&&(s>0||o);if(Wt.current&&!c){Kt.current=s;return}if((c||r)&&(c&&(Wt.current=!1),Ne(!1),it(!0),!Qt&&(De("files"),!I&&!Oe&&s>0))){const i=ju(Ge);i&&setTimeout(()=>qr(i),0)}Kt.current=s},[Ge,z.length,H,I,Oe,Qt]);const pc=f.useMemo(()=>{const s=$a(I);if(!s)return null;const o=Array.isArray(s)?s[0]:s;return Ta(o)||bt(o,0)},[I]),to=!Jn&&!!(I||Oe||Ge.length>0||H&&z.length>0||pe==="diffs"||pe==="activity"||pe==="browser"||Xt.some(s=>["browser_live","screenshot","image","deliverable"].includes(s.type))||pe==="files"&&gl||zt),ja=f.useRef(!1);Jn?ja.current=!1:to&&(ja.current=!0);const Se=to||!Jn&&ja.current,fc=f.useMemo(()=>!(w!=null&&w.orgId)||!(zt||Se)?"":vn.paths.filter(c=>Ct[c]==null).join("\0"),[w==null?void 0:w.orgId,zt,Se,vn.pathsKey,Ct]);f.useEffect(()=>{if(!(w!=null&&w.orgId)||!zt&&!Se)return;const s=vn.paths.filter(i=>Ct[i]==null);if(s.length===0)return;let o=!1;const c=w.orgId,r=5;return(async()=>{for(let i=0;i<s.length;i+=r){if(o)return;const p=s.slice(i,i+r),u={};if(await Promise.all(p.map(async l=>{try{const g=await kn(l,{orgId:c,signal:AbortSignal.timeout(25e3)});if(!g.ok)return;const y=await g.text();u[l]=y}catch{}})),o)return;Object.keys(u).length!==0&&mr(l=>{let g=l,y=!1;for(const[S,A]of Object.entries(u))l[S]==null&&(y||(g={...l},y=!0),g[S]=A);return y?g:l})}})(),()=>{o=!0}},[w==null?void 0:w.orgId,zt,Se,vn.pathsKey,fc]);const hc=!!t.assigneeId&&t.status!=="inbox",xc=e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:Ar,type:"file",multiple:!0,className:"hidden",onChange:Jl}),e.jsx(nm,{onAttach:()=>{var s;return(s=Ar.current)==null?void 0:s.click()},orgId:(a==null?void 0:a.id)||"",getIdToken:m,planMode:On,onTogglePlanMode:()=>q.setState(s=>({planMode:!s.planMode,executeMode:s.planMode?s.executeMode:!1})),executeMode:Dn,onToggleExecuteMode:()=>q.setState(s=>({executeMode:!s.executeMode,planMode:s.executeMode?s.planMode:!1})),executionMode:q.getState().executionMode,onSetExecutionMode:s=>{var o,c;return(c=(o=q.getState()).setExecutionMode)==null?void 0:c.call(o,s)},devices:Qe,selectedDeviceMode:ol,selectedDeviceId:il,onSelectDevice:(s,o)=>zn==null?void 0:zn({mode:s,deviceId:o}),onManageDevices:()=>window.dispatchEvent(new CustomEvent("navigate-page",{detail:"devices"})),skills:Pe,onOpenSkills:()=>window.dispatchEvent(new CustomEvent("navigate-page",{detail:"skills"})),onOpenConnections:()=>window.dispatchEvent(new CustomEvent("navigate-page",{detail:"connections"})),triggerClassName:"h-7 w-7 border-neutral-200 bg-white text-neutral-500 hover:bg-neutral-50 hover:text-neutral-800"}),w?e.jsx(Vd,{compact:!0,activeSession:ge,preference:os,onSelect:dl}):null]}),ya=wi({planMode:On,executeMode:Dn}),gc=!!(w||Jt),bc=e.jsx(am,{modeChip:ya?e.jsx(om,{mode:ya,onExit:()=>{ya==="plan"?q.setState({planMode:!1}):q.setState({executeMode:!1})}}
53):null,showControls:gc,orgId:(a==null?void 0:a.id)||"",getIdToken:m,layoutRef:_r,mic:{enabled:ls&&ce.state==="idle",disabled:!w||!Mt,onStart:()=>ce.startRecording()},extras:hc?e.jsx(rm,{icon:Wa,label:"Reset task",onClick:()=>us(!0)}):null,primary:{state:$l?sr?"uploading":"send":te?"stop":gt(t.status)==="in_progress"?"pause":t.status==="paused"?"resume":"disabled",sendLabel:te?"Add to queue":"Send message",onSend:xa,onPause:Ml,onResume:Ol,onStop:()=>{var s;return G({agentId:((s=da[0])==null?void 0:s[0])||(ae==null?void 0:ae.agentId)||null,taskId:t.id,runId:Gt||(ae==null?void 0:ae.runId)||null,sessionKey:Le||(ae==null?void 0:ae.sessionKey)||null})}}}),vc=f.useCallback(s=>{if(Ne(!1),De(s),s==="files"){it(!0);return}ve(null),yt(null),at(null)},[]),wc=f.useMemo(()=>({diffs:{badge:Yr.count},activity:{badge:eo},browser:{indicator:Qt}}),[Yr.count,eo,Qt]),so=f.useMemo(()=>{const s=(I==null?void 0:I.fileRef)||(I==null?void 0:I.artifactRef)||null;if(!s)return null;const o=s.name||s.title||(typeof s.path=="string"?s.path.split("/").filter(Boolean).pop():"")||"File",c=String(s.ext||s.lang||s.type||oe(o)||"txt").toLowerCase();return{name:o,path:s.path,ext:c,content:String(s.content??s.code??"")}},[I]),jc=Oe?pl?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(Zt,{size:20})}):e.jsx(Aa,{orgId:w==null?void 0:w.orgId,file:{name:Oe.fileName,content:ul||"",ext:Ei(Oe.fileName).toLowerCase()},canvasEnabled:Be.length>=1,onOpenCanvas:()=>{Fe(!0),Ne(!1)}}):so?e.jsx(Aa,{orgId:w==null?void 0:w.orgId,file:so,canvasEnabled:Be.length>=1,onOpenCanvas:()=>{Fe(!0),Ne(!1)},onClose:()=>{var o,c;ve(null);const s=String(((o=t==null?void 0:t.planReview)==null?void 0:o.markdown)||"").trim();s&&(String((t==null?void 0:t.executionPhase)||"").toLowerCase()==="plan_review"||String(((c=t==null?void 0:t.planReview)==null?void 0:c.status)||"").toLowerCase()==="pending"||String((t==null?void 0:t.executionPhase)||"").toLowerCase()==="planning")&&ve({fileRef:{name:"PLAN.md",ext:"md",content:s}})}}):null,yc=f.useMemo(()=>{const s=Xt.find(r=>r.type==="screenshot"),o=Xt.find(r=>r.type==="image"),c=Xt.find(r=>r.type==="deliverable");if(s){const r=String(s.base64||"").trim();if(!(r&&r.length>32&&!/^\[(?:omitted|trimmed)\s+\d+\s+chars\]/i.test(r)))return null;const p=r.startsWith("/9j/")?"image/jpeg":"image/png";return e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-auto bg-stone-50/40 p-3",children:e.jsx("img",{src:`data:${p};base64,${r}`,alt:"Screenshot",className:"max-h-full max-w-full rounded-lg object-contain shadow-sm"})})}return o?e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-auto bg-stone-50/40 p-3",children:e.jsx("img",{src:o.src,alt:"Output",className:"max-h-full max-w-full rounded-lg object-contain shadow-sm"})}):c?e.jsx(Aa,{orgId:w==null?void 0:w.orgId,file:{name:c.name||"Deliverable",content:c.content||"",ext:c.ext||""},canvasEnabled:Be.length>=1,onOpenCanvas:()=>{Fe(!0),Ne(!1)}}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-stone-100",children:e.jsx(mt,{className:"h-5 w-5 text-neutral-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-neutral-700",children:"No files yet"}),e.jsx("p",{className:"mt-1 max-w-[240px] text-xs text-neutral-500",children:"Files and previews will appear here as the task progresses."})]})]}),ca.length>0?e.jsxs("div",{className:"border-t border-neutral-100 px-5 py-4",children:[e.jsx("h4",{className:"mb-2 text-[10px] font-semibold uppercase tracking-wider text-neutral-500",children:"History"}),e.jsx("div",{className:"space-y-1.5",children:ca.slice().reverse().slice(0,6).map((r,i)=>{var p;return e.jsxs("div",{className:"flex items-center gap-2 text-xs text-neutral-500",children:[e.jsx("span",{className:"h-1 w-1 shrink-0 rounded-full bg-stone-300"}),e.jsxs("span",{children:[r.action==="created"&&"Created",r.action==="moved"&&`â ${(p=r.to)==null?void 0:p.replace(/_/g," ")}`,r.action==="assigned"&&`Assigned to ${r.to}`,r.at&&e.jsx("span",{className:"ml-1 text-neutral-400",children:Ri(new Date(r.at),{addSuffix:!0})})]})]},i)})})]}):null]})},[Xt,ca,w==null?void 0:w.orgId,Be.length]),Nc=pe==="files"?e.jsx("div",{className:"mb-1 flex shrink-0 items-center gap-1",children:Oe?e.jsxs(T,{size:"sm",className:"h-7 text-xs",onClick:s=>{ba(s,`https://app.trooper.so/api/tasks/${t.id}/deliveries/${Oe.id}/download`,Oe.fileName)},children:[e.jsx(Ka,{className:"mr-1 h-3 w-3"})," Download"]}):null}):null;return e.jsxs(qu,{inline:n,onClose:Or,children:[e.jsx("div",{className:V("pointer-events-auto relative flex min-h-0 w-full flex-col items-stretch self-stretch bg-background",n?"h-full rounded-none shadow-none":"rounded-none shadow-2xl sm:rounded-2xl",!n&&Se?"lg:max-w-[min(1650px,98vw)] sm:max-w-[98vw]":n?"":"sm:max-w-[min(98vw,1100px)] lg:max-w-[min(1200px,96vw)]"),children:e.jsx("div",{className:V("relative flex min-h-0 w-full flex-1 flex-col overflow-hidden rounded-none bg-background",n?"border-0":"border border-border sm:rounded-2xl"),children:e.jsxs("div",{className:"task-modal-split flex-1 min-h-0 flex flex-col lg:flex-row",children:[e.jsxs("div",{className:V("relative flex min-h-0 min-w-0 flex-col overflow-hidden",Se&&nt&&"border-r border-border",(!Se||!nt)&&"flex-1"),style:Se&&nt?{width:`calc(${Gs}% - 4px)`,flexShrink:0}:void 0,children:[e.jsx(T,{variant:"ghost",size:"icon",onClick:Or,className:"absolute right-2 top-2 z-20 h-9 w-9 rounded-xl border border-border bg-card text-muted-foreground shadow-sm hover:bg-muted/60 hover:text-foreground sm:right-3 sm:top-3",title:"Close","aria-label":"Close modal",children:e.jsx(En,{className:"w-4 h-4"})}),e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{className:V("pointer-events-none absolute inset-x-0 top-0 z-10 h-10 bg-gradient-to-b from-white via-white/90 to-transparent",jr.top?"opacity-100":"opacity-0")}),e.jsx("div",{className:V("pointer-events-none absolute inset-x-0 bottom-0 z-10 h-14 bg-gradient-to-t from-white via-white/92 to-transparent",jr.bottom?"opacity-100":"opacity-0")}),e.jsxs("div",{ref:bs,onScroll:kl,"data-channel-chat-scroll":!0,className:"size-full min-h-0 flex-1 overflow-y-auto overscroll-contain scrollbar-hide bg-white",children:[e.jsx("div",{className:"relative z-10 scroll-mt-0 border-b border-neutral-100 pb-4 pt-12 sm:pt-14",children:e.jsxs("div",{className:V("mx-auto max-w-[min(100%,42rem)] min-w-0","pl-[max(1.5rem,env(safe-area-inset-left,0px))] pr-[max(1.5rem,env(safe-area-inset-right,0px))]","sm:pl-[max(2rem,env(safe-area-inset-left,0px))] sm:pr-[max(2rem,env(safe-area-inset-right,0px))]","md:pl-[max(2.5rem,env(safe-area-inset-left,0px))] md:pr-[max(2.5rem,env(safe-area-inset-right,0px))]","lg:pl-[max(2rem,env(safe-area-inset-left,0px))] lg:pr-[max(2rem,env(safe-area-inset-right,0px))]"),children:[e.jsxs("div",{className:"mb-2",children:[t.channelId&&(()=>{const s=(J||[]).find(o=>o.id===t.channelId);return s?e.jsxs("p",{className:"text-meta text-quiet mb-1 flex items-center gap-1",children:[Oc(s)?e.jsx(gd,{className:"h-3.5 w-3.5 text-green-500",strokeWidth:1.75,fill:"currentColor",fillOpacity:.2,"aria-hidden":!0}):e.jsx("span",{children:s.channelType==="project"?"ð":s.channelType==="team"?"ð¥":"#"}),e.jsx("span",{className:"font-medium",children:Dc(s)}),s.goal&&e.jsxs("span",{className:"text-neutral-500 opacity-80 ml-1",children:["â ð¯ ",s.goal]})]}):null})(),e.jsx("p",{className:"font-display text-subtitle text-foreground leading-[1.6] font-semibold tracking-tight",children:t.title}),t.description&&t.description!==t.title&&e.jsx("p",{className:"text-dense text-quiet mt-0.5 leading-[1.6] line-clamp-2",children:t.description}),!nt&&Ke.length>0&&["done","review","awaiting_approval"].includes(pt)&&!Oe&&e.jsx("div",{className:"mt-2 lg:hidden",children:e.jsxs(T,{variant:"outline",type:"button",className:"w-full justify-center gap-2 rounded-xl",onClick:()=>hn(Ke[Ke.length-1]),children:[e.jsx(mt,{className:"h-4 w-4 text-green-700"}),"View delivery",e.jsx("span",{className:"truncate text-xs font-normal text-neutral-500",children:Pi(((So=Ke[Ke.length-1])==null?void 0:So.fileName)||"")})]})}),js&&e.jsxs("div",{className:"mt-2 rounded-xl border border-amber-200 bg-amber-50/90 px-3 py-2",children:[e.jsx("p",{className:"text-meta font-semibold uppercase tracking-wider text-amber-700",children:"Device dispatch pending"}),e.jsx("p",{className:"mt-0.5 text-xs text-amber-900/90",children:t.blockedReason||((Co=t.executionDispatch)==null?void 0:Co.reason)||"Queued for future Device delivery."})]}),(ke==null?void 0:ke.waitingForResume)&&e.jsx("div",{className:"mt-2 rounded-xl border border-amber-200 bg-amber-50/90 px-3 py-2",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-meta font-semibold uppercase tracking-wider text-amber-700",children:"Browser needs you"}),e.jsx("p",{className:"mt-0.5 text-xs text-amber-900/90",children:ke.handoffMessage||t.blockedReason||"Complete the blocker in the VM browser, then continue this step."}),(ke.lastUrl||ke.pageUrl)&&e.jsx("p",{className:"mt-1 truncate font-mono text-[11px] text-amber-700",children:ke.lastUrl||ke.pageUrl})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[ke.liveViewUrl&&e.jsxs(T,{variant:"outline",size:"sm",className:"h-8 bg-white",onClick:()=>window.open(ke.liveViewUrl,"_blank","noopener,noreferrer"),children:[e.jsx(bd,{className:"mr-1.5 h-3.5 w-3.5"}),"Open VM browser"]}),e.jsx(T,{size:"sm",className:"h-8",onClick:Kl,children:"Continue"})]})]})}),t.playbook&&e.jsxs("details",{className:"mt-2 rounded-xl border border-neutral-200 bg-stone-50 overflow-hidden",children:[e.jsxs("summary",{className:"px-3 py-2 cursor-pointer text-meta font-semibold text-neutral-500 uppercase tracking-wider select-none hover:bg-stone-100/30",children:["Playbook â ",t.playbook.name]}),e.jsxs("div",{className:"px-3 py-2 border-t border-neutral-200",children:[t.playbook.description&&e.jsx("p",{className:"text-xs text-neutral-500",children:t.playbook.description}),Array.isArray(t.playbook.requiredOutputs)&&t.playbook.requiredOutputs.length>0&&e.jsxs("p",{className:"text-meta text-neutral-500 mt-1",children:["Required outputs: ",t.playbook.requiredOutputs.join(", ")
53]})]})]}),Array.isArray(t.policyWarnings)&&t.policyWarnings.length>0&&e.jsxs("details",{className:"mt-2 rounded-xl border border-amber-200 bg-amber-50/80 overflow-hidden",children:[e.jsxs("summary",{className:"px-3 py-2 cursor-pointer text-meta font-semibold text-amber-700 uppercase tracking-wider select-none hover:bg-amber-100/50",children:[t.policyWarnings.length," policy warning",t.policyWarnings.length>1?"s":""]}),e.jsx("ul",{className:"px-3 py-2 border-t border-amber-200 space-y-1",children:t.policyWarnings.map((s,o)=>e.jsxs("li",{className:"text-xs text-amber-900/90",children:["⢠",s]},o))})]}),Array.isArray(t.memorySuggestions)&&t.memorySuggestions.length>0&&e.jsxs("details",{className:"mt-2 rounded-xl border border-neutral-200 bg-stone-100 overflow-hidden",children:[e.jsxs("summary",{className:"px-3 py-2 cursor-pointer text-meta font-semibold text-neutral-500 uppercase tracking-wider select-none hover:bg-stone-100/30",children:[t.memorySuggestions.length," memory suggestion",t.memorySuggestions.length>1?"s":"",fr&&e.jsx("span",{className:"ml-2 font-normal normal-case",children:fr})]}),e.jsx("div",{className:"px-3 py-2 border-t border-neutral-200 space-y-2",children:t.memorySuggestions.map(s=>e.jsxs("div",{className:"rounded-lg border border-neutral-100 bg-white px-3 py-2",children:[e.jsxs("p",{className:"text-xs font-medium text-neutral-900",children:["[",s.scope,"] ",s.title]}),e.jsx("p",{className:"text-xs text-neutral-500 mt-0.5",children:s.summary}),e.jsx("div",{className:"mt-2 flex items-center gap-2",children:s.status==="suggested"?e.jsxs(e.Fragment,{children:[e.jsx(T,{size:"sm",onClick:()=>vr(s.suggestionId,"accept"),className:"bg-brand text-brand-foreground hover:bg-brand/90",children:"Save"}),e.jsx(T,{variant:"outline",size:"sm",onClick:()=>vr(s.suggestionId,"reject"),className:"border-neutral-200 text-neutral-900 hover:bg-stone-50",children:"Dismiss"})]}):e.jsx("span",{className:"text-meta text-neutral-500 font-medium",children:s.status})})]},s.suggestionId))})]})]}),e.jsx(Fc,{delayDuration:300,children:e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap text-xs",children:[(()=>{const s=pt,o=ci(t),r={done:"Done",in_progress:"In Progress",review:o?"Awaiting user response":"Human review",blocked:js?"Dispatch Pending":"Awaiting user response",waiting_human:"Awaiting user response",awaiting_approval:"Awaiting user response",inbox:"Inbox",assigned:"Assigned"}[s]||(s==null?void 0:s.replace(/_/g," "));return e.jsx(ji,{variant:"secondary",className:V("text-[10px] uppercase tracking-wider py-0",s==="done"&&"bg-green-50 text-green-800 border-green-200/90",s==="in_progress"&&"bg-amber-50 text-amber-600 border-amber-200/80",(s==="review"||o)&&"bg-amber-50/90 text-amber-700 border-amber-200/70",s==="blocked"&&!js&&"bg-amber-50 text-amber-700 border-amber-200/80",s==="blocked"&&js&&"bg-green-50 text-green-600 border-green-200/80",!["done","in_progress","review","blocked","waiting_human","awaiting_approval"].includes(s)&&"bg-stone-50 text-neutral-600 border-neutral-200"),children:r})})(),Y&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ln,{src:Y.avatar,name:Y.name,size:"w-4 h-4 text-xxs",agent:Y}),e.jsx("span",{className:"text-neutral-500",children:Y.name})]}),e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsxs("span",{className:V("inline-flex items-center gap-0.5 text-neutral-500"),children:[At.type==="device"?e.jsx(pi,{className:"w-3 h-3"}):e.jsx(Ii,{className:"w-3 h-3"}),At.type==="device"?At.deviceName||"Device":"Cloud"]}),fa>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsxs("span",{className:"text-neutral-500",children:[Bl,"/",fa," steps"]})]}),(()=>{const s=t.subtasks||t.executionSteps||[],o=s.reduce((p,u)=>{var l;return p+(((l=u.metrics)==null?void 0:l.inputTokens)||0)},0),c=s.reduce((p,u)=>{var l;return p+(((l=u.metrics)==null?void 0:l.outputTokens)||0)},0),r=o+c;if(r===0)return null;const i=p=>p>=1e3?(p/1e3).toFixed(1)+"k":String(p);return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsxs(Bc,{children:[e.jsx(zc,{asChild:!0,children:e.jsxs("span",{className:"text-neutral-500 cursor-default",children:[i(r)," tokens"]})}),e.jsxs(Wc,{children:["Input: ",i(o)," · Output: ",i(c)]})]})]})})(),e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsx("span",{className:"text-neutral-500",children:Ri(new Date(t.createdAt),{addSuffix:!0})}),br&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsx("span",{className:"text-muted-foreground font-medium",children:br.name})]}),gr&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsx("span",{className:"text-muted-foreground font-medium",children:gr.title})]}),Qn>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-neutral-500 opacity-40",children:"·"}),e.jsxs("span",{className:"text-neutral-500",children:[Qn," output",Qn===1?"":"s"]})]})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2 border-t border-border/70 pt-4",children:[ci(t)&&!js&&e.jsxs("div",{className:"mb-1 w-full rounded-lg border border-amber-200/80 bg-amber-50/80 px-3 py-2 text-xs text-amber-900",children:[e.jsx("p",{className:"font-semibold",children:"Awaiting user response"}),e.jsx("p",{className:"mt-0.5 text-amber-800/90",children:t.blockedReason||"Agents paused â reply in this task or approve to continue collaboration."})]}),(pt==="review"||pt==="blocked"&&t.blockedType==="review")&&e.jsxs(e.Fragment,{children:[e.jsxs(T,{size:"sm",onClick:()=>{pt==="blocked"&&t.blockedType==="review"?$(t.id,"approved"):(Br("done"),R(t.id,{authorName:(w==null?void 0:w.name)||"You",authorId:(w==null?void 0:w.id)||null,content:"â
Approved"}))},className:"h-9 gap-1.5 rounded-lg bg-brand px-4 text-brand-foreground shadow-sm hover:bg-brand/90",children:[e.jsx(Tn,{className:"w-3.5 h-3.5"})," Approve"]}),e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>nn(!0),className:"h-9 gap-1.5 rounded-lg border-border text-foreground hover:bg-muted/50 flex items-center px-4",children:[e.jsx(ts,{className:"w-3.5 h-3.5"})," Reject"]})]}),["inbox","assigned"].includes(pt)&&e.jsx(T,{type:"button",size:"sm",disabled:Xs,onClick:ql,className:"h-9 gap-1.5 rounded-lg bg-brand px-4 text-brand-foreground shadow-sm hover:bg-brand/90 disabled:opacity-60",children:Xs?e.jsxs(e.Fragment,{children:[e.jsx(Zt,{size:12})," Startingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(el,{className:"w-3.5 h-3.5"})," Start work"]})}),e.jsxs(T,{type:"button",variant:"outline",size:"sm",onClick:()=>zr("routine"),className:"h-9 gap-1.5 rounded-lg border-border bg-white px-3 text-foreground shadow-sm hover:bg-muted/50",children:[e.jsx(Wa,{className:"h-3.5 w-3.5"})," Routine"]}),e.jsxs(T,{type:"button",variant:"outline",size:"sm",onClick:()=>zr("workflow"),className:"h-9 gap-1.5 rounded-lg border-border bg-white px-3 text-foreground shadow-sm hover:bg-muted/50",children:[e.jsx(Ts,{className:"h-3.5 w-3.5"})," Workflow"]}),e.jsxs(wd,{children:[e.jsx(jd,{asChild:!0,children:e.jsx(T,{variant:"outline",size:"icon",className:"h-9 w-9 rounded-lg text-muted-foreground border-border",title:"More actions",children:e.jsx(Hm,{className:"w-4 h-4"})})}),e.jsxs(yd,{align:"end",collisionPadding:16,className:"min-w-[200px] max-w-[min(20rem,calc(100vw-1.5rem))]",children:[!Y&&!["review","done","inbox","assigned"].includes(pt)&&e.jsxs(fi,{onClick:async()=>{try{const s=await je(t.id);
53s.task&&s.assignedTo&&Hl(s.assignedTo.id)}catch(s){console.error(s)}},children:[e.jsx(tl,{className:"w-4 h-4 mr-2"}),"Auto-Assign"]}),e.jsxs(fi,{onClick:()=>qs(!0),className:"text-green-600 focus:text-green-600 focus:bg-green-50",children:[e.jsx(Zi,{className:"w-4 h-4 mr-2"}),"Delete task"]})]})]})]}),xr&&e.jsx("p",{className:"mt-2 text-sm text-destructive",role:"alert",children:xr}),ra&&e.jsxs("div",{className:"mt-3 p-3 border border-neutral-200 rounded-xl",children:[e.jsx("label",{className:"block text-xs font-medium text-neutral-900 mb-1.5",children:"What needs to change?"}),e.jsx("textarea",{value:Cr,onChange:s=>an(s.target.value),placeholder:"Describe what needs improvement...",rows:3,className:"w-full px-3 py-2 text-sm rounded-lg border border-neutral-200 bg-white outline-none focus:ring-2 focus:ring-stone-300/40 resize-none",autoFocus:!0}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(T,{size:"sm",variant:"destructive",onClick:()=>{Br("in_progress"),R(t.id,{authorName:(w==null?void 0:w.name)||"You",authorId:(w==null?void 0:w.id)||null,content:`â Needs revision: ${Cr.trim()||"No feedback provided"}`}),nn(!1),an("")},children:"Submit"}),e.jsx(T,{size:"sm",variant:"outline",onClick:()=>{nn(!1),an("")},children:"Cancel"})]})]}),Wn&&e.jsxs("div",{className:"mt-3 p-3 bg-green-50 border border-green-200/40 rounded-xl",children:[e.jsx("p",{className:"text-sm text-green-800 font-medium",children:"Delete this task?"}),e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"This will permanently remove all comments, deliveries, and subtasks."}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(T,{size:"sm",variant:"destructive",onClick:async()=>{Sn(),await E(t.id),qs(!1),j(null)},children:"Delete"}),e.jsx(T,{size:"sm",variant:"outline",onClick:()=>qs(!1),children:"Cancel"})]})]})]})}),e.jsx("div",{className:V("mx-auto flex max-w-[min(100%,42rem)] min-w-0 flex-col","pl-[max(1.5rem,env(safe-area-inset-left,0px))] pr-[max(1.5rem,env(safe-area-inset-right,0px))]","sm:pl-[max(2rem,env(safe-area-inset-left,0px))] sm:pr-[max(2rem,env(safe-area-inset-right,0px))]","md:pl-[max(2.5rem,env(safe-area-inset-left,0px))] md:pr-[max(2.5rem,env(safe-area-inset-right,0px))]","lg:pl-[max(2rem,env(safe-area-inset-left,0px))] lg:pr-[max(2rem,env(safe-area-inset-right,0px))]"),children:e.jsxs("div",{className:"flex w-full flex-col pt-4 pb-4",children:[t.blockedByDeps&&e.jsxs("div",{className:"mb-4 p-4 bg-stone-50 border border-stone-200/40 rounded-xl flex items-center gap-3",children:[e.jsx(qm,{className:"w-4 h-4 text-stone-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-stone-700",children:"Blocked by dependencies"}),e.jsx("p",{className:"text-xs text-stone-500 mt-0.5",children:(t.dependsOn||[]).map(s=>{const o=_.find(c=>c.id===s);return o?`"${o.title}"`:s.substring(0,8)}).join(", ")})]})]}),t.approvalStatus==="pending"&&e.jsxs("div",{className:"mb-4 p-4 bg-amber-50 border border-amber-200/40 rounded-xl flex flex-wrap items-center gap-3 min-w-0",children:[e.jsx(Nd,{className:"w-4 h-4 text-amber-600 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm font-medium text-amber-800",children:"Awaiting approval"})}),e.jsxs("div",{className:"flex gap-1.5 flex-shrink-0 flex-wrap",children:[e.jsx(T,{size:"sm",className:"bg-brand text-brand-foreground hover:bg-brand/90",onClick:()=>$(t.id,"approved"),children:"Approve"}),e.jsx(T,{size:"sm",variant:"outline",className:"text-green-600 border-green-200/40 hover:bg-green-50",onClick:()=>$(t.id,"denied"),children:"Deny"})]})]}),(Qs==null?void 0:Qs.hasContent)&&e.jsxs(e.Fragment,{children:[e.jsx(Tm,{view:Qs,className:"mb-4",onSelectTask:Zn,onApproveTask:s=>$(s,"approved"),onDenyTask:s=>$(s,"denied")}),(Zs==null?void 0:Zs.hasContent)&&e.jsx(Lm,{detail:Zs,className:"mb-4",onSelectTask:Zn,onApproveTask:s=>$(s,"approved"),onDenyTask:s=>$(s,"denied")}),(en==null?void 0:en.hasContent)&&e.jsx($m,{view:en,className:"mb-4",onSelectTask:Zn})]}),t.acpSessions&&t.acpSessions.length>0&&e.jsxs("div",{className:"mb-4 p-4 bg-stone-50 border border-neutral-200 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-sm",children:"ð¤"}),e.jsx("p",{className:"text-xs font-medium text-neutral-500",children:"ACP Agent Sessions"})]}),e.jsx("div",{className:"space-y-1",children:t.acpSessions.map(s=>{var o;return e.jsxs("div",{className:"flex items-center gap-2 text-meta",children:[e.jsx("span",{className:V("w-1.5 h-1.5 rounded-full",s.status==="running"?"bg-green-700":s.status==="cancelled"?"bg-red-400":"bg-stone-400")}),e.jsx("span",{className:"font-medium text-neutral-700 capitalize",children:s.agent}),e.jsxs("span",{className:"text-neutral-600",children:[(o=s.sessionId)==null?void 0:o.substring(0,8),"..."]}),e.jsx("span",{className:V("px-1.5 py-0.5 rounded-full text-xxs",s.status==="running"?"bg-green-50 text-green-800 border border-green-200/80":"bg-stone-100 text-neutral-600"),children:s.status})]},s.sessionId)})})]}),t.pipeline&&e.jsxs("div",{className:"mb-4 p-4 bg-stone-100 border border-neutral-200 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-sm",children:"ð"}),e.jsx("p",{className:"text-xs font-medium text-neutral-900",children:"Pipeline Progress"})]}),e.jsx("div",{className:"flex items-center gap-1 flex-wrap mb-2",children:(ko=t.pipeline.phases)==null?void 0:ko.map((s,o)=>{const c=(t.subtasks||[]).filter(g=>g.phase===s),r=c.filter(g=>g.status==="completed").length,i=c.filter(g=>g.status==="failed").length,p=s===t.pipeline.currentPhase,u=c.length>0&&r===c.length,l=i>0;return e.jsxs("span",{className:"flex items-center gap-1",children:[o>0&&e.jsx("span",{className:"text-neutral-500 text-xs",children:"â"}),e.jsxs("span",{className:V("px-2 py-0.5 text-xxs rounded-full capitalize",u?"bg-green-50 text-green-800 border border-green-200/70":l?"bg-green-100 text-green-700":p?"bg-amber-50 text-amber-600 border border-amber-200/70 font-medium":"bg-stone-50 text-neutral-500 border border-neutral-200"),children:[s,c.length>0?` (${r}/${c.length})`:""]})]},s)})}),t.pipeline.status==="completed"&&e.jsx("p",{className:"text-xxs text-green-800 font-medium",children:"â
Pipeline complete"})]}),(String(t.executionPhase||"").toLowerCase()==="plan_review"||String(((Io=t.planReview)==null?void 0:Io.status)||"").toLowerCase()==="pending")&&(t.executionSteps||[]).length>0&&e.jsxs("div",{className:"mb-4 rounded-2xl border border-brand/25 bg-brand/[0.04] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-neutral-900",children:"Proposed plan"}),(((Ro=t.planReview)==null?void 0:Ro.fallback)||t.planFallback==="deterministic")&&e.jsx("span",{className:"rounded-full bg-amber-100 px-2 py-0.5 text-[11px] font-medium text-amber-800",title:"The AI planner was unreachable, so this is a generic template plan. Revise once the gateway is back for a tailored plan.",children:"Fallback plan â planner unreachable"})]}),e.jsx("p",{className:"mt-0.5 text-xs text-neutral-500",children:xn?"Review the checklist below â nothing runs until you approve.":"Review the steps â nothing runs until you approve."}),e.jsx("ol",{className:"mt-3 space-y-1.5",children:(t.executionSteps||[]).map((s,o)=>e.jsxs("li",{className:"flex items-start gap-2 text-[13px] text-neutral-800",children:[e.jsxs("span",{className:"mt-px shrink-0 tabular-nums text-neutral-400",children:[o+1,"."]}
53),e.jsxs("span",{className:"min-w-0",children:[s.title,s.assigneeName?e.jsxs("span",{className:"text-neutral-400",children:[" â ",s.assigneeName]}):null]})]},s.id||o))}),xn?(Po=t.planReview)!=null&&Po.markdown?e.jsx(T,{size:"sm",variant:"ghost",className:"mt-3 h-7 text-xs text-neutral-500",onClick:()=>fn({type:"markdown",title:`Plan â ${t.title||"Task"}`,name:"PLAN.md",code:t.planReview.markdown}),children:"View full plan"}):null:yr?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("textarea",{value:Vt,onChange:s=>na(s.target.value),placeholder:"What should change about this plan?",className:"min-h-[64px] w-full rounded-xl border border-neutral-200 bg-white px-3 py-2 text-[13px] outline-none focus:border-neutral-400"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{size:"sm",className:"h-7 text-xs",disabled:ht||!Vt.trim(),onClick:()=>Ut("revise",Vt.trim()),children:"Send revision"}),e.jsx(T,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>fs(!1),children:"Cancel"})]})]}):e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(T,{size:"sm",className:"h-7 bg-brand text-xs text-brand-foreground hover:bg-brand/90",disabled:ht,onClick:()=>Ut("approve"),children:"Approve & start"}),e.jsx(T,{size:"sm",variant:"outline",className:"h-7 text-xs",disabled:ht,onClick:()=>fs(!0),children:"Revise"}),e.jsx(T,{size:"sm",variant:"ghost",className:"h-7 text-xs text-neutral-500",disabled:ht,onClick:()=>Ut("reject"),children:"Reject"}),(Ao=t.planReview)!=null&&Ao.markdown?e.jsx(T,{size:"sm",variant:"ghost",className:"h-7 text-xs text-neutral-500",onClick:()=>fn({type:"markdown",title:`Plan â ${t.title||"Task"}`,name:"PLAN.md",code:t.planReview.markdown}),children:"View full plan"}):null]}),sn&&!xn?e.jsx("p",{className:"mt-2 text-xs font-medium text-red-600",children:sn}):null]}),t.status==="pipeline_paused"&&((Eo=t.pipelineCheckpoints)==null?void 0:Eo.some(s=>s.status==="pending"))&&e.jsxs("div",{className:"mb-4 p-4 bg-amber-50 border border-amber-200/40 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(qa,{className:"w-4 h-4 text-amber-600 flex-shrink-0"}),e.jsx("p",{className:"text-sm font-medium text-amber-800",children:"Pipeline paused â checkpoint requires approval"})]}),t.pipelineCheckpoints.filter(s=>s.status==="pending").map(s=>e.jsx("p",{className:"text-xs text-amber-700 mb-3",children:s.message},s.id)),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(T,{size:"sm",className:"bg-brand text-brand-foreground hover:bg-brand/90",onClick:async()=>{try{await fetch(`https://app.trooper.so/api/tasks/${t.id}/pipeline/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:"approved",resumedBy:"user"})})}catch{}},children:[e.jsx(Tn,{className:"w-3.5 h-3.5"})," Approve & Continue"]}),e.jsxs(T,{size:"sm",variant:"outline",className:"text-green-600 border-green-200/40 hover:bg-green-50",onClick:()=>ps(!0),children:[e.jsx(ts,{className:"w-3.5 h-3.5"})," Reject"]})]}),sa&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-amber-200/40",children:[e.jsx("label",{className:"block text-xs font-medium text-amber-800 mb-1.5",children:"Why are you rejecting this checkpoint?"}),e.jsx("textarea",{value:Sr,onChange:s=>hs(s.target.value),placeholder:"Provide feedback...",rows:3,className:"w-full px-3 py-2 text-sm rounded-lg border border-amber-200/60 bg-white outline-none focus:ring-2 focus:ring-amber-300/50 resize-none",autoFocus:!0}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(T,{size:"sm",variant:"destructive",onClick:async()=>{await fetch(`https://app.trooper.so/api/tasks/${t.id}/pipeline/resume`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:"rejected",feedback:Sr.trim()||"No feedback provided",resumedBy:"user"})}).catch(()=>{}),ps(!1),hs("")},children:"Submit rejection"}),e.jsx(T,{size:"sm",variant:"outline",className:"text-amber-700 border-amber-200/40 hover:bg-amber-50",onClick:()=>{ps(!1),hs("")},children:"Cancel"})]})]})]}),t.status==="awaiting_approval"&&t.desktopWorkflow&&e.jsxs("div",{className:"mb-4 p-4 bg-stone-100 border border-neutral-200 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Kc,{className:"w-4 h-4 text-neutral-500 flex-shrink-0"}),e.jsx("p",{className:"text-sm font-medium text-neutral-900",children:"Test complete â review and approve"})]}),t.desktopWorkflow.testSummary&&e.jsx("p",{className:"text-xs text-neutral-500 mb-3 whitespace-pre-wrap",children:t.desktopWorkflow.testSummary}),t.desktopWorkflow.recordingUrl&&e.jsx("div",{className:"mb-3 rounded-lg overflow-hidden bg-black",children:e.jsx("video",{src:t.desktopWorkflow.recordingUrl,controls:!0,className:"w-full max-h-64",preload:"metadata"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(T,{size:"sm",className:"bg-brand text-brand-foreground hover:bg-brand/90",onClick:async()=>{try{await fetch(`https://app.trooper.so/api/tasks/${t.id}/test-approval`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:"approved"})})}catch{}},children:[e.jsx(Tn,{className:"w-3.5 h-3.5"})," Approve & Ship"]}),e.jsxs(T,{size:"sm",variant:"outline",className:"text-amber-700 border-amber-200/40 hover:bg-amber-50",onClick:()=>xs(!0),children:[e.jsx(ts,{className:"w-3.5 h-3.5"})," Request Changes"]})]}),oa&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-neutral-200",children:[e.jsx("label",{className:"block text-xs font-medium text-neutral-900 mb
53-1.5",children:"What needs to change?"}),e.jsx("textarea",{value:kr,onChange:s=>gs(s.target.value),placeholder:"Describe the changes needed...",rows:3,className:"w-full px-3 py-2 text-sm rounded-lg border border-neutral-200 bg-white outline-none focus:ring-2 focus:ring-stone-300/40 resize-none",autoFocus:!0}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(T,{size:"sm",className:"bg-amber-500 hover:opacity-90",onClick:async()=>{await fetch(`https://app.trooper.so/api/tasks/${t.id}/test-approval`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({decision:"revision_requested",feedback:kr.trim()||"No feedback provided"})}).catch(()=>{}),xs(!1),gs("")},children:"Submit feedback"}),e.jsx(T,{size:"sm",variant:"outline",onClick:()=>{xs(!1),gs("")},children:"Cancel"})]})]})]}),(t.status==="testing"||t.status==="recording")&&e.jsxs("div",{className:"mb-4 p-4 bg-stone-50 border border-neutral-200 rounded-xl flex items-center gap-3",children:[e.jsx(Gm,{className:"w-4 h-4 text-amber-600 flex-shrink-0 animate-pulse"}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-sm font-medium text-neutral-900",children:t.status==="recording"?"Recording test session...":"Testing in browser..."})}),t.status==="recording"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-red-600 font-medium",children:[e.jsx("span",{className:"w-2 h-2 bg-red-500 rounded-full animate-pulse"})," REC"]})]}),t.escalated&&e.jsxs("div",{className:"mb-4 p-4 bg-green-50 border border-green-200 rounded-xl flex items-center gap-3",children:[e.jsx(Sd,{className:"w-4 h-4 text-green-500 flex-shrink-0"}),e.jsx("div",{className:"flex-1",children:e.jsxs("p",{className:"text-sm font-medium text-destructive",children:["Escalated â failed ",t.failureCount," times"]})})]}),t.qualityReview&&e.jsxs("details",{className:V("mb-4 rounded-xl border overflow-hidden shadow-sm group",t.qualityReview.passed?"border-green-200/90 bg-green-50/60":"border-amber-200/90 bg-amber-50/50"),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-3 px-4 py-3.5 [&::-webkit-details-marker]:hidden select-none hover:bg-black/[0.02]",children:[e.jsx("span",{className:V("font-display text-base font-bold tabular-nums shrink-0",t.qualityReview.passed?"text-green-800":"text-amber-900"),children:t.qualityReview.overallScore}),e.jsx("span",{className:V("min-w-0 flex-1 text-sm font-medium leading-snug",t.qualityReview.passed?"text-green-900":"text-amber-900"),children:t.qualityReview.passed?"Quality passed":"Needs improvement"}),e.jsxs("span",{className:"shrink-0 rounded-md bg-background/80 px-2 py-0.5 text-meta text-muted-foreground ring-1 ring-inset ring-border/60",children:[((To=t.qualityReview.checks)==null?void 0:To.length)||0," checks"]}),e.jsx($s,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-transform group-open:rotate-180"})]}),((Lo=t.qualityReview.checks)==null?void 0:Lo.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-x-5 gap-y-2 border-t border-border/50 px-4 py-3",children:t.qualityReview.checks.map((s,o)=>e.jsxs("span",{className:"flex items-center gap-1 text-meta text-neutral-500",children:[e.jsx("span",{className:s.passed?"text-green-800":"text-red-600",children:s.passed?"â":"â"}),s.label]},o))})]}),e.jsx("div",{className:"relative pl-1 w-full",style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)"},children:(()=>{const s=[...ac.map(c=>({_kind:"comment",_ts:new Date(c.createdAt||0).getTime(),...c})),...Ke.map(c=>({_kind:"delivery",_ts:new Date(c.createdAt||c.timestamp||0).getTime(),...c}))].sort((c,r)=>c._ts-r._ts),o={};if(Ve.length>0){const c=s.filter(r=>r._kind==="comment");Ve.forEach((r,i)=>{if(!r.startedAt)return;const p=new Date(r.startedAt).getTime();let u=!1;
53c.forEach((l,g)=>{if(u)return;if(l._ts>=p-2e3){const S=s.indexOf(l);o[S]={step:r,stepIdx:i},u=!0}})})}return s.map((c,r)=>{if(c._kind==="delivery"){const P=c;return e.jsx("div",{className:"mb-4",children:e.jsx(Fu,{fileName:Pi(P.fileName),subtitle:`${Ti(P.fileName)==="code"?"Code":"Document"} · ${Ei(P.fileName)}`,iconType:Ti(P.fileName),onDownload:()=>ba(null,`https://app.trooper.so/api/tasks/${t.id}/deliveries/${P.id}/download`,P.fileName),onPreview:()=>hn(P)})},`delivery-${P.id}`)}const i=c,p=r;if(i.isAgent&&xn&&Pu(i.content))return null;const u=()=>{const F=((D=[])=>{var he,Q;for(const X of Array.isArray(D)?D:[]){const wn=((he=X==null?void 0:X.data)==null?void 0:he.runId)||(X==null?void 0:X.runId)||null,Je=((Q=X==null?void 0:X.data)==null?void 0:Q.sessionKey)||(X==null?void 0:X.sessionKey)||null;if(wn||Je)return{runId:wn||null,sessionKey:Je||null}}return{runId:null,sessionKey:null}})(i.toolEvents),x=i.runId||F.runId||null,M=i.sessionKey||F.sessionKey||null,ie={id:i.id,senderId:i.authorId,senderName:i.authorName,runId:x,sessionKey:M,toolEvents:i.toolEvents||[],content:i.content,rawContent:i.rawContent,createdAt:i.createdAt,channel:t!=null&&t.id?`task:${t.id}`:"task"},Z=(Array.isArray(se)?se:[]).filter(D=>D==null?void 0:D.isAgent).map(D=>({id:D.id,senderId:D.authorId,senderName:D.authorName,runId:D.runId||null,sessionKey:D.sessionKey||null,toolEvents:D.toolEvents||[],content:D.content,rawContent:D.rawContent,createdAt:D.createdAt,channel:t!=null&&t.id?`task:${t.id}`:"task"}));let de=Od(ie,Z).events;de.length||(de=Array.isArray(i.toolEvents)?[...i.toolEvents]:[]),de.length===0&&(i.rawContent||i.content)?de=[{event:"text",data:{text:i.rawContent||i.content,...x?{runId:x}:{},...M?{sessionKey:M}:{}},time:i.createdAt||Date.now()}]:(x||M)&&(de=de.map(D=>{var he,Q;return{...D,data:{...(D==null?void 0:D.data)||{},...x&&!((he=D==null?void 0:D.data)!=null&&he.runId)?{runId:x}:{},...M&&!((Q=D==null?void 0:D.data)!=null&&Q.sessionKey)?{sessionKey:M}:{}}}})),tn({events:de,agentName:i.authorName,agentAvatar:i.authorAvatar||null,agentId:i.authorId,runId:x,sessionKey:M,requestSource:{messageId:i.id||null,senderName:i.authorName||null,senderType:i.isAgent?"agent":"human",channel:t!=null&&t.id?`task:${t.id}`:"task",createdAt:i.createdAt||null,textPreview:String(i.content||i.rawContent||"").replace(/\s+/g," ").trim().slice(0,180),sourceSurface:i.sourceSurface||i.platform||"task_comment",responseTarget:i.responseTarget||null}})},l=nc(i),g=!i.isAgent&&(i.authorId===(w==null?void 0:w.id)||!i.isAgent&&!v.find(P=>P.id===i.authorId||P.name===i.authorName)),y=i.replyTo?se.find(P=>P.id===i.replyTo):null,S=o[p],A=p>0?s[p-1]:null,C=!S&&Hd(i,A);return e.jsxs(Ls.Fragment,{children:[S&&e.jsx(zu,{step:S.step,stepIdx:S.stepIdx,totalSteps:fa}),e.jsx("div",{className:"group relative my-1.5 sm:my-2",onMouseLeave:()=>ea(null),children:g?e.jsx("div",{className:"flex flex-col items-end gap-1",children:e.jsx("div",{className:V("relative inline-flex max-w-[min(85%,520px)] break-words",Rd),children:e.jsxs("div",{className:"flex-1",children:[y&&e.jsxs("div",{className:"mb-1.5 rounded-md border border-neutral-200/90 bg-neutral-50/70 px-2 py-1 text-meta text-neutral-500",children:[e.jsx("span",{className:"font-semibold text-neutral-700",children:y.authorName})," ",y.content.substring(0,60),"â¦"]}),e.jsx("div",{className:"text-sm leading-[1.75] text-neutral-900",children:e.jsx(Es,{content:i.content,agents:v,humans:O,className:"text-sm"})})]})})}):e.jsxs("div",{className:"relative",children:[!C&&e.jsxs("div",{className:"mb-1.5 flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"cursor-pointer transition-opacity hover:opacity-80",onClick:()=>{const P=v.find(F=>F.id===i.authorId||F.name===i.authorName);P&&(Bn==null||Bn(P))},children:e.jsx(Ln,{src:l.avatar,name:l.name,size:"w-7 h-7 text-[9px]",agent:v.find(P=>P.id===i.authorId||P.name===i.authorName)||l})}),e.jsx("span",{className:"text-[13px] font-medium text-neutral-800",children:l.name}),i.isAgent&&(()=>{const P=v.find(F=>F.id===i.authorId||F.name===i.authorName);return e.jsxs(e.Fragment,{children:[(P==null?void 0:P.title)&&e.jsx("span",{className:"text-[11px] text-neutral-500",children:P.title}),(P==null?void 0:P.role)==="LEAD"&&e.jsx(ji,{className:"text-[9px] px-1.5 py-0 h-4 font-semibold",children:"Manager"})]})})()]}),e.jsxs("div",{className:"max-w-[min(100%,42rem)] px-3",children:[y&&e.jsxs("div",{className:"mb-2 rounded-lg border border-stone-200 px-3 py-1 text-meta text-neutral-600",children:[e.jsx("span",{className:"font-semibold",children:y.authorName})," ",y.content.substring(0,60),"â¦"]}),i.isAgent?e.jsx(Sm,{message:i,agents:v,humans:O,bridgeUrl:Fn,onOpenArtifact:fn,onOpenActivityDrawer:u,enableChildRuns:!0,taskProjectFolder:H,workspaceFiles:z,onTaskClick:()=>{Ne(!1),it(!0),De("files")},reactions:i.reactions,showReactions:wr===i.id,onReply:()=>{Us(i),mn()},onCopy:()=>navigator.clipboard.writeText(i.content),onReact:()=>ea(wr===i.id?null:i.id),onReactEmoji:P=>{Kr(i.id,P),ea(null)}}):e.jsx("div",{className:"text-sm text-neutral-900 leading-[1.75]",children:sc(i)}),i.diffArtifact&&e.jsx(bi,{artifact:i.diffArtifact,className:"my-2 w-full max-w-2xl"}),!i.isAgent&&di(i.reactions).length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:di(i.reactions).map((P,F)=>e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>Kr(i.id,P.emoji),className:"px-2 py-0.5 h-auto rounded-full border-neutral-200 bg-white hover:border-stone-400 flex items-center gap-1",children:[e.jsx("span",{children:P.emoji})," ",e.jsx("span",{className:"font-medium text-neutral-600",children:P.count??Vc(P.userIds).length})]},F))})]})]})})]},i.id)})})()}),se.length===0&&!Ll&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[e.jsx(Hc,{className:"w-7 h-7 text-neutral-300"}),e.jsx("p",{className:"text-sm text-neutral-400",children:"No activity yet."}),e.jsx("p",{className:"text-xs text-neutral-400",children:"Send a message to get started"})]}),Ke.length>1&&e.jsx("div",{className:"py-2",children:e.jsxs(T,{variant:"ghost",size:"sm",onClick:()=>{const s="https://app.trooper.so";Ke.forEach((o,c)=>{setTimeout(()=>ba(null,`${s}/api/tasks/${t.id}/deliveries/${o.id}/download`,o.fileName),c*300)})},className:"h-8 px-3 pl-2 pr-2.5 gap-1 text-neutral-600 hover:text-neutral-900 hover:bg-stone-100 self-start",children:[e.jsx(Ka,{className:"w-3.5 h-3.5"})," Download all deliveries"]})}),(()=>{var Bo,zo,Wo,Ko,Vo,Ho,qo,Go,Jo,Uo,Yo,Xo;const s=da,o=qt.filter(L=>L.status==="in_progress"),c=Array.from(new Map(o.map(L=>{const W=L.assigneeId?v.find(le=>le.id===L.assigneeId):L.assigneeName?v.find(le=>{var Ie;return le.name===L.assigneeName||le.name===((Ie=L.assigneeName)==null?void 0:Ie.replace(/^@/,""))}):null;return W?[W.id,W]:null}
53).filter(Boolean)).values()),r=Am(_e,t.id,{preferredAgentIds:Xn,assigneeId:t.assigneeId,agents:v}),i=r.executorId||(ae==null?void 0:ae.agentId)||((Bo=s.find(([L])=>v.some(W=>W.id===L)))==null?void 0:Bo[0])||((zo=c[0])==null?void 0:zo.id)||t.assigneeId,p=["done","review","blocked","paused","cancelled"].includes(gt(t.status))||String(t.executionPhase||"").toLowerCase()==="done",u=String(t.executionPhase||"").toLowerCase();if(u==="plan_review")return Me.current={taskId:null,snapshot:null},ye.current={taskId:t.id,events:[],model:null,stream:"",streamAgentId:null},tt.current={taskId:null,label:null,rank:-1},null;if(ye.current.taskId!==t.id)ye.current={taskId:t.id,events:[],model:null,stream:"",streamAgentId:null},tt.current={taskId:null,label:null,rank:-1};else if(ee.length>0&&(ye.current.events=ee),pa&&(ye.current.model=pa),on){const L=ae!=null&&ae.agentId?String(ae.agentId):null,W=ye.current.streamAgentId||null,le=W&&s.some(([Ie])=>String(Ie)===W);(!W||!L||L===W||!le)&&(ye.current.stream=on,ye.current.streamAgentId=L)}const g=ee.length>0?ee:ye.current.events,y=on||ye.current.stream,A=!!String(y||"").length&&qc(g,y),C=pa||ye.current.model;((C==null?void 0:C.semanticTimelineEntries)||[]).some(L=>{var W;return L.status==="running"||L.type==="parallel"&&((W=L.children)==null?void 0:W.some(le=>le.status==="running"))});const F=g.length>0,x=!!(C&&(C.semanticTimelineEntries.length>0||C.aggregate.sources.length>0)),M=[...t.comments||[]].reverse().find(L=>L==null?void 0:L.isAgent),ie={agentId:i||t.assigneeId||null,agentName:((Ko=(Wo=s[0])==null?void 0:Wo[1])==null?void 0:Ko.name)||t.assigneeName||"Agent",runId:Gt||null,sessionKey:Le||null,channel:t!=null&&t.id?`task-chat-${t.id}`:"general",streamingText:y},Z=!!(M&&(qd(ie,M)||String(M.content||"").trim().length>=24&&Gd(y,M.content)||A&&String(M.content||"").trim().length>=16&&Date.now()-Number(M.createdAt||0)<12e4)),de=!A&&!Z&&(te||s.length>0||c.length>0||!p&&t.lastRunSignalPending||!p&&F&&te&&(u==="executing"||gt(t.status)==="in_progress"));if((Z||A)&&(ye.current={taskId:t.id,events:[],model:null,stream:"",streamAgentId:null}),!de){p&&!te&&!s.length&&(Me.current={taskId:null,snapshot:null},tt.current={taskId:null,label:null,rank:-1},ye.current={taskId:t.id,events:[],model:null,stream:"",streamAgentId:null});const L=u;return!((t.executionSteps||[]).length>0)&&(L==="preparing_team"||L==="planning")?e.jsxs("div",{className:"mb-4 flex items-center gap-2.5 px-3 py-2 text-[13px] text-neutral-500",children:[e.jsx(Xa,{className:"h-3.5 w-3.5 animate-spin text-neutral-400"}),e.jsx("span",{children:L==="preparing_team"?"Getting the team readyâ¦":`${(Y==null?void 0:Y.name)||"The team lead"} is planning the workâ¦`})]}):null}const D=i?v.find(L=>L.id===i):null,he=(Vo=t.subtasks)==null?void 0:Vo.find(L=>L.status==="in_progress");Me.current.taskId!==t.id&&(Me.current={taskId:t.id,snapshot:null});const Q=Me.current.snapshot,X=(L,W)=>L!=null&&W!=null&&String(L)===String(W),wn=(Q==null?void 0:Q.agentId)&&(X(Q.agentId,i)||s.some(([L])=>X(L,Q.agentId))||!!(r.primary&&X(r.primary.agentId,Q.agentId))),Je=D||(r.executorName?{id:i,name:r.executorName,avatar:((Ho=v.find(L=>L.id===i))==null?void 0:Ho.avatar)??null,character:((qo=v.find(L=>L.id===i))==null?void 0:qo.character)??null,title:((Go=v.find(L=>
53L.id===i))==null?void 0:Go.title)??null,role:((Jo=v.find(L=>L.id===i))==null?void 0:Jo.role)??null}:null);if(!Q||!wn){if(Je)Me.current.snapshot={agentId:Je.id||i,name:Je.name,avatar:Je.avatar??null,character:Je.character??null,title:Je.title??null,role:Je.role??null};else if(!Q&&t.assigneeId){const L=v.find(W=>W.id===t.assigneeId);L&&(Me.current.snapshot={agentId:L.id,name:L.name,avatar:L.avatar??null,character:L.character??null,title:L.title??null,role:L.role??null})}}else if(Q&&i&&!X(Q.agentId,i)&&t.assigneeId&&X(Q.agentId,t.assigneeId)&&!X(i,t.assigneeId)){const L=v.find(W=>W.id===i);L&&(Me.current.snapshot={agentId:L.id,name:L.name,avatar:L.avatar??null,character:L.character??null,title:L.title??null,role:L.role??null})}const re=Me.current.snapshot,Sc=(D==null?void 0:D.name)||((Yo=(Uo=s[0])==null?void 0:Uo[1])==null?void 0:Yo.name)||((Xo=he==null?void 0:he.assigneeName)==null?void 0:Xo.replace(/^@/,""))||"Agent",Na=re?re.name:Sc,ct=(re==null?void 0:re.agentId)||i,Ce=ct?v.find(L=>X(L.id,ct)):null,jn=(re==null?void 0:re.avatar)??(D==null?void 0:D.avatar)??(Ce==null?void 0:Ce.avatar)??null;re&&!re.avatar&&jn&&(re.avatar=jn);const Do=(re?re.title:null)??(D==null?void 0:D.title)??(Ce==null?void 0:Ce.title)??null,Sa=(re?re.role:null)??(D==null?void 0:D.role)??(Ce==null?void 0:Ce.role)??null,Cc=(Do||Sa||"").trim(),Fo=Sa==="LEAD",kc=!Fo&&!!(re||D),Ca=Na,Ic=r.managerName&&ct&&t.assigneeId&&X(ct,t.assigneeId)&&r.delegatedTo?r.delegatedTo:null,ka=r.runPhase==="planning"?{label:"Planning the work",rank:1}:r.runPhase==="step"&&r.stepCount>0?{label:`Step ${r.stepIndex+1}/${r.stepCount}${r.stepTitle?` · ${r.stepTitle}`:""}`,rank:2+(Number.isInteger(r.stepIndex)?r.stepIndex:0)}:{label:"Working",rank:0};return tt.current.taskId!==t.id&&(tt.current={taskId:t.id,label:null,rank:-1}),(!tt.current.label||ka.rank>=tt.current.rank)&&(tt.current.label=ka.label,tt.current.rank=ka.rank),e.jsxs("div",{className:"mb-4",children:[e.jsx(Bu,{agent:Ce||{id:ct,name:Na,avatar:jn,character:(re==null?void 0:re.character)||(Ce==null?void 0:Ce.character),role:Sa,title:Do},avatarSrc:jn,name:Na,subtitle:Cc||null,showManagerBadge:Fo,showSpecialistBadge:kc,delegatedTo:Ic}),e.jsxs("div",{className:"px-3",children:[g.length>0||y||x?e.jsx(Md,{rootClassName:"mt-2",events:g,streamingText:y,isLive:de,runId:Gt||null,sessionKey:Le||null,sessionEntries:rn,enableChildRuns:!!(Gt||Le),agentName:Ca,renderStreamingBody:Fr,preferSemantic:!0,allowSemanticWhenLive:!0,semanticThinkingTitle:"Activity",semanticShowThinkingHeader:!1,semanticShowMilestones:!1,semanticShowSources:!0,semanticShowRuntimeUsage:!1,semanticSourceVariant:"pills",chatInlineSummaryOnly:!0,hideSettledToolRecap:!de,showSessionPanel:!1,onOpenRunLogs:()=>{var L;tn({events:g,timelineEntries:(C==null?void 0:C.semanticTimelineEntries)||[],agentName:Ca,agentAvatar:((L=v.find(W=>W.id===ct))==null?void 0:L.avatar)||null,isLive:te,agentId:ct,runId:Gt||null,sessionKey:Le||null,streamingText:y})}}):y?e.jsxs("div",{className:"mt-1 stream-typing-surface rounded-lg border border-brand/25 bg-brand/[0.03] px-3 py-2",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5 text-[11px] text-neutral-500",children:[e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-brand/80","aria-hidden":!0}),"Writing responseâ¦"]}),Fr(y)]}):e.jsxs("div",{className:"flex items-center gap-2 text-sm text-neutral-600 py-2",children:[e.jsx(Zt,{size:16}),e.jsx("span",{children:"Thinking..."})]}),g.length>0||y||x?null:e.jsxs(T,{variant:"link",onClick:()=>{var L;tn({events:g,timelineEntries:(C==null?void 0:C.semanticTimelineEntries)||[],agentName:Ca,agentAvatar:((L=v.find(W=>W.id===ct))==null?void 0:L.avatar)||null,isLive:te,agentId:ct,runId:Gt||null,sessionKey:Le||null,streamingText:y})},className:"mt-1.5 flex items-center gap-1 text-meta text-neutral-400 hover:text-neutral-600 h-auto p-0",title:"View full activity log",children:[e.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"})}),e.jsx("span",{children:"Activity"})]}),(()=>{const L=(g||[]).filter(W=>{var le,Ie;return W.event==="file_written"&&(((le=W.data)==null?void 0:le.path)||((Ie=W.data)==null?void 0:Ie.name))}).reduce((W,le)=>{var Zo,ei,ti,si,ni,ai;const Ie=((Zo=le.data)==null?void 0:Zo.name)||((ti=(ei=le.data)==null?void 0:ei.path)==null?void 0:ti.split("/").pop()),Qo={name:Ie,path:(si=le.data)==null?void 0:si.path,ext:((ni=le.data)==null?void 0:ni.ext)||((ai=Ie.split(".").pop())==null?void 0:ai.toLowerCase())||""};return!Ie||za(Qo)||W.some(Rc=>Rc.name===Ie)||W.push(Qo),W},[]);return L.length===0?null:e.jsxs("div",{className:"mt-3 flex w-full flex-col gap-2 max-w-full sm:max-w-[560px]",children:[e.jsx("div",{className:"text-meta font-medium text-neutral-500 uppercase tracking-wide",children:"Files being created"}),L.slice(-4).map((W,le)=>e.jsxs(T,{variant:"outline",onClick:()=>Et({name:W.name,path:W.path,ext:W.ext,content:""}),className:"text-left h-auto border-neutral-200/50 bg-white px-3 py-2 hover:bg-stone-50 flex flex-col items-start",children:[e.jsx("div",{className:"text-sm text-neutral-900 truncate",children:W.name}),e.jsx("div",{className:"text-meta text-neutral-500 truncate",children:W.path||"workspace file"})]},`${W.path||W.name}-${le}`))]})})()]})]})})(),e.jsx("div",{ref:vs}),e.jsx("div",{className:"h-14 shrink-0 sm:h-16","aria-hidden":!0,style:{overflowAnchor:"none"}})]})})]})]}),wl&&e.jsx(T,{variant:"outline",size:"icon",onClick:Il,className:"absolute bottom-28 left-1/2 -translate-x-1/2 z-10 h-9 w-9 rounded-xl border border-border shadow-md bg-card","aria-label":"Scroll to new messages",children:e.jsx(sl,{className:"w-4 h-4 text-neutral-500"})}),e.jsx("div",{className:"relative z-[5] w-full flex-shrink-0 border-t border-neutral-100 bg-white",children:e.jsxs("div",{className:V("mx-auto max-w-[min(100%,42rem)] min-w-0 pb-2 pt-2","pl-[max(1.5rem,env(safe-area-inset-left,0px))] pr-[max(1.5rem,env(safe-area-inset-right,0px))]","sm:pl-[max(2rem,env(safe-area-inset-left,0px))] sm:pr-[max(2rem,env(safe-area-inset-right,0px))]","md:pl-[max(2.5rem,env(safe-area-inset-left,0px))] md:pr-[max(2.5rem,env(safe-area-inset-right,0px))]","lg:pl-[max(2rem,env(safe-area-inset-left,0px))] lg:pr-[max(2rem,env(safe-area-inset-right,0px))]"),children:[li(Ze,{taskId:t==null?void 0:t.id})?e.jsx(Jd,{queuedCount:(Ze==null?void 0:Ze.queuedCount)||xt.length,onContinue:()=>rs==null?void 0:rs(),onDiscard:()=>_t==null?void 0:_t()}):null,(($o=qe==null?void 0:qe.todos)==null?void 0:$o.length)>
530?e.jsx(Cm,{todoData:qe,variant:"composer",className:"mb-2",forceOpen:va,footerContent:va||xt.length>0?e.jsxs("div",{className:"space-y-3",children:[va?e.jsxs("div",{"data-plan-approval-bar":"true",children:[yr?e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{value:Vt,onChange:s=>na(s.target.value),placeholder:"What should change about this plan?",className:"min-h-[64px] w-full rounded-xl border border-neutral-200 bg-white px-3 py-2 text-[13px] outline-none focus:border-neutral-400"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{size:"sm",className:"h-7 text-xs",disabled:ht||!Vt.trim(),onClick:()=>Ut("revise",Vt.trim()),children:"Send revision"}),e.jsx(T,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>fs(!1),children:"Cancel"})]})]}):e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(T,{size:"sm",className:"h-8 bg-brand text-xs text-brand-foreground hover:bg-brand/90",disabled:ht,onClick:()=>Ut("approve"),children:"Approve & start"}),e.jsx(T,{size:"sm",variant:"outline",className:"h-8 text-xs",disabled:ht,onClick:()=>fs(!0),children:"Revise"}),e.jsx(T,{size:"sm",variant:"ghost",className:"h-8 text-xs text-neutral-500",disabled:ht,onClick:()=>Ut("reject"),children:"Reject"}),(_o=t.planReview)!=null&&_o.markdown?e.jsx(T,{size:"sm",variant:"ghost",className:"h-8 text-xs text-neutral-500",onClick:()=>fn({type:"markdown",title:`Plan â ${t.title||"Task"}`,name:"PLAN.md",code:t.planReview.markdown}),children:"View full plan"}):null]}),sn?e.jsx("p",{className:"mt-2 text-xs font-medium text-red-600",children:sn}):null]}):null,xt.length>0?e.jsx(yi,{entries:xt,hasActiveRun:te,onToggleMode:Jr,onEdit:K,onRemove:as,onReorder:ut,onSetEditing:Ae,embedded:!0}):null]}):null}):null,!((Mo=qe==null?void 0:qe.todos)!=null&&Mo.length)&&xt.length>0&&e.jsx(yi,{entries:xt,hasActiveRun:te,onToggleMode:Jr,onEdit:K,onRemove:as,onReorder:ut,onSetEditing:Ae,className:"mb-2"}),be&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-xl border border-border bg-muted/40 px-3.5 py-2.5 text-xs ring-2 ring-brand/20",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-semibold text-neutral-900",children:be.authorName}),e.jsx("p",{className:"text-neutral-500 truncate text-meta mt-0.5",children:Ud(be)})]}),e.jsx(T,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground hover:bg-muted/50 rounded-lg shrink-0",onClick:()=>Us(null),"aria-label":"Cancel reply",children:e.jsx(En,{className:"w-3.5 h-3.5"})})]}),ta&&e.jsxs("div",{className:"mb-4 p-4 bg-amber-50/90 border border-amber-200/60 rounded-xl",children:[e.jsx("p",{className:"text-sm text-amber-600 font-medium",children:"Reset this task?"}),e.jsx("p",{className:"text-xs text-neutral-500 mt-1",children:"All comments will be cleared and execution will restart from scratch."}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(T,{onClick:async()=>{try{const s="https://app.trooper.so",o=await(m==null?void 0:m()
53);t.id;const c=await fetch(`${s}/api/tasks/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...o&&{Authorization:`Bearer ${o}`}}});if(c.status,c.ok){const r={...t,status:"in_progress",comments:[],deliveries:[],executionPhase:"planning",executionSteps:[],subtasks:(t.subtasks||[]).map(i=>({...i,status:"pending",output:null,outputSummary:null,failedAt:null,completedAt:null,startedAt:null,failureReason:null,skipReason:null}))};j(r),q.setState(i=>({tasks:i.tasks.map(p=>p.id===r.id?r:p)}))}else{const r=await c.json().catch(()=>({}));console.error("[TaskModal] Reset failed:",c.status,r),As.error(`Reset failed: ${r.error||c.status}`)}}catch(s){console.error("[TaskModal] Reset error:",s),As.error(`Reset error: ${s.message}`)}us(!1)},className:"bg-amber-500 hover:opacity-90",size:"sm",children:"Reset"}),e.jsx(T,{size:"sm",variant:"outline",onClick:()=>us(!1),children:"Cancel"})]})]}),e.jsx(im,{open:Ee&&Pt.length>0,anchorRef:Rr,className:Yd,side:"top",zIndex:260,onInteractOutside:ec,children:e.jsx(rd,{groups:ga,selectedIndex:Js,itemRefs:Pr,onSelect:Wr})}),e.jsx("div",{className:"relative h-0",children:e.jsx("div",{className:"absolute inset-x-0 bottom-0 z-20",children:e.jsx(lm,{className:"mb-1.5 shadow-md"})})}),e.jsx(cm,{ref:Rr,className:"relative",pluginSuggestion:Cl,onPluginInstalled:s=>{ll(o=>[...new Set([...o,...s||[]])])},onPluginConnect:ne.openPluginConnect,onPluginUse:Sl,cardClassName:um(wi({planMode:On,executeMode:Dn})),toolbarLeft:xc,toolbarRight:bc,toolbarRightRef:_r,toolbarRightClassName:"gap-1 py-1 sm:gap-1",toolbarLeftClassName:"gap-0.5 py-1",afterBillingSlot:w||Jt?e.jsx(km,{sessionKey:Jt||null,agentName:(Y==null?void 0:Y.name)||"",channel:"tasks",hasActiveRun:te,contextBudget:Dl,runEvents:ee,composerModelId:_l,className:"shrink-0"}):null,inputSlot:e.jsxs("div",{className:"relative z-20 flex min-h-0 w-full flex-col overflow-visible px-3 pt-2",children:[Dt.length>0?e.jsx(dm,{attachments:Dt,onRemove:Ul,compact:!0}):null,e.jsx(bm,{refs:Ks.filter(s=>!(s!=null&&s.inlineToken)&&!(s!=null&&s.hiddenChip)),onRemove:s=>is(o=>o.filter(c=>c.id!==s)),compact:!0}),e.jsx("div",{ref:We,className:"w-full",children:e.jsx(od,{displayValue:st,options:id,autoConvertMentions:!1,keepTriggerOnSelect:!1,onChange:s=>{const o=ld(We.current,s);wt(o),is(c=>cd(c,s,Xl.registry)),Ql(o)},onKeyDown:s=>{if(Ee&&["ArrowDown","ArrowUp","Enter","Tab","Escape"].includes(s.key)){const o=mi(s.key,Te)&&Pt.length>0;un(s),s.key==="Enter"&&!s.shiftKey&&!o&&xa(s);return}if(s.key==="Enter"&&!s.shiftKey){s.preventDefault(),xa(s);return}un(s)},slotsProps:{container:{className:"w-full"},contentEditable:{className:"scrollbar-thin w-full min-h-[44px] max-h-[240px] overflow-auto bg-transparent px-0.5 pb-1 pt-1 text-base font-normal leading-[1.65] text-neutral-900 outline-none placeholder:text-neutral-400","data-placeholder":be?`Reply to ${be.authorName}â¦`:"Steer this taskâ¦","data-composer-input":!0},modal:{className:"hidden"},chipClassName:"mention-chip composer-inline-ref-chip"}})}),ls&&(ce.state==="recording"||ce.state==="transcribing")?e.jsx(mm,{state:ce.state,liveStream:ce.liveStream,duration:ce.duration,formatTime:ce.formatTime,onCancel:ce.cancelRecording,onSend:ce.stopAndTranscribe}):null]})}),(w||Jt||rn.length>0)&&e.jsx("div",{className:"@container mt-0.5 flex min-w-0 items-center gap-1 text-[10px] text-neutral-500 @md:mt-1.5 @md:gap-1.5 @md:text-[11px]",children:e.jsx("div",{className:"flex min-h-7 min-w-0 flex-1 items-center gap-1 overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:e.jsxs(Td,{value:ws.mode==="device"&&ws.deviceId?ws.deviceId:ws.mode==="cloud"?"cloud":"auto",onValueChange:s=>{if(s==="__add__"){window.dispatchEvent(new CustomEvent("navigate-page",{detail:"devices"}));return}const o=(Qe||[]).find(i=>i.id===s)||null,c=(o==null?void 0:o.openClawReadiness)||(o==null?void 0:o.readiness)||null,r=o?{deviceRef:{mode:"device",type:"device",deviceId:o.id,deviceName:o.name||null,label:o.name||"Selected device",...c?{openClawReadiness:c,readiness:c}:{}},executionTarget:{type:"device",deviceId:o.id,deviceName:o.name||null,...c?{openClawReadiness:c,readiness:c}:{}}}:{deviceRef:s==="cloud"?{mode:"cloud",type:"cloud",label:"Cloud Computer"}:{mode:"auto",type:"auto",label:"All Devices"},executionTarget:{type:"brain"}};Ue(`/api/tasks/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)},{orgId:Rt}).catch(()=>{})},children:[e.jsxs(Ld,{className:"h-7 w-auto max-w-[min(100%,240px)] min-w-0 shrink-0 gap-1 rounded-full border-0 bg-transparent px-2.5 py-0 text-[11px] font-medium text-neutral-500 shadow-none ring-0 ring-offset-0 focus:ring-0 focus-visible:ring-0 data-[state=open]:ring-0 hover:bg-neutral-500/10 hover:text-neutral-700",title:"Where this task runs",children:[e.jsx(Fl,{className:"mr-0.5 h-3.5 w-3.5 shrink-0 text-neutral-400",strokeWidth:1.75}),e.jsx($d,{placeholder:"All Devices"})]}),e.jsxs(_d,{children:[e.jsx(In,{value:"auto",children:"All Devices"}),e.jsx(In,{value:"cloud",children:"Cloud Computer (VPS) only"}),(Qe||[]).filter(s=>s.kind!=="brain"&&s.trust!=="pending"&&s.status!=="rejected").map(s=>e.jsxs(In,{value:s.id,children:["Only ",s.name]},s.id)),e.jsx(In,{value:"__add__",children:"Manage devicesâ¦"})]})]})})})]})})]}),Se&&nt&&e.jsxs("div",{onMouseDown:Vl,className:"group w-2 relative cursor-col-resize flex-shrink-0 z-0 grid place-items-center -mr-1 self-stretch",children:[e.jsx("div",{className:"absolute top-0 bottom-0 right-1 w-px bg-border transition-all duration-200 group-hover:delay-75 group-hover:bg-muted-foreground
53/30"}),e.jsx("div",{className:"h-7 w-2 relative rounded-full border border-border bg-card shadow-sm transition-all duration-200 group-hover:delay-75 group-hover:border-muted-foreground/25 group-hover:bg-muted cursor-col-resize"})]}),(()=>{var o,c;const s=e.jsx("div",{className:V("flex min-h-0 min-w-0 flex-col overflow-hidden bg-card",nt?V("border-l border-border",Se?"flex-initial basis-auto min-h-0":"hidden"):"flex-1"),style:Se&&nt?{width:`calc(${100-Gs}% - 4px)`,flexShrink:0}:void 0,children:e.jsx(Fd,{tab:pe,onTabChange:vc,onClose:pn,tabs:gu,initialTabs:bu,channels:J,sideChatChannelId:Ir||"general",onSideChatChannelChange:Nl,tabMeta:wc,trailing:Nc,children:e.jsx("div",{className:"relative z-0 flex min-h-0 flex-1 flex-col overflow-hidden bg-white",children:zt?e.jsx(Dd,{artifacts:uc,activeId:pc,initialMode:"cascade",onSelect:r=>{if(Fe(!1),Ne(!1),De("files"),it(!0),r!=null&&r.path){const i=String(r.path);Et({name:r.title||i.split("/").filter(Boolean).pop()||"file",path:i,ext:r.type||r.lang||"",content:r.code!=null?String(r.code):""});return}if((r==null?void 0:r.code)!==void 0&&String(r.code).length>0){ve({fileRef:{name:r.title||"file",path:r.path,ext:r.type||r.lang||"",content:String(r.code)}});return}ve({artifactRef:{title:r.title||"Artifact",code:r.code||"",type:r.type||"html",lang:r.lang||r.type||"",path:r.path}})},onClose:tc,onExit:()=>Fe(!1)}):e.jsxs(e.Fragment,{children:[pe==="terminal"&&e.jsx(f.Suspense,{fallback:e.jsx(Ps,{label:"Loading terminalâ¦"}),children:e.jsx(lu,{onClose:pn})}),pe==="canvas"&&e.jsx(f.Suspense,{fallback:e.jsx(Ps,{label:"Loading canvasâ¦"}),children:e.jsx(iu,{className:"h-full min-h-0 flex-1",orgId:(w==null?void 0:w.orgId)||null,channelId:(Ht==null?void 0:Ht.key)||"general",onExit:pn,onOpenArtifact:r=>{r&&we("files",{artifact:{artifactRef:r}})}})}),pe==="video"&&e.jsx(f.Suspense,{fallback:e.jsx(Ps,{label:"Loading video editorâ¦"}),children:e.jsx(cu,{})}),pe==="apps"&&e.jsx(f.Suspense,{fallback:e.jsx(Ps,{label:"Loading appsâ¦"}),children:e.jsx(du,{onOpenArtifact:r=>{r&&we("files",{artifact:{artifactRef:r}})}})}),pe==="chat"&&e.jsx(f.Suspense,{fallback:e.jsx(Ps,{label:"Loading chatâ¦"}),children:e.jsx(mu,{embedded:!0,channelId:Ir||"general",onOpenArtifact:r=>{r&&we("files",{artifact:{artifactRef:r}})}})}),pe==="browser"&&e.jsx(Wd,{scope:Ht,assigneeId:t.assigneeId}),pe==="diffs"&&e.jsx(zd,{scope:Ht,events:mc}),pe==="activity"&&e.jsx(Bd,{entries:wa,rawEvents:Xr,isLive:te,messageContent:((o=Is==null?void 0:Is.aggregate)==null?void 0:o.visibleText)||""}),pe==="files"&&e.jsx(Ed,{scope:Ht,projectPath:((c=t==null?void 0:t.projectRef)==null?void 0:c.localPath)||"",orgId:w==null?void 0:w.orgId,seedFiles:z,extraFiles:Ge,extraFilesLabel:"From this task",extraFolders:Er,refreshToken:`${$e}:${se.length}`,canvasEnabled:Be.length>=1,onOpenCanvas:()=>{Fe(!0),Ne(!1)},onSelectFile:()=>{ve(null),yt(null),at(null)},onOpenChatEntry:r=>{qr({...r,type:r.entryType||r.type})},isWide:nt,overrideViewer:jc,emptyState:yc})]})})})});return nt?Se?s:null:e.jsx(Qd,{open:!!Se,onClose:pn,children:s})})()]})})}),ze&&e.jsx(Nm,{isOpen:!!ze,onClose:()=>tn(null),events:ze.events,agentName:ze.agentName,agentAvatar:ze.agentAvatar||null,agentId:ze.agentId,runId:ze.runId||null,sessionKey:ze.sessionKey||null,isLive:ze.isLive||!1,requestSource:ze.requestSource||null}),Bt&&e.jsx(ou,{repo:Bt.repo,taskId:t==null?void 0:t.id,onClose:()=>rr(null),onSave:async s=>{const o=[...t.repos||[]];o[Bt.index]={...o[Bt.index],runConfig:s};try{await Ue(`/api/tasks/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({repos:o})},{orgId:Rt})}catch(c){console.error("Failed to save run config:",c)}},onRun:async()=>{const s=Bt.repo,o=s.runConfig||{};try{await Ue(`/api/tasks/${t.id}/run-repo`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({repoIndex:Bt.index,repoUrl:s.url,repoPath:s.path,setupCommands:o.setupCommands,runCommand:o.runCommand,envVars:o.envVars,recordSession:o.recordSession,taskFolder:t.projectFolder})},{orgId:Rt})}catch(c){console.error("Failed to trigger repo run:",c)}rr(null)}}
53),U&&e.jsx("div",{className:"fixed inset-0 z-[260] flex items-center justify-center bg-black/30 px-4 py-6",children:e.jsxs("div",{className:"flex max-h-[min(760px,92vh)] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-border bg-white shadow-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border px-5 py-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:U.type==="routine"?"Create Routine":"Create Workflow"}),e.jsx("h3",{className:"mt-1 text-base font-semibold text-foreground",children:U.type==="routine"?"Repeat this task automatically":"Save this as a reusable SOP"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Built from the task goal, completed context, outputs, and recovery notes."})]}),e.jsx(T,{type:"button",variant:"ghost",size:"icon",onClick:()=>ue(null),className:"h-8 w-8 rounded-lg text-muted-foreground","aria-label":"Close",children:e.jsx(En,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"min-h-0 flex-1 space-y-4 overflow-y-auto overscroll-contain px-5 py-4",children:U.type==="routine"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Routine name"}),e.jsx("input",{value:U.name,onChange:s=>ue(o=>({...o,name:s.target.value})),className:"mt-1 h-10 w-full rounded-lg border border-border bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-stone-300/40"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[1fr_1fr]",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Schedule cron"}),e.jsx("input",{value:U.cronExpression,onChange:s=>ue(o=>({...o,cronExpression:s.target.value})),className:"mt-1 h-10 w-full rounded-lg border border-border bg-white px-3 font-mono text-sm outline-none focus:ring-2 focus:ring-stone-300/40"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Agent"}),e.jsx("input",{value:U.targetAgent||"",onChange:s=>ue(o=>({...o,targetAgent:s.target.value})),placeholder:"Auto",className:"mt-1 h-10 w-full rounded-lg border border-border bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-stone-300/40"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Reusable routine prompt"}),e.jsx("textarea",{value:U.message,onChange:s=>ue(o=>({...o,message:s.target.value})),rows:14,className:"mt-1 w-full resize-none rounded-xl border border-border bg-stone-50 px-3 py-2 font-mono text-xs leading-relaxed text-stone-800 outline-none focus:ring-2 focus:ring-stone-300/40"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Workflow name"}),e.jsx("input",{value:U.workflow.name,onChange:s=>ue(o=>({...o,workflow:{...o.workflow,name:s.target.value}})),className:"mt-1 h-10 w-full rounded-lg border border-border bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-stone-300/40"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Workflow description"}),e.jsx("textarea",{value:U.workflow.description,onChange:s=>ue(o=>({...o,workflow:{...o.workflow,description:s.target.value}})),rows:3,className:"mt-1 w-full resize-none rounded-lg border border-border bg-white px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-stone-300/40"})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-foreground",children:"Generated workflow chart"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Ft?"Generating the workflow graph from the taskâ¦":"Edit nodes, prompts, and config before saving. Type @ in a
53node prompt to add references."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[Ft&&e.jsx(Zt,{size:14}),e.jsxs("div",{className:"rounded-full bg-stone-100 px-2 py-1 text-[11px] font-medium text-stone-600",children:[(((Oo=U.workflow.graph)==null?void 0:Oo.nodes)||U.workflow.nodes||[]).length," nodes"]})]})]}),e.jsx(Bm,{playbook:{graph:U.workflow.graph||er(U.workflow)},editable:!0,heightClass:"h-[320px]",mentionGroups:Zl,onGraphChange:s=>{ue(o=>({...o,workflow:Ku(o.workflow,s)}))}})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Workflow tags"}),e.jsx("input",{value:(U.workflow.tags||[]).join(", "),onChange:s=>{const o=s.target.value.split(",").map(c=>c.trim()).filter(Boolean);ue(c=>({...c,workflow:{...c.workflow,tags:o}}))},placeholder:"task-workflow, files, approval",className:"mt-1 h-10 w-full rounded-lg border border-border bg-white px-3 text-sm outline-none focus:ring-2 focus:ring-stone-300/40"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-medium text-foreground",children:"SOP runbook"}),e.jsx("textarea",{value:U.workflow.runbook,onChange:s=>{const o=s.target.value;ue(c=>({...c,workflow:{...c.workflow,runbook:o,nodes:c.workflow.nodes.map(r=>{var i,p;return r.type==="document"||r.type==="agent"?{...r,config:{...r.config,content:r.type==="document"?o:(i=r.config)==null?void 0:i.content,prompt:r.type==="agent"?o:(p=r.config)==null?void 0:p.prompt}}:r})}}))},rows:15,className:"mt-1 w-full resize-none rounded-xl border border-border bg-stone-50 px-3 py-2 font-mono text-xs leading-relaxed text-stone-800 outline-none focus:ring-2 focus:ring-stone-300/40"})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 border-t border-border bg-stone-50 px-5 py-4",children:[e.jsx(T,{type:"button",variant:"outline",onClick:()=>ue(null),disabled:cs,children:"Cancel"}),e.jsx(T,{type:"button",onClick:Gl,disabled:cs||Ft,children:cs?e.jsxs(e.Fragment,{children:[e.jsx(Zt,{size:12})," Savingâ¦"]}):Ft?e.jsxs(e.Fragment,{children:[e.jsx(Zt,{size:12})," Generatingâ¦"]}
53):U.type==="routine"?"Create routine":"Add workflow"})]})]})}),e.jsx(Vm,{open:ne.connectDialogOpen,onOpenChange:s=>{s||ne.closePluginConnect()},plugin:ne.connectPlugin,orgId:ne.orgId,composioConfigured:ne.composioConfigured,composioKeyInvalid:ne.composioKeyInvalid,connected:ne.connectPlugin?Gc(ne.connectPlugin.id,ne.connectedSlugs):!1,onConnected:ne.handlePluginConnected})]})}export{Uh as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.