blade-code 0.10.176 → 0.10.178

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 (73) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-3zz9m825.js → chunk-2p9j16ed.js} +1 -1
  3. package/dist/{chunk-hcgw662n.js → chunk-4jfs3qsd.js} +1 -1
  4. package/dist/{chunk-zxmy26da.js → chunk-4vn0dr8c.js} +1 -1
  5. package/dist/{chunk-q599m0dn.js → chunk-5f3jvt7q.js} +1 -1
  6. package/dist/{chunk-1k1dkbpa.js → chunk-5hs5pv2z.js} +1 -1
  7. package/dist/{chunk-k6b013wk.js → chunk-600xa10z.js} +1 -1
  8. package/dist/{chunk-yt31g9xb.js → chunk-6ayrcbda.js} +1 -1
  9. package/dist/{chunk-g58z5vrv.js → chunk-8gdw286x.js} +1 -1
  10. package/dist/{chunk-z5s67ate.js → chunk-8wnhsgvw.js} +1 -1
  11. package/dist/{chunk-k4agcfcy.js → chunk-96jpzf75.js} +1 -1
  12. package/dist/{chunk-pkn0mjed.js → chunk-awxfg8y0.js} +1 -1
  13. package/dist/{chunk-ynfv949b.js → chunk-aznbr6ay.js} +1 -1
  14. package/dist/{chunk-saky5ntj.js → chunk-b8rkgzjs.js} +1 -1
  15. package/dist/{chunk-3gtj63ss.js → chunk-c8mhvnyf.js} +1 -1
  16. package/dist/chunk-dma247n9.js +1 -0
  17. package/dist/{chunk-gznfyegp.js → chunk-dqb5fm8x.js} +1 -1
  18. package/dist/{chunk-6ke6p47w.js → chunk-fb773kdb.js} +1 -1
  19. package/dist/{chunk-e5qpgfa8.js → chunk-fk3qhnsn.js} +1 -1
  20. package/dist/{chunk-vpb63htc.js → chunk-hv1z8nxq.js} +1 -1
  21. package/dist/{chunk-arc5mz9q.js → chunk-knyn38rp.js} +1 -1
  22. package/dist/{chunk-9wq0504z.js → chunk-mdepy489.js} +1 -1
  23. package/dist/{chunk-s7q2tqfc.js → chunk-mjw0evjt.js} +1 -1
  24. package/dist/{chunk-3w1aqkz9.js → chunk-mn8e305h.js} +2 -2
  25. package/dist/{chunk-jq7pcxpx.js → chunk-nan8mv2n.js} +1 -1
  26. package/dist/{chunk-5y536ycm.js → chunk-nr4axed3.js} +1 -1
  27. package/dist/{chunk-h26667eb.js → chunk-nxmcc4rw.js} +1 -1
  28. package/dist/{chunk-5rrvwesz.js → chunk-pq1cyhc1.js} +1 -1
  29. package/dist/{chunk-d0rwtkvt.js → chunk-qtnykwv9.js} +1 -1
  30. package/dist/{chunk-adjtgsqe.js → chunk-r0ragech.js} +4 -4
  31. package/dist/{chunk-txz3xnz5.js → chunk-sdn7af9d.js} +1 -1
  32. package/dist/{chunk-578gfr58.js → chunk-vpwar5x8.js} +1 -1
  33. package/dist/{chunk-gwfz0qrr.js → chunk-vw4f9sx9.js} +1 -1
  34. package/dist/chunk-w41f5j91.js +1 -0
  35. package/dist/{chunk-1g9vwbv4.js → chunk-x1vjav7g.js} +1 -1
  36. package/dist/{chunk-0yebb919.js → chunk-y94nrgaf.js} +1 -1
  37. package/dist/{chunk-ha6btpqh.js → chunk-yc8ejwev.js} +1 -1
  38. package/dist/{chunk-bf9ek9cw.js → chunk-z8drxtsd.js} +1 -1
  39. package/dist/{chunk-jv8hwxj9.js → chunk-zvf33r3d.js} +1 -1
  40. package/dist/web/assets/{ChatView-DZFf4jjy.js → ChatView-Dg2v0KMf.js} +7 -7
  41. package/dist/web/assets/{CodeBlockHighlighter-DY4qBIi-.js → CodeBlockHighlighter-DutdTJjZ.js} +1 -1
  42. package/dist/web/assets/{FilePreview-BYTOfi8P.js → FilePreview-C-3jKPCu.js} +1 -1
  43. package/dist/web/assets/{KanbanBoard-Hi-ZEgiG.js → KanbanBoard-M_Rkwz9x.js} +1 -1
  44. package/dist/web/assets/{MarkdownRenderer-DhB-5HAw.js → MarkdownRenderer-DnFpJUbW.js} +3 -3
  45. package/dist/web/assets/{ScrollArea-0lfUxj2J.js → ScrollArea-DyAy4OGv.js} +1 -1
  46. package/dist/web/assets/{SessionHistorySurface-Bd8YrQOv.js → SessionHistorySurface-uXDhmU5C.js} +1 -1
  47. package/dist/web/assets/{SettingsModal-DdY8ccML.js → SettingsModal-DnbGsAVl.js} +1 -1
  48. package/dist/web/assets/{Sidebar-D2ljT_Ei.js → Sidebar-Dwv0KgIq.js} +1 -1
  49. package/dist/web/assets/{TaskSwitcher-CpCBHpWo.js → TaskSwitcher-Cb-yXog6.js} +1 -1
  50. package/dist/web/assets/{TerminalPanel-BHqVUQMc.js → TerminalPanel-BdXo1NN-.js} +1 -1
  51. package/dist/web/assets/{archive-CUjyyeiU.js → archive-CUbs5vgy.js} +1 -1
  52. package/dist/web/assets/{arrow-left-CBlHLoKb.js → arrow-left-DlqODZvK.js} +1 -1
  53. package/dist/web/assets/{calendar-clock-DUvlDjDF.js → calendar-clock-Mthj1nAa.js} +1 -1
  54. package/dist/web/assets/{chevron-right-Beyzy8qR.js → chevron-right-CpJ4RBHM.js} +1 -1
  55. package/dist/web/assets/{clock-3-C10-R9rx.js → clock-3-C5RVIVNu.js} +1 -1
  56. package/dist/web/assets/{copy-J8ZBLXui.js → copy-CCSMs5cP.js} +1 -1
  57. package/dist/web/assets/{download-DKZqTyde.js → download-1jRVkf-_.js} +1 -1
  58. package/dist/web/assets/{external-link-SepVL_2V.js → external-link-B91XupCq.js} +1 -1
  59. package/dist/web/assets/{folder-OyeWsTZg.js → folder-D_kWhdNI.js} +1 -1
  60. package/dist/web/assets/{index-ES2XG3sq.js → index-MWUi6KyG.js} +3 -3
  61. package/dist/web/assets/{message-square-plus-BxA6O-RL.js → message-square-plus-C4H2_lhl.js} +1 -1
  62. package/dist/web/assets/{pause-D_YsT8hg.js → pause-CC1xUxBL.js} +1 -1
  63. package/dist/web/assets/{pencil-CMHEoIW4.js → pencil-BbLrttp-.js} +1 -1
  64. package/dist/web/assets/{play-jj1ruX6k.js → play-DH-_FuZ9.js} +1 -1
  65. package/dist/web/assets/{plus-BM3HiihZ.js → plus-C6tyK4Qh.js} +1 -1
  66. package/dist/web/assets/{settings-njnShBiW.js → settings-DkOer6Q4.js} +1 -1
  67. package/dist/web/assets/{team-DREheoaL.js → team-BPZkbhCg.js} +1 -1
  68. package/dist/web/assets/{teamService-2PvKB0do.js → teamService-BTEsMr_G.js} +1 -1
  69. package/dist/web/assets/{terminal-CkUNT8KS.js → terminal-DScJ3QX0.js} +1 -1
  70. package/dist/web/index.html +1 -1
  71. package/package.json +1 -1
  72. package/dist/chunk-49gfpqkn.js +0 -1
  73. package/dist/chunk-rkebq2gn.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-DhB-5HAw.js","assets/index-ES2XG3sq.js","assets/vendor-react-DofNRwfy.js","assets/vendor-radix-D6QrtXqd.js","assets/session-events-aq2qdB3u.js","assets/index-CaCifsSK.css","assets/copy-J8ZBLXui.js"])))=>i.map(i=>d[i]);
2
- import{r as h,j as e,b as jt}from"./vendor-react-DofNRwfy.js";import{c as Z,u as _,a as v,s as tt,b as wt,d as ue,H as Ve,P as Nt,G as st,L as U,S as $e,T as ie,C as je,D as at,e as rt,f as St,g as nt,h as it,i as ot,j as L,k as Ct,l as re,B as Tt,m as Et,M as ct,n as Re,o as he,R as ve,F as Mt,_ as lt,p as At,q as Rt,r as Dt,t as dt,v as Ft,w as ut,x as It,X as mt,y as Lt,A as Pe,z as Bt,E as $t,W as Pt,I as _t,J as Ot}from"./index-ES2XG3sq.js";import{a0 as _e,N as oe,$ as q,a5 as ge,A as ht,a6 as Ut,a7 as Kt,V as Vt,a8 as Ht,Z as zt,_ as qt}from"./session-events-aq2qdB3u.js";import{A as Qt,E as Gt}from"./external-link-SepVL_2V.js";import{S as Wt}from"./ScrollArea-0lfUxj2J.js";import{C as xt}from"./copy-J8ZBLXui.js";import{C as ce}from"./chevron-right-Beyzy8qR.js";import{M as Jt,A as Oe,a as Yt,C as Xt}from"./message-square-plus-BxA6O-RL.js";import{f as Zt,g as es,h as ts,i as pt}from"./vendor-radix-D6QrtXqd.js";import{P as ss}from"./pause-D_YsT8hg.js";import{P as as}from"./play-jj1ruX6k.js";import{P as ft}from"./pencil-CMHEoIW4.js";import{C as rs}from"./clock-3-C10-R9rx.js";import{P as ns}from"./plus-BM3HiihZ.js";import{t as H,A as He}from"./team-DREheoaL.js";import{teamService as ze}from"./teamService-2PvKB0do.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-DnFpJUbW.js","assets/index-MWUi6KyG.js","assets/vendor-react-DofNRwfy.js","assets/vendor-radix-D6QrtXqd.js","assets/session-events-aq2qdB3u.js","assets/index-CaCifsSK.css","assets/copy-CCSMs5cP.js"])))=>i.map(i=>d[i]);
2
+ import{r as h,j as e,b as jt}from"./vendor-react-DofNRwfy.js";import{c as Z,u as _,a as v,s as tt,b as wt,d as ue,H as Ve,P as Nt,G as st,L as U,S as $e,T as ie,C as je,D as at,e as rt,f as St,g as nt,h as it,i as ot,j as L,k as Ct,l as re,B as Et,m as Tt,M as ct,n as Re,o as he,R as ve,F as Mt,_ as lt,p as At,q as Rt,r as Dt,t as dt,v as Ft,w as ut,x as It,X as mt,y as Lt,A as Pe,z as Bt,E as $t,W as Pt,I as _t,J as Ot}from"./index-MWUi6KyG.js";import{a0 as _e,N as oe,$ as q,a5 as ge,A as ht,a6 as Ut,a7 as Kt,V as Vt,a8 as Ht,Z as zt,_ as qt}from"./session-events-aq2qdB3u.js";import{A as Qt,E as Gt}from"./external-link-B91XupCq.js";import{S as Wt}from"./ScrollArea-DyAy4OGv.js";import{C as xt}from"./copy-CCSMs5cP.js";import{C as ce}from"./chevron-right-CpJ4RBHM.js";import{M as Jt,A as Oe,a as Yt,C as Xt}from"./message-square-plus-C4H2_lhl.js";import{f as Zt,g as es,h as ts,i as pt}from"./vendor-radix-D6QrtXqd.js";import{P as ss}from"./pause-CC1xUxBL.js";import{P as as}from"./play-DH-_FuZ9.js";import{P as ft}from"./pencil-BbLrttp-.js";import{C as rs}from"./clock-3-C5RVIVNu.js";import{P as ns}from"./plus-C6tyK4Qh.js";import{t as H,A as He}from"./team-BPZkbhCg.js";import{teamService as ze}from"./teamService-BTEsMr_G.js";/**
3
3
  * @license lucide-react v0.300.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -49,9 +49,9 @@ import{r as h,j as e,b as jt}from"./vendor-react-DofNRwfy.js";import{c as Z,u as
49
49
  *
50
50
  * This source code is licensed under the ISC license.
51
51
  * See the LICENSE file in the root directory of this source tree.
52
- */const xs=Z("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function qe(t){return t.split("/").filter(Boolean).at(-1)||t}function ps(){const t=_(),s=v(j=>j.sessions),a=v(j=>j.currentSessionRef),r=v(j=>j.historySurfaceSelection),i=v(j=>j.taskDeliveryActions),n=v(j=>j.deliverTask),c=_e(j=>j.openFilePreview),[m,x]=h.useState(!1),l=s.find(j=>tt({sessionId:j.sessionId,projectPath:j.projectPath},a));if(oe(r)||!(l!=null&&l.taskIsolation))return null;const b=l.taskDiffStat,k=l.taskIsolation==="worktree",u=wt(l),g=i[ue(u)],p=l.taskDelivery,w=(p==null?void 0:p.status)==="conflicted",d=!!(b&&(b.changedFiles>0||b.commits>0)),N=!["queued","running"].includes(l.taskStatus),f=(p==null?void 0:p.status)==="applied"||(p==null?void 0:p.status)==="discarded",S=k&&d&&N&&!f,o=b?b.additions+b.deletions:0,E=o>0&&b?b.additions/o*100:0,I=j=>{q(v.getState())||n(u,j).catch(()=>{})},R=()=>{q(v.getState())||c({tab:"diff"})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-10 flex-wrap items-center gap-x-3 gap-y-1.5 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/60 px-3 py-1.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:px-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx(Ve,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:qe(l.taskSourceProjectPath||l.projectPath)})]}),e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[k?e.jsx(Nt,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(Ve,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:k?"text-[hsl(var(--deck-accent))]":void 0,children:t(k?"artifact.env.isolated":"artifact.env.local")})]}),l.taskWorktreeBranch&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 truncate",title:l.taskWorktreeBranch,children:[e.jsx(st,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:l.taskWorktreeBranch})]})]})]}),b&&e.jsxs("div",{className:"ml-auto flex max-w-full items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(os,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:b.changedFiles})]}),o>0&&e.jsxs("span",{className:"relative hidden h-1.5 w-14 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:inline-flex","aria-hidden":"true",children:[e.jsx("span",{className:"h-full bg-[hsl(var(--deck-accent))]",style:{width:`${E}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-E}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",b.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",b.deletions]}),b.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:b.commits})}),d&&(p==null?void 0:p.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:R,className:"inline-flex items-center gap-1 rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-2 py-1 text-[hsl(var(--deck-ink))] transition hover:border-[hsl(var(--deck-accent)/0.55)] hover:text-[hsl(var(--deck-accent))]",children:t("artifact.review")}),S&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!g,onClick:()=>I("apply"),className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2 py-1 font-semibold text-white transition hover:brightness-95 disabled:cursor-wait disabled:opacity-65",children:[g==="apply"?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx($e,{className:"h-3 w-3"}),t(g==="apply"?"artifact.applying":w?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!g,onClick:()=>x(!0),className:"inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[hsl(var(--deck-ink-faint))] transition hover:bg-red-500/10 hover:text-red-600 disabled:cursor-wait disabled:opacity-50 dark:hover:text-red-400","aria-label":t("artifact.discard"),title:t("artifact.discard"),children:g==="discard"?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx(ie,{className:"h-3 w-3"})})]}),(p==null?void 0:p.status)==="applied"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/10 px-2 py-1 font-semibold text-emerald-700 dark:text-emerald-300",children:[e.jsx(je,{className:"h-3 w-3"}),t("artifact.applied")]}),(p==null?void 0:p.status)==="discarded"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-surface-2))] px-2 py-1 text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(ie,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(p==null?void 0:p.status)==="conflicted"&&e.jsxs("div",{className:"flex w-full items-start gap-1.5 border-t border-amber-500/20 pt-1.5 text-amber-700 dark:text-amber-300",role:"alert",children:[e.jsx(Qt,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsx("span",{className:"block",children:p.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(at,{open:m,onOpenChange:x,children:e.jsxs(rt,{className:"w-[calc(100%_-_2rem)] max-w-md border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] text-[hsl(var(--deck-ink))]",children:[e.jsxs(St,{children:[e.jsx(nt,{children:t("artifact.discardDialog.title")}),e.jsx(it,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:qe(l.taskSourceProjectPath||l.projectPath),count:(b==null?void 0:b.changedFiles)??0})})]}),e.jsx("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-xs leading-relaxed text-red-700 dark:text-red-300",children:t("artifact.discardDialog.warning")}),e.jsxs(ot,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>x(!1),className:"rounded-md border border-[hsl(var(--deck-border))] px-3 py-2 text-sm hover:bg-[hsl(var(--deck-surface-2))]",children:t("artifact.discardDialog.cancel")}),e.jsxs("button",{type:"button",onClick:()=>{x(!1),I("discard")},className:"inline-flex items-center justify-center gap-1.5 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white hover:bg-red-700",children:[e.jsx(ie,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}function fs(t){var s,a;return!!((s=t.metadata)!=null&&s.codeReview||(a=t.metadata)!=null&&a.structuredOutput)}function Fe(t){const s=t.agentContent;return!!(t.role==="assistant"&&s&&!fs(t)&&s.tasks.length===0&&ht(s).length===0&&!s.confirmation&&!s.question&&!s.elicitation)}function bs(t,s){return s.map((a,r)=>({...a,id:`${t}:${r}:${a.id}`}))}function vs(t){return!Fe(t)||!t.agentContent?t:{...t,displaySourceMessageIds:[t.id],agentContent:{...t.agentContent,timeline:bs(t.id,ge(t.agentContent))}}}function gs(t,s){const a=t.map(i=>({...i})),r=new Map(a.map((i,n)=>[i.toolCallId,n]));for(const i of s){const n=r.get(i.toolCallId);n===void 0?(r.set(i.toolCallId,a.length),a.push({...i})):a[n]={...a[n],...i}}return a}function Se(t,s){return[t,s].filter(Boolean).join(`
52
+ */const xs=Z("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function qe(t){return t.split("/").filter(Boolean).at(-1)||t}function ps(){const t=_(),s=v(j=>j.sessions),a=v(j=>j.currentSessionRef),r=v(j=>j.historySurfaceSelection),i=v(j=>j.taskDeliveryActions),n=v(j=>j.deliverTask),c=_e(j=>j.openFilePreview),[m,x]=h.useState(!1),l=s.find(j=>tt({sessionId:j.sessionId,projectPath:j.projectPath},a));if(oe(r)||!(l!=null&&l.taskIsolation))return null;const b=l.taskDiffStat,k=l.taskIsolation==="worktree",u=wt(l),g=i[ue(u)],p=l.taskDelivery,w=(p==null?void 0:p.status)==="conflicted",d=!!(b&&(b.changedFiles>0||b.commits>0)),N=!["queued","running"].includes(l.taskStatus),f=(p==null?void 0:p.status)==="applied"||(p==null?void 0:p.status)==="discarded",S=k&&d&&N&&!f,o=b?b.additions+b.deletions:0,T=o>0&&b?b.additions/o*100:0,I=j=>{q(v.getState())||n(u,j).catch(()=>{})},R=()=>{q(v.getState())||c({tab:"diff"})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-10 flex-wrap items-center gap-x-3 gap-y-1.5 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/60 px-3 py-1.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:px-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx(Ve,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:qe(l.taskSourceProjectPath||l.projectPath)})]}),e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[k?e.jsx(Nt,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(Ve,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:k?"text-[hsl(var(--deck-accent))]":void 0,children:t(k?"artifact.env.isolated":"artifact.env.local")})]}),l.taskWorktreeBranch&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 truncate",title:l.taskWorktreeBranch,children:[e.jsx(st,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:l.taskWorktreeBranch})]})]})]}),b&&e.jsxs("div",{className:"ml-auto flex max-w-full items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(os,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:b.changedFiles})]}),o>0&&e.jsxs("span",{className:"relative hidden h-1.5 w-14 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:inline-flex","aria-hidden":"true",children:[e.jsx("span",{className:"h-full bg-[hsl(var(--deck-accent))]",style:{width:`${T}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-T}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",b.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",b.deletions]}),b.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:b.commits})}),d&&(p==null?void 0:p.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:R,className:"inline-flex items-center gap-1 rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-2 py-1 text-[hsl(var(--deck-ink))] transition hover:border-[hsl(var(--deck-accent)/0.55)] hover:text-[hsl(var(--deck-accent))]",children:t("artifact.review")}),S&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!g,onClick:()=>I("apply"),className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2 py-1 font-semibold text-white transition hover:brightness-95 disabled:cursor-wait disabled:opacity-65",children:[g==="apply"?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx($e,{className:"h-3 w-3"}),t(g==="apply"?"artifact.applying":w?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!g,onClick:()=>x(!0),className:"inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[hsl(var(--deck-ink-faint))] transition hover:bg-red-500/10 hover:text-red-600 disabled:cursor-wait disabled:opacity-50 dark:hover:text-red-400","aria-label":t("artifact.discard"),title:t("artifact.discard"),children:g==="discard"?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx(ie,{className:"h-3 w-3"})})]}),(p==null?void 0:p.status)==="applied"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/10 px-2 py-1 font-semibold text-emerald-700 dark:text-emerald-300",children:[e.jsx(je,{className:"h-3 w-3"}),t("artifact.applied")]}),(p==null?void 0:p.status)==="discarded"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-surface-2))] px-2 py-1 text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(ie,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(p==null?void 0:p.status)==="conflicted"&&e.jsxs("div",{className:"flex w-full items-start gap-1.5 border-t border-amber-500/20 pt-1.5 text-amber-700 dark:text-amber-300",role:"alert",children:[e.jsx(Qt,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsx("span",{className:"block",children:p.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(at,{open:m,onOpenChange:x,children:e.jsxs(rt,{className:"w-[calc(100%_-_2rem)] max-w-md border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] text-[hsl(var(--deck-ink))]",children:[e.jsxs(St,{children:[e.jsx(nt,{children:t("artifact.discardDialog.title")}),e.jsx(it,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:qe(l.taskSourceProjectPath||l.projectPath),count:(b==null?void 0:b.changedFiles)??0})})]}),e.jsx("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-xs leading-relaxed text-red-700 dark:text-red-300",children:t("artifact.discardDialog.warning")}),e.jsxs(ot,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>x(!1),className:"rounded-md border border-[hsl(var(--deck-border))] px-3 py-2 text-sm hover:bg-[hsl(var(--deck-surface-2))]",children:t("artifact.discardDialog.cancel")}),e.jsxs("button",{type:"button",onClick:()=>{x(!1),I("discard")},className:"inline-flex items-center justify-center gap-1.5 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white hover:bg-red-700",children:[e.jsx(ie,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}function fs(t){var s,a;return!!((s=t.metadata)!=null&&s.codeReview||(a=t.metadata)!=null&&a.structuredOutput)}function Fe(t){const s=t.agentContent;return!!(t.role==="assistant"&&s&&!fs(t)&&s.tasks.length===0&&ht(s).length===0&&!s.confirmation&&!s.question&&!s.elicitation)}function bs(t,s){return s.map((a,r)=>({...a,id:`${t}:${r}:${a.id}`}))}function vs(t){return!Fe(t)||!t.agentContent?t:{...t,displaySourceMessageIds:[t.id],agentContent:{...t.agentContent,timeline:bs(t.id,ge(t.agentContent))}}}function gs(t,s){const a=t.map(i=>({...i})),r=new Map(a.map((i,n)=>[i.toolCallId,n]));for(const i of s){const n=r.get(i.toolCallId);n===void 0?(r.set(i.toolCallId,a.length),a.push({...i})):a[n]={...a[n],...i}}return a}function Se(t,s){return[t,s].filter(Boolean).join(`
53
53
 
