@hearsay-tools/squawk 0.19.0-pr4422.8666 → 0.19.0-pr4422.8708

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/automations/tools.d.ts +8 -8
  2. package/dist/ci-wait/controller.d.ts +7 -7
  3. package/dist/contract/index.js +55 -14
  4. package/dist/contract/runs.d.ts +50 -0
  5. package/dist/contract/workspace-events.d.ts +18 -0
  6. package/dist/delegation/routes.d.ts +65 -65
  7. package/dist/delegation/transport.d.ts +14 -14
  8. package/dist/preview/chromium.d.ts +3 -2
  9. package/dist/preview/chromium.js +5 -1
  10. package/dist/preview/chromium.js.map +1 -1
  11. package/dist/runs/run-database.d.ts +5 -0
  12. package/dist/runs/run-database.js +5 -0
  13. package/dist/runs/run-database.js.map +1 -1
  14. package/dist/runs/run-queries.d.ts +9 -0
  15. package/dist/runs/run-queries.js +43 -6
  16. package/dist/runs/run-queries.js.map +1 -1
  17. package/dist/runs/store.js +1 -0
  18. package/dist/runs/store.js.map +1 -1
  19. package/dist/runs/transcript-facts-queue.d.ts +9 -1
  20. package/dist/runs/transcript-facts-queue.js +43 -10
  21. package/dist/runs/transcript-facts-queue.js.map +1 -1
  22. package/dist/runs/transcript-facts-sidecar.d.ts +22 -0
  23. package/dist/runs/transcript-facts-sidecar.js +58 -0
  24. package/dist/runs/transcript-facts-sidecar.js.map +1 -0
  25. package/dist/runs/transcript-facts-topic.d.ts +2 -0
  26. package/dist/runs/transcript-facts-topic.js +8 -10
  27. package/dist/runs/transcript-facts-topic.js.map +1 -1
  28. package/dist/runs/transcript-facts-worker.d.ts +7 -2
  29. package/dist/runs/transcript-facts-worker.js +8 -5
  30. package/dist/runs/transcript-facts-worker.js.map +1 -1
  31. package/dist/runs/transcript-facts.d.ts +4 -0
  32. package/dist/runs/transcript-facts.js +36 -16
  33. package/dist/runs/transcript-facts.js.map +1 -1
  34. package/dist/server/automations-routes.d.ts +150 -150
  35. package/dist/server/live-routes.d.ts +6 -6
  36. package/dist/server/models-routes.d.ts +12 -12
  37. package/dist/server/project-settings-routes.d.ts +107 -107
  38. package/dist/server/providers-routes.d.ts +57 -57
  39. package/dist/server/repo-routes.d.ts +34 -34
  40. package/dist/server/runner-install-routes.d.ts +10 -10
  41. package/dist/server/runners-routes.d.ts +10 -10
  42. package/dist/server/runs-routes.d.ts +24 -16
  43. package/dist/server/server.d.ts +1622 -1598
  44. package/dist/server/workspace-live-routes.d.ts +6 -6
  45. package/dist/server/workspace-routes.d.ts +92 -84
  46. package/package.json +4 -4
  47. package/scripts/measure-transcript-facts-health.mjs +10 -5
  48. package/scripts/measure-transcript-facts-lag.mjs +11 -2
  49. package/scripts/mock-ci-tool.mjs +4 -5
  50. package/scripts/transcript-facts-timing.mjs +10 -0
  51. package/web/dist/assets/{accounts-section-DrBRvg0M.js → accounts-section-De2qXAo-.js} +1 -1
  52. package/web/dist/assets/activity-motion-EJBR3wlq.js +1 -0
  53. package/web/dist/assets/{activity-route-CRu58Zj9.js → activity-route-6cQ_MX2v.js} +1 -1
  54. package/web/dist/assets/{agent-config-section-DXLXyPzF.js → agent-config-section-DFP2-YWs.js} +1 -1
  55. package/web/dist/assets/{agent-defaults-section-MHwKLUxx.js → agent-defaults-section-D88m66PJ.js} +1 -1
  56. package/web/dist/assets/{appearance-Dk8ikc1j.js → appearance-BwV8iZFM.js} +1 -1
  57. package/web/dist/assets/{archive-on-merge-field-CRGCTE05.js → archive-on-merge-field-BzFhSzxv.js} +1 -1
  58. package/web/dist/assets/attention--Y0CyzCN.js +1 -0
  59. package/web/dist/assets/{automations-route-2Z1J6aVz.js → automations-route-Cuz2CxlC.js} +2 -2
  60. package/web/dist/assets/commit-list-D8yY5bIe.js +1 -0
  61. package/web/dist/assets/diff-BBr7hIpt.js +3 -0
  62. package/web/dist/assets/{diff-controls-U3q_bktr.js → diff-controls-PEQLG-Zu.js} +1 -1
  63. package/web/dist/assets/diff-stat-U7DT4Ilj.js +1 -0
  64. package/web/dist/assets/{diff-view-BaEIMlyb.js → diff-view-Dma7qveY.js} +1 -1
  65. package/web/dist/assets/{file-preview-LgaV6Wwo.js → file-preview-DXB5mwQq.js} +1 -1
  66. package/web/dist/assets/{folder-browser-D_V807qp.js → folder-browser-CF2Sk1aR.js} +1 -1
  67. package/web/dist/assets/git-toolbar-dRjJ3sJQ.js +1 -0
  68. package/web/dist/assets/github-CLbTpdZ7.js +1 -0
  69. package/web/dist/assets/{global-activity-route-CrRAIAo1.js → global-activity-route-BXwZUqR8.js} +2 -2
  70. package/web/dist/assets/image-preview-2S3PEy8S.js +1 -0
  71. package/web/dist/assets/index-1TLdjVro.css +1 -0
  72. package/web/dist/assets/index-7Rg7tdSP.js +21 -0
  73. package/web/dist/assets/{label-C6BpWk0J.js → label-Bgcri58t.js} +1 -1
  74. package/web/dist/assets/{markdown-BVqO9ORd.js → markdown-gNAPnLDC.js} +1 -1
  75. package/web/dist/assets/{notifications-section-CliGeYkh.js → notifications-section-CnjarooH.js} +1 -1
  76. package/web/dist/assets/{open-in-menu-BkmmqWdB.js → open-in-menu-Qylys2X_.js} +1 -1
  77. package/web/dist/assets/{preview-pane-connected-Bg56dRpV.js → preview-pane-connected-CimzK7Qz.js} +2 -2
  78. package/web/dist/assets/{project-location-Z28U6-d1.js → project-location-n15GhUq1.js} +1 -1
  79. package/web/dist/assets/{project-router-B8blqSVo.js → project-router-CT6gVIcC.js} +1 -1
  80. package/web/dist/assets/{projects-section-DSNxCSOR.js → projects-section-DiaRaoyV.js} +1 -1
  81. package/web/dist/assets/{prompt-templates-section-BBGVLRbE.js → prompt-templates-section-5UJStA2u.js} +1 -1
  82. package/web/dist/assets/{queries-BwJVP1so.js → queries-BddxDJyD.js} +1 -1
  83. package/web/dist/assets/{reference-chip-uLQTF-sm.js → reference-chip-BGFxuvs6.js} +1 -1
  84. package/web/dist/assets/{remote-settings-notice-7BteeZ5o.js → remote-settings-notice-ihbrhzlZ.js} +1 -1
  85. package/web/dist/assets/repo-git-DaKHEjDf.js +1 -0
  86. package/web/dist/assets/{report-reader-Be9J9B79.js → report-reader-8B7MnBnV.js} +1 -1
  87. package/web/dist/assets/{report-selection-DBM7S3ha.js → report-selection-BwiY8hK3.js} +1 -1
  88. package/web/dist/assets/{reports-BOiZGsQR.js → reports-BeOzwtBO.js} +1 -1
  89. package/web/dist/assets/{resources-section-B3kPFCJY.js → resources-section-D2tex4pF.js} +1 -1
  90. package/web/dist/assets/review-panel-YwUoKsbu.js +8 -0
  91. package/web/dist/assets/{run-detail-refresh-YR2-iM4z.js → run-detail-refresh-C8P2J7Wq.js} +1 -1
  92. package/web/dist/assets/{run-header-BG-RicJl.js → run-header-CkhPOV1B.js} +2 -2
  93. package/web/dist/assets/{select-Be4wVHHG.js → select-BXpAjbYk.js} +1 -1
  94. package/web/dist/assets/{session-context-section-DdCeADhA.js → session-context-section-DkhGlKdR.js} +2 -2
  95. package/web/dist/assets/{settings-agent-picker-C4hz36AY.js → settings-agent-picker-3cUJmNQz.js} +1 -1
  96. package/web/dist/assets/{settings-shell-BluR2G4L.js → settings-shell-D--QpDPG.js} +1 -1
  97. package/web/dist/assets/{sidebar-section-Bo1FJw3L.js → sidebar-section-BydWRh8S.js} +1 -1
  98. package/web/dist/assets/{skills-DWVky-g5.js → skills-CbEyPyvn.js} +1 -1
  99. package/web/dist/assets/{tab-link-BkHBgpdC.js → tab-link-DE6t7XkG.js} +1 -1
  100. package/web/dist/assets/task-changes-BXDJmZkO.js +1 -0
  101. package/web/dist/assets/task-commits-B4uUhWjt.js +1 -0
  102. package/web/dist/assets/{task-files-BtAxAAcl.js → task-files-vOSCBpIt.js} +1 -1
  103. package/web/dist/assets/{task-github-item-DFD4xHYk.js → task-github-item-BIaOF-Ea.js} +1 -1
  104. package/web/dist/assets/{task-groups-BSovus2j.js → task-groups-CHHLB77I.js} +1 -1
  105. package/web/dist/assets/task-thread-MKnHdrU1.js +2 -0
  106. package/web/dist/assets/{tasks-table-C-wxALy6.js → tasks-table-5GNEZlxs.js} +1 -1
  107. package/web/dist/assets/{thread-state-DyYOz-Ad.js → thread-state-BtUboBbd.js} +1 -1
  108. package/web/dist/assets/{toaster-UvSCLhYx.js → toaster-C-xqAWVX.js} +2 -2
  109. package/web/dist/assets/use-hand-to-agent-state-BwQ45AKw.js +1 -0
  110. package/web/dist/assets/{workflows-C4UY4ka5.js → workflows-DUoxhR8h.js} +3 -3
  111. package/web/dist/assets/{workspace-tools-BMtjV-oC.js → workspace-tools-dwQmpL6C.js} +1 -1
  112. package/web/dist/assets/{worktrees-section-Bntdbzrl.js → worktrees-section-B9LR3yvO.js} +1 -1
  113. package/web/dist/index.html +16 -15
  114. package/web/dist/assets/activity-motion-DyczKxjj.js +0 -1
  115. package/web/dist/assets/attention-CXG_AzDe.js +0 -1
  116. package/web/dist/assets/commit-list-CjmYvVCK.js +0 -1
  117. package/web/dist/assets/diff-B1RHxCxU.js +0 -3
  118. package/web/dist/assets/git-toolbar-DyQaOcLy.js +0 -1
  119. package/web/dist/assets/github-DYLq16Wk.js +0 -1
  120. package/web/dist/assets/image-preview-OjGspLQY.js +0 -1
  121. package/web/dist/assets/index-AgYIT7cV.js +0 -21
  122. package/web/dist/assets/index-DTMSoiHJ.css +0 -1
  123. package/web/dist/assets/repo-git-DiNgzGWX.js +0 -1
  124. package/web/dist/assets/review-panel-CQp83gYh.js +0 -8
  125. package/web/dist/assets/task-changes-2yAaEJQ_.js +0 -1
  126. package/web/dist/assets/task-commits-02w8Ivwi.js +0 -1
  127. package/web/dist/assets/task-thread-Ck75x2Rd.js +0 -2
  128. package/web/dist/assets/use-hand-to-agent-state-BfQx2nM5.js +0 -1
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,r as n,t as r}from"./react-runtime-CCIEwYL0.js";import{n as i,t as a}from"./utils-DSMR_WLb.js";import{G as o,J as s,R as c,Ut as l,V as u,Wt as d,Xt as f,Y as p,_ as m,dn as h,dt as g,ln as _,lt as v,nt as y,ot as b,rn as x,rt as S,sn as ee,un as C,xt as w,yt as T,z as E}from"./queries-BddxDJyD.js";import{$r as D,An as O,At as te,Fn as k,Nn as A,Pn as j,Qn as M,Xn as N,Yn as P,Zn as ne,ei as F,hi as I,ii as L,it as R,lt as z,n as B,ot as V,rt as H,tr as U,vr as re,yr as ie}from"./toaster-C-xqAWVX.js";import{f as ae,h as W,n as oe}from"./chunk-KS7C4IRE-Cg8l-LDN.js";import{d as se,m as ce,r as le,s as ue,v as de}from"./tasks-table-5GNEZlxs.js";import{A as fe,B as pe,a as me,f as he,g as G,h as ge,it as _e,k as ve,l as ye,m as K,n as be,ot as xe,p as Se,s as Ce,u as we,ut as Te,y as Ee,z as De}from"./design-icons-CzEoMH9c.js";import{t as Oe}from"./createLucideIcon-BHp8sXmF.js";import{A as ke,B as Ae,C as je,D as Me,E as Ne,F as Pe,H as Fe,I as Ie,L as Le,M as Re,N as ze,O as Be,P as Ve,R as He,S as Ue,T as We,V as Ge,_ as Ke,a as qe,b as Je,c as Ye,d as Xe,f as Ze,g as Qe,h as $e,i as et,j as tt,k as nt,l as rt,m as it,n as at,o as ot,p as st,r as ct,s as lt,t as ut,u as dt,v as ft,w as pt,x as mt,y as ht,z as gt}from"./review-panel-YwUoKsbu.js";import{a as _t,c as vt,i as yt,n as bt,o as xt,r as St,s as Ct,t as wt}from"./run-header-CkhPOV1B.js";import{t as Tt}from"./loader-circle-CPBhhDbB.js";import{a as Et}from"./tool-display-B9NN44oU.js";import{i as Dt,l as Ot,o as kt,t as At}from"./reference-chip-BGFxuvs6.js";import{a as jt,i as Mt,n as Nt,o as Pt,r as Ft,t as It}from"./thread-state-BtUboBbd.js";import{t as q}from"./button-B7MKxYjT.js";import{n as Lt,r as Rt,t as zt}from"./collapsible-BEV4FO-1.js";import{a as Bt}from"./popover-BPgUYFyu.js";import{s as Vt,t as Ht}from"./project-router-CT6gVIcC.js";import"./attention--Y0CyzCN.js";import{D as Ut,E as Wt,O as Gt,S as Kt,b as qt,f as J,u as Jt,w as Yt,x as Xt}from"./task-groups-CHHLB77I.js";import{t as Zt}from"./status-dot-BRzVlF2X.js";import{c as Qt,i as $t,l as en,o as tn,r as nn,s as rn,t as an}from"./report-selection-BwiY8hK3.js";import{c as on}from"./page-shell-7pLJMOgh.js";import{t as sn}from"./centered-state-V15AR_qo.js";import{$t as cn,A as ln,H as un,M as dn,N as fn,Tn as pn,U as mn,W as hn,Zt as gn,_n,cn as vn,dn as yn,hn as bn,i as xn,j as Sn,k as Cn,l as wn,ln as Tn,m as En,mn as Dn,n as On,nn as kn,on as An,q as jn,rn as Mn,s as Nn,sn as Pn,wn as Fn,y as In}from"./index-7Rg7tdSP.js";import{t as Ln}from"./markdown-gNAPnLDC.js";import{i as Rn}from"./automation-format-DB34jUyF.js";var zn=Oe(`chart-column`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`M18 17V9`,key:`2bz60n`}],[`path`,{d:`M13 17V5`,key:`1frdt8`}],[`path`,{d:`M8 17v-3`,key:`17ska0`}]]),Bn=Oe(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),Y=e(t(),1),X=r(),Vn=12;function Hn({run:e}){let t=I(),n=h({mutationFn:()=>H(e.id),onSuccess:()=>{t.invalidateQueries({queryKey:d.runs.detail(e.id)}),t.invalidateQueries({queryKey:d.runs.list()}),B(`This task will not resume itself`)},onError:e=>B(e.message,{tone:`danger`})});if(!U(e))return null;let r=new Date(e.autoResumeAt);if(!Number.isFinite(r.getTime()))return null;let i=new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`long`}).format(r);return(0,X.jsxs)(`div`,{"data-slot":`auto-resume-hint`,role:`status`,className:`flex flex-wrap items-center gap-x-2 gap-y-1 px-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(Zt,{tone:`neutral`,shape:`ring`}),e.autoResumeReason===`provider-error`?(0,X.jsxs)(`span`,{title:e.error,children:[`Provider error — this task retries automatically at`,` `,(0,X.jsx)(`time`,{dateTime:e.autoResumeAt,className:`font-medium text-foreground`,children:i}),` `,`(attempt `,(e.autoResumeAttempts??0)+1,` of `,Vn,`)`]}):(0,X.jsxs)(`span`,{children:[`Usage limit reached — this task resumes automatically at`,` `,(0,X.jsx)(`time`,{dateTime:e.autoResumeAt,className:`font-medium text-foreground`,children:i})]}),(0,X.jsx)(`button`,{type:`button`,"data-action":`auto-resume-cancel`,disabled:n.isPending,onClick:()=>n.mutate(),className:`font-medium text-foreground underline decoration-border underline-offset-2 hover:decoration-foreground disabled:opacity-50`,children:`Don’t resume`}),(0,X.jsx)(oe,{to:`/settings/global/resources`,"data-slot":`auto-resume-settings-link`,className:`font-medium text-foreground underline decoration-border underline-offset-2 hover:decoration-foreground`,children:`Auto-resume settings`})]})}function Un(e,t,n,r,i,a,o,s,c){let l=Gt(e,Mn(e)),u=l?l.model:e.model,d=l?l.effort:e.effort,f=!r&&!n&&u?{...i?.defaultModels,[t]:u}:i?.defaultModels,p=r?null:s,m=Sn(t,o,a,[p,f?.[t]]),h=fn(p,t,o,f,a),g=ln(h,a),_=r?``:c??d??``,v=dn(_,g);return{models:m,model:h,effortOptions:g,effort:v,mustClearStoredEffort:!r&&c===null&&_!==``&&v===``}}function Wn(e,t,n,r){let i=Wt(e.steps),a=Gt(e,Mn(e)),o=a?.agentProfile??e.agentProfile??i?.profileId??`default`;return{sessionStep:i,workerStep:a,account:n?r?.[t]??`default`:o}}function Gn(e,t,n,r,i,a,o,{model:s,effort:c,mustClearStoredEffort:l}){return{text:e.trim()?e:void 0,images:t.length?t:void 0,runner:n,model:!r&&(a!==null||i)?s:void 0,effort:!r&&(o!==null||i)?c:l?``:void 0}}function Kn(e,t,n,r){return!!t&&(r!==Ut(t,e)||(n?.agentProfile??e.agentProfile??t.profileId??`default`)!==(t.profileId??`default`))}function qn({models:e,model:t,effortOptions:n,effort:r}){return{modelLabel:e.find(e=>e.id===t)?.label??`auto`,effortLabel:n.find(e=>e.value===r)?.label??`auto`}}function Jn(e){let t=v(),n=Tn(e).continueRun,r=m(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),u=`${e.id}:${Gt(e,Mn(e))?.id??``}`,[d,p]=(0,Y.useState)(u);d!==u&&(p(u),a(null),s(null),l(null));let g=et(e,i),{runners:_,canContinue:y,currentRunner:b,runner:S}=g,{sessionStep:w,workerStep:E,account:D}=Wn(e,S,S!==b,_n().repoAccount),O=T(),te=O.data?.capabilities?.localHandoff!==!1,A=x(),j=ee(S,n&&!O.isPending&&!A.isPending,te?D:null),M=r.data?.modelsLocked===!0,N=S!==b,P=Un(e,S,N,M,r.data,j.data,A.data,o,c),{models:ne,model:F,effortOptions:I,effort:L}=P,{modelLabel:R,effortLabel:z}=qn(P),B=h({mutationFn:({text:t,images:n})=>y?V(C(e.id),Gn(t,n,g.runnerOverride,M,N,o,c,P)):Promise.reject(Error(g.reason??`Connect an agent provider to continue.`)),onMutate:()=>C(e.id),onSuccess:(e,n,r)=>t.invalidateAfter(`continue`,r),onError:(e,n,r)=>{e instanceof k&&e.status===409&&r&&t.invalidateAfter(`continue`,r)}}),H=e.delegation?.role===`worker`;return{skillRunner:S,skillAccount:D,available:n,canContinue:y,startsNewConversation:Kn(e,w,E,S),reason:g.reason,providerPending:g.providerPending,pills:(0,X.jsx)(Yn,{compact:e.status===`review`,summary:`${f(A.data,S)} · ${R} · ${z}`,children:(0,X.jsxs)(mn,{children:[!H&&(_.length>1||g.signedOut.length>0)?(0,X.jsx)(hn,{icon:(0,X.jsx)(_e,{"aria-hidden":`true`,className:`size-[18px] shrink-0 text-accent-text`}),fieldLabel:!0,runners:_,signedOut:g.signedOut,value:S,onPick:e=>{e!==S&&(a(e),s(null))}}):(0,X.jsx)(un,{icon:(0,X.jsx)(_e,{"aria-hidden":`true`,className:`size-[18px] shrink-0 text-accent-text`}),fieldLabel:!0,readOnly:!0,disabledHint:H?`Owned workers keep their runner; change model or effort instead.`:void 0,slot:`session-runner-value`,ariaLabel:`Runner`,label:S,value:S,onPick:()=>{},options:[{value:S,label:S}]}),(0,X.jsx)(un,{icon:(0,X.jsx)(Ee,{"aria-hidden":`true`,className:`size-[18px] shrink-0 text-accent-text`}),fieldLabel:!0,slot:`follow-up-model-pill`,ariaLabel:`Model`,label:R,value:F,readOnly:M,disabledHint:`Model selection is locked to native coding-agent settings.`,onPick:e=>{s(e);let t=ln(e,j.data);L!==``&&dn(L,t)===``&&l(``)},options:ne.map(e=>({value:e.id,label:e.label,desc:e.desc})),status:Cn(S,A.data,j)}),(0,X.jsx)(un,{icon:(0,X.jsx)(ve,{"aria-hidden":`true`,className:`size-[18px] shrink-0 text-accent-text`}),fieldLabel:!0,slot:`follow-up-effort-pill`,ariaLabel:`Effort`,label:z,value:L,readOnly:M,disabledHint:`Effort selection is locked to native coding-agent settings.`,onPick:e=>l(e),options:I.map(e=>({value:e.value,label:e.label,desc:e.desc}))})]})},u),continueWith:(e,t)=>B.mutateAsync({text:e,images:t})}}function Yn({compact:e,summary:t,children:n}){let[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),o=e&&!r;return(0,Y.useEffect)(()=>{r&&a.current?.querySelector(`button:not([disabled])`)?.focus()},[r]),(0,X.jsx)(`div`,{ref:a,"data-slot":`follow-up-engine`,"data-folded":o||void 0,className:o?`min-w-0`:`session-engine-controls`,children:o?(0,X.jsxs)(`button`,{type:`button`,"data-slot":`follow-up-engine-summary`,"aria-expanded":!1,"aria-label":`Agent settings: ${t}`,title:`Change the runner, model or effort`,onClick:()=>i(!0),className:`inline-flex min-h-11 max-w-full min-w-0 items-center gap-1.5 rounded-md px-2 text-xs text-muted-foreground transition-colors outline-hidden hover:bg-muted hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50`,children:[(0,X.jsx)(_e,{"aria-hidden":`true`,className:`size-4 shrink-0 text-accent-text`}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:t}),(0,X.jsx)(ye,{"aria-hidden":`true`,className:`size-3.5 shrink-0`})]}):n})}var Xn=120,Zn=e=>e!==`pending`&&e!==`running`,Qn=e=>e.kind===`tool`&&e.toolKind===`task`,$n=e=>Qn(e)&&e.parentItemId===void 0,er=e=>Le(e.kind)&&!(e.kind===`tool`&&e.toolKind===`plan`);function tr(e){let t=e.input;if(typeof t!=`object`||!t)return;let n=t;for(let e of[`subagent_type`,`subagentType`,`agent`]){let t=n[e];if(typeof t==`string`&&t.trim()!==``)return t.trim()}}function nr(e){if(e.kind===`tool`)return rr(e.title);if(e.kind===`hook`)return rr(`${e.event} hook${e.status===`completed`?``:` ${e.status}`}`);if(e.kind===`message`||e.kind===`reasoning`){let t=e.text.split(`
2
+ `);for(let e=t.length-1;e>=0;--e){let n=t[e].trim();if(n!==``)return rr(n)}}}function rr(e){return e.length>Xn?`${e.slice(0,Xn-1).trimEnd()}…`:e}function ir(e,t=!1,n=e){let r=cr(e,e=>e.items.some($n));if(r===-1)return[];let i=e=>!t&&!Zn(e.status),a=e=>i(e)&&e.background===!0,o=[],s=!1;for(let t=r-1;t>=0;--t){let n=e[t].items.filter($n);n.length!==0&&(!s&&!n.some(i)&&(s=!0),(!s||n.some(a))&&o.unshift(...n))}let c=[...o,...e[r].items.filter($n)];return r!==e.length-1&&!c.some(i)?[]:c.map(r=>ar(r,fr(n,e,r.id),t))}function ar(e,t,n){let r={id:e.id,title:Ie(e.title).detail??e.title,status:e.status,toolCalls:t.filter(e=>e.kind===`tool`).length},i=tr(e);i!==void 0&&(r.agentType=i),n&&!Zn(e.status)&&(r.stalled=!0);for(let e=t.length-1;e>=0;--e){let n=nr(t[e]);if(n!==void 0){r.activity=n;break}}return r}function or(e){return{done:e.filter(e=>e.status===`completed`).length,total:e.length}}function sr(e){return e.activity??(e.stalled===!0?`never finished`:`starting…`)}function cr(e,t){for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1}function lr(e,t,n=!1,r=e){for(let i=e.length-1;i>=0;--i){let a=e[i].items.find(e=>e.id===t&&$n(e));if(a!==void 0)return ar(a,fr(r,e,t),n)}}function ur(e,t){return cr(e,e=>e.items.some(e=>e.id===t&&$n(e)))}function dr(e,t,n){let r=[];for(let i=n;i<e.length;i+=1){let n=e[i];for(let e of n.items)er(e)&&e.parentItemId===t&&e.id!==t&&r.push({entry:e,seqs:n.itemSeqs?.get(e.id)})}return r}function fr(e,t,n){let r=ur(t,n);if(r===-1)return[];let i=dr(t,n,r);if(e===t)return i.map(({entry:e})=>e);let a=t[r].itemSeqs?.get(n)?.first,o=e=>a===void 0||e.seqs===void 0||e.seqs.first>a,s=new Map;for(let t of dr(e,n,Math.max(ur(e,n),0)))o(t)&&!s.has(t.entry.id)&&s.set(t.entry.id,t);for(let e of i){let t=s.get(e.entry.id);s.set(e.entry.id,t===void 0?e:pr(t,e))}return[...s.values()].sort(mr).map(({entry:e})=>e)}function pr(e,t){return e.seqs===void 0||t.seqs===void 0?e:{entry:(t.seqs.last>e.seqs.last?t:e).entry,seqs:{first:Math.min(e.seqs.first,t.seqs.first),last:Math.max(e.seqs.last,t.seqs.last)}}}function mr(e,t){return e.seqs===void 0||t.seqs===void 0?0:e.seqs.first-t.seqs.first}function hr(e,t){if(e.kind===`entry`){let n=e.entry;return n.kind===`message`&&n.role===`assistant`?[{messageKey:`${t}:${n.id}`,text:n.text}]:[]}return e.kind===`tool-card`?Pe(e.children).flatMap(n=>hr(n,`${t}:${e.id}`)):e.kind===`streak`?e.blocks.flatMap(e=>hr(e,t)):[]}function gr(e){return e.flatMap((e,t)=>e.content.kind===`block`?hr(e.content.block,e.scope).map(n=>({...n,rowKey:e.key,rowIndex:t})):[])}function _r(e,t,n,r){let i=(0,Y.useContext)(an),{projectId:a}=W(),o=(0,Y.useMemo)(()=>gr(t),[t]);(0,Y.useLayoutEffect)(()=>{if(!i)return;let t=[],s={runId:e,...a?{projectId:a}:{}};for(let e of o){let a=Ge(e.text,s);for(let e of a)t.push(i.register(e.artifactId,e.runId));r===`document`&&a.length>0&&t.push(i.registerOpener(e.messageKey,(t,r)=>{let i=Ae(e.messageKey,t);n.jumpToRow(e.rowKey,e.rowIndex,e=>[...e.querySelectorAll(`[id]`)].find(e=>e.id===i)??null,r)}))}return()=>{for(let e of t)e()}},[i,o,e,a,r,n.jumpToRow])}function vr(e){let t=I();return h({mutationFn:t=>z(e,t),retry:!1,networkMode:`always`,onSettled:()=>{t.invalidateQueries({queryKey:d.runs.all})}})}var yr=e=>(window.addEventListener(`online`,e),window.addEventListener(`offline`,e),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,e)}),br=()=>navigator.onLine;function xr({permission:e,runId:t,sessionOpen:n=!1}){return e.status!==`pending`||!n?(0,X.jsx)(Cr,{permission:e,state:e.status===`resolved`?`resolved`:`expired`}):(0,X.jsx)(Sr,{permission:e,runId:t},e.requestId)}function Sr({permission:e,runId:t}){let n=vr(t),r=(0,Y.useSyncExternalStore)(yr,br,()=>!1),i=(0,Y.useRef)(!1),[a,o]=(0,Y.useState)(`pending`),[s,c]=(0,Y.useState)(),[l,u]=(0,Y.useState)(),d=async t=>{if(!(i.current||!r||a!==`pending`)){i.current=!0,o(`sending`),u(void 0);try{await n.mutateAsync({requestId:e.requestId,optionId:t}),c(t),o(`resolved`)}catch(e){e instanceof k&&e.status===409?o(`expired`):(u(e instanceof Error?e.message:String(e)),o(`pending`))}finally{i.current=!1}}};return(0,X.jsx)(Cr,{permission:{...e,...s===void 0?{}:{optionId:s}},state:a,offline:!r,error:l,onSelect:e=>{d(e)}})}function Cr({permission:e,state:t,offline:n=!1,error:r,onSelect:i}){let a=(0,Y.useId)(),o=e.options.find(t=>t.id===e.optionId),s=t!==`pending`||n||!i,c=t===`expired`?`Approval expired. This session can no longer accept a decision.`:t===`resolved`?`Decision sent: ${o?.label??`Recorded`}.`:t===`sending`?`Sending decision…`:n?`Offline. Reconnect to send a decision.`:`Choose an option to respond to this permission request.`;return(0,X.jsxs)(`section`,{"data-slot":`permission-card`,"data-request-id":e.requestId,"data-state":n&&t===`pending`?`offline`:t,"aria-labelledby":a,"aria-busy":t===`sending`,className:`flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-card p-3.5 text-sm [overflow-wrap:anywhere]`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Permission request`}),(0,X.jsx)(`h3`,{id:a,className:`font-semibold whitespace-pre-wrap`,children:e.title})]}),e.details?(0,X.jsx)(`pre`,{className:`min-w-0 font-mono text-xs leading-relaxed whitespace-pre-wrap [overflow-wrap:anywhere]`,children:e.details}):null,(0,X.jsx)(`div`,{role:`group`,"aria-labelledby":a,className:`flex min-w-0 flex-col gap-2`,children:e.options.map(t=>(0,X.jsx)(q,{type:`button`,variant:`outline`,disabled:s,"aria-pressed":e.optionId===t.id,className:`h-auto min-h-11 min-w-0 max-w-full justify-start py-2 text-start whitespace-normal [overflow-wrap:anywhere] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring`,onClick:()=>i?.(t.id),children:t.label},t.id))}),(0,X.jsxs)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:[c,e.reason?` ${e.reason}`:``]}),r&&t===`pending`?(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:r}):null]})}var wr=(0,Y.createContext)({targets:new Map,replies:new Map,navigate:()=>{}});function Tr(e,t){let n={};for(let e of t??[])n[e.id]=e.currentStepBackend??e.runner;return n[e.id]=e.steps.find(t=>t.id===e.currentStepId)?.backend??e.runner,n}function Er(e,t,n=[]){let r={};for(let e of n)r[e.id]=J(e);for(let e of t??[])r[e.id]=J(e);return r[e.id]=J(e),r}function Dr(e,t){return t?.[e]??`Task`}function Or(e,t,n){return t?n?.[e]??`peer task`:Dr(e,n)}function kr(e,t){return e.senderRunId===t?`outbound`:`inbound`}function Ar(e){return e?.relationship===`peer`}function jr(e){switch(e){case`request`:return`Request`;case`progress`:return`Progress`;case`follow-up`:return`Follow-up`;case`reply`:return`Reply`}}function Mr(e){switch(e){case`pending`:return`Pending`;case`replied`:return`Replied`;case`replied-late`:return`Replied late`;case`timed-out`:return`Timed out`;case`cancelled`:return`Cancelled`;case`completed-without-reply`:return`Completed without reply`;case`failed`:return`Failed`;case`destroyed`:return`Destroyed`;case`sender-closed`:return`Sender closed`;case`human-fallback`:return`Sent to a human`;case`deleted`:return`Recipient deleted`}}function Nr(e){if(e.outcome)return Mr(e.outcome.status);if(e.delivery===`not-delivered`)return Pr(`not-delivered`)}function Pr(e){switch(e){case`queued`:return`Queued`;case`delivered`:return`Delivered`;case`consumed`:return`Read`;case`not-delivered`:return`Not delivered`}}function Fr(e,t){return e.instruction===void 0?e.delivery===`queued`?`${t?`Queued for delivery. This agent can receive messages during its current turn.`:`Queued for delivery. Timing depends on the recipient agent.`} Pending messages are batched within the size limit; human questions and scheduler capacity can delay delivery.`:e.state===`continuation-required`?Ar(e)?`Not delivered. The recipient is not running. Only its human can continue it.`:`Not delivered. The recipient needs a new instruction to resume. A parent can resume its owned worker with ${Dn()} worker resume; workers cannot resume parents.`:e.state===`destroyed`?`Not delivered. This worker was destroyed.`:void 0:e.instruction}function Ir({id:e,peer:t,taskTitles:n,children:r}){return!t||n?.[e]!==void 0?r({title:Dr(e,n),linkable:!0}):(0,X.jsx)(Lr,{id:e,children:r})}function Lr({id:e,children:t}){let n=p(e);return n.data?t({title:J(n.data),linkable:!0}):n.isPending?t({title:`Peer task`,linkable:!1}):t({title:n.error instanceof k&&n.error.status===404?`Deleted task`:`Task unavailable`,linkable:!1})}var Rr={outbound:{classes:`border-message-outbound-border bg-message-outbound-bg [html:not(.light)_&]:border-s-[3px] [html:not(.light)_&]:border-s-message-outbound-accent`,accent:`text-message-outbound-accent`},inbound:{classes:`border-message-inbound-border bg-message-inbound-bg [html:not(.light)_&]:border-s-[3px] [html:not(.light)_&]:border-s-message-inbound-accent`,accent:`text-message-inbound-accent`},peer:{classes:`border-message-peer-border bg-message-peer-bg [html:not(.light)_&]:border-s-[3px] [html:not(.light)_&]:border-s-message-peer-accent`,accent:`text-message-peer-accent`}},zr=`inline-flex min-h-11 max-w-full items-center break-words underline underline-offset-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;function Br({block:e,runId:t,taskTitles:n,recipientBackends:r}){return(0,X.jsx)(`div`,{"data-slot":`worker-conversation`,className:`flex min-w-0 flex-col gap-2`,children:e.batches.map(e=>(0,X.jsx)(Vr,{batch:e,runId:t,taskTitles:n,recipientBackends:r},e.id))})}function Vr({batch:e,runId:t,taskTitles:n,recipientBackends:r}){let i=kr(e.messages[0]??{senderRunId:e.senderRunId},t),o=Ar(e.messages[0]),s=Rr[o?`peer`:i],c=Xr(e.messages.map(e=>i===`outbound`?e.recipientRunId:e.senderRunId)),l=i===`outbound`?`SENT to`:`RECEIVED from`,u=`${l} ${c.map(e=>Or(e,o,n)).join(`, `)}`,d=e.messages[0],f=d?.createdAt??d?.recordedAt;return(0,X.jsxs)(`article`,{"data-slot":`worker-conversation-card`,"data-direction":i,"data-relationship":o?`peer`:`family`,"data-kind":e.kind,className:a(`flex w-full min-w-0 flex-col gap-2 rounded-[8px] border p-3 md:px-4 md:py-[14px]`,s.classes),children:[(0,X.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-start gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`p`,{className:a(`m-0 flex min-w-0 flex-wrap items-center gap-x-2 text-[11px] leading-[1.2] font-semibold tracking-[0.6px] uppercase`,s.accent),children:[(0,X.jsx)(`span`,{children:l}),c.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-x-2 normal-case tracking-normal`,children:[t>0?(0,X.jsx)(`span`,{"aria-hidden":!0,children:`,`}):null,(0,X.jsx)(Ir,{id:e,peer:o,taskTitles:n,children:t=>(0,X.jsx)(Kr,{view:t,to:`/tasks/${e}`,label:`${l} ${t.title}`})})]},e))]}),o?(0,X.jsx)(`span`,{"data-slot":`conversation-relationship`,className:`rounded-full border border-message-peer-border px-2 py-0.5 text-[11px] font-semibold tracking-[0.05em] text-foreground uppercase`,children:`Peer`}):null,(0,X.jsx)(`span`,{"data-slot":`conversation-kind`,className:`rounded-full bg-background/60 px-2 py-0.5 text-[11px] font-semibold tracking-[0.05em] text-foreground uppercase`,children:jr(e.kind)}),e.messages.length===1&&d?(0,X.jsx)(Ur,{message:d}):null]}),(0,X.jsx)(Hr,{at:f,className:`flex shrink-0 items-center justify-self-end gap-1 whitespace-nowrap text-[11px] text-soft-foreground`,children:e.messages.length>1?`First sent`:null})]}),(0,X.jsx)(Gr,{batch:e},`${t}:${d?.messageId??e.id}`),[...new Set(e.messages.map(e=>Fr(e,r?.[e.recipientRunId])))].map(e=>e?(0,X.jsx)(`p`,{"data-slot":`conversation-delivery-explanation`,className:`min-w-0 text-xs leading-relaxed text-muted-foreground [overflow-wrap:anywhere]`,children:e},e):null),e.kind===`request`&&e.messages.length>1?(0,X.jsx)(Wr,{messages:e.messages,peer:o,runId:t,taskTitles:n}):null,e.messages.length===1&&d?(0,X.jsx)(qr,{message:d,runId:t,taskTitles:n}):null,(0,X.jsx)(Jr,{batch:e,heading:u})]})}function Hr({at:e,className:t,children:n}){return e===void 0||mt(e)===void 0?null:(0,X.jsxs)(`span`,{className:t,children:[n,(0,X.jsx)(ht,{ts:e})]})}function Ur({message:e}){let t=Nr(e),n=Pr(e.delivery),r=(e.messageKind===`request`||e.messageKind===`reply`)&&n!==t;return(0,X.jsxs)(X.Fragment,{children:[t?(0,X.jsx)(`span`,{"data-slot":`conversation-outcome`,className:`text-xs font-medium text-muted-foreground`,children:t}):null,r?(0,X.jsx)(`span`,{"data-slot":`conversation-delivery`,className:`text-xs text-muted-foreground`,children:n}):null]})}function Wr({messages:e,peer:t,runId:n,taskTitles:r}){return(0,X.jsx)(`ul`,{className:`grid min-w-0 gap-1 text-xs text-muted-foreground`,children:e.map(e=>{let i=Nr(e),a=e.createdAt??e.recordedAt;return(0,X.jsxs)(`li`,{className:`flex min-h-11 min-w-0 flex-wrap items-center gap-2`,children:[(0,X.jsx)(Ir,{id:e.recipientRunId,peer:t,taskTitles:r,children:t=>(0,X.jsx)(Kr,{view:t,to:`/tasks/${e.recipientRunId}`,label:`${t.title}${i?` — ${i}`:``}`})}),i?(0,X.jsx)(`span`,{"data-slot":`conversation-outcome`,children:i}):null,Pr(e.delivery)===i?null:(0,X.jsx)(`span`,{"data-slot":`conversation-delivery`,children:Pr(e.delivery)}),(0,X.jsx)(qr,{message:e,runId:n,taskTitles:r}),(0,X.jsx)(Hr,{at:a,className:`ml-auto whitespace-nowrap`})]},e.id)})})}function Gr({batch:e}){let t=Ve(),n=`conversation-body:${e.messages[0]?.messageId??e.id}`,[r,i]=(0,Y.useState)(()=>t?.get(n)??!1),a=(0,X.jsx)(`div`,{className:`min-w-0 break-words text-[14px] leading-[1.6] text-foreground select-text [overflow-wrap:anywhere]`,children:(0,X.jsx)(Ln,{breaks:!0,children:e.text})});return e.kind!==`request`&&e.kind!==`reply`?a:(0,X.jsxs)(zt,{"data-slot":`conversation-body`,open:r,onOpenChange:e=>{t?.set(n,e),i(e)},className:`min-w-0`,children:[(0,X.jsxs)(Rt,{type:`button`,"data-slot":`conversation-body-toggle`,className:`group/body inline-flex min-h-11 min-w-11 items-center gap-1.5 rounded-md px-2 text-start text-xs font-medium text-muted-foreground [@media(hover:hover)_and_(pointer:fine)]:hover:bg-background/40 [@media(hover:hover)_and_(pointer:fine)]:hover:text-foreground active:bg-background/60 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring`,children:[(0,X.jsx)(we,{"aria-hidden":!0,className:`size-3.5 shrink-0 group-data-[state=open]/body:rotate-90`}),r?`Hide message`:`Show message`]}),(0,X.jsx)(Lt,{children:a})]})}function Kr({view:e,to:t,label:n}){return e.linkable?(0,X.jsx)(Ht,{className:zr,to:t,"aria-label":n,children:e.title}):(0,X.jsx)(`span`,{"data-slot":`conversation-counterpart`,children:e.title})}function qr({message:e,runId:t,taskTitles:n}){let{targets:r,replies:i,navigate:o}=(0,Y.useContext)(wr),s=e.requestId?r.get(e.requestId):void 0,c=e.requestId?s?[s]:[]:i.get(e.messageId)??[],l=e.requestId?`request`:`reply`;return c.length===0?e.requestId||e.outcome?.replyId?(0,X.jsxs)(`p`,{"data-slot":`conversation-connector`,className:`text-xs text-muted-foreground`,children:[`Linked `,l,` is outside loaded history.`]}):null:c.map(e=>{let r=kr(e.message,t)===`outbound`,i=r?e.message.recipientRunId:e.message.senderRunId;return(0,X.jsxs)(`button`,{type:`button`,"data-slot":`conversation-connector`,className:a(zr,`w-fit gap-1.5 text-xs text-muted-foreground`),onClick:()=>o(e),children:[(0,X.jsx)(`span`,{"aria-hidden":!0,children:`↗`}),(0,X.jsx)(Ir,{id:i,peer:Ar(e.message),taskTitles:n,children:e=>(0,X.jsxs)(X.Fragment,{children:[`View `,l,` `,r?`to`:`from`,` `,e.title]})})]},e.message.messageId)})}function Jr({batch:e,heading:t}){return(0,X.jsxs)(zt,{"data-slot":`conversation-details`,className:`group/details`,children:[(0,X.jsxs)(Rt,{type:`button`,className:`inline-flex min-h-11 min-w-11 items-center gap-1.5 rounded-md px-2 text-left text-xs font-medium text-muted-foreground hover:bg-background/40 hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none`,children:[(0,X.jsx)(we,{"aria-hidden":!0,className:`size-3.5 shrink-0 transition-transform group-data-[state=open]/details:rotate-90`}),`Details`]}),(0,X.jsx)(Lt,{children:(0,X.jsxs)(`dl`,{className:`grid min-w-0 gap-1 break-all px-2 pb-1 font-mono text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`div`,{className:`sr-only`,children:t}),e.messages.flatMap(e=>Yr(e)).map((e,t)=>(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`dt`,{className:`inline font-sans font-medium text-soft-foreground`,children:[e.label,`: `]}),(0,X.jsx)(`dd`,{className:`inline`,children:e.value})]},`${e.label}:${e.value}:${t}`))]})})]})}function Yr(e){let t=[{label:`Message`,value:e.messageId},{label:`Sender`,value:e.senderRunId},{label:`Recipient`,value:e.recipientRunId},...Ar(e)?[{label:`Relationship`,value:`peer`}]:[],{label:`Delivery`,value:Pr(e.delivery)}];return e.requestId&&t.push({label:`Request`,value:e.requestId}),e.outcome?.replyId&&t.push({label:`Reply`,value:e.outcome.replyId}),e.state&&t.push({label:`State`,value:e.state}),e.createdAt&&t.push({label:`Created`,value:e.createdAt}),e.deliveredAt&&t.push({label:e.resumed?`Opening turn completed`:`Delivery acknowledged`,value:e.deliveredAt}),e.recordedAt&&t.push({label:`Event recorded`,value:e.recordedAt}),e.resumed&&t.push({label:`Continuation`,value:`Requested by parent with this instruction`}),e.deadline&&t.push({label:`Deadline`,value:e.deadline}),e.requestHash&&t.push({label:`Hash`,value:e.requestHash}),t}function Xr(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}var Zr=e(n(),1),Qr=`pending-ask`;function $r(e){return e.querySelector(`[data-slot="ask-question"] :is(button, textarea):not(:disabled)`)||(e.tabIndex=-1,e)}function ei(e){let t=e.querySelector(`[data-slot="ask-card"][data-pinned="true"]`);return t?$r(t):null}function ti(e,t){let n=`${Qr}:${e}`;return e=>{if(!t())return!1;let r=[...e.querySelectorAll(`[data-row-key]`)].find(e=>e.dataset.rowKey===n);return r?ei(r):null}}var ni=`[data-slot="ask-card"][data-pinned="true"]`;function ri(e,t){let[n,r]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e||typeof IntersectionObserver>`u`||typeof MutationObserver>`u`)return;let n=t.current??document.body,i=null,a=null,o=()=>{let e=n.querySelector(ni);if(e===i)return;if(a?.disconnect(),i=e,!i){r(!1);return}let t=document.querySelector(`[data-slot="thread-dock"]`),o=t&&getComputedStyle(t).position===`sticky`?Math.round(t.getBoundingClientRect().height):0;a=new IntersectionObserver(e=>r(e.some(e=>e.isIntersecting)),{rootMargin:`0px 0px -${o}px 0px`}),a.observe(i)};o();let s=new MutationObserver(o);return s.observe(n,{childList:!0,subtree:!0}),()=>{s.disconnect(),a?.disconnect()}},[e,t]),e&&n}function ii(e){return e<=0?`Jump to latest`:`Jump to latest (${e} ${e===1?`question`:`questions`} pending)`}function ai({onGoToQuestion:e}){return(0,X.jsxs)(`div`,{"data-slot":`ask-origin`,className:`flex flex-wrap items-center gap-x-2 rounded-lg border border-dashed border-accent-strong/40 px-3.5 py-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`font-medium text-link-foreground`,children:`Question asked here`}),(0,X.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,"data-slot":`ask-go-to-question`,className:`min-h-11 min-w-11 px-2 text-foreground underline underline-offset-4`,onClick:e,children:`Go to the question`})]})}function oi(){let e=(0,Y.useRef)(null);return(0,Y.useLayoutEffect)(()=>{let t=e.current,n=t?.closest(`[data-slot="main"]`),r=t?.querySelector(`[data-slot="run-header"]`),i=t?.querySelector(`[data-slot="thread-dock"]`);if(!n||!r||!i)return;let a=()=>{let e=r.querySelector(`[data-slot="run-tabs"]`),t=r.getBoundingClientRect();r.style.setProperty(`--run-header-lead`,`${e?Math.max(0,e.getBoundingClientRect().top-t.top):0}px`),n.style.setProperty(`--thread-viewport-height`,`${n.clientHeight}px`),n.style.setProperty(`--thread-header-height`,`${si(r)}px`),n.style.setProperty(`--thread-footer-height`,`${i.getBoundingClientRect().height}px`)};a();let o=new ResizeObserver(a);return o.observe(r),o.observe(i),o.observe(n),()=>{o.disconnect(),r.style.removeProperty(`--run-header-lead`),n.style.removeProperty(`--thread-header-height`),n.style.removeProperty(`--thread-footer-height`),n.style.removeProperty(`--thread-viewport-height`)}},[]),e}function si(e){let t=Number.parseFloat(getComputedStyle(e).insetBlockStart)||0;return Math.max(0,e.getBoundingClientRect().height+Math.min(0,t))}var Z={viewKey:void 0,generation:0},ci=600,li=24;function ui(e,t={}){let{surface:n=`document`,onLoadOlder:r,onJumpToLatest:i,rowKeys:a=[]}=t,o=(0,Y.useRef)(a);o.current=a;let s=(0,Y.useRef)(e);s.current=e;let c=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),m=(0,Y.useRef)(!0),h=(0,Y.useRef)(!0),g=(0,Y.useRef)(0),_=(0,Y.useRef)(0),v=(0,Y.useRef)(new Set),y=(0,Y.useCallback)(e=>{for(let t of[...v.current])t(e)},[]),b=(0,Y.useCallback)(e=>(v.current.add(e),()=>{v.current.delete(e)}),[]),x=(0,Y.useRef)(null),S=(0,Y.useRef)(null),ee=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=(0,Y.useCallback)(e=>{let t=c.current;if(!t)return;let n=C.current;n?n.scrollTo(e):t.scrollTop=e},[]),T=(0,Y.useCallback)(()=>{let e=c.current;if(!e)return;let t=h.current?o.current.findIndex(e=>e.startsWith(`pending-ask:`)):-1,n=h.current?e.querySelector(`[data-slot="ask-card"][data-pinned="true"][data-resolved="false"]`):null,r=e.querySelector(`[data-slot="run-header"]`),i=r&&getComputedStyle(r).position===`sticky`?si(r):0;n?w(e.scrollTop+n.getBoundingClientRect().top-e.getBoundingClientRect().top-i-12):t>=0&&C.current?C.current.scrollToIndex(t,{align:`start`,offset:-i-12}):w(e.scrollHeight-e.clientHeight)},[w]),E=(0,Y.useCallback)(()=>{if(c.current){if(ee.current!==e){ee.current=e,h.current=!0;let t=Be(e);t&&!t.atBottom?(m.current=!1,x.current=t.top,S.current=Ne(e)?.rowKeys?{viewKey:e,top:t.top}:null):(m.current=!0,x.current=null,S.current=null)}x.current===null?m.current&&T():w(x.current)}},[e,w,T]),D=(0,Y.useCallback)(e=>S.current?.viewKey===e,[]),O=(0,Y.useCallback)(e=>{let t=S.current;return!t||!D(e)||e!==s.current?!1:(x.current=t.top,m.current=!1,S.current=null,!0)},[D]),te=(0,Y.useCallback)(e=>{d(e),e&&(c.current=e.closest(n===`panel`?`[data-slot="transcript-viewport"]`:`[data-slot="main"]`),E())},[n,E]),k=(0,Y.useCallback)(()=>{m.current&&T()},[T]),A=(0,Y.useRef)(!1),j=(0,Y.useRef)(0),M=(0,Y.useRef)(!1),N=(0,Y.useRef)(void 0),P=(0,Y.useRef)(!1),ne=(0,Y.useRef)(!1),F=(0,Y.useCallback)(e=>[...e.querySelectorAll(`[data-slot="thread-row"][data-row-key]`)].map(e=>{let t=e.getBoundingClientRect();return{key:e.dataset.rowKey,top:t.top,bottom:t.bottom}}),[]),I=(0,Y.useRef)(null),L=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{if(!l())return;let e=e=>{x.current=null,S.current=null,L.current+=1,I.current=null,m.current=!1,h.current=!1,w(e)};return window.__cezThreadScrollTo=e,()=>{window.__cezThreadScrollTo===e&&delete window.__cezThreadScrollTo}},[w]);let R=(0,Y.useCallback)(()=>{let e=I.current,t=c.current;if(!e||!t)return;I.current=null;let n=e.beforeTop+Math.max(0,t.scrollHeight-e.beforeHeight),r=t.getBoundingClientRect().top,i=e.anchor===void 0?-1:o.current.indexOf(e.anchor.key),a=C.current;a&&i>=0?a.scrollToIndex(i,{align:`start`,offset:-e.anchor.offset}):w(tt(t.scrollTop,r,e.anchor,F(t),n))},[F,w]),z=(0,Y.useCallback)(()=>{let e=c.current;if(!e||!r||A.current)return;x.current=null,S.current=null,m.current=!1,A.current=!0;let t=j.current+1;j.current=t;let n=e.scrollHeight,i=e.scrollTop,a=e.getBoundingClientRect().top,l=je(a,F(e)),u=l===void 0?-1:o.current.indexOf(l.key),d=s.current,f=L.current;r().then(()=>{s.current===d&&L.current===f&&(I.current={beforeHeight:n,beforeTop:i,anchor:l,anchorIndex:u})},()=>{}).finally(()=>{j.current===t&&(A.current=!1)})},[F,r]);(0,Y.useEffect)(()=>()=>clearTimeout(N.current),[]);let B=(0,Y.useRef)(null),V=(0,Y.useRef)(0),H=(0,Y.useCallback)(()=>n===`document`?++Z.generation:++V.current,[n]),U=(0,Y.useCallback)((e,t)=>n===`document`?Z.viewKey===e&&Z.generation===t:s.current===e&&V.current===t,[n]);(0,Y.useEffect)(()=>()=>B.current?.disconnect(),[e,u]);let re=(0,Y.useCallback)((t,n,r,i)=>{let a=c.current;if(!a||!u)return;x.current=null,S.current=null,L.current+=1,I.current=null,m.current=!1,g.current=0,p(!0),H(),B.current?.disconnect();let o=()=>[...u.querySelectorAll(`[data-row-key]`)].find(e=>e.dataset.rowKey===t),s=()=>{let e=o();if(!e||getComputedStyle(e).visibility===`hidden`)return!1;let t=r?.(e)??e;return t===e&&(e.tabIndex=-1),t.focus({preventScroll:!0}),document.activeElement===t?(B.current?.disconnect(),!0):!1},l=a.querySelector(`[data-slot="run-header"]`),d=l&&getComputedStyle(l).position===`sticky`?si(l):0,f=C.current;if(i!==void 0)w(i);else if(f)f.scrollToIndex(n,{align:`start`,...d>0?{offset:-d}:{}});else{let e=o();e&&w(a.scrollTop+e.getBoundingClientRect().top-a.getBoundingClientRect().top-d)}s()||(B.current=new MutationObserver(()=>{s()}),B.current.observe(u,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`,`class`]})),ke(e,{top:i??a.scrollTop,atBottom:!1})},[u,w,e,H]),ie=(0,Y.useCallback)(t=>{let n=H(),r=s.current;B.current?.disconnect();let a=c.current;if(!a)return;x.current=null,S.current=null,L.current+=1,I.current=null,m.current=!0,h.current=!0,_.current=0,y({direction:`tail`}),ke(e,{top:a.scrollHeight-a.clientHeight,atBottom:!0});let o=()=>{m.current&&T()},l=()=>U(r,n),u=()=>{let e=t?.(a);return e===!1?!0:e?(e.focus({preventScroll:!0}),document.activeElement===e):!1};(i?.()??Promise.resolve()).finally(()=>{requestAnimationFrame(()=>{o(),requestAnimationFrame(()=>{if(o(),!t||!l()||u())return;B.current?.disconnect();let e=new MutationObserver(()=>{l()?u()&&e.disconnect():e.disconnect()});B.current=e,e.observe(a,{childList:!0,subtree:!0})})})})},[i,e,T,H,U,y]),ae=a.at(-1),W=a.length;return(0,Y.useLayoutEffect)(()=>{L.current+=1,I.current=null,A.current=!1,n===`document`?Z.viewKey!==e&&(Z.viewKey=e,Z.generation+=1):V.current+=1},[e,n]),(0,Y.useLayoutEffect)(()=>{let e=I.current;e?(e.anchor===void 0?-1:o.current.indexOf(e.anchor.key))>e.anchorIndex?R():I.current=null:m.current&&T()},[ae,W,R,T]),(0,Y.useLayoutEffect)(()=>{!c.current||!u||E()},[u,E]),(0,Y.useEffect)(()=>{let t=c.current,n=u;if(!t||!n)return;g.current=0;let r=null,i=!1,a=t.scrollTop,o,s=0,l,d=()=>{h.current&&!pt(t,80)&&(m.current=!1),h.current=!1},f=e=>{_.current=Date.now(),d(),l=e},v=()=>{H(),B.current?.disconnect(),x.current=null,S.current=null,L.current+=1,I.current=null,m.current=!1,g.current=0},b=()=>{x.current=null,S.current=null,L.current+=1,I.current=null,g.current=Date.now()},ee=e=>{if(e.deltaY!==0)if(f(e.deltaY<0?`up`:`down`),e.deltaY<0){v();let e=!M.current;M.current=!0,clearTimeout(N.current),N.current=setTimeout(()=>{M.current=!1},180),e&&We(t)&&z()}else b()},C=e=>{[`ArrowUp`,`PageUp`,`Home`].includes(e.key)?(f(`up`),v(),!e.repeat&&We(t)&&z()):[`ArrowDown`,`PageDown`,`End`].includes(e.key)&&(f(`down`),b())},E=e=>{if(e.target!==t||e.button!==0||e.pointerType===`touch`||e.pointerType===`pen`||t.scrollHeight<=t.clientHeight)return;i=!0,ne.current=!1,a=t.scrollTop;let n=t.getBoundingClientRect(),r=getComputedStyle(t),o=parseFloat(r.borderLeftWidth)||0,s=parseFloat(r.borderRightWidth)||0,c=n.left+t.clientLeft,l=c+t.clientWidth;!(e.clientX>=n.left+o&&e.clientX<c||e.clientX>=l&&e.clientX<n.right-s)||e.clientY<n.top+t.clientTop||e.clientY>=n.top+t.clientTop+t.clientHeight||(h.current=!1,x.current=null,S.current=null,pt(t,80)||(v(),b()))},O=()=>{i=!1},te=e=>{P.current=!1,r=e.touches[0]?.clientY??null},k=e=>{let n=e.touches[0]?.clientY;n!==void 0&&(r!==null&&n>r+1?(f(`up`),v(),!P.current&&We(t)&&(P.current=!0,z())):r!==null&&n<r-1&&(f(`down`),b()),r=n)},A=e=>{if(e===0||!i&&Date.now()-_.current>=ci)return;let n=e<0?`up`:`down`;!i&&n!==l||(n!==o&&(o=n,s=0),s+=Math.abs(e),s>=li&&(0,Zr.flushSync)(()=>y({direction:n,distanceFromBottom:t.scrollHeight-t.clientHeight-t.scrollTop})))},j=()=>{let n=m.current;A(t.scrollTop-a),i&&t.scrollTop!==a&&(d(),t.scrollTop<a?v():b()),i&&!ne.current&&t.scrollTop<a&&We(t)&&(ne.current=!0,z()),a=t.scrollTop;let r=pt(t,80);r&&x.current===null&&(m.current||Date.now()-g.current<2e3)&&(m.current=!0),!n&&m.current&&y({direction:`tail`}),p(!r),x.current===null&&!D(e)&&ke(e,{top:t.scrollTop,atBottom:r})};t.addEventListener(`scroll`,j,{passive:!0}),t.addEventListener(`wheel`,ee,{passive:!0}),t.addEventListener(`touchstart`,te,{passive:!0}),t.addEventListener(`touchmove`,k,{passive:!0}),t.addEventListener(`pointerdown`,E,{passive:!0}),window.addEventListener(`pointerup`,O,{passive:!0}),window.addEventListener(`pointercancel`,O,{passive:!0}),t.addEventListener(`keydown`,C);let F;if(typeof ResizeObserver<`u`){F=new ResizeObserver(()=>{let e=x.current;if(e!==null){let n=t.scrollHeight-t.clientHeight;w(Math.min(e,n)),n>=e&&(x.current=null)}else m.current&&T()}),F.observe(n);let e=n.closest(`[data-route="task-thread"]`),r=e?.querySelector(`[data-slot="run-header"]`),i=e?.querySelector(`[data-slot="thread-dock"]`);r&&F.observe(r),i&&F.observe(i)}return()=>{t.removeEventListener(`scroll`,j),t.removeEventListener(`wheel`,ee),t.removeEventListener(`touchstart`,te),t.removeEventListener(`touchmove`,k),t.removeEventListener(`pointerdown`,E),window.removeEventListener(`pointerup`,O),window.removeEventListener(`pointercancel`,O),t.removeEventListener(`keydown`,C),F?.disconnect()}},[e,u,z,w,T,D,H,y]),{attachContent:te,scrollElRef:c,virtualizerRef:C,restoreMeasurements:O,ownsMeasurementRestore:D,pillVisible:f,jumpToLatest:ie,jumpToRow:re,loadOlder:z,restickIfStuck:k,subscribeReaderScroll:b}}function di({runId:e,rows:t,mode:n,controls:r}){return n===`virtual`?(0,X.jsx)(fi,{runId:e,rows:t,controls:r}):(0,X.jsx)(`div`,{ref:r.attachContent,"data-slot":`thread-rows`,"data-virtualized":`false`,className:`[overflow-anchor:none]`,children:t.map(e=>(0,X.jsx)(`div`,{"data-slot":`thread-row`,"data-row-key":e.key,className:`flex w-full flex-col pb-2.5 [contain-intrinsic-block-size:auto_3rem] [content-visibility:auto]`,children:e.node},e.key))})}function fi({runId:e,rows:t,controls:n}){return(0,X.jsx)(pi,{runId:e,rows:t,controls:n},e)}function pi({runId:e,rows:t,controls:n}){let r=(0,Y.useRef)(null),i=(0,Y.useRef)(t),a=t[0]?.key,o=i.current[0]?.key,s=a!==o&&(t.some(e=>e.key===o)||i.current.some(e=>e.key===a));(0,Y.useLayoutEffect)(()=>{i.current=t},[t]);let[c]=(0,Y.useState)(()=>Ne(e)),[l,u]=(0,Y.useState)(()=>({cache:Me(e,t.length,t.map(e=>e.key)),generation:0})),d=(0,Y.useRef)(l.cache===void 0&&c?.rowKeys?.length===c?.rows&&c!==void 0);(0,Y.useLayoutEffect)(()=>{let r=c?.rowKeys;if(!d.current){n.restoreMeasurements(e);return}if(!(!c||!r)){if(t.length>c.rows||t.some((e,t)=>e.key!==r[t])){d.current=!1,n.restoreMeasurements(e);return}t.length===c.rows&&(d.current=!1,n.restoreMeasurements(e)&&u({cache:c.cache,generation:1}))}},[c,t,n.restoreMeasurements,e]);let f=(0,Y.useRef)(t.length);f.current=t.length;let p=(0,Y.useRef)(t.map(e=>e.key));p.current=t.map(e=>e.key);let m=(0,Y.useRef)(null),h=(0,Y.useCallback)(t=>{n.virtualizerRef.current=t,t?m.current=t:m.current&&=(d.current&&c?.rowKeys&&f.current<c.rows&&n.ownsMeasurementRestore(e)||nt(e,{rows:f.current,cache:m.current.cache,rowKeys:p.current}),null)},[e,n.virtualizerRef,n.ownsMeasurementRestore,c]),[g,_]=(0,Y.useState)(0);return(0,Y.useLayoutEffect)(()=>{let e=()=>{let e=r.current,t=n.scrollElRef.current;!e||!t||_(Math.max(0,Math.round(e.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[n.scrollElRef]),(0,X.jsx)(`div`,{ref:e=>{r.current=e,n.attachContent(e)},"data-slot":`thread-rows`,"data-virtualized":`true`,className:`[overflow-anchor:none]`,children:(0,X.jsx)(Nn,{ref:h,scrollRef:n.scrollElRef,startMargin:g,shift:s,...l.cache===void 0?{}:{cache:l.cache},children:t.map(e=>(0,X.jsx)(`div`,{"data-slot":`thread-row`,"data-row-key":e.key,className:`flex w-full flex-col pb-2.5`,children:e.node},e.key))},l.generation)})}function mi({onJump:e,pendingQuestions:t=0}){return(0,X.jsxs)(`button`,{type:`button`,"data-slot":`jump-to-latest`,"data-pending-questions":t>0?t:void 0,onClick:()=>e(),className:`pointer-events-auto inline-flex min-h-11 min-w-11 items-center gap-1.5 rounded-full border border-border bg-background px-3.5 text-xs font-medium text-muted-foreground shadow-sm hover:text-foreground`,children:[(0,X.jsx)(be,{"aria-hidden":!0,className:`size-3.5`}),ii(t)]})}function hi(e){return e.consumedAt?`consumed`:e.deliveredAt?`delivered`:`queued`}function gi(e,t){let n=new Map((e.agentInputs??[]).map(e=>[e.id,hi(e)]));if(n.size===0)return t;let r=!1,i=t.map(e=>{if(e.kind!==`note`||!e.id.startsWith(`agent-input:`))return e;let t=n.get(e.id.slice(12));return!t||e.delivery===t?e:(r=!0,{...e,delivery:t})});return r?i:t}function _i(e,t,n){return e.kind===`ask`?e.id===t?n===void 0?e:{...e,placement:`origin`}:e.resolved?e:{...e,resolved:!0}:e}var vi=new WeakMap;function yi(e,t){let n=vi.get(e);return n?.length===t.length&&t.every((e,t)=>{let r=n[t];return e===r||Object.keys(e).length===Object.keys(r).length&&Object.entries(e).every(([e,t])=>t===r[e])})?n:(vi.set(e,t),t)}function bi(e,t,n=t,r){let i=r==null?void 0:n.turns.flatMap(e=>e.items).find(e=>e.kind===`ask`&&e.id===r&&!e.resolved),a=new Map(n.turns.flatMap(e=>e.items).filter(e=>e.kind===`permission`).map(e=>[e.requestId,e])),o=new Set,s=new Set(t.turns.map(e=>e.userMessage?.ask?.id)),c=[];e.task&&c.push({id:`task`,userMessageKey:`task`,userMessage:{text:e.task,images:e.taskImages??[],ts:e.createdAt},entries:[]});for(let t of e.queuedMessages??[])c.push({id:`queued:${t.id}`,userMessageKey:`queued:${t.id}`,userMessage:{text:t.text,images:t.images??[],ts:t.createdAt},inDaySequence:!1,entries:[]});let l=t.turns.at(-1);for(let n of t.turns){let t=e.status===`review`&&n===l?Si(n.items):n.items;c.push({id:n.id,userMessageKey:`${n.id}:user`,...n.userMessage===void 0?{}:{userMessage:{text:n.userMessage.text,ask:n.userMessage.ask,imageCount:n.userMessage.imageCount,images:n.userMessage.images,...n.userMessage.ts===void 0?{}:{ts:n.userMessage.ts}}},...n.startedAt===void 0?{}:{startedAt:n.startedAt},...n.completed?.ts===void 0?{}:{completedAt:n.completed.ts},entries:yi(n.items,gi(e,t.filter(t=>!e.task||!jt(t,`opening`)).map(e=>e.kind===`ask`&&s.has(e.id)?{...e,placement:`origin`}:r!==void 0&&e.kind===`ask`?_i(e,r,i):e.kind===`permission`?(o.add(e.requestId),a.get(e.requestId)??(e.status===`pending`?{...e,status:`expired`}:e)):e)))})}let u=[...a.values()].filter(e=>e.status===`pending`&&!o.has(e.requestId));return u.length>0&&c.push({id:`pending-permissions`,entries:u,inDaySequence:!1}),i!==void 0&&c.push({id:Qr,entries:[{...i,placement:`pinned`}],inDaySequence:!1}),c}var xi=`changes ready for review`;function Si(e){return e.filter(e=>!(e.kind===`note`&&e.tone===`dim`&&e.text.startsWith(xi)))}function Ci(e,t,n){let r=e.findIndex(({content:e})=>e.kind===`block`&&e.block.kind===`entry`&&e.block.entry.kind===`ask`&&e.block.entry.id===t&&e.block.entry.placement===n);return r<0?void 0:{key:e[r].key,index:r}}function wi(e,t){return[{id:`agent:${e}`,entries:t}]}function Ti(e){if(e.inDaySequence!==!1)return e.userMessage?.ts??e.startedAt??e.completedAt}function Ei(e,t){let n=[],r;for(let t of e){let e=Ti(t),i=Ue(e);i!==void 0&&e!==void 0&&(r===void 0||i>r)&&(r!==void 0&&n.push({key:`${t.id}:day-separator`,scope:t.id,content:{kind:`day-separator`,ts:e}}),r=i),t.userMessage!==void 0&&n.push({key:t.userMessageKey??`${t.id}:user`,scope:t.id,content:{kind:`user-message`,message:t.userMessage}});for(let e of Pe(t.entries))n.push({key:`${t.id}:${e.id}`,scope:t.id,content:{kind:`block`,block:e}});t.completedAt!==void 0&&n.push({key:`${t.id}:turn-time`,scope:t.id,content:{kind:`turn-time`,completedAt:t.completedAt,...t.startedAt===void 0?{}:{startedAt:t.startedAt}}})}return n}function Di({runId:e,viewId:t,sections:n,mode:r,empty:i,renderAsk:a,renderPermission:o,messageActions:s,scrollControls:c,renderMode:l,taskTitles:u,recipientBackends:d}){let f=(0,Y.useMemo)(()=>Ei(n,e),[n,e]),p=ui(`${e}:${t}`,{surface:r}),m=c??p;_r(e,f,m,r);let h=(0,Y.useMemo)(()=>{let e=new Map;f.forEach((t,n)=>{if(!(t.content.kind!==`block`||t.content.block.kind!==`worker-conversation`))for(let r of t.content.block.batches)for(let i of r.messages)e.set(i.messageId,{message:i,rowKey:t.key,rowIndex:n})});let t=new Map;for(let n of e.values()){let{message:e}=n;if(e.messageKind!==`reply`||!e.requestId)continue;let r=t.get(e.requestId)??[];r.push(n),t.set(e.requestId,r)}return{targets:e,replies:t,navigate:e=>m.jumpToRow(e.rowKey,e.rowIndex)}},[f,m.jumpToRow]),g=(0,Y.useMemo)(()=>f.map(t=>({key:t.key,node:Oi(t,s?.[t.key],a,o,e,u,d)})),[s,a,o,f,e,u,d]),_=l??Re(``,g.length),v=g.length===0?i??null:(0,X.jsx)(di,{runId:`${e}:${t}`,rows:g,mode:_,controls:m});return(0,X.jsx)(bt,{runId:e,children:(0,X.jsx)(ze,{runId:e,children:(0,X.jsx)(wr.Provider,{value:h,children:r===`panel`?(0,X.jsxs)(`div`,{"data-slot":`transcript-viewport`,"aria-label":`Agent transcript`,role:`region`,tabIndex:0,className:`relative flex min-h-0 flex-1 flex-col overflow-y-auto [scrollbar-gutter:stable]`,children:[(0,X.jsx)(`div`,{"data-slot":`subagent-stream`,className:`flex flex-col px-5 py-4`,children:v}),m.pillVisible?(0,X.jsx)(`div`,{className:`pointer-events-none sticky inset-x-0 bottom-4 flex justify-center`,children:(0,X.jsx)(mi,{onJump:m.jumpToLatest})}):null]}):v})})})}function Oi(e,t,n,r,i,a,o){switch(e.content.kind){case`user-message`:return(0,X.jsx)(ki,{message:e.content.message,actions:t});case`day-separator`:return(0,X.jsx)(ft,{ts:e.content.ts});case`turn-time`:return(0,X.jsx)(Je,{completedAt:e.content.completedAt,...e.content.startedAt===void 0?{}:{startedAt:e.content.startedAt}});case`block`:return(0,X.jsx)(Ai,{block:e.content.block,scope:e.scope,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o});default:return Pi(e.content)}}function ki({message:e,actions:t}){return(0,X.jsx)($e,{text:e.text,imageCount:e.imageCount,images:e.images,...e.ts===void 0?{}:{ts:e.ts},onEdit:t?.onEdit,onRemove:t?.onRemove,editLabel:t?.editLabel,removeLabel:t?.removeLabel,children:e.ask?(0,X.jsx)(`div`,{"data-slot":`ask-card`,"data-resolved":`true`,children:(0,X.jsx)(Fe,{ask:e.ask})}):void 0})}function Ai({block:e,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o}){switch(e.kind){case`entry`:return(0,X.jsx)(He.Provider,{value:`${t}:${e.entry.id}`,children:(0,X.jsx)(Mi,{entry:e.entry,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o})});case`tool-card`:return(0,X.jsx)(st,{item:e.item,nested:e.children,cacheKey:`${t}:${e.id}`,renderNested:(e,t)=>(0,X.jsx)(ji,{entries:e,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o})});case`context-group`:return(0,X.jsx)(Ye,{group:e,scope:t});case`streak`:return(0,X.jsx)(it,{count:e.count,children:e.blocks.map(e=>(0,X.jsx)(Ai,{block:e,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o},e.id))});case`worker-conversation`:return(0,X.jsx)(Br,{block:e,runId:i,taskTitles:a,recipientBackends:o});default:return Pi(e)}}function ji({entries:e,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o}){return Pe(e).map(e=>(0,X.jsx)(Ai,{block:e,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o},e.id))}function Mi({entry:e,scope:t,renderAsk:n,renderPermission:r,runId:i,taskTitles:a,recipientBackends:o}){switch(e.kind){case`message`:return e.role===`assistant`?(0,X.jsx)(lt,{text:e.text,ts:e.ts}):(0,X.jsx)($e,{text:e.text,ts:e.ts});case`reasoning`:return(0,X.jsx)(Ze,{text:e.text});case`tool`:return(0,X.jsx)(st,{item:e,cacheKey:`${t}:${e.id}`});case`note`:return e.attribution?(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-border px-4 py-3 text-sm`,children:[(0,X.jsxs)(`p`,{className:`mb-2 break-all text-xs text-muted-foreground`,children:[e.attribution.source===`agent`?`Agent input from parent ${e.attribution.parentRunId}`:`Worker lifecycle context for parent ${e.attribution.parentRunId}`,e.delivery?` · ${Pr(e.delivery)}`:``]}),(0,X.jsx)(Ke,{note:e})]}):(0,X.jsx)(Ke,{note:e});case`conversation`:return(0,X.jsx)(Br,{runId:i,taskTitles:a,recipientBackends:o,block:{kind:`worker-conversation`,id:e.id,batches:[{id:e.id,kind:e.messageKind,text:e.text,senderRunId:e.senderRunId,messages:[e]}]}});case`image`:return(0,X.jsx)(dt,{image:e});case`ask`:return n===void 0?(0,X.jsx)(`div`,{"data-slot":`ask-card`,className:`rounded-lg border border-border bg-card px-4 py-3 text-sm`,children:`The agent asked a question. Open the main session to answer it.`}):n(e);case`permission`:return r?r(e):(0,X.jsx)(xr,{permission:e,runId:i});case`provider-auth-required`:return(0,X.jsx)(Xe,{incident:e});case`preview-server`:return(0,X.jsx)(Ni,{entry:e});case`hook`:return(0,X.jsx)(rt,{item:e,cacheKey:`${t}:${e.id}`});default:return Pi(e)}}function Ni({entry:e}){let t=En(),n=T().data?.capabilities?.preview===!0;return(0,X.jsx)(Pt,{entry:t?.worktreeRemoved?{kind:`preview-server`,id:e.id,server:e.server,state:`unavailable`}:e,inPreview:t!==null&&t.open&&t.port===e.server.port,onOpen:t!==null&&n?t.openPane:void 0})}function Pi(e){throw Error(`Unhandled transcript variant: ${JSON.stringify(e)}`)}function Fi({runId:e,renderAsk:t,renderPermission:n,agent:r,entries:i,onClose:a,taskTitles:o,recipientBackends:s}){let c=(0,Y.useContext)(an),l=(0,Y.useRef)(void 0),u=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>()=>{l.current?.()},[c,e]),(0,X.jsx)($t,{open:r!==void 0,onOpenChange:e=>{e||a()},children:(0,X.jsx)(tn,{"data-slot":`subagent-sheet`,side:`right`,onCloseAutoFocus:e=>{u.current&&=(e.preventDefault(),!1)},className:`flex min-h-0 w-full gap-0 p-0 sm:max-w-xl`,children:r===void 0?null:(0,X.jsx)(gt.Provider,{value:e=>{let t=[...document.querySelectorAll(`[data-agent-id]`)].find(e=>e.dataset.agentId===r?.id);l.current?.(),l.current=c?.registerOpener(e,()=>{t?.focus({preventScroll:!0})}),u.current=!0,a()},children:(0,X.jsx)(Ii,{runId:e,renderAsk:t,renderPermission:n,agent:r,entries:i,taskTitles:o,recipientBackends:s})})})})}function Ii({runId:e,renderAsk:t,renderPermission:n,agent:r,entries:i,taskTitles:a,recipientBackends:o}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(Qt,{className:`gap-1.5 border-b border-border px-5 py-4`,children:[(0,X.jsxs)(en,{className:`flex min-w-0 items-center gap-2 pr-8 text-[16px]`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:r.title}),r.agentType===void 0?null:(0,X.jsx)(`span`,{"data-slot":`agent-type`,className:`shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] font-semibold tracking-[0.05em] text-muted-foreground uppercase`,children:r.agentType})]}),(0,X.jsxs)(rn,{"data-slot":`subagent-meta`,className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(Li,{status:r.status}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[r.toolCalls,` `,r.toolCalls===1?`tool call`:`tool calls`]})]})]}),(0,X.jsx)(Di,{runId:e,viewId:`agent:${r.id}`,sections:wi(r.id,i),mode:`panel`,renderAsk:t,renderPermission:n,taskTitles:a,recipientBackends:o,empty:(0,X.jsx)(`div`,{"data-slot":`subagent-empty`,className:`py-2 text-[13px] text-muted-foreground`,children:`No attributed output — see the thread card for this agent's result.`})})]})}function Li({status:e}){let t=e===`completed`?`Completed`:e===`failed`?`Failed`:e===`declined`?`Declined`:e===`pending`?`Pending`:`Running`;return(0,X.jsx)(`span`,{"data-slot":`subagent-status`,"data-status":e,className:a(`rounded-full px-2 py-0.5 text-[11px] font-semibold tracking-[0.05em] uppercase`,e===`completed`&&`bg-success/15 text-success`,(e===`failed`||e===`declined`)&&`bg-danger/15 text-danger`,(e===`running`||e===`pending`)&&`bg-muted text-muted-foreground`),children:t})}function Ri(e,t,n,r){return n?r===`step`?`Step ${e} of ${t}`:`${e} of ${t} complete`:`${e} / ${t}`}function zi(e){return typeof e==`object`&&!!e&&!(0,Y.isValidElement)(e)&&`keep`in e}function Q({slot:e,icon:t,title:n,meta:r,summary:i,aside:o,open:s,onToggle:c,className:l,children:u}){let d=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`flex size-4 shrink-0 items-center justify-center text-accent-text`,children:t}),(0,X.jsx)(`span`,{className:a(`truncate text-[14px] font-semibold text-foreground`,typeof n==`string`?`shrink-0`:`min-w-0 shrink`),children:n}),i??(zi(r)?(0,X.jsxs)(`span`,{"data-slot":`run-activity-meta`,className:`contents text-[13px] text-muted-foreground tabular-nums`,children:[r.drop===void 0?null:(0,X.jsxs)(`span`,{className:`flex h-[1lh] min-w-0 shrink-[2] flex-wrap overflow-hidden`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-[1lh] w-0`}),(0,X.jsxs)(`span`,{"data-slot":`run-activity-meta-drop`,className:`whitespace-nowrap`,children:[r.drop,(0,X.jsx)(`span`,{className:`text-soft-foreground`,children:` ·`})]})]}),` `,(0,X.jsx)(`span`,{"data-slot":`run-activity-meta-keep`,className:`shrink-0 whitespace-nowrap`,children:r.keep})]}):r===void 0?null:(0,X.jsx)(`span`,{"data-slot":`run-activity-meta`,className:`min-w-0 shrink-[2] truncate text-[13px] text-muted-foreground tabular-nums`,children:r}))]}),f=c!==void 0;return(0,X.jsxs)(`div`,{"data-slot":`run-activity-${e}`,"data-state":f&&s?`open`:`collapsed`,className:a(`min-w-0 border-t border-border first:border-t-0`,l),children:[f?(0,X.jsxs)(`button`,{type:`button`,"aria-expanded":s,onClick:c,className:`flex min-h-11 w-full min-w-0 items-center gap-2.5 px-3.5 py-2 text-start hover:bg-muted/40 active:bg-muted focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring`,children:[d,o,(0,X.jsx)(ye,{"aria-hidden":!0,className:a(`size-4 shrink-0 text-soft-foreground motion-safe:transition-transform motion-reduce:transition-none`,!o&&`ms-auto`,s&&`rotate-180`)})]}):(0,X.jsxs)(`div`,{className:`flex min-h-11 w-full min-w-0 items-center gap-2.5 px-3.5 py-2`,children:[d,o]}),f&&s?(0,X.jsx)(`div`,{"data-slot":`run-activity-body`,className:`min-w-0 border-t border-border/60 bg-muted/30 px-3.5 py-2.5`,children:u}):null]})}function Bi(e){return re(e.delegation)}function Vi(e,t){let n=e?.role===`root`?e.receipts.map(e=>e.workerId).reverse():[];return[...new Set([...n,...(t?.workers??[]).map(e=>e.workerId)])]}function Hi(e){let t=e.delegation,n=Bi(e),r=y(e.id,{enabled:n});if(!n||!t)return`complete`;if(!r.isSuccess)return r.isError||r.fetchStatus===`paused`?`unknown`:`pending`;let i=new Map(r.data.workers.map(e=>[e.workerId,e])),a=Vi(t,r.data).map(e=>{let t=i.get(e)?.status;return t===`done`||t===`cancelled`?`complete`:t===void 0||t===`failed`?`issue`:`pending`});return a.includes(`pending`)?`pending`:a.includes(`issue`)?`issue`:`complete`}function Ui(e){let t=y(e.id,{enabled:e.delegation?.role===`root`});return t.isSuccess&&t.data.workers.some(e=>Xt(e.status))}function Wi({run:e,open:t,onToggle:n}){let r=y(e.id),i=S(),o=gn(),s=e.delegation,c=new Map(r.data?.workers.map(e=>[e.workerId,e])),l=Vi(s,r.data),u=P(e)??N(e),d=u?Gi(e,u):void 0,f=e=>i.data?.find(t=>t.id===e)??r.data?.titles?.find(t=>t.id===e),p=e=>{let t=f(e);return t?J(t):`worker ${e.slice(0,8)}`};return(0,X.jsx)(Q,{slot:`workers`,icon:(0,X.jsx)(fe,{className:`size-4`}),title:`Workers`,meta:Ki({ids:l,workers:c,desktop:o,query:r}),aside:r.data?.capacity?(0,X.jsx)($i,{capacity:r.data.capacity}):void 0,open:t,onToggle:n,children:(0,X.jsxs)(`div`,{"aria-label":`Task relationships`,className:`min-w-0 text-[13px] text-muted-foreground`,role:`group`,children:[r.data?.capacity&&r.data.capacity.outstanding>=r.data.capacity.limit?(0,X.jsx)(`p`,{role:`status`,className:`px-1 py-1`,children:`All worker slots are in use. Clean up finished workers to free a slot.`}):null,u?(0,X.jsx)(Xi,{wait:u,dependencyLabel:d}):null,l.length>0?(0,X.jsx)(`ul`,{className:`grid max-h-64 min-w-0 gap-0.5 overflow-y-auto`,children:l.map(t=>{let n=c.get(t),i=f(t),o=n?Ji(n.status):r.isSuccess?`Record unavailable or deleted`:`Status unavailable`;return(0,X.jsxs)(`li`,{"data-slot":`worker-item`,"data-status":n?.status,className:`min-w-0`,children:[(0,X.jsxs)(Ht,{to:`/tasks/${t}`,"aria-label":`Worker task ${t}`,className:`group flex min-h-11 min-w-0 items-center gap-2.5 rounded-md px-1 text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,X.jsx)(qi,{status:n?.status}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate`,children:i?J(i):`Worker ${t.slice(0,8)}`}),n?.supervisorRunId&&n.supervisorRunId!==e.id?(0,X.jsxs)(`span`,{"data-slot":`worker-supervisor`,className:`block truncate text-xs text-muted-foreground`,children:[`Started by `,p(n.supervisorRunId)]}):null]}),(0,X.jsx)(`span`,{className:a(`max-w-[45%] shrink-0 truncate text-xs`,Yi(n?.status)),children:o}),(0,X.jsx)(me,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-soft-foreground`})]}),n?(0,X.jsx)(ta,{parentRunId:e.id,worker:n}):null,n?.destroy?(0,X.jsx)(aa,{state:n.destroy}):null]},t)})}):Bi(e)&&r.isSuccess?(0,X.jsx)(`p`,{className:`px-1 py-1`,children:`No workers`}):null,r.fetchStatus===`paused`?(0,X.jsx)(`p`,{role:`status`,className:`px-1 py-1`,children:`Offline — relationship details will refresh when connected.`}):r.isPending?(0,X.jsx)(`p`,{role:`status`,className:`px-1 py-1`,children:`Loading relationships…`}):null,r.isError?(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-1 py-1`,children:[(0,X.jsx)(`p`,{role:`status`,children:`Could not load relationships. Known task links are retained.`}),(0,X.jsx)(q,{variant:`outline`,className:`min-h-11`,onClick:()=>void r.refetch(),children:`Retry relationships`})]}):null]})})}function Gi(e,t){let n=e.delegation;if(!(!n||n.role===`invalid`))return j(e)??A(n.role,t,`requestIds`in t&&M(n,t.requestIds))}function Ki({ids:e,workers:t,desktop:n,query:r}){if(e.length===0)return r.isError?`Unavailable`:r.isPending?`Linking…`:`No workers`;let i=`${e.length} linked`;if(!n)return i;let a=new Map;for(let n of e){let e=t.get(n)?.status;e!==void 0&&a.set(e,(a.get(e)??0)+1)}return[i,...[...a.entries()].map(([e,t])=>`${t} ${e}`)].join(` · `)}function qi({status:e}){let t=`size-[15px] shrink-0`;return e===`done`?(0,X.jsx)(he,{"aria-hidden":!0,className:a(t,`text-success`)}):e===`failed`?(0,X.jsx)(G,{"aria-hidden":!0,className:a(t,`text-danger`)}):e===`cancelled`?(0,X.jsx)(ge,{"aria-hidden":!0,className:a(t,`text-soft-foreground`)}):e===`running`||e===`waiting`||e===`review`?(0,X.jsx)(Tt,{role:`status`,"aria-label":`Worker running`,className:a(t,`animate-spin stroke-pending motion-reduce:animate-none`)}):(0,X.jsx)(K,{"aria-hidden":!0,className:a(t,`text-soft-foreground`)})}function Ji(e){return`${e.charAt(0).toUpperCase()}${e.slice(1)}`}function Yi(e){return e===`done`?`text-success`:e===`failed`?`text-danger`:`text-muted-foreground`}function Xi({wait:e,dependencyLabel:t}){return(0,X.jsxs)(`p`,{className:`px-2 break-words`,children:[e.phase===`parked`&&t?`${t.charAt(0).toUpperCase()}${t.slice(1)}`:`requestIds`in e&&e.requestIds?e.phase===`parked`?`Waiting on request replies`:e.phase===`wake-pending`?`Conversation update queued for this task`:`Request wait registered — the agent is finishing its turn`:e.phase===`parked`?`Waiting on workers`:e.phase===`wake-pending`?`Worker update queued for the parent`:`Worker wait registered — the agent is finishing its turn`,`.`,`deadline`in e?(0,X.jsxs)(X.Fragment,{children:[` `,`Deadline: `,(0,X.jsx)(`time`,{dateTime:e.deadline,children:e.deadline})]}):` No deadline: Squawk wakes this task when they have all settled.`]})}function Zi(e){return e.delegation?.role===`worker`&&N(e)?.phase===`wake-pending`}function Qi({run:e}){let t=N(e);return e.delegation?.role===`worker`&&t?.phase===`wake-pending`?(0,X.jsx)(Xi,{wait:t,dependencyLabel:A(`worker`,t)}):null}function $i({capacity:e}){return(0,X.jsxs)(`span`,{"data-slot":`worker-capacity`,role:`status`,"aria-label":`Worker capacity: ${e.outstanding} of ${e.limit} in use`,className:`ms-auto shrink-0 whitespace-nowrap text-[13px] font-normal text-muted-foreground tabular-nums`,children:[e.outstanding,` of `,e.limit,` in use`]})}var ea=new Set([`review`,`done`,`failed`,`cancelled`]);function ta({parentRunId:e,worker:t}){let n=c(e),[r,i]=(0,Y.useState)(!1);if(!ea.has(t.status)||t.destroy?.phase===`complete`&&t.destroy.remaining.length===0)return null;let a=t.workerId.slice(0,8),o=!!t.destroy&&t.destroy.phase!==`complete`,s=n.error instanceof k?n.error.work:void 0;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 px-1`,children:[r?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`break-words text-xs`,children:ie(t.workspace)?`Removes this worker's worktree and branch. Its result is saved first.`:`Stops this worker and frees its slot. It runs in this task's worktree, so no worktree or branch is removed. Its result is saved first.`}),(0,X.jsx)(q,{variant:`danger-ghost`,size:`sm`,className:`min-h-11`,"aria-label":`Confirm clean up of worker ${a}`,onClick:()=>{i(!1),n.mutate({workerId:t.workerId})},children:`Clean up`}),(0,X.jsx)(q,{variant:`outline`,size:`sm`,className:`min-h-11`,onClick:()=>i(!1),children:`Cancel`})]}):(0,X.jsx)(q,{variant:`outline`,size:`sm`,className:`min-h-11`,"aria-label":o?`Retry clean up of worker ${a}`:`Clean up worker ${a}`,disabled:n.isPending,onClick:()=>i(!0),children:n.isPending?`Cleaning up…`:o?`Retry clean up`:`Clean up`}),n.isError&&!r?(0,X.jsx)(`span`,{role:`status`,className:`break-words text-xs`,children:s?`Cleanup stopped: this worker holds ${ra(s)}. Land or commit what you need first, or discard it.`:`Cleanup did not finish: ${n.error.message}`}):null,s&&!r&&!n.isPending?(0,X.jsx)(q,{variant:`danger-ghost`,size:`sm`,className:`min-h-11`,"aria-label":`Discard work and clean up worker ${a}`,onClick:()=>n.mutate({workerId:t.workerId,discardWork:!0}),children:`Discard work and clean up`}):null]})}var na=(e,t,n)=>`${e} ${e===1?t:n}`;function ra(e){return[...e.uncommittedFiles?[na(e.uncommittedFiles,`uncommitted file`,`uncommitted files`)]:[],...e.commits?[`${na(e.commits,`commit`,`commits`)} no other branch reaches`]:[]].join(` and `)}function ia(e){return e!==void 0&&(e.phase!==`complete`||e.remaining.length>0||e.error!==void 0)}function aa({state:e}){if(!ia(e))return null;let t=e.phase===`complete`?void 0:e.retry,n=t&&(0,X.jsx)(oa,{at:t.nextAt});return(0,X.jsxs)(`p`,{className:`px-2 pb-2 break-words`,children:[t?.needsAttention?`Cleanup needs attention`:e.phase===`incomplete`?`Cleanup incomplete`:e.phase===`complete`?`Cleanup complete`:`Cleanup ${e.phase}`,e.remaining.length?` — remaining: ${e.remaining.join(`, `)}`:``,e.error?` — ${t?e.error.replace(/\.$/,``):e.error}`:``,t?.needsAttention?(0,X.jsxs)(X.Fragment,{children:[`. Nothing changed after `,t.attempts,` automatic attempts; checking hourly, next check `,n,`. Retry clean up to try now.`]}):t?(0,X.jsxs)(X.Fragment,{children:[`. Retrying automatically, next attempt `,n,`.`]}):null]})}function oa({at:e}){let t=nn(3e4);return(0,X.jsx)(`time`,{dateTime:e,title:new Date(e).toLocaleString(),children:Rn(t,Date.parse(e))})}function sa(e){let t=I(),[n,r]=(0,Y.useState)(),i=qt(e);(0,Y.useEffect)(()=>{(!i||n&&n!==e.id)&&r(void 0)},[i,e.id,n]);let a=h({mutationFn:async()=>{r(e.id);try{if(!(await R(e.id)).cancelled)throw Error(`The task changed before Stop was accepted. Check its status and retry.`)}catch(e){throw r(void 0),e}},onSettled:()=>t.invalidateQueries({queryKey:d.runs.all})});return{stopping:!!e.stopping||a.isPending||i&&n===e.id,stop:()=>a.mutateAsync()}}function ca({agents:e,onSelect:t}){return e.length===0?null:(0,X.jsx)(`ul`,{"data-slot":`agents-list`,className:`flex min-w-0 flex-col gap-[7px]`,children:e.map(e=>(0,X.jsx)(la,{agent:e,onSelect:t},e.id))})}function la({agent:e,onSelect:t}){let n=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ua,{status:e.status,stalled:e.stalled===!0}),(0,X.jsx)(`span`,{className:`min-w-0 shrink truncate font-medium`,children:e.title}),e.agentType===void 0?null:(0,X.jsx)(`span`,{"data-slot":`agent-type`,className:`shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] font-semibold tracking-[0.05em] text-muted-foreground uppercase`,children:e.agentType}),(0,X.jsx)(`span`,{"data-slot":`agent-activity`,className:`min-w-0 flex-1 truncate text-muted-foreground`,children:sr(e)}),(0,X.jsxs)(`span`,{"data-slot":`agent-tools`,className:`shrink-0 text-muted-foreground tabular-nums`,children:[e.toolCalls,` `,e.toolCalls===1?`tool`:`tools`]})]});return(0,X.jsx)(`li`,{"data-slot":`agent-item`,"data-status":e.status,className:`min-w-0 text-[13px]`,children:t?(0,X.jsx)(`button`,{type:`button`,"data-agent-id":e.id,onClick:()=>t(e.id),"aria-haspopup":`dialog`,className:`flex min-h-5 w-full min-w-0 items-center gap-2.5 rounded-sm text-left hover:bg-muted/50`,children:n}):(0,X.jsx)(`div`,{className:`flex min-h-5 min-w-0 items-center gap-2.5`,children:n})})}function ua({status:e,stalled:t=!1}){return t?(0,X.jsx)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,"data-stalled":`true`,className:`size-[15px] shrink-0 text-soft-foreground`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:`3 2.5`,children:(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`})}):e===`completed`?(0,X.jsxs)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,className:`size-[15px] shrink-0 text-success`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`.35`}),(0,X.jsx)(`path`,{d:`m8.5 12.2 2.4 2.4 4.6-5`})]}):e===`failed`||e===`declined`?(0,X.jsxs)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,className:`size-[15px] shrink-0 text-danger`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`.35`}),(0,X.jsx)(`path`,{d:`m9 9 6 6M15 9l-6 6`})]}):(0,X.jsxs)(`svg`,{"aria-hidden":!0,"data-slot":`agent-glyph`,className:`size-[15px] shrink-0 animate-pulse motion-reduce:animate-none`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,X.jsx)(`circle`,{className:`stroke-pending`,cx:`12`,cy:`12`,r:`8.5`,strokeWidth:`2`}),(0,X.jsx)(`path`,{className:`fill-pending`,d:`M12 3.5 A8.5 8.5 0 0 1 12 20.5 Z`})]})}function da(e){return{done:e.filter(e=>e.status===`completed`).length,total:e.filter(e=>e.status!==`cancelled`).length}}function fa({entries:e}){return e.length===0?null:(0,X.jsx)(`ul`,{"data-slot":`plan-list`,className:`flex min-w-0 flex-col gap-[7px]`,children:e.map((e,t)=>(0,X.jsx)(pa,{entry:e},`${t}:${e.content}`))})}function pa({entry:e}){return(0,X.jsxs)(`li`,{"data-slot":`plan-item`,"data-status":e.status,className:a(`flex min-h-5 min-w-0 items-center gap-2.5 text-[13px]`,e.status===`completed`&&`text-soft-foreground line-through`,e.status===`in_progress`&&`font-medium`,e.status===`pending`&&`text-muted-foreground`,e.status===`cancelled`&&`text-soft-foreground/70 line-through`),children:[(0,X.jsx)(ma,{status:e.status}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:e.content}),e.status===`in_progress`?(0,X.jsx)(`span`,{"data-slot":`plan-tag`,className:`ml-auto shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] font-semibold tracking-[0.05em] text-muted-foreground uppercase`,children:`in progress`}):null]})}function ma({status:e}){return e===`cancelled`?(0,X.jsxs)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 text-soft-foreground/70`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`,opacity:`.5`}),(0,X.jsx)(`path`,{d:`m8.5 15.5 7-7`})]}):e===`completed`?(0,X.jsxs)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 text-success`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`.35`}),(0,X.jsx)(`path`,{d:`m8.5 12.2 2.4 2.4 4.6-5`})]}):e===`in_progress`?(0,X.jsxs)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 animate-pulse motion-reduce:animate-none`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,X.jsx)(`circle`,{className:`stroke-pending`,cx:`12`,cy:`12`,r:`8.5`,strokeWidth:`2`}),(0,X.jsx)(`path`,{className:`fill-pending`,d:`M12 3.5 A8.5 8.5 0 0 1 12 20.5 Z`})]}):(0,X.jsx)(`svg`,{"aria-hidden":!0,className:`size-[15px] shrink-0 text-soft-foreground`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,X.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`})})}function ha(e){switch(e){case`done`:return`done`;case`running`:case`waiting`:case`review`:return`active`;case`failed`:case`cancelled`:return`failed`;case`pending`:case`skipped`:return`pending`}}function ga(e,t){let n=ha(e);return n===`active`&&t===`waiting`?`paused`:n}function _a(e){return e===`active`?`running`:e}function va(e){if(e.length===0)return 0;let t=new Set([`done`,`failed`,`cancelled`,`skipped`]),n=new Set([`running`,`waiting`,`review`]),r=0;for(let i of e)t.has(i.status)?r+=1:n.has(i.status)&&(r+=.5);return r/e.length}function ya({steps:e,runStatus:t=`running`}){if(e.length===0)return null;let n=va(e)*100;return(0,X.jsxs)(`div`,{"data-slot":`step-rail`,className:`flex min-w-0 flex-col gap-1`,children:[e.map((n,r)=>(0,X.jsxs)(`div`,{"data-slot":`step-row`,"data-visual":ga(n.status,t),className:`flex min-h-[22px] min-w-0 items-center gap-2 text-[13px] text-muted-foreground`,children:[(0,X.jsx)(ba,{visual:ga(n.status,t)}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-medium text-foreground`,children:n.name}),n.iterations>1?(0,X.jsxs)(`span`,{"data-slot":`step-iterations`,className:`shrink-0 text-xs text-soft-foreground tabular-nums`,children:[`×`,n.iterations]}):null,(0,X.jsxs)(`span`,{className:`ml-auto shrink-0 pl-2 text-[11px] text-soft-foreground tabular-nums`,children:[n.pluginKind??n.kind,` · step `,r+1,` of `,e.length]})]},n.id)),(0,X.jsx)(`div`,{"data-slot":`step-progress`,className:`mt-1 h-0.5 overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full bg-pending`,style:{width:`${n}%`}})})]})}function ba({visual:e}){let t=`size-[13px] shrink-0`;switch(e){case`done`:return(0,X.jsx)(he,{"aria-hidden":!0,className:a(t,`text-success`)});case`active`:return(0,X.jsx)(Tt,{role:`status`,"aria-label":`Step running`,className:a(t,`animate-spin stroke-pending motion-reduce:animate-none [html.light_&]:stroke-pending-strong`)});case`paused`:return(0,X.jsx)(Se,{role:`img`,"aria-label":`Step paused`,className:a(t,xa)});case`failed`:return(0,X.jsx)(G,{"aria-hidden":!0,className:a(t,`text-danger`)});case`pending`:return(0,X.jsx)(K,{"aria-hidden":!0,className:a(t,`text-soft-foreground`)})}}var xa=`stroke-pending [html.light_&]:stroke-pending-strong`,Sa={done:`done`,failed:`failed`,cancelled:`cancelled`};function Ca(e){let t=Sa[e.status];return t?e.steps.map(e=>ha(e.status)===`active`?{...e,status:t}:e.status===`pending`?{...e,status:`skipped`}:e):wa(e)}function wa(e){let t=Ta(e.currentStepId,e.steps);return e.steps.some((e,n)=>n!==t&&e.status===`waiting`)?e.steps.map((e,n)=>n!==t&&e.status===`waiting`?{...e,status:`done`}:e):e.steps}function Ta(e,t){let n=t.findIndex(t=>t.id===e);if(n>=0)return n;let r=t.reduce((e,t,n)=>ha(t.status)===`active`?n:e,-1);if(r>=0)return r;let i=t.findIndex(e=>e.status===`pending`);return i>=0?i:t.reduce((e,t,n)=>t.status===`skipped`?e:n,0)}function Ea({items:e,lead:t=0}){let n=(0,Y.useRef)(null),[r,i]=(0,Y.useState)(-1/0);return(0,Y.useLayoutEffect)(()=>{let r=n.current;if(!r)return;let a=()=>{let n=r.getBoundingClientRect().width;if(!n&&r.getClientRects().length===0)return;let a=getComputedStyle(r),o=Number.parseFloat(a.width),s=o>0?n/o:1,c=(Number.parseFloat(a.columnGap)||0)*s,l=Array.from(r.children,e=>e.getBoundingClientRect().width),u=e.map((e,t)=>({...e,width:l[t]??0})),d=-1/0,f=()=>u.reduce((e,t)=>e+t.width,0)+Math.max(0,u.length-1)*c+(u.length>0?t*s:0);for(let t of[...new Set(e.map(e=>e.priority))].sort((e,t)=>e-t)){if(f()<=n)break;d=t,u=u.filter(e=>e.priority>t)}i(e=>e===d?e:d)};if(a(),typeof ResizeObserver>`u`)return;let o=new ResizeObserver(a);o.observe(r);for(let e of r.children)o.observe(e);return()=>o.disconnect()},[e,t]),(0,X.jsx)(`span`,{ref:n,"data-slot":`activity-summary`,className:`relative flex h-[max(1.5em,22px)] min-w-0 flex-1 items-center gap-2.5 overflow-clip whitespace-nowrap text-[13px] font-normal text-muted-foreground tabular-nums`,children:e.map(n=>{let i=n.priority<=r,a=n===e.find(e=>e.priority>r);return(0,X.jsxs)(`span`,{"data-summary-item":n.id,"data-hidden":i,"aria-hidden":i||void 0,inert:i||void 0,style:a&&t?{marginInlineStart:t}:void 0,className:`inline-flex w-max shrink-0 items-center gap-1.5 data-[hidden=true]:invisible data-[hidden=true]:absolute`,children:[!a||t>0?(0,X.jsx)(`span`,{"aria-hidden":`true`,"data-slot":`activity-separator`,className:`before:content-['·']`}):null,n.content]},n.id)})})}function Da({run:e,references:t}){return(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1.5`,children:t.map(t=>(0,X.jsx)(At,{reference:t,taskTitle:J(e),inert:!0},ue(t)))})}function Oa(e){return e.accountId===void 0||e.profilesPending?void 0:e.profilesError?e.accountId:e.accountId==="default"?bn(e.accounts,e.accountBackend)?`default`:void 0:e.known?bn(e.accounts,e.accountBackend)?e.known.label:void 0:`${e.accountId} (removed)`}function ka(e){let t=x(),n=m(),r=g(),{accounts:i}=_n(),a=e.runner??n.data?.defaultRunner??`claude`,o=e.model??`auto`,s=e.effort||`auto`,c=[...e.steps].reverse().find(e=>e.profileId),l=c?.profileId,u=c?.backend??a,d=r.data?.profiles.find(e=>e.id===l&&e.provider===u),p=Oa({accountId:l,profilesPending:r.isPending,profilesError:r.isError,known:d,accounts:i,accountBackend:u}),h=e.modelIdentity&&e.modelIdentity!==o?e.modelIdentity:void 0;return{runner:e.removedRunner===void 0?f(t.data,a):D(e.removedRunner),...p?{account:p}:{},model:o,effort:s,...h?{identity:h}:{}}}var Aa=[`running`,`queued`,`waiting`];function ja(e){return Array.isArray(e)?e.filter(e=>e?.kind===`pr`||e?.kind===`timer`||e?.kind===`worker`||e?.kind===`process`||e?.kind===`peer`||e?.kind===`subagent`||e?.kind===`plugin`):[]}function $(e){let t=e?new Date(e):void 0;return t&&Number.isFinite(t.getTime())?new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`long`}).format(t):void 0}function Ma(e,t){return`${e} — ${t.status===`failed`?`not delivered; Continue delivers it, Stop discards it`:t.status===`running`?`current turn still working`:`waiting for capacity`}`}function Na(e){return e.kind!==`worker`&&e.kind!==`peer`&&e.kind!==`subagent`}function Pa(e){let t=ja(e.waits),n=Aa.includes(e.status),r=t.filter(t=>t.phase===`open`?n:t.phase===`resolved`&&Na(t)&&(n||e.status===`failed`)),i=r.some(e=>e.kind===`pr`),a=[...ja(e.lastWaits),...t.filter(e=>!r.includes(e)&&e.phase!==`open`)],o=i?void 0:a.filter(e=>e.kind===`pr`).at(-1),s=i?void 0:e.lastWaitsError,c=r.some(e=>e.kind===`process`)?void 0:a.filter(e=>e.kind===`process`).at(-1);return r.length||o||s||c?{open:r,lastCi:o,error:s,lastProcess:c}:void 0}function Fa(e){return Pa(e)!==void 0}function Ia(e){return(Pa(e)?.open??[]).filter(e=>e.kind===`pr`).map(e=>({kind:`PR`,number:e.prNumber,url:e.prUrl}))}function La({run:e}){let t=Pa(e);if(!t)return null;let{open:n,lastCi:r,error:i,lastProcess:a}=t;return(0,X.jsxs)(`div`,{"data-slot":`open-waits`,className:`flex min-w-0 flex-col gap-1`,children:[n.map(t=>t.kind===`pr`?(0,X.jsx)(za,{run:e,wait:t},t.id):t.kind===`worker`?(0,X.jsx)(Ba,{wait:t},t.id):t.kind===`process`?(0,X.jsx)(Ka,{run:e,wait:t},t.id):t.kind===`peer`?(0,X.jsx)(Va,{wait:t},t.id):t.kind===`subagent`?(0,X.jsx)(Ha,{wait:t},t.id):t.kind===`plugin`?(0,X.jsx)(Ua,{run:e,wait:t},t.id):(0,X.jsx)(Wa,{run:e,wait:t},t.id)),i?(0,X.jsx)(`div`,{"data-slot":`ci-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:i}):r?(0,X.jsx)(za,{run:e,wait:r,settled:!0}):null,a?(0,X.jsx)(Ka,{run:e,wait:a,settled:!0}):null]})}function Ra(e,t,n){let r=t.result,i=t.until!==`checks`,a={passed:`CI checks passed — observed checks only; not merge approval`,stuck:`CI checks stuck in queue — inspect the PR checks`,failed:`CI checks failed — inspect the PR checks`,conflicting:i?`PR has merge conflicts — inspect the PR; not merged`:`PR has merge conflicts — inspect the PR; not merge approval`,cancelled:i?`Merge wait cancelled`:`CI wait cancelled`,skipped:`CI checks skipped — inspect the PR checks`,no_checks:`No CI checks found — inspect the PR workflows`,startup_failure:`CI workflow never started — inspect the PR workflows`,deadline:i?`Merge wait timed out — merge not confirmed`:`CI wait timed out — inspect the PR checks`,error:i?`Merge wait unavailable — inspect access and the PR`:`CI wait unavailable — inspect access and the PR checks`,head_changed:`CI head changed — ${r?.headSha?Fn(r.headSha):`unknown`} → ${r?.observedHeadSha?Fn(r.observedHeadSha):`unknown`}`,merged:`PR merged`,closed:`PR closed without merge — inspect the PR`,blocked:`Initiated merge blocked — inspect the PR; not merged`},o=i?`Merge`:`CI`,s=n&&t.phase===`cancelled`;return n?s?`${o} wait cancelled`:r?a[r.outcome]:`${o} wait unavailable`:t.phase===`resolved`?Ma(`${o} result ready`,e):t.until===`merge_or_blocked`?`Waiting for merge or blockage`:i?`Waiting for merge`:`Waiting for CI`}function za({run:e,wait:t,settled:n=!1}){let r=t.result,a=t.until===`checks`?`CI`:`Merge`,o=n&&t.phase===`cancelled`,s=Ra(e,t,n),c=n?o?t.cancelledAt:r?.observedAt:t.deadline,l=$(c),u=`${t.repository}#${t.prNumber}`;return(0,X.jsx)(`div`,{"data-slot":`ci-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-[13px] text-muted-foreground [overflow-wrap:anywhere]`,children:(0,X.jsxs)(`dl`,{className:`grid min-w-0 grid-cols-[auto_minmax(0,1fr)] items-baseline gap-x-3 gap-y-1`,children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Status`}),(0,X.jsx)(`dd`,{children:s}),(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Pull request`}),(0,X.jsx)(`dd`,{className:`min-w-0`,children:i(t.prUrl)?(0,X.jsx)(`a`,{href:t.prUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex min-h-11 min-w-11 max-w-full items-center rounded-sm px-1 font-medium text-foreground underline underline-offset-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring active:bg-muted`,children:u}):(0,X.jsx)(`span`,{children:u})}),l?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:n?o?`Cancelled`:`Observed`:`Deadline`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`time`,{dateTime:c,children:l})})]}):n?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Deadline`}),(0,X.jsxs)(`dd`,{children:[a,` deadline unavailable`]})]})]})})}function Ba({wait:e}){let t=e.workerIds!==void 0,n=new Set((t?e.outcomes:e.requestOutcomes)?.map(e=>`workerId`in e?e.workerId:e.requestId)),r=(e.workerIds??e.requestIds??[]).filter(e=>!n.has(e)).length,i=t?r===1?`worker`:`workers`:r===1?`request reply`:`request replies`,a=$(e.deadline);return(0,X.jsxs)(`div`,{"data-slot":`worker-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:[(0,X.jsxs)(`p`,{children:[`Waiting on `,r,` `,i]}),a?(0,X.jsxs)(`p`,{children:[`Deadline`,` `,(0,X.jsx)(`time`,{dateTime:e.deadline,children:a})]}):(0,X.jsx)(`p`,{children:`Worker wait deadline unavailable`})]})}function Va({wait:e}){let t=e.peerIds.length,n=$(e.deadline);return(0,X.jsxs)(`div`,{"data-slot":`peer-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:[(0,X.jsxs)(`p`,{children:[`Waiting on `,t,` `,t===1?`task`:`tasks`]}),n?(0,X.jsxs)(`p`,{children:[`Deadline`,` `,(0,X.jsx)(`time`,{dateTime:e.deadline,children:n})]}):(0,X.jsx)(`p`,{children:`Peer wait deadline unavailable`})]})}function Ha({wait:e}){let t=(Array.isArray(e.children)?e.children:[]).filter(e=>e?.status===`running`).length,n=$(e.deadline);return(0,X.jsxs)(`div`,{"data-slot":`subagent-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:[(0,X.jsxs)(`p`,{children:[`Waiting for `,t,` `,t===1?`subagent`:`subagents`]}),n?(0,X.jsxs)(`p`,{children:[`Check by`,` `,(0,X.jsx)(`time`,{dateTime:e.deadline,children:n})]}):(0,X.jsx)(`p`,{children:`Subagent wait deadline unavailable`})]})}function Ua({run:e,wait:t}){let n=t.phase===`open`?$(t.deadline):void 0;return(0,X.jsxs)(`div`,{"data-slot":`plugin-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:[(0,X.jsx)(`p`,{children:t.phase===`resolved`?Ma(t.summary,e):t.summary}),n?(0,X.jsxs)(`p`,{children:[`Deadline`,` `,(0,X.jsx)(`time`,{dateTime:t.deadline,children:n})]}):null]})}function Wa({run:e,wait:t}){let n=$(t.deadline);return(0,X.jsxs)(`div`,{"data-slot":`monitoring-schedule`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:[t.phase===`resolved`?(0,X.jsx)(`p`,{children:Ma(`Automatic check due`,e)}):n?(0,X.jsxs)(`p`,{children:[`Next automatic check`,` `,(0,X.jsx)(`time`,{dateTime:t.deadline,className:`font-medium text-foreground`,children:n})]}):(0,X.jsx)(`p`,{children:`Automatic check time unavailable`}),t.note?(0,X.jsx)(`p`,{children:t.note}):null]})}function Ga(e){let t=e.result;return t?t.outcome===`exit_file`?t.exitCode===void 0?`PID ${e.pid} wrote an exit file that is not an exit code`:`PID ${e.pid} exited with code ${t.exitCode}`:t.outcome===`exited`?e.startToken===void 0&&t.observedAt===e.registeredAt?`PID ${e.pid} was not running when the wait was registered`:`PID ${e.pid} exited, code unknown`:t.outcome===`deadline`?`PID ${e.pid} still running at the deadline`:`PID ${e.pid} could not be checked`:`PID ${e.pid} still running at the deadline`}function Ka({run:e,wait:t,settled:n=!1}){let r=n&&t.phase===`cancelled`?`Process wait on PID ${t.pid} cancelled`:n?Ga(t):t.phase===`resolved`?Ma(Ga(t),e):`Waiting for PID ${t.pid}${t.note?` — ${t.note}`:``}`,i=!n&&t.phase===`open`?$(t.deadline):void 0;return(0,X.jsxs)(`div`,{"data-slot":`process-wait-status`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`min-w-0 text-xs text-muted-foreground [overflow-wrap:anywhere]`,children:[(0,X.jsx)(`p`,{children:r}),i?(0,X.jsxs)(`p`,{children:[`Until`,` `,(0,X.jsx)(`time`,{dateTime:t.deadline,children:i})]}):null]})}var qa=new Map,Ja=new Map;function Ya(e){let{referenceProjectId:t,repoBase:n,references:r,requests:i}=Ct(e.run);return(0,X.jsx)(Dt,{projectId:t,repoBase:n,requests:i,children:(0,X.jsx)(Xa,{...e,references:r,prNumbers:i.filter(e=>e.kind===`PR`).map(e=>e.number),hasReferences:r.length>0||!!ce(e.run)||!!se(e.run,n)})})}function Xa({run:e,thread:t,currentThread:n,currentComplete:r=!0,pendingAsk:i=!1,onOpenWorker:a,readerScroll:o,prNumbers:s,hasReferences:c,references:l}){let u=gn(),d=ka(e),[f,p]=(0,Y.useState)(()=>i?!1:qa.get(e.id)??!1),m=po(o,f),h=m.open,[g,_]=(0,Y.useState)({}),v=Za(e,t??n,n,r,s),y=xt(e),b=t=>g[t]??Ja.get(`${e.id}:${t}`)??t===`workers`,x=t=>{let n=!b(t);Ja.set(`${e.id}:${t}`,n),_(e=>({...e,[t]:n}))},S=e=>({open:b(e),onToggle:()=>x(e)});return(0,X.jsxs)(`section`,{"data-slot":`run-activity-dock`,ref:m.ref,"data-state":h?`open`:`collapsed`,className:`min-w-0 overflow-hidden rounded-xl border border-border bg-card shadow-xs`,children:[(0,X.jsx)(no,{run:e,identity:d,activity:v,references:l,open:h,onToggle:()=>{qa.set(e.id,!h),p(!h),m.chose(!h)}}),h?(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col border-t border-border`,children:[(0,X.jsx)(ao,{run:e,activity:v,...S(`status`)}),(0,X.jsx)(oo,{run:e,desktop:u,automations:v.automations,...S(`workflow`)}),(0,X.jsx)(so,{activity:v,desktop:u,onOpenWorker:a,...S(`subagents`)}),(0,X.jsx)(co,{run:e,...S(`workers`)}),(0,X.jsx)(lo,{activity:v,desktop:u,...S(`plan`)}),(0,X.jsx)(uo,{run:e,identity:d,activity:v,...S(`usage`)}),(0,X.jsx)(fo,{run:e,references:l,conflicts:v.conflicts,hasReferences:c,onResume:()=>y.mutate(),...S(`workspace`)})]}):null]})}function Za(e,t,n,r,i){let a=T(),o=On(a.data),s=S(),c=vt(e,{queuePosition:e.status===`queued`?Jt(s.data??[]).get(e.id):void 0}),l=kt(i),u=!Kt(e)&&e.status!==`queued`,d=(0,Y.useMemo)(()=>r?ir(n.turns,u,t.turns):[],[r,n.turns,u,t.turns]),f=It(n)??[],p=Hi(e),m=or(d),h=da(f);return{line:c,...Qa(e,c,p,r?m:void 0,h),...$a(e,o),conflicts:l,waitReferences:Ia(e),agents:d,agentCounts:m,planEntries:f,planCounts:h,automations:pn(a.data)}}function Qa(e,t,n,r,i){let a=e.steps.every(e=>e.status===`done`||e.status===`skipped`),o=e.status===`done`&&a&&n===`complete`&&r!==void 0&&r.done===r.total&&i.done===i.total;return{allComplete:o,statusText:o?`All complete`:e.status!==`done`||r===void 0?t.label:n===`unknown`?`Workers unavailable`:n===`pending`?`In progress`:`Incomplete`,failed:t.attention.tone===`danger`||e.status===`cancelled`,glyph:o?(0,X.jsx)(he,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-success`}):(0,X.jsx)(Zt,{tone:t.attention.tone,shape:t.attention.shape,pulse:t.attention.pulse})}}function $a(e,t){return{cost:t.cost&&e.costUsd!==void 0?le(e.costUsd):void 0,tokens:t.tokens&&(e.inputTokens!==void 0||e.outputTokens!==void 0)?(0,X.jsx)(xn,{inputTokens:e.inputTokens,outputTokens:e.outputTokens}):void 0}}function eo(e){return e.allComplete?`text-success`:e.failed&&`text-danger`}function to(e){let t=Ca(e),n=Ta(e.currentStepId,t);return t.length>0?{steps:t,index:n,step:t[n]}:void 0}function no({run:e,identity:t,activity:n,references:r,open:i,onToggle:o}){let{cost:s}=n,c=[...new Map([...r,...n.waitReferences].map(e=>[ue(e),e])).values()];return(0,X.jsxs)(`button`,{type:`button`,"aria-expanded":i,"aria-label":ro(e,t,n,c,i),onClick:o,className:a(`flex min-h-11 w-full min-w-0 items-center px-3.5 py-2 text-start text-[14px] hover:bg-muted/40 active:bg-muted focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring`,i?`gap-2.5`:`gap-2`),children:[(0,X.jsx)(De,{"aria-hidden":!0,className:`size-4 shrink-0 text-accent-text`}),(0,X.jsx)(`span`,{className:`shrink-0 font-semibold`,children:`Activity`}),i?null:(0,X.jsx)(io,{run:e,identity:t,activity:n,summaryReferences:c}),i&&s?(0,X.jsx)(`span`,{"data-slot":`run-activity-cost`,className:`ms-auto shrink-0 text-[13px] text-muted-foreground tabular-nums`,children:s}):null,(0,X.jsx)(ye,{"aria-hidden":!0,className:a(`size-4 shrink-0 text-soft-foreground motion-safe:transition-transform motion-reduce:transition-none`,i&&!s&&`ms-auto`,i&&`rotate-180`)})]})}function ro(e,t,n,r,i){let{statusText:a,conflicts:o,cost:s}=n,c=`Session activity: ${a}${o.length?`; pull request conflicts`:``}${s?`; cost ${s}`:``}`;if(i)return c;let l=to(e)?.step,u=l?`; step ${l.name}, ${_a(ga(l.status,e.status))}`:``,d=r.length?`; ${r.map(e=>`${e.kind} #${e.number}`).join(`; `)}`:``;return`${c}${u}; runner ${t.runner}; model ${t.model}; effort ${t.effort}${d}`}function io({run:e,identity:t,activity:n,summaryReferences:r}){let{statusText:i,cost:o,conflicts:s}=n,c=to(e)?.step,l=[{id:`runner`,priority:2,content:t.runner},{id:`model`,priority:4,content:t.model},{id:`effort`,priority:3,content:t.effort},...o?[{id:`cost`,priority:1,content:(0,X.jsx)(`span`,{"data-slot":`run-activity-cost`,children:o})}]:[],...r.length||s.length?[{id:`chips`,priority:0,content:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Da,{run:e,references:r}),s.length>0?(0,X.jsxs)(`span`,{"data-slot":`run-activity-conflict`,className:`inline-flex items-center gap-1 font-medium text-conflict`,children:[(0,X.jsx)(xe,{"aria-hidden":!0,className:`size-3.5`}),`Conflicts`]}):null]})}]:[]];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{"data-slot":`run-activity-status`,title:i,className:a(`inline-flex min-w-[calc(0.875rem+3ch)] flex-[0_1_auto] items-center gap-1.5 text-[13px] whitespace-nowrap text-muted-foreground`,eo(n)),children:[n.glyph,(0,X.jsx)(`span`,{"data-slot":`run-activity-status-label`,className:`min-w-0 truncate`,children:i})]}),c?(0,X.jsxs)(`span`,{"data-slot":`run-activity-step`,className:a(`flex max-w-max min-w-[calc(1.375rem+2ch)] flex-[1000_1_0] items-center gap-1.5 text-[13px] text-muted-foreground`,e.status===`waiting`&&`max-md:hidden`),children:[(0,X.jsx)(_o,{step:c,runStatus:e.status,decorative:!0}),(0,X.jsx)(`span`,{"data-slot":`run-activity-step-name`,title:c.name,className:`min-w-0 truncate`,children:c.name})]}):null,(0,X.jsx)(`span`,{className:`-ms-2 flex min-w-0 flex-[1_1_0]`,children:(0,X.jsx)(Ea,{items:l,lead:8})})]})}function ao({run:e,activity:t,open:n,onToggle:r}){let{line:i,waitReferences:o}=t,s=Zi(e);return(0,X.jsxs)(Q,{slot:`status-row`,icon:t.glyph,title:(0,X.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,X.jsx)(`span`,{"data-slot":`run-activity-status`,className:a(`truncate`,eo(t)),children:t.statusText}),i.nextCheck?(0,X.jsxs)(`span`,{"data-slot":`run-activity-next-check`,className:`whitespace-normal text-[13px] font-normal text-muted-foreground`,children:[`Next check `,(0,X.jsx)(`time`,{dateTime:i.nextCheck.at,children:i.nextCheck.text})]}):null]}),summary:!n&&o.length>0?(0,X.jsx)(Ea,{items:[{id:`chips`,priority:0,content:(0,X.jsx)(Da,{run:e,references:o})}]}):void 0,open:n,onToggle:Fa(e)||s?r:void 0,children:[(0,X.jsx)(La,{run:e}),s?(0,X.jsx)(Qi,{run:e}):null]})}function oo({run:e,desktop:t,automations:n,open:r,onToggle:i}){let a=de(e),o=to(e);return!a&&!o?null:(0,X.jsxs)(Q,{slot:`workflow`,icon:o?(0,X.jsx)(_o,{step:o.step,runStatus:e.status}):(0,X.jsx)(Te,{className:`size-4`}),title:(0,X.jsxs)(X.Fragment,{children:[`Workflow`,a?(0,X.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[` · `,a]}):null]}),meta:o?{drop:o.step.name,keep:Ri(o.index+1,o.steps.length,t,`step`)}:void 0,open:r,onToggle:i,children:[o?(0,X.jsx)(ya,{steps:o.steps,runStatus:e.status}):null,(0,X.jsx)(go,{run:e,available:n})]})}function so({activity:e,desktop:t,onOpenWorker:n,open:r,onToggle:i}){let{agents:a,agentCounts:o}=e;return a.length===0?null:(0,X.jsx)(Q,{slot:`subagents`,icon:(0,X.jsx)(Ce,{className:`size-4`}),title:`Subagents`,meta:Ri(o.done,o.total,t),open:r,onToggle:i,children:(0,X.jsx)(ca,{agents:a,onSelect:n})})}function co({run:e,open:t,onToggle:n}){return Bi(e)?(0,X.jsx)(Wi,{run:e,open:t,onToggle:n}):null}function lo({activity:e,desktop:t,open:n,onToggle:r}){let{planEntries:i,planCounts:a}=e;return i.length===0?null:(0,X.jsx)(Q,{slot:`plan`,icon:(0,X.jsx)(pe,{className:`size-4`}),title:`Plan`,meta:Ri(a.done,a.total,t),open:n,onToggle:r,children:(0,X.jsx)(fa,{entries:i})})}function uo({run:e,identity:t,activity:n,open:r,onToggle:i}){let{cost:a,tokens:o}=n,s=e.modelIdentity?.includes(`/`)?e.modelIdentity.split(`/`)[0]:void 0,c=[...s?[{id:`provider`,priority:2,content:s}]:[],{id:`model`,priority:4,content:t.model},{id:`effort`,priority:3,content:t.effort},...a?[{id:`cost`,priority:1,content:a}]:[],...o?[{id:`tokens`,priority:0,content:o}]:[]];return(0,X.jsx)(Q,{slot:`usage`,icon:(0,X.jsx)(zn,{className:`size-4`}),title:`Usage & agent`,summary:(0,X.jsx)(`span`,{"data-slot":`run-activity-meta`,className:`contents`,children:(0,X.jsx)(Ea,{items:c})}),open:r,onToggle:i,children:(0,X.jsx)(ho,{run:e,tokens:o,cost:a})})}function fo({run:e,references:t,conflicts:n,hasReferences:r,onResume:i,open:a,onToggle:o}){let s=e.delegation?.role===`worker`?e.delegation.destroy:void 0;if(!(e.branch||e.worktreePath||r||vn(e)||ia(s)))return null;let c=n.length===1?`PR #${n[0]} conflicts`:`${n.length} PRs conflict`;return(0,X.jsx)(Q,{slot:`workspace`,icon:(0,X.jsx)(fe,{className:`size-4`}),title:`Workspace`,summary:!a&&t.length>0?(0,X.jsx)(`span`,{"data-slot":`run-activity-meta`,className:`contents`,children:(0,X.jsx)(Ea,{items:[...e.branch?[{id:`branch`,priority:0,content:(0,X.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.branch})}]:[],{id:`chips`,priority:1,content:(0,X.jsx)(Da,{run:e,references:t})},...n.length>0?[{id:`conflicts`,priority:2,content:(0,X.jsx)(`span`,{className:`font-medium text-conflict`,children:c})}]:[]]})}):void 0,meta:n.length>0?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-medium text-conflict`,children:[(0,X.jsx)(xe,{"aria-hidden":!0,className:`size-3.5`}),c]}):e.branch?(0,X.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.branch}):void 0,open:a,onToggle:o,children:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 text-[13px] text-muted-foreground`,children:[s?(0,X.jsx)(aa,{state:s}):null,(0,X.jsx)(yt,{run:e}),e.branch?(0,X.jsx)(mo,{label:`Branch`,children:(0,X.jsx)(St,{branch:e.branch})}):null,e.worktreePath?(0,X.jsx)(mo,{label:`Worktree`,children:(0,X.jsx)(`span`,{className:`min-w-0 break-all font-mono text-[12px] text-foreground`,children:e.worktreePath})}):null,(0,X.jsx)(_t,{run:e,canResume:Tn(e).terminal,onResume:i})]})})}function po(e,t){let n=(0,Y.useRef)(null),[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(t);a.current=t;let o=(0,Y.useRef)({active:!1,override:!1});return(0,Y.useEffect)(()=>e?.(e=>{if(e.direction===`tail`){o.current={active:!1,override:!1},i(!1);return}if(e.direction===`down`){i(!1);return}if(o.current.active=!0,o.current.override||!a.current)return;let t=n.current?.closest(`[data-slot="thread-dock"]`);!t||getComputedStyle(t).position!==`sticky`||e.distanceFromBottom<=t.getBoundingClientRect().height||i(!0)}),[e]),{ref:n,open:t&&!r,chose:e=>{i(!1),e&&o.current.active&&(o.current.override=!0)}}}function mo({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,X.jsx)(`span`,{className:`w-20 shrink-0 font-medium text-foreground`,children:e}),t]})}function ho({run:e,tokens:t,cost:n}){let{runner:r,account:i,model:a,effort:o,identity:s}=ka(e);return(0,X.jsxs)(`dl`,{"data-slot":`agent-details`,className:`grid min-w-0 grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-[13px]`,children:[t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Tokens`}),(0,X.jsx)(`dd`,{className:`min-w-0 text-[12px]`,children:t})]}):null,n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Cost`}),(0,X.jsx)(`dd`,{className:`min-w-0 font-mono text-[12px] tabular-nums`,children:n})]}):null,(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Runner`}),(0,X.jsx)(`dd`,{className:`min-w-0 break-all font-mono text-[12px]`,children:r}),i?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Account`}),(0,X.jsx)(`dd`,{"data-slot":`agent-badge-account`,className:`min-w-0 break-all font-mono text-[12px]`,children:i})]}):null,(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Model`}),(0,X.jsx)(`dd`,{className:`min-w-0 break-all font-mono text-[12px]`,children:a}),(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Effort`}),(0,X.jsx)(`dd`,{"data-slot":`agent-badge-effort`,className:`min-w-0 break-all font-mono text-[12px]`,children:o}),s?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`font-medium text-foreground`,children:`Identity`}),(0,X.jsx)(`dd`,{"data-slot":`agent-badge-identity`,className:`min-w-0 break-all font-mono text-[12px]`,children:s})]}):null]})}function go({run:e,available:t}){if(!e.automation)return null;let n=`inline-flex min-h-11 items-center rounded-sm text-[13px] font-medium md:min-h-8`;return(0,X.jsxs)(`p`,{className:`mt-2 text-[13px] text-muted-foreground`,children:[`Launched by`,` `,t?(0,X.jsx)(Ht,{to:`/automations/${encodeURIComponent(e.automation.automationId)}/log`,className:a(n,`text-foreground underline underline-offset-2`),children:`Automation`}):(0,X.jsx)(`span`,{"data-slot":`automation-origin`,title:`Automations are off on this server (CEZ_AUTOMATIONS)`,className:n,children:`Automation`})]})}function _o({step:e,runStatus:t,decorative:n=!1}){let r=ga(e.status,t),i=`size-4 shrink-0`;switch(r){case`active`:return(0,X.jsx)(Tt,{...n?{"aria-hidden":!0}:{role:`status`,"aria-label":`Step running`},"data-slot":`workflow-glyph`,"data-visual":r,className:a(i,`animate-spin stroke-pending motion-reduce:animate-none [html.light_&]:stroke-pending-strong`)});case`paused`:return(0,X.jsx)(Se,{...n?{"aria-hidden":!0}:{role:`img`,"aria-label":`Step paused`},"data-slot":`workflow-glyph`,"data-visual":r,className:a(i,xa)});case`failed`:return(0,X.jsx)(G,{"aria-hidden":!0,"data-slot":`workflow-glyph`,"data-visual":r,className:a(i,`text-danger`)});case`pending`:return(0,X.jsx)(K,{"aria-hidden":!0,"data-slot":`workflow-glyph`,"data-visual":r,className:a(i,`text-soft-foreground`)});case`done`:return(0,X.jsx)(he,{"aria-hidden":!0,"data-slot":`workflow-glyph`,"data-visual":r,className:a(i,`text-success`)})}}var vo=2e3;function yo(e){let t=0,n=0;for(let r of e)typeof r.seq==`number`&&(r.type===`session.ended`&&r.seq>t&&(t=r.seq),(r.type===`session.started`||r.type===`step-start`&&r.kind===`agent`)&&r.seq>n&&(n=r.seq));return t>n?t:0}function bo(e){let t=0,n=0;for(let r of e)typeof r.seq==`number`&&(r.type===`turn-end`&&r.seq>t&&(t=r.seq),(r.type===`turn.started`||r.type===`session.started`||r.type===`user-message`||r.type===`step-start`&&r.kind===`agent`)&&r.seq>n&&(n=r.seq));return t>n?t:0}function xo(e,t){let n=I(),r=(0,Y.useMemo)(()=>yo(t),[t]),i=(0,Y.useMemo)(()=>bo(t),[t]),a=e?.id,o=e?.status;(0,Y.useEffect)(()=>{if(!(r!==0&&(o===`running`||o===`waiting`))&&!(i!==0&&o===`running`)||a===void 0)return;let e=setTimeout(()=>{n.invalidateQueries({queryKey:d.runs.detail(a)}),n.invalidateQueries({queryKey:d.runs.list()})},vo);return()=>clearTimeout(e)},[r,i,a,o,n])}function So(e){let t=e.querySelector(`[data-slot="ask-origin"]`);return t&&(t.tabIndex=-1),t}function Co({pendingAskId:e,askSeq:t,rows:n,history:r,jumpToRow:i}){let[a,o]=(0,Y.useState)(void 0),s=(0,Y.useCallback)(()=>o(e),[e]),c=r?.visibleEvents,l=t!==void 0&&(c?.some(({seq:e})=>e===t)??!1),u=r?.hasOlder??!1,d=r?.isFetchingOlder??!1,f=r?.olderError,p=r?.loadOlder;return(0,Y.useEffect)(()=>{if(a===void 0)return;if(a!==e){o(void 0);return}let r=Ci(n,a,`origin`);if(r){o(void 0),i(r.key,r.index,So);return}if(!(p!==void 0&&u&&f===void 0&&t!==void 0&&!l)){o(void 0);return}d||p().catch(()=>{})},[a,e,n,c,l,u,d,f,p,t,i]),{reveal:s,seeking:a!==void 0&&a===e}}function wo(){let{id:e}=W(),t=p(e),n=wn(e),r=t.data?.status,i=(0,Y.useMemo)(()=>Nt(n.visibleEvents,{activeTurn:r===`running`}),[n.visibleEvents,r]),a=(0,Y.useMemo)(()=>Nt(n.currentEvents,{activeTurn:r===`running`}),[n.currentEvents,r]),o=(0,Y.useRef)(void 0),s=(0,Y.useCallback)(e=>{o.current=e},[]),{mutate:c}=u();if((0,Y.useEffect)(()=>{t.data&&o.current!==t.data.id&&Yt(t.data)&&c(t.data.id)},[c,t.data?.id,t.data?.status,t.data?.finishedAt,t.data?.seenAt,t.data?.archived]),xo(t.data,n.visibleEvents),t.isPending)return(0,X.jsx)(In,{});if(t.isError){let e=t.error instanceof k&&t.error.status===404;return(0,X.jsx)(on,{route:`task-thread`,density:`empty`,flushPadding:!0,children:(0,X.jsx)(sn,{icon:e?(0,X.jsx)(Ot,{}):(0,X.jsx)(Bn,{}),tone:e?`neutral`:`danger`,title:e?`Task not found`:`Could not load this task`,subtitle:e?`No run has this id. It may have been deleted, or the link is from another machine.`:t.error.message,actions:(0,X.jsx)(q,{asChild:!0,variant:`outline`,children:(0,X.jsx)(Ht,{to:`/`,children:`Back to tasks`})})})})}return n.isPending?(0,X.jsx)(In,{}):(0,X.jsx)(Eo,{run:t.data,thread:i,currentThread:a,history:n,onMarkedUnread:s})}var To=e=>({titles:Object.fromEntries(e.map(e=>[e.id,J(e)])),backends:Object.fromEntries(e.map(e=>[e.id,e.currentStepBackend??e.runner]))});function Eo({run:e,thread:t,currentThread:n=t,history:r,onMarkedUnread:i}){Vt();let a=L({queryKey:d.runs.list(),queryFn:({signal:e})=>te(_(),{signal:e}),select:To}),{pendingAsk:c,transcriptAsk:l,pendingAskId:u,historyLoading:f}=Do(r,n),p=O(e),m=Mt(e.status,e.error,t),h=kn(e),g=!h&&e.status!==`queued`,v=e.status===`queued`,x=Jn(e),S=sa(e),ee=ct(e.id),C=l||ne(e),{hasContinuation:T,continuable:D}=Oo(h,v,x),[k,A]=(0,Y.useState)(void 0),[j,M]=(0,Y.useState)(e.id);j!==e.id&&(M(e.id),A(void 0));let N=(0,Y.useMemo)(()=>k===void 0?void 0:lr(n.turns,k,g,t.turns),[n.turns,k,g,t.turns]),P=(0,Y.useMemo)(()=>k===void 0?[]:fr(t.turns,n.turns,k),[t.turns,n.turns,k]),F=b(e.id),I=cn(e),{providerBlocked:R,providerReason:z}=ko(h,yn(e),T,x),{mutateAsync:B}=o(e.id),{mutateAsync:V}=E(e.id),{mutateAsync:H}=s(e.id),U=(0,Y.useMemo)(()=>v?{onEditTask:async e=>{await B({task:e})},onEditMessage:(e,t)=>V({msgId:e,message:{text:t}}).then(()=>void 0),onRemoveMessage:e=>H(e).then(()=>void 0)}:void 0,[v,B,V,H]),re=f?void 0:u??null,ie=(0,Y.useMemo)(()=>bi(e,t,n,re),[e,t,n,re]),W=(0,Y.useMemo)(()=>Ei(ie,e.id),[ie,e.id]),oe=e.delegation?.role===`root`||e.delegation?.role===`worker`,ce=y(e.id,{enabled:oe}),le=(0,Y.useMemo)(()=>({...Er(e,void 0,ce.data?.titles),...a.data?.titles,[e.id]:J(e)}),[e,a.data,ce.data]),ue=(0,Y.useMemo)(()=>({...a.data?.backends,...Tr(e,void 0)}),[e,a.data]),de=(0,Y.useCallback)(t=>(0,X.jsx)(xr,{permission:t,runId:e.id,sessionOpen:h}),[e.id,h]),fe=(0,Y.useMemo)(()=>{if(U===void 0)return;let t={task:{onEdit:U.onEditTask,editLabel:`Edit the prompt`}};for(let n of e.queuedMessages??[])t[`queued:${n.id}`]={onEdit:e=>U.onEditMessage(n.id,e),onRemove:()=>U.onRemoveMessage(n.id)};return t},[U,e.queuedMessages]),pe=se(e,w()),{search:me}=ae(),he=Re(me,W.length),G=ui(`${e.id}:main`,{onLoadOlder:r?.hasOlder?r.loadOlder:void 0,onJumpToLatest:r?.jumpToLatest,rowKeys:W.map(({key:e})=>e)}),{pinnedAsk:ge,pendingQuestions:_e}=Ao(ie),ve=Co({pendingAskId:u,askSeq:r?c?.seq:void 0,rows:W,history:r,jumpToRow:G.jumpToRow}),ye=(0,Y.useRef)(u);f||(ye.current=u);let K=(0,Y.useRef)({rows:W,jumpToRow:G.jumpToRow,reveal:ve.reveal});K.current={rows:W,jumpToRow:G.jumpToRow,reveal:ve.reveal};let be=(0,Y.useCallback)(t=>t.placement===`origin`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[t.resolved&&t.context?(0,X.jsx)(ot,{text:t.context}):null,t.resolved?null:(0,X.jsx)(ai,{onGoToQuestion:()=>{let{rows:e,jumpToRow:n}=K.current,r=Ci(e,t.id,`pinned`);r&&n(r.key,r.index,e=>ei(e))}})]}):(0,X.jsx)(qe,{ask:t,run:e,onShowOrigin:()=>K.current.reveal()}),[e]);Bt(G.restickIfStuck);let xe=oi();return(0,X.jsxs)(on,{route:`task-thread`,density:t.turns.length===0?`empty`:`full`,flushPadding:!0,rootRef:xe,rootProps:{"data-run-id":e.id},children:[(0,X.jsx)(wt,{run:e,onMarkedUnread:()=>i?.(e.id)}),(0,X.jsx)(jo,{run:e,thread:t,history:r,footer:m,issueUrl:pe,sections:ie,renderAsk:be,renderPermission:de,messageActions:fe,scroll:G,mode:he,taskTitles:le,recipientBackends:ue}),(0,X.jsx)(ut,{status:e.status}),(0,X.jsx)(Fi,{runId:e.id,renderAsk:be,renderPermission:de,agent:N,entries:P,taskTitles:le,recipientBackends:ue,onClose:()=>A(void 0)}),(0,X.jsx)(Mo,{run:e,thread:t,currentThread:n,currentComplete:r?.currentComplete??!0,scroll:G,pendingQuestions:_e,onJump:()=>{let e=_e>0?ge?.id:void 0;G.jumpToLatest(e===void 0?void 0:ti(e,()=>ye.current===e))},onOpenWorker:A,sessionOpen:h,attention:p,queued:v,continuable:D,continueAction:x,stopAction:S,finishAction:ee,needsAnswer:C,sendMessage:F,reply:I,providerBlocked:R,providerReason:z}),(0,X.jsx)(`div`,{"data-slot":`thread-tail-anchor`,"aria-hidden":`true`,className:`h-px shrink-0 md:hidden`})]})}function Do(e,t){let n=e?Et(e.currentEvents):void 0;return{pendingAsk:n,transcriptAsk:e?n!==void 0:t.turns.some(e=>e.items.some(e=>e.kind===`ask`&&!e.resolved)),pendingAskId:e?n?.requestId:t.turns.flatMap(e=>e.items).reverse().find(e=>e.kind===`ask`&&!e.resolved)?.id,historyLoading:e!==void 0&&(e.isPending||e.contextPending)}}function Oo(e,t,n){let r=!e&&!t&&n.available;return{hasContinuation:r,continuable:r&&n.canContinue}}function ko(e,t,n,r){let i=e&&!t.usable,a=n&&!r.canContinue;return{providerBlocked:i||a,providerReason:i?t.reason:r.reason}}function Ao(e){let t=e.at(-1),n=t?.id===`pending-ask`?t.entries[0]:void 0;return{pinnedAsk:n,pendingQuestions:n?.kind===`ask`?n.questions.length:0}}function jo({run:e,thread:t,history:n,footer:r,issueUrl:o,sections:s,renderAsk:c,renderPermission:l,messageActions:u,scroll:d,mode:f,taskTitles:p,recipientBackends:m}){return(0,X.jsxs)(`div`,{"data-slot":`session-conversation`,className:`mx-auto flex w-full max-w-[var(--measure)] flex-1 flex-col gap-2.5 px-[18px] py-3 [padding-block-end:12px] md:gap-3.5 md:px-16 md:py-5 md:[padding-block-end:24px]`,children:[n?(0,X.jsx)(Lo,{hasOlder:n.hasOlder,loading:n.isFetchingOlder,error:n.olderError,fallback:n.fallback,retainedPages:n.retainedPages,onLoad:d.loadOlder}):null,(0,X.jsx)(Di,{runId:e.id,viewId:`main`,sections:s,mode:`document`,renderAsk:c,renderPermission:l,messageActions:u,scrollControls:d,renderMode:f,taskTitles:p,recipientBackends:m}),t.turns.length===0?e.status===`queued`?(0,X.jsx)(Ro,{run:e}):(0,X.jsx)(`p`,{"data-slot":`thread-empty`,className:`py-6 text-center text-xs text-soft-foreground`,children:`No session events yet.`}):null,e.status===`running`?(0,X.jsx)(Qe,{}):null,r&&r.state===`closed`?(0,X.jsxs)(`div`,{"data-slot":`thread-footer`,"data-state":r.state,className:a(`mt-auto flex items-center gap-2 border-t border-border pt-3 text-xs`,r.tone===`danger`?`text-danger`:`text-soft-foreground`),children:[r.label,i(ce(e))?(0,X.jsx)(`a`,{"data-slot":`pr-link`,href:ce(e),target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-foreground underline-offset-2 hover:underline`,children:`PR ↗`}):null,i(o)?(0,X.jsx)(`a`,{"data-slot":`issue-link`,href:o,target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-foreground underline-offset-2 hover:underline`,children:`Issue ↗`}):null]}):null,e.status===`review`?(0,X.jsx)(at,{run:e}):null]})}function Mo({run:e,thread:t,currentThread:n,currentComplete:r,scroll:i,pendingQuestions:a,onJump:o,onOpenWorker:s,sessionOpen:c,attention:l,queued:u,continuable:d,continueAction:f,stopAction:p,finishAction:m,needsAnswer:h,sendMessage:g,reply:_,providerBlocked:v,providerReason:y}){let b=ri(h&&a>0,i.scrollElRef);return(0,X.jsxs)(`div`,{"data-slot":`thread-dock`,"data-pending-ask":h||void 0,className:`relative z-10 bg-background pt-1 pb-2 md:pt-1.5 md:pb-4`,children:[i.pillVisible&&!b?(0,X.jsx)(`div`,{"data-slot":`thread-jump`,className:`pointer-events-none z-30 flex justify-center`,children:(0,X.jsx)(mi,{pendingQuestions:a,onJump:o})}):null,(0,X.jsxs)(`div`,{"data-slot":`thread-footer-content`,className:`mx-auto flex w-full max-w-[var(--measure)] flex-col gap-1.5 px-[14px] md:gap-2.5 md:px-16`,children:[(0,X.jsx)(Ya,{pendingAsk:h,run:e,thread:t,currentThread:n,currentComplete:r,onOpenWorker:s,readerScroll:i.subscribeReaderScroll},`${e.id}:${h}`),(0,X.jsx)(Hn,{run:e}),e.status===`waiting`&&c?(0,X.jsxs)(`div`,{"data-slot":`paused-hint`,className:`flex items-center gap-2 px-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(Zt,{tone:l.tone,shape:l.shape,pulse:l.pulse}),l.bucket===`permission`?`Choose an approval option above to continue`:l.bucket===`waiting`?`The agent is paused, waiting for your reply`:`${l.label.charAt(0).toUpperCase()}${l.label.slice(1)} — you can send a message to resume`]}):null,u?(0,X.jsxs)(`div`,{"data-slot":`queued-hint`,className:`flex items-center gap-2 px-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(Zt,{tone:`neutral`,shape:`ring`}),`Messages you add now are folded into the prompt before the run starts.`]}):null,d&&e.removedRunner!==void 0?(0,X.jsx)(`p`,{className:`px-1 text-xs text-muted-foreground`,role:`status`,children:F(e.removedRunner)}):d&&f.startsNewConversation?(0,X.jsx)(`p`,{className:`px-1 text-xs text-muted-foreground`,role:`status`,children:`Starts a new agent conversation.`}):null,(0,X.jsx)(Po,{run:e,thread:t,stopAction:p,finishAction:m,attention:l,needsAnswer:h,continuable:d,continueAction:f,queued:u,sendMessage:g,reply:_,providerBlocked:v,providerReason:y,sessionOpen:c})]})]})}function No(e,t,n){if(t)return{skillRunner:n.skillRunner,skillAccount:n.skillAccount};let r=e.steps.find(t=>t.id===e.currentStepId),i=e.workflowDef?.steps.find(t=>t.id===e.currentStepId);return{skillRunner:r?.backend??i?.runner??e.runner,skillAccount:r?.profileId??i?.agentProfile??e.agentProfile}}function Po({run:e,thread:t,stopAction:n,finishAction:r,attention:i,needsAnswer:a,continuable:o,continueAction:s,queued:c,sendMessage:l,reply:u,providerBlocked:d,providerReason:f,sessionOpen:p}){let m=Ui(e);return(0,X.jsx)(jn,{...No(e,o,s),onStop:Tn(e,m).cancel?n.stop:void 0,onFinish:An(e)?()=>r.mutateAsync().catch(()=>void 0):void 0,finishing:r.isPending,stopOnEmpty:Fo(e,i,a),stopping:n.stopping,retainDraftUntilSuccess:!0,compactFeedback:!0,pendingLabel:o?`Continuing…`:`Sending…`,failureHint:`Your draft is kept. Check the task status and connection, then retry.`,sessionControls:o?s.pills:void 0,onSubmit:o?(e,t)=>s.continueWith(e,t):c?(e,t)=>l.mutateAsync({text:e,images:t}):async(e,t)=>{let n=await u.send(e,t);if(n!==void 0)throw Error(n)},disabled:d||!p&&!c&&!o,disabledReason:d?f:`Session closed — no session to resume.`,footerEnd:d&&!s.providerPending?(0,X.jsx)(Ht,{to:`/settings/agent-defaults#providers`,className:`text-xs font-medium text-foreground underline underline-offset-4`,children:`Configure providers`}):void 0,allowEmptySubmit:o&&!a,emptySubmitVariant:e.status===`review`?`outline`:`primary`,emptySubmitLabel:o&&!a?`Continue`:void 0,placeholder:Io(e,c,o),autocompleteSkills:!0,quickReplies:!0,getMentionCandidates:()=>Ft(t)})}function Fo(e,t,n){return e.status===`queued`||e.status===`running`||e.status===`waiting`&&t.bucket===`none`&&!n}function Io(e,t,n){return t?`Add to the prompt — sent when the run starts…`:n?`Continue — add a prompt, or send to just reopen the session…`:e.status===`waiting`?`Reply — / for skills, @ for files…`:`Message the agent — / for skills, @ for files…`}function Lo({hasOlder:e,loading:t,error:n,fallback:r,retainedPages:i,onLoad:a}){return r?(0,X.jsx)(`p`,{"data-slot":`history-fallback`,className:`text-center text-xs text-soft-foreground`,role:`status`,children:`Progressive history is unavailable; showing the complete session.`}):!e&&!n?(0,X.jsxs)(`div`,{"data-slot":`history-start`,className:`flex items-center gap-3 text-[11px] text-soft-foreground`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-px flex-1 bg-border`}),`Start of session`,(0,X.jsx)(`span`,{"aria-hidden":!0,className:`h-px flex-1 bg-border`})]}):(0,X.jsxs)(`div`,{"data-slot":`history-boundary`,"data-retained-pages":i,"aria-busy":t,className:`flex min-h-8 items-center justify-center text-xs text-muted-foreground`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:a,disabled:t,className:`rounded-md px-3 py-1.5 font-medium hover:bg-muted disabled:cursor-wait`,children:t?`Loading 100 earlier items…`:n?`Couldn’t load earlier items · Retry`:`Load 100 earlier items`}),(0,X.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,children:t?`Loading earlier session history`:n||``})]})}function Ro({run:e}){let t=Pn(S().data??[],e.id);return(0,X.jsxs)(`div`,{"data-slot":`queued-state`,className:`flex flex-col items-center gap-1.5 py-10 text-center`,children:[(0,X.jsx)(Zt,{tone:`neutral`,shape:`ring`}),(0,X.jsxs)(`p`,{className:`text-[13px] font-medium`,children:[`Waiting for a free agent slot`,t===void 0?``:` — #${t} in queue`]}),(0,X.jsxs)(`p`,{className:`text-xs text-soft-foreground`,children:[e.workflow,` · starts automatically when a slot frees up`]})]})}export{wo as TaskThreadRoute};
@@ -1 +1 @@
1
- import{er as e}from"./toaster-UvSCLhYx.js";import{C as t,f as n,o as r}from"./task-groups-BSovus2j.js";function i(e){if(e.workflow===`(planned)`||e.workflow===`(inbox)`){let t=(e.steps??[]).find(e=>e.kind===`agent`);if(t?.name)return t.name}return e.workflow}function a(e){let t=/\/(\d+)\/?$/.exec(e.trim()),n=t?Number(t[1]):NaN;return Number.isInteger(n)&&n>0?n:null}function o(e){let t=new Set;for(let n of[e.pullRequestUrl,e.referencedPullRequestUrl,e.referencedIssueUrl]){let e=n?a(n):null;e!==null&&t.add(e)}for(let n of[e.prNumber,e.issueNumber,e.markerRefs?.pr,e.markerRefs?.issue])typeof n==`number`&&Number.isInteger(n)&&n>0&&t.add(n);for(let n of e.pullRequests??[])t.add(n.number);return[...t]}var s=[{id:`title`,kind:`text`,scopes:[`stored`],source:`summary`,texts:e=>[e.title]},{id:`titleSummary`,kind:`text`,scopes:[`stored`],source:`summary`,texts:e=>[e.titleSummary]},{id:`displayTitle`,kind:`text`,scopes:[`shown`],source:`reader`,texts:(e,t)=>[t.displayTitle]},{id:`branch`,kind:`text`,scopes:[`stored`,`shown`],source:`summary`,texts:e=>[e.branch]},{id:`workflow`,kind:`text`,scopes:[`stored`,`shown`],source:`summary`,texts:e=>[e.workflow]},{id:`workflowLabel`,kind:`text`,scopes:[`stored`,`shown`],source:`summary`,texts:e=>[e.workflowLabel]},{id:`automation`,kind:`text`,scopes:[`stored`,`shown`],source:`reader`,texts:(e,t)=>[t.automation],universe:e=>[...e.automationNames?.values()??[]]},{id:`projectName`,kind:`text`,scopes:[`shown`],source:`reader`,texts:(e,t)=>[t.projectName]},{id:`tags`,kind:`text`,scopes:[`shown`],source:`reader`,texts:(e,t)=>t.tags??[]},{id:`id`,kind:`identifier`,scopes:[`stored`],source:`summary`,texts:e=>[e.id]},{id:`urls`,kind:`link`,scopes:[`stored`],source:`summary`,texts:e=>[e.pullRequestUrl,e.referencedPullRequestUrl,e.referencedIssueUrl,...(e.pullRequests??[]).map(e=>e.url)]},{id:`heldReferences`,kind:`reference`,scopes:[`stored`],source:`summary`,numbers:o},{id:`shownReferences`,kind:`reference`,scopes:[`shown`],source:`reader`,numbers:(e,t)=>t.references?.()??[]}];function c(e){return e.trim().toLowerCase().split(/\s+/).filter(e=>e!==``)}function l(e,t){return t&&e.automationId!==void 0?t.get(e.automationId)??e.automationId:void 0}function u(e,t){let n=t.scope??`stored`,r=t.scope===`shown`?t.extras:{automation:l(e,t.automationNames)},i=[],a=[],o=[],c={text:i,identifier:a,link:o},u=[];for(let t of s)if(t.scopes.includes(n)){if(t.kind===`reference`){u.push(()=>t.numbers(e,r));continue}for(let n of t.texts(e,r))typeof n==`string`&&c[t.kind].push(n.toLowerCase())}let d;return{prose:i,ids:a,links:o,references:()=>d??=new Set(u.flatMap(e=>e().map(String)))}}function d(e,t,n={}){let r=c(t);if(r.length===0)return!1;let{prose:i,ids:a,links:o,references:s}=u(e,n);return r.every(e=>{if(i.some(t=>t.includes(e)))return!0;let t=e.replace(/^#/,``);return/^\d+$/.test(t)?s().has(String(Number(t)))||a.some(e=>e.startsWith(t)):a.some(t=>t.includes(e))||o.some(t=>t.includes(e))})}var f=new Set([`running`,`waiting`]);function p(e){return e?e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:`${Math.round(e/1024)} kB`:``}function m(e){return e===void 0?``:`$${e>=10?e.toFixed(0):e.toFixed(2)}`}function h(t,n=new Date){if(!e(t))return;let r=new Date(t.autoResumeAt);if(!Number.isFinite(r.getTime()))return;let i=r.toDateString()===n.toDateString(),a=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}).format(r);return{label:i?a:`${new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`}).format(r)} ${a}`,title:`Resumes automatically at ${new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`long`}).format(r)}`}}function g(e){return e.steps?i({workflow:e.workflow,steps:e.steps}):e.workflowLabel??e.workflow}function _(e,t,i=()=>``){let a=e.filter(e=>!r(e));return t.trim()?a.filter(e=>d(e,t,{scope:`shown`,extras:{displayTitle:n(e),automation:i(e),references:()=>v(e)}})):[...a]}function v(e){return T(e).map(e=>e.number)}function y(e,n){return e.filter(e=>t(e,n)).length}function b(e){return y(e)}function x(e){return S(e)[0]??e.pullRequests?.find(e=>e.url)?.url}function S(e){let t=[];return e.pullRequestUrl&&t.push(e.pullRequestUrl),!(e.markerRefs?.issue!==void 0&&e.markerRefs?.pr===void 0)&&e.referencedPullRequestUrl&&t.push(e.referencedPullRequestUrl),t}function C(e,t){if(e.referencedIssueUrl)return e.referencedIssueUrl;let n=e.issueNumber??e.markerRefs?.issue;if(!(!n||!t))return`${t}/issues/${n}`}function w(e){let t=`${e.kind}#${e.number}`;if(!e.url)return`${t}@project:${e.projectId??`default`}`;try{let n=new URL(e.url),r=n.pathname.split(`/`).filter(Boolean).slice(0,2).join(`/`);return`${t}@${n.host.toLowerCase()}/${r.toLowerCase()}`}catch{return`${t}@${e.url}`}}function T(e,t,n=e.projectId){let r=S(e),i=e.markerRefs?.pr,a=[...i===void 0||[...r,...(e.pullRequests??[]).flatMap(e=>e.url?[e.url]:[])].some(e=>M(e)===String(i))?[]:[{kind:`PR`,number:i}],...r.map(e=>({kind:`PR`,url:e})),{kind:`PR`,number:e.prNumber},...(e.pullRequests??[]).map(e=>({kind:`PR`,number:e.number,...e.url?{url:e.url}:{},authoritative:!0})),{kind:`Issue`,url:C(e,t)},{kind:`Issue`,number:e.issueNumber}],o=new Set,s=[];for(let e of a){let r=e.url?Number(M(e.url)):e.number;if(!r||!Number.isInteger(r)||!e.url&&!e.authoritative&&s.some(t=>t.url&&t.kind===e.kind&&t.number===r))continue;let i=e.url??E(e.kind,r,t),a={kind:e.kind,number:r,...i?{url:i}:n===void 0?{}:{projectId:n}},c=w(a);o.has(c)||(o.add(c),s.push(a))}return s}function E(e,t,n){if(n)return`${n}/${e===`PR`?`pull`:`issues`}/${t}`}function D(e){return T(e)[0]}function O(e,t){if(!e.url)return!0;if(!t)return!1;let n=k(t);return n!==void 0&&k(e.url)===n}function k(e){try{let t=new URL(e),[n,r]=t.pathname.split(`/`).filter(Boolean);return n&&r?`${t.host}/${n}/${r}`.toLowerCase():void 0}catch{return}}function A(e,t){let n=[];for(let r of T(e,t)){if(!O(r,t))continue;let e=r.kind===`PR`?`pr`:`issue`;n.some(t=>t.kind===e&&t.number===r.number)||n.push({kind:e,number:r.number})}return n}function j(e,t,n,r){if(O(n,r))return`/p/${e}/tasks/${t}/${n.kind===`PR`?`pr`:`issue`}/${n.number}`}function M(e){return/\/(\d+)\/?(?:[?#].*)?$/.exec(e)?.[1]??null}function N(e,t){let n=f.has(e.status)?t:void 0;if(n)return{cpu:{text:`${n.cpuPct.toFixed(0)}%`,kind:`live`},mem:{text:p(n.rssBytes),kind:`live`}};let r=p(e.peakRssBytes);return{cpu:{text:``,kind:`none`},mem:r?{text:`peak ${r}`,kind:`peak`,title:`peak — run finished${e.peakProcCount?` · ${e.peakProcCount} procs`:``}`}:{text:``,kind:`none`}}}export{N as _,O as a,h as c,C as d,j as f,T as g,D as h,p as i,v as l,x as m,b as n,M as o,A as p,m as r,w as s,_ as t,y as u,g as v,d as y};
1
+ import{tr as e}from"./toaster-C-xqAWVX.js";import{C as t,f as n,o as r}from"./task-groups-CHHLB77I.js";function i(e){if(e.workflow===`(planned)`||e.workflow===`(inbox)`){let t=(e.steps??[]).find(e=>e.kind===`agent`);if(t?.name)return t.name}return e.workflow}function a(e){let t=/\/(\d+)\/?$/.exec(e.trim()),n=t?Number(t[1]):NaN;return Number.isInteger(n)&&n>0?n:null}function o(e){let t=new Set;for(let n of[e.pullRequestUrl,e.referencedPullRequestUrl,e.referencedIssueUrl]){let e=n?a(n):null;e!==null&&t.add(e)}for(let n of[e.prNumber,e.issueNumber,e.markerRefs?.pr,e.markerRefs?.issue])typeof n==`number`&&Number.isInteger(n)&&n>0&&t.add(n);for(let n of e.pullRequests??[])t.add(n.number);return[...t]}var s=[{id:`title`,kind:`text`,scopes:[`stored`],source:`summary`,texts:e=>[e.title]},{id:`titleSummary`,kind:`text`,scopes:[`stored`],source:`summary`,texts:e=>[e.titleSummary]},{id:`displayTitle`,kind:`text`,scopes:[`shown`],source:`reader`,texts:(e,t)=>[t.displayTitle]},{id:`branch`,kind:`text`,scopes:[`stored`,`shown`],source:`summary`,texts:e=>[e.branch]},{id:`workflow`,kind:`text`,scopes:[`stored`,`shown`],source:`summary`,texts:e=>[e.workflow]},{id:`workflowLabel`,kind:`text`,scopes:[`stored`,`shown`],source:`summary`,texts:e=>[e.workflowLabel]},{id:`automation`,kind:`text`,scopes:[`stored`,`shown`],source:`reader`,texts:(e,t)=>[t.automation],universe:e=>[...e.automationNames?.values()??[]]},{id:`projectName`,kind:`text`,scopes:[`shown`],source:`reader`,texts:(e,t)=>[t.projectName]},{id:`tags`,kind:`text`,scopes:[`shown`],source:`reader`,texts:(e,t)=>t.tags??[]},{id:`id`,kind:`identifier`,scopes:[`stored`],source:`summary`,texts:e=>[e.id]},{id:`urls`,kind:`link`,scopes:[`stored`],source:`summary`,texts:e=>[e.pullRequestUrl,e.referencedPullRequestUrl,e.referencedIssueUrl,...(e.pullRequests??[]).map(e=>e.url)]},{id:`heldReferences`,kind:`reference`,scopes:[`stored`],source:`summary`,numbers:o},{id:`shownReferences`,kind:`reference`,scopes:[`shown`],source:`reader`,numbers:(e,t)=>t.references?.()??[]}];function c(e){return e.trim().toLowerCase().split(/\s+/).filter(e=>e!==``)}function l(e,t){return t&&e.automationId!==void 0?t.get(e.automationId)??e.automationId:void 0}function u(e,t){let n=t.scope??`stored`,r=t.scope===`shown`?t.extras:{automation:l(e,t.automationNames)},i=[],a=[],o=[],c={text:i,identifier:a,link:o},u=[];for(let t of s)if(t.scopes.includes(n)){if(t.kind===`reference`){u.push(()=>t.numbers(e,r));continue}for(let n of t.texts(e,r))typeof n==`string`&&c[t.kind].push(n.toLowerCase())}let d;return{prose:i,ids:a,links:o,references:()=>d??=new Set(u.flatMap(e=>e().map(String)))}}function d(e,t,n={}){let r=c(t);if(r.length===0)return!1;let{prose:i,ids:a,links:o,references:s}=u(e,n);return r.every(e=>{if(i.some(t=>t.includes(e)))return!0;let t=e.replace(/^#/,``);return/^\d+$/.test(t)?s().has(String(Number(t)))||a.some(e=>e.startsWith(t)):a.some(t=>t.includes(e))||o.some(t=>t.includes(e))})}var f=new Set([`running`,`waiting`]);function p(e){return e?e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:`${Math.round(e/1024)} kB`:``}function m(e){return e===void 0?``:`$${e>=10?e.toFixed(0):e.toFixed(2)}`}function h(t,n=new Date){if(!e(t))return;let r=new Date(t.autoResumeAt);if(!Number.isFinite(r.getTime()))return;let i=r.toDateString()===n.toDateString(),a=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`}).format(r);return{label:i?a:`${new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`}).format(r)} ${a}`,title:`Resumes automatically at ${new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`long`}).format(r)}`}}function g(e){return e.steps?i({workflow:e.workflow,steps:e.steps}):e.workflowLabel??e.workflow}function _(e,t,i=()=>``){let a=e.filter(e=>!r(e));return t.trim()?a.filter(e=>d(e,t,{scope:`shown`,extras:{displayTitle:n(e),automation:i(e),references:()=>v(e)}})):[...a]}function v(e){return T(e).map(e=>e.number)}function y(e,n){return e.filter(e=>t(e,n)).length}function b(e){return y(e)}function x(e){return S(e)[0]??e.pullRequests?.find(e=>e.url)?.url}function S(e){let t=[];return e.pullRequestUrl&&t.push(e.pullRequestUrl),!(e.markerRefs?.issue!==void 0&&e.markerRefs?.pr===void 0)&&e.referencedPullRequestUrl&&t.push(e.referencedPullRequestUrl),t}function C(e,t){if(e.referencedIssueUrl)return e.referencedIssueUrl;let n=e.issueNumber??e.markerRefs?.issue;if(!(!n||!t))return`${t}/issues/${n}`}function w(e){let t=`${e.kind}#${e.number}`;if(!e.url)return`${t}@project:${e.projectId??`default`}`;try{let n=new URL(e.url),r=n.pathname.split(`/`).filter(Boolean).slice(0,2).join(`/`);return`${t}@${n.host.toLowerCase()}/${r.toLowerCase()}`}catch{return`${t}@${e.url}`}}function T(e,t,n=e.projectId){let r=S(e),i=e.markerRefs?.pr,a=[...i===void 0||[...r,...(e.pullRequests??[]).flatMap(e=>e.url?[e.url]:[])].some(e=>M(e)===String(i))?[]:[{kind:`PR`,number:i}],...r.map(e=>({kind:`PR`,url:e})),{kind:`PR`,number:e.prNumber},...(e.pullRequests??[]).map(e=>({kind:`PR`,number:e.number,...e.url?{url:e.url}:{},authoritative:!0})),{kind:`Issue`,url:C(e,t)},{kind:`Issue`,number:e.issueNumber}],o=new Set,s=[];for(let e of a){let r=e.url?Number(M(e.url)):e.number;if(!r||!Number.isInteger(r)||!e.url&&!e.authoritative&&s.some(t=>t.url&&t.kind===e.kind&&t.number===r))continue;let i=e.url??E(e.kind,r,t),a={kind:e.kind,number:r,...i?{url:i}:n===void 0?{}:{projectId:n}},c=w(a);o.has(c)||(o.add(c),s.push(a))}return s}function E(e,t,n){if(n)return`${n}/${e===`PR`?`pull`:`issues`}/${t}`}function D(e){return T(e)[0]}function O(e,t){if(!e.url)return!0;if(!t)return!1;let n=k(t);return n!==void 0&&k(e.url)===n}function k(e){try{let t=new URL(e),[n,r]=t.pathname.split(`/`).filter(Boolean);return n&&r?`${t.host}/${n}/${r}`.toLowerCase():void 0}catch{return}}function A(e,t){let n=[];for(let r of T(e,t)){if(!O(r,t))continue;let e=r.kind===`PR`?`pr`:`issue`;n.some(t=>t.kind===e&&t.number===r.number)||n.push({kind:e,number:r.number})}return n}function j(e,t,n,r){if(O(n,r))return`/p/${e}/tasks/${t}/${n.kind===`PR`?`pr`:`issue`}/${n.number}`}function M(e){return/\/(\d+)\/?(?:[?#].*)?$/.exec(e)?.[1]??null}function N(e,t){let n=f.has(e.status)?t:void 0;if(n)return{cpu:{text:`${n.cpuPct.toFixed(0)}%`,kind:`live`},mem:{text:p(n.rssBytes),kind:`live`}};let r=p(e.peakRssBytes);return{cpu:{text:``,kind:`none`},mem:r?{text:`peak ${r}`,kind:`peak`,title:`peak — run finished${e.peakProcCount?` · ${e.peakProcCount} procs`:``}`}:{text:``,kind:`none`}}}export{N as _,O as a,h as c,C as d,j as f,T as g,D as h,p as i,v as l,x as m,b as n,M as o,A as p,m as r,w as s,_ as t,y as u,g as v,d as y};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./react-runtime-CCIEwYL0.js";import{t}from"./utils-DSMR_WLb.js";import{gr as n,hr as r,ti as i}from"./toaster-UvSCLhYx.js";import{h as a,p as o,v as s}from"./live-protocol-DMhTnCmf.js";import{t as c}from"./createLucideIcon-BHp8sXmF.js";import{t as l}from"./app-window-CSHwDX9N.js";import{t as u}from"./play-CmVAj_fu.js";import{i as d,n as ee,o as te,r as ne}from"./tool-display-B9NN44oU.js";import{t as re}from"./square-terminal-B6RYYieR.js";import{t as ie}from"./button-B7MKxYjT.js";import{t as ae}from"./status-dot-BRzVlF2X.js";import{a as oe,o as se}from"./format-BU7D3IfE.js";import{Kn as ce,f,p}from"./index-AgYIT7cV.js";var m=c(`server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),h=e(),g={registered:e=>e.server.answeredAtRegistration?{label:`Open`,run:!1}:{label:`Run and open`,run:!0},adopted:()=>({label:`Open`,run:!1}),starting:()=>({label:`Open`,run:!1}),up:()=>({label:`Open`,run:!1}),stalled:()=>({label:`View`,run:!1}),exited:()=>({label:`Start again`,run:!0}),stopped:()=>({label:`Start again`,run:!0}),unavailable:()=>void 0};function _(e){let{text:t,...n}=p(e),r={...n,status:t},i=g[e.state](e);return i?{...r,action:i}:r}var v={"Run and open":u,Open:l,View:ce,"Start again":te};function y({entry:e,inPreview:n,onOpen:r}){let{server:i}=e,a=_(e),o=e.state===`unavailable`,s=r?a.action:void 0,c=f(i.command),l=oe(i.registeredAt);return(0,h.jsxs)(`div`,{"data-slot":`preview-server-card`,"data-state":e.state,className:t(`min-w-0 rounded-lg border border-border bg-card px-3.5 py-3 text-sm`,o&&`text-muted-foreground`),children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-xs text-soft-foreground`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 font-mono`,children:[(0,h.jsx)(m,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`truncate`,children:`cezar_preview_serve`})]}),o?(0,h.jsx)(`span`,{children:`worktree removed`}):l?(0,h.jsx)(`span`,{children:se(l)}):null]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,h.jsx)(ae,{tone:a.tone,shape:a.ring?`ring`:`filled`,pulse:a.pulse===!0,"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`font-semibold text-foreground`,children:i.label}),(0,h.jsxs)(`span`,{className:`font-mono text-muted-foreground`,children:[`:`,i.port]}),(0,h.jsx)(`span`,{className:`text-muted-foreground`,children:a.status})]}),(0,h.jsx)(le,{entry:e,inPreview:n,action:s,onOpen:r})]}),(0,h.jsxs)(`div`,{className:`mt-2.5 min-w-0 rounded-md bg-muted px-3 py-2 font-mono text-xs`,children:[(0,h.jsx)(`p`,{className:`break-words whitespace-pre-wrap text-foreground`,children:i.command}),i.cwd?(0,h.jsxs)(`p`,{className:`mt-1 flex gap-3 text-soft-foreground`,children:[(0,h.jsx)(`span`,{children:`cwd`}),(0,h.jsx)(`span`,{className:`break-all`,children:i.cwd})]}):null]}),s?.run?(0,h.jsx)(b,{icon:(0,h.jsx)(re,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),children:`${s.label===`Start again`?`Starting again`:`Opening`} runs ${c} in this task's worktree, on the host.`}):null,o?(0,h.jsx)(b,{children:`The worktree this server ran in is gone. Register it again from a new task.`}):null]})}function le({entry:e,inPreview:t,action:n,onOpen:r}){let{server:i}=e,a=t&&n!==void 0&&!n.run,o=a?`In preview`:n?.label,s=a?l:n?v[n.label]:null;return n&&o&&s?(0,h.jsxs)(ie,{variant:a||n.label===`View`||n.label===`Open`&&e.state===`starting`?`outline`:`contrast`,size:`sm`,className:`max-md:h-11 max-md:px-3.5`,onClick:()=>r?.({port:i.port,run:n.run}),children:[(0,h.jsx)(s,{"aria-hidden":`true`}),o]}):null}function b({icon:e,children:t}){return(0,h.jsxs)(`p`,{className:`mt-2.5 flex items-start gap-2 text-xs text-muted-foreground`,children:[e,(0,h.jsx)(`span`,{children:t})]})}function x(e,t){return e.kind===`message`&&e.role===`user`&&e.skillInput?.source===t&&typeof e.skillInput.id==`string`&&e.skillInput.id!==``}function ue(){return{turns:[],itemsById:new Map,turnSeq:0,eventSeq:0,permissions:new Map,conversationEntries:new Map,outcomesByRequest:new Map,seenInputs:new Set,previewByPort:new Map,handedOff:!1}}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(e){return typeof e==`string`?e:void 0}function w(e){let t=typeof e==`string`?new Date(e):void 0;return!t||Number.isNaN(t.getTime())?``:` · ${t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`})}`}function T(e){if(!(typeof e!=`string`||e===``))return Number.isFinite(new Date(e).getTime())?e:void 0}function de(e){return i.safeParse(e).data}function E(e,t){e.turnSeq+=1;let n={id:t===void 0?`turn-fallback-${e.turnSeq}`:`turn-seq-${t}`,entries:[],v2Items:!1};return e.turns.push(n),n}function D(e){return e.turns.at(-1)??E(e)}function O(e,t){let n={origin:`meta`,entry:t,firstSeq:e.eventSeq,lastSeq:e.eventSeq};return D(e).entries.push(n),n}var k=[/^run failed\s+[—-]\s+/,/^continue failed(?:\s+[—-]\s+|:\s+)/,/^step\s+"[^"]+"\s+failed:\s+/,/^step\s+\S+\s+failed\s+[—-]\s+/],A=/^(?:run failed\s+[—-]\s+|continue failed(?:\s+[—-]\s+|:\s+))/;function j(e){return e.trim().replace(/\s+/g,` `)}function M(e){let t=e.trim(),n=!0;for(;n;){n=!1;for(let e of k){let r=t.replace(e,``).trim();r!==t&&r!==``&&(t=r,n=!0)}}return j(t)}function N(e,t,n){if(t===e.primarySource&&n===e.primaryText||e.draft.entry.kind!==`note`)return;let r=e.draft.entry;r.details?.some(e=>e.source===t&&e.text===n)||(r.details=[...r.details??[],{source:t,text:n}])}function P(e,t,n){let r=e.failures;if(r)for(let e=r.length-1;e>=0;--e){let i=r[e];if(t!==``&&i.cause===t||t===``&&i.fatal&&(n===void 0||i.stepId===void 0||i.stepId===n))return i}}function F(e,t,n){let r=D(e),i=P(r,n.cause,n.stepId);if(i){i.draft.lastSeq=Math.max(i.draft.lastSeq,t.seq),n.fatal&&(i.fatal=!0),n.stepId!==void 0&&i.stepId===void 0&&(i.stepId=n.stepId),N(i,n.source,n.text);return}let a={draft:O(e,{kind:`note`,id:n.id,text:n.text,tone:`danger`}),cause:n.cause,primarySource:n.source,primaryText:n.text,...n.stepId===void 0?{}:{stepId:n.stepId},fatal:n.fatal};r.failures=[...r.failures??[],a]}function I(e,t,n){if(!A.test(n))return!1;let r=e.turns.at(-1);if(!r)return!1;let i=M(n);if(i===``)return!1;let a=P(r,i,C(t.stepId));return a?(a.draft.lastSeq=Math.max(a.draft.lastSeq,t.seq),a.fatal=!0,N(a,`lifecycle`,n),!0):!1}function L(e,t,n){let r=e.turns.at(-1);if(!r)return;let i=P(r,n?M(n):``,C(t.stepId));i&&(i.fatal=!0)}function R(e){for(let t of e.permissions.values())t.status===`pending`&&(t.status=`expired`)}function z(e,t){let n=C(e.stepId);return n===void 0?t:`${n}:${t}`}function B(e,t){t.v2Items=!0;for(let n of t.entries)n.origin===`v1`&&n.entry.kind===`tool`&&e.itemsById.delete(n.entry.id);t.entries=t.entries.filter(e=>!(e.origin===`v1`&&e.entry.kind===`tool`))}function V(e,t,n,r,i,a=!1){let o=n.kind===`message`&&i!==void 0?{...n,ts:i}:{...n};!t.v2Items&&o.kind!==`hook`&&B(e,t);let s=e.itemsById.get(r);if(s&&s.turn===t){s.entry.entry=o,s.entry.lastSeq=e.eventSeq,s.entry.streaming=a;return}let c={origin:`v2`,entry:o,firstSeq:e.eventSeq,lastSeq:e.eventSeq,streaming:a};t.entries.push(c),e.itemsById.set(r,{turn:t,entry:c})}var H={"not-delivered":0,queued:1,delivered:2,consumed:3},fe=[`instruction`,`resumed`,`requestId`,`relationship`,`state`,`createdAt`,`requestHash`,`deadline`];function U(e){let t={};for(let n of fe)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}function W(e,t){if(t.messageKind!==`request`)return;let n=e.outcomesByRequest.get(t.messageId);n&&(t.outcome={status:n.status,...n.replyId===void 0?{}:{replyId:n.replyId},observedAt:n.observedAt})}function pe(e,t){let n=e.conversationEntries.get(t);n&&W(e,n)}function me(e,t,n,r){(H[e.delivery]<H.delivered||H[n]>H[e.delivery])&&(e.delivery=n),t.text!==``&&(e.text=t.text),Object.assign(e,U(t)),r.deliveredAt!==void 0&&(e.deliveredAt=r.deliveredAt),r.consumedAt!==void 0&&(e.consumedAt=r.consumedAt),r.recordedAt!==void 0&&(n===`delivered`||e.delivery!==`delivered`)&&(e.recordedAt=r.recordedAt)}function G(e,t,n,r){let i=e.conversationEntries.get(t.id);if(i){me(i,t,n,r),W(e,i);return}let a={kind:`conversation`,id:`conversation-message:${t.id}`,messageId:t.id,text:t.text,senderRunId:t.senderRunId,recipientRunId:t.recipientRunId,messageKind:t.kind,delivery:n,...r,...U(t)};W(e,a),e.conversationEntries.set(t.id,a),O(e,a)}function he(e,t){let n=w(t.ts),r=C(t.message),i=t.notify===!1?`Stopped notifying the webhook${n}`:`${e.handedOff?`Note sent to webhook`:`Handed off to webhook`}${n}${r?` — ${r}`:``}`;e.handedOff=t.notify!==!1,O(e,{kind:`note`,id:`v1:${t.seq}`,text:i,tone:`dim`,icon:`handoff`})}function ge(e,t){let n=typeof t.attempts==`number`?t.attempts:void 0,r=C(t.webhookName),i=`${r?`Delivery to ${r} failed`:`Webhook delivery failed`}${C(t.event)?` (${C(t.event)})`:``}${n?` after ${n} attempt${n===1?``:`s`}`:``}: ${C(t.error)??`unknown error`}`;O(e,{kind:`note`,id:`v1:${t.seq}`,text:i,tone:`danger`})}function _e(e,t){let n=C(t.webhookName)??`webhook`,r=C(t.title),i=`v1:${t.seq}`;if(t.ok===!1){O(e,{kind:`note`,id:i,text:`Report to ${n} failed: ${C(t.error)??`unknown error`}`,tone:`danger`});return}let a=`${t.dryRun===!0?`Report to ${n} (dry run, nothing sent)`:`Sent report to ${n}`}${w(t.ts)}${r?` — ${r}`:``}`;O(e,t.dryRun===!0?{kind:`note`,id:i,text:a,tone:`dim`}:{kind:`note`,id:i,text:a,tone:`dim`,icon:`handoff`})}function ve(e,t){let n=t.payload??{},r=`Webhook (dry run, nothing sent): ${C(t.event)??`delivery`}${C(n.status)?` · ${C(n.status)}`:``}`;O(e,{kind:`note`,id:`v1:${t.seq}`,text:r,tone:`dim`})}function ye(e,t){let n=r.safeParse(t.server);if(!n.success)return;let i=e.previewByPort.get(n.data.port);i&&(i.turn.entries=i.turn.entries.filter(e=>e!==i.draft));let a=D(e),o={origin:`meta`,firstSeq:t.seq,lastSeq:t.seq,entry:{kind:`preview-server`,id:`preview-server:${n.data.port}`,server:n.data,state:`registered`,stateAt:t.ts}};a.entries.push(o),e.previewByPort.set(n.data.port,{turn:a,draft:o})}function be(e,t){let r=n.safeParse(t.state),i=typeof t.port==`number`?e.previewByPort.get(t.port):void 0;if(!r.success||!i||i.draft.entry.kind!==`preview-server`)return;let{server:a,id:o}=i.draft.entry;i.draft.lastSeq=t.seq,i.draft.entry={kind:`preview-server`,id:o,server:a,state:r.data,stateAt:t.ts,...typeof t.exitCode==`number`?{exitCode:t.exitCode}:{},...t.reason===`user`||t.reason===`idle`?{reason:t.reason}:{}}}function xe(e,t){let n=a.safeParse(t);if(!n.success)return;let{message:r,delivery:i,deliveredAt:o,consumedAt:s,ts:c}=n.data;G(e,r,i,{deliveredAt:o,consumedAt:s,recordedAt:c})}function Se(e,t){let n=s.safeParse(t);if(!n.success)return;let{outcome:r}=n.data,i=e.outcomesByRequest.get(r.requestId);i&&!(i.status===`timed-out`&&r.status===`replied-late`)||(e.outcomesByRequest.set(r.requestId,r),pe(e,r.requestId))}function Ce(e,t){let n=o.safeParse(t);if(!n.success)return;let{input:r}=n.data;if(!e.seenInputs.has(r.id)){if(e.seenInputs.add(r.id),r.conversation){G(e,{id:r.id,text:r.text,createdAt:r.createdAt,...r.conversation},`delivered`,{deliveredAt:r.deliveredAt,recordedAt:n.data.ts});return}O(e,{kind:`note`,id:`agent-input:${r.id}`,text:r.text,tone:`dim`,attribution:{source:r.source,parentRunId:r.parentRunId}})}}function we(e,t){let n=C(t.text)??``,r=e.pendingAsk;e.pendingAsk&&!e.pendingAsk.resolved&&(e.pendingAsk.resolved=!0,e.pendingAsk.answeredBy=`human`,n!==``&&(e.pendingAsk.answer=n),e.pendingAsk=void 0);let i=E(e,t.seq),a=T(t.ts);i.userMessage={text:n,ask:r,imageCount:typeof t.imageCount==`number`?t.imageCount:0,images:Array.isArray(t.images)?t.images.filter(e=>typeof e==`string`):[],...a===void 0?{}:{ts:a}},a!==void 0&&(i.startedAt=a)}function Te(e,t){let n=e.turns.at(-1),r=n&&n.turnId===void 0&&!n.v2Items?n:E(e,t.seq);r.turnId=C(t.turnId),r.startedAt??=T(t.ts)}function Ee(e,t){for(let n=e.turns.length-1;n>=0;--n)if(e.turns[n].turnId===t)return e.turns[n];return e.turns.at(-1)}function De(e,t){R(e);let n=Ee(e,C(t.turnId));if(!n)return;let r=T(t.ts);n.completed={stopReason:C(t.stopReason)??`end_turn`,...typeof t.costUsd==`number`?{costUsd:t.costUsd}:{},...r===void 0?{}:{ts:r}}}var K=new Set([`message`,`reasoning`,`tool`,`hook`]),Oe=e=>K.has(e.kind);function ke(e){if(!(!S(e)||!K.has(e.kind)))return typeof e.id==`string`&&e.id!==``?e:void 0}function q(e,t){let n=ke(t.item);if(!n)return;let r=z(t,n.id),i=e.itemsById.get(r),a=t.type===`item.completed`,o=!a&&(n.kind===`message`||n.kind===`reasoning`);V(e,i?.turn??D(e),n,r,a?T(t.ts):void 0,o)}function Ae(e,t){let n=e.itemsById.get(z(t,C(t.itemId)??``)),r=C(t.delta)??``;if(!n||r===``||!Oe(n.entry.entry))return;let i=n.entry.entry;n.entry.lastSeq=t.seq,t.field===`output`&&i.kind===`tool`?i.output=(i.output??``)+r:t.field!==`output`&&(i.kind===`message`||i.kind===`reasoning`)&&(i.text+=r)}function je(e,t){let n=D(e),r=C(t.text)??``;if(r===``)return;let i=T(t.ts);n.entries.push({origin:`v1`,firstSeq:t.seq,lastSeq:t.seq,entry:{kind:`message`,id:`v1:${t.seq}`,role:`assistant`,text:r,...i===void 0?{}:{ts:i}}})}var Me=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function Ne(e){if(!S(e)||!Array.isArray(e.todos))return;let t=[];for(let n of e.todos){if(!S(n)||typeof n.content!=`string`)return;t.push({content:n.content,status:Me.has(n.status)?n.status:`pending`,...typeof n.activeForm==`string`?{activeForm:n.activeForm}:{}})}return t}var Pe=new Set([`subAgentActivity`,`collabAgentToolCall`,`collabToolCall`]);function Fe(e,t){let n=D(e),r=C(t.tool)??`Tool`;if(n.v2Items||Pe.has(r))return;let i=ee(r,t.input),a=i.toolKind===`plan`?Ne(t.input):void 0;a!==void 0&&(n.planEntries=a);let o={kind:`tool`,id:C(t.id)??`v1:${t.seq}`,name:r,toolKind:i.toolKind,title:i.title,status:`running`,input:t.input},s={origin:`v1`,entry:o,firstSeq:t.seq,lastSeq:t.seq};n.entries.push(s),e.itemsById.set(o.id,{turn:n,entry:s})}function Ie(e){if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}}function Le(e,t){let n=e.itemsById.get(C(t.toolCallId)??``);if(!n||n.turn.v2Items||n.entry.origin!==`v1`)return;let r=n.entry.entry;r.kind===`tool`&&(n.entry.lastSeq=t.seq,r.status=`completed`,r.output=Ie(t.result))}function Re(e,t,n,r){let i=C(t.message)??``;i!==``&&O(e,{kind:`note`,id:n,text:i,tone:r})}function J(e,t){let n=C(t.message)??``;t.type===`lifecycle`&&n!==``&&I(e,t,n)||Re(e,t,`v1:${t.seq}`,t.tone===`danger`?`danger`:`dim`)}function ze(e,t){let n=C(t.message)??``;n!==``&&F(e,t,{id:`v1:${t.seq}`,source:`error`,text:n,cause:M(n),stepId:C(t.stepId),fatal:!1})}function Be(e,t){let n=C(t.message)??``;n!==``&&F(e,t,{id:`v2:${t.seq}`,source:`session.error`,text:n,cause:M(n),stepId:C(t.stepId),fatal:t.fatal===!0})}function Ve(e,t){if(t.status!==`failed`)return;let n=C(t.stepId),r=C(t.error),i=r?` — ${r}`:``;F(e,t,{id:`v1:${t.seq}`,source:`step-end`,text:`step ${n??`?`} failed${i}`,cause:r?M(r):``,stepId:n,fatal:!0})}function He(e,t){let n=C(t.command)??`check`,r=typeof t.exitCode==`number`?t.exitCode:-1;O(e,{kind:`tool`,id:`v1:${t.seq}`,name:`check`,toolKind:`execute`,title:`Ran ${n}`,status:r===0?`completed`:`failed`,output:C(t.text)??``,exitCode:r})}function Ue(e,t){let n=de(t.provider),r=C(t.authFailureId)??``;n===void 0||r.length<1||r.length>128||O(e,{kind:`provider-auth-required`,id:`v1:${t.seq}`,provider:n,authFailureId:r})}function We(e,t){let n=C(t.url);if(n===void 0)return;let r={kind:`image`,id:`v1:${t.seq}`,url:n},i=C(t.name);i!==void 0&&(r.name=i),O(e,r)}function Ge(e,t){Array.isArray(t.entries)&&(D(e).planEntries=t.entries)}function Ke(e,t){R(e);let n=C(t.reason)??`end_turn`,r=C(t.message);n===`error`&&L(e,t,r),e.sessionEnded={reason:n,...r===void 0?{}:{message:r}}}var qe=new Set([`allow_once`,`allow_always`,`reject_once`,`reject_always`]);function Je(e){return S(e)&&typeof e.id==`string`&&e.id!==``&&typeof e.label==`string`&&e.label!==``&&qe.has(e.kind)}function Ye(e){if(!(!Array.isArray(e)||e.length===0||!e.every(Je)))return new Set(e.map(e=>e.id)).size===e.length?e:void 0}function Xe(e,t){let n=C(t.requestId),r=C(t.title),i=Ye(t.options);if(!n||!r||e.permissions.has(n)||!i)return;let a=C(t.itemId),o=C(t.details),s={kind:`permission`,id:`permission:${n}`,requestId:n,title:r,options:i.map(e=>({...e})),status:`pending`,...a===void 0?{}:{itemId:a},...o===void 0?{}:{details:o}};e.permissions.set(n,s),O(e,s)}function Ze(e,t){let n=e.permissions.get(C(t.requestId)??``);if(!n||n.status!==`pending`)return;let r=C(t.optionId);r!==void 0&&n.options.some(e=>e.id===r)?(n.status=`resolved`,n.optionId=r):n.status=`expired`;let i=C(t.reason);i!==void 0&&(n.reason=i)}function Qe(e,t){let n=d(t),r=n&&ne(n);if(!r)return;let i={kind:`ask`,...r,questions:r.questions,resolved:!1};O(e,i),e.pendingAsk=i}function Y(e,t){let n=e.pendingAsk;return n&&!n.resolved&&n.askSeq===t.askSeq?n:void 0}function $e(e,t){let n=Y(e,t);if(!n)return;n.routedToParent=!0;let r=C(t.parentRunId);r!==void 0&&(n.parentRunId=r)}function et(e,t){let n=Y(e,t);n&&(n.routedToParent=!1)}function tt(e,t){let n=Y(e,t);n&&X(e,n,`undeliverable`)}var nt=new Set([`finish`,`superseded`,`parent-stopped`,`worker-stopped`,`undeliverable`]);function rt(e,t){let n=Y(e,t);n&&nt.has(t.reason)&&X(e,n,t.reason)}function X(e,t,n){t.resolved=!0,t.closed=n,e.pendingAsk=void 0}function it(e,t){let n=Y(e,t);if(n){if(t.source===`cezar`){X(e,n,`undeliverable`);return}t.source===`parent`&&(n.resolved=!0,n.answeredBy=`parent`,e.pendingAsk=void 0)}}var Z=()=>{},at=new Map([[`handoff`,he],[`webhook.failed`,ge],[`webhook.dry-run`,ve],[`webhook.report`,_e],[`preview.server-registered`,ye],[`preview.server-state`,be],[`conversation-message`,xe],[`request-outcome`,Se],[`agent-input`,Ce],[`user-message`,we],[`turn.started`,Te],[`turn.completed`,De],[`item.started`,q],[`item.updated`,q],[`item.completed`,q],[`item.delta`,Ae],[`text`,je],[`tool-call`,Fe],[`tool-result`,Le],[`note`,J],[`lifecycle`,J],[`error`,ze],[`session.error`,Be],[`step-end`,Ve],[`check-output`,He],[`provider-auth-required`,Ue],[`image`,We],[`plan.updated`,Ge],[`session.started`,e=>R(e)],[`session.ended`,Ke],[`permission.requested`,Xe],[`permission.resolved`,Ze],[`ask.requested`,Qe],[`worker-question-routed`,$e],[`worker-question-fallback`,et],[`worker-question-undelivered`,tt],[`human-ask-closed`,rt],[`human-input-delivered`,it],[`step-start`,Z],[`token-usage`,Z],[`cost`,Z],[`turn-end`,Z],[`done`,Z],[`session`,Z]]);function ot(e,t){e.eventSeq=t.seq,at.get(t.type)?.(e,t)}function st(e){for(let t=e.turns.length-1;t>=0;--t){let n=e.turns[t].planEntries;if(n!==void 0)return n}}function ct(e){let t=[];for(let n of e.turns)for(let e of n.items)if(e.kind===`tool`){for(let n of e.locations??[])t.push(n.path);for(let n of e.diffs??[])t.push(n.path)}let n=new Set;for(let e=t.length-1;e>=0;--e)n.add(t[e]);return[...n]}function lt(e,t){let n=e?.turns.at(-1);if(!n)return!1;let r=M(t);return r!==``&&n.items.some(e=>e.kind===`note`&&e.tone===`danger`&&M(e.text)===r)}function ut(e,t,n){switch(e){case`waiting`:return{state:`waiting`};case`failed`:return{state:`closed`,tone:`danger`,label:t!==void 0&&t!==``&&!lt(n,t)?`Session failed — ${t}`:`Session failed`};case`review`:return{state:`closed`,tone:`dim`,label:`Session closed — waiting for your review`};case`done`:case`cancelled`:return{state:`closed`,tone:`dim`,label:`Session closed`};default:return null}}function Q(e,t){let n=e.replace(/\s*CEZ:DONE\s*$/,``).replace(/\s*CEZ:MONITORING\s*$/,``);if(t){let e=n.trimEnd(),t=e.lastIndexOf(`
1
+ import{t as e}from"./react-runtime-CCIEwYL0.js";import{t}from"./utils-DSMR_WLb.js";import{gr as n,hr as r,ti as i}from"./toaster-C-xqAWVX.js";import{h as a,p as o,v as s}from"./live-protocol-DMhTnCmf.js";import{t as c}from"./createLucideIcon-BHp8sXmF.js";import{t as l}from"./app-window-CSHwDX9N.js";import{t as u}from"./play-CmVAj_fu.js";import{i as d,n as ee,o as te,r as ne}from"./tool-display-B9NN44oU.js";import{t as re}from"./square-terminal-B6RYYieR.js";import{t as ie}from"./button-B7MKxYjT.js";import{t as ae}from"./status-dot-BRzVlF2X.js";import{a as oe,o as se}from"./format-BU7D3IfE.js";import{Xn as ce,f,p}from"./index-7Rg7tdSP.js";var m=c(`server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),h=e(),g={registered:e=>e.server.answeredAtRegistration?{label:`Open`,run:!1}:{label:`Run and open`,run:!0},adopted:()=>({label:`Open`,run:!1}),starting:()=>({label:`Open`,run:!1}),up:()=>({label:`Open`,run:!1}),stalled:()=>({label:`View`,run:!1}),exited:()=>({label:`Start again`,run:!0}),stopped:()=>({label:`Start again`,run:!0}),unavailable:()=>void 0};function _(e){let{text:t,...n}=p(e),r={...n,status:t},i=g[e.state](e);return i?{...r,action:i}:r}var v={"Run and open":u,Open:l,View:ce,"Start again":te};function y({entry:e,inPreview:n,onOpen:r}){let{server:i}=e,a=_(e),o=e.state===`unavailable`,s=r?a.action:void 0,c=f(i.command),l=oe(i.registeredAt);return(0,h.jsxs)(`div`,{"data-slot":`preview-server-card`,"data-state":e.state,className:t(`min-w-0 rounded-lg border border-border bg-card px-3.5 py-3 text-sm`,o&&`text-muted-foreground`),children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2 text-xs text-soft-foreground`,children:[(0,h.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 font-mono`,children:[(0,h.jsx)(m,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`truncate`,children:`cezar_preview_serve`})]}),o?(0,h.jsx)(`span`,{children:`worktree removed`}):l?(0,h.jsx)(`span`,{children:se(l)}):null]}),(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-2`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,h.jsx)(ae,{tone:a.tone,shape:a.ring?`ring`:`filled`,pulse:a.pulse===!0,"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`font-semibold text-foreground`,children:i.label}),(0,h.jsxs)(`span`,{className:`font-mono text-muted-foreground`,children:[`:`,i.port]}),(0,h.jsx)(`span`,{className:`text-muted-foreground`,children:a.status})]}),(0,h.jsx)(le,{entry:e,inPreview:n,action:s,onOpen:r})]}),(0,h.jsxs)(`div`,{className:`mt-2.5 min-w-0 rounded-md bg-muted px-3 py-2 font-mono text-xs`,children:[(0,h.jsx)(`p`,{className:`break-words whitespace-pre-wrap text-foreground`,children:i.command}),i.cwd?(0,h.jsxs)(`p`,{className:`mt-1 flex gap-3 text-soft-foreground`,children:[(0,h.jsx)(`span`,{children:`cwd`}),(0,h.jsx)(`span`,{className:`break-all`,children:i.cwd})]}):null]}),s?.run?(0,h.jsx)(b,{icon:(0,h.jsx)(re,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),children:`${s.label===`Start again`?`Starting again`:`Opening`} runs ${c} in this task's worktree, on the host.`}):null,o?(0,h.jsx)(b,{children:`The worktree this server ran in is gone. Register it again from a new task.`}):null]})}function le({entry:e,inPreview:t,action:n,onOpen:r}){let{server:i}=e,a=t&&n!==void 0&&!n.run,o=a?`In preview`:n?.label,s=a?l:n?v[n.label]:null;return n&&o&&s?(0,h.jsxs)(ie,{variant:a||n.label===`View`||n.label===`Open`&&e.state===`starting`?`outline`:`contrast`,size:`sm`,className:`max-md:h-11 max-md:px-3.5`,onClick:()=>r?.({port:i.port,run:n.run}),children:[(0,h.jsx)(s,{"aria-hidden":`true`}),o]}):null}function b({icon:e,children:t}){return(0,h.jsxs)(`p`,{className:`mt-2.5 flex items-start gap-2 text-xs text-muted-foreground`,children:[e,(0,h.jsx)(`span`,{children:t})]})}function x(e,t){return e.kind===`message`&&e.role===`user`&&e.skillInput?.source===t&&typeof e.skillInput.id==`string`&&e.skillInput.id!==``}function ue(){return{turns:[],itemsById:new Map,turnSeq:0,eventSeq:0,permissions:new Map,conversationEntries:new Map,outcomesByRequest:new Map,seenInputs:new Set,previewByPort:new Map,handedOff:!1}}function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(e){return typeof e==`string`?e:void 0}function w(e){let t=typeof e==`string`?new Date(e):void 0;return!t||Number.isNaN(t.getTime())?``:` · ${t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`})}`}function T(e){if(!(typeof e!=`string`||e===``))return Number.isFinite(new Date(e).getTime())?e:void 0}function de(e){return i.safeParse(e).data}function E(e,t){e.turnSeq+=1;let n={id:t===void 0?`turn-fallback-${e.turnSeq}`:`turn-seq-${t}`,entries:[],v2Items:!1};return e.turns.push(n),n}function D(e){return e.turns.at(-1)??E(e)}function O(e,t){let n={origin:`meta`,entry:t,firstSeq:e.eventSeq,lastSeq:e.eventSeq};return D(e).entries.push(n),n}var k=[/^run failed\s+[—-]\s+/,/^continue failed(?:\s+[—-]\s+|:\s+)/,/^step\s+"[^"]+"\s+failed:\s+/,/^step\s+\S+\s+failed\s+[—-]\s+/],A=/^(?:run failed\s+[—-]\s+|continue failed(?:\s+[—-]\s+|:\s+))/;function j(e){return e.trim().replace(/\s+/g,` `)}function M(e){let t=e.trim(),n=!0;for(;n;){n=!1;for(let e of k){let r=t.replace(e,``).trim();r!==t&&r!==``&&(t=r,n=!0)}}return j(t)}function N(e,t,n){if(t===e.primarySource&&n===e.primaryText||e.draft.entry.kind!==`note`)return;let r=e.draft.entry;r.details?.some(e=>e.source===t&&e.text===n)||(r.details=[...r.details??[],{source:t,text:n}])}function P(e,t,n){let r=e.failures;if(r)for(let e=r.length-1;e>=0;--e){let i=r[e];if(t!==``&&i.cause===t||t===``&&i.fatal&&(n===void 0||i.stepId===void 0||i.stepId===n))return i}}function F(e,t,n){let r=D(e),i=P(r,n.cause,n.stepId);if(i){i.draft.lastSeq=Math.max(i.draft.lastSeq,t.seq),n.fatal&&(i.fatal=!0),n.stepId!==void 0&&i.stepId===void 0&&(i.stepId=n.stepId),N(i,n.source,n.text);return}let a={draft:O(e,{kind:`note`,id:n.id,text:n.text,tone:`danger`}),cause:n.cause,primarySource:n.source,primaryText:n.text,...n.stepId===void 0?{}:{stepId:n.stepId},fatal:n.fatal};r.failures=[...r.failures??[],a]}function I(e,t,n){if(!A.test(n))return!1;let r=e.turns.at(-1);if(!r)return!1;let i=M(n);if(i===``)return!1;let a=P(r,i,C(t.stepId));return a?(a.draft.lastSeq=Math.max(a.draft.lastSeq,t.seq),a.fatal=!0,N(a,`lifecycle`,n),!0):!1}function L(e,t,n){let r=e.turns.at(-1);if(!r)return;let i=P(r,n?M(n):``,C(t.stepId));i&&(i.fatal=!0)}function R(e){for(let t of e.permissions.values())t.status===`pending`&&(t.status=`expired`)}function z(e,t){let n=C(e.stepId);return n===void 0?t:`${n}:${t}`}function B(e,t){t.v2Items=!0;for(let n of t.entries)n.origin===`v1`&&n.entry.kind===`tool`&&e.itemsById.delete(n.entry.id);t.entries=t.entries.filter(e=>!(e.origin===`v1`&&e.entry.kind===`tool`))}function V(e,t,n,r,i,a=!1){let o=n.kind===`message`&&i!==void 0?{...n,ts:i}:{...n};!t.v2Items&&o.kind!==`hook`&&B(e,t);let s=e.itemsById.get(r);if(s&&s.turn===t){s.entry.entry=o,s.entry.lastSeq=e.eventSeq,s.entry.streaming=a;return}let c={origin:`v2`,entry:o,firstSeq:e.eventSeq,lastSeq:e.eventSeq,streaming:a};t.entries.push(c),e.itemsById.set(r,{turn:t,entry:c})}var H={"not-delivered":0,queued:1,delivered:2,consumed:3},fe=[`instruction`,`resumed`,`requestId`,`relationship`,`state`,`createdAt`,`requestHash`,`deadline`];function U(e){let t={};for(let n of fe)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}function W(e,t){if(t.messageKind!==`request`)return;let n=e.outcomesByRequest.get(t.messageId);n&&(t.outcome={status:n.status,...n.replyId===void 0?{}:{replyId:n.replyId},observedAt:n.observedAt})}function pe(e,t){let n=e.conversationEntries.get(t);n&&W(e,n)}function me(e,t,n,r){(H[e.delivery]<H.delivered||H[n]>H[e.delivery])&&(e.delivery=n),t.text!==``&&(e.text=t.text),Object.assign(e,U(t)),r.deliveredAt!==void 0&&(e.deliveredAt=r.deliveredAt),r.consumedAt!==void 0&&(e.consumedAt=r.consumedAt),r.recordedAt!==void 0&&(n===`delivered`||e.delivery!==`delivered`)&&(e.recordedAt=r.recordedAt)}function G(e,t,n,r){let i=e.conversationEntries.get(t.id);if(i){me(i,t,n,r),W(e,i);return}let a={kind:`conversation`,id:`conversation-message:${t.id}`,messageId:t.id,text:t.text,senderRunId:t.senderRunId,recipientRunId:t.recipientRunId,messageKind:t.kind,delivery:n,...r,...U(t)};W(e,a),e.conversationEntries.set(t.id,a),O(e,a)}function he(e,t){let n=w(t.ts),r=C(t.message),i=t.notify===!1?`Stopped notifying the webhook${n}`:`${e.handedOff?`Note sent to webhook`:`Handed off to webhook`}${n}${r?` — ${r}`:``}`;e.handedOff=t.notify!==!1,O(e,{kind:`note`,id:`v1:${t.seq}`,text:i,tone:`dim`,icon:`handoff`})}function ge(e,t){let n=typeof t.attempts==`number`?t.attempts:void 0,r=C(t.webhookName),i=`${r?`Delivery to ${r} failed`:`Webhook delivery failed`}${C(t.event)?` (${C(t.event)})`:``}${n?` after ${n} attempt${n===1?``:`s`}`:``}: ${C(t.error)??`unknown error`}`;O(e,{kind:`note`,id:`v1:${t.seq}`,text:i,tone:`danger`})}function _e(e,t){let n=C(t.webhookName)??`webhook`,r=C(t.title),i=`v1:${t.seq}`;if(t.ok===!1){O(e,{kind:`note`,id:i,text:`Report to ${n} failed: ${C(t.error)??`unknown error`}`,tone:`danger`});return}let a=`${t.dryRun===!0?`Report to ${n} (dry run, nothing sent)`:`Sent report to ${n}`}${w(t.ts)}${r?` — ${r}`:``}`;O(e,t.dryRun===!0?{kind:`note`,id:i,text:a,tone:`dim`}:{kind:`note`,id:i,text:a,tone:`dim`,icon:`handoff`})}function ve(e,t){let n=t.payload??{},r=`Webhook (dry run, nothing sent): ${C(t.event)??`delivery`}${C(n.status)?` · ${C(n.status)}`:``}`;O(e,{kind:`note`,id:`v1:${t.seq}`,text:r,tone:`dim`})}function ye(e,t){let n=r.safeParse(t.server);if(!n.success)return;let i=e.previewByPort.get(n.data.port);i&&(i.turn.entries=i.turn.entries.filter(e=>e!==i.draft));let a=D(e),o={origin:`meta`,firstSeq:t.seq,lastSeq:t.seq,entry:{kind:`preview-server`,id:`preview-server:${n.data.port}`,server:n.data,state:`registered`,stateAt:t.ts}};a.entries.push(o),e.previewByPort.set(n.data.port,{turn:a,draft:o})}function be(e,t){let r=n.safeParse(t.state),i=typeof t.port==`number`?e.previewByPort.get(t.port):void 0;if(!r.success||!i||i.draft.entry.kind!==`preview-server`)return;let{server:a,id:o}=i.draft.entry;i.draft.lastSeq=t.seq,i.draft.entry={kind:`preview-server`,id:o,server:a,state:r.data,stateAt:t.ts,...typeof t.exitCode==`number`?{exitCode:t.exitCode}:{},...t.reason===`user`||t.reason===`idle`?{reason:t.reason}:{}}}function xe(e,t){let n=a.safeParse(t);if(!n.success)return;let{message:r,delivery:i,deliveredAt:o,consumedAt:s,ts:c}=n.data;G(e,r,i,{deliveredAt:o,consumedAt:s,recordedAt:c})}function Se(e,t){let n=s.safeParse(t);if(!n.success)return;let{outcome:r}=n.data,i=e.outcomesByRequest.get(r.requestId);i&&!(i.status===`timed-out`&&r.status===`replied-late`)||(e.outcomesByRequest.set(r.requestId,r),pe(e,r.requestId))}function Ce(e,t){let n=o.safeParse(t);if(!n.success)return;let{input:r}=n.data;if(!e.seenInputs.has(r.id)){if(e.seenInputs.add(r.id),r.conversation){G(e,{id:r.id,text:r.text,createdAt:r.createdAt,...r.conversation},`delivered`,{deliveredAt:r.deliveredAt,recordedAt:n.data.ts});return}O(e,{kind:`note`,id:`agent-input:${r.id}`,text:r.text,tone:`dim`,attribution:{source:r.source,parentRunId:r.parentRunId}})}}function we(e,t){let n=C(t.text)??``,r=e.pendingAsk;e.pendingAsk&&!e.pendingAsk.resolved&&(e.pendingAsk.resolved=!0,e.pendingAsk.answeredBy=`human`,n!==``&&(e.pendingAsk.answer=n),e.pendingAsk=void 0);let i=E(e,t.seq),a=T(t.ts);i.userMessage={text:n,ask:r,imageCount:typeof t.imageCount==`number`?t.imageCount:0,images:Array.isArray(t.images)?t.images.filter(e=>typeof e==`string`):[],...a===void 0?{}:{ts:a}},a!==void 0&&(i.startedAt=a)}function Te(e,t){let n=e.turns.at(-1),r=n&&n.turnId===void 0&&!n.v2Items?n:E(e,t.seq);r.turnId=C(t.turnId),r.startedAt??=T(t.ts)}function Ee(e,t){for(let n=e.turns.length-1;n>=0;--n)if(e.turns[n].turnId===t)return e.turns[n];return e.turns.at(-1)}function De(e,t){R(e);let n=Ee(e,C(t.turnId));if(!n)return;let r=T(t.ts);n.completed={stopReason:C(t.stopReason)??`end_turn`,...typeof t.costUsd==`number`?{costUsd:t.costUsd}:{},...r===void 0?{}:{ts:r}}}var K=new Set([`message`,`reasoning`,`tool`,`hook`]),Oe=e=>K.has(e.kind);function ke(e){if(!(!S(e)||!K.has(e.kind)))return typeof e.id==`string`&&e.id!==``?e:void 0}function q(e,t){let n=ke(t.item);if(!n)return;let r=z(t,n.id),i=e.itemsById.get(r),a=t.type===`item.completed`,o=!a&&(n.kind===`message`||n.kind===`reasoning`);V(e,i?.turn??D(e),n,r,a?T(t.ts):void 0,o)}function Ae(e,t){let n=e.itemsById.get(z(t,C(t.itemId)??``)),r=C(t.delta)??``;if(!n||r===``||!Oe(n.entry.entry))return;let i=n.entry.entry;n.entry.lastSeq=t.seq,t.field===`output`&&i.kind===`tool`?i.output=(i.output??``)+r:t.field!==`output`&&(i.kind===`message`||i.kind===`reasoning`)&&(i.text+=r)}function je(e,t){let n=D(e),r=C(t.text)??``;if(r===``)return;let i=T(t.ts);n.entries.push({origin:`v1`,firstSeq:t.seq,lastSeq:t.seq,entry:{kind:`message`,id:`v1:${t.seq}`,role:`assistant`,text:r,...i===void 0?{}:{ts:i}}})}var Me=new Set([`pending`,`in_progress`,`completed`,`cancelled`]);function Ne(e){if(!S(e)||!Array.isArray(e.todos))return;let t=[];for(let n of e.todos){if(!S(n)||typeof n.content!=`string`)return;t.push({content:n.content,status:Me.has(n.status)?n.status:`pending`,...typeof n.activeForm==`string`?{activeForm:n.activeForm}:{}})}return t}var Pe=new Set([`subAgentActivity`,`collabAgentToolCall`,`collabToolCall`]);function Fe(e,t){let n=D(e),r=C(t.tool)??`Tool`;if(n.v2Items||Pe.has(r))return;let i=ee(r,t.input),a=i.toolKind===`plan`?Ne(t.input):void 0;a!==void 0&&(n.planEntries=a);let o={kind:`tool`,id:C(t.id)??`v1:${t.seq}`,name:r,toolKind:i.toolKind,title:i.title,status:`running`,input:t.input},s={origin:`v1`,entry:o,firstSeq:t.seq,lastSeq:t.seq};n.entries.push(s),e.itemsById.set(o.id,{turn:n,entry:s})}function Ie(e){if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e)}catch{return String(e)}}function Le(e,t){let n=e.itemsById.get(C(t.toolCallId)??``);if(!n||n.turn.v2Items||n.entry.origin!==`v1`)return;let r=n.entry.entry;r.kind===`tool`&&(n.entry.lastSeq=t.seq,r.status=`completed`,r.output=Ie(t.result))}function Re(e,t,n,r){let i=C(t.message)??``;i!==``&&O(e,{kind:`note`,id:n,text:i,tone:r})}function J(e,t){let n=C(t.message)??``;t.type===`lifecycle`&&n!==``&&I(e,t,n)||Re(e,t,`v1:${t.seq}`,t.tone===`danger`?`danger`:`dim`)}function ze(e,t){let n=C(t.message)??``;n!==``&&F(e,t,{id:`v1:${t.seq}`,source:`error`,text:n,cause:M(n),stepId:C(t.stepId),fatal:!1})}function Be(e,t){let n=C(t.message)??``;n!==``&&F(e,t,{id:`v2:${t.seq}`,source:`session.error`,text:n,cause:M(n),stepId:C(t.stepId),fatal:t.fatal===!0})}function Ve(e,t){if(t.status!==`failed`)return;let n=C(t.stepId),r=C(t.error),i=r?` — ${r}`:``;F(e,t,{id:`v1:${t.seq}`,source:`step-end`,text:`step ${n??`?`} failed${i}`,cause:r?M(r):``,stepId:n,fatal:!0})}function He(e,t){let n=C(t.command)??`check`,r=typeof t.exitCode==`number`?t.exitCode:-1;O(e,{kind:`tool`,id:`v1:${t.seq}`,name:`check`,toolKind:`execute`,title:`Ran ${n}`,status:r===0?`completed`:`failed`,output:C(t.text)??``,exitCode:r})}function Ue(e,t){let n=de(t.provider),r=C(t.authFailureId)??``;n===void 0||r.length<1||r.length>128||O(e,{kind:`provider-auth-required`,id:`v1:${t.seq}`,provider:n,authFailureId:r})}function We(e,t){let n=C(t.url);if(n===void 0)return;let r={kind:`image`,id:`v1:${t.seq}`,url:n},i=C(t.name);i!==void 0&&(r.name=i),O(e,r)}function Ge(e,t){Array.isArray(t.entries)&&(D(e).planEntries=t.entries)}function Ke(e,t){R(e);let n=C(t.reason)??`end_turn`,r=C(t.message);n===`error`&&L(e,t,r),e.sessionEnded={reason:n,...r===void 0?{}:{message:r}}}var qe=new Set([`allow_once`,`allow_always`,`reject_once`,`reject_always`]);function Je(e){return S(e)&&typeof e.id==`string`&&e.id!==``&&typeof e.label==`string`&&e.label!==``&&qe.has(e.kind)}function Ye(e){if(!(!Array.isArray(e)||e.length===0||!e.every(Je)))return new Set(e.map(e=>e.id)).size===e.length?e:void 0}function Xe(e,t){let n=C(t.requestId),r=C(t.title),i=Ye(t.options);if(!n||!r||e.permissions.has(n)||!i)return;let a=C(t.itemId),o=C(t.details),s={kind:`permission`,id:`permission:${n}`,requestId:n,title:r,options:i.map(e=>({...e})),status:`pending`,...a===void 0?{}:{itemId:a},...o===void 0?{}:{details:o}};e.permissions.set(n,s),O(e,s)}function Ze(e,t){let n=e.permissions.get(C(t.requestId)??``);if(!n||n.status!==`pending`)return;let r=C(t.optionId);r!==void 0&&n.options.some(e=>e.id===r)?(n.status=`resolved`,n.optionId=r):n.status=`expired`;let i=C(t.reason);i!==void 0&&(n.reason=i)}function Qe(e,t){let n=d(t),r=n&&ne(n);if(!r)return;let i={kind:`ask`,...r,questions:r.questions,resolved:!1};O(e,i),e.pendingAsk=i}function Y(e,t){let n=e.pendingAsk;return n&&!n.resolved&&n.askSeq===t.askSeq?n:void 0}function $e(e,t){let n=Y(e,t);if(!n)return;n.routedToParent=!0;let r=C(t.parentRunId);r!==void 0&&(n.parentRunId=r)}function et(e,t){let n=Y(e,t);n&&(n.routedToParent=!1)}function tt(e,t){let n=Y(e,t);n&&X(e,n,`undeliverable`)}var nt=new Set([`finish`,`superseded`,`parent-stopped`,`worker-stopped`,`undeliverable`]);function rt(e,t){let n=Y(e,t);n&&nt.has(t.reason)&&X(e,n,t.reason)}function X(e,t,n){t.resolved=!0,t.closed=n,e.pendingAsk=void 0}function it(e,t){let n=Y(e,t);if(n){if(t.source===`cezar`){X(e,n,`undeliverable`);return}t.source===`parent`&&(n.resolved=!0,n.answeredBy=`parent`,e.pendingAsk=void 0)}}var Z=()=>{},at=new Map([[`handoff`,he],[`webhook.failed`,ge],[`webhook.dry-run`,ve],[`webhook.report`,_e],[`preview.server-registered`,ye],[`preview.server-state`,be],[`conversation-message`,xe],[`request-outcome`,Se],[`agent-input`,Ce],[`user-message`,we],[`turn.started`,Te],[`turn.completed`,De],[`item.started`,q],[`item.updated`,q],[`item.completed`,q],[`item.delta`,Ae],[`text`,je],[`tool-call`,Fe],[`tool-result`,Le],[`note`,J],[`lifecycle`,J],[`error`,ze],[`session.error`,Be],[`step-end`,Ve],[`check-output`,He],[`provider-auth-required`,Ue],[`image`,We],[`plan.updated`,Ge],[`session.started`,e=>R(e)],[`session.ended`,Ke],[`permission.requested`,Xe],[`permission.resolved`,Ze],[`ask.requested`,Qe],[`worker-question-routed`,$e],[`worker-question-fallback`,et],[`worker-question-undelivered`,tt],[`human-ask-closed`,rt],[`human-input-delivered`,it],[`step-start`,Z],[`token-usage`,Z],[`cost`,Z],[`turn-end`,Z],[`done`,Z],[`session`,Z]]);function ot(e,t){e.eventSeq=t.seq,at.get(t.type)?.(e,t)}function st(e){for(let t=e.turns.length-1;t>=0;--t){let n=e.turns[t].planEntries;if(n!==void 0)return n}}function ct(e){let t=[];for(let n of e.turns)for(let e of n.items)if(e.kind===`tool`){for(let n of e.locations??[])t.push(n.path);for(let n of e.diffs??[])t.push(n.path)}let n=new Set;for(let e=t.length-1;e>=0;--e)n.add(t[e]);return[...n]}function lt(e,t){let n=e?.turns.at(-1);if(!n)return!1;let r=M(t);return r!==``&&n.items.some(e=>e.kind===`note`&&e.tone===`danger`&&M(e.text)===r)}function ut(e,t,n){switch(e){case`waiting`:return{state:`waiting`};case`failed`:return{state:`closed`,tone:`danger`,label:t!==void 0&&t!==``&&!lt(n,t)?`Session failed — ${t}`:`Session failed`};case`review`:return{state:`closed`,tone:`dim`,label:`Session closed — waiting for your review`};case`done`:case`cancelled`:return{state:`closed`,tone:`dim`,label:`Session closed`};default:return null}}function Q(e,t){let n=e.replace(/\s*CEZ:DONE\s*$/,``).replace(/\s*CEZ:MONITORING\s*$/,``);if(t){let e=n.trimEnd(),t=e.lastIndexOf(`
2
2
  `)+1;/^CEZ:ASK[ \t]+.+$/.test(e.slice(t))&&(n=e.slice(0,t).trimEnd())}return n.includes(`CEZ:`)?n.split(`
3
3
  `).filter(e=>!/^CEZ:(?:PR=\d+|ISSUE=\d+|TITLE=.+)\s*$/.test(e)).join(`
4
4
  `):n}var dt=/\s*(?:^|\n)C(?:E(?:Z(?::.*)?)?)?$/,ft=/[ \t]+CEZ(?::[A-Z]*)?$/;function $(e){return e.replace(dt,``).replace(ft,``)}function pt(e,t,n){return t!==``&&e.some(e=>e.norm===``?n>e.firstSeq:e.norm.startsWith(t)||t.startsWith(e.norm))}function mt(e,t){let n=e=>Q(e,!0).replace(/\s+/g,``),r=new Set,i=[],a=[];for(let{origin:o,entry:s,firstSeq:c,streaming:l}of e.entries)if(o===`v2`&&s.kind===`message`){let e=n(s.text);r.add(e),i.push(e),t&&l===!0&&a.push({norm:e,firstSeq:c})}if(i.length===0)return;r.add(i.join(``));let o=[],s={entries:[],texts:[]},c=()=>{let e=n(s.texts.join(``)),t=s.entries[0],i=s.entries.length>=2&&r.has(e);if(t&&(i||pt(a,e,t.firstSeq))){s={entries:[],texts:[]};return}o.push(...s.entries),s={entries:[],texts:[]}};for(let t of e.entries)t.origin===`v1`&&t.entry.kind===`message`?(s.entries.push(t),s.texts.push(t.entry.text)):(c(),o.push(t));c(),e.entries=o}function ht(e,t){let n=new Set;for(let{origin:t,entry:r}of e.entries)t===`v2`&&r.kind===`message`&&n.add(Q(r.text,!0).trim());n.size!==0&&(e.entries=e.entries.filter(e=>!(e.origin===`v1`&&e.entry.kind===`message`&&n.has(Q(e.entry.text,!0).trim()))),mt(e,t))}function gt(e){let t=e.failures?.filter(e=>e.fatal&&e.cause!==``);if(!t||t.length===0)return;let n=new Map;for(let e of t)n.set(e.cause,e);e.entries=e.entries.filter(e=>{if(e.entry.kind!==`message`||e.entry.role!==`assistant`)return!0;let t=Q(e.entry.text,!0).trim();if(t===``)return!0;let r=n.get(j(t));return r?(r.draft.firstSeq=Math.min(r.draft.firstSeq,e.firstSeq),r.draft.lastSeq=Math.max(r.draft.lastSeq,e.lastSeq),N(r,`assistant`,t),!1):!0})}function _t(e){e.userMessage&&(e.entries=e.entries.filter(({entry:e})=>!x(e,`human`)))}function vt(e){for(let t of e.conversationEntries.values())t.messageKind!==`request`||t.outcome!==void 0||t.delivery!==`not-delivered`&&(t.state!==void 0&&t.state!==`accepted`||(t.outcome={status:`pending`}))}function yt(e,t,n){let{entry:r}=e;if(r.kind!==`message`||r.role!==`assistant`)return r;let i=Q(r.text,t);return n&&e.streaming===!0?{...r,text:$(i),streaming:!0}:{...r,text:i}}function bt(e,t){let n=t||e.entries.some(({entry:e})=>e.kind===`ask`);return{id:e.id,...e.turnId===void 0?{}:{turnId:e.turnId},...e.userMessage===void 0?{}:{userMessage:e.userMessage},...e.startedAt===void 0?{}:{startedAt:e.startedAt},...e.planEntries===void 0?{}:{planEntries:e.planEntries},...e.completed===void 0?{}:{completed:e.completed},items:e.entries.map(e=>yt(e,n,t)),itemSeqs:xt(e.entries)}}function xt(e){let t=new Map;for(let{entry:n,firstSeq:r,lastSeq:i}of e)t.has(n.id)||t.set(n.id,{first:r,last:i});return t}function St(e,t={}){let n=ue();for(let t of e)ot(n,t);let r=n.turns.length-1;for(let[e,i]of n.turns.entries())i.v2Items&&ht(i,t.activeTurn===!0&&e===r),gt(i),_t(i);return vt(n),{turns:n.turns.map((e,n)=>bt(e,t.activeTurn===!0&&n===r)),...n.sessionEnded===void 0?{}:{sessionEnded:n.sessionEnded}}}export{x as a,ut as i,St as n,y as o,ct as r,m as s,st as t};