54
- `)}function ks(t,s){const a=t.agentContent,r=s.agentContent;return{...t,...t.metadata||s.metadata?{metadata:{...t.metadata,...s.metadata}}:{},displaySourceMessageIds:[...t.displaySourceMessageIds??[t.id],...s.displaySourceMessageIds??[s.id]],agentContent:{...a,timeline:[...ge(a),...ge(r)],textBefore:Se(a.textBefore,r.textBefore),toolCalls:gs(a.toolCalls,r.toolCalls),textAfter:Se(a.textAfter,r.textAfter),thinkingContent:Se(a.thinkingContent,r.thinkingContent),tasks:[],subagent:null,subagents:[],confirmation:null,question:null,elicitation:null}}}function ys(t){const s=[];for(const a of t){const r=vs(a),i=s[s.length-1];i&&Fe(i)&&Fe(r)?s[s.length-1]=ks(i,r):s.push(r)}return s}const js=new Set(["completed","stale","failed","aborted","interrupted"]),ws={completed:"chat.review.status.completed",stale:"chat.review.status.stale",failed:"chat.review.status.failed",aborted:"chat.review.status.aborted",interrupted:"chat.review.status.interrupted"},Ns={completed:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/20",stale:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20",failed:"bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/20",aborted:"bg-zinc-500/10 text-zinc-700 dark:text-zinc-300 border-zinc-500/20",interrupted:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20"};function ke(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Ss(t){const s=ke(t),a=ke(s==null?void 0:s.codeLocation),r=s==null?void 0:s.priority,i=s==null?void 0:s.confidenceScore,n=a==null?void 0:a.lineStart,c=a==null?void 0:a.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||r!==0&&r!==1&&r!==2&&r!==3||typeof i!="number"||!Number.isFinite(i)||typeof(a==null?void 0:a.path)!="string"||!Number.isInteger(n)||!Number.isInteger(c)))return{title:s.title,body:s.body,priority:r,confidenceScore:i,codeLocation:{path:a.path,lineStart:n,lineEnd:c}}}function Cs(t){const s=ke(t),a=ke(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!js.has(s.status)||typeof(a==null?void 0:a.label)!="string"||a.kind!=="uncommitted"&&a.kind!=="base"&&a.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const r=s.findings.map(Ss);if(!r.some(i=>i===void 0))return{status:s.status,target:{kind:a.kind,label:a.label,...typeof a.reference=="string"?{reference:a.reference}:{}},overallExplanation:s.overallExplanation,findings:r,...typeof s.error=="string"?{error:s.error}:{}}}function Ts(t){const{path:s,lineStart:a,lineEnd:r}=t.codeLocation;return a===r?`${s}:L${a}`:`${s}:L${a}-${r}`}function Es({report:t}){const s=_(),a=t.target.kind==="uncommitted"?s("chat.review.target.uncommitted"):t.target.kind==="base"?s("chat.review.target.base",{ref:t.target.reference??t.target.label}):s("chat.review.target.commit",{ref:t.target.reference??t.target.label});return e.jsxs("section",{"data-code-review-report":!0,className:"overflow-hidden rounded-xl border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface-2))]/60 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.review.title")}),e.jsxs("p",{className:"mt-0.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-faint))]",children:[s("chat.review.target"),": ",a]})]}),e.jsxs("span",{className:L("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",Ns[t.status]),children:[s("chat.review.status"),": ",s(ws[t.status])]})]}),e.jsxs("div",{className:"space-y-4 px-4 py-3.5",children:[e.jsx("p",{className:"whitespace-pre-wrap text-[13px] leading-6 text-[hsl(var(--deck-ink-muted))]",children:t.overallExplanation}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("h4",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.findings")}),e.jsx("span",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:t.findings.length})]}),t.findings.length===0?e.jsx("div",{className:"rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2.5 text-[12px] text-[hsl(var(--deck-ink-muted))]",children:s("chat.review.noFindings")}):e.jsx("ol",{className:"space-y-2",children:t.findings.map((r,i)=>e.jsxs("li",{className:"rounded-lg border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))] px-3 py-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsx("h5",{className:"text-[12.5px] font-medium leading-5 text-[hsl(var(--deck-ink))]",children:r.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:r.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:Ts(r)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:r.body})]},`${r.codeLocation.path}:${r.codeLocation.lineStart}:${i}`))})]}),t.error&&e.jsxs("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-[11px] text-red-700 dark:text-red-300",children:[e.jsxs("span",{className:"font-medium",children:[s("chat.review.error"),":"]})," ",t.error]})]})]})}function Ms({elicitation:t,messageId:s}){const a=_(),r=v(f=>f.currentSessionRef),i=v(f=>f.setElicitation),[n,c]=h.useState(()=>Rs(t.details.fields??[])),[m,x]=h.useState(()=>Ds(t.details.fields??[])),[l,b]=h.useState(!1),[k,u]=h.useState(),g=t.details.fields??[],p=h.useMemo(()=>g.every(f=>{var o;if(!f.required)return!0;if(we(f))return!!((o=m[f.name])!=null&&o.trim()||f.defaultValue!==void 0);const S=n[f.name]??f.defaultValue;return Array.isArray(S)?S.length>0:S!==void 0}),[g,m,n]);if(t.status!=="pending")return e.jsx("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:a(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const w=async(f,S)=>{if(!q(v.getState())&&!(!r||l)){b(!0),u(void 0);try{await re.respondToElicitation(r,t.toolCallId,{action:f,...S?{content:S}:{}}),i(s,{...t,status:"responded"})}catch(o){u(o instanceof Error?o.message:a("interaction.elicitation.failed"))}finally{b(!1)}}},d=async()=>{try{await w("accept",Fs(g,n,m))}catch(f){u(f instanceof Error?f.message:String(f))}},N=()=>{if(q(v.getState()))return;const f=t.details.url;if(!f){u("MCP URL is unavailable");return}if(!window.open(f,"_blank","noopener,noreferrer")){u("The browser blocked the external window");return}w("accept")};return e.jsxs("div",{"data-pending-interaction":"elicitation",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ct,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"font-mono text-[12px] font-semibold text-[hsl(var(--deck-ink))]",children:[a("interaction.elicitation.title")," · ",t.details.serverName]}),e.jsx("div",{className:"font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:t.details.message}),e.jsx("div",{className:"font-mono text-[11px] text-amber-700 dark:text-amber-300",children:a("interaction.elicitation.warning")})]})]}),t.details.mode==="url"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] p-3 font-mono text-[11px]",children:[e.jsx("div",{className:"text-[hsl(var(--deck-ink-muted))]",children:t.details.domain}),e.jsx("div",{className:"mt-1 break-all text-[hsl(var(--deck-ink))]",children:t.details.url})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ne,{onClick:N,disabled:l,primary:!0,label:a("interaction.elicitation.open"),icon:e.jsx(Gt,{className:"h-3.5 w-3.5"})}),e.jsx(ne,{onClick:()=>void w("decline"),disabled:l,label:a("interaction.elicitation.decline")}),e.jsx(ne,{onClick:()=>void w("cancel"),disabled:l,label:a("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[g.map(f=>e.jsx(As,{field:f,value:n[f.name],rawValue:m[f.name]??"",onValueChange:S=>c(o=>({...o,[f.name]:S})),onRawChange:S=>x(o=>({...o,[f.name]:S}))},f.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ne,{onClick:()=>void d(),disabled:l||!p,primary:!0,label:a("interaction.elicitation.submit"),icon:l?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(ne,{onClick:()=>void w("decline"),disabled:l,label:a("interaction.elicitation.decline")}),e.jsx(ne,{onClick:()=>void w("cancel"),disabled:l,label:a("interaction.elicitation.cancel")})]})]}),k&&e.jsx("div",{className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:k})]})}function As({field:t,value:s,rawValue:a,onValueChange:r,onRawChange:i}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{htmlFor:`mcp-elicitation-${t.name}`,className:"block font-mono text-[12px] font-medium text-[hsl(var(--deck-ink))]",children:[t.title,t.required?" *":""]}),t.description&&e.jsx("div",{className:"font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:t.description}),t.type==="select"||t.type==="multi-select"||t.type==="boolean"?e.jsx("div",{id:`mcp-elicitation-${t.name}`,className:"flex flex-wrap gap-2",children:Is(t).map(n=>{const c=Array.isArray(s)?s.includes(n.value):s===n.typedValue;return e.jsx("button",{type:"button","aria-pressed":c,onClick:()=>{if(t.type==="multi-select"){const m=Array.isArray(s)?s:[];r(m.includes(n.value)?m.filter(x=>x!==n.value):[...m,n.value])}else r(n.typedValue)},className:L("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",c?"border-emerald-500 bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-200":"border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:n.label},n.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Ls(t),value:a,onChange:n=>i(n.target.value),min:t.minimum,max:t.maximum,minLength:t.minLength,maxLength:t.maxLength,required:t.required,placeholder:t.defaultValue===void 0?t.required?"Required":"Optional":String(t.defaultValue),className:"w-full rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink))] outline-none transition-colors focus:border-amber-500 focus:ring-1 focus:ring-amber-500"})]})}function ne({onClick:t,disabled:s,primary:a=!1,label:r,icon:i}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:L("inline-flex min-h-8 items-center gap-1.5 rounded-md px-3 py-1.5 font-mono text-[12px] transition-colors disabled:cursor-wait disabled:opacity-50",a?"bg-amber-600 text-white hover:bg-amber-700":"border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:[i,r]})}function Rs(t){return Object.fromEntries(t.filter(s=>!we(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function Ds(t){return Object.fromEntries(t.filter(s=>we(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Fs(t,s,a){var i;const r={};for(const n of t){if(we(n)){const m=((i=a[n.name])==null?void 0:i.trim())??"";if(!m){if(n.defaultValue!==void 0)r[n.name]=n.defaultValue;else if(n.required)throw new Error(`${n.title} is required`);continue}if(n.type==="number"||n.type==="integer"){const x=Number(m);if(!Number.isFinite(x))throw new Error(`${n.title} must be a finite number`);if(n.type==="integer"&&!Number.isSafeInteger(x))throw new Error(`${n.title} must be a safe integer`);r[n.name]=x}else r[n.name]=m;continue}const c=s[n.name]??n.defaultValue;if(c===void 0){if(n.required)throw new Error(`${n.title} is required`);continue}if(Array.isArray(c)){if(n.minItems!==void 0&&c.length<n.minItems)throw new Error(`${n.title} requires at least ${n.minItems} choices`);if(n.maxItems!==void 0&&c.length>n.maxItems)throw new Error(`${n.title} allows at most ${n.maxItems} choices`)}r[n.name]=c}return r}function Is(t){return t.type==="boolean"?[{value:"true",label:"Yes",typedValue:!0},{value:"false",label:"No",typedValue:!1}]:(t.options??[]).map(s=>({...s,typedValue:s.value}))}function we(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Ls(t){return t.type==="number"||t.type==="integer"?"number":t.format==="email"?"email":t.format==="uri"?"url":t.format==="date"?"date":t.format==="date-time"?"datetime-local":"text"}function Bs(t){if(!t||typeof t!="object"||Array.isArray(t))return;const s=t;if(!(!s.output||typeof s.output!="object"||Array.isArray(s.output)))return{output:s.output,...typeof s.schemaDigest=="string"?{schemaDigest:s.schemaDigest}:{}}}function $s({report:t}){const s=_(),[a,r]=h.useState(!1),i=JSON.stringify(t.output,null,2),n=async()=>{try{await navigator.clipboard.writeText(i),r(!0),window.setTimeout(()=>r(!1),1400)}catch{}};return e.jsxs("section",{"data-structured-output":!0,className:"overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex min-h-9 items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Tt,{className:"h-3.5 w-3.5 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsx("span",{className:"font-mono text-[11px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.structuredOutput.title")}),t.schemaDigest&&e.jsxs("span",{title:t.schemaDigest,className:"truncate font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["sha256:",t.schemaDigest.slice(0,10)]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":s("chat.structuredOutput.copy"),title:s("chat.structuredOutput.copy"),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-[hsl(var(--deck-ink-faint))] hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:a?e.jsx(je,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(xt,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"max-h-[440px] overflow-auto whitespace-pre p-3 font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink))]",children:i})]})}const Ps=h.lazy(()=>lt(()=>import("./MarkdownRenderer-DhB-5HAw.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function Qe({text:t,label:s}){const[a,r]=h.useState(!1);if(!t.trim())return null;const i=async()=>{try{await navigator.clipboard.writeText(t),r(!0),window.setTimeout(()=>r(!1),1400)}catch{}};return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:i,className:"flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:a?e.jsx(je,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(xt,{className:"h-3.5 w-3.5"})})}function _s(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] shadow-[0_1px_0_hsl(var(--deck-hairline))]",children:e.jsx(Re,{size:20,pulse:!1})})}function Os(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-full border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas-veil))]",children:e.jsx("span",{className:"font-mono text-[11px] font-medium text-[hsl(var(--deck-ink))]",children:"U"})})}function Ge(t){let s=t;return s=s.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g,""),s=s.replace(/<file path="[^"]*">[\s\S]*?<\/file>/g,""),s=s.replace(/<attached_files>[\s\S]*?<\/attached_files>/g,""),s=s.trim(),s}function Us(t){if(typeof t=="string")return{text:Ge(t),images:[]};const s=t.filter(r=>r.type==="text").map(r=>r.text).join(`
54
+ `)}function ks(t,s){const a=t.agentContent,r=s.agentContent;return{...t,...t.metadata||s.metadata?{metadata:{...t.metadata,...s.metadata}}:{},displaySourceMessageIds:[...t.displaySourceMessageIds??[t.id],...s.displaySourceMessageIds??[s.id]],agentContent:{...a,timeline:[...ge(a),...ge(r)],textBefore:Se(a.textBefore,r.textBefore),toolCalls:gs(a.toolCalls,r.toolCalls),textAfter:Se(a.textAfter,r.textAfter),thinkingContent:Se(a.thinkingContent,r.thinkingContent),tasks:[],subagent:null,subagents:[],confirmation:null,question:null,elicitation:null}}}function ys(t){const s=[];for(const a of t){const r=vs(a),i=s[s.length-1];i&&Fe(i)&&Fe(r)?s[s.length-1]=ks(i,r):s.push(r)}return s}const js=new Set(["completed","stale","failed","aborted","interrupted"]),ws={completed:"chat.review.status.completed",stale:"chat.review.status.stale",failed:"chat.review.status.failed",aborted:"chat.review.status.aborted",interrupted:"chat.review.status.interrupted"},Ns={completed:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/20",stale:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20",failed:"bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/20",aborted:"bg-zinc-500/10 text-zinc-700 dark:text-zinc-300 border-zinc-500/20",interrupted:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20"};function ke(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Ss(t){const s=ke(t),a=ke(s==null?void 0:s.codeLocation),r=s==null?void 0:s.priority,i=s==null?void 0:s.confidenceScore,n=a==null?void 0:a.lineStart,c=a==null?void 0:a.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||r!==0&&r!==1&&r!==2&&r!==3||typeof i!="number"||!Number.isFinite(i)||typeof(a==null?void 0:a.path)!="string"||!Number.isInteger(n)||!Number.isInteger(c)))return{title:s.title,body:s.body,priority:r,confidenceScore:i,codeLocation:{path:a.path,lineStart:n,lineEnd:c}}}function Cs(t){const s=ke(t),a=ke(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!js.has(s.status)||typeof(a==null?void 0:a.label)!="string"||a.kind!=="uncommitted"&&a.kind!=="base"&&a.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const r=s.findings.map(Ss);if(!r.some(i=>i===void 0))return{status:s.status,target:{kind:a.kind,label:a.label,...typeof a.reference=="string"?{reference:a.reference}:{}},overallExplanation:s.overallExplanation,findings:r,...typeof s.error=="string"?{error:s.error}:{}}}function Es(t){const{path:s,lineStart:a,lineEnd:r}=t.codeLocation;return a===r?`${s}:L${a}`:`${s}:L${a}-${r}`}function Ts({report:t}){const s=_(),a=t.target.kind==="uncommitted"?s("chat.review.target.uncommitted"):t.target.kind==="base"?s("chat.review.target.base",{ref:t.target.reference??t.target.label}):s("chat.review.target.commit",{ref:t.target.reference??t.target.label});return e.jsxs("section",{"data-code-review-report":!0,className:"overflow-hidden rounded-xl border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface-2))]/60 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.review.title")}),e.jsxs("p",{className:"mt-0.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-faint))]",children:[s("chat.review.target"),": ",a]})]}),e.jsxs("span",{className:L("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",Ns[t.status]),children:[s("chat.review.status"),": ",s(ws[t.status])]})]}),e.jsxs("div",{className:"space-y-4 px-4 py-3.5",children:[e.jsx("p",{className:"whitespace-pre-wrap text-[13px] leading-6 text-[hsl(var(--deck-ink-muted))]",children:t.overallExplanation}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("h4",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.findings")}),e.jsx("span",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:t.findings.length})]}),t.findings.length===0?e.jsx("div",{className:"rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2.5 text-[12px] text-[hsl(var(--deck-ink-muted))]",children:s("chat.review.noFindings")}):e.jsx("ol",{className:"space-y-2",children:t.findings.map((r,i)=>e.jsxs("li",{className:"rounded-lg border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))] px-3 py-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsx("h5",{className:"text-[12.5px] font-medium leading-5 text-[hsl(var(--deck-ink))]",children:r.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:r.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:Es(r)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:r.body})]},`${r.codeLocation.path}:${r.codeLocation.lineStart}:${i}`))})]}),t.error&&e.jsxs("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-[11px] text-red-700 dark:text-red-300",children:[e.jsxs("span",{className:"font-medium",children:[s("chat.review.error"),":"]})," ",t.error]})]})]})}function Ms({elicitation:t,messageId:s}){const a=_(),r=v(f=>f.currentSessionRef),i=v(f=>f.setElicitation),[n,c]=h.useState(()=>Rs(t.details.fields??[])),[m,x]=h.useState(()=>Ds(t.details.fields??[])),[l,b]=h.useState(!1),[k,u]=h.useState(),g=t.details.fields??[],p=h.useMemo(()=>g.every(f=>{var o;if(!f.required)return!0;if(we(f))return!!((o=m[f.name])!=null&&o.trim()||f.defaultValue!==void 0);const S=n[f.name]??f.defaultValue;return Array.isArray(S)?S.length>0:S!==void 0}),[g,m,n]);if(t.status!=="pending")return e.jsx("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:a(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const w=async(f,S)=>{if(!q(v.getState())&&!(!r||l)){b(!0),u(void 0);try{await re.respondToElicitation(r,t.toolCallId,{action:f,...S?{content:S}:{}}),i(s,{...t,status:"responded"})}catch(o){u(o instanceof Error?o.message:a("interaction.elicitation.failed"))}finally{b(!1)}}},d=async()=>{try{await w("accept",Fs(g,n,m))}catch(f){u(f instanceof Error?f.message:String(f))}},N=()=>{if(q(v.getState()))return;const f=t.details.url;if(!f){u("MCP URL is unavailable");return}if(!window.open(f,"_blank","noopener,noreferrer")){u("The browser blocked the external window");return}w("accept")};return e.jsxs("div",{"data-pending-interaction":"elicitation",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ct,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"font-mono text-[12px] font-semibold text-[hsl(var(--deck-ink))]",children:[a("interaction.elicitation.title")," · ",t.details.serverName]}),e.jsx("div",{className:"font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:t.details.message}),e.jsx("div",{className:"font-mono text-[11px] text-amber-700 dark:text-amber-300",children:a("interaction.elicitation.warning")})]})]}),t.details.mode==="url"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] p-3 font-mono text-[11px]",children:[e.jsx("div",{className:"text-[hsl(var(--deck-ink-muted))]",children:t.details.domain}),e.jsx("div",{className:"mt-1 break-all text-[hsl(var(--deck-ink))]",children:t.details.url})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ne,{onClick:N,disabled:l,primary:!0,label:a("interaction.elicitation.open"),icon:e.jsx(Gt,{className:"h-3.5 w-3.5"})}),e.jsx(ne,{onClick:()=>void w("decline"),disabled:l,label:a("interaction.elicitation.decline")}),e.jsx(ne,{onClick:()=>void w("cancel"),disabled:l,label:a("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[g.map(f=>e.jsx(As,{field:f,value:n[f.name],rawValue:m[f.name]??"",onValueChange:S=>c(o=>({...o,[f.name]:S})),onRawChange:S=>x(o=>({...o,[f.name]:S}))},f.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(ne,{onClick:()=>void d(),disabled:l||!p,primary:!0,label:a("interaction.elicitation.submit"),icon:l?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(ne,{onClick:()=>void w("decline"),disabled:l,label:a("interaction.elicitation.decline")}),e.jsx(ne,{onClick:()=>void w("cancel"),disabled:l,label:a("interaction.elicitation.cancel")})]})]}),k&&e.jsx("div",{className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:k})]})}function As({field:t,value:s,rawValue:a,onValueChange:r,onRawChange:i}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{htmlFor:`mcp-elicitation-${t.name}`,className:"block font-mono text-[12px] font-medium text-[hsl(var(--deck-ink))]",children:[t.title,t.required?" *":""]}),t.description&&e.jsx("div",{className:"font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:t.description}),t.type==="select"||t.type==="multi-select"||t.type==="boolean"?e.jsx("div",{id:`mcp-elicitation-${t.name}`,className:"flex flex-wrap gap-2",children:Is(t).map(n=>{const c=Array.isArray(s)?s.includes(n.value):s===n.typedValue;return e.jsx("button",{type:"button","aria-pressed":c,onClick:()=>{if(t.type==="multi-select"){const m=Array.isArray(s)?s:[];r(m.includes(n.value)?m.filter(x=>x!==n.value):[...m,n.value])}else r(n.typedValue)},className:L("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",c?"border-emerald-500 bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-200":"border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:n.label},n.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Ls(t),value:a,onChange:n=>i(n.target.value),min:t.minimum,max:t.maximum,minLength:t.minLength,maxLength:t.maxLength,required:t.required,placeholder:t.defaultValue===void 0?t.required?"Required":"Optional":String(t.defaultValue),className:"w-full rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink))] outline-none transition-colors focus:border-amber-500 focus:ring-1 focus:ring-amber-500"})]})}function ne({onClick:t,disabled:s,primary:a=!1,label:r,icon:i}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:L("inline-flex min-h-8 items-center gap-1.5 rounded-md px-3 py-1.5 font-mono text-[12px] transition-colors disabled:cursor-wait disabled:opacity-50",a?"bg-amber-600 text-white hover:bg-amber-700":"border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:[i,r]})}function Rs(t){return Object.fromEntries(t.filter(s=>!we(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function Ds(t){return Object.fromEntries(t.filter(s=>we(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Fs(t,s,a){var i;const r={};for(const n of t){if(we(n)){const m=((i=a[n.name])==null?void 0:i.trim())??"";if(!m){if(n.defaultValue!==void 0)r[n.name]=n.defaultValue;else if(n.required)throw new Error(`${n.title} is required`);continue}if(n.type==="number"||n.type==="integer"){const x=Number(m);if(!Number.isFinite(x))throw new Error(`${n.title} must be a finite number`);if(n.type==="integer"&&!Number.isSafeInteger(x))throw new Error(`${n.title} must be a safe integer`);r[n.name]=x}else r[n.name]=m;continue}const c=s[n.name]??n.defaultValue;if(c===void 0){if(n.required)throw new Error(`${n.title} is required`);continue}if(Array.isArray(c)){if(n.minItems!==void 0&&c.length<n.minItems)throw new Error(`${n.title} requires at least ${n.minItems} choices`);if(n.maxItems!==void 0&&c.length>n.maxItems)throw new Error(`${n.title} allows at most ${n.maxItems} choices`)}r[n.name]=c}return r}function Is(t){return t.type==="boolean"?[{value:"true",label:"Yes",typedValue:!0},{value:"false",label:"No",typedValue:!1}]:(t.options??[]).map(s=>({...s,typedValue:s.value}))}function we(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Ls(t){return t.type==="number"||t.type==="integer"?"number":t.format==="email"?"email":t.format==="uri"?"url":t.format==="date"?"date":t.format==="date-time"?"datetime-local":"text"}function Bs(t){if(!t||typeof t!="object"||Array.isArray(t))return;const s=t;if(!(!s.output||typeof s.output!="object"||Array.isArray(s.output)))return{output:s.output,...typeof s.schemaDigest=="string"?{schemaDigest:s.schemaDigest}:{}}}function $s({report:t}){const s=_(),[a,r]=h.useState(!1),i=JSON.stringify(t.output,null,2),n=async()=>{try{await navigator.clipboard.writeText(i),r(!0),window.setTimeout(()=>r(!1),1400)}catch{}};return e.jsxs("section",{"data-structured-output":!0,className:"overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex min-h-9 items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Et,{className:"h-3.5 w-3.5 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsx("span",{className:"font-mono text-[11px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.structuredOutput.title")}),t.schemaDigest&&e.jsxs("span",{title:t.schemaDigest,className:"truncate font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["sha256:",t.schemaDigest.slice(0,10)]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":s("chat.structuredOutput.copy"),title:s("chat.structuredOutput.copy"),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-[hsl(var(--deck-ink-faint))] hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:a?e.jsx(je,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(xt,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"max-h-[440px] overflow-auto whitespace-pre p-3 font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink))]",children:i})]})}const Ps=h.lazy(()=>lt(()=>import("./MarkdownRenderer-DnFpJUbW.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function Qe({text:t,label:s}){const[a,r]=h.useState(!1);if(!t.trim())return null;const i=async()=>{try{await navigator.clipboard.writeText(t),r(!0),window.setTimeout(()=>r(!1),1400)}catch{}};return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:i,className:"flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:a?e.jsx(je,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(xt,{className:"h-3.5 w-3.5"})})}function _s(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] shadow-[0_1px_0_hsl(var(--deck-hairline))]",children:e.jsx(Re,{size:20,pulse:!1})})}function Os(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-full border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas-veil))]",children:e.jsx("span",{className:"font-mono text-[11px] font-medium text-[hsl(var(--deck-ink))]",children:"U"})})}function Ge(t){let s=t;return s=s.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g,""),s=s.replace(/<file path="[^"]*">[\s\S]*?<\/file>/g,""),s=s.replace(/<attached_files>[\s\S]*?<\/attached_files>/g,""),s=s.trim(),s}function Us(t){if(typeof t=="string")return{text:Ge(t),images:[]};const s=t.filter(r=>r.type==="text").map(r=>r.text).join(`
55
55
  `),a=t.filter(r=>r.type==="image_url").map(r=>r.image_url.url);return{text:Ge(s),images:a}}function Ue(t){return typeof t=="string"?t:t.filter(s=>s.type==="text").map(s=>s.text).join(`
56
56
  `)}function Ks(t){const s=t.agentContent;return s?Ut(s):Ue(t.content)}function We({content:t,syntaxHighlight:s=!0}){return e.jsx(h.Suspense,{fallback:e.jsx("pre",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono whitespace-pre-wrap",children:t}),children:e.jsx(Ps,{content:t,syntaxHighlight:s})})}function Ke({status:t}){if(!t)return null;const s={running:"bg-[#FEF3C7] text-[#92400E] dark:bg-[#F59E0B]/20 dark:text-[#FBBF24]",success:"bg-[#DCFCE7] text-[#15803D] dark:bg-[#22C55E]/20 dark:text-[#22C55E]",error:"bg-[#FEE2E2] text-[#b91c1c] dark:bg-[#EF4444]/20 dark:text-[#fca5a5]",pending:"bg-[#E5E7EB] text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]",info:"bg-[#DBEAFE] text-[#1D4ED8] dark:bg-[#3B82F6]/20 dark:text-[#60A5FA]"},a={running:"Running",success:"Success",error:"Error",pending:"Pending",info:"Info"};return e.jsx("span",{className:L("text-[11px] px-2 py-0.5 rounded-full font-mono",s[t]),children:a[t]})}function Vs(t){if(!t)return"";if(typeof t=="string")try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}return JSON.stringify(t,null,2)}const Je=500;function bt(t,s){if(t.length<=s)return t;let a=Math.max(0,s);return a>0&&/[\uD800-\uDBFF]/.test(t.charAt(a-1))&&(a-=1),t.slice(0,a)}function Ye(t,s){if(t.length<=s)return t;let a=Math.max(0,t.length-s);return/[\uDC00-\uDFFF]/.test(t.charAt(a))&&(a+=1),t.slice(a)}function Ce(t,s){if(t.length<=s)return t;if(s<=0)return"";const a=`
57
57
  ... (display clipped) ...
@@ -64,7 +64,7 @@ stderr:
64
64
  stdout:
65
65
  `)){const b=i.slice(0,x),k=i.slice(x+1),u=Math.max(0,c-1),g=Math.floor(u/2);l=`${Ce(b,g)}
66
66
  ${Ce(k,u-g)}`}else l=Ce(i,c);return{body:bt(l,c),...r?{notice:r}:{},truncated:!!r||t.length>Je}}function zs({tool:t}){const[s,a]=h.useState(!1),r=Vs(t.arguments),i=t.output?Hs(t.output):void 0;return e.jsxs("div",{"data-tool-name":t.toolName,"data-tool-status":t.status,"data-tool-truncated":i!=null&&i.truncated?"true":"false",className:"bg-white dark:bg-[#18181b] border border-[hsl(var(--deck-border))] rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button","aria-expanded":s,"data-tool-call-id":t.toolCallId,onClick:()=>a(n=>!n),className:"w-full flex items-center justify-between px-3 py-2 bg-[hsl(var(--deck-surface-2))] hover:bg-[hsl(var(--deck-surface))] transition-colors",children:[e.jsxs("div",{className:"flex gap-2 items-center min-w-0",children:[s?e.jsx(he,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}):e.jsx(ce,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}),e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink))] font-mono shrink-0",children:t.toolName}),t.summary&&e.jsx("span",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono truncate",children:t.summary})]}),e.jsx(Ke,{status:t.status})]}),t.status==="running"&&t.progressMessage&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx("span",{className:"truncate",children:t.progressMessage}),t.progressTotal!==void 0&&t.progress!==void 0&&e.jsxs("span",{className:"shrink-0",children:[Math.max(0,Math.min(100,Math.round(t.progress/t.progressTotal*100))),"%"]})]}),t.progressTotal!==void 0&&t.progress!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${t.toolName} progress`,"aria-valuemin":0,"aria-valuemax":t.progressTotal,"aria-valuenow":Math.min(t.progress,t.progressTotal),className:"h-1 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,t.progress/t.progressTotal*100))}%`}})})]}),s&&e.jsxs("div",{className:"px-3 py-2 space-y-2 border-t border-[hsl(var(--deck-border))]",children:[r&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:"Arguments"}),e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:r})]}),i&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:"Output"}),e.jsxs("pre",{"data-tool-output":!0,className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:[i.body,i.notice&&e.jsxs(e.Fragment,{children:[`
67
- `,e.jsx("span",{"data-tool-truncation-notice":!0,children:i.notice})]})]})]})]})]})}function vt({toolCalls:t}){return t.length===0?null:e.jsx("div",{className:"space-y-2",children:t.map(s=>e.jsx(zs,{tool:s},s.toolCallId))})}function qs({toolCalls:t,toolCallIds:s}){const a=_(),[r,i]=h.useState(!1),n=h.useMemo(()=>new Map(t.map(k=>[k.toolCallId,k])),[t]),c=s.flatMap(k=>{const u=n.get(k);return u?[u]:[]});if(c.length===0)return null;const m=c.filter(k=>k.status==="running").length,x=c.filter(k=>k.status==="error").length,l=[...c].reverse().find(k=>k.status==="running"&&!!k.progressMessage),b=m>0?a(c.length===1?"chat.timeline.tools.runningOne":"chat.timeline.tools.running",{count:c.length}):x>0?a(c.length===1?"chat.timeline.tools.completedOneWithError":"chat.timeline.tools.completedWithErrors",{count:c.length,errors:x}):a(c.length===1?"chat.timeline.tools.completedOne":"chat.timeline.tools.completed",{count:c.length});return e.jsxs("div",{"data-agent-tool-group":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>i(k=>!k),className:"group flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[r?e.jsx(he,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(ce,{className:"h-3.5 w-3.5 shrink-0"}),m>0&&e.jsx(U,{className:"h-3 w-3 shrink-0 animate-spin text-[hsl(var(--deck-accent))]"}),e.jsx("span",{children:b}),(l==null?void 0:l.progressMessage)&&e.jsxs("span",{className:"min-w-0 truncate text-[10.5px] text-[hsl(var(--deck-ink-muted))]",children:[l.progressMessage,l.progress!==void 0&&l.progressTotal!==void 0&&` · ${Math.max(0,Math.min(100,Math.round(l.progress/l.progressTotal*100)))}%`]})]}),(l==null?void 0:l.progress)!==void 0&&l.progressTotal!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${l.toolName} progress`,"aria-valuemin":0,"aria-valuemax":l.progressTotal,"aria-valuenow":Math.min(l.progress,l.progressTotal),className:"mx-1.5 h-0.5 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,l.progress/l.progressTotal*100))}%`}})}),r&&e.jsx("div",{"data-agent-tool-group-details":!0,className:"pl-1 mt-2 space-y-2",children:e.jsx(vt,{toolCalls:c})})]})}function Qs({content:t}){const s=_(),[a,r]=h.useState(!1);return t?e.jsxs("div",{"data-agent-thinking":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>r(i=>!i),className:"flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[a?e.jsx(he,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}):e.jsx(ce,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{children:s("chat.timeline.thinking")})]}),a&&e.jsx("div",{className:"ml-1 mt-1 border-l border-[hsl(var(--deck-border))] py-1 pl-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:t})})]}):null}function Gs({tasks:t}){if(t.length===0)return null;const s=t.filter(r=>r.status==="completed").length,a=s===t.length;return e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"flex gap-2 items-center",children:e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:a?"✓ All tasks done":`Tasks: ${s}/${t.length}`})})})}function Ws({toolCalls:t}){const s=_e(n=>n.openFilePreview),a=v(n=>oe(n.historySurfaceSelection)),r=h.useMemo(()=>{const n=new Map,c=["Write","SearchReplace","Edit","ApplyPatch"];for(const m of t){if(m.status!=="success")continue;const x=m.metadata;if(m.toolName==="ApplyPatch"&&Array.isArray(x==null?void 0:x.changes)){for(const b of x.changes)b&&typeof b=="object"&&"path"in b&&typeof b.path=="string"&&n.set(b.path,{path:b.path,toolName:m.toolName});continue}const l=x==null?void 0:x.file_path;l&&c.includes(m.toolName)&&n.set(l,{path:l,toolName:m.toolName})}return Array.from(n.values())},[t]);if(a||r.length===0)return null;const i=n=>{q(v.getState())||s({tab:"diff",targetPath:n})};return e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono mb-1.5",children:["Changed files (",r.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map(({path:n})=>{const c=n.split("/").pop()||n;return e.jsxs("button",{onClick:()=>i(n),className:"flex items-center gap-1 px-2 py-1 text-[11px] font-mono bg-[#E5E7EB] dark:bg-[#27272a] text-[hsl(var(--deck-ink))] rounded hover:bg-[#D1D5DB] dark:hover:bg-[#3f3f46] transition-colors",title:n,children:[e.jsx(Mt,{className:"w-3 h-3"}),c]},n)})})]})}function Js({subagent:t}){var A,D,G,ee;const s=_(),[a,r]=h.useState(null),[i,n]=h.useState(!1),[c,m]=h.useState(null),[x,l]=h.useState(!1),[b,k]=h.useState(""),[u,g]=h.useState(!1),[p,w]=h.useState(null),[d,N]=h.useState(null),[f,S]=h.useState(null),o=v(F=>F.currentSessionRef),E=v(F=>F.isStreaming),I=v(F=>F.isTemporarySession),R=v(F=>oe(F.historySurfaceSelection));if(!t)return null;const j=t.status==="running",V=a!==null?a:j,X=t.toolCalls||c||[],T=t.output||t.thinking||X.length>0||t.sessionId,B=d&&d.status!=="running"?d:f,O=(B==null?void 0:B.id)??t.sessionId,P=((A=B==null?void 0:B.restartRecovery)==null?void 0:A.outcome)==="failed",C=!j&&!E&&!I&&!R&&!P&&(d==null?void 0:d.status)!=="running"&&!!(O&&o);h.useEffect(()=>{if(R||!V||j||!t.sessionId||!(o!=null&&o.projectPath)||c!==null||t.toolCalls&&t.toolCalls.length>0)return;let F=!0;return n(!0),re.getMessages({sessionId:t.sessionId,projectPath:o.projectPath}).then(W=>{var z,K;if(!F)return;const J=Vt(W),Q=new Map;for(const Y of J)if((K=(z=Y.agentContent)==null?void 0:z.toolCalls)!=null&&K.length)for(const te of Y.agentContent.toolCalls)Q.has(te.toolCallId)||Q.set(te.toolCallId,te);m(Array.from(Q.values()))}).finally(()=>{F&&n(!1)}),()=>{F=!1}},[V,R,j,t.sessionId,t.toolCalls,c,o==null?void 0:o.projectPath]),h.useEffect(()=>{if(R||!t.sessionId||!o)return;let F=!0;const W=t.rootAgentId??t.sessionId,J=t.resumeDepth??0;return re.listSubagents(o).then(Q=>{if(!F)return;S(Q.find(K=>K.id===t.sessionId)??null);const z=Q.filter(K=>K.id!==t.sessionId&&K.rootAgentId===W&&K.resumeDepth>J).sort((K,Y)=>Y.resumeDepth-K.resumeDepth||Y.lastActiveAt-K.lastActiveAt)[0];z&&N(z)}).catch(()=>{}),()=>{F=!1}},[o==null?void 0:o.sessionId,o==null?void 0:o.projectPath,R,t.sessionId,t.rootAgentId,t.resumeDepth]),h.useEffect(()=>{if(R||!d||d.status!=="running"||!o)return;let F=!0;const W=async()=>{try{const z=(await re.listSubagents(o)).find(K=>K.id===d.id);F&&z&&N(z)}catch{}},J=window.setInterval(()=>{W()},1e3);return()=>{F=!1,window.clearInterval(J)}},[o,R,d==null?void 0:d.id,d==null?void 0:d.status]);const M=async()=>{if(!q(v.getState())&&!(!o||!O||!b.trim()||u)){g(!0),w(null);try{const F=await re.resumeSubagent(o,O,b.trim());N(F.session),k(""),l(!1),r(!0)}catch(F){w(F instanceof Error?F.message:s("chat.subagent.resumeFailed"))}finally{g(!1)}}};return e.jsxs("div",{"data-subagent-id":t.id,"data-subagent-session-id":t.sessionId,className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>r(!V),className:"flex gap-2 justify-between items-center w-full transition-opacity cursor-pointer hover:opacity-80",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[j&&e.jsx(U,{className:"h-3 w-3 animate-spin text-[hsl(var(--deck-ink-muted))]"}),e.jsxs("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[t.type,": ",t.description]}),e.jsx(Ke,{status:t.status==="completed"?"success":t.status==="failed"?"error":"running"}),t.type==="verification"&&t.verificationVerdict&&e.jsx("span",{"data-verification-verdict":t.verificationVerdict,className:L("rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide",t.verificationVerdict==="pass"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":t.verificationVerdict==="fail"?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"),children:t.verificationVerdict}),t.resumedFrom&&e.jsx("span",{className:"rounded bg-[#EDE9FE] px-1.5 py-0.5 text-[10px] font-mono text-[#6D28D9] dark:bg-[#2E1065] dark:text-[#C4B5FD]",title:s("chat.subagent.resumedFromTitle",{id:t.resumedFrom}),children:s("chat.subagent.resumedDepth",{depth:t.resumeDepth??1})})]}),T&&e.jsx(he,{className:L("h-3.5 w-3.5 text-[hsl(var(--deck-ink-muted))] transition-transform",V&&"rotate-180")})]}),!V&&!j&&t.output&&e.jsx("div",{"data-subagent-output-summary":!0,className:"mt-2 max-h-10 overflow-hidden whitespace-pre-wrap break-words font-mono text-[11px] text-[hsl(var(--deck-ink))]",children:t.output}),V&&e.jsxs("div",{className:"mt-2 space-y-2",children:[(t.output||t.thinking)&&e.jsxs(e.Fragment,{children:[t.output&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[160px] overflow-y-auto",children:t.output}),t.thinking&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:t.thinking})]}),i&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[e.jsx(U,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.loadingLogs")]}),!i&&X.length>0&&e.jsx(vt,{toolCalls:X}),d&&e.jsxs("div",{className:"rounded-md border border-[#DDD6FE] bg-[#F5F3FF] p-2 text-[11px] font-mono text-[#5B21B6] dark:border-[#4C1D95] dark:bg-[#1E1B4B] dark:text-[#C4B5FD]",children:[e.jsx("div",{children:s("chat.subagent.resumedAs",{id:d.id,status:d.status,depth:d.resumeDepth??1})}),(((D=d.result)==null?void 0:D.message)||((G=d.result)==null?void 0:G.error))&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap text-[hsl(var(--deck-ink))]",children:d.result.message||d.result.error})]}),P&&((ee=B==null?void 0:B.result)==null?void 0:ee.error)&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:B.result.error}),C&&e.jsxs("div",{className:"space-y-2",children:[x?e.jsxs("div",{className:"space-y-2 rounded-md border border-[#E5E7EB] bg-white p-2 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsx("textarea",{"aria-label":s("chat.subagent.followUpAria"),value:b,onChange:F=>k(F.target.value),placeholder:s("chat.subagent.followUpPlaceholder"),rows:3,className:"w-full resize-y rounded border border-[#D1D5DB] bg-white p-2 text-[11px] text-[#111827] outline-none focus:border-[#8B5CF6] dark:border-[#3f3f46] dark:bg-[#18181b] dark:text-[#f4f4f5]"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>{l(!1),w(null)},className:"rounded px-2 py-1 text-[11px] text-[#6B7280] hover:bg-[#F3F4F6] dark:hover:bg-[#27272a]",children:s("chat.subagent.cancel")}),e.jsxs("button",{type:"button",onClick:()=>void M(),disabled:!b.trim()||u,className:"flex items-center gap-1 rounded bg-[#7C3AED] px-2 py-1 text-[11px] font-medium text-white disabled:opacity-50",children:[u&&e.jsx(U,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.resumeAgent")]})]})]}):e.jsxs("button",{type:"button","aria-label":s("chat.subagent.resumeAria"),onClick:()=>l(!0),className:"flex items-center gap-1.5 rounded-md border border-[#D1D5DB] px-2 py-1 text-[11px] font-medium text-[#374151] transition-colors hover:bg-[#F3F4F6] dark:border-[#3f3f46] dark:text-[#d4d4d8] dark:hover:bg-[#27272a]",children:[e.jsx(ve,{className:"w-3 h-3"}),s("chat.subagent.resume")]}),p&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:p})]})]})]})}function Ys({confirmation:t,messageId:s}){const a=_(),[r,i]=h.useState(!1),[n,c]=h.useState(null),m=v(b=>b.currentSessionRef),x=v(b=>b.setConfirmation);if(!t)return null;const l=async(b,k)=>{if(!q(v.getState())&&!(!m||r)){i(!0),c(null);try{await re.respondPermission(m,t.toolCallId,{approved:b,scope:k}),x(s,{...t,status:b?"approved":"denied"})}catch(u){c(u instanceof Error?u.message:a("interaction.permission.failed"))}finally{i(!1)}}};return t.status!=="pending"?null:e.jsxs("div",{"data-pending-interaction":"permission",tabIndex:-1,role:"alert",className:"p-4 space-y-3 rounded-lg border outline-none border-amber-300/70 bg-amber-50/70 focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:a("interaction.permission.title",{tool:t.toolName})}),e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:t.description}),t.diff&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[200px] overflow-y-auto",children:t.diff}),n&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:n}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"once"),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:r?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):a("interaction.permission.once")}),t.allowRemember!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"session"),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#3B82F6] text-white rounded-md hover:bg-[#2563EB] disabled:cursor-wait disabled:opacity-50",children:a("interaction.permission.session")}),e.jsx("button",{type:"button",onClick:()=>void l(!0,"project"),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#6366F1] text-white rounded-md hover:bg-[#4F46E5] disabled:cursor-wait disabled:opacity-50",children:a("interaction.permission.project")})]}),e.jsx("button",{type:"button",onClick:()=>void l(!1),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#EF4444] text-white rounded-md hover:bg-[#DC2626] disabled:cursor-wait disabled:opacity-50",children:a("interaction.permission.deny")})]})]})}function Xs({question:t,messageId:s}){const a=_(),[r,i]=h.useState({}),[n,c]=h.useState({}),[m,x]=h.useState(!1),[l,b]=h.useState(null),k=v(d=>d.currentSessionRef),u=v(d=>d.setQuestion),g=h.useMemo(()=>t?t.questions.reduce((d,N)=>{var E;const f=(E=n[N.header])==null?void 0:E.trim(),S=r[N.header];if(N.multiSelect){const I=Array.isArray(S)?[...S]:[];return f&&I.push(f),I.length>0&&(d[N.header]=I),d}const o=f||(typeof S=="string"?S:"");return o&&(d[N.header]=o),d},{}):{},[r,n,t]),p=(t==null?void 0:t.questions.every(d=>d.header in g))??!1;if(!t)return null;const w=async()=>{if(!q(v.getState())&&!(!k||m||!p)){x(!0),b(null);try{await re.respondToQuestion(k,t.toolCallId,g),u(s,{...t,status:"answered",answers:g})}catch(d){b(d instanceof Error?d.message:a("interaction.question.failed"))}finally{x(!1)}}};return t.status!=="pending"?e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:a("interaction.question.answered")})}):e.jsxs("div",{"data-pending-interaction":"question",tabIndex:-1,role:"alert",className:"p-4 space-y-4 rounded-lg border outline-none border-amber-300/70 bg-amber-50/70 focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[t.questions.map((d,N)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:d.question}),e.jsxs("div",{className:"space-y-1",children:[d.options.map((f,S)=>e.jsxs("button",{type:"button",onClick:()=>{if(d.multiSelect){const o=r[d.header]||[],E=o.includes(f.label)?o.filter(I=>I!==f.label):[...o,f.label];i({...r,[d.header]:E})}else i({...r,[d.header]:f.label}),c({...n,[d.header]:""})},className:L("w-full text-left px-3 py-2 rounded-md border text-[12px] font-mono transition-colors","border-[hsl(var(--deck-border))]",(d.multiSelect?(r[d.header]||[]).includes(f.label):r[d.header]===f.label)?"bg-[#DCFCE7] text-[#166534] dark:bg-[#22C55E]/20 dark:text-[#E5E5E5]":"bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))]"),children:[e.jsx("div",{children:f.label}),e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-faint))] mt-1",children:f.description})]},S)),e.jsx("input",{"aria-label":`${d.header} other response`,value:n[d.header]??"",onChange:f=>c({...n,[d.header]:f.target.value}),placeholder:a("interaction.question.other"),className:"w-full rounded-md border border-[#E5E7EB] bg-white px-3 py-2 text-[12px] text-[#111827] outline-none focus:border-[#22C55E] dark:border-[#27272a] dark:bg-[#111113] dark:text-[#E5E5E5]"})]})]},N)),l&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:l}),e.jsxs("button",{type:"button",onClick:()=>void w(),disabled:m||!p,className:"inline-flex min-h-8 items-center gap-1.5 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:[m&&e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}),a("interaction.question.submit")]})]})}function Zs({message:t}){const s=t.agentContent,a=v(p=>{var w;return p.isStreaming&&!!(p.currentAssistantMessageId&&(((w=t.displaySourceMessageIds)==null?void 0:w.includes(p.currentAssistantMessageId))??p.currentAssistantMessageId===t.id))});if(!s){const p=Ue(t.content);return p?e.jsx(We,{content:p}):null}const{toolCalls:r,tasks:i,confirmation:n,question:c,elicitation:m}=s,x=ht(s),l=Kt(ge(s));if(!(l.length>0||i.length>0||x.length>0||n||c||m)&&a)return e.jsxs("div",{className:"flex items-center gap-2 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(U,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-[12px] font-mono",children:"Thinking..."})]});const u=r.length>0&&r.every(p=>p.status==="success"||p.status==="error")&&!a,g=!a;return e.jsxs("div",{className:"space-y-3",children:[l.map(p=>p.type==="thinking"?e.jsx("div",{"data-agent-timeline-block":"thinking",children:e.jsx(Qs,{content:p.content})},p.id):p.type==="text"?e.jsx("div",{"data-agent-timeline-block":"text",children:e.jsx(We,{content:p.content,syntaxHighlight:g})},p.id):e.jsx("div",{"data-agent-timeline-block":"tool_group",children:e.jsx(qs,{toolCalls:r,toolCallIds:p.toolCallIds})},p.id)),i.length>0&&e.jsx(Gs,{tasks:i}),x.map(p=>e.jsx(Js,{subagent:p},p.id)),n&&e.jsx(Ys,{confirmation:n,messageId:t.id}),c&&e.jsx(Xs,{question:c,messageId:t.id}),m&&e.jsx(Ms,{elicitation:m,messageId:t.id}),u&&e.jsx(Ws,{toolCalls:r})]})}function ea({message:t,showAvatar:s=!0}){var x,l,b,k;const a=_(),r=t.role==="user";if(t.role==="system"){const u=Ue(t.content);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"system",className:"flex justify-center p-2 w-full",children:e.jsx("div",{className:"text-xs text-[hsl(var(--deck-ink-muted))] bg-[#F3F4F6] dark:bg-[#18181b] px-3 py-1 rounded-full font-mono",children:u})})}if(r){const u=(x=t.metadata)!=null&&x.userShellCommand&&typeof t.metadata.userShellCommand=="object"?t.metadata.userShellCommand:(l=t.metadata)!=null&&l.userShellExecution&&typeof t.metadata.userShellExecution=="object"?t.metadata.userShellExecution:void 0;if(u){const d=typeof u.command=="string"?u.command:"",N=u.status==="running"?"running":u.status==="completed"?"success":"error",f=typeof u.output=="string"?u.output:[typeof u.stdout=="string"?u.stdout:"",typeof u.stderr=="string"&&u.stderr?`stderr:
67
+ `,e.jsx("span",{"data-tool-truncation-notice":!0,children:i.notice})]})]})]})]})]})}function vt({toolCalls:t}){return t.length===0?null:e.jsx("div",{className:"space-y-2",children:t.map(s=>e.jsx(zs,{tool:s},s.toolCallId))})}function qs({toolCalls:t,toolCallIds:s}){const a=_(),[r,i]=h.useState(!1),n=h.useMemo(()=>new Map(t.map(k=>[k.toolCallId,k])),[t]),c=s.flatMap(k=>{const u=n.get(k);return u?[u]:[]});if(c.length===0)return null;const m=c.filter(k=>k.status==="running").length,x=c.filter(k=>k.status==="error").length,l=[...c].reverse().find(k=>k.status==="running"&&!!k.progressMessage),b=m>0?a(c.length===1?"chat.timeline.tools.runningOne":"chat.timeline.tools.running",{count:c.length}):x>0?a(c.length===1?"chat.timeline.tools.completedOneWithError":"chat.timeline.tools.completedWithErrors",{count:c.length,errors:x}):a(c.length===1?"chat.timeline.tools.completedOne":"chat.timeline.tools.completed",{count:c.length});return e.jsxs("div",{"data-agent-tool-group":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>i(k=>!k),className:"group flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[r?e.jsx(he,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(ce,{className:"h-3.5 w-3.5 shrink-0"}),m>0&&e.jsx(U,{className:"h-3 w-3 shrink-0 animate-spin text-[hsl(var(--deck-accent))]"}),e.jsx("span",{children:b}),(l==null?void 0:l.progressMessage)&&e.jsxs("span",{className:"min-w-0 truncate text-[10.5px] text-[hsl(var(--deck-ink-muted))]",children:[l.progressMessage,l.progress!==void 0&&l.progressTotal!==void 0&&` · ${Math.max(0,Math.min(100,Math.round(l.progress/l.progressTotal*100)))}%`]})]}),(l==null?void 0:l.progress)!==void 0&&l.progressTotal!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${l.toolName} progress`,"aria-valuemin":0,"aria-valuemax":l.progressTotal,"aria-valuenow":Math.min(l.progress,l.progressTotal),className:"mx-1.5 h-0.5 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,l.progress/l.progressTotal*100))}%`}})}),r&&e.jsx("div",{"data-agent-tool-group-details":!0,className:"pl-1 mt-2 space-y-2",children:e.jsx(vt,{toolCalls:c})})]})}function Qs({content:t}){const s=_(),[a,r]=h.useState(!1);return t?e.jsxs("div",{"data-agent-thinking":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>r(i=>!i),className:"flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[a?e.jsx(he,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}):e.jsx(ce,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{children:s("chat.timeline.thinking")})]}),a&&e.jsx("div",{className:"ml-1 mt-1 border-l border-[hsl(var(--deck-border))] py-1 pl-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:t})})]}):null}function Gs({tasks:t}){if(t.length===0)return null;const s=t.filter(r=>r.status==="completed").length,a=s===t.length;return e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"flex gap-2 items-center",children:e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:a?"✓ All tasks done":`Tasks: ${s}/${t.length}`})})})}function Ws({toolCalls:t}){const s=_e(n=>n.openFilePreview),a=v(n=>oe(n.historySurfaceSelection)),r=h.useMemo(()=>{const n=new Map,c=["Write","SearchReplace","Edit","ApplyPatch"];for(const m of t){if(m.status!=="success")continue;const x=m.metadata;if(m.toolName==="ApplyPatch"&&Array.isArray(x==null?void 0:x.changes)){for(const b of x.changes)b&&typeof b=="object"&&"path"in b&&typeof b.path=="string"&&n.set(b.path,{path:b.path,toolName:m.toolName});continue}const l=x==null?void 0:x.file_path;l&&c.includes(m.toolName)&&n.set(l,{path:l,toolName:m.toolName})}return Array.from(n.values())},[t]);if(a||r.length===0)return null;const i=n=>{q(v.getState())||s({tab:"diff",targetPath:n})};return e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono mb-1.5",children:["Changed files (",r.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map(({path:n})=>{const c=n.split("/").pop()||n;return e.jsxs("button",{onClick:()=>i(n),className:"flex items-center gap-1 px-2 py-1 text-[11px] font-mono bg-[#E5E7EB] dark:bg-[#27272a] text-[hsl(var(--deck-ink))] rounded hover:bg-[#D1D5DB] dark:hover:bg-[#3f3f46] transition-colors",title:n,children:[e.jsx(Mt,{className:"w-3 h-3"}),c]},n)})})]})}function Js({subagent:t}){var A,D,G,ee;const s=_(),[a,r]=h.useState(null),[i,n]=h.useState(!1),[c,m]=h.useState(null),[x,l]=h.useState(!1),[b,k]=h.useState(""),[u,g]=h.useState(!1),[p,w]=h.useState(null),[d,N]=h.useState(null),[f,S]=h.useState(null),o=v(F=>F.currentSessionRef),T=v(F=>F.isStreaming),I=v(F=>F.isTemporarySession),R=v(F=>oe(F.historySurfaceSelection));if(!t)return null;const j=t.status==="running",V=a!==null?a:j,X=t.toolCalls||c||[],E=t.output||t.thinking||X.length>0||t.sessionId,B=d&&d.status!=="running"?d:f,O=(B==null?void 0:B.id)??t.sessionId,P=((A=B==null?void 0:B.restartRecovery)==null?void 0:A.outcome)==="failed",C=!j&&!T&&!I&&!R&&!P&&(d==null?void 0:d.status)!=="running"&&!!(O&&o);h.useEffect(()=>{if(R||!V||j||!t.sessionId||!(o!=null&&o.projectPath)||c!==null||t.toolCalls&&t.toolCalls.length>0)return;let F=!0;return n(!0),re.getMessages({sessionId:t.sessionId,projectPath:o.projectPath}).then(W=>{var z,K;if(!F)return;const J=Vt(W),Q=new Map;for(const Y of J)if((K=(z=Y.agentContent)==null?void 0:z.toolCalls)!=null&&K.length)for(const te of Y.agentContent.toolCalls)Q.has(te.toolCallId)||Q.set(te.toolCallId,te);m(Array.from(Q.values()))}).finally(()=>{F&&n(!1)}),()=>{F=!1}},[V,R,j,t.sessionId,t.toolCalls,c,o==null?void 0:o.projectPath]),h.useEffect(()=>{if(R||!t.sessionId||!o)return;let F=!0;const W=t.rootAgentId??t.sessionId,J=t.resumeDepth??0;return re.listSubagents(o).then(Q=>{if(!F)return;S(Q.find(K=>K.id===t.sessionId)??null);const z=Q.filter(K=>K.id!==t.sessionId&&K.rootAgentId===W&&K.resumeDepth>J).sort((K,Y)=>Y.resumeDepth-K.resumeDepth||Y.lastActiveAt-K.lastActiveAt)[0];z&&N(z)}).catch(()=>{}),()=>{F=!1}},[o==null?void 0:o.sessionId,o==null?void 0:o.projectPath,R,t.sessionId,t.rootAgentId,t.resumeDepth]),h.useEffect(()=>{if(R||!d||d.status!=="running"||!o)return;let F=!0;const W=async()=>{try{const z=(await re.listSubagents(o)).find(K=>K.id===d.id);F&&z&&N(z)}catch{}},J=window.setInterval(()=>{W()},1e3);return()=>{F=!1,window.clearInterval(J)}},[o,R,d==null?void 0:d.id,d==null?void 0:d.status]);const M=async()=>{if(!q(v.getState())&&!(!o||!O||!b.trim()||u)){g(!0),w(null);try{const F=await re.resumeSubagent(o,O,b.trim());N(F.session),k(""),l(!1),r(!0)}catch(F){w(F instanceof Error?F.message:s("chat.subagent.resumeFailed"))}finally{g(!1)}}};return e.jsxs("div",{"data-subagent-id":t.id,"data-subagent-session-id":t.sessionId,className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>r(!V),className:"flex gap-2 justify-between items-center w-full transition-opacity cursor-pointer hover:opacity-80",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[j&&e.jsx(U,{className:"h-3 w-3 animate-spin text-[hsl(var(--deck-ink-muted))]"}),e.jsxs("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[t.type,": ",t.description]}),e.jsx(Ke,{status:t.status==="completed"?"success":t.status==="failed"?"error":"running"}),t.type==="verification"&&t.verificationVerdict&&e.jsx("span",{"data-verification-verdict":t.verificationVerdict,className:L("rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide",t.verificationVerdict==="pass"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":t.verificationVerdict==="fail"?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"),children:t.verificationVerdict}),t.resumedFrom&&e.jsx("span",{className:"rounded bg-[#EDE9FE] px-1.5 py-0.5 text-[10px] font-mono text-[#6D28D9] dark:bg-[#2E1065] dark:text-[#C4B5FD]",title:s("chat.subagent.resumedFromTitle",{id:t.resumedFrom}),children:s("chat.subagent.resumedDepth",{depth:t.resumeDepth??1})})]}),E&&e.jsx(he,{className:L("h-3.5 w-3.5 text-[hsl(var(--deck-ink-muted))] transition-transform",V&&"rotate-180")})]}),!V&&!j&&t.output&&e.jsx("div",{"data-subagent-output-summary":!0,className:"mt-2 max-h-10 overflow-hidden whitespace-pre-wrap break-words font-mono text-[11px] text-[hsl(var(--deck-ink))]",children:t.output}),V&&e.jsxs("div",{className:"mt-2 space-y-2",children:[(t.output||t.thinking)&&e.jsxs(e.Fragment,{children:[t.output&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[160px] overflow-y-auto",children:t.output}),t.thinking&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:t.thinking})]}),i&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[e.jsx(U,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.loadingLogs")]}),!i&&X.length>0&&e.jsx(vt,{toolCalls:X}),d&&e.jsxs("div",{className:"rounded-md border border-[#DDD6FE] bg-[#F5F3FF] p-2 text-[11px] font-mono text-[#5B21B6] dark:border-[#4C1D95] dark:bg-[#1E1B4B] dark:text-[#C4B5FD]",children:[e.jsx("div",{children:s("chat.subagent.resumedAs",{id:d.id,status:d.status,depth:d.resumeDepth??1})}),(((D=d.result)==null?void 0:D.message)||((G=d.result)==null?void 0:G.error))&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap text-[hsl(var(--deck-ink))]",children:d.result.message||d.result.error})]}),P&&((ee=B==null?void 0:B.result)==null?void 0:ee.error)&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:B.result.error}),C&&e.jsxs("div",{className:"space-y-2",children:[x?e.jsxs("div",{className:"space-y-2 rounded-md border border-[#E5E7EB] bg-white p-2 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsx("textarea",{"aria-label":s("chat.subagent.followUpAria"),value:b,onChange:F=>k(F.target.value),placeholder:s("chat.subagent.followUpPlaceholder"),rows:3,className:"w-full resize-y rounded border border-[#D1D5DB] bg-white p-2 text-[11px] text-[#111827] outline-none focus:border-[#8B5CF6] dark:border-[#3f3f46] dark:bg-[#18181b] dark:text-[#f4f4f5]"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>{l(!1),w(null)},className:"rounded px-2 py-1 text-[11px] text-[#6B7280] hover:bg-[#F3F4F6] dark:hover:bg-[#27272a]",children:s("chat.subagent.cancel")}),e.jsxs("button",{type:"button",onClick:()=>void M(),disabled:!b.trim()||u,className:"flex items-center gap-1 rounded bg-[#7C3AED] px-2 py-1 text-[11px] font-medium text-white disabled:opacity-50",children:[u&&e.jsx(U,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.resumeAgent")]})]})]}):e.jsxs("button",{type:"button","aria-label":s("chat.subagent.resumeAria"),onClick:()=>l(!0),className:"flex items-center gap-1.5 rounded-md border border-[#D1D5DB] px-2 py-1 text-[11px] font-medium text-[#374151] transition-colors hover:bg-[#F3F4F6] dark:border-[#3f3f46] dark:text-[#d4d4d8] dark:hover:bg-[#27272a]",children:[e.jsx(ve,{className:"w-3 h-3"}),s("chat.subagent.resume")]}),p&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:p})]})]})]})}function Ys({confirmation:t,messageId:s}){const a=_(),[r,i]=h.useState(!1),[n,c]=h.useState(null),m=v(b=>b.currentSessionRef),x=v(b=>b.setConfirmation);if(!t)return null;const l=async(b,k)=>{if(!q(v.getState())&&!(!m||r)){i(!0),c(null);try{await re.respondPermission(m,t.toolCallId,{approved:b,scope:k}),x(s,{...t,status:b?"approved":"denied"})}catch(u){c(u instanceof Error?u.message:a("interaction.permission.failed"))}finally{i(!1)}}};return t.status!=="pending"?null:e.jsxs("div",{"data-pending-interaction":"permission",tabIndex:-1,role:"alert",className:"p-4 space-y-3 rounded-lg border outline-none border-amber-300/70 bg-amber-50/70 focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:a("interaction.permission.title",{tool:t.toolName})}),e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:t.description}),t.diff&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[200px] overflow-y-auto",children:t.diff}),n&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:n}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"once"),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:r?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}):a("interaction.permission.once")}),t.allowRemember!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"session"),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#3B82F6] text-white rounded-md hover:bg-[#2563EB] disabled:cursor-wait disabled:opacity-50",children:a("interaction.permission.session")}),e.jsx("button",{type:"button",onClick:()=>void l(!0,"project"),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#6366F1] text-white rounded-md hover:bg-[#4F46E5] disabled:cursor-wait disabled:opacity-50",children:a("interaction.permission.project")})]}),e.jsx("button",{type:"button",onClick:()=>void l(!1),disabled:r,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#EF4444] text-white rounded-md hover:bg-[#DC2626] disabled:cursor-wait disabled:opacity-50",children:a("interaction.permission.deny")})]})]})}function Xs({question:t,messageId:s}){const a=_(),[r,i]=h.useState({}),[n,c]=h.useState({}),[m,x]=h.useState(!1),[l,b]=h.useState(null),k=v(d=>d.currentSessionRef),u=v(d=>d.setQuestion),g=h.useMemo(()=>t?t.questions.reduce((d,N)=>{var T;const f=(T=n[N.header])==null?void 0:T.trim(),S=r[N.header];if(N.multiSelect){const I=Array.isArray(S)?[...S]:[];return f&&I.push(f),I.length>0&&(d[N.header]=I),d}const o=f||(typeof S=="string"?S:"");return o&&(d[N.header]=o),d},{}):{},[r,n,t]),p=(t==null?void 0:t.questions.every(d=>d.header in g))??!1;if(!t)return null;const w=async()=>{if(!q(v.getState())&&!(!k||m||!p)){x(!0),b(null);try{await re.respondToQuestion(k,t.toolCallId,g),u(s,{...t,status:"answered",answers:g})}catch(d){b(d instanceof Error?d.message:a("interaction.question.failed"))}finally{x(!1)}}};return t.status!=="pending"?e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:a("interaction.question.answered")})}):e.jsxs("div",{"data-pending-interaction":"question",tabIndex:-1,role:"alert",className:"p-4 space-y-4 rounded-lg border outline-none border-amber-300/70 bg-amber-50/70 focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[t.questions.map((d,N)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:d.question}),e.jsxs("div",{className:"space-y-1",children:[d.options.map((f,S)=>e.jsxs("button",{type:"button",onClick:()=>{if(d.multiSelect){const o=r[d.header]||[],T=o.includes(f.label)?o.filter(I=>I!==f.label):[...o,f.label];i({...r,[d.header]:T})}else i({...r,[d.header]:f.label}),c({...n,[d.header]:""})},className:L("w-full text-left px-3 py-2 rounded-md border text-[12px] font-mono transition-colors","border-[hsl(var(--deck-border))]",(d.multiSelect?(r[d.header]||[]).includes(f.label):r[d.header]===f.label)?"bg-[#DCFCE7] text-[#166534] dark:bg-[#22C55E]/20 dark:text-[#E5E5E5]":"bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))]"),children:[e.jsx("div",{children:f.label}),e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-faint))] mt-1",children:f.description})]},S)),e.jsx("input",{"aria-label":`${d.header} other response`,value:n[d.header]??"",onChange:f=>c({...n,[d.header]:f.target.value}),placeholder:a("interaction.question.other"),className:"w-full rounded-md border border-[#E5E7EB] bg-white px-3 py-2 text-[12px] text-[#111827] outline-none focus:border-[#22C55E] dark:border-[#27272a] dark:bg-[#111113] dark:text-[#E5E5E5]"})]})]},N)),l&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:l}),e.jsxs("button",{type:"button",onClick:()=>void w(),disabled:m||!p,className:"inline-flex min-h-8 items-center gap-1.5 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:[m&&e.jsx(U,{className:"h-3.5 w-3.5 animate-spin"}),a("interaction.question.submit")]})]})}function Zs({message:t}){const s=t.agentContent,a=v(p=>{var w;return p.isStreaming&&!!(p.currentAssistantMessageId&&(((w=t.displaySourceMessageIds)==null?void 0:w.includes(p.currentAssistantMessageId))??p.currentAssistantMessageId===t.id))});if(!s){const p=Ue(t.content);return p?e.jsx(We,{content:p}):null}const{toolCalls:r,tasks:i,confirmation:n,question:c,elicitation:m}=s,x=ht(s),l=Kt(ge(s));if(!(l.length>0||i.length>0||x.length>0||n||c||m)&&a)return e.jsxs("div",{className:"flex items-center gap-2 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(U,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-[12px] font-mono",children:"Thinking..."})]});const u=r.length>0&&r.every(p=>p.status==="success"||p.status==="error")&&!a,g=!a;return e.jsxs("div",{className:"space-y-3",children:[l.map(p=>p.type==="thinking"?e.jsx("div",{"data-agent-timeline-block":"thinking",children:e.jsx(Qs,{content:p.content})},p.id):p.type==="text"?e.jsx("div",{"data-agent-timeline-block":"text",children:e.jsx(We,{content:p.content,syntaxHighlight:g})},p.id):e.jsx("div",{"data-agent-timeline-block":"tool_group",children:e.jsx(qs,{toolCalls:r,toolCallIds:p.toolCallIds})},p.id)),i.length>0&&e.jsx(Gs,{tasks:i}),x.map(p=>e.jsx(Js,{subagent:p},p.id)),n&&e.jsx(Ys,{confirmation:n,messageId:t.id}),c&&e.jsx(Xs,{question:c,messageId:t.id}),m&&e.jsx(Ms,{elicitation:m,messageId:t.id}),u&&e.jsx(Ws,{toolCalls:r})]})}function ea({message:t,showAvatar:s=!0}){var x,l,b,k;const a=_(),r=t.role==="user";if(t.role==="system"){const u=Ue(t.content);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"system",className:"flex justify-center p-2 w-full",children:e.jsx("div",{className:"text-xs text-[hsl(var(--deck-ink-muted))] bg-[#F3F4F6] dark:bg-[#18181b] px-3 py-1 rounded-full font-mono",children:u})})}if(r){const u=(x=t.metadata)!=null&&x.userShellCommand&&typeof t.metadata.userShellCommand=="object"?t.metadata.userShellCommand:(l=t.metadata)!=null&&l.userShellExecution&&typeof t.metadata.userShellExecution=="object"?t.metadata.userShellExecution:void 0;if(u){const d=typeof u.command=="string"?u.command:"",N=u.status==="running"?"running":u.status==="completed"?"success":"error",f=typeof u.output=="string"?u.output:[typeof u.stdout=="string"?u.stdout:"",typeof u.stderr=="string"&&u.stderr?`stderr:
68
68
  ${u.stderr}`:""].filter(Boolean).join(`
69
- `);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"user","data-user-shell-command":!0,className:"flex justify-end p-4 w-full",children:e.jsxs("div",{className:"w-full max-w-[85%] overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 truncate font-mono text-[12px] text-[hsl(var(--deck-ink))]",children:[e.jsx("span",{className:"mr-2 text-amber-600 dark:text-amber-400",children:"$"}),d]}),e.jsx(Ke,{status:N})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:f||"(no output)"}),typeof u.exitCode=="number"&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-1.5 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:["exit ",u.exitCode,typeof u.durationMs=="number"?` · ${(u.durationMs/1e3).toFixed(3)}s`:"",u.truncated===!0?" · truncated":""]})]})})}const{text:g,images:p}=Us(t.content),w=Et(t.metadata);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"user",className:"flex gap-2 justify-end items-start p-4 w-full group",children:[e.jsx("div",{className:"flex mt-1 opacity-0 transition-opacity shrink-0 group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(Qe,{text:g,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[w.length>0&&e.jsxs("details",{"data-user-message-annotations":!0,className:"mb-2",children:[e.jsxs("summary",{className:"inline-flex min-h-7 cursor-pointer list-none items-center gap-1.5 rounded-md border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))] px-2.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(ct,{"aria-hidden":!0,className:"h-3.5 w-3.5"}),a(w.length===1?"chat.input.annotation.one":"chat.input.annotation.many",{count:w.length})]}),e.jsx("div",{className:"mt-2 space-y-2",children:w.map((d,N)=>e.jsxs("div",{className:"border-l-2 border-[hsl(var(--deck-accent)/0.45)] pl-2",children:[e.jsx("div",{className:"font-mono text-[9.5px] uppercase text-[hsl(var(--deck-ink-faint))]",children:a("chat.input.annotation.item",{index:N+1})}),e.jsx("blockquote",{className:"mt-0.5 whitespace-pre-wrap text-[11px] leading-4 text-[hsl(var(--deck-ink-muted))]",children:d.text}),d.comment&&e.jsx("p",{className:"mt-1 text-[11px] leading-4 text-[hsl(var(--deck-ink))]",children:d.comment})]},d.id))})]}),g&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:g}),p.length>0&&e.jsx("div",{className:L("grid gap-2",p.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:p.map((d,N)=>e.jsx("img",{src:d,alt:`attachment-${N+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${d}-${N}`))})]}),e.jsx(Os,{})]})}const n=Ks(t),c=Cs((b=t.metadata)==null?void 0:b.codeReview),m=Bs((k=t.metadata)==null?void 0:k.structuredOutput);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"assistant",className:L("flex gap-4 justify-start w-full group",s?"p-4":"px-4 pt-0 pb-3"),children:[s?e.jsx(_s,{}):e.jsx("div",{className:"w-8 shrink-0"}),e.jsxs("div",{className:"overflow-hidden flex-1 min-w-0",children:[c?e.jsx(Es,{report:c}):m?e.jsx($s,{report:m}):e.jsx(Zs,{message:t}),!m&&n.trim()&&e.jsx("div",{className:"mt-1.5 flex opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(Qe,{text:n,label:"Copy response"})})]})]})}const ta=h.memo(ea),pe=8,Xe=10;function sa(t){return t instanceof HTMLElement&&!!t.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')}function aa(){const t=window.visualViewport;return{left:(t==null?void 0:t.offsetLeft)??0,top:(t==null?void 0:t.offsetTop)??0,width:(t==null?void 0:t.width)??window.innerWidth,height:(t==null?void 0:t.height)??window.innerHeight}}function ra(t,s,a){const r=aa(),i=r.left+pe,n=r.left+r.width-s-pe,c=t.left+t.width/2-s/2,m=Math.max(i,Math.min(Math.max(i,n),c)),x=t.bottom+Xe,l=t.top-a-Xe,b=r.top+r.height-a-pe,k=x<=b?x:Math.max(r.top+pe,Math.min(b,l));return{left:m,top:k}}function na({rootRef:t,draftKey:s,canAskSideConversation:a,onOpenSideConversation:r}){const i=_(),n=h.useRef(null),c=h.useRef(null),m=h.useRef(!1),x=h.useRef("actions"),[l,b]=h.useState(null),[k,u]=h.useState("actions"),[g,p]=h.useState(""),[w,d]=h.useState(null),N=h.useCallback(T=>{m.current=!1,x.current=T,u(T),p("")},[]),f=h.useCallback(()=>{var T;m.current=!1,x.current="actions",u("actions"),p(""),b(null),d(null),(T=window.getSelection())==null||T.removeAllRanges()},[]),S=h.useCallback(T=>{var C,M;if(!l||l.tooLarge)return;const B=((M=(C=globalThis.crypto)==null?void 0:C.randomUUID)==null?void 0:M.call(C))??`selection-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,O=T==null?void 0:T.trim();At(s,{id:B,text:l.text,sourceMessageId:l.messageId,sourceRole:l.role,...O?{comment:O}:{}})&&f()},[f,s,l]),o=h.useCallback(()=>{!l||l.tooLarge||!a||r(l.text)&&f()},[a,f,r,l]),E=h.useCallback(()=>{if(x.current!=="actions")return;const T=t.current;if(!T)return;const B=Rt(T,window.getSelection());b(B),d(null)},[t]);if(h.useEffect(()=>{var M;let T=0;const B=()=>{window.cancelAnimationFrame(T),T=window.requestAnimationFrame(E)},O=A=>{var D;(D=n.current)!=null&&D.contains(A.target)||l&&(m.current=!1,x.current="actions",u("actions"),p(""),b(null))},P=A=>{var D;(D=n.current)!=null&&D.contains(A.target)||f()},C=A=>{if(!(!l||m.current||A.isComposing||A.keyCode===229)){if(A.key==="Escape"){A.preventDefault(),f();return}if(!(x.current!=="actions"||sa(A.target))){if((A.metaKey||A.ctrlKey)&&A.key.toLowerCase()==="j"){A.preventDefault(),N("comment");return}A.key==="Enter"&&(A.preventDefault(),S())}}};return document.addEventListener("selectionchange",B),document.addEventListener("pointerup",B),document.addEventListener("pointerdown",O),document.addEventListener("keydown",C),document.addEventListener("scroll",P,!0),window.addEventListener("resize",f),(M=window.visualViewport)==null||M.addEventListener("resize",f),()=>{var A;window.cancelAnimationFrame(T),document.removeEventListener("selectionchange",B),document.removeEventListener("pointerup",B),document.removeEventListener("pointerdown",O),document.removeEventListener("keydown",C),document.removeEventListener("scroll",P,!0),window.removeEventListener("resize",f),(A=window.visualViewport)==null||A.removeEventListener("resize",f)}},[S,E,f,l,N]),h.useLayoutEffect(()=>{if(!l||!n.current)return;const T=n.current.getBoundingClientRect();d(ra(l.rect,T.width,T.height))},[k,l]),h.useEffect(()=>{k!=="actions"&&requestAnimationFrame(()=>{var T;return(T=c.current)==null?void 0:T.focus()})},[k]),!l||typeof document>"u")return null;const R=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/u.test(navigator.userAgent)?"⌘ J":"Ctrl J",j=l.tooLarge?i("chat.selection.tooLarge"):a?void 0:i("chat.selection.sideUnavailable"),V={left:(w==null?void 0:w.left)??0,top:(w==null?void 0:w.top)??0,visibility:w?"visible":"hidden"},X=T=>{if(!(m.current||T.nativeEvent.isComposing||T.keyCode===229)){if((T.metaKey||T.ctrlKey)&&T.key.toLocaleLowerCase()==="a"){T.preventDefault(),T.stopPropagation(),T.currentTarget.select();return}if(T.key==="Escape"){T.preventDefault(),f();return}T.key!=="Enter"||T.shiftKey||(T.preventDefault(),S(g))}};return jt.createPortal(e.jsx("div",{ref:n,"data-chat-selection-overlay":!0,style:V,className:"fixed z-50 max-w-[calc(100vw-1rem)]",onPointerDown:T=>T.stopPropagation(),onPointerUp:T=>T.stopPropagation(),children:k==="actions"?e.jsxs("div",{role:"toolbar","aria-label":i("chat.selection.toolbar"),className:"grid min-w-[250px] overflow-hidden rounded-lg border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/98 text-[hsl(var(--deck-ink))] shadow-xl backdrop-blur-md divide-y divide-[hsl(var(--deck-border))] sm:flex sm:min-w-0 sm:divide-x sm:divide-y-0",onPointerDown:T=>T.preventDefault(),children:[e.jsxs("button",{type:"button","aria-keyshortcuts":"Meta+J Control+J",disabled:l.tooLarge,onClick:()=>N("comment"),className:"flex min-h-11 items-center gap-2 whitespace-nowrap px-3 text-left text-[12px] transition-colors hover:bg-[hsl(var(--deck-surface-2))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))] disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(ct,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:i("chat.selection.comment")}),e.jsx("kbd",{className:"ml-auto font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:R})]}),e.jsxs("button",{type:"button","aria-keyshortcuts":"Enter",disabled:l.tooLarge,onClick:()=>S(),className:"flex min-h-11 items-center gap-2 whitespace-nowrap px-3 text-left text-[12px] transition-colors hover:bg-[hsl(var(--deck-surface-2))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))] disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(Jt,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:i("chat.selection.add")}),e.jsx("kbd",{className:"ml-auto font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:"↵"})]}),e.jsxs("button",{type:"button",disabled:!!j,title:j,onClick:o,className:"flex min-h-11 items-center gap-2 whitespace-nowrap px-3 text-left text-[12px] transition-colors hover:bg-[hsl(var(--deck-surface-2))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))] disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(De,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:i("chat.selection.askSide")})]})]}):e.jsxs("form",{role:"dialog","aria-label":i("chat.selection.commentDialog"),className:"w-[min(360px,calc(100vw-1rem))] rounded-lg border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))] p-2 shadow-xl",onSubmit:T=>{T.preventDefault(),S(g)},children:[e.jsx("div",{className:"mb-2 line-clamp-2 border-l-2 border-[hsl(var(--deck-accent)/0.55)] pl-2 font-mono text-[10.5px] leading-4 text-[hsl(var(--deck-ink-muted))]",children:l.text}),e.jsx("textarea",{ref:c,name:"selected-conversation-comment",maxLength:Ht,rows:3,value:g,onChange:T=>p(T.target.value),onCompositionStart:()=>{m.current=!0},onCompositionEnd:()=>{m.current=!1},onBlur:()=>{m.current=!1},onKeyDown:X,"aria-label":i("chat.selection.commentInput"),placeholder:i("chat.selection.commentPlaceholder"),className:"block max-h-32 min-h-[72px] w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-2.5 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] placeholder:text-[hsl(var(--deck-ink-faint))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:f,className:"h-8 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-surface-2))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:i("chat.selection.cancel")}),e.jsxs("button",{type:"submit",className:"inline-flex h-8 items-center gap-1.5 rounded-md bg-[hsl(var(--deck-accent))] px-3 text-[11px] font-medium text-white transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[hsl(var(--deck-accent))] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-45",children:[i("chat.selection.add"),e.jsx(is,{"aria-hidden":!0,className:"h-3 w-3"})]})]})]})}),document.body)}function ia(t,s,a){return Math.max(0,t+(a-s))}function oa(t,s,a){return Math.min(s,Math.max(0,t)+Math.max(0,a))}function ca(t,s,a,r){const i=new Map(t.filter(c=>!!c.id).map(c=>[c.id,c])),n=new Set(a);for(const c of s){if(!c.id)continue;const m=i.get(c.id);m!==c&&(!m||!r||r(m)!==r(c))&&n.add(c.id)}return n}function Ze(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function la({turns:t,viewportRef:s,containerRef:a,onRevealTurn:r}){const i=_(),[n,c]=h.useState(null),[m,x]=h.useState(!1),l=h.useRef(null),b=h.useCallback(()=>{var d;const u=s.current,g=a.current;if(!u||!g||t.length===0)return;const p=u.getBoundingClientRect().top;let w=((d=t[0])==null?void 0:d.id)??null;for(const N of t){const f=Ze(g,N.id);if(f)if(f.getBoundingClientRect().top-p<=24)w=N.id;else break}c(w)},[t,s,a]);h.useEffect(()=>{const u=s.current;if(!u)return;const g=()=>{l.current===null&&(l.current=window.requestAnimationFrame(()=>{l.current=null,b()}))};return b(),u.addEventListener("scroll",g,{passive:!0}),()=>{u.removeEventListener("scroll",g),l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null)}},[b,s]);const k=h.useCallback(u=>{const g=()=>{const w=Ze(a.current,u.id);w&&(w.scrollIntoView({behavior:"smooth",block:"start"}),c(u.id))};r(u.index)?g():window.requestAnimationFrame(()=>window.requestAnimationFrame(g))},[a,r]);return t.length<2?null:e.jsx("nav",{"aria-label":i("chat.turns.aria"),className:"absolute right-1 top-1/2 z-20 hidden -translate-y-1/2 sm:block",onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),onFocusCapture:()=>x(!0),onBlurCapture:u=>{u.currentTarget.contains(u.relatedTarget)||x(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:L("flex flex-col items-center gap-2 py-2 transition-opacity",m?"opacity-0":"opacity-100"),"aria-hidden":m,children:t.map(u=>e.jsx("li",{children:e.jsx("span",{className:L("block rounded-full transition-all",u.id===n?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},u.id))}),e.jsx("div",{className:L("absolute right-0 max-h-[min(70vh,520px)] w-[280px] overflow-y-auto rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/95 p-1 shadow-xl backdrop-blur transition-all",m?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((u,g)=>e.jsxs("button",{type:"button",onClick:()=>k(u),className:L("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u.id===n?"bg-[hsl(var(--deck-hairline))]/70 text-[hsl(var(--deck-ink))]":"text-[hsl(var(--deck-ink-muted))] hover:bg-[hsl(var(--deck-hairline))]/50 hover:text-[hsl(var(--deck-ink))]"),children:[e.jsx("span",{className:L("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",u.id===n?"bg-[hsl(var(--deck-accent))]":"bg-[hsl(var(--deck-ink-faint))]/40")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[9.5px] uppercase tracking-[0.12em] text-[hsl(var(--deck-ink-faint))]",children:i("chat.turns.label",{n:g+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:u.preview})]})]},u.id))})]})})}const et=80;function da(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ua(t){const s=da(t).replace(/\s+/g," ").trim();return s?s.length>et?`${s.slice(0,et-1)}…`:s:""}function ma(t){const s=[];for(let a=0;a<t.length;a+=1){const r=t[a];if(r.role!=="user"||!r.id)continue;const i=ua(r.content);i&&s.push({id:r.id,index:a,preview:i})}return s}const Te=120,Ee=80,ha=96;function de(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function xa(t){return JSON.stringify([t.role,t.content,t.metadata,t.agentContent])}function pa({messages:t,isLoading:s,selectionDraftKey:a,canAskSideConversation:r=!1,onOpenSideConversation:i}){const n=_(),c=h.useMemo(()=>ys(t),[t]),m=h.useRef(null),x=h.useRef(null),l=h.useRef(!0),b=h.useRef(!1),k=h.useRef(c),u=h.useRef(c),g=h.useRef(new Set),p=h.useRef(c.length),w=h.useRef(null),[d,N]=h.useState(Te),[f,S]=h.useState(!1),[o,E]=h.useState(0),I=c.length>0;k.current=c,h.useEffect(()=>{const C=de(m.current);if(!C||b.current&&!l.current)return;const M=window.requestAnimationFrame(()=>{C.scrollTop=C.scrollHeight,b.current=!0,l.current=!0,g.current=new Set,E(0),S(!1)});return()=>window.cancelAnimationFrame(M)},[c]),h.useEffect(()=>{const C=de(m.current);if(!C)return;x.current=C;const M=()=>{if(!b.current)return;const D=C.scrollHeight-C.scrollTop-C.clientHeight<=ha,G=l.current;l.current=D,S(!D),D?(g.current=new Set,E(0)):G&&(u.current=k.current,g.current=new Set,E(0))};return M(),C.addEventListener("scroll",M,{passive:!0}),()=>C.removeEventListener("scroll",M)},[I,s]),h.useEffect(()=>{const C=u.current;if(u.current=c,l.current){g.current.size>0&&(g.current=new Set,E(0));return}const M=ca(C,c,g.current,xa);g.current=M,E(M.size)},[c]),h.useEffect(()=>{const C=p.current;p.current=c.length,N(M=>M>=C&&c.length>C?c.length:Math.min(Math.max(M,Te),c.length||Te))},[c.length]);const R=Math.max(c.length-d,0),j=R,V=h.useMemo(()=>c.slice(j),[c,j]),X=h.useMemo(()=>ma(c),[c]);if(h.useLayoutEffect(()=>{var A;const C=w.current;if(!C)return;const M=de(m.current);if(w.current=null,!!M){if((A=C.element)!=null&&A.isConnected){const D=C.element.getBoundingClientRect().top-C.viewportTop;M.scrollTop+=D;return}M.scrollTop=ia(C.scrollTop,C.scrollHeight,M.scrollHeight)}},[d]),s)return e.jsx("div",{role:"status","aria-live":"polite","aria-busy":"true",className:"flex overflow-hidden flex-1 justify-center items-center px-5 py-8 min-h-0",children:e.jsxs("div",{className:"w-full max-w-[560px]",children:[e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 animate-pulse rounded-full bg-[hsl(var(--deck-accent-soft))] blur-xl"}),e.jsx(Re,{size:42,className:"relative"})]}),e.jsxs("div",{className:"mt-4 inline-flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--deck-accent))]",children:[e.jsx(Dt,{className:"w-3 h-3"}),n("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:n("chat.list.loading.title")}),e.jsx("p",{className:"mt-1 max-w-sm text-[11.5px] leading-5 text-[hsl(var(--deck-ink-faint))]",children:n("chat.list.loading.hint")})]}),e.jsx("div",{"aria-hidden":"true",className:"mt-7 space-y-4 rounded-xl border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))]/45 px-4 py-5",children:[72,88,64].map((C,M)=>e.jsxs("div",{className:L("flex gap-3",M%2===1&&"flex-row-reverse"),children:[e.jsx("span",{className:"h-7 w-7 shrink-0 animate-pulse rounded-md bg-[hsl(var(--deck-surface-2))]"}),e.jsx("span",{className:"h-10 animate-pulse rounded-lg bg-[hsl(var(--deck-surface-2))]",style:{width:`${C}%`,animationDelay:`${M*120}ms`}})]},C))})]})});if(c.length===0&&!s)return e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsxs("div",{className:"flex flex-col gap-4 items-center text-center",children:[e.jsx(Re,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:n("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:n("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:n("chat.list.empty.hint")})]})]})});const T=()=>{const C=de(m.current);C&&(C.scrollTop=C.scrollHeight,l.current=!0,b.current=!0,g.current=new Set,E(0),S(!1))},B=()=>{var M;const C=de(m.current);if(C){const A=((M=m.current)==null?void 0:M.querySelector("[data-chat-message-id]"))??null;w.current={element:A,viewportTop:(A==null?void 0:A.getBoundingClientRect().top)??0,scrollHeight:C.scrollHeight,scrollTop:C.scrollTop}}N(A=>oa(A,c.length,Ee))},O=C=>C>=j?!0:(N(c.length),!1),P=o===1?n("chat.list.unreadMessage"):n("chat.list.unreadMessages",{count:o});return e.jsxs("div",{ref:m,className:"relative flex-1 min-h-0",children:[e.jsx(Wt,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[R>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:B,"aria-label":n("chat.list.showEarlierWithRemaining",{count:Math.min(R,Ee),remaining:R}),className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-3 py-1.5 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:border-[hsl(var(--deck-border-strong))] hover:text-[hsl(var(--deck-ink))]",children:n("chat.list.showEarlier",{count:Math.min(R,Ee)})})}),V.map((C,M)=>{const A=j+M,D=A>0?c[A-1]:null,G=!D||D.role!==C.role||D.role==="user";return e.jsx(ta,{message:C,showAvatar:G},C.id||`msg-${A}`)})]})}),e.jsx(la,{turns:X,viewportRef:x,containerRef:m,onRevealTurn:O}),a&&i&&e.jsx(na,{rootRef:m,draftKey:a,canAskSideConversation:r,onOpenSideConversation:i}),f&&e.jsxs("button",{type:"button",onClick:T,"aria-live":"polite","aria-label":o>0?P:n("chat.list.jumpLatest"),className:"absolute bottom-4 left-1/2 z-10 inline-flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/95 px-3 py-1.5 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] shadow-lg backdrop-blur transition-colors hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(Oe,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),o>0?P:n("chat.list.jumpLatest")]})]})}const gt=h.memo(pa);function fa({queue:t,mutation:s,onMutate:a,onRefresh:r}){const i=_(),[n,c]=h.useState(!1),m=h.useRef(null),x=h.useRef(null),l=h.useRef(null);h.useLayoutEffect(()=>{var p,w,d;if(s.pending||!m.current)return;const u=m.current;m.current=null,(d=Array.from(((p=x.current)==null?void 0:p.querySelectorAll("[data-follow-up-focus-id]"))??[]).find(N=>N.dataset.followUpFocusId===u)??((w=x.current)==null?void 0:w.querySelector("button")))==null||d.focus()},[s.pending,t==null?void 0:t.version]);const b=h.useCallback(async u=>{m.current=u.messageId,await a(u)},[a]),k=h.useCallback((u,g)=>{b({type:"move",messageId:u,toPosition:g})},[b]);return!t||t.pending===0&&!s.errorMessage?null:e.jsxs("section",{ref:x,"data-blade-follow-up-queue":!0,className:"mx-4 mb-2 overflow-hidden rounded-lg border border-amber-300/70 bg-amber-50/70 shadow-sm dark:border-amber-900/60 dark:bg-amber-950/25 md:mx-6","aria-label":i("chat.followUpQueue.title"),children:[e.jsxs("button",{type:"button","aria-label":i(n?"chat.followUpQueue.hide":"chat.followUpQueue.show"),"aria-expanded":n,onClick:()=>c(u=>!u),className:"flex min-h-10 w-full items-center gap-2 px-3 text-left font-mono text-[11px] text-amber-950 transition-colors hover:bg-amber-100/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-amber-500 dark:text-amber-100 dark:hover:bg-amber-900/35",children:[e.jsx(ds,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),e.jsx("span",{className:"font-semibold",children:i("chat.followUpQueue.count",{count:t.pending})}),t.locked>0&&e.jsx("span",{className:"text-amber-700/80 dark:text-amber-300/75",children:i("chat.followUpQueue.lockedCount",{count:t.locked})}),e.jsx(ce,{className:`ml-auto h-3.5 w-3.5 transition-transform ${n?"rotate-90":""}`,"aria-hidden":!0})]}),n&&e.jsxs("div",{className:"border-t border-amber-300/60 px-2 py-2 dark:border-amber-900/50",children:[s.errorMessage&&e.jsxs("div",{role:"alert",className:"mb-2 flex items-center gap-2 rounded-md border border-red-200 bg-red-50 px-2.5 py-2 text-[11px] text-red-700 dark:border-red-900/60 dark:bg-red-950/35 dark:text-red-300",children:[e.jsx("span",{className:"min-w-0 flex-1",children:s.errorCode==="revision_conflict"?i("chat.followUpQueue.stale"):s.errorMessage}),r&&e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.refresh"),onClick:()=>void r(),className:"rounded p-1 hover:bg-red-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 dark:hover:bg-red-900/60",children:e.jsx(dt,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),e.jsx("ol",{className:"space-y-1.5",children:t.items.map((u,g)=>{const p=t.items[g-1],w=t.items[g+1],d=u.mutable&&(p==null?void 0:p.mutable)===!0,N=u.mutable&&(w==null?void 0:w.mutable)===!0,f=s.pending;return e.jsxs("li",{"data-follow-up-id":u.id,"data-follow-up-state":u.state,"data-follow-up-focus-id":u.id,tabIndex:-1,draggable:u.mutable&&!s.pending,onDragStart:()=>{l.current=u.mutable?u.id:null},onDragOver:S=>{const o=l.current,E=t.items.find(I=>I.id===o);E!=null&&E.mutable&&u.mutable&&S.preventDefault()},onDrop:S=>{S.preventDefault();const o=l.current;l.current=null;const E=t.items.find(j=>j.id===o);if(!(E!=null&&E.mutable)||!u.mutable||E.id===u.id)return;const I=Math.min(E.position,u.position),R=Math.max(E.position,u.position);t.items.slice(I,R+1).some(j=>!j.mutable)||k(E.id,u.position)},onDragEnd:()=>{l.current=null},className:"flex min-w-0 items-center gap-2 rounded-md border border-amber-200/70 bg-white/75 px-2.5 py-2 dark:border-amber-900/50 dark:bg-zinc-950/45",children:[e.jsx("span",{className:"w-5 shrink-0 text-center font-mono text-[10px] text-amber-700 dark:text-amber-400",children:g+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-xs text-[hsl(var(--deck-ink))]",children:u.kind==="internal"?i("chat.followUpQueue.internal"):u.preview||i("chat.followUpQueue.attachmentOnly")}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 font-mono text-[9px] uppercase tracking-[0.08em] text-[hsl(var(--deck-ink-faint))]",children:[e.jsx("span",{children:i(`chat.followUpQueue.delivery.${u.delivery}`)}),!u.mutable&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(us,{className:"h-2.5 w-2.5","aria-hidden":!0}),i("chat.followUpQueue.locked")]}),u.attachmentCount>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ft,{className:"h-2.5 w-2.5","aria-hidden":!0}),u.attachmentCount]})]})]}),f&&s.messageId===u.id?e.jsx(U,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-amber-600"}):e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.moveUp",{id:u.id}),disabled:f||!d,onClick:()=>k(u.id,g-1),className:"rounded p-1 text-amber-800 transition-colors hover:bg-amber-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-500 disabled:opacity-30 dark:text-amber-300 dark:hover:bg-amber-900/50",children:e.jsx(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.moveDown",{id:u.id}),disabled:f||!N,onClick:()=>k(u.id,g+1),className:"rounded p-1 text-amber-800 transition-colors hover:bg-amber-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-500 disabled:opacity-30 dark:text-amber-300 dark:hover:bg-amber-900/50",children:e.jsx(Oe,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.remove",{id:u.id}),disabled:f||!u.mutable,onClick:()=>void b({type:"remove",messageId:u.id}),className:"rounded p-1 text-red-600 transition-colors hover:bg-red-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 disabled:opacity-30 dark:text-red-400 dark:hover:bg-red-950/60",children:e.jsx(ie,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})]},u.id)})})]})]})}const Ie=Zt,Le=es,Be=ts,ye=h.forwardRef(({className:t,sideOffset:s=4,...a},r)=>e.jsx(pt,{ref:r,sideOffset:s,className:L("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",t),...a}));ye.displayName=pt.displayName;const ba={active:{labelKey:"goal.status.active",dot:"bg-[hsl(var(--deck-accent))] shadow-[0_0_6px_hsl(var(--deck-accent-glow)/0.5)]",accent:"text-[hsl(var(--deck-accent))]"},verifying:{labelKey:"goal.status.active",dot:"animate-pulse bg-sky-400",accent:"text-sky-600 dark:text-sky-300"},paused:{labelKey:"goal.status.paused",dot:"bg-amber-400",accent:"text-amber-600 dark:text-amber-300"},blocked:{labelKey:"goal.status.blocked",dot:"bg-rose-500",accent:"text-rose-600 dark:text-rose-300"},usage_limited:{labelKey:"goal.status.usageLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},budget_limited:{labelKey:"goal.status.budgetLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},complete:{labelKey:"goal.status.complete",dot:"bg-emerald-500",accent:"text-emerald-600 dark:text-emerald-300"}};function fe(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function va(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),a=t%60;return a===0?`${s}m`:`${s}m ${a}s`}function ga(){var T,B,O,P,C,M,A,D,G,ee,F,W,J,Q,z,K,Y,te,le,xe;const t=_(),{locale:s}=ut(),a=v($=>$.goal),r=v($=>$.pauseGoal),i=v($=>$.resumeGoal),n=v($=>$.editGoal),c=v($=>$.clearGoal),m=v($=>oe($.historySurfaceSelection)),[x,l]=h.useState(!1),[b,k]=h.useState(!1),[u,g]=h.useState(""),[p,w]=h.useState(null),[d,N]=h.useState(!1);if(h.useEffect(()=>{l(!1),k(!1),g((a==null?void 0:a.objective)??""),N(!1)},[a==null?void 0:a.goalId]),m||!a)return null;const f=ba[a.status],S=["active","verifying","paused","blocked"].includes(a.status),o=a.status==="active"||a.status==="verifying",E=a.status==="paused"||a.status==="blocked",I=p!==null,R=async($,se)=>{if(!q(v.getState())){w($);try{await se()}finally{w(null)}}},j=()=>{g(a.objective),k(!0),l(!0)},V=async $=>{$.preventDefault();const se=u.trim();if(!se||se===a.objective){k(!1);return}await R("edit",()=>n(se)),k(!1)},X=async()=>{await R("delete",c),N(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Ie,{delayDuration:250,children:e.jsxs("section",{"aria-label":t("goal.aria.section"),className:"mx-3 mb-1 shrink-0","data-blade-goal-status":a.status,"data-blade-goal-recovery":(T=a.prematureStop)==null?void 0:T.consecutiveCount,"data-blade-goal-recovery-pattern":(B=a.prematureStop)==null?void 0:B.pattern,"data-blade-goal-verification-stall":(O=a.verificationStall)==null?void 0:O.consecutiveCount,"data-blade-goal-frontier-task-list":(P=a.executionFrontier)==null?void 0:P.taskListId,"data-blade-goal-frontier-total":(C=a.executionFrontier)==null?void 0:C.total,"data-blade-goal-frontier-completed":(M=a.executionFrontier)==null?void 0:M.completed,"data-blade-goal-frontier-in-progress":(A=a.executionFrontier)==null?void 0:A.inProgress,"data-blade-goal-frontier-pending":(D=a.executionFrontier)==null?void 0:D.pending,"data-blade-goal-frontier-blocked":(G=a.executionFrontier)==null?void 0:G.blocked,"data-blade-goal-frontier-next-task":(F=(ee=a.executionFrontier)==null?void 0:ee.nextTask)==null?void 0:F.id,"data-blade-goal-frontier-digest":(W=a.executionFrontier)==null?void 0:W.digestSha256.slice(0,16),"data-blade-goal-frontier-stall":(J=a.frontierStall)==null?void 0:J.category,"data-blade-goal-frontier-stall-count":(Q=a.frontierStall)==null?void 0:Q.consecutiveCount,"data-blade-goal-execution-host-failure":(z=a.executionHostFailure)==null?void 0:z.category,"data-blade-goal-execution-host-failure-count":(K=a.executionHostFailure)==null?void 0:K.consecutiveCount,"data-blade-goal-root-turn":(Y=a.turnLineage)==null?void 0:Y.rootTurnId,"data-blade-goal-current-turn":(te=a.turnLineage)==null?void 0:te.currentTurnId,"data-blade-goal-parent-turn":(le=a.turnLineage)==null?void 0:le.parentTurnId,children:[e.jsxs("div",{className:L("flex h-9 items-center gap-2 rounded-lg border px-3 transition-colors","border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 backdrop-blur-sm",x&&"rounded-b-none border-b-0"),children:[a.status==="complete"?e.jsx(It,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(ms,{className:L("h-3.5 w-3.5 shrink-0",f.accent)}),e.jsx("span",{className:L("h-1.5 w-1.5 shrink-0 rounded-full",f.dot)}),e.jsx("span",{className:L("shrink-0 text-[10px] font-medium leading-none",f.accent),children:a.status==="verifying"?s==="zh"?"验证中":"Verifying":t(f.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(x?"goal.action.collapse":"goal.action.expand"),className:"min-w-0 flex-1 truncate text-left text-[12px] leading-5 text-[hsl(var(--deck-ink))]/85 outline-none transition-colors hover:text-[hsl(var(--deck-ink))]",onClick:()=>l($=>!$),"aria-expanded":x,title:a.objective,children:a.objective}),a.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[fe(a.tokensUsed),a.tokenBudget!==void 0&&`/${fe(a.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[o&&e.jsx(be,{label:t("goal.action.pause"),disabled:I,onClick:()=>void R("pause",r),children:p==="pause"?e.jsx(U,{className:"animate-spin"}):e.jsx(ss,{})}),E&&e.jsx(be,{label:t("goal.action.resume"),disabled:I,onClick:()=>void R("resume",i),children:p==="resume"?e.jsx(U,{className:"animate-spin"}):e.jsx(as,{})}),e.jsx(be,{label:t(S?"goal.action.edit":"goal.action.expand"),disabled:!S&&!x,onClick:S?j:()=>l($=>!$),children:S?e.jsx(ft,{}):e.jsx(Xt,{})}),e.jsx(be,{label:t("goal.action.delete"),disabled:I,destructive:!0,onClick:()=>N(!0),children:e.jsx(ie,{})})]})]}),x&&e.jsx("div",{className:"rounded-b-lg border border-t-0 border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 px-4 py-3 backdrop-blur-sm",children:b?e.jsxs("form",{onSubmit:V,children:[e.jsx("textarea",{id:"goal-objective",value:u,onChange:$=>g($.target.value),onKeyDown:$=>{$.key==="Escape"&&k(!1)},rows:3,autoFocus:!0,className:"w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] outline-none transition-shadow focus:border-[hsl(var(--deck-accent))] focus:ring-1 focus:ring-[hsl(var(--deck-accent-glow))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>k(!1),className:"inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-hairline))]/60",children:[e.jsx(mt,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!u.trim()||p==="edit",className:"inline-flex h-7 items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2.5 text-[11px] font-medium text-white transition-colors hover:bg-[hsl(var(--deck-accent))]/90 disabled:cursor-not-allowed disabled:opacity-50",children:[p==="edit"?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx(je,{className:"h-3 w-3"}),t("goal.action.save")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink))]/90",children:a.objective}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(cs,{className:"h-3 w-3"}),fe(a.tokensUsed),a.tokenBudget!==void 0&&` / ${fe(a.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(hs,{className:"h-3 w-3"}),va(a.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ve,{className:"h-3 w-3"}),a.continuationCount===1?t("goal.metrics.continuationOne",{n:a.continuationCount}):t("goal.metrics.continuationMany",{n:a.continuationCount})]})]}),a.turnLineage&&e.jsxs("div",{className:"mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 rounded-md border border-[hsl(var(--deck-border))]/50 bg-[hsl(var(--deck-canvas))]/45 px-2.5 py-2 font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx("span",{children:t("goal.lineage.origin")}),e.jsx("span",{className:"truncate",children:a.turnLineage.rootTurnId??"?"}),e.jsx("span",{children:t("goal.lineage.current")}),e.jsx("span",{className:"truncate",children:a.turnLineage.currentTurnId}),e.jsx("span",{children:t("goal.lineage.parent")}),e.jsx("span",{className:"truncate",children:a.turnLineage.parentTurnId??"?"})]}),a.prematureStop&&e.jsxs("div",{className:"mt-2 inline-flex items-center gap-1.5 font-mono text-[10px] text-amber-700 dark:text-amber-300",children:[e.jsx(ve,{className:"h-3 w-3"}),s==="zh"?"恢复提示":"Recovery nudge"," ",a.prematureStop.consecutiveCount," ·"," ",a.prematureStop.pattern.replaceAll("_"," ")]}),a.executionHostFailure&&e.jsxs("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-2 text-[11px] text-amber-900 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-100",children:[e.jsx("p",{className:"font-medium",children:t("goal.executionHostFailure.title")}),e.jsxs("p",{className:"mt-1 font-mono opacity-80",children:[t(`goal.executionHostFailure.category.${a.executionHostFailure.category}`)," ","· ",a.executionHostFailure.consecutiveCount,"/3"]})]}),a.completionVerification&&e.jsxs("div",{"data-goal-verification":a.completionVerification.status,className:"mt-2 rounded-md border border-sky-200/50 bg-sky-50/60 px-2.5 py-2 text-[11px] text-sky-900 dark:border-sky-400/15 dark:bg-sky-400/[0.05] dark:text-sky-100",children:[e.jsxs("p",{className:"font-mono font-medium",children:["#",a.completionVerification.attempt," ·"," ",a.completionVerification.status.toUpperCase()," ·"," ",((xe=a.completionVerification.verifierSessionId)==null?void 0:xe.slice(0,12))??"-",a.verificationStall?s==="zh"?` · 重复 ${a.verificationStall.consecutiveCount}/3`:` · repeat ${a.verificationStall.consecutiveCount}/3`:""]}),a.completionVerification.summary&&e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap opacity-80",children:a.completionVerification.summary}),a.completionVerification.evidenceSha256&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] opacity-60",children:["sha256:",a.completionVerification.evidenceSha256.slice(0,12)]})]}),a.statusReason&&e.jsx("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-1.5 text-[11px] text-amber-800 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-200",children:a.statusReason})]})})]})}),e.jsx(at,{open:d,onOpenChange:N,children:e.jsxs(rt,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(nt,{children:t("goal.dialog.title")}),e.jsx(it,{children:t("goal.dialog.description")}),e.jsxs(ot,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>N(!1),className:"inline-flex h-8 items-center justify-center rounded-md border border-[hsl(var(--deck-border))] px-3 text-[12px] text-[hsl(var(--deck-ink))] hover:bg-[hsl(var(--deck-hairline))]/60",children:t("goal.action.cancel")}),e.jsxs("button",{type:"button",disabled:p==="delete",onClick:()=>void X(),className:"inline-flex gap-1.5 justify-center items-center px-3 h-8 text-[12px] font-medium text-white bg-rose-600 rounded-md hover:bg-rose-500 disabled:opacity-50",children:[p==="delete"&&e.jsx(U,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function be({label:t,children:s,disabled:a,destructive:r,onClick:i}){return e.jsxs(Le,{children:[e.jsx(Be,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:a,onClick:i,className:L("flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-muted))] outline-none transition-colors focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent-glow))]/50 disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",r?"hover:bg-rose-500/10 hover:text-rose-500":"hover:bg-[hsl(var(--deck-hairline))]/60 hover:text-[hsl(var(--deck-ink))]"),children:s})}),e.jsx(ye,{side:"top",className:"text-[10px]",children:t})]})}function ka(){const t=_(),s=v(l=>l.currentSessionRef),a=v(l=>l.sessions),r=v(l=>l.messages),i=v(l=>oe(l.historySurfaceSelection)),n=h.useMemo(()=>{var b,k,u,g,p;const l=s?(b=Lt(a,s))==null?void 0:b.pendingInteraction:void 0;if(l)return l.type;for(let w=r.length-1;w>=0;w-=1){const d=(k=r[w])==null?void 0:k.agentContent;if(((u=d==null?void 0:d.confirmation)==null?void 0:u.status)==="pending")return"permission";if(((g=d==null?void 0:d.question)==null?void 0:g.status)==="pending")return"question";if(((p=d==null?void 0:d.elicitation)==null?void 0:p.status)==="pending")return"elicitation"}return null},[s,r,a]);if(i||!n)return null;const c=()=>{const l=document.querySelector(`[data-pending-interaction="${n}"]`);l==null||l.scrollIntoView({block:"center",behavior:"smooth"}),window.setTimeout(()=>l==null?void 0:l.focus(),250)},m=n==="question",x=n==="elicitation";return e.jsxs("div",{role:"alert",className:"mx-3 mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-amber-300/80 bg-amber-50/95 px-3 py-2 font-mono text-amber-950 shadow-sm backdrop-blur dark:border-amber-800/80 dark:bg-amber-950/90 dark:text-amber-100 sm:mx-5",children:[e.jsx(Pe,{className:"h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-[180px] flex-1",children:[e.jsx("div",{className:"text-[11.5px] font-semibold",children:t(m?"interaction.bar.questionTitle":x?"interaction.bar.elicitationTitle":"interaction.bar.permissionTitle")}),e.jsx("div",{className:"mt-0.5 text-[10px] leading-4 text-amber-800 dark:text-amber-300",children:t(m?"interaction.bar.questionHint":x?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:c,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/80 bg-white/80 px-2.5 text-[10.5px] font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/70 dark:hover:bg-amber-900",children:[e.jsx(Oe,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}function me(t){return Math.max(0,Math.ceil((t??0)/1e3))}function ya(t,s=Date.now()){var r;const a=(r=t.snapshot)==null?void 0:r.nextActionAt;return a===void 0?void 0:me(a-s)}function kt(t,s=Date.now()){const a=t==null?void 0:t.snapshot;if(!a)return null;const r=ya(t,s)??0,i=a.retry,n=a.admission,c=a.stall,m=a.fallback,x={seconds:r,attempt:(i==null?void 0:i.attempt)??0,maxRetries:(i==null?void 0:i.maxRetries)??0,budgetSeconds:me(i==null?void 0:i.recoveryRemainingMs),position:(n==null?void 0:n.queuePosition)??0,depth:n?Math.max(n.queueDepth,n.queuePosition):0,scope:(n==null?void 0:n.scope)??"",waitSeconds:me(n==null?void 0:n.waitMs),stallSeconds:me(c==null?void 0:c.durationMs),timeoutSeconds:me(c==null?void 0:c.timeoutMs),from:(m==null?void 0:m.from.model)??"",to:(m==null?void 0:m.to.model)??"",candidate:(m==null?void 0:m.candidate)??0,candidateCount:(m==null?void 0:m.candidateCount)??0};switch(a.activity){case"admission_wait":return{titleKey:"chat.providerRecovery.admission",detailKey:"chat.providerRecovery.admissionDetail",compactKey:"chat.providerRecovery.admissionCompact",params:x};case"retry_wait":return{titleKey:a.reason==="rate_limit"?"chat.providerRecovery.rateLimit":"chat.providerRecovery.retryWait",detailKey:"chat.providerRecovery.retryDetail",compactKey:"chat.providerRecovery.retryCompact",params:x};case"retry_attempt":return{titleKey:"chat.providerRecovery.retryAttempt",detailKey:"chat.providerRecovery.retryDetail",compactKey:"chat.providerRecovery.retryCompact",params:x};case"circuit_open":return{titleKey:a.reason==="rate_limit"?"chat.providerRecovery.rateLimitCircuit":"chat.providerRecovery.circuit",detailKey:"chat.providerRecovery.circuitDetail",compactKey:a.reason==="rate_limit"?"chat.providerRecovery.rateLimitCircuitCompact":"chat.providerRecovery.circuitCompact",params:x};case"circuit_probe":return{titleKey:"chat.providerRecovery.probe",detailKey:"chat.providerRecovery.probeDetail",compactKey:"chat.providerRecovery.probeCompact",params:x};case"stream_stall":return{titleKey:c!=null&&c.outputStarted?"chat.providerRecovery.stallAfterOutput":"chat.providerRecovery.stall",detailKey:"chat.providerRecovery.stallDetail",compactKey:"chat.providerRecovery.stallCompact",params:x};case"fallback":return{titleKey:"chat.providerRecovery.fallback",detailKey:"chat.providerRecovery.fallbackDetail",compactKey:"chat.providerRecovery.fallbackCompact",params:x}}}function ja({recovery:t,stopping:s,onStop:a}){var x;const r=_(),[i,n]=h.useState(Date.now()),c=(x=t==null?void 0:t.snapshot)==null?void 0:x.nextActionAt;h.useEffect(()=>{if(c===void 0)return;n(Date.now());const l=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(l)},[c]);const m=kt(t,i);return m?e.jsxs("section",{role:"status","aria-live":"polite","data-provider-recovery-banner":!0,className:"mx-4 mb-2 flex min-h-12 items-center gap-3 rounded-lg border border-amber-300/70 bg-amber-50/80 px-3 py-2 text-amber-950 shadow-sm dark:border-amber-800/60 dark:bg-amber-950/35 dark:text-amber-100 md:mx-6",children:[e.jsx(U,{className:"h-4 w-4 shrink-0 animate-spin","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-semibold",children:r(m.titleKey,m.params)}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-[10px] opacity-80",children:r(m.detailKey,m.params)})]}),e.jsxs("button",{type:"button","data-provider-recovery-stop":!0,onClick:a,disabled:s,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/70 bg-white/70 px-2.5 text-xs font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 disabled:cursor-wait disabled:opacity-60 dark:border-amber-700 dark:bg-amber-950/50 dark:hover:bg-amber-900/50",children:[s?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):e.jsx(Bt,{className:"h-3 w-3 fill-current","aria-hidden":!0}),r(s?"chat.input.action.stopping":"chat.providerRecovery.stop")]})]}):null}const wa=h.lazy(()=>lt(()=>import("./MarkdownRenderer-DhB-5HAw.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function Na(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Sa(t,s){return t?[{id:"legacy-user",role:"user",content:t},...s?[{id:"legacy-assistant",role:"assistant",content:s}]:[]]:[]}function Me(t){return t?JSON.stringify([t.sessionRef.projectPath,t.sessionRef.sessionId,t.requestId]):null}function Ca(){const t=_(),s=v(d=>d.sideConversation),a=v(d=>d.askSideConversation),r=v(d=>d.openSideConversation),i=v(d=>d.dismissSideConversation),n=Me(s),[c,m]=h.useState({owner:n,text:""}),x=c.owner===n?c.text:"";c.owner!==n&&m({owner:n,text:""});const l=d=>m({owner:n,text:d}),b=h.useRef(null),k=h.useRef(!1),u=h.useRef(null),g=h.useMemo(()=>(s==null?void 0:s.messages)??Sa((s==null?void 0:s.question)??"",s==null?void 0:s.response),[s==null?void 0:s.messages,s==null?void 0:s.question,s==null?void 0:s.response]);if(h.useEffect(()=>{k.current=!1,!(!s||s.status==="loading")&&requestAnimationFrame(()=>{var d;return(d=b.current)==null?void 0:d.focus()})},[s==null?void 0:s.sessionRef,s==null?void 0:s.selectedText,s==null?void 0:s.status]),h.useEffect(()=>{var d,N;(N=(d=u.current)==null?void 0:d.scrollIntoView)==null||N.call(d,{block:"nearest"})},[g.length,s==null?void 0:s.status]),!s)return null;const p=()=>{const d=x.trim();if(!d||s.status==="loading")return;l("");const N=a(d),f=Me(v.getState().sideConversation);N.then(S=>{!S&&f!==null&&Me(v.getState().sideConversation)===f&&m({owner:f,text:d})})},w=d=>{if(!(k.current||d.nativeEvent.isComposing||d.keyCode===229)){if((d.metaKey||d.ctrlKey)&&d.key.toLocaleLowerCase()==="a"){d.preventDefault(),d.stopPropagation(),d.currentTarget.select();return}if(d.key==="Escape"){d.preventDefault(),i();return}d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),p())}};return e.jsxs("aside",{"aria-label":t("chat.side.title"),"data-blade-side-conversation":!0,"data-status":s.status,className:"absolute inset-0 z-30 flex min-h-0 flex-col bg-[hsl(var(--deck-canvas))] md:relative md:inset-auto md:w-[min(420px,42vw)] md:shrink-0 md:border-l md:border-[hsl(var(--deck-hairline))]",children:[e.jsxs("header",{className:"flex h-12 shrink-0 items-center gap-2 border-b border-[hsl(var(--deck-hairline))] px-3",children:[e.jsx(De,{"aria-hidden":!0,className:"h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsx("h2",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-[hsl(var(--deck-ink))]",children:t("chat.side.title")}),s.durationMs!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(rs,{"aria-hidden":!0,className:"h-3 w-3"}),Na(s.durationMs)]}),e.jsx("button",{type:"button",onClick:()=>{l(""),r()},"aria-label":t("chat.side.new"),title:t("chat.side.new"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface-2))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:e.jsx(ns,{"aria-hidden":!0,className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":t("chat.side.dismiss"),title:t("chat.side.dismiss"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface-2))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:e.jsx(mt,{"aria-hidden":!0,className:"h-4 w-4"})})]}),e.jsxs("div",{"aria-live":"polite","aria-busy":s.status==="loading",className:"min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4",children:[s.selectedText&&e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"inline-flex min-h-8 cursor-pointer list-none items-center gap-1.5 rounded-md border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))] px-2.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(De,{"aria-hidden":!0,className:"h-3.5 w-3.5"}),t("chat.side.selectedText")]}),e.jsx("blockquote",{className:"mt-2 whitespace-pre-wrap border-l-2 border-[hsl(var(--deck-accent)/0.45)] pl-3 font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:s.selectedText})]}),g.map(d=>d.role==="user"?e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"max-w-[88%] rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))]",children:d.content})},d.id):e.jsx("div",{className:"min-w-0",children:e.jsx(h.Suspense,{fallback:e.jsx("div",{className:"whitespace-pre-wrap break-words text-[12px] leading-5 text-[hsl(var(--deck-ink))]",children:d.content}),children:e.jsx(wa,{content:d.content,className:"text-[12px] leading-5 [&_h1]:text-[14px] [&_h2]:text-[13px] [&_h3]:text-[12px]"})})},d.id)),s.status==="loading"&&e.jsxs("div",{role:"status",className:"flex min-h-9 items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(U,{"aria-hidden":!0,className:"h-3.5 w-3.5 animate-spin text-[hsl(var(--deck-accent))]"}),t("chat.side.loading")]}),s.status==="error"&&e.jsxs("div",{role:"alert",className:"flex min-h-9 items-start gap-2 text-[11px] leading-5 text-red-700 dark:text-red-300",children:[e.jsx(Pe,{"aria-hidden":!0,className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"break-words",children:s.error??t("chat.side.failed")})]}),e.jsx("div",{ref:u})]}),e.jsx("div",{className:"shrink-0 border-t border-[hsl(var(--deck-hairline))] p-3",children:e.jsxs("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] focus-within:border-[hsl(var(--deck-border-strong))] focus-within:ring-1 focus-within:ring-[hsl(var(--deck-border-strong))]",children:[e.jsx("textarea",{ref:b,name:"side-conversation-composer",value:x,onChange:d=>l(d.target.value),onCompositionStart:()=>{k.current=!0},onCompositionEnd:()=>{k.current=!1},onBlur:()=>{k.current=!1},onKeyDown:w,rows:3,disabled:s.status==="loading","aria-label":t("chat.side.input"),placeholder:t("chat.side.placeholder"),className:"block max-h-40 min-h-[88px] w-full resize-none bg-transparent px-3 py-2.5 text-[13px] leading-5 text-[hsl(var(--deck-ink))] placeholder:text-[hsl(var(--deck-ink-faint))] focus:outline-none disabled:cursor-wait disabled:opacity-60"}),e.jsx("div",{className:"flex items-center justify-end px-2 pb-2",children:e.jsx("button",{type:"button",onClick:p,disabled:!x.trim()||s.status==="loading","aria-label":t("chat.side.send"),title:t("chat.side.send"),className:"flex h-8 w-8 items-center justify-center rounded-md bg-[hsl(var(--deck-ink))] text-[hsl(var(--deck-canvas))] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[hsl(var(--deck-accent))] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-35",children:e.jsx($e,{"aria-hidden":!0,className:"h-3.5 w-3.5"})})})]})})]})}function Ae(t){return Number.isFinite(t)?Math.max(0,t):0}function Ta(t){const s=Ae(t.totalInputTokens),a=Ae(t.cacheReadTokens),r=Ae(t.cacheWriteTokens),i=Math.min(a,s),n=Math.min(r,Math.max(0,s-i)),c=Math.max(0,s-i-n),m=s>0&&(a>0||r>0);return{totalInputTokens:s,cacheReadTokens:i,cacheWriteTokens:n,uncachedInputTokens:c,...m?{hitRate:i/s}:{}}}function Ea(t){return t===void 0||!Number.isFinite(t)?"—":`${Math.round(Math.max(0,Math.min(1,t))*100)}%`}const Ma={running:"status.phase.running",compacting:"status.phase.compacting",recovering_context:"status.phase.recoveringContext",switching_model:"status.phase.switchingModel",waiting_permission:"status.phase.waitingPermission",error:"status.phase.error",idle:""},Aa={model_changed:"status.cacheBreak.model",system_prompt_changed:"status.cacheBreak.system",tools_changed:"status.cacheBreak.tools",request_policy_changed:"status.cacheBreak.policy",ttl_expired:"status.cacheBreak.ttl",server_side:"status.cacheBreak.server"},ae=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString(),Ra=t=>{const s=Math.max(0,Math.ceil(t/1e3)),a=Math.floor(s/60),r=s%60;return a>0?`${a}m ${r}s`:`${r}s`};function yt(){const t=_(),s=v(o=>o.tokenUsage),a=v(o=>o.isStreaming),r=v(o=>o.agentPhase),i=v(o=>o.providerRecovery),n=v(o=>o.turnActivity),c=v(o=>o.pendingResume),m=v(o=>o.actionStationarity),x=v(o=>o.turnRecovery),l=Ma[r]??"",b=kt(i),k=(c==null?void 0:c.delayMs)!==void 0?` · retry in ${Ra(c.delayMs)}`:"",u=(x==null?void 0:x.state)==="requires_attention"?t("status.recovery.review"):"",g=(x==null?void 0:x.state)==="requires_attention"?t(x.reason==="interrupted_tool_call"?"status.recovery.interruptedTool":"status.recovery.successfulTool"):"",p=u||(m?`${t(m.phase==="halted"?"status.phase.actionStationarityStopped":"status.phase.actionStationarityRecovering")} · ${m.toolName} · ${m.runLength}/${m.haltThreshold}`:b?t(b.compactKey,b.params):c?`Recovery attempt ${c.attempt}/${c.maxAttempts}${k}`:l?t(l):""),w=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,d=Ta(s),N=Ea(d.hitRate),f=Math.min(w,100),S=w>95?"danger":w>80?"warn":"safe";return e.jsxs("div",{"data-chat-status-bar":!0,className:"flex items-center gap-2 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:gap-4 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.context")}),e.jsxs("span",{className:"flex gap-1 items-baseline tabular-nums",children:[e.jsx("span",{className:L("text-[12px] font-medium",S==="safe"&&"text-[hsl(var(--deck-ink))]",S==="warn"&&"text-amber-600 dark:text-amber-400",S==="danger"&&"text-red-600 dark:text-red-400"),children:ae(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",ae(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(Ie,{children:e.jsxs(Le,{children:[e.jsx(Be,{asChild:!0,children:e.jsx(ls,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(ye,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative hidden h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:block","aria-hidden":"true",children:[e.jsx("div",{className:L("absolute inset-y-0 left-0 transition-[width] duration-300",S==="safe"&&"bg-[hsl(var(--deck-accent))]",S==="warn"&&"bg-amber-500",S==="danger"&&"bg-red-500"),style:{width:`${f}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(o=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${o}%`}},o))})]}),e.jsxs("span",{className:L("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",S==="warn"&&"text-amber-600 dark:text-amber-400",S==="danger"&&"text-red-600 dark:text-red-400"),children:[w,"%"]})]}),e.jsx(Ie,{children:e.jsxs(Le,{children:[e.jsx(Be,{asChild:!0,children:e.jsxs("div",{className:"flex shrink-0 cursor-help items-baseline gap-2 border-l border-[hsl(var(--deck-hairline))] pl-2 sm:pl-4","data-testid":"prompt-cache-hit-rate","aria-label":`${t("status.cache")} ${N}`,children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.cache")}),e.jsx("span",{className:L("tabular-nums",d.hitRate===void 0?"text-[hsl(var(--deck-ink-faint))]":"font-medium text-[hsl(var(--deck-accent))]"),children:N})]})}),e.jsx(ye,{side:"top",className:"max-w-[280px]",children:d.hitRate===void 0?e.jsx("p",{className:"text-xs",children:t("status.cacheUnavailable")}):e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("p",{children:t("status.cacheTooltip")}),e.jsx("p",{className:"font-mono tabular-nums",children:t("status.cacheDetails",{read:ae(d.cacheReadTokens),write:ae(d.cacheWriteTokens),uncached:ae(d.uncachedInputTokens)})}),s.cacheBreak&&e.jsx("p",{className:"text-[hsl(var(--deck-accent))]",children:t("status.cacheBreak",{reason:t(Aa[s.cacheBreak.reason]??"status.cacheBreak.server"),previous:ae(s.cacheBreak.previousCacheReadTokens),current:ae(s.cacheBreak.cacheReadTokens)})})]})})]})}),e.jsx("div",{className:"flex-1"}),(u||a&&p&&(!(n!=null&&n.snapshot)||m))&&e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:L("shrink-0",u?"h-2 w-2 rounded-sm bg-amber-500":"deck-pulse-dot")}),e.jsxs("span",{className:L("truncate",u?"text-amber-600 dark:text-amber-400":"text-[hsl(var(--deck-accent))]"),children:[p,g?e.jsxs("span",{className:"hidden sm:inline",children:[" · ",g]}):null]})]})]})}function Da(){const{locale:t}=ut(),s=$t(o=>o.agentTeamsEnabled),a=v(o=>o.teams),r=v(o=>o.currentSessionRef),i=v(o=>oe(o.historySurfaceSelection)),n=v(o=>o.loadTeams),[c,m]=h.useState({}),[x,l]=h.useState({}),[b,k]=h.useState({}),[u,g]=h.useState(null),[p,w]=h.useState(null),[d,N]=h.useState(null);if(h.useEffect(()=>{i||n(r??void 0)},[s,r,i,n]),i||!s||!r||a.length===0)return null;const f=async o=>{var I;if(q(v.getState()))return;const E=(I=b[o])==null?void 0:I.trim();if(!(!E||u)){g(o),N(null);try{await ze.sendMessage(r,o,x[o]??"*",E),k(R=>({...R,[o]:""})),await n(r)}catch(R){N(R instanceof Error?R.message:H(t,"actionFailed"))}finally{g(null)}}},S=async o=>{if(!q(v.getState())&&!p){w(o),N(null);try{await ze.delete(r,o),await n(r)}catch(E){N(E instanceof Error?E.message:H(t,"actionFailed"))}finally{w(null)}}};return e.jsxs("section",{"aria-label":H(t,"title"),"data-blade-team-panel":!0,className:"shrink-0 border-y border-emerald-300/50 bg-emerald-50/55 dark:border-emerald-800/55 dark:bg-emerald-950/20",children:[d&&e.jsx("div",{role:"alert",className:"border-b border-red-200 bg-red-50 px-4 py-2 font-mono text-[10px] text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300 md:px-6",children:d}),a.filter(o=>o.status!=="deleted").map(o=>{var R;const E=c[o.name]??o.status==="running",I=o.tasks.filter(j=>j.status==="completed").length;return e.jsxs("div",{className:"border-b border-emerald-200/40 last:border-0 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"flex min-h-11 items-center gap-2 px-4 py-2 md:px-6",children:[e.jsx("button",{type:"button",onClick:()=>m(j=>({...j,[o.name]:!E})),"aria-label":E?H(t,"collapse"):H(t,"expand"),className:"flex h-7 w-7 items-center justify-center rounded-md text-emerald-700 hover:bg-emerald-100 dark:text-emerald-300 dark:hover:bg-emerald-900/50",children:E?e.jsx(he,{className:"h-4 w-4"}):e.jsx(ce,{className:"h-4 w-4"})}),e.jsx(xs,{className:"h-4 w-4 shrink-0 text-emerald-700 dark:text-emerald-300"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("h2",{className:"truncate font-mono text-[11px] font-semibold uppercase text-emerald-800 dark:text-emerald-200",children:o.name}),e.jsxs("span",{className:"font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[o.status," · ",o.members.length-1," ",H(t,"members")," · ",I,"/",o.tasks.length," ",H(t,"tasks")]})]}),o.description&&e.jsx("p",{className:"truncate font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:o.description})]}),e.jsx("button",{type:"button",onClick:()=>void S(o.name),disabled:p===o.name,"aria-label":H(t,"delete"),title:H(t,"delete"),className:"flex h-7 w-7 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] hover:bg-red-50 hover:text-red-600 disabled:opacity-40 dark:hover:bg-red-950/40",children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),E&&e.jsxs("div",{className:"max-h-[min(40vh,360px)] overflow-y-auto border-t border-emerald-200/40 px-4 py-3 md:px-6 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 lg:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:H(t,"members")}),o.members.map(j=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsx("span",{"aria-label":j.status,className:`h-1.5 w-1.5 shrink-0 rounded-full ${j.status==="running"?"bg-emerald-500":j.status==="completed"||j.status==="leader"?"bg-sky-500":j.status==="failed"?"bg-red-500":"bg-zinc-400"}`}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:j.name}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:j.subagentType}),j.worktreePath&&e.jsx(st,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]","aria-label":H(t,"worktree")})]},j.id))]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:H(t,"tasks")}),o.tasks.length===0?e.jsx("p",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:H(t,"noTasks")}):o.tasks.map(j=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["#",j.id]}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:j.subject}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:j.status})]},j.id))]})]}),o.peerMessagingEnabled&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-emerald-200/40 pt-3 dark:border-emerald-900/40",children:[e.jsxs("select",{"aria-label":H(t,"recipient"),value:x[o.name]??"*",onChange:j=>l(V=>({...V,[o.name]:j.target.value})),className:"h-8 max-w-32 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10px]",children:[e.jsx("option",{value:"*",children:H(t,"broadcast")}),o.members.filter(j=>j.status!=="leader").map(j=>e.jsx("option",{value:j.name,children:j.name},j.id))]}),e.jsx("input",{value:b[o.name]??"",onChange:j=>k(V=>({...V,[o.name]:j.target.value})),onKeyDown:j=>{j.key==="Enter"&&f(o.name)},placeholder:H(t,"messagePlaceholder"),className:"h-8 min-w-0 flex-1 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10.5px] outline-none focus:border-emerald-500"}),e.jsx("button",{type:"button",onClick:()=>void f(o.name),disabled:!((R=b[o.name])!=null&&R.trim())||u===o.name,"aria-label":H(t,"send"),title:H(t,"send"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-emerald-700 text-white hover:bg-emerald-800 disabled:opacity-40 dark:bg-emerald-600",children:e.jsx($e,{className:"h-3.5 w-3.5"})})]})]})]},o.name)})]})}const Fa={starting:"chat.turnActivity.starting",thinking:"chat.turnActivity.thinking",responding:"chat.turnActivity.responding",executing_tools:"chat.turnActivity.executingTools",compacting:"chat.turnActivity.compacting",continuing:"chat.turnActivity.continuing"};function Ia(t){const s=Math.max(0,Math.floor(t/1e3));if(s<60)return`${s}s`;const a=Math.floor(s/60),r=s%60;return a<60?`${a}m ${r}s`:`${Math.floor(a/60)}h ${a%60}m ${r}s`}function La(t,s=Date.now()){const a=t==null?void 0:t.snapshot;if(!a)return null;const r=a.activeTools.length+a.activeToolOverflow,i=a.activeTools.slice(0,2).map(c=>c.progress!==void 0&&c.total!==void 0?`${c.name} ${c.progress}/${c.total}`:c.name),n=Math.max(0,a.activeTools.length-i.length+a.activeToolOverflow);return{phaseKey:Fa[a.phase],phaseParams:{count:r},tools:i,hiddenTools:n,completedTools:a.toolCallsCompleted,startedTools:a.toolCallsStarted,turn:a.turn,maxTurns:a.maxTurns,elapsed:Ia(s-a.startedAt)}}function Ba({activity:t,memory:s=null}){var x;const a=_(),[r,i]=h.useState(Date.now()),n=(x=t==null?void 0:t.snapshot)==null?void 0:x.startedAt;h.useEffect(()=>{if(n===void 0)return;i(Date.now());const l=window.setInterval(()=>i(Date.now()),1e3);return()=>window.clearInterval(l)},[n]);const c=La(t,r);if(!c)return(s==null?void 0:s.outcome)!=="written"?null:e.jsxs("section",{role:"status","aria-live":"polite","data-memory-consolidation-notice":!0,className:"mx-4 mb-2 flex min-h-10 items-center gap-3 rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/80 px-3 py-2 text-[hsl(var(--deck-ink))] shadow-sm md:mx-6",children:[e.jsx(He,{className:"h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))]","aria-hidden":!0}),e.jsx("span",{className:"text-xs font-semibold",children:a("chat.memoryConsolidation.saved",{count:s.entries})})]});const m=[(s==null?void 0:s.outcome)==="written"?a("chat.memoryConsolidation.saved",{count:s.entries}):void 0,...c.tools,c.hiddenTools>0?`+${c.hiddenTools}`:void 0,c.startedTools>0?a("chat.turnActivity.toolCount",{completed:c.completedTools,started:c.startedTools}):void 0,c.turn>0?c.maxTurns===null?a("chat.turnActivity.turn",{turn:c.turn}):a("chat.turnActivity.turnBounded",{turn:c.turn,maxTurns:c.maxTurns}):void 0].filter(l=>l!==void 0);return e.jsxs("section",{role:"status","aria-live":"polite","data-turn-activity-strip":!0,className:"mx-4 mb-2 flex min-h-10 items-center gap-3 rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/80 px-3 py-2 text-[hsl(var(--deck-ink))] shadow-sm md:mx-6",children:[e.jsx(He,{className:"h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))] motion-safe:animate-pulse","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-semibold",children:a(c.phaseKey,c.phaseParams)}),m.length>0&&e.jsx("div",{className:"mt-0.5 truncate font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:m.join(" · ")})]}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))]",children:c.elapsed})]})}function $a(t){const s=[...t].reverse().find(i=>i.role==="user");if(!s)return null;if(typeof s.content=="string")return{content:s.content,attachments:[]};const a=s.content.filter(i=>i.type==="text").map(i=>i.text).join(`
70
- `),r=s.content.filter(i=>i.type==="image_url").map((i,n)=>{var m;const c=((m=i.image_url.url.match(/^data:([^;,]+)[;,]/))==null?void 0:m[1])??"application/octet-stream";return{id:`recovery-${s.id}-${n}`,name:`attachment-${n+1}`,mimeType:c,dataUrl:i.image_url.url}});return{content:a,attachments:r}}function Pa({messages:t,isLoading:s,isStreaming:a,isStopping:r,errorMessage:i}){const n=_(),[c,m]=h.useState(!1),x=n(i?"status.phase.error":r?"chat.input.action.stopping":a?"status.phase.running":"preview.files.status.ready");return e.jsxs("details",{"data-preview-status-disclosure":!0,open:c,onToggle:l=>m(l.currentTarget.open),className:"group hidden",children:[e.jsxs("summary",{className:"flex h-9 cursor-pointer list-none items-center gap-2 px-3 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))]",children:[a&&e.jsx("span",{className:"deck-pulse-dot"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:x}),e.jsx(ce,{className:"h-3.5 w-3.5 shrink-0 transition-transform group-open:rotate-90"})]}),c&&e.jsxs("div",{"data-preview-activity-details":!0,className:"flex h-[min(44vh,420px)] min-h-0 flex-col border-t border-[hsl(var(--deck-hairline))]",children:[i&&e.jsx("div",{role:"alert",className:"border-b border-red-200/60 bg-red-50/80 px-3 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-300",children:i}),e.jsx(gt,{messages:t,isLoading:s}),e.jsx(yt,{})]})]})}function tr(){var se;const t=_(),s=v(y=>y.messages),a=v(y=>y.currentSessionRef),r=v(y=>y.isStreaming),i=v(y=>y.isStopping),n=v(y=>y.providerRecovery),c=v(y=>y.turnActivity),m=v(y=>y.memoryConsolidation),x=v(y=>y.actionStationarity),l=v(y=>y.sessionEventConnectionState),b=v(y=>y.pendingSteeringCount),k=v(y=>y.pendingInputDelivery),u=v(y=>y.recoveredSteeringCount),g=v(y=>y.followUpQueue),p=v(y=>y.followUpQueueMutation),w=v(y=>y.mutateFollowUpQueue),d=v(y=>y.refreshFollowUpQueue),N=v(y=>!!y.historySurfaceSelection),f=v(y=>y.isLoading),S=v(y=>y.error),o=v(y=>y.errorContext),E=v(y=>y.sessions),I=v(y=>y.sendMessage),R=v(y=>y.openSideConversation),j=v(y=>y.abortSession),V=v(y=>y.retryTask),X=v(y=>y.retryingTaskKeys),T=_e(y=>y.openSettings),B=v(y=>y.reconnectSessionEvents),O=v(y=>y.clearError),[P,C]=h.useState(null),M=a?E.find(y=>y.sessionId===a.sessionId&&y.projectPath===a.projectPath):void 0,A=!!S&&((o==null?void 0:o.kind)==="navigation"||!(o!=null&&o.sessionRef)||tt(o.sessionRef,a)),D=(o==null?void 0:o.failureCode)??((se=M==null?void 0:M.taskFailure)==null?void 0:se.code),G=((o==null?void 0:o.kind)==="execution"||o!=null&&o.failureCode)&&D?t(zt(D)):S==="queue_full"?t("chat.error.queueFull"):S==="turn_unavailable"||S==="turn_active"?t("chat.error.turnChanged"):S,ee=l==="connecting"||l==="reconnecting",F=r&&l!=="connected",W=a?`session:${ue(a)}`:"session:temporary",J=h.useMemo(()=>$a(s),[s]),Q=a?ue(a):"temporary-session",z=!!(a&&(M!=null&&M.taskRetryAvailable)&&(!D||qt(D)))&&((o==null?void 0:o.kind)==="execution"||(o==null?void 0:o.kind)==="task_action"),K=(o==null?void 0:o.kind)==="execution"&&(D==="authentication"||D==="permission"||D==="model_unavailable"),Y=a?X.includes(ue(a)):!1;h.useEffect(()=>{C(null)},[Q]);const te=async y=>q(v.getState())?!1:I({content:y.content,modelId:y.modelId,reasoningEffort:y.reasoningEffort,serviceTier:y.serviceTier,responseVerbosity:y.responseVerbosity,communicationStyle:y.communicationStyle,...y.annotations?{annotations:y.annotations}:{},...y.outputSchema?{outputSchema:y.outputSchema}:{},attachments:y.attachments.map(Ne=>({type:"image",content:Ne.dataUrl,mimeType:Ne.mimeType,name:Ne.name}))}),le=()=>{if(!q(v.getState()))return j()},xe=async()=>{if(!q(v.getState())){if(K){O(),T("models");return}if(z&&a){O(),await V(a).catch(()=>{});return}if((o==null?void 0:o.kind)==="execution"&&J){C({...J,revision:Date.now()}),O();return}O(),requestAnimationFrame(()=>Ot())}},$=z?t(Y?"chat.error.action.retryingTask":"chat.error.action.retryTask"):K?t("chat.error.action.checkModels"):(o==null?void 0:o.kind)==="execution"&&J?t("chat.error.action.editResend"):(o==null?void 0:o.kind)==="submission"?t("chat.error.action.returnDraft"):null;return e.jsxs("div",{"data-chat-view":!0,className:"relative flex h-full min-h-0 overflow-hidden bg-[hsl(var(--deck-canvas))]",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("div",{"data-chat-history":!0,className:"contents",children:[A&&e.jsxs("div",{role:"alert","data-blade-session-error":!0,className:"flex min-h-11 flex-wrap items-center gap-2 border-b border-red-200/60 bg-red-50/80 px-4 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-300 sm:px-5",children:[e.jsx(Pe,{className:"h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 break-words",children:[e.jsx("span",{className:"font-semibold",children:t((o==null?void 0:o.kind)==="submission"?"chat.error.title.submission":(o==null?void 0:o.kind)==="execution"?"chat.error.title.execution":(o==null?void 0:o.kind)==="navigation"?"chat.error.title.navigation":"chat.error.title.generic")})," ",G]}),$&&e.jsxs("button",{type:"button",onClick:()=>void xe(),disabled:Y,className:"inline-flex min-h-7 shrink-0 items-center gap-1.5 rounded-md border border-red-300/70 bg-white/65 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 disabled:cursor-wait disabled:opacity-60 dark:border-red-800 dark:bg-red-950/45 dark:hover:bg-red-900/60",children:[z?Y?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx(ve,{className:"h-3 w-3"}):e.jsx(ft,{className:"h-3 w-3"}),$]}),e.jsx("button",{type:"button",onClick:O,"aria-label":t("chat.error.dismiss"),className:"p-1 text-red-500 rounded transition-colors hover:bg-red-100/60 hover:text-red-700 dark:hover:bg-red-950/60 dark:hover:text-red-100",children:"✕"})]}),(ee||l==="offline")&&e.jsxs("div",{role:l==="offline"?"alert":"status","aria-live":"polite",className:"flex min-h-10 flex-wrap items-center gap-2 border-b border-amber-300/60 bg-amber-50/80 px-4 py-2 font-mono text-[11px] text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/35 dark:text-amber-200 sm:px-5",children:[ee?e.jsx(U,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Pt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t(ee?"chat.connection.reconnecting":"chat.connection.offline")}),l==="offline"&&e.jsxs("button",{type:"button",onClick:()=>{q(v.getState())||B().catch(()=>{})},className:"inline-flex min-h-7 items-center gap-1.5 rounded-md border border-amber-400/70 bg-white/60 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/50 dark:hover:bg-amber-900/50",children:[e.jsx(dt,{className:"h-3 w-3"}),t("chat.connection.retry")]})]}),e.jsx(ps,{}),e.jsx(gt,{messages:s,isLoading:f,selectionDraftKey:N?void 0:W,canAskSideConversation:!!(a&&!N),onOpenSideConversation:R},a?ue(a):"temporary-session"),e.jsx(Da,{})]}),e.jsxs("div",{"data-chat-composer-dock":!0,className:"contents",children:[e.jsx(Pa,{messages:s,isLoading:f,isStreaming:r,isStopping:i,errorMessage:A?G:null},Q),e.jsx(ka,{}),e.jsx(ga,{}),e.jsx(fa,{queue:N?null:g,mutation:p,onMutate:w,onRefresh:d}),e.jsx(ja,{recovery:N?null:n,stopping:i,onStop:le}),e.jsx(Ba,{activity:N||n!=null&&n.snapshot||x||M!=null&&M.pendingInteraction?null:c,memory:N?null:m}),e.jsx(_t,{draftKey:W,draft:P==null?void 0:P.content,draftAttachments:P==null?void 0:P.attachments,draftRevision:P==null?void 0:P.revision,onSend:te,onAbort:le,disabled:f||F,isStreaming:r,isStopping:i,pendingSteeringCount:b,pendingInputDelivery:k,recoveredSteeringCount:u,workspacePath:a==null?void 0:a.projectPath},W),e.jsx("div",{"data-chat-primary-status":!0,className:"contents",children:e.jsx(yt,{})})]})]}),e.jsx(Ca,{})]})}export{tr as ChatView};
69
+ `);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"user","data-user-shell-command":!0,className:"flex justify-end p-4 w-full",children:e.jsxs("div",{className:"w-full max-w-[85%] overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 truncate font-mono text-[12px] text-[hsl(var(--deck-ink))]",children:[e.jsx("span",{className:"mr-2 text-amber-600 dark:text-amber-400",children:"$"}),d]}),e.jsx(Ke,{status:N})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:f||"(no output)"}),typeof u.exitCode=="number"&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-1.5 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:["exit ",u.exitCode,typeof u.durationMs=="number"?` · ${(u.durationMs/1e3).toFixed(3)}s`:"",u.truncated===!0?" · truncated":""]})]})})}const{text:g,images:p}=Us(t.content),w=Tt(t.metadata);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"user",className:"flex gap-2 justify-end items-start p-4 w-full group",children:[e.jsx("div",{className:"flex mt-1 opacity-0 transition-opacity shrink-0 group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(Qe,{text:g,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[w.length>0&&e.jsxs("details",{"data-user-message-annotations":!0,className:"mb-2",children:[e.jsxs("summary",{className:"inline-flex min-h-7 cursor-pointer list-none items-center gap-1.5 rounded-md border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))] px-2.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(ct,{"aria-hidden":!0,className:"h-3.5 w-3.5"}),a(w.length===1?"chat.input.annotation.one":"chat.input.annotation.many",{count:w.length})]}),e.jsx("div",{className:"mt-2 space-y-2",children:w.map((d,N)=>e.jsxs("div",{className:"border-l-2 border-[hsl(var(--deck-accent)/0.45)] pl-2",children:[e.jsx("div",{className:"font-mono text-[9.5px] uppercase text-[hsl(var(--deck-ink-faint))]",children:a("chat.input.annotation.item",{index:N+1})}),e.jsx("blockquote",{className:"mt-0.5 whitespace-pre-wrap text-[11px] leading-4 text-[hsl(var(--deck-ink-muted))]",children:d.text}),d.comment&&e.jsx("p",{className:"mt-1 text-[11px] leading-4 text-[hsl(var(--deck-ink))]",children:d.comment})]},d.id))})]}),g&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:g}),p.length>0&&e.jsx("div",{className:L("grid gap-2",p.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:p.map((d,N)=>e.jsx("img",{src:d,alt:`attachment-${N+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${d}-${N}`))})]}),e.jsx(Os,{})]})}const n=Ks(t),c=Cs((b=t.metadata)==null?void 0:b.codeReview),m=Bs((k=t.metadata)==null?void 0:k.structuredOutput);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"assistant",className:L("flex gap-4 justify-start w-full group",s?"p-4":"px-4 pt-0 pb-3"),children:[s?e.jsx(_s,{}):e.jsx("div",{className:"w-8 shrink-0"}),e.jsxs("div",{className:"overflow-hidden flex-1 min-w-0",children:[c?e.jsx(Ts,{report:c}):m?e.jsx($s,{report:m}):e.jsx(Zs,{message:t}),!m&&n.trim()&&e.jsx("div",{className:"mt-1.5 flex opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(Qe,{text:n,label:"Copy response"})})]})]})}const ta=h.memo(ea),pe=8,Xe=10;function sa(t){return t instanceof HTMLElement&&!!t.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')}function aa(){const t=window.visualViewport;return{left:(t==null?void 0:t.offsetLeft)??0,top:(t==null?void 0:t.offsetTop)??0,width:(t==null?void 0:t.width)??window.innerWidth,height:(t==null?void 0:t.height)??window.innerHeight}}function ra(t,s,a){const r=aa(),i=r.left+pe,n=r.left+r.width-s-pe,c=t.left+t.width/2-s/2,m=Math.max(i,Math.min(Math.max(i,n),c)),x=t.bottom+Xe,l=t.top-a-Xe,b=r.top+r.height-a-pe,k=x<=b?x:Math.max(r.top+pe,Math.min(b,l));return{left:m,top:k}}function na({rootRef:t,draftKey:s,canAskSideConversation:a,onOpenSideConversation:r}){const i=_(),n=h.useRef(null),c=h.useRef(null),m=h.useRef(!1),x=h.useRef("actions"),[l,b]=h.useState(null),[k,u]=h.useState("actions"),[g,p]=h.useState(""),[w,d]=h.useState(null),N=h.useCallback(E=>{m.current=!1,x.current=E,u(E),p("")},[]),f=h.useCallback(()=>{var E;m.current=!1,x.current="actions",u("actions"),p(""),b(null),d(null),(E=window.getSelection())==null||E.removeAllRanges()},[]),S=h.useCallback(E=>{var C,M;if(!l||l.tooLarge)return;const B=((M=(C=globalThis.crypto)==null?void 0:C.randomUUID)==null?void 0:M.call(C))??`selection-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,O=E==null?void 0:E.trim();At(s,{id:B,text:l.text,sourceMessageId:l.messageId,sourceRole:l.role,...O?{comment:O}:{}})&&f()},[f,s,l]),o=h.useCallback(()=>{!l||l.tooLarge||!a||r(l.text)&&f()},[a,f,r,l]),T=h.useCallback(()=>{if(x.current!=="actions")return;const E=t.current;if(!E)return;const B=Rt(E,window.getSelection());b(B),d(null)},[t]);if(h.useEffect(()=>{var M;let E=0;const B=()=>{window.cancelAnimationFrame(E),E=window.requestAnimationFrame(T)},O=A=>{var D;(D=n.current)!=null&&D.contains(A.target)||l&&(m.current=!1,x.current="actions",u("actions"),p(""),b(null))},P=A=>{var D;(D=n.current)!=null&&D.contains(A.target)||f()},C=A=>{if(!(!l||m.current||A.isComposing||A.keyCode===229)){if(A.key==="Escape"){A.preventDefault(),f();return}if(!(x.current!=="actions"||sa(A.target))){if((A.metaKey||A.ctrlKey)&&A.key.toLowerCase()==="j"){A.preventDefault(),N("comment");return}A.key==="Enter"&&(A.preventDefault(),S())}}};return document.addEventListener("selectionchange",B),document.addEventListener("pointerup",B),document.addEventListener("pointerdown",O),document.addEventListener("keydown",C),document.addEventListener("scroll",P,!0),window.addEventListener("resize",f),(M=window.visualViewport)==null||M.addEventListener("resize",f),()=>{var A;window.cancelAnimationFrame(E),document.removeEventListener("selectionchange",B),document.removeEventListener("pointerup",B),document.removeEventListener("pointerdown",O),document.removeEventListener("keydown",C),document.removeEventListener("scroll",P,!0),window.removeEventListener("resize",f),(A=window.visualViewport)==null||A.removeEventListener("resize",f)}},[S,T,f,l,N]),h.useLayoutEffect(()=>{if(!l||!n.current)return;const E=n.current.getBoundingClientRect();d(ra(l.rect,E.width,E.height))},[k,l]),h.useEffect(()=>{k!=="actions"&&requestAnimationFrame(()=>{var E;return(E=c.current)==null?void 0:E.focus()})},[k]),!l||typeof document>"u")return null;const R=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/u.test(navigator.userAgent)?"⌘ J":"Ctrl J",j=l.tooLarge?i("chat.selection.tooLarge"):a?void 0:i("chat.selection.sideUnavailable"),V={left:(w==null?void 0:w.left)??0,top:(w==null?void 0:w.top)??0,visibility:w?"visible":"hidden"},X=E=>{if(!(m.current||E.nativeEvent.isComposing||E.keyCode===229)){if((E.metaKey||E.ctrlKey)&&E.key.toLocaleLowerCase()==="a"){E.preventDefault(),E.stopPropagation(),E.currentTarget.select();return}if(E.key==="Escape"){E.preventDefault(),f();return}E.key!=="Enter"||E.shiftKey||(E.preventDefault(),S(g))}};return jt.createPortal(e.jsx("div",{ref:n,"data-chat-selection-overlay":!0,style:V,className:"fixed z-50 max-w-[calc(100vw-1rem)]",onPointerDown:E=>E.stopPropagation(),onPointerUp:E=>E.stopPropagation(),children:k==="actions"?e.jsxs("div",{role:"toolbar","aria-label":i("chat.selection.toolbar"),className:"grid min-w-[250px] overflow-hidden rounded-lg border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/98 text-[hsl(var(--deck-ink))] shadow-xl backdrop-blur-md divide-y divide-[hsl(var(--deck-border))] sm:flex sm:min-w-0 sm:divide-x sm:divide-y-0",onPointerDown:E=>E.preventDefault(),children:[e.jsxs("button",{type:"button","aria-keyshortcuts":"Meta+J Control+J",disabled:l.tooLarge,onClick:()=>N("comment"),className:"flex min-h-11 items-center gap-2 whitespace-nowrap px-3 text-left text-[12px] transition-colors hover:bg-[hsl(var(--deck-surface-2))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))] disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(ct,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:i("chat.selection.comment")}),e.jsx("kbd",{className:"ml-auto font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:R})]}),e.jsxs("button",{type:"button","aria-keyshortcuts":"Enter",disabled:l.tooLarge,onClick:()=>S(),className:"flex min-h-11 items-center gap-2 whitespace-nowrap px-3 text-left text-[12px] transition-colors hover:bg-[hsl(var(--deck-surface-2))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))] disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(Jt,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:i("chat.selection.add")}),e.jsx("kbd",{className:"ml-auto font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:"↵"})]}),e.jsxs("button",{type:"button",disabled:!!j,title:j,onClick:o,className:"flex min-h-11 items-center gap-2 whitespace-nowrap px-3 text-left text-[12px] transition-colors hover:bg-[hsl(var(--deck-surface-2))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))] disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(De,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:i("chat.selection.askSide")})]})]}):e.jsxs("form",{role:"dialog","aria-label":i("chat.selection.commentDialog"),className:"w-[min(360px,calc(100vw-1rem))] rounded-lg border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))] p-2 shadow-xl",onSubmit:E=>{E.preventDefault(),S(g)},children:[e.jsx("div",{className:"mb-2 line-clamp-2 border-l-2 border-[hsl(var(--deck-accent)/0.55)] pl-2 font-mono text-[10.5px] leading-4 text-[hsl(var(--deck-ink-muted))]",children:l.text}),e.jsx("textarea",{ref:c,name:"selected-conversation-comment",maxLength:Ht,rows:3,value:g,onChange:E=>p(E.target.value),onCompositionStart:()=>{m.current=!0},onCompositionEnd:()=>{m.current=!1},onBlur:()=>{m.current=!1},onKeyDown:X,"aria-label":i("chat.selection.commentInput"),placeholder:i("chat.selection.commentPlaceholder"),className:"block max-h-32 min-h-[72px] w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-2.5 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] placeholder:text-[hsl(var(--deck-ink-faint))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:f,className:"h-8 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-surface-2))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:i("chat.selection.cancel")}),e.jsxs("button",{type:"submit",className:"inline-flex h-8 items-center gap-1.5 rounded-md bg-[hsl(var(--deck-accent))] px-3 text-[11px] font-medium text-white transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[hsl(var(--deck-accent))] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-45",children:[i("chat.selection.add"),e.jsx(is,{"aria-hidden":!0,className:"h-3 w-3"})]})]})]})}),document.body)}function ia(t,s,a){return Math.max(0,t+(a-s))}function oa(t,s,a){return Math.min(s,Math.max(0,t)+Math.max(0,a))}function ca(t,s,a,r){const i=new Map(t.filter(c=>!!c.id).map(c=>[c.id,c])),n=new Set(a);for(const c of s){if(!c.id)continue;const m=i.get(c.id);m!==c&&(!m||!r||r(m)!==r(c))&&n.add(c.id)}return n}function Ze(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function la({turns:t,viewportRef:s,containerRef:a,onRevealTurn:r}){const i=_(),[n,c]=h.useState(null),[m,x]=h.useState(!1),l=h.useRef(null),b=h.useCallback(()=>{var d;const u=s.current,g=a.current;if(!u||!g||t.length===0)return;const p=u.getBoundingClientRect().top;let w=((d=t[0])==null?void 0:d.id)??null;for(const N of t){const f=Ze(g,N.id);if(f)if(f.getBoundingClientRect().top-p<=24)w=N.id;else break}c(w)},[t,s,a]);h.useEffect(()=>{const u=s.current;if(!u)return;const g=()=>{l.current===null&&(l.current=window.requestAnimationFrame(()=>{l.current=null,b()}))};return b(),u.addEventListener("scroll",g,{passive:!0}),()=>{u.removeEventListener("scroll",g),l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null)}},[b,s]);const k=h.useCallback(u=>{const g=()=>{const w=Ze(a.current,u.id);w&&(w.scrollIntoView({behavior:"smooth",block:"start"}),c(u.id))};r(u.index)?g():window.requestAnimationFrame(()=>window.requestAnimationFrame(g))},[a,r]);return t.length<2?null:e.jsx("nav",{"aria-label":i("chat.turns.aria"),className:"absolute right-1 top-1/2 z-20 hidden -translate-y-1/2 sm:block",onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),onFocusCapture:()=>x(!0),onBlurCapture:u=>{u.currentTarget.contains(u.relatedTarget)||x(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:L("flex flex-col items-center gap-2 py-2 transition-opacity",m?"opacity-0":"opacity-100"),"aria-hidden":m,children:t.map(u=>e.jsx("li",{children:e.jsx("span",{className:L("block rounded-full transition-all",u.id===n?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},u.id))}),e.jsx("div",{className:L("absolute right-0 max-h-[min(70vh,520px)] w-[280px] overflow-y-auto rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/95 p-1 shadow-xl backdrop-blur transition-all",m?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((u,g)=>e.jsxs("button",{type:"button",onClick:()=>k(u),className:L("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u.id===n?"bg-[hsl(var(--deck-hairline))]/70 text-[hsl(var(--deck-ink))]":"text-[hsl(var(--deck-ink-muted))] hover:bg-[hsl(var(--deck-hairline))]/50 hover:text-[hsl(var(--deck-ink))]"),children:[e.jsx("span",{className:L("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",u.id===n?"bg-[hsl(var(--deck-accent))]":"bg-[hsl(var(--deck-ink-faint))]/40")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[9.5px] uppercase tracking-[0.12em] text-[hsl(var(--deck-ink-faint))]",children:i("chat.turns.label",{n:g+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:u.preview})]})]},u.id))})]})})}const et=80;function da(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ua(t){const s=da(t).replace(/\s+/g," ").trim();return s?s.length>et?`${s.slice(0,et-1)}…`:s:""}function ma(t){const s=[];for(let a=0;a<t.length;a+=1){const r=t[a];if(r.role!=="user"||!r.id)continue;const i=ua(r.content);i&&s.push({id:r.id,index:a,preview:i})}return s}const Ee=120,Te=80,ha=96;function de(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function xa(t){return JSON.stringify([t.role,t.content,t.metadata,t.agentContent])}function pa({messages:t,isLoading:s,selectionDraftKey:a,canAskSideConversation:r=!1,onOpenSideConversation:i}){const n=_(),c=h.useMemo(()=>ys(t),[t]),m=h.useRef(null),x=h.useRef(null),l=h.useRef(!0),b=h.useRef(!1),k=h.useRef(c),u=h.useRef(c),g=h.useRef(new Set),p=h.useRef(c.length),w=h.useRef(null),[d,N]=h.useState(Ee),[f,S]=h.useState(!1),[o,T]=h.useState(0),I=c.length>0;k.current=c,h.useEffect(()=>{const C=de(m.current);if(!C||b.current&&!l.current)return;const M=window.requestAnimationFrame(()=>{C.scrollTop=C.scrollHeight,b.current=!0,l.current=!0,g.current=new Set,T(0),S(!1)});return()=>window.cancelAnimationFrame(M)},[c]),h.useEffect(()=>{const C=de(m.current);if(!C)return;x.current=C;const M=()=>{if(!b.current)return;const D=C.scrollHeight-C.scrollTop-C.clientHeight<=ha,G=l.current;l.current=D,S(!D),D?(g.current=new Set,T(0)):G&&(u.current=k.current,g.current=new Set,T(0))};return M(),C.addEventListener("scroll",M,{passive:!0}),()=>C.removeEventListener("scroll",M)},[I,s]),h.useEffect(()=>{const C=u.current;if(u.current=c,l.current){g.current.size>0&&(g.current=new Set,T(0));return}const M=ca(C,c,g.current,xa);g.current=M,T(M.size)},[c]),h.useEffect(()=>{const C=p.current;p.current=c.length,N(M=>M>=C&&c.length>C?c.length:Math.min(Math.max(M,Ee),c.length||Ee))},[c.length]);const R=Math.max(c.length-d,0),j=R,V=h.useMemo(()=>c.slice(j),[c,j]),X=h.useMemo(()=>ma(c),[c]);if(h.useLayoutEffect(()=>{var A;const C=w.current;if(!C)return;const M=de(m.current);if(w.current=null,!!M){if((A=C.element)!=null&&A.isConnected){const D=C.element.getBoundingClientRect().top-C.viewportTop;M.scrollTop+=D;return}M.scrollTop=ia(C.scrollTop,C.scrollHeight,M.scrollHeight)}},[d]),s)return e.jsx("div",{role:"status","aria-live":"polite","aria-busy":"true",className:"flex overflow-hidden flex-1 justify-center items-center px-5 py-8 min-h-0",children:e.jsxs("div",{className:"w-full max-w-[560px]",children:[e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 animate-pulse rounded-full bg-[hsl(var(--deck-accent-soft))] blur-xl"}),e.jsx(Re,{size:42,className:"relative"})]}),e.jsxs("div",{className:"mt-4 inline-flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--deck-accent))]",children:[e.jsx(Dt,{className:"w-3 h-3"}),n("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:n("chat.list.loading.title")}),e.jsx("p",{className:"mt-1 max-w-sm text-[11.5px] leading-5 text-[hsl(var(--deck-ink-faint))]",children:n("chat.list.loading.hint")})]}),e.jsx("div",{"aria-hidden":"true",className:"mt-7 space-y-4 rounded-xl border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))]/45 px-4 py-5",children:[72,88,64].map((C,M)=>e.jsxs("div",{className:L("flex gap-3",M%2===1&&"flex-row-reverse"),children:[e.jsx("span",{className:"h-7 w-7 shrink-0 animate-pulse rounded-md bg-[hsl(var(--deck-surface-2))]"}),e.jsx("span",{className:"h-10 animate-pulse rounded-lg bg-[hsl(var(--deck-surface-2))]",style:{width:`${C}%`,animationDelay:`${M*120}ms`}})]},C))})]})});if(c.length===0&&!s)return e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsxs("div",{className:"flex flex-col gap-4 items-center text-center",children:[e.jsx(Re,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:n("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:n("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:n("chat.list.empty.hint")})]})]})});const E=()=>{const C=de(m.current);C&&(C.scrollTop=C.scrollHeight,l.current=!0,b.current=!0,g.current=new Set,T(0),S(!1))},B=()=>{var M;const C=de(m.current);if(C){const A=((M=m.current)==null?void 0:M.querySelector("[data-chat-message-id]"))??null;w.current={element:A,viewportTop:(A==null?void 0:A.getBoundingClientRect().top)??0,scrollHeight:C.scrollHeight,scrollTop:C.scrollTop}}N(A=>oa(A,c.length,Te))},O=C=>C>=j?!0:(N(c.length),!1),P=o===1?n("chat.list.unreadMessage"):n("chat.list.unreadMessages",{count:o});return e.jsxs("div",{ref:m,className:"relative flex-1 min-h-0",children:[e.jsx(Wt,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[R>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:B,"aria-label":n("chat.list.showEarlierWithRemaining",{count:Math.min(R,Te),remaining:R}),className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-3 py-1.5 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:border-[hsl(var(--deck-border-strong))] hover:text-[hsl(var(--deck-ink))]",children:n("chat.list.showEarlier",{count:Math.min(R,Te)})})}),V.map((C,M)=>{const A=j+M,D=A>0?c[A-1]:null,G=!D||D.role!==C.role||D.role==="user";return e.jsx(ta,{message:C,showAvatar:G},C.id||`msg-${A}`)})]})}),e.jsx(la,{turns:X,viewportRef:x,containerRef:m,onRevealTurn:O}),a&&i&&e.jsx(na,{rootRef:m,draftKey:a,canAskSideConversation:r,onOpenSideConversation:i}),f&&e.jsxs("button",{type:"button",onClick:E,"aria-live":"polite","aria-label":o>0?P:n("chat.list.jumpLatest"),className:"absolute bottom-4 left-1/2 z-10 inline-flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/95 px-3 py-1.5 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] shadow-lg backdrop-blur transition-colors hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(Oe,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),o>0?P:n("chat.list.jumpLatest")]})]})}const gt=h.memo(pa);function fa({queue:t,mutation:s,onMutate:a,onRefresh:r}){const i=_(),[n,c]=h.useState(!1),m=h.useRef(null),x=h.useRef(null),l=h.useRef(null);h.useLayoutEffect(()=>{var p,w,d;if(s.pending||!m.current)return;const u=m.current;m.current=null,(d=Array.from(((p=x.current)==null?void 0:p.querySelectorAll("[data-follow-up-focus-id]"))??[]).find(N=>N.dataset.followUpFocusId===u)??((w=x.current)==null?void 0:w.querySelector("button")))==null||d.focus()},[s.pending,t==null?void 0:t.version]);const b=h.useCallback(async u=>{m.current=u.messageId,await a(u)},[a]),k=h.useCallback((u,g)=>{b({type:"move",messageId:u,toPosition:g})},[b]);return!t||t.pending===0&&!s.errorMessage?null:e.jsxs("section",{ref:x,"data-blade-follow-up-queue":!0,className:"mx-4 mb-2 overflow-hidden rounded-lg border border-amber-300/70 bg-amber-50/70 shadow-sm dark:border-amber-900/60 dark:bg-amber-950/25 md:mx-6","aria-label":i("chat.followUpQueue.title"),children:[e.jsxs("button",{type:"button","aria-label":i(n?"chat.followUpQueue.hide":"chat.followUpQueue.show"),"aria-expanded":n,onClick:()=>c(u=>!u),className:"flex min-h-10 w-full items-center gap-2 px-3 text-left font-mono text-[11px] text-amber-950 transition-colors hover:bg-amber-100/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-amber-500 dark:text-amber-100 dark:hover:bg-amber-900/35",children:[e.jsx(ds,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":!0}),e.jsx("span",{className:"font-semibold",children:i("chat.followUpQueue.count",{count:t.pending})}),t.locked>0&&e.jsx("span",{className:"text-amber-700/80 dark:text-amber-300/75",children:i("chat.followUpQueue.lockedCount",{count:t.locked})}),e.jsx(ce,{className:`ml-auto h-3.5 w-3.5 transition-transform ${n?"rotate-90":""}`,"aria-hidden":!0})]}),n&&e.jsxs("div",{className:"border-t border-amber-300/60 px-2 py-2 dark:border-amber-900/50",children:[s.errorMessage&&e.jsxs("div",{role:"alert",className:"mb-2 flex items-center gap-2 rounded-md border border-red-200 bg-red-50 px-2.5 py-2 text-[11px] text-red-700 dark:border-red-900/60 dark:bg-red-950/35 dark:text-red-300",children:[e.jsx("span",{className:"min-w-0 flex-1",children:s.errorCode==="revision_conflict"?i("chat.followUpQueue.stale"):s.errorMessage}),r&&e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.refresh"),onClick:()=>void r(),className:"rounded p-1 hover:bg-red-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 dark:hover:bg-red-900/60",children:e.jsx(dt,{className:"h-3.5 w-3.5","aria-hidden":!0})})]}),e.jsx("ol",{className:"space-y-1.5",children:t.items.map((u,g)=>{const p=t.items[g-1],w=t.items[g+1],d=u.mutable&&(p==null?void 0:p.mutable)===!0,N=u.mutable&&(w==null?void 0:w.mutable)===!0,f=s.pending;return e.jsxs("li",{"data-follow-up-id":u.id,"data-follow-up-state":u.state,"data-follow-up-focus-id":u.id,tabIndex:-1,draggable:u.mutable&&!s.pending,onDragStart:()=>{l.current=u.mutable?u.id:null},onDragOver:S=>{const o=l.current,T=t.items.find(I=>I.id===o);T!=null&&T.mutable&&u.mutable&&S.preventDefault()},onDrop:S=>{S.preventDefault();const o=l.current;l.current=null;const T=t.items.find(j=>j.id===o);if(!(T!=null&&T.mutable)||!u.mutable||T.id===u.id)return;const I=Math.min(T.position,u.position),R=Math.max(T.position,u.position);t.items.slice(I,R+1).some(j=>!j.mutable)||k(T.id,u.position)},onDragEnd:()=>{l.current=null},className:"flex min-w-0 items-center gap-2 rounded-md border border-amber-200/70 bg-white/75 px-2.5 py-2 dark:border-amber-900/50 dark:bg-zinc-950/45",children:[e.jsx("span",{className:"w-5 shrink-0 text-center font-mono text-[10px] text-amber-700 dark:text-amber-400",children:g+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-xs text-[hsl(var(--deck-ink))]",children:u.kind==="internal"?i("chat.followUpQueue.internal"):u.preview||i("chat.followUpQueue.attachmentOnly")}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 font-mono text-[9px] uppercase tracking-[0.08em] text-[hsl(var(--deck-ink-faint))]",children:[e.jsx("span",{children:i(`chat.followUpQueue.delivery.${u.delivery}`)}),!u.mutable&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(us,{className:"h-2.5 w-2.5","aria-hidden":!0}),i("chat.followUpQueue.locked")]}),u.attachmentCount>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ft,{className:"h-2.5 w-2.5","aria-hidden":!0}),u.attachmentCount]})]})]}),f&&s.messageId===u.id?e.jsx(U,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-amber-600"}):e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.moveUp",{id:u.id}),disabled:f||!d,onClick:()=>k(u.id,g-1),className:"rounded p-1 text-amber-800 transition-colors hover:bg-amber-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-500 disabled:opacity-30 dark:text-amber-300 dark:hover:bg-amber-900/50",children:e.jsx(Yt,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.moveDown",{id:u.id}),disabled:f||!N,onClick:()=>k(u.id,g+1),className:"rounded p-1 text-amber-800 transition-colors hover:bg-amber-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-amber-500 disabled:opacity-30 dark:text-amber-300 dark:hover:bg-amber-900/50",children:e.jsx(Oe,{className:"h-3.5 w-3.5","aria-hidden":!0})}),e.jsx("button",{type:"button","aria-label":i("chat.followUpQueue.remove",{id:u.id}),disabled:f||!u.mutable,onClick:()=>void b({type:"remove",messageId:u.id}),className:"rounded p-1 text-red-600 transition-colors hover:bg-red-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 disabled:opacity-30 dark:text-red-400 dark:hover:bg-red-950/60",children:e.jsx(ie,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})]},u.id)})})]})]})}const Ie=Zt,Le=es,Be=ts,ye=h.forwardRef(({className:t,sideOffset:s=4,...a},r)=>e.jsx(pt,{ref:r,sideOffset:s,className:L("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",t),...a}));ye.displayName=pt.displayName;const ba={active:{labelKey:"goal.status.active",dot:"bg-[hsl(var(--deck-accent))] shadow-[0_0_6px_hsl(var(--deck-accent-glow)/0.5)]",accent:"text-[hsl(var(--deck-accent))]"},verifying:{labelKey:"goal.status.active",dot:"animate-pulse bg-sky-400",accent:"text-sky-600 dark:text-sky-300"},paused:{labelKey:"goal.status.paused",dot:"bg-amber-400",accent:"text-amber-600 dark:text-amber-300"},blocked:{labelKey:"goal.status.blocked",dot:"bg-rose-500",accent:"text-rose-600 dark:text-rose-300"},usage_limited:{labelKey:"goal.status.usageLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},budget_limited:{labelKey:"goal.status.budgetLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},complete:{labelKey:"goal.status.complete",dot:"bg-emerald-500",accent:"text-emerald-600 dark:text-emerald-300"}};function fe(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function va(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),a=t%60;return a===0?`${s}m`:`${s}m ${a}s`}function ga(){var E,B,O,P,C,M,A,D,G,ee,F,W,J,Q,z,K,Y,te,le,xe;const t=_(),{locale:s}=ut(),a=v($=>$.goal),r=v($=>$.pauseGoal),i=v($=>$.resumeGoal),n=v($=>$.editGoal),c=v($=>$.clearGoal),m=v($=>oe($.historySurfaceSelection)),[x,l]=h.useState(!1),[b,k]=h.useState(!1),[u,g]=h.useState(""),[p,w]=h.useState(null),[d,N]=h.useState(!1);if(h.useEffect(()=>{l(!1),k(!1),g((a==null?void 0:a.objective)??""),N(!1)},[a==null?void 0:a.goalId]),m||!a)return null;const f=ba[a.status],S=["active","verifying","paused","blocked"].includes(a.status),o=a.status==="active"||a.status==="verifying",T=a.status==="paused"||a.status==="blocked",I=p!==null,R=async($,se)=>{if(!q(v.getState())){w($);try{await se()}finally{w(null)}}},j=()=>{g(a.objective),k(!0),l(!0)},V=async $=>{$.preventDefault();const se=u.trim();if(!se||se===a.objective){k(!1);return}await R("edit",()=>n(se)),k(!1)},X=async()=>{await R("delete",c),N(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Ie,{delayDuration:250,children:e.jsxs("section",{"aria-label":t("goal.aria.section"),className:"mx-3 mb-1 shrink-0","data-blade-goal-status":a.status,"data-blade-goal-recovery":(E=a.prematureStop)==null?void 0:E.consecutiveCount,"data-blade-goal-recovery-pattern":(B=a.prematureStop)==null?void 0:B.pattern,"data-blade-goal-verification-stall":(O=a.verificationStall)==null?void 0:O.consecutiveCount,"data-blade-goal-frontier-task-list":(P=a.executionFrontier)==null?void 0:P.taskListId,"data-blade-goal-frontier-total":(C=a.executionFrontier)==null?void 0:C.total,"data-blade-goal-frontier-completed":(M=a.executionFrontier)==null?void 0:M.completed,"data-blade-goal-frontier-in-progress":(A=a.executionFrontier)==null?void 0:A.inProgress,"data-blade-goal-frontier-pending":(D=a.executionFrontier)==null?void 0:D.pending,"data-blade-goal-frontier-blocked":(G=a.executionFrontier)==null?void 0:G.blocked,"data-blade-goal-frontier-next-task":(F=(ee=a.executionFrontier)==null?void 0:ee.nextTask)==null?void 0:F.id,"data-blade-goal-frontier-digest":(W=a.executionFrontier)==null?void 0:W.digestSha256.slice(0,16),"data-blade-goal-frontier-stall":(J=a.frontierStall)==null?void 0:J.category,"data-blade-goal-frontier-stall-count":(Q=a.frontierStall)==null?void 0:Q.consecutiveCount,"data-blade-goal-execution-host-failure":(z=a.executionHostFailure)==null?void 0:z.category,"data-blade-goal-execution-host-failure-count":(K=a.executionHostFailure)==null?void 0:K.consecutiveCount,"data-blade-goal-root-turn":(Y=a.turnLineage)==null?void 0:Y.rootTurnId,"data-blade-goal-current-turn":(te=a.turnLineage)==null?void 0:te.currentTurnId,"data-blade-goal-parent-turn":(le=a.turnLineage)==null?void 0:le.parentTurnId,children:[e.jsxs("div",{className:L("flex h-9 items-center gap-2 rounded-lg border px-3 transition-colors","border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 backdrop-blur-sm",x&&"rounded-b-none border-b-0"),children:[a.status==="complete"?e.jsx(It,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(ms,{className:L("h-3.5 w-3.5 shrink-0",f.accent)}),e.jsx("span",{className:L("h-1.5 w-1.5 shrink-0 rounded-full",f.dot)}),e.jsx("span",{className:L("shrink-0 text-[10px] font-medium leading-none",f.accent),children:a.status==="verifying"?s==="zh"?"验证中":"Verifying":t(f.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(x?"goal.action.collapse":"goal.action.expand"),className:"min-w-0 flex-1 truncate text-left text-[12px] leading-5 text-[hsl(var(--deck-ink))]/85 outline-none transition-colors hover:text-[hsl(var(--deck-ink))]",onClick:()=>l($=>!$),"aria-expanded":x,title:a.objective,children:a.objective}),a.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[fe(a.tokensUsed),a.tokenBudget!==void 0&&`/${fe(a.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[o&&e.jsx(be,{label:t("goal.action.pause"),disabled:I,onClick:()=>void R("pause",r),children:p==="pause"?e.jsx(U,{className:"animate-spin"}):e.jsx(ss,{})}),T&&e.jsx(be,{label:t("goal.action.resume"),disabled:I,onClick:()=>void R("resume",i),children:p==="resume"?e.jsx(U,{className:"animate-spin"}):e.jsx(as,{})}),e.jsx(be,{label:t(S?"goal.action.edit":"goal.action.expand"),disabled:!S&&!x,onClick:S?j:()=>l($=>!$),children:S?e.jsx(ft,{}):e.jsx(Xt,{})}),e.jsx(be,{label:t("goal.action.delete"),disabled:I,destructive:!0,onClick:()=>N(!0),children:e.jsx(ie,{})})]})]}),x&&e.jsx("div",{className:"rounded-b-lg border border-t-0 border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 px-4 py-3 backdrop-blur-sm",children:b?e.jsxs("form",{onSubmit:V,children:[e.jsx("textarea",{id:"goal-objective",value:u,onChange:$=>g($.target.value),onKeyDown:$=>{$.key==="Escape"&&k(!1)},rows:3,autoFocus:!0,className:"w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] outline-none transition-shadow focus:border-[hsl(var(--deck-accent))] focus:ring-1 focus:ring-[hsl(var(--deck-accent-glow))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>k(!1),className:"inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-hairline))]/60",children:[e.jsx(mt,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!u.trim()||p==="edit",className:"inline-flex h-7 items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2.5 text-[11px] font-medium text-white transition-colors hover:bg-[hsl(var(--deck-accent))]/90 disabled:cursor-not-allowed disabled:opacity-50",children:[p==="edit"?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx(je,{className:"h-3 w-3"}),t("goal.action.save")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink))]/90",children:a.objective}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(cs,{className:"h-3 w-3"}),fe(a.tokensUsed),a.tokenBudget!==void 0&&` / ${fe(a.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(hs,{className:"h-3 w-3"}),va(a.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ve,{className:"h-3 w-3"}),a.continuationCount===1?t("goal.metrics.continuationOne",{n:a.continuationCount}):t("goal.metrics.continuationMany",{n:a.continuationCount})]})]}),a.turnLineage&&e.jsxs("div",{className:"mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 rounded-md border border-[hsl(var(--deck-border))]/50 bg-[hsl(var(--deck-canvas))]/45 px-2.5 py-2 font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx("span",{children:t("goal.lineage.origin")}),e.jsx("span",{className:"truncate",children:a.turnLineage.rootTurnId??"?"}),e.jsx("span",{children:t("goal.lineage.current")}),e.jsx("span",{className:"truncate",children:a.turnLineage.currentTurnId}),e.jsx("span",{children:t("goal.lineage.parent")}),e.jsx("span",{className:"truncate",children:a.turnLineage.parentTurnId??"?"})]}),a.prematureStop&&e.jsxs("div",{className:"mt-2 inline-flex items-center gap-1.5 font-mono text-[10px] text-amber-700 dark:text-amber-300",children:[e.jsx(ve,{className:"h-3 w-3"}),s==="zh"?"恢复提示":"Recovery nudge"," ",a.prematureStop.consecutiveCount," ·"," ",a.prematureStop.pattern.replaceAll("_"," ")]}),a.executionHostFailure&&e.jsxs("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-2 text-[11px] text-amber-900 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-100",children:[e.jsx("p",{className:"font-medium",children:t("goal.executionHostFailure.title")}),e.jsxs("p",{className:"mt-1 font-mono opacity-80",children:[t(`goal.executionHostFailure.category.${a.executionHostFailure.category}`)," ","· ",a.executionHostFailure.consecutiveCount,"/3"]})]}),a.completionVerification&&e.jsxs("div",{"data-goal-verification":a.completionVerification.status,className:"mt-2 rounded-md border border-sky-200/50 bg-sky-50/60 px-2.5 py-2 text-[11px] text-sky-900 dark:border-sky-400/15 dark:bg-sky-400/[0.05] dark:text-sky-100",children:[e.jsxs("p",{className:"font-mono font-medium",children:["#",a.completionVerification.attempt," ·"," ",a.completionVerification.status.toUpperCase()," ·"," ",((xe=a.completionVerification.verifierSessionId)==null?void 0:xe.slice(0,12))??"-",a.verificationStall?s==="zh"?` · 重复 ${a.verificationStall.consecutiveCount}/3`:` · repeat ${a.verificationStall.consecutiveCount}/3`:""]}),a.completionVerification.summary&&e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap opacity-80",children:a.completionVerification.summary}),a.completionVerification.evidenceSha256&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] opacity-60",children:["sha256:",a.completionVerification.evidenceSha256.slice(0,12)]})]}),a.statusReason&&e.jsx("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-1.5 text-[11px] text-amber-800 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-200",children:a.statusReason})]})})]})}),e.jsx(at,{open:d,onOpenChange:N,children:e.jsxs(rt,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(nt,{children:t("goal.dialog.title")}),e.jsx(it,{children:t("goal.dialog.description")}),e.jsxs(ot,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>N(!1),className:"inline-flex h-8 items-center justify-center rounded-md border border-[hsl(var(--deck-border))] px-3 text-[12px] text-[hsl(var(--deck-ink))] hover:bg-[hsl(var(--deck-hairline))]/60",children:t("goal.action.cancel")}),e.jsxs("button",{type:"button",disabled:p==="delete",onClick:()=>void X(),className:"inline-flex gap-1.5 justify-center items-center px-3 h-8 text-[12px] font-medium text-white bg-rose-600 rounded-md hover:bg-rose-500 disabled:opacity-50",children:[p==="delete"&&e.jsx(U,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function be({label:t,children:s,disabled:a,destructive:r,onClick:i}){return e.jsxs(Le,{children:[e.jsx(Be,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:a,onClick:i,className:L("flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-muted))] outline-none transition-colors focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent-glow))]/50 disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",r?"hover:bg-rose-500/10 hover:text-rose-500":"hover:bg-[hsl(var(--deck-hairline))]/60 hover:text-[hsl(var(--deck-ink))]"),children:s})}),e.jsx(ye,{side:"top",className:"text-[10px]",children:t})]})}function ka(){const t=_(),s=v(l=>l.currentSessionRef),a=v(l=>l.sessions),r=v(l=>l.messages),i=v(l=>oe(l.historySurfaceSelection)),n=h.useMemo(()=>{var b,k,u,g,p;const l=s?(b=Lt(a,s))==null?void 0:b.pendingInteraction:void 0;if(l)return l.type;for(let w=r.length-1;w>=0;w-=1){const d=(k=r[w])==null?void 0:k.agentContent;if(((u=d==null?void 0:d.confirmation)==null?void 0:u.status)==="pending")return"permission";if(((g=d==null?void 0:d.question)==null?void 0:g.status)==="pending")return"question";if(((p=d==null?void 0:d.elicitation)==null?void 0:p.status)==="pending")return"elicitation"}return null},[s,r,a]);if(i||!n)return null;const c=()=>{const l=document.querySelector(`[data-pending-interaction="${n}"]`);l==null||l.scrollIntoView({block:"center",behavior:"smooth"}),window.setTimeout(()=>l==null?void 0:l.focus(),250)},m=n==="question",x=n==="elicitation";return e.jsxs("div",{role:"alert",className:"mx-3 mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-amber-300/80 bg-amber-50/95 px-3 py-2 font-mono text-amber-950 shadow-sm backdrop-blur dark:border-amber-800/80 dark:bg-amber-950/90 dark:text-amber-100 sm:mx-5",children:[e.jsx(Pe,{className:"h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-[180px] flex-1",children:[e.jsx("div",{className:"text-[11.5px] font-semibold",children:t(m?"interaction.bar.questionTitle":x?"interaction.bar.elicitationTitle":"interaction.bar.permissionTitle")}),e.jsx("div",{className:"mt-0.5 text-[10px] leading-4 text-amber-800 dark:text-amber-300",children:t(m?"interaction.bar.questionHint":x?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:c,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/80 bg-white/80 px-2.5 text-[10.5px] font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/70 dark:hover:bg-amber-900",children:[e.jsx(Oe,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}function me(t){return Math.max(0,Math.ceil((t??0)/1e3))}function ya(t,s=Date.now()){var r;const a=(r=t.snapshot)==null?void 0:r.nextActionAt;return a===void 0?void 0:me(a-s)}function kt(t,s=Date.now()){const a=t==null?void 0:t.snapshot;if(!a)return null;const r=ya(t,s)??0,i=a.retry,n=a.admission,c=a.stall,m=a.fallback,x={seconds:r,attempt:(i==null?void 0:i.attempt)??0,maxRetries:(i==null?void 0:i.maxRetries)??0,budgetSeconds:me(i==null?void 0:i.recoveryRemainingMs),position:(n==null?void 0:n.queuePosition)??0,depth:n?Math.max(n.queueDepth,n.queuePosition):0,scope:(n==null?void 0:n.scope)??"",waitSeconds:me(n==null?void 0:n.waitMs),stallSeconds:me(c==null?void 0:c.durationMs),timeoutSeconds:me(c==null?void 0:c.timeoutMs),from:(m==null?void 0:m.from.model)??"",to:(m==null?void 0:m.to.model)??"",candidate:(m==null?void 0:m.candidate)??0,candidateCount:(m==null?void 0:m.candidateCount)??0};switch(a.activity){case"admission_wait":return{titleKey:"chat.providerRecovery.admission",detailKey:"chat.providerRecovery.admissionDetail",compactKey:"chat.providerRecovery.admissionCompact",params:x};case"retry_wait":return{titleKey:a.reason==="rate_limit"?"chat.providerRecovery.rateLimit":"chat.providerRecovery.retryWait",detailKey:"chat.providerRecovery.retryDetail",compactKey:"chat.providerRecovery.retryCompact",params:x};case"retry_attempt":return{titleKey:"chat.providerRecovery.retryAttempt",detailKey:"chat.providerRecovery.retryDetail",compactKey:"chat.providerRecovery.retryCompact",params:x};case"circuit_open":return{titleKey:a.reason==="rate_limit"?"chat.providerRecovery.rateLimitCircuit":"chat.providerRecovery.circuit",detailKey:"chat.providerRecovery.circuitDetail",compactKey:a.reason==="rate_limit"?"chat.providerRecovery.rateLimitCircuitCompact":"chat.providerRecovery.circuitCompact",params:x};case"circuit_probe":return{titleKey:"chat.providerRecovery.probe",detailKey:"chat.providerRecovery.probeDetail",compactKey:"chat.providerRecovery.probeCompact",params:x};case"stream_stall":return{titleKey:c!=null&&c.outputStarted?"chat.providerRecovery.stallAfterOutput":"chat.providerRecovery.stall",detailKey:"chat.providerRecovery.stallDetail",compactKey:"chat.providerRecovery.stallCompact",params:x};case"fallback":return{titleKey:"chat.providerRecovery.fallback",detailKey:"chat.providerRecovery.fallbackDetail",compactKey:"chat.providerRecovery.fallbackCompact",params:x}}}function ja({recovery:t,stopping:s,onStop:a}){var x;const r=_(),[i,n]=h.useState(Date.now()),c=(x=t==null?void 0:t.snapshot)==null?void 0:x.nextActionAt;h.useEffect(()=>{if(c===void 0)return;n(Date.now());const l=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(l)},[c]);const m=kt(t,i);return m?e.jsxs("section",{role:"status","aria-live":"polite","data-provider-recovery-banner":!0,className:"mx-4 mb-2 flex min-h-12 items-center gap-3 rounded-lg border border-amber-300/70 bg-amber-50/80 px-3 py-2 text-amber-950 shadow-sm dark:border-amber-800/60 dark:bg-amber-950/35 dark:text-amber-100 md:mx-6",children:[e.jsx(U,{className:"h-4 w-4 shrink-0 animate-spin","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-semibold",children:r(m.titleKey,m.params)}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-[10px] opacity-80",children:r(m.detailKey,m.params)})]}),e.jsxs("button",{type:"button","data-provider-recovery-stop":!0,onClick:a,disabled:s,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/70 bg-white/70 px-2.5 text-xs font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 disabled:cursor-wait disabled:opacity-60 dark:border-amber-700 dark:bg-amber-950/50 dark:hover:bg-amber-900/50",children:[s?e.jsx(U,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):e.jsx(Bt,{className:"h-3 w-3 fill-current","aria-hidden":!0}),r(s?"chat.input.action.stopping":"chat.providerRecovery.stop")]})]}):null}const wa=h.lazy(()=>lt(()=>import("./MarkdownRenderer-DnFpJUbW.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function Na(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Sa(t,s){return t?[{id:"legacy-user",role:"user",content:t},...s?[{id:"legacy-assistant",role:"assistant",content:s}]:[]]:[]}function Me(t){return t?JSON.stringify([t.sessionRef.projectPath,t.sessionRef.sessionId,t.requestId]):null}function Ca(){const t=_(),s=v(d=>d.sideConversation),a=v(d=>d.askSideConversation),r=v(d=>d.openSideConversation),i=v(d=>d.dismissSideConversation),n=Me(s),[c,m]=h.useState({owner:n,text:""}),x=c.owner===n?c.text:"";c.owner!==n&&m({owner:n,text:""});const l=d=>m({owner:n,text:d}),b=h.useRef(null),k=h.useRef(!1),u=h.useRef(null),g=h.useMemo(()=>(s==null?void 0:s.messages)??Sa((s==null?void 0:s.question)??"",s==null?void 0:s.response),[s==null?void 0:s.messages,s==null?void 0:s.question,s==null?void 0:s.response]);if(h.useEffect(()=>{if(k.current=!1,!s||s.status==="loading")return;const d=document.activeElement;if(s.status!=="idle"&&d instanceof HTMLElement&&d!==b.current&&d.matches('input, textarea, select, [contenteditable="true"]'))return;const N=requestAnimationFrame(()=>{var f;document.activeElement===d&&((f=b.current)==null||f.focus())});return()=>cancelAnimationFrame(N)},[s==null?void 0:s.sessionRef,s==null?void 0:s.selectedText,s==null?void 0:s.status]),h.useEffect(()=>{var d,N;(N=(d=u.current)==null?void 0:d.scrollIntoView)==null||N.call(d,{block:"nearest"})},[g.length,s==null?void 0:s.status]),!s)return null;const p=()=>{const d=x.trim();if(!d||s.status==="loading")return;l("");const N=a(d),f=Me(v.getState().sideConversation);N.then(S=>{!S&&f!==null&&Me(v.getState().sideConversation)===f&&m({owner:f,text:d})})},w=d=>{if(!(k.current||d.nativeEvent.isComposing||d.keyCode===229)){if((d.metaKey||d.ctrlKey)&&d.key.toLocaleLowerCase()==="a"){d.preventDefault(),d.stopPropagation(),d.currentTarget.select();return}if(d.key==="Escape"){d.preventDefault(),i();return}d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),p())}};return e.jsxs("aside",{"aria-label":t("chat.side.title"),"data-blade-side-conversation":!0,"data-status":s.status,className:"absolute inset-0 z-30 flex min-h-0 flex-col bg-[hsl(var(--deck-canvas))] md:relative md:inset-auto md:w-[min(420px,42vw)] md:shrink-0 md:border-l md:border-[hsl(var(--deck-hairline))]",children:[e.jsxs("header",{className:"flex h-12 shrink-0 items-center gap-2 border-b border-[hsl(var(--deck-hairline))] px-3",children:[e.jsx(De,{"aria-hidden":!0,className:"h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsx("h2",{className:"min-w-0 flex-1 truncate text-[13px] font-medium text-[hsl(var(--deck-ink))]",children:t("chat.side.title")}),s.durationMs!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(rs,{"aria-hidden":!0,className:"h-3 w-3"}),Na(s.durationMs)]}),e.jsx("button",{type:"button",onClick:()=>{l(""),r()},"aria-label":t("chat.side.new"),title:t("chat.side.new"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface-2))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:e.jsx(ns,{"aria-hidden":!0,className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":t("chat.side.dismiss"),title:t("chat.side.dismiss"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface-2))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:e.jsx(mt,{"aria-hidden":!0,className:"h-4 w-4"})})]}),e.jsxs("div",{"aria-live":"polite","aria-busy":s.status==="loading",className:"min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4",children:[s.selectedText&&e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"inline-flex min-h-8 cursor-pointer list-none items-center gap-1.5 rounded-md border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))] px-2.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(De,{"aria-hidden":!0,className:"h-3.5 w-3.5"}),t("chat.side.selectedText")]}),e.jsx("blockquote",{className:"mt-2 whitespace-pre-wrap border-l-2 border-[hsl(var(--deck-accent)/0.45)] pl-3 font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:s.selectedText})]}),g.map(d=>d.role==="user"?e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"max-w-[88%] rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))]",children:d.content})},d.id):e.jsx("div",{className:"min-w-0",children:e.jsx(h.Suspense,{fallback:e.jsx("div",{className:"whitespace-pre-wrap break-words text-[12px] leading-5 text-[hsl(var(--deck-ink))]",children:d.content}),children:e.jsx(wa,{content:d.content,className:"text-[12px] leading-5 [&_h1]:text-[14px] [&_h2]:text-[13px] [&_h3]:text-[12px]"})})},d.id)),s.status==="loading"&&e.jsxs("div",{role:"status",className:"flex min-h-9 items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(U,{"aria-hidden":!0,className:"h-3.5 w-3.5 animate-spin text-[hsl(var(--deck-accent))]"}),t("chat.side.loading")]}),s.status==="error"&&e.jsxs("div",{role:"alert",className:"flex min-h-9 items-start gap-2 text-[11px] leading-5 text-red-700 dark:text-red-300",children:[e.jsx(Pe,{"aria-hidden":!0,className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"break-words",children:s.error??t("chat.side.failed")})]}),e.jsx("div",{ref:u})]}),e.jsx("div",{className:"shrink-0 border-t border-[hsl(var(--deck-hairline))] p-3",children:e.jsxs("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] focus-within:border-[hsl(var(--deck-border-strong))] focus-within:ring-1 focus-within:ring-[hsl(var(--deck-border-strong))]",children:[e.jsx("textarea",{ref:b,name:"side-conversation-composer",value:x,onChange:d=>l(d.target.value),onCompositionStart:()=>{k.current=!0},onCompositionEnd:()=>{k.current=!1},onBlur:()=>{k.current=!1},onKeyDown:w,rows:3,disabled:s.status==="loading","aria-label":t("chat.side.input"),placeholder:t("chat.side.placeholder"),className:"block max-h-40 min-h-[88px] w-full resize-none bg-transparent px-3 py-2.5 text-[13px] leading-5 text-[hsl(var(--deck-ink))] placeholder:text-[hsl(var(--deck-ink-faint))] focus:outline-none disabled:cursor-wait disabled:opacity-60"}),e.jsx("div",{className:"flex items-center justify-end px-2 pb-2",children:e.jsx("button",{type:"button",onClick:p,disabled:!x.trim()||s.status==="loading","aria-label":t("chat.side.send"),title:t("chat.side.send"),className:"flex h-8 w-8 items-center justify-center rounded-md bg-[hsl(var(--deck-ink))] text-[hsl(var(--deck-canvas))] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[hsl(var(--deck-accent))] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-35",children:e.jsx($e,{"aria-hidden":!0,className:"h-3.5 w-3.5"})})})]})})]})}function Ae(t){return Number.isFinite(t)?Math.max(0,t):0}function Ea(t){const s=Ae(t.totalInputTokens),a=Ae(t.cacheReadTokens),r=Ae(t.cacheWriteTokens),i=Math.min(a,s),n=Math.min(r,Math.max(0,s-i)),c=Math.max(0,s-i-n),m=s>0&&(a>0||r>0);return{totalInputTokens:s,cacheReadTokens:i,cacheWriteTokens:n,uncachedInputTokens:c,...m?{hitRate:i/s}:{}}}function Ta(t){return t===void 0||!Number.isFinite(t)?"—":`${Math.round(Math.max(0,Math.min(1,t))*100)}%`}const Ma={running:"status.phase.running",compacting:"status.phase.compacting",recovering_context:"status.phase.recoveringContext",switching_model:"status.phase.switchingModel",waiting_permission:"status.phase.waitingPermission",error:"status.phase.error",idle:""},Aa={model_changed:"status.cacheBreak.model",system_prompt_changed:"status.cacheBreak.system",tools_changed:"status.cacheBreak.tools",request_policy_changed:"status.cacheBreak.policy",ttl_expired:"status.cacheBreak.ttl",server_side:"status.cacheBreak.server"},ae=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString(),Ra=t=>{const s=Math.max(0,Math.ceil(t/1e3)),a=Math.floor(s/60),r=s%60;return a>0?`${a}m ${r}s`:`${r}s`};function yt(){const t=_(),s=v(o=>o.tokenUsage),a=v(o=>o.isStreaming),r=v(o=>o.agentPhase),i=v(o=>o.providerRecovery),n=v(o=>o.turnActivity),c=v(o=>o.pendingResume),m=v(o=>o.actionStationarity),x=v(o=>o.turnRecovery),l=Ma[r]??"",b=kt(i),k=(c==null?void 0:c.delayMs)!==void 0?` · retry in ${Ra(c.delayMs)}`:"",u=(x==null?void 0:x.state)==="requires_attention"?t("status.recovery.review"):"",g=(x==null?void 0:x.state)==="requires_attention"?t(x.reason==="interrupted_tool_call"?"status.recovery.interruptedTool":"status.recovery.successfulTool"):"",p=u||(m?`${t(m.phase==="halted"?"status.phase.actionStationarityStopped":"status.phase.actionStationarityRecovering")} · ${m.toolName} · ${m.runLength}/${m.haltThreshold}`:b?t(b.compactKey,b.params):c?`Recovery attempt ${c.attempt}/${c.maxAttempts}${k}`:l?t(l):""),w=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,d=Ea(s),N=Ta(d.hitRate),f=Math.min(w,100),S=w>95?"danger":w>80?"warn":"safe";return e.jsxs("div",{"data-chat-status-bar":!0,className:"flex items-center gap-2 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:gap-4 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.context")}),e.jsxs("span",{className:"flex gap-1 items-baseline tabular-nums",children:[e.jsx("span",{className:L("text-[12px] font-medium",S==="safe"&&"text-[hsl(var(--deck-ink))]",S==="warn"&&"text-amber-600 dark:text-amber-400",S==="danger"&&"text-red-600 dark:text-red-400"),children:ae(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",ae(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(Ie,{children:e.jsxs(Le,{children:[e.jsx(Be,{asChild:!0,children:e.jsx(ls,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(ye,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative hidden h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:block","aria-hidden":"true",children:[e.jsx("div",{className:L("absolute inset-y-0 left-0 transition-[width] duration-300",S==="safe"&&"bg-[hsl(var(--deck-accent))]",S==="warn"&&"bg-amber-500",S==="danger"&&"bg-red-500"),style:{width:`${f}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(o=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${o}%`}},o))})]}),e.jsxs("span",{className:L("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",S==="warn"&&"text-amber-600 dark:text-amber-400",S==="danger"&&"text-red-600 dark:text-red-400"),children:[w,"%"]})]}),e.jsx(Ie,{children:e.jsxs(Le,{children:[e.jsx(Be,{asChild:!0,children:e.jsxs("div",{className:"flex shrink-0 cursor-help items-baseline gap-2 border-l border-[hsl(var(--deck-hairline))] pl-2 sm:pl-4","data-testid":"prompt-cache-hit-rate","aria-label":`${t("status.cache")} ${N}`,children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.cache")}),e.jsx("span",{className:L("tabular-nums",d.hitRate===void 0?"text-[hsl(var(--deck-ink-faint))]":"font-medium text-[hsl(var(--deck-accent))]"),children:N})]})}),e.jsx(ye,{side:"top",className:"max-w-[280px]",children:d.hitRate===void 0?e.jsx("p",{className:"text-xs",children:t("status.cacheUnavailable")}):e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("p",{children:t("status.cacheTooltip")}),e.jsx("p",{className:"font-mono tabular-nums",children:t("status.cacheDetails",{read:ae(d.cacheReadTokens),write:ae(d.cacheWriteTokens),uncached:ae(d.uncachedInputTokens)})}),s.cacheBreak&&e.jsx("p",{className:"text-[hsl(var(--deck-accent))]",children:t("status.cacheBreak",{reason:t(Aa[s.cacheBreak.reason]??"status.cacheBreak.server"),previous:ae(s.cacheBreak.previousCacheReadTokens),current:ae(s.cacheBreak.cacheReadTokens)})})]})})]})}),e.jsx("div",{className:"flex-1"}),(u||a&&p&&(!(n!=null&&n.snapshot)||m))&&e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:L("shrink-0",u?"h-2 w-2 rounded-sm bg-amber-500":"deck-pulse-dot")}),e.jsxs("span",{className:L("truncate",u?"text-amber-600 dark:text-amber-400":"text-[hsl(var(--deck-accent))]"),children:[p,g?e.jsxs("span",{className:"hidden sm:inline",children:[" · ",g]}):null]})]})]})}function Da(){const{locale:t}=ut(),s=$t(o=>o.agentTeamsEnabled),a=v(o=>o.teams),r=v(o=>o.currentSessionRef),i=v(o=>oe(o.historySurfaceSelection)),n=v(o=>o.loadTeams),[c,m]=h.useState({}),[x,l]=h.useState({}),[b,k]=h.useState({}),[u,g]=h.useState(null),[p,w]=h.useState(null),[d,N]=h.useState(null);if(h.useEffect(()=>{i||n(r??void 0)},[s,r,i,n]),i||!s||!r||a.length===0)return null;const f=async o=>{var I;if(q(v.getState()))return;const T=(I=b[o])==null?void 0:I.trim();if(!(!T||u)){g(o),N(null);try{await ze.sendMessage(r,o,x[o]??"*",T),k(R=>({...R,[o]:""})),await n(r)}catch(R){N(R instanceof Error?R.message:H(t,"actionFailed"))}finally{g(null)}}},S=async o=>{if(!q(v.getState())&&!p){w(o),N(null);try{await ze.delete(r,o),await n(r)}catch(T){N(T instanceof Error?T.message:H(t,"actionFailed"))}finally{w(null)}}};return e.jsxs("section",{"aria-label":H(t,"title"),"data-blade-team-panel":!0,className:"shrink-0 border-y border-emerald-300/50 bg-emerald-50/55 dark:border-emerald-800/55 dark:bg-emerald-950/20",children:[d&&e.jsx("div",{role:"alert",className:"border-b border-red-200 bg-red-50 px-4 py-2 font-mono text-[10px] text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300 md:px-6",children:d}),a.filter(o=>o.status!=="deleted").map(o=>{var R;const T=c[o.name]??o.status==="running",I=o.tasks.filter(j=>j.status==="completed").length;return e.jsxs("div",{className:"border-b border-emerald-200/40 last:border-0 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"flex min-h-11 items-center gap-2 px-4 py-2 md:px-6",children:[e.jsx("button",{type:"button",onClick:()=>m(j=>({...j,[o.name]:!T})),"aria-label":T?H(t,"collapse"):H(t,"expand"),className:"flex h-7 w-7 items-center justify-center rounded-md text-emerald-700 hover:bg-emerald-100 dark:text-emerald-300 dark:hover:bg-emerald-900/50",children:T?e.jsx(he,{className:"h-4 w-4"}):e.jsx(ce,{className:"h-4 w-4"})}),e.jsx(xs,{className:"h-4 w-4 shrink-0 text-emerald-700 dark:text-emerald-300"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("h2",{className:"truncate font-mono text-[11px] font-semibold uppercase text-emerald-800 dark:text-emerald-200",children:o.name}),e.jsxs("span",{className:"font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[o.status," · ",o.members.length-1," ",H(t,"members")," · ",I,"/",o.tasks.length," ",H(t,"tasks")]})]}),o.description&&e.jsx("p",{className:"truncate font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:o.description})]}),e.jsx("button",{type:"button",onClick:()=>void S(o.name),disabled:p===o.name,"aria-label":H(t,"delete"),title:H(t,"delete"),className:"flex h-7 w-7 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] hover:bg-red-50 hover:text-red-600 disabled:opacity-40 dark:hover:bg-red-950/40",children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),T&&e.jsxs("div",{className:"max-h-[min(40vh,360px)] overflow-y-auto border-t border-emerald-200/40 px-4 py-3 md:px-6 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 lg:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:H(t,"members")}),o.members.map(j=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsx("span",{"aria-label":j.status,className:`h-1.5 w-1.5 shrink-0 rounded-full ${j.status==="running"?"bg-emerald-500":j.status==="completed"||j.status==="leader"?"bg-sky-500":j.status==="failed"?"bg-red-500":"bg-zinc-400"}`}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:j.name}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:j.subagentType}),j.worktreePath&&e.jsx(st,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]","aria-label":H(t,"worktree")})]},j.id))]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:H(t,"tasks")}),o.tasks.length===0?e.jsx("p",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:H(t,"noTasks")}):o.tasks.map(j=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["#",j.id]}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:j.subject}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:j.status})]},j.id))]})]}),o.peerMessagingEnabled&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-emerald-200/40 pt-3 dark:border-emerald-900/40",children:[e.jsxs("select",{"aria-label":H(t,"recipient"),value:x[o.name]??"*",onChange:j=>l(V=>({...V,[o.name]:j.target.value})),className:"h-8 max-w-32 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10px]",children:[e.jsx("option",{value:"*",children:H(t,"broadcast")}),o.members.filter(j=>j.status!=="leader").map(j=>e.jsx("option",{value:j.name,children:j.name},j.id))]}),e.jsx("input",{value:b[o.name]??"",onChange:j=>k(V=>({...V,[o.name]:j.target.value})),onKeyDown:j=>{j.key==="Enter"&&f(o.name)},placeholder:H(t,"messagePlaceholder"),className:"h-8 min-w-0 flex-1 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10.5px] outline-none focus:border-emerald-500"}),e.jsx("button",{type:"button",onClick:()=>void f(o.name),disabled:!((R=b[o.name])!=null&&R.trim())||u===o.name,"aria-label":H(t,"send"),title:H(t,"send"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-emerald-700 text-white hover:bg-emerald-800 disabled:opacity-40 dark:bg-emerald-600",children:e.jsx($e,{className:"h-3.5 w-3.5"})})]})]})]},o.name)})]})}const Fa={starting:"chat.turnActivity.starting",thinking:"chat.turnActivity.thinking",responding:"chat.turnActivity.responding",executing_tools:"chat.turnActivity.executingTools",compacting:"chat.turnActivity.compacting",continuing:"chat.turnActivity.continuing"};function Ia(t){const s=Math.max(0,Math.floor(t/1e3));if(s<60)return`${s}s`;const a=Math.floor(s/60),r=s%60;return a<60?`${a}m ${r}s`:`${Math.floor(a/60)}h ${a%60}m ${r}s`}function La(t,s=Date.now()){const a=t==null?void 0:t.snapshot;if(!a)return null;const r=a.activeTools.length+a.activeToolOverflow,i=a.activeTools.slice(0,2).map(c=>c.progress!==void 0&&c.total!==void 0?`${c.name} ${c.progress}/${c.total}`:c.name),n=Math.max(0,a.activeTools.length-i.length+a.activeToolOverflow);return{phaseKey:Fa[a.phase],phaseParams:{count:r},tools:i,hiddenTools:n,completedTools:a.toolCallsCompleted,startedTools:a.toolCallsStarted,turn:a.turn,maxTurns:a.maxTurns,elapsed:Ia(s-a.startedAt)}}function Ba({activity:t,memory:s=null}){var x;const a=_(),[r,i]=h.useState(Date.now()),n=(x=t==null?void 0:t.snapshot)==null?void 0:x.startedAt;h.useEffect(()=>{if(n===void 0)return;i(Date.now());const l=window.setInterval(()=>i(Date.now()),1e3);return()=>window.clearInterval(l)},[n]);const c=La(t,r);if(!c)return(s==null?void 0:s.outcome)!=="written"?null:e.jsxs("section",{role:"status","aria-live":"polite","data-memory-consolidation-notice":!0,className:"mx-4 mb-2 flex min-h-10 items-center gap-3 rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/80 px-3 py-2 text-[hsl(var(--deck-ink))] shadow-sm md:mx-6",children:[e.jsx(He,{className:"h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))]","aria-hidden":!0}),e.jsx("span",{className:"text-xs font-semibold",children:a("chat.memoryConsolidation.saved",{count:s.entries})})]});const m=[(s==null?void 0:s.outcome)==="written"?a("chat.memoryConsolidation.saved",{count:s.entries}):void 0,...c.tools,c.hiddenTools>0?`+${c.hiddenTools}`:void 0,c.startedTools>0?a("chat.turnActivity.toolCount",{completed:c.completedTools,started:c.startedTools}):void 0,c.turn>0?c.maxTurns===null?a("chat.turnActivity.turn",{turn:c.turn}):a("chat.turnActivity.turnBounded",{turn:c.turn,maxTurns:c.maxTurns}):void 0].filter(l=>l!==void 0);return e.jsxs("section",{role:"status","aria-live":"polite","data-turn-activity-strip":!0,className:"mx-4 mb-2 flex min-h-10 items-center gap-3 rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/80 px-3 py-2 text-[hsl(var(--deck-ink))] shadow-sm md:mx-6",children:[e.jsx(He,{className:"h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))] motion-safe:animate-pulse","aria-hidden":!0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-semibold",children:a(c.phaseKey,c.phaseParams)}),m.length>0&&e.jsx("div",{className:"mt-0.5 truncate font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:m.join(" · ")})]}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))]",children:c.elapsed})]})}function $a(t){const s=[...t].reverse().find(i=>i.role==="user");if(!s)return null;if(typeof s.content=="string")return{content:s.content,attachments:[]};const a=s.content.filter(i=>i.type==="text").map(i=>i.text).join(`
70
+ `),r=s.content.filter(i=>i.type==="image_url").map((i,n)=>{var m;const c=((m=i.image_url.url.match(/^data:([^;,]+)[;,]/))==null?void 0:m[1])??"application/octet-stream";return{id:`recovery-${s.id}-${n}`,name:`attachment-${n+1}`,mimeType:c,dataUrl:i.image_url.url}});return{content:a,attachments:r}}function Pa({messages:t,isLoading:s,isStreaming:a,isStopping:r,errorMessage:i}){const n=_(),[c,m]=h.useState(!1),x=n(i?"status.phase.error":r?"chat.input.action.stopping":a?"status.phase.running":"preview.files.status.ready");return e.jsxs("details",{"data-preview-status-disclosure":!0,open:c,onToggle:l=>m(l.currentTarget.open),className:"group hidden",children:[e.jsxs("summary",{className:"flex h-9 cursor-pointer list-none items-center gap-2 px-3 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[hsl(var(--deck-accent))]",children:[a&&e.jsx("span",{className:"deck-pulse-dot"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:x}),e.jsx(ce,{className:"h-3.5 w-3.5 shrink-0 transition-transform group-open:rotate-90"})]}),c&&e.jsxs("div",{"data-preview-activity-details":!0,className:"flex h-[min(44vh,420px)] min-h-0 flex-col border-t border-[hsl(var(--deck-hairline))]",children:[i&&e.jsx("div",{role:"alert",className:"border-b border-red-200/60 bg-red-50/80 px-3 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-300",children:i}),e.jsx(gt,{messages:t,isLoading:s}),e.jsx(yt,{})]})]})}function tr(){var se;const t=_(),s=v(y=>y.messages),a=v(y=>y.currentSessionRef),r=v(y=>y.isStreaming),i=v(y=>y.isStopping),n=v(y=>y.providerRecovery),c=v(y=>y.turnActivity),m=v(y=>y.memoryConsolidation),x=v(y=>y.actionStationarity),l=v(y=>y.sessionEventConnectionState),b=v(y=>y.pendingSteeringCount),k=v(y=>y.pendingInputDelivery),u=v(y=>y.recoveredSteeringCount),g=v(y=>y.followUpQueue),p=v(y=>y.followUpQueueMutation),w=v(y=>y.mutateFollowUpQueue),d=v(y=>y.refreshFollowUpQueue),N=v(y=>!!y.historySurfaceSelection),f=v(y=>y.isLoading),S=v(y=>y.error),o=v(y=>y.errorContext),T=v(y=>y.sessions),I=v(y=>y.sendMessage),R=v(y=>y.openSideConversation),j=v(y=>y.abortSession),V=v(y=>y.retryTask),X=v(y=>y.retryingTaskKeys),E=_e(y=>y.openSettings),B=v(y=>y.reconnectSessionEvents),O=v(y=>y.clearError),[P,C]=h.useState(null),M=a?T.find(y=>y.sessionId===a.sessionId&&y.projectPath===a.projectPath):void 0,A=!!S&&((o==null?void 0:o.kind)==="navigation"||!(o!=null&&o.sessionRef)||tt(o.sessionRef,a)),D=(o==null?void 0:o.failureCode)??((se=M==null?void 0:M.taskFailure)==null?void 0:se.code),G=((o==null?void 0:o.kind)==="execution"||o!=null&&o.failureCode)&&D?t(zt(D)):S==="queue_full"?t("chat.error.queueFull"):S==="turn_unavailable"||S==="turn_active"?t("chat.error.turnChanged"):S,ee=l==="connecting"||l==="reconnecting",F=r&&l!=="connected",W=a?`session:${ue(a)}`:"session:temporary",J=h.useMemo(()=>$a(s),[s]),Q=a?ue(a):"temporary-session",z=!!(a&&(M!=null&&M.taskRetryAvailable)&&(!D||qt(D)))&&((o==null?void 0:o.kind)==="execution"||(o==null?void 0:o.kind)==="task_action"),K=(o==null?void 0:o.kind)==="execution"&&(D==="authentication"||D==="permission"||D==="model_unavailable"),Y=a?X.includes(ue(a)):!1;h.useEffect(()=>{C(null)},[Q]);const te=async y=>q(v.getState())?!1:I({content:y.content,modelId:y.modelId,reasoningEffort:y.reasoningEffort,serviceTier:y.serviceTier,responseVerbosity:y.responseVerbosity,communicationStyle:y.communicationStyle,...y.annotations?{annotations:y.annotations}:{},...y.outputSchema?{outputSchema:y.outputSchema}:{},attachments:y.attachments.map(Ne=>({type:"image",content:Ne.dataUrl,mimeType:Ne.mimeType,name:Ne.name}))}),le=()=>{if(!q(v.getState()))return j()},xe=async()=>{if(!q(v.getState())){if(K){O(),E("models");return}if(z&&a){O(),await V(a).catch(()=>{});return}if((o==null?void 0:o.kind)==="execution"&&J){C({...J,revision:Date.now()}),O();return}O(),requestAnimationFrame(()=>Ot())}},$=z?t(Y?"chat.error.action.retryingTask":"chat.error.action.retryTask"):K?t("chat.error.action.checkModels"):(o==null?void 0:o.kind)==="execution"&&J?t("chat.error.action.editResend"):(o==null?void 0:o.kind)==="submission"?t("chat.error.action.returnDraft"):null;return e.jsxs("div",{"data-chat-view":!0,className:"relative flex h-full min-h-0 overflow-hidden bg-[hsl(var(--deck-canvas))]",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("div",{"data-chat-history":!0,className:"contents",children:[A&&e.jsxs("div",{role:"alert","data-blade-session-error":!0,className:"flex min-h-11 flex-wrap items-center gap-2 border-b border-red-200/60 bg-red-50/80 px-4 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-300 sm:px-5",children:[e.jsx(Pe,{className:"h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 break-words",children:[e.jsx("span",{className:"font-semibold",children:t((o==null?void 0:o.kind)==="submission"?"chat.error.title.submission":(o==null?void 0:o.kind)==="execution"?"chat.error.title.execution":(o==null?void 0:o.kind)==="navigation"?"chat.error.title.navigation":"chat.error.title.generic")})," ",G]}),$&&e.jsxs("button",{type:"button",onClick:()=>void xe(),disabled:Y,className:"inline-flex min-h-7 shrink-0 items-center gap-1.5 rounded-md border border-red-300/70 bg-white/65 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 disabled:cursor-wait disabled:opacity-60 dark:border-red-800 dark:bg-red-950/45 dark:hover:bg-red-900/60",children:[z?Y?e.jsx(U,{className:"h-3 w-3 animate-spin"}):e.jsx(ve,{className:"h-3 w-3"}):e.jsx(ft,{className:"h-3 w-3"}),$]}),e.jsx("button",{type:"button",onClick:O,"aria-label":t("chat.error.dismiss"),className:"p-1 text-red-500 rounded transition-colors hover:bg-red-100/60 hover:text-red-700 dark:hover:bg-red-950/60 dark:hover:text-red-100",children:"✕"})]}),(ee||l==="offline")&&e.jsxs("div",{role:l==="offline"?"alert":"status","aria-live":"polite",className:"flex min-h-10 flex-wrap items-center gap-2 border-b border-amber-300/60 bg-amber-50/80 px-4 py-2 font-mono text-[11px] text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/35 dark:text-amber-200 sm:px-5",children:[ee?e.jsx(U,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Pt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t(ee?"chat.connection.reconnecting":"chat.connection.offline")}),l==="offline"&&e.jsxs("button",{type:"button",onClick:()=>{q(v.getState())||B().catch(()=>{})},className:"inline-flex min-h-7 items-center gap-1.5 rounded-md border border-amber-400/70 bg-white/60 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/50 dark:hover:bg-amber-900/50",children:[e.jsx(dt,{className:"h-3 w-3"}),t("chat.connection.retry")]})]}),e.jsx(ps,{}),e.jsx(gt,{messages:s,isLoading:f,selectionDraftKey:N?void 0:W,canAskSideConversation:!!(a&&!N),onOpenSideConversation:R},a?ue(a):"temporary-session"),e.jsx(Da,{})]}),e.jsxs("div",{"data-chat-composer-dock":!0,className:"contents",children:[e.jsx(Pa,{messages:s,isLoading:f,isStreaming:r,isStopping:i,errorMessage:A?G:null},Q),e.jsx(ka,{}),e.jsx(ga,{}),e.jsx(fa,{queue:N?null:g,mutation:p,onMutate:w,onRefresh:d}),e.jsx(ja,{recovery:N?null:n,stopping:i,onStop:le}),e.jsx(Ba,{activity:N||n!=null&&n.snapshot||x||M!=null&&M.pendingInteraction?null:c,memory:N?null:m}),e.jsx(_t,{draftKey:W,draft:P==null?void 0:P.content,draftAttachments:P==null?void 0:P.attachments,draftRevision:P==null?void 0:P.revision,onSend:te,onAbort:le,disabled:f||F,isStreaming:r,isStopping:i,pendingSteeringCount:b,pendingInputDelivery:k,recoveredSteeringCount:u,workspacePath:a==null?void 0:a.projectPath},W),e.jsx("div",{"data-chat-primary-status":!0,className:"contents",children:e.jsx(yt,{})})]})]}),e.jsx(Ca,{})]})}export{tr as ChatView